summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2000-07-19 20:20:39 +0000
committerbwarsaw2000-07-19 20:20:39 +0000
commit5343ffc83e330cbcb9543261bfd4634e82c4a24d (patch)
treee2576a062ff343c7511e6af71dcba2826bc16d86
parentb74063ace7b5bd6c1ad7d3a982977d902f1f2ead (diff)
downloadmailman-5343ffc83e330cbcb9543261bfd4634e82c4a24d.tar.gz
mailman-5343ffc83e330cbcb9543261bfd4634e82c4a24d.tar.zst
mailman-5343ffc83e330cbcb9543261bfd4634e82c4a24d.zip
-rw-r--r--Mailman/Utils.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index 4c52042b0..8c7314b5c 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -609,3 +609,23 @@ def reap(kids, func=None):
except KeyError:
# Huh? How can this happen?
pass
+
+
+# Useful conversion routines
+# unhexlify(hexlify(s)) == s
+def hexlify(s):
+ acc = []
+ def munge(byte, acc=acc, a=ord('a'), z=ord('0')):
+ if byte > 9: acc.append(byte+a-10)
+ else: acc.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 = []
+ for i in range(0, len(s), 2):
+ acc.append(chr(int(s[i], 16)*16 + int(s[i+1], 16)))
+ return string.join(acc, '')