From ac99754f5e68f3731b7bdd7c8070c58346983bf4 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 29 Mar 2009 17:39:10 +0200 Subject: make digest.gen_rand_str forward compatible (py3) --- wsgitools/digest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wsgitools/digest.py b/wsgitools/digest.py index c666460..d99f67d 100755 --- a/wsgitools/digest.py +++ b/wsgitools/digest.py @@ -7,14 +7,18 @@ try: from hashlib import md5 except ImportError: from md5 import md5 - +import binascii +import base64 import time sysrand = random.SystemRandom() def gen_rand_str(bytes=33): - return (("%%0%dX" % (2*bytes)) % sysrand.getrandbits(bytes*8) - ).decode("hex").encode("base64").strip() + randnum = sysrand.getrandbits(bytes*8) + randstr = ("%%0%dX" % (2*bytes)) % randnum + randstr = binascii.unhexlify(randstr) + randstr = base64.encodestring(randstr).strip() + return randstr def parse_digest_response(data, ret=dict()): """internal -- cgit v1.2.3