From d50ff5582240c7c9b4ca78c271e3e5cf927c1690 Mon Sep 17 00:00:00 2001 From: Padraic Fanning Date: Thu, 2 Sep 2021 21:27:45 -0400 Subject: [PATCH] Update encodings module to CPython 3.8 --- Lib/encodings/__init__.py | 7 +++---- Lib/encodings/aliases.py | 3 +++ Lib/encodings/punycode.py | 2 +- Lib/encodings/uu_codec.py | 4 ++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index 86c282de5..ddd5afdcf 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -12,7 +12,7 @@ * getregentry() -> codecs.CodecInfo object The getregentry() API must return a CodecInfo object with encoder, decoder, incrementalencoder, incrementaldecoder, streamwriter and streamreader - atttributes which adhere to the Python Codec Interface Standard. + attributes which adhere to the Python Codec Interface Standard. In addition, a module may optionally also define the following APIs which are then used by the package's codec search function: @@ -49,8 +49,7 @@ def normalize_encoding(encoding): collapsed and replaced with a single underscore, e.g. ' -;#' becomes '_'. Leading and trailing underscores are removed. - Note that encoding names should be ASCII only; if they do use - non-ASCII characters, these must be Latin-1 compatible. + Note that encoding names should be ASCII only. """ if isinstance(encoding, bytes): @@ -58,7 +57,7 @@ def normalize_encoding(encoding): chars = [] punct = False - for c in encoding.lower(): + for c in encoding: if c.isalnum() or c == '.': if punct and chars: chars.append('_') diff --git a/Lib/encodings/aliases.py b/Lib/encodings/aliases.py index 2e63c2f94..2444f9f17 100644 --- a/Lib/encodings/aliases.py +++ b/Lib/encodings/aliases.py @@ -266,6 +266,8 @@ aliases = { 'roman8' : 'hp_roman8', 'r8' : 'hp_roman8', 'csHPRoman8' : 'hp_roman8', + 'cp1051' : 'hp_roman8', + 'ibm1051' : 'hp_roman8', # hz codec 'hzgb' : 'hz', @@ -534,6 +536,7 @@ aliases = { 'utf8' : 'utf_8', 'utf8_ucs2' : 'utf_8', 'utf8_ucs4' : 'utf_8', + 'cp65001' : 'utf_8', # uu_codec codec 'uu' : 'uu_codec', diff --git a/Lib/encodings/punycode.py b/Lib/encodings/punycode.py index 66c51013e..1c5726447 100644 --- a/Lib/encodings/punycode.py +++ b/Lib/encodings/punycode.py @@ -143,7 +143,7 @@ def decode_generalized_number(extended, extpos, bias, errors): digit = char - 22 # 0x30-26 elif errors == "strict": raise UnicodeError("Invalid extended code point '%s'" - % extended[extpos]) + % extended[extpos-1]) else: return extpos, None t = T(j, bias) diff --git a/Lib/encodings/uu_codec.py b/Lib/encodings/uu_codec.py index 2a5728fb5..4e58c62fe 100644 --- a/Lib/encodings/uu_codec.py +++ b/Lib/encodings/uu_codec.py @@ -20,6 +20,10 @@ def uu_encode(input, errors='strict', filename='', mode=0o666): read = infile.read write = outfile.write + # Remove newline chars from filename + filename = filename.replace('\n','\\n') + filename = filename.replace('\r','\\r') + # Encode write(('begin %o %s\n' % (mode & 0o777, filename)).encode('ascii')) chunk = read(45)