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
5defef12
Commit
5defef12
authored
Aug 05, 2003
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
parent
a42f8903
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
Lib/encodings/idna.py
Lib/encodings/idna.py
+15
-3
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+4
-0
No files found.
Lib/encodings/idna.py
View file @
5defef12
...
...
@@ -150,10 +150,16 @@ class Codec(codecs.Codec):
raise
UnicodeError
,
"unsupported error handling "
+
errors
result
=
[]
for
label
in
dots
.
split
(
input
):
labels
=
dots
.
split
(
input
)
if
labels
and
len
(
labels
[
-
1
])
==
0
:
trailing_dot
=
'.'
del
labels
[
-
1
]
else
:
trailing_dot
=
''
for
label
in
labels
:
result
.
append
(
ToASCII
(
label
))
# Join with U+002E
return
"."
.
join
(
result
),
len
(
input
)
return
"."
.
join
(
result
)
+
trailing_dot
,
len
(
input
)
def
decode
(
self
,
input
,
errors
=
'strict'
):
...
...
@@ -168,11 +174,17 @@ class Codec(codecs.Codec):
unicode
(
input
,
"ascii"
)
labels
=
input
.
split
(
"."
)
if
labels
and
len
(
labels
[
-
1
])
==
0
:
trailing_dot
=
u'.'
del
labels
[
-
1
]
else
:
trailing_dot
=
u''
result
=
[]
for
label
in
labels
:
result
.
append
(
ToUnicode
(
label
))
return
u"."
.
join
(
result
),
len
(
input
)
return
u"."
.
join
(
result
)
+
trailing_dot
,
len
(
input
)
class
StreamWriter
(
Codec
,
codecs
.
StreamWriter
):
pass
...
...
Lib/test/test_unicode.py
View file @
5defef12
...
...
@@ -524,6 +524,10 @@ class UnicodeTest(
# * strict decoding testing for all of the
# UTF8_ERROR cases in PyUnicode_DecodeUTF8
def test_codecs_idna(self):
# Test whether trailing dot is preserved
self.assertEqual(u"www.python.org.".encode("idna"), "www.python.org.")
def test_codecs_errors(self):
# Error handling (encoding)
self.assertRaises(UnicodeError, u'
Andr
\
202
x
'.encode, '
ascii
')
...
...
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