backport patch to remove usage of cgi module (rhbz #2083956)
This commit is contained in:
parent
c6284b9b39
commit
1ebbd453ea
75
babel-remove-cgi-deprecation-warning.patch
Normal file
75
babel-remove-cgi-deprecation-warning.patch
Normal file
@ -0,0 +1,75 @@
|
||||
From 965523b6c61263f48a20f1cbe8862e460c1b4853 Mon Sep 17 00:00:00 2001
|
||||
From: Aarni Koskela <akx@iki.fi>
|
||||
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 <EMAIL@ADDRESS>, 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"
|
||||
@ -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 <fschwarz@fedoraproject.org> - 2.10.3-2
|
||||
- backport patch to remove usage of cgi module (rhbz #2083956)
|
||||
|
||||
* Mon Jun 20 2022 Felix Schwarz <fschwarz@fedoraproject.org> - 2.10.3-1
|
||||
- update to 2.10.3
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user