From: Mike Frysinger Date: Tue, 29 Sep 2015 00:37:37 +0000 (-0400) Subject: app-misc/ca-certificates: rework py3 patch a bit more #561586 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=751d0f79973aa5c2918b386e814aa3eda17df27b;p=gentoo.git app-misc/ca-certificates: rework py3 patch a bit more #561586 Rework some of the codec logic to make sure we can read files when in a non-UTF8 locale (like LANG=C), and it works w/py2.7 and py3.4. --- diff --git a/app-misc/ca-certificates/files/ca-certificates-20150426-nss-certdata2pem-py3.patch b/app-misc/ca-certificates/files/ca-certificates-20150426-nss-certdata2pem-py3.patch index 300ce479b227..d639aefb4c09 100644 --- a/app-misc/ca-certificates/files/ca-certificates-20150426-nss-certdata2pem-py3.patch +++ b/app-misc/ca-certificates/files/ca-certificates-20150426-nss-certdata2pem-py3.patch @@ -3,6 +3,19 @@ https://bugs.gentoo.org/548374 --- a/ca-certificates/mozilla/certdata2pem.py +++ b/ca-certificates/mozilla/certdata2pem.py +@@ -31,7 +31,11 @@ objects = [] + # Dirty file parser. + in_data, in_multiline, in_obj = False, False, False + field, type, value, obj = None, None, None, dict() +-for line in open('certdata.txt', 'r'): ++try: ++ f = open('certdata.txt', 'r', encoding='utf-8') ++except TypeError: ++ f = open('certdata.txt', 'r') ++for line in f: + # Ignore the file header. + if not in_data: + if line.startswith('BEGINDATA'): @@ -53,7 +53,7 @@ for line in open('certdata.txt', 'r'): if type == 'MULTILINE_OCTAL': line = line.strip() @@ -62,17 +75,19 @@ https://bugs.gentoo.org/548374 .replace(')', '=')\ .replace(',', '_') - bname = bname.decode('string_escape') +- fname = bname + '.crt' + + # this is the only way to decode the way NSS stores multi-byte UTF-8 + if bytes != str: + bname = bname.encode('utf-8') + bname = bname.decode('unicode_escape').encode('latin-1').decode('utf-8') - fname = bname + '.crt' ++ fname = (bname + '.crt').encode('utf-8') + if os.path.exists(fname): - print "Found duplicate certificate name %s, renaming." % bname -+ print("Found duplicate certificate name %s, renaming." % bname) - fname = bname + '_2.crt' +- fname = bname + '_2.crt' ++ print("Found duplicate certificate name %s, renaming." % fname) ++ fname = (bname + '_2.crt').encode('utf-8') f = open(fname, 'w') f.write("-----BEGIN CERTIFICATE-----\n") - f.write("\n".join(textwrap.wrap(base64.b64encode(obj['CKA_VALUE']), 64)))