From 1ebbd453eaefc837f37b68a25ec730ccb69b865c Mon Sep 17 00:00:00 2001 From: Felix Schwarz Date: Mon, 20 Jun 2022 22:30:08 +0200 Subject: [PATCH] backport patch to remove usage of cgi module (rhbz #2083956) --- babel-remove-cgi-deprecation-warning.patch | 75 ++++++++++++++++++++++ babel.spec | 8 ++- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 babel-remove-cgi-deprecation-warning.patch diff --git a/babel-remove-cgi-deprecation-warning.patch b/babel-remove-cgi-deprecation-warning.patch new file mode 100644 index 0000000..8eb5b76 --- /dev/null +++ b/babel-remove-cgi-deprecation-warning.patch @@ -0,0 +1,75 @@ +From 965523b6c61263f48a20f1cbe8862e460c1b4853 Mon Sep 17 00:00:00 2001 +From: Aarni Koskela +Date: Tue, 10 May 2022 15:36:47 +0300 +Subject: [PATCH] Use email.Message for pofile header parsing + +cgi.parse_header is due to be deprecated + +Fixes #873 +--- + babel/messages/catalog.py | 12 +++++++++--- + tests/messages/test_pofile.py | 11 +++++++++++ + 2 files changed, 20 insertions(+), 3 deletions(-) + +diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py +index 564b2c7c..e43a28c0 100644 +--- a/babel/messages/catalog.py ++++ b/babel/messages/catalog.py +@@ -10,7 +10,6 @@ + + import re + +-from cgi import parse_header + from collections import OrderedDict + from datetime import datetime, time as time_ + from difflib import get_close_matches +@@ -225,6 +224,13 @@ class TranslationError(Exception): + # FIRST AUTHOR , YEAR. + #""" + ++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 Catalog: + """Representation of a message catalog.""" +@@ -424,11 +430,11 @@ def _set_mime_headers(self, headers): + elif name == 'language-team': + self.language_team = value + elif name == 'content-type': +- mimetype, params = parse_header(value) ++ params = parse_separated_header(value) + if 'charset' in params: + self.charset = params['charset'].lower() + elif name == 'plural-forms': +- _, params = parse_header(' ;' + value) ++ params = parse_separated_header(' ;' + value) + self._num_plurals = int(params.get('nplurals', 2)) + self._plural_expr = params.get('plural', '(n != 1)') + elif name == 'pot-creation-date': +diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py +index 632efe7b..118960ab 100644 +--- a/tests/messages/test_pofile.py ++++ b/tests/messages/test_pofile.py +@@ -68,6 +68,17 @@ def test_applies_specified_encoding_during_read(self): + catalog = pofile.read_po(buf, locale='de_DE') + self.assertEqual(u'bär', catalog.get('foo').string) + ++ def test_encoding_header_read(self): ++ buf = BytesIO(b'msgid ""\nmsgstr ""\n"Content-Type: text/plain; charset=mac_roman\\n"\n') ++ catalog = pofile.read_po(buf, locale='xx_XX') ++ assert catalog.charset == 'mac_roman' ++ ++ def test_plural_forms_header_parsed(self): ++ buf = BytesIO(b'msgid ""\nmsgstr ""\n"Plural-Forms: nplurals=42; plural=(n % 11);\\n"\n') ++ catalog = pofile.read_po(buf, locale='xx_XX') ++ assert catalog.plural_expr == '(n % 11)' ++ assert catalog.num_plurals == 42 ++ + def test_read_multiline(self): + buf = StringIO(r'''msgid "" + "Here's some text that\n" diff --git a/babel.spec b/babel.spec index 04d194a..ff39f8a 100644 --- a/babel.spec +++ b/babel.spec @@ -8,12 +8,15 @@ Name: babel Version: 2.10.3 -Release: 1%{?dist} +Release: 2%{?dist} Summary: Tools for internationalizing Python applications License: BSD URL: https://babel.pocoo.org/ Source0: %{pypi_source} +# patch present in upstream master (commit 965523b6) but not in +# 2.10.x branch +Patch0: babel-remove-cgi-deprecation-warning.patch BuildArch: noarch @@ -124,6 +127,9 @@ export TZ=UTC %endif %changelog +* Mon Jun 20 2022 Felix Schwarz - 2.10.3-2 +- backport patch to remove usage of cgi module (rhbz #2083956) + * Mon Jun 20 2022 Felix Schwarz - 2.10.3-1 - update to 2.10.3