Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f36af7

Browse files
committed
Normalize the encoding names for Latin-1 and UTF-8 to
'latin-1' and 'utf-8'. These are optimized in the Python Unicode implementation to result in more direct processing, bypassing the codec registry. Also see issue11303.
1 parent a391b11 commit 8f36af7

32 files changed

Lines changed: 84 additions & 79 deletions

Lib/asynchat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class async_chat (asyncore.dispatcher):
7575
# sign of an application bug that we don't want to pass silently
7676

7777
use_encoding = 0
78-
encoding = 'latin1'
78+
encoding = 'latin-1'
7979

8080
def __init__ (self, sock=None, map=None):
8181
# for string terminator matching

Lib/distutils/command/bdist_wininst.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ def create_exe(self, arcname, fullname, bitmap=None):
263263
cfgdata = cfgdata + b"\0"
264264
if self.pre_install_script:
265265
# We need to normalize newlines, so we open in text mode and
266-
# convert back to bytes. "latin1" simply avoids any possible
266+
# convert back to bytes. "latin-1" simply avoids any possible
267267
# failures.
268268
with open(self.pre_install_script, "r",
269-
encoding="latin1") as script:
270-
script_data = script.read().encode("latin1")
269+
encoding="latin-1") as script:
270+
script_data = script.read().encode("latin-1")
271271
cfgdata = cfgdata + script_data + b"\n\0"
272272
else:
273273
# empty pre-install script

Lib/ftplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class FTP:
100100
file = None
101101
welcome = None
102102
passiveserver = 1
103-
encoding = "latin1"
103+
encoding = "latin-1"
104104

105105
# Initialization method (called by class instantiation).
106106
# Initialize host to localhost, port to standard ftp port

Lib/http/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def _tunnel(self):
697697
self.send(connect_bytes)
698698
for header, value in self._tunnel_headers.items():
699699
header_str = "%s: %s\r\n" % (header, value)
700-
header_bytes = header_str.encode("latin1")
700+
header_bytes = header_str.encode("latin-1")
701701
self.send(header_bytes)
702702
self.send(b'\r\n')
703703

@@ -937,7 +937,7 @@ def putheader(self, header, *values):
937937
values = list(values)
938938
for i, one_value in enumerate(values):
939939
if hasattr(one_value, 'encode'):
940-
values[i] = one_value.encode('latin1')
940+
values[i] = one_value.encode('latin-1')
941941
elif isinstance(one_value, int):
942942
values[i] = str(one_value).encode('ascii')
943943
value = b'\r\n\t'.join(values)

Lib/http/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ def send_response_only(self, code, message=None):
448448
message = ''
449449
if self.request_version != 'HTTP/0.9':
450450
self.wfile.write(("%s %d %s\r\n" %
451-
(self.protocol_version, code, message)).encode('latin1', 'strict'))
451+
(self.protocol_version, code, message)).encode('latin-1', 'strict'))
452452

453453
def send_header(self, keyword, value):
454454
"""Send a MIME header."""
455455
if self.request_version != 'HTTP/0.9':
456456
if not hasattr(self, '_headers_buffer'):
457457
self._headers_buffer = []
458458
self._headers_buffer.append(
459-
("%s: %s\r\n" % (keyword, value)).encode('latin1', 'strict'))
459+
("%s: %s\r\n" % (keyword, value)).encode('latin-1', 'strict'))
460460

461461
if keyword.lower() == 'connection':
462462
if value.lower() == 'close':

Lib/multiprocessing/connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ def recv(self):
434434
return self._loads(s)
435435

436436
def _xml_dumps(obj):
437-
return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf8')
437+
return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf-8')
438438

439439
def _xml_loads(s):
440-
(obj,), method = xmlrpclib.loads(s.decode('utf8'))
440+
(obj,), method = xmlrpclib.loads(s.decode('utf-8'))
441441
return obj
442442

443443
class XmlListener(Listener):

Lib/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def seed(self, a=None, version=2):
114114
if version == 2:
115115
if isinstance(a, (str, bytes, bytearray)):
116116
if isinstance(a, str):
117-
a = a.encode("utf8")
117+
a = a.encode("utf-8")
118118
a += _sha512(a).digest()
119119
a = int.from_bytes(a, 'big')
120120

Lib/smtpd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def collect_incoming_data(self, data):
275275
return
276276
elif limit:
277277
self.num_bytes += len(data)
278-
self.received_lines.append(str(data, "utf8"))
278+
self.received_lines.append(str(data, "utf-8"))
279279

280280
# Implementation of base class abstract method
281281
def found_terminator(self):

Lib/sqlite3/test/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(self, _val):
8585
if isinstance(_val, bytes):
8686
# sqlite3 always calls __init__ with a bytes created from a
8787
# UTF-8 string when __conform__ was used to store the object.
88-
_val = _val.decode('utf8')
88+
_val = _val.decode('utf-8')
8989
self.val = _val
9090

9191
def __cmp__(self, other):

Lib/sre_parse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ def literal(literal, p=p, pappend=a):
791791
else:
792792
# The tokenizer implicitly decodes bytes objects as latin-1, we must
793793
# therefore re-encode the final representation.
794-
encode = lambda x: x.encode('latin1')
794+
encode = lambda x: x.encode('latin-1')
795795
for c, s in p:
796796
if c is MARK:
797797
groupsappend((i, s))

0 commit comments

Comments
 (0)