summaryrefslogtreecommitdiff
path: root/dev-python/python-mimeparse
diff options
context:
space:
mode:
Diffstat (limited to 'dev-python/python-mimeparse')
-rw-r--r--dev-python/python-mimeparse/files/python-mimeparse-1.6.0-py3.13.patch79
-rw-r--r--dev-python/python-mimeparse/python-mimeparse-1.6.0-r5.ebuild28
2 files changed, 107 insertions, 0 deletions
diff --git a/dev-python/python-mimeparse/files/python-mimeparse-1.6.0-py3.13.patch b/dev-python/python-mimeparse/files/python-mimeparse-1.6.0-py3.13.patch
new file mode 100644
index 000000000000..90b4c4fc7d8a
--- /dev/null
+++ b/dev-python/python-mimeparse/files/python-mimeparse-1.6.0-py3.13.patch
@@ -0,0 +1,79 @@
+From 5427072b12119fe28fd66f19f74beb7da0c1de8b Mon Sep 17 00:00:00 2001
+From: Stanis Trendelenburg <stanis.trendelenburg@gmail.com>
+Date: Mon, 1 Jan 2024 12:48:19 +0100
+Subject: [PATCH] chore(cgi): include `parse_header()` from the deprecated cgi
+ module (#46)
+
+* Include functions from the deprecated cgi module
+
+* Document source of vendored functions from cgi.py
+
+* Fix linter error
+---
+
+Upstream-PR: https://github.com/falconry/python-mimeparse/pull/46
+
+diff --git a/mimeparse.py b/mimeparse.py
+index 0de6d57..506e138 100644
+--- a/mimeparse.py
++++ b/mimeparse.py
+@@ -1,5 +1,3 @@
+-import cgi
+-
+ __version__ = '1.6.0'
+ __author__ = 'Joe Gregorio'
+ __email__ = 'joe@bitworking.org'
+@@ -11,6 +9,44 @@ class MimeTypeParseException(ValueError):
+ pass
+
+
++# Vendored version of cgi._parseparam from Python 3.11 (deprecated and slated
++# for removal in 3.13)
++def _parseparam(s):
++ while s[:1] == ';':
++ s = s[1:]
++ end = s.find(';')
++ while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
++ end = s.find(';', end + 1)
++ if end < 0:
++ end = len(s)
++ f = s[:end]
++ yield f.strip()
++ s = s[end:]
++
++
++# Vendored version of cgi.parse_header from Python 3.11 (deprecated and slated
++# for removal in 3.13)
++def _parse_header(line):
++ """Parse a Content-type like header.
++
++ Return the main content-type and a dictionary of options.
++
++ """
++ parts = _parseparam(';' + line)
++ key = parts.__next__()
++ pdict = {}
++ for p in parts:
++ i = p.find('=')
++ if i >= 0:
++ name = p[:i].strip().lower()
++ value = p[i + 1:].strip()
++ if len(value) >= 2 and value[0] == value[-1] == '"':
++ value = value[1:-1]
++ value = value.replace('\\\\', '\\').replace('\\"', '"')
++ pdict[name] = value
++ return key, pdict
++
++
+ def parse_mime_type(mime_type):
+ """Parses a mime-type into its component parts.
+
+@@ -23,7 +59,7 @@ def parse_mime_type(mime_type):
+
+ :rtype: (str,str,dict)
+ """
+- full_type, params = cgi.parse_header(mime_type)
++ full_type, params = _parse_header(mime_type)
+ # Java URLConnection class sends an Accept header that includes a
+ # single '*'. Turn it into a legal wildcard.
+ if full_type == '*':
diff --git a/dev-python/python-mimeparse/python-mimeparse-1.6.0-r5.ebuild b/dev-python/python-mimeparse/python-mimeparse-1.6.0-r5.ebuild
new file mode 100644
index 000000000000..ef0bbf3fd3e0
--- /dev/null
+++ b/dev-python/python-mimeparse/python-mimeparse-1.6.0-r5.ebuild
@@ -0,0 +1,28 @@
+# Copyright 1999-2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+DISTUTILS_USE_PEP517=setuptools
+PYPI_NO_NORMALIZE=1
+PYTHON_COMPAT=( python3_{8,9,10,11,12} pypy3 )
+
+inherit distutils-r1 pypi
+
+DESCRIPTION="Basic functions for handling mime-types in python"
+HOMEPAGE="
+ https://github.com/falconry/python-mimeparse/
+ https://pypi.org/project/python-mimeparse/
+"
+
+LICENSE="MIT"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sparc ~x86 ~amd64-linux ~x86-linux ~x64-macos"
+
+PATCHES=(
+ "${FILESDIR}/${P}-py3.13.patch"
+)
+
+python_test() {
+ "${EPYTHON}" mimeparse_test.py -v || die "Tests fail with ${EPYTHON}"
+}