diff options
| author | Bob Halley <halley@dnspython.org> | 2014-08-31 16:26:59 -0700 |
|---|---|---|
| committer | Bob Halley <halley@dnspython.org> | 2014-08-31 16:26:59 -0700 |
| commit | ab853d428c547fb736950491e05667d388a04fab (patch) | |
| tree | 75ed2504c82dc06c6d6dd9b212d14bd33340b659 | |
| parent | 7b6ebf77c3ace2bc502a2b142a28a0c2540deece (diff) | |
| download | dnspython-ab853d428c547fb736950491e05667d388a04fab.tar.gz | |
Pull up 42a85bfb058e6d59b7674651c6fba3aebd8a3481 from dnspython.
| -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 2948998..f556287 100644 --- a/dns/name.py +++ b/dns/name.py @@ -82,8 +82,10 @@ class LabelMixesUnicodeAndASCII(dns.exception.SyntaxError): _escaped = frozenset([ord(c) for c in '"().;\\@$']) -def _escapify(label): +def _escapify(label, unicode_mode=False): """Escape the characters in label which need it. + @param unicode_mode: escapify only special and whitespace (<= 0x20) + characters @returns: the escaped string @rtype: string""" text = '' @@ -93,7 +95,10 @@ def _escapify(label): elif c > 0x20 and c < 0x7F: text += chr(c) else: - text += '\\%03d' % c + if unicode_mode and c >= 0x7F: + text += chr(c) + else: + text += '\\%03d' % c return text def _bytesify(label): @@ -360,7 +365,7 @@ class Name(object): l = self.labels[:-1] else: l = self.labels - s = '.'.join([encodings.idna.ToUnicode(_escapify(x)) for x in l]) + s = '.'.join([_escapify(encodings.idna.ToUnicode(x), True) for x in l]) return s def to_digestable(self, origin=None): |
