Skip to content

Commit

Permalink
Merge pull request #15 from ocefpaf/remove_cgi
Browse files Browse the repository at this point in the history
Remove cgi
  • Loading branch information
EddyCMWF authored Oct 14, 2024
2 parents ac087a7 + 3d4216b commit 77b3878
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 11 additions & 3 deletions multiurl/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# nor does it submit to any jurisdiction.
#

import cgi
import datetime
import json
import logging
Expand Down Expand Up @@ -35,6 +34,15 @@ def NoFilter(x):
return x


def parse_separated_header(value: str):
"""Adapted from https://peps.python.org/pep-0594/#cgi."""
from email.message import Message

m = Message()
m["content-type"] = value
return dict(m.get_params())


class HTTPDownloaderBase(DownloaderBase):
def __init__(
self,
Expand Down Expand Up @@ -103,7 +111,7 @@ def extension(self):
headers = self.headers()

if "content-disposition" in headers:
value, params = cgi.parse_header(headers["content-disposition"])
value, params = parse_separated_header(headers["content-disposition"])
assert value == "attachment", value
if "filename" in params:
ext = super().extension(params["filename"])
Expand All @@ -113,7 +121,7 @@ def extension(self):
def title(self):
headers = self.headers()
if "content-disposition" in headers:
value, params = cgi.parse_header(headers["content-disposition"])
value, params = parse_separated_header(headers["content-disposition"])
if "filename" in params:
return params["filename"]
return super().title()
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def read(fname):
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: OS Independent",
Expand Down

0 comments on commit 77b3878

Please sign in to comment.