Skip to content

Commit

Permalink
[py3] Avoided the deprecated base64 interface.
Browse files Browse the repository at this point in the history
This fixes a deprecation warning under Python 3.
  • Loading branch information
aaugustin committed Aug 14, 2012
1 parent 928baee commit 212a512
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/contrib/sessions/backends/base.py
Expand Up @@ -81,10 +81,10 @@ def encode(self, session_dict):
"Returns the given session dictionary pickled and encoded as a string."
pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL)
hash = self._hash(pickled)
return base64.encodestring(hash.encode() + b":" + pickled)
return base64.b64encode(hash.encode() + b":" + pickled)

def decode(self, session_data):
encoded_data = base64.decodestring(smart_bytes(session_data))
encoded_data = base64.b64decode(smart_bytes(session_data))
try:
# could produce ValueError if there is no ':'
hash, pickled = encoded_data.split(b':', 1)
Expand Down
4 changes: 2 additions & 2 deletions django/core/cache/backends/db.py
Expand Up @@ -72,7 +72,7 @@ def get(self, key, default=None, version=None):
transaction.commit_unless_managed(using=db)
return default
value = connections[db].ops.process_clob(row[1])
return pickle.loads(base64.decodestring(value))
return pickle.loads(base64.b64decode(value))

def set(self, key, value, timeout=None, version=None):
key = self.make_key(key, version=version)
Expand Down Expand Up @@ -103,7 +103,7 @@ def _base_set(self, mode, key, value, timeout=None):
if num > self._max_entries:
self._cull(db, cursor, now)
pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL)
encoded = base64.encodestring(pickled).strip()
encoded = base64.b64encode(pickled).strip()
cursor.execute("SELECT cache_key, expires FROM %s "
"WHERE cache_key = %%s" % table, [key])
try:
Expand Down

0 comments on commit 212a512

Please sign in to comment.