From 4ff4e965c8db8eaa270e9d781aded81f865c4d0d Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Wed, 9 Oct 2024 18:11:01 +0200 Subject: [PATCH 1/3] replace cgi module --- multiurl/http.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/multiurl/http.py b/multiurl/http.py index 4a6e345..657fc67 100644 --- a/multiurl/http.py +++ b/multiurl/http.py @@ -7,7 +7,6 @@ # nor does it submit to any jurisdiction. # -import cgi import datetime import json import logging @@ -35,6 +34,14 @@ 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, @@ -103,7 +110,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"]) @@ -113,7 +120,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() From 5755069b1bda1eb06133ddd03a325cb10ab30e9f Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Wed, 9 Oct 2024 18:11:22 +0200 Subject: [PATCH 2/3] update classifiers --- setup.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index b41f569..fd5fc24 100644 --- a/setup.py +++ b/setup.py @@ -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", From 3d4216bbcd98a1aa5131d836d7ccd8ce11fdc819 Mon Sep 17 00:00:00 2001 From: Filipe Fernandes Date: Thu, 10 Oct 2024 18:48:28 +0200 Subject: [PATCH 3/3] QA fix --- multiurl/http.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/multiurl/http.py b/multiurl/http.py index 657fc67..42eefec 100644 --- a/multiurl/http.py +++ b/multiurl/http.py @@ -37,8 +37,9 @@ def NoFilter(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 + m["content-type"] = value return dict(m.get_params())