_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 = ''
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):
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):