summaryrefslogtreecommitdiffstats
path: root/Lib/encodings/punycode.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-11 10:32:57 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-11 10:32:57 (GMT)
commit0ac30f82fe1beb4e0255d06c693ccfba56e45a9f (patch)
tree1795d671685687ef172c7f4d57290292cdf06879 /Lib/encodings/punycode.py
parent1f05a3b7fb754d6b30300e1e50aeb92aabe6afd6 (diff)
downloadcpython-0ac30f82fe1beb4e0255d06c693ccfba56e45a9f.zip
cpython-0ac30f82fe1beb4e0255d06c693ccfba56e45a9f.tar.gz
cpython-0ac30f82fe1beb4e0255d06c693ccfba56e45a9f.tar.bz2
Enhance the punycode decoder so that it can decode
unicode objects. Fix the idna codec and the tests.
Diffstat (limited to 'Lib/encodings/punycode.py')
-rw-r--r--Lib/encodings/punycode.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/encodings/punycode.py b/Lib/encodings/punycode.py
index 9d7df10..4c22fe5 100644
--- a/Lib/encodings/punycode.py
+++ b/Lib/encodings/punycode.py
@@ -181,6 +181,8 @@ def insertion_sort(base, extended, errors):
return base
def punycode_decode(text, errors):
+ if isinstance(text, str):
+ text = text.encode("ascii")
pos = text.rfind(b"-")
if pos == -1:
base = ""
@@ -194,11 +196,11 @@ def punycode_decode(text, errors):
class Codec(codecs.Codec):
- def encode(self,input,errors='strict'):
+ def encode(self, input, errors='strict'):
res = punycode_encode(input)
return res, len(input)
- def decode(self,input,errors='strict'):
+ def decode(self, input, errors='strict'):
if errors not in ('strict', 'replace', 'ignore'):
raise UnicodeError, "Unsupported error handling "+errors
res = punycode_decode(input, errors)