Merge ~cjwatson/launchpad:py3-baseopenidstore into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 24edf50512aab8abd75859bdd7e1305ffd052c31
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-baseopenidstore
Merge into: launchpad:master
Diff against target: 80 lines (+12/-11)
1 file modified
lib/lp/services/openid/model/baseopenidstore.py (+12/-11)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+397864@code.launchpad.net

Commit message

Fix baseopenidstore for Python 3

Description of the change

On Python 3, python-openid seems to pass strings as text, so we don't need to decode them. Use six.ensure_text to paper over the differences.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/services/openid/model/baseopenidstore.py b/lib/lp/services/openid/model/baseopenidstore.py
2index 7b0c336..01a0ec0 100644
3--- a/lib/lp/services/openid/model/baseopenidstore.py
4+++ b/lib/lp/services/openid/model/baseopenidstore.py
5@@ -16,6 +16,7 @@ import time
6 from openid.association import Association
7 from openid.store import nonce
8 from openid.store.interface import OpenIDStore
9+import six
10 from storm.properties import (
11 Bytes,
12 Int,
13@@ -39,18 +40,18 @@ class BaseStormOpenIDAssociation:
14
15 def __init__(self, server_url, association):
16 super(BaseStormOpenIDAssociation, self).__init__()
17- self.server_url = server_url.decode('UTF-8')
18- self.handle = association.handle.decode('ASCII')
19+ self.server_url = six.ensure_text(server_url)
20+ self.handle = six.ensure_text(association.handle, 'ASCII')
21 self.update(association)
22
23 def update(self, association):
24- assert self.handle == association.handle.decode('ASCII'), (
25+ assert self.handle == six.ensure_text(association.handle, 'ASCII'), (
26 "Association handle does not match (expected %r, got %r" %
27 (self.handle, association.handle))
28 self.secret = association.secret
29 self.issued = association.issued
30 self.lifetime = association.lifetime
31- self.assoc_type = association.assoc_type.decode('ASCII')
32+ self.assoc_type = six.ensure_text(association.assoc_type, 'ASCII')
33
34 def as_association(self):
35 """Return an equivalent openid-python `Association` object."""
36@@ -84,8 +85,8 @@ class BaseStormOpenIDStore(OpenIDStore):
37 """See `OpenIDStore`."""
38 store = IMasterStore(self.Association)
39 db_assoc = store.get(
40- self.Association, (server_url.decode('UTF-8'),
41- association.handle.decode('ASCII')))
42+ self.Association, (six.ensure_text(server_url),
43+ six.ensure_text(association.handle, 'ASCII')))
44 if db_assoc is None:
45 db_assoc = self.Association(server_url, association)
46 store.add(db_assoc)
47@@ -95,11 +96,11 @@ class BaseStormOpenIDStore(OpenIDStore):
48 def getAssociation(self, server_url, handle=None):
49 """See `OpenIDStore`."""
50 store = IMasterStore(self.Association)
51- server_url = server_url.decode('UTF-8')
52+ server_url = six.ensure_text(server_url)
53 if handle is None:
54 result = store.find(self.Association, server_url=server_url)
55 else:
56- handle = handle.decode('ASCII')
57+ handle = six.ensure_text(handle, 'ASCII')
58 result = store.find(
59 self.Association, server_url=server_url, handle=handle)
60
61@@ -121,7 +122,7 @@ class BaseStormOpenIDStore(OpenIDStore):
62 """See `OpenIDStore`."""
63 store = IMasterStore(self.Association)
64 assoc = store.get(self.Association, (
65- server_url.decode('UTF-8'), handle.decode('ASCII')))
66+ six.ensure_text(server_url), six.ensure_text(handle, 'ASCII')))
67 if assoc is None:
68 return False
69 store.remove(assoc)
70@@ -133,8 +134,8 @@ class BaseStormOpenIDStore(OpenIDStore):
71 if abs(timestamp - time.time()) > nonce.SKEW:
72 return False
73
74- server_url = server_url.decode('UTF-8')
75- salt = salt.decode('ASCII')
76+ server_url = six.ensure_text(server_url)
77+ salt = six.ensure_text(salt, 'ASCII')
78
79 store = IMasterStore(self.Nonce)
80 old_nonce = store.get(self.Nonce, (server_url, timestamp, salt))

Subscribers

People subscribed via source and target branches

to status/vote changes: