discovered and use _compat to_bytes and to_native functions

This commit is contained in:
Radu Ioan Fericean
2018-04-14 14:58:53 +03:00
parent 086bfb5851
commit 0900a3ddb9
3 changed files with 13 additions and 17 deletions
+2 -3
View File
@@ -13,6 +13,7 @@ from gluon import current
from gluon.storage import Storage from gluon.storage import Storage
from gluon.contrib.redis_utils import acquire_lock, release_lock from gluon.contrib.redis_utils import acquire_lock, release_lock
from gluon.contrib.redis_utils import register_release_lock from gluon.contrib.redis_utils import register_release_lock
from gluon._compat import to_bytes
logger = logging.getLogger("web2py.session.redis") logger = logging.getLogger("web2py.session.redis")
@@ -185,9 +186,7 @@ class MockQuery(object):
if rtn: if rtn:
if self.unique_key: if self.unique_key:
# make sure the id and unique_key are correct # make sure the id and unique_key are correct
if not isinstance(self.unique_key, bytes): if rtn[b'unique_key'] == to_bytes(self.unique_key):
self.unique_key = bytes(self.unique_key, 'utf8')
if rtn[b'unique_key'] == self.unique_key:
rtn[b'update_record'] = self.update # update record support rtn[b'update_record'] = self.update # update record support
else: else:
rtn = None rtn = None
+3 -5
View File
@@ -14,7 +14,7 @@ Contains the classes for the global used variables:
""" """
from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, \ from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, \
unicodeT, long, hashlib_md5, urllib_quote to_bytes, unicodeT, long, hashlib_md5, urllib_quote
from gluon.storage import Storage, List from gluon.storage import Storage, List
from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
from gluon.contenttype import contenttype from gluon.contenttype import contenttype
@@ -1049,9 +1049,7 @@ class Session(Storage):
if record_id.isdigit() and long(record_id) > 0: if record_id.isdigit() and long(record_id) > 0:
new_unique_key = web2py_uuid() new_unique_key = web2py_uuid()
row = table(record_id) row = table(record_id)
if not isinstance(unique_key, bytes): if row and row[b'unique_key'] == to_bytes(unique_key):
unique_key = bytes(unique_key, 'utf8')
if row and row[b'unique_key'] == unique_key:
table._db(table.id == record_id).update(unique_key=new_unique_key) table._db(table.id == record_id).update(unique_key=new_unique_key)
else: else:
record_id = None record_id = None
@@ -1169,7 +1167,7 @@ class Session(Storage):
compression_level=compression_level) compression_level=compression_level)
rcookies = response.cookies rcookies = response.cookies
rcookies.pop(name, None) rcookies.pop(name, None)
rcookies[name] = value.decode('utf8') rcookies[name] = to_native(value)
rcookies[name]['path'] = '/' rcookies[name]['path'] = '/'
expires = response.session_cookie_expires expires = response.session_cookie_expires
if isinstance(expires, datetime.datetime): if isinstance(expires, datetime.datetime):
+1 -2
View File
@@ -207,8 +207,7 @@ def secure_dumps(data, encryption_key, hash_key=None, compression_level=None):
def secure_loads(data, encryption_key, hash_key=None, compression_level=None): def secure_loads(data, encryption_key, hash_key=None, compression_level=None):
if not isinstance(data, bytes): data = to_bytes(data)
data = bytes(data, 'utf8')
components = data.count(b':') components = data.count(b':')
if components == 1: if components == 1:
return secure_loads_deprecated(data, encryption_key, hash_key, compression_level) return secure_loads_deprecated(data, encryption_key, hash_key, compression_level)