8000 Update encodings from CPyhton 3.12.2 · RustPython/RustPython@9f65a30 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f65a30

Browse files
CPython Developersyouknowone
CPython Developers
authored andcommitted
Update encodings from CPyhton 3.12.2
1 parent b018123 commit 9f65a30

File tree

5 files changed

+29
-412
lines changed

5 files changed

+29
-412
lines changed

Lib/encodings/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def search_function(encoding):
156156
codecs.register(search_function)
157157

158158
if sys.platform == 'win32':
159+
# bpo-671666, bpo-46668: If Python does not implement a codec for current
160+
# Windows ANSI code page, use the "mbcs" codec instead:
161+
# WideCharToMultiByte() and MultiByteToWideChar() functions with CP_ACP.
162+
# Python does not support custom code pages.
159163
def _alias_mbcs(encoding):
160164
try:
161165
import _winapi

Lib/encodings/cp65001.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

Lib/encodings/idna.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,21 @@ def nameprep(label):
3939

4040
# Check bidi
4141
RandAL = [stringprep.in_table_d1(x) for x in label]
42-
for c in RandAL:
43-
if c:
44-
# There is a RandAL char in the string. Must perform further
45-
# tests:
46-
# 1) The characters in section 5.8 MUST be prohibited.
47-
# This is table C.8, which was already checked
48-
# 2) If a string contains any RandALCat character, the string
49-
# MUST NOT contain any LCat character.
50-
if any(stringprep.in_table_d2(x) for x in label):
51-
raise UnicodeError("Violation of BIDI requirement 2")
52-
53-
# 3) If a string contains any RandALCat character, a
54-
# RandALCat character MUST be the first character of the
55-
# string, and a RandALCat character MUST be the last
56-
# character of the string.
57-
if not RandAL[0] or not RandAL[-1]:
58-
raise UnicodeError("Violation of BIDI requirement 3")
42+
if any(RandAL):
43+
# There is a RandAL char in the string. Must perform further
44+
# tests:
45+
# 1) The characters in section 5.8 MUST be prohibited.
46+
# This is table C.8, which was already checked
47+
# 2) If a string contains any RandALCat character, the string
48+
# MUST NOT contain any LCat character.
49+
if any(stringprep.in_table_d2(x) for x in label):
50+
raise UnicodeError("Violation of BIDI requirement 2")
51+
# 3) If a string contains any RandALCat character, a
52+
# RandALCat character MUST be the first character of the
53+
# string, and a RandALCat character MUST be the last
54+
# character of the string.
55+
if not RandAL[0] or not RandAL[-1]:
56+
raise UnicodeError("Violation of BIDI requirement 3")
5957

6058
return label
6159

@@ -103,6 +101,16 @@ def ToASCII(label):
103101
raise UnicodeError("label empty or too long")
104102

105103
def ToUnicode(label):
104+
if len(label) > 1024:
105+
# Protection from https://github.com/python/cpython/issues/98433.
106+
# https://datatracker.ietf.org/doc/html/rfc5894#section-6
107+
# doesn't specify a label size limit prior to NAMEPREP. But having
108+
# one makes practical sense.
109+
# This leaves ample room for nameprep() to remove Nothing characters
110+
# per https://www.rfc-editor.org/rfc/rfc3454#section-3.1 while still
111+
# preventing us from wasting time decoding a big thing that'll just
112+
# hit the actual <= 63 length limit in Step 6.
113+
raise UnicodeError("label way too long")
106114
# Step 1: Check for ASCII
107115
if isinstance(label, bytes):
108116
pure_ascii = True

0 commit comments

Comments
 (0)
0