Skip to content

Commit 3da1c91

Browse files
authored
Vendor parse_header out of the deprecated cgi module (#112)
* Vendor parse_header out of the deprecated cgi module * Migrate to GH Actions * Update run conditions * Fix doc build * Vendor better * Use a newer Python on RTD * Bye bye pipelines * Update rtd config format * Fix test extras * Add ftp extra for dist tests
1 parent 658a7c1 commit 3da1c91

5 files changed

Lines changed: 92 additions & 79 deletions

File tree

.github/workflows/ci_workflows.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- '*.*'
8+
- '!*backport*'
9+
tags:
10+
- 'v*'
11+
- '!*dev*'
12+
- '!*pre*'
13+
- '!*post*'
14+
pull_request:
15+
# Allow manual runs through the web UI
16+
workflow_dispatch:
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.ref }}
20+
cancel-in-progress: true
21+
22+
jobs:
23+
24+
tests:
25+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1
26+
with:
27+
envs: |
28+
- linux: mypy
29+
- linux: py38-conda
30+
- linux: py310
31+
- linux: py311
32+
- linux: py39
33+
- windows: py38
34+
- macos: py37
35+
coverage: 'codecov'
36+
37+
publish:
38+
needs: tests
39+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
40+
with:
41+
test_extras: tests,ftp
42+
test_command: pytest --pyargs parfive
43+
secrets:
44+
pypi_token: ${{ secrets.pypi_token }}

.readthedocs.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
# .readthedocs.yml
22
# Read the Docs configuration file
33
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4-
5-
# Required
64
version: 2
75

8-
# Build documentation in the docs/ directory with Sphinx
6+
build:
7+
os: ubuntu-22.04
8+
tools:
9+
python: "3.10"
10+
apt_packages:
11+
- graphviz
12+
913
sphinx:
1014
builder: html
1115
configuration: docs/conf.py
1216
fail_on_warning: true
1317

14-
# Set the version of Python and requirements required to build your docs
1518
python:
16-
version: 3.8
17-
install:
18-
- method: pip
19-
path: .
20-
extra_requirements:
19+
install:
20+
- method: pip
21+
path: .
22+
extra_requirements:
2123
- docs
24+
- ftp

azure-pipelines.yml

Lines changed: 0 additions & 66 deletions
This file was deleted.

parfive/utils.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import cgi
32
import asyncio
43
import hashlib
54
import pathlib
@@ -22,12 +21,45 @@
2221
]
2322

2423

24+
# Copied out of CPython under PSF Licence 2
25+
def _parseparam(s):
26+
while s[:1] == ";":
27+
s = s[1:]
28+
end = s.find(";")
29+
while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
30+
end = s.find(";", end + 1)
31+
if end < 0:
32+
end = len(s)
33+
f = s[:end]
34+
yield f.strip()
35+
s = s[end:]
36+
37+
38+
def parse_header(line):
39+
"""Parse a Content-type like header.
40+
Return the main content-type and a dictionary of options.
41+
"""
42+
parts = _parseparam(";" + line)
43+
key = parts.__next__()
44+
pdict = {}
45+
for p in parts:
46+
i = p.find("=")
47+
if i >= 0:
48+
name = p[:i].strip().lower()
49+
value = p[i + 1 :].strip()
50+
if len(value) >= 2 and value[0] == value[-1] == '"':
51+
value = value[1:-1]
52+
value = value.replace("\\\\", "\\").replace('\\"', '"')
53+
pdict[name] = value
54+
return key, pdict
55+
56+
2557
def default_name(path: os.PathLike, resp: aiohttp.ClientResponse, url: str) -> os.PathLike:
2658
url_filename = url.split("/")[-1]
2759
if resp:
2860
cdheader = resp.headers.get("Content-Disposition", None)
2961
if cdheader:
30-
value, params = cgi.parse_header(cdheader)
62+
value, params = parse_header(cdheader)
3163
name = params.get("filename", url_filename)
3264
else:
3365
name = url_filename

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ tests =
3838
pytest-cov
3939
aiofiles
4040
docs =
41-
sphinx
41+
# Book theme seems to not like sphinx 5
42+
sphinx<5
4243
sphinx-automodapi
43-
sunpy-sphinx-theme
4444
sphinx-autodoc-typehints
4545
sphinx-contributors
4646
sphinx-book-theme

0 commit comments

Comments
 (0)