diff options
| author | bwarsaw | 2000-08-22 15:09:44 +0000 |
|---|---|---|
| committer | bwarsaw | 2000-08-22 15:09:44 +0000 |
| commit | cec951c30777745f007dae4f619a6431b343307f (patch) | |
| tree | 5104b09f277ad82b268030f31a725647917ec1d6 /Mailman/Utils.py | |
| parent | 588e5a108e8ca269b697f60f603a1658c1804696 (diff) | |
| download | mailman-cec951c30777745f007dae4f619a6431b343307f.tar.gz mailman-cec951c30777745f007dae4f619a6431b343307f.tar.zst mailman-cec951c30777745f007dae4f619a6431b343307f.zip | |
Diffstat (limited to 'Mailman/Utils.py')
| -rw-r--r-- | Mailman/Utils.py | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py index 321609293..faa1d7b62 100644 --- a/Mailman/Utils.py +++ b/Mailman/Utils.py @@ -624,25 +624,32 @@ def reap(kids, func=None): # Useful conversion routines # unhexlify(hexlify(s)) == s -def hexlify(s): - acc = [] - def munge(byte, append=acc.append, a=ord('a'), z=ord('0')): - if byte > 9: append(byte+a-10) - else: append(byte+z) - for c in s: - hi, lo = divmod(ord(c), 16) - munge(hi) - munge(lo) - return string.join(map(chr, acc), '') +# +# Python 2.0 has these in the binascii module +try: + from binascii import hexlify, unhexlify +except ImportError: + # Not the most efficient of implementations, but good enough for older + # versions of Python. + def hexlify(s): + acc = [] + def munge(byte, append=acc.append, a=ord('a'), z=ord('0')): + if byte > 9: append(byte+a-10) + else: append(byte+z) + for c in s: + hi, lo = divmod(ord(c), 16) + munge(hi) + munge(lo) + return string.join(map(chr, acc), '') -def unhexlify(s): - acc = [] - append = acc.append - # In Python 2.0, we can use the int() built-in - int16 = string.atoi - for i in range(0, len(s), 2): - append(chr(int16(s[i:i+2], 16))) - return string.join(acc, '') + def unhexlify(s): + acc = [] + append = acc.append + # In Python 2.0, we can use the int() built-in + int16 = string.atoi + for i in range(0, len(s), 2): + append(chr(int16(s[i:i+2], 16))) + return string.join(acc, '') |
