← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-pgsession-hashed-client-id into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-pgsession-hashed-client-id into launchpad:master.

Commit message:
Fix PGSessionData.hashed_client_id for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/392079

`hashlib.sha256(...).hexdigest()` returns a `str` on Python 3, which doesn't have a `.decode()` method.  Use `six.ensure_text` instead to make sure we end up with text on both Python 2 and 3.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-pgsession-hashed-client-id into launchpad:master.
diff --git a/lib/lp/services/webapp/pgsession.py b/lib/lp/services/webapp/pgsession.py
index eefdd2a..1940fac 100644
--- a/lib/lp/services/webapp/pgsession.py
+++ b/lib/lp/services/webapp/pgsession.py
@@ -10,6 +10,7 @@ import hashlib
 import time
 
 from lazr.restful.utils import get_current_browser_request
+import six
 from six.moves import cPickle as pickle
 from storm.zope.interfaces import IZStorm
 from zope.authentication.interfaces import IUnauthenticatedPrincipal
@@ -93,8 +94,9 @@ class PGSessionData(PGSessionBase):
     def __init__(self, session_data_container, client_id):
         self.session_data_container = session_data_container
         self.client_id = ensure_unicode(client_id)
-        self.hashed_client_id = hashlib.sha256(
-            self.client_id.encode('utf-8')).hexdigest().decode('ascii')
+        self.hashed_client_id = six.ensure_text(
+            hashlib.sha256(self.client_id.encode('utf-8')).hexdigest(),
+            'ascii')
         self.lastAccessTime = time.time()
 
         # Update the last access time in the db if it is out of date