diff options
author | Bob Halley <halley@play-bow.org> | 2014-06-19 05:32:27 -0700 |
---|---|---|
committer | Bob Halley <halley@play-bow.org> | 2014-06-19 05:32:27 -0700 |
commit | 46580d815ac1ae8677e3fbc01d48d0f5351ae2d3 (patch) | |
tree | 5a085c7a7977088597eb11aaad6aea46c4169c1f | |
parent | 21cda943823c64d970cac3bbe8ae80e0859fe89f (diff) | |
parent | 42a85bfb058e6d59b7674651c6fba3aebd8a3481 (diff) | |
download | dnspython-46580d815ac1ae8677e3fbc01d48d0f5351ae2d3.tar.gz |
Merge pull request #67 from bastiak/master
IDNA encoding/decoding issue fix
-rw-r--r-- | dns/name.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/dns/name.py b/dns/name.py index 5f8f213..0d9b4f2 100644 --- a/dns/name.py +++ b/dns/name.py @@ -88,8 +88,10 @@ _escaped = { '$' : True } -def _escapify(label): +def _escapify(label, whitespaces_only=False): """Escape the characters in label which need it. + @param whitespaces_only: escapify only special and whitespace (ord < 0x20) + characters @returns: the escaped string @rtype: string""" text = '' @@ -99,7 +101,10 @@ def _escapify(label): elif ord(c) > 0x20 and ord(c) < 0x7F: text += c else: - text += '\\%03d' % ord(c) + if whitespaces_only and ord(c) >= 0x7F: + text += c + else: + text += '\\%03d' % ord(c) return text def _validate_labels(labels): @@ -352,7 +357,7 @@ class Name(object): l = self.labels[:-1] else: l = self.labels - s = u'.'.join([encodings.idna.ToUnicode(_escapify(x)) for x in l]) + s = u'.'.join([_escapify(encodings.idna.ToUnicode(x), whitespaces_only=True) for x in l]) return s def to_digestable(self, origin=None): |