summaryrefslogtreecommitdiff
path: root/wsgitools
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2009-03-29 17:39:10 +0200
committerHelmut Grohne <helmut@subdivi.de>2009-03-29 17:39:10 +0200
commitac99754f5e68f3731b7bdd7c8070c58346983bf4 (patch)
tree1d69a47a325c06297c06dc4170254646ed28db3f /wsgitools
parent894ad7b53b22e8aa1ec8b4d6806b86c35e674086 (diff)
downloadwsgitools-ac99754f5e68f3731b7bdd7c8070c58346983bf4.tar.gz
make digest.gen_rand_str forward compatible (py3)
Diffstat (limited to 'wsgitools')
-rwxr-xr-xwsgitools/digest.py10
1 files 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