|
10 | 10 |
|
11 | 11 | import re |
12 | 12 |
|
13 | | -from cgi import parse_header |
14 | 13 | from collections import OrderedDict |
15 | 14 | from datetime import datetime, time as time_ |
16 | 15 | from difflib import get_close_matches |
@@ -225,6 +224,13 @@ class TranslationError(Exception): |
225 | 224 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
226 | 225 | #""" |
227 | 226 |
|
| 227 | +def parse_separated_header(value: str): |
| 228 | + # Adapted from https://peps.python.org/pep-0594/#cgi |
| 229 | + from email.message import Message |
| 230 | + m = Message() |
| 231 | + m['content-type'] = value |
| 232 | + return dict(m.get_params()) |
| 233 | + |
228 | 234 |
|
229 | 235 | class Catalog: |
230 | 236 | """Representation of a message catalog.""" |
@@ -424,11 +430,11 @@ def _set_mime_headers(self, headers): |
424 | 430 | elif name == 'language-team': |
425 | 431 | self.language_team = value |
426 | 432 | elif name == 'content-type': |
427 | | - mimetype, params = parse_header(value) |
| 433 | + params = parse_separated_header(value) |
428 | 434 | if 'charset' in params: |
429 | 435 | self.charset = params['charset'].lower() |
430 | 436 | elif name == 'plural-forms': |
431 | | - _, params = parse_header(' ;' + value) |
| 437 | + params = parse_separated_header(' ;' + value) |
432 | 438 | self._num_plurals = int(params.get('nplurals', 2)) |
433 | 439 | self._plural_expr = params.get('plural', '(n != 1)') |
434 | 440 | elif name == 'pot-creation-date': |
|
0 commit comments