discovered and use _compat to_bytes and to_native functions
This commit is contained in:
@@ -13,6 +13,7 @@ from gluon import current
|
||||
from gluon.storage import Storage
|
||||
from gluon.contrib.redis_utils import acquire_lock, release_lock
|
||||
from gluon.contrib.redis_utils import register_release_lock
|
||||
from gluon._compat import to_bytes
|
||||
|
||||
logger = logging.getLogger("web2py.session.redis")
|
||||
|
||||
@@ -185,9 +186,7 @@ class MockQuery(object):
|
||||
if rtn:
|
||||
if self.unique_key:
|
||||
# make sure the id and unique_key are correct
|
||||
if not isinstance(self.unique_key, bytes):
|
||||
self.unique_key = bytes(self.unique_key, 'utf8')
|
||||
if rtn[b'unique_key'] == self.unique_key:
|
||||
if rtn[b'unique_key'] == to_bytes(self.unique_key):
|
||||
rtn[b'update_record'] = self.update # update record support
|
||||
else:
|
||||
rtn = None
|
||||
|
||||
@@ -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, \
|
||||
unicodeT, long, hashlib_md5, urllib_quote
|
||||
to_bytes, unicodeT, long, hashlib_md5, urllib_quote
|
||||
from gluon.storage import Storage, List
|
||||
from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
|
||||
from gluon.contenttype import contenttype
|
||||
@@ -225,7 +225,7 @@ class Request(Storage):
|
||||
# instead of load.
|
||||
# This line can be simplified to json_vars = json_parser.load(body)
|
||||
# if and when we drop support for python versions under 3.6
|
||||
json_vars = json_parser.loads(to_native(body.read()))
|
||||
json_vars = json_parser.loads(to_native(body.read()))
|
||||
except:
|
||||
# incoherent request bodies can still be parsed "ad-hoc"
|
||||
json_vars = {}
|
||||
@@ -344,8 +344,8 @@ class Request(Storage):
|
||||
user_agent = Storage(user_agent)
|
||||
user_agent.is_mobile = 'Mobile' in http_user_agent
|
||||
user_agent.is_tablet = 'Tablet' in http_user_agent
|
||||
session._user_agent = user_agent
|
||||
|
||||
session._user_agent = user_agent
|
||||
|
||||
return user_agent
|
||||
|
||||
def requires_https(self):
|
||||
@@ -485,12 +485,12 @@ class Response(Storage):
|
||||
#
|
||||
# We will only minify and concat adjacent internal files as there's
|
||||
# no way to know if changing the order with which the files are apppended
|
||||
# will break things since the order matters in both CSS and JS and
|
||||
# will break things since the order matters in both CSS and JS and
|
||||
# internal files may be interleaved with external ones.
|
||||
files = []
|
||||
# For the adjacent list we're going to use storage List to both distinguish
|
||||
# from the regular list and so we can add attributes
|
||||
internal = List()
|
||||
internal = List()
|
||||
internal.has_js = False
|
||||
internal.has_css = False
|
||||
done = set() # to remove duplicates
|
||||
@@ -513,7 +513,7 @@ class Response(Storage):
|
||||
if item.endswith('.js'):
|
||||
internal.has_js = True
|
||||
if item.endswith('.css'):
|
||||
internal.has_css = True
|
||||
internal.has_css = True
|
||||
if internal:
|
||||
files.append(internal)
|
||||
|
||||
@@ -537,7 +537,7 @@ class Response(Storage):
|
||||
time_expire)
|
||||
else:
|
||||
files[i] = call_minify()
|
||||
|
||||
|
||||
def static_map(s, item):
|
||||
if isinstance(item, str):
|
||||
f = item.lower().split('?')[0]
|
||||
@@ -1049,9 +1049,7 @@ class Session(Storage):
|
||||
if record_id.isdigit() and long(record_id) > 0:
|
||||
new_unique_key = web2py_uuid()
|
||||
row = table(record_id)
|
||||
if not isinstance(unique_key, bytes):
|
||||
unique_key = bytes(unique_key, 'utf8')
|
||||
if row and row[b'unique_key'] == unique_key:
|
||||
if row and row[b'unique_key'] == to_bytes(unique_key):
|
||||
table._db(table.id == record_id).update(unique_key=new_unique_key)
|
||||
else:
|
||||
record_id = None
|
||||
@@ -1169,7 +1167,7 @@ class Session(Storage):
|
||||
compression_level=compression_level)
|
||||
rcookies = response.cookies
|
||||
rcookies.pop(name, None)
|
||||
rcookies[name] = value.decode('utf8')
|
||||
rcookies[name] = to_native(value)
|
||||
rcookies[name]['path'] = '/'
|
||||
expires = response.session_cookie_expires
|
||||
if isinstance(expires, datetime.datetime):
|
||||
|
||||
@@ -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):
|
||||
if not isinstance(data, bytes):
|
||||
data = bytes(data, 'utf8')
|
||||
data = to_bytes(data)
|
||||
components = data.count(b':')
|
||||
if components == 1:
|
||||
return secure_loads_deprecated(data, encryption_key, hash_key, compression_level)
|
||||
|
||||
Reference in New Issue
Block a user