diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py
index ad2aa54..394caef 100644
a
|
b
|
import hashlib
|
3 | 3 | import os |
4 | 4 | import random |
5 | 5 | import time |
| 6 | from django.utils.encoding import smart_str |
6 | 7 | from django.utils.py3 import b |
7 | 8 | from datetime import datetime, timedelta |
8 | 9 | |
… |
… |
class SessionBase(object):
|
96 | 97 | return base64.encodestring(hash + b(":") + pickled) |
97 | 98 | |
98 | 99 | def decode(self, session_data): |
99 | | encoded_data = base64.decodestring(session_data.encode('ascii')) |
| 100 | encoded_data = base64.decodestring(b(session_data)) |
100 | 101 | try: |
101 | 102 | # could produce ValueError if there is no ':' |
102 | | hash, pickled = encoded_data.split(':', 1) |
| 103 | hash, pickled = encoded_data.split(b(':'), 1) |
103 | 104 | expected_hash = self._hash(pickled) |
104 | 105 | if not constant_time_compare(hash, expected_hash): |
105 | 106 | raise SuspiciousOperation("Session data corrupted") |
diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py
index 95e8e90..fb32bb8 100644
a
|
b
|
class SessionTestsMixin(object):
|
85 | 85 | self.assertFalse(self.session.modified) |
86 | 86 | |
87 | 87 | def test_values(self): |
88 | | self.assertEqual(self.session.values(), []) |
| 88 | self.assertEqual(list(self.session.values()), []) |
89 | 89 | self.assertTrue(self.session.accessed) |
90 | 90 | self.session['some key'] = 1 |
91 | | self.assertEqual(self.session.values(), [1]) |
| 91 | self.assertEqual(list(self.session.values()), [1]) |
92 | 92 | |
93 | 93 | def test_iterkeys(self): |
94 | 94 | self.session['x'] = 1 |
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index 9824fc4..d56eb60 100644
a
|
b
|
def default_key_func(key, key_prefix, version):
|
24 | 24 | the `key_prefix'. KEY_FUNCTION can be used to specify an alternate |
25 | 25 | function with custom key making behavior. |
26 | 26 | """ |
27 | | return ':'.join([key_prefix, str(version), smart_str(key)]) |
| 27 | return smart_str(':'.join([key_prefix, str(version), key])) |
28 | 28 | |
29 | 29 | def get_key_func(key_func): |
30 | 30 | """ |
… |
… |
class BaseCache(object):
|
63 | 63 | except (ValueError, TypeError): |
64 | 64 | self._cull_frequency = 3 |
65 | 65 | |
66 | | self.key_prefix = smart_str(params.get('KEY_PREFIX', '')) |
| 66 | self.key_prefix = params.get('KEY_PREFIX', '') |
67 | 67 | self.version = params.get('VERSION', 1) |
68 | 68 | self.key_func = get_key_func(params.get('KEY_FUNCTION', None)) |
69 | 69 | |
… |
… |
class BaseCache(object):
|
199 | 199 | '%s (longer than %s)' % (key, MEMCACHE_MAX_KEY_LENGTH), |
200 | 200 | CacheKeyWarning) |
201 | 201 | for char in key: |
| 202 | #in Python3 iterating over a byte string yields ints. |
| 203 | if type(char) == int: |
| 204 | char = chr(char) |
202 | 205 | if ord(char) < 33 or ord(char) == 127: |
203 | 206 | warnings.warn('Cache key contains characters that will cause ' |
204 | 207 | 'errors if used with memcached: %r' % key, |
diff --git a/django/core/signing.py b/django/core/signing.py
index 7f92d61..755cd50 100644
a
|
b
|
import zlib
|
39 | 39 | from django.conf import settings |
40 | 40 | from django.core.exceptions import ImproperlyConfigured |
41 | 41 | from django.utils import baseconv, simplejson |
| 42 | from django.utils.py3 import b |
42 | 43 | from django.utils.crypto import constant_time_compare, salted_hmac |
43 | 44 | from django.utils.encoding import force_unicode, smart_str |
44 | 45 | from django.utils.importlib import import_module |
… |
… |
class SignatureExpired(BadSignature):
|
59 | 60 | |
60 | 61 | |
61 | 62 | def b64_encode(s): |
62 | | return base64.urlsafe_b64encode(s).strip('=') |
| 63 | return base64.urlsafe_b64encode(s).strip(b('=')) |
63 | 64 | |
64 | 65 | |
65 | 66 | def b64_decode(s): |
… |
… |
def loads(s, key=None, salt='django.core.signing', serializer=JSONSerializer, ma
|
149 | 150 | |
150 | 151 | class Signer(object): |
151 | 152 | def __init__(self, key=None, sep=':', salt=None): |
152 | | self.sep = sep |
| 153 | self.sep = b(sep) |
153 | 154 | self.key = key or settings.SECRET_KEY |
154 | 155 | self.salt = salt or ('%s.%s' % |
155 | 156 | (self.__class__.__module__, self.__class__.__name__)) |