Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
00c9b430
Commit
00c9b430
authored
May 09, 2007
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Random modifications that slightly improve the chances of this not blowing up.
Walter will fix it for real.
parent
2c38013e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
Lib/encodings/idna.py
Lib/encodings/idna.py
+10
-11
No files found.
Lib/encodings/idna.py
View file @
00c9b430
...
@@ -87,7 +87,7 @@ def ToASCII(label):
...
@@ -87,7 +87,7 @@ def ToASCII(label):
raise
UnicodeError
(
"label empty or too long"
)
raise
UnicodeError
(
"label empty or too long"
)
# Step 5: Check ACE prefix
# Step 5: Check ACE prefix
if
label
.
startswith
(
u
ace_prefix
):
if
label
.
startswith
(
ace_prefix
):
raise
UnicodeError
(
"Label starts with ACE prefix"
)
raise
UnicodeError
(
"Label starts with ACE prefix"
)
# Step 6: Encode with PUNYCODE
# Step 6: Encode with PUNYCODE
...
@@ -103,7 +103,7 @@ def ToASCII(label):
...
@@ -103,7 +103,7 @@ def ToASCII(label):
def
ToUnicode
(
label
):
def
ToUnicode
(
label
):
# Step 1: Check for ASCII
# Step 1: Check for ASCII
if
isinstance
(
label
,
str
):
if
isinstance
(
label
,
bytes
):
pure_ascii
=
True
pure_ascii
=
True
else
:
else
:
try
:
try
:
...
@@ -150,19 +150,19 @@ class Codec(codecs.Codec):
...
@@ -150,19 +150,19 @@ class Codec(codecs.Codec):
raise
UnicodeError
(
"unsupported error handling "
+
errors
)
raise
UnicodeError
(
"unsupported error handling "
+
errors
)
if
not
input
:
if
not
input
:
return
""
,
0
return
b
""
,
0
result
=
[]
result
=
[]
labels
=
dots
.
split
(
input
)
labels
=
dots
.
split
(
input
)
if
labels
and
len
(
labels
[
-
1
])
==
0
:
if
labels
and
len
(
labels
[
-
1
])
==
0
:
trailing_dot
=
'.'
trailing_dot
=
b
'.'
del
labels
[
-
1
]
del
labels
[
-
1
]
else
:
else
:
trailing_dot
=
''
trailing_dot
=
b
''
for
label
in
labels
:
for
label
in
labels
:
result
.
append
(
ToASCII
(
label
))
result
.
append
(
ToASCII
(
label
))
# Join with U+002E
# Join with U+002E
return
"."
.
join
(
result
)
+
trailing_dot
,
len
(
input
)
return
b
"."
.
join
(
result
)
+
trailing_dot
,
len
(
input
)
def
decode
(
self
,
input
,
errors
=
'strict'
):
def
decode
(
self
,
input
,
errors
=
'strict'
):
...
@@ -173,13 +173,12 @@ class Codec(codecs.Codec):
...
@@ -173,13 +173,12 @@ class Codec(codecs.Codec):
return
""
,
0
return
""
,
0
# IDNA allows decoding to operate on Unicode strings, too.
# IDNA allows decoding to operate on Unicode strings, too.
if
isinstance
(
input
,
str
):
if
isinstance
(
input
,
bytes
):
labels
=
dots
.
split
(
input
)
labels
=
dots
.
split
(
input
)
else
:
else
:
# Must be ASCII string
# Force to bytes
input
=
str
(
input
)
input
=
bytes
(
input
)
str
(
input
,
"ascii"
)
labels
=
input
.
split
(
b"."
)
labels
=
input
.
split
(
"."
)
if
labels
and
len
(
labels
[
-
1
])
==
0
:
if
labels
and
len
(
labels
[
-
1
])
==
0
:
trailing_dot
=
'.'
trailing_dot
=
'.'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment