Fix parsing of .po files on python2

This commit is contained in:
Kovid Goyal 2020-02-06 12:14:13 +05:30
parent e94361e527
commit cea9c6cb93
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -166,7 +166,12 @@ def make(filename, outfile):
if not msgid:
# See whether there is an encoding declaration
p = HeaderParser()
charset = p.parsestr(msgstr.decode(encoding)).get_content_charset()
if sys.version_info.major > 2:
charset = p.parsestr(msgstr.decode(encoding)).get_content_charset()
else:
charset = p.parsestr(msgstr.decode(encoding).encode('ascii', 'replace')).get_content_charset()
if isinstance(charset, bytes):
charset = charset.decode('ascii')
if charset:
encoding = charset
section = ID