manually adapt few imports

This commit is contained in:
ilvalle
2016-06-01 20:16:30 +02:00
parent aa2bf4134e
commit 01bab81432
28 changed files with 174 additions and 189 deletions
+8 -14
View File
@@ -23,17 +23,11 @@ import logging
import socket
import base64
import zlib
from gluon._compat import basestring, pickle, PY2, xrange, to_bytes
_struct_2_long_long = struct.Struct('=QQ')
python_version = sys.version_info[0]
if python_version == 2:
import cPickle as pickle
else:
import pickle
import hashlib
import hashlib, binascii
from hashlib import md5, sha1, sha224, sha256, sha384, sha512
try:
@@ -46,9 +40,9 @@ import hmac
if hasattr(hashlib, "pbkdf2_hmac"):
def pbkdf2_hex(data, salt, iterations=1000, keylen=24, hashfunc=None):
hashfunc = hashfunc or sha1
return hashlib.pbkdf2_hmac(hashfunc().name,
data, salt, iterations,
keylen).encode("hex")
hmac = hashlib.pbkdf2_hmac(hashfunc().name, to_bytes(data),
to_bytes(salt), iterations, keylen)
return binascii.hexlify(hmac)
HAVE_PBKDF2 = True
else:
try:
@@ -85,7 +79,7 @@ def compare(a, b):
return hmac.compare_digest(a, b)
result = len(a) ^ len(b)
for i in xrange(len(b)):
result |= ord(a[i%len(a)]) ^ ord(b[i])
result |= ord(a[i%len(a)]) ^ ord(b[i])
return result == 0
@@ -227,7 +221,7 @@ def initialize_urandom():
# try to add process-specific entropy
frandom = open('/dev/urandom', 'wb')
try:
if python_version == 2:
if PY2:
frandom.write(''.join(chr(t) for t in ctokens)) # python 2
else:
frandom.write(bytes([]).join(bytes([t]) for t in ctokens)) # python 3
@@ -242,7 +236,7 @@ def initialize_urandom():
"""Cryptographically secure session management is not possible on your system because
your system does not provide a cryptographically secure entropy source.
This is not specific to web2py; consider deploying on a different operating system.""")
if python_version == 2:
if PY2:
packed = ''.join(chr(x) for x in ctokens) # python 2
else:
packed = bytes([]).join(bytes([x]) for x in ctokens) # python 3