summaryrefslogtreecommitdiffstats
path: root/Lib/encodings
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2003-08-05 06:19:47 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2003-08-05 06:19:47 (GMT)
commit0d8e16c7adb3ac57d74e86bcf2311215ced1d034 (patch)
tree646731f6130f1a23144fae61e3c5d5469df1511a /Lib/encodings
parent8db4403a768b711bbda1857ab4f38ed4be726e4b (diff)
downloadcpython-0d8e16c7adb3ac57d74e86bcf2311215ced1d034.zip
cpython-0d8e16c7adb3ac57d74e86bcf2311215ced1d034.tar.gz
cpython-0d8e16c7adb3ac57d74e86bcf2311215ced1d034.tar.bz2
Support trailing dots in DNS names. Fixes #782510. Will backport to 2.3.
Diffstat (limited to 'Lib/encodings')
-rw-r--r--Lib/encodings/idna.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/encodings/idna.py b/Lib/encodings/idna.py
index 62aa450..37462db 100644
--- a/Lib/encodings/idna.py
+++ b/Lib/encodings/idna.py
@@ -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