[Mailman-Developers] cookies
Barry A. Warsaw
bwarsaw@beopen.com
Thu, 20 Jul 2000 08:48:50 -0400 (EDT)
>>>>> "DM" == Dan Mick <Dan.Mick@west.sun.com> writes:
DM> OK, I'm probably missing something again, but this looks
DM> completely broken to me. unhexlify is using int(c, 16), but
DM> there is no such 2-argument int that I can find in Python
DM> 1.5.2.
DM> Barry, the following patch made cookies work again, but they
DM> were utterly broken before this patch, and I don't understand
DM> how you could have thought they were not...so is there a
DM> 2-argument int() in some unreleased Python or something?...
Ack! Yup, the next version of Python will have an int() that accepts
two arguments. In fact, the entire string module will be largely
unnecessary (string objects have methods). Try this patch, which
should also be moderately faster.
Thanks,
-Barry
-------------------- snip snip --------------------
Index: Utils.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Utils.py,v
retrieving revision 1.93
diff -u -r1.93 Utils.py
--- Utils.py 2000/07/19 20:20:39 1.93
+++ Utils.py 2000/07/20 12:47:03
@@ -615,9 +615,9 @@
# 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)
+ 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)
@@ -626,6 +626,9 @@
def unhexlify(s):
acc = []
+ append = acc.append
+ # In Python 2.0, we can use the int() built-in
+ int16 = string.atol
for i in range(0, len(s), 2):
- acc.append(chr(int(s[i], 16)*16 + int(s[i+1], 16)))
+ append(chr(int16(s[i], 16)*16 + int16(s[i+1], 16)))
return string.join(acc, '')