Merge lp:~barry/ubuntuone-client/lp1077089 into lp:ubuntuone-client

Proposed by Barry Warsaw on 2013-01-03
Status: Merged
Approved by: dobey on 2013-02-11
Approved revision: 1365
Merged at revision: 1386
Proposed branch: lp:~barry/ubuntuone-client/lp1077089
Merge into: lp:ubuntuone-client
Diff against target: 91 lines (+34/-14)
2 files modified
tests/syncdaemon/test_action_queue.py (+9/-7)
ubuntuone/syncdaemon/action_queue.py (+25/-7)
To merge this branch: bzr merge lp:~barry/ubuntuone-client/lp1077089
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve on 2013-02-06
Michał Karnicki (community) 2013-01-03 Approve on 2013-02-05
Review via email: mp+141828@code.launchpad.net

Commit message

Switch from python-oauth to python-oauthlib for using OAuth.

Description of the change

The oauth library has been abandoned upstream for years now. It also only supports Python 2 and OAuth 1 (not even the RFC version). Our current best recommendation for Python oauth client libraries is oauthlib (a.k.a. python-oauthlib).

This branch ports ubuntuone-client from oauth to oauthlib. It uses @property to maintain the old API.

To post a comment you must log in.
lp:~barry/ubuntuone-client/lp1077089 updated on 2013-02-04
1365. By Barry Warsaw on 2013-02-04

trunk merge

Michał Karnicki (karni) wrote :

Looks good, please seek a second review from a full-time Python hacker ;)

review: Approve
Alejandro J. Cura (alecu) wrote :

Looks great, +1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_action_queue.py'
2--- tests/syncdaemon/test_action_queue.py 2013-01-17 19:16:53 +0000
3+++ tests/syncdaemon/test_action_queue.py 2013-02-04 22:03:22 +0000
4@@ -45,7 +45,7 @@
5 import OpenSSL.SSL
6
7 from mocker import Mocker, MockerTestCase, ANY, expect
8-from oauth import oauth
9+from oauthlib.oauth1 import Client
10 from twisted.internet import defer, reactor
11 from twisted.internet import error as twisted_error
12 from twisted.python.failure import DefaultException, Failure
13@@ -3962,13 +3962,15 @@
14
15 self.user_connect()
16
17- expected = oauth.OAuthToken('bla', 'ble')
18- self.assertEqual(self.action_queue.token.key, expected.key)
19- self.assertEqual(self.action_queue.token.secret, expected.secret)
20+ expected = Client('bla', 'ble', 'foo', 'bar')
21
22- expected = oauth.OAuthConsumer('foo', 'bar')
23- self.assertEqual(self.action_queue.consumer.key, expected.key)
24- self.assertEqual(self.action_queue.consumer.secret, expected.secret)
25+ self.assertEqual(self.action_queue.token.key, expected.client_key)
26+ self.assertEqual(self.action_queue.token.secret,
27+ expected.client_secret)
28+ self.assertEqual(self.action_queue.consumer.key,
29+ expected.resource_owner_key)
30+ self.assertEqual(self.action_queue.consumer.secret,
31+ expected.resource_owner_secret)
32
33
34 class SpecificException(Exception):
35
36=== modified file 'ubuntuone/syncdaemon/action_queue.py'
37--- ubuntuone/syncdaemon/action_queue.py 2013-01-11 20:05:24 +0000
38+++ ubuntuone/syncdaemon/action_queue.py 2013-02-04 22:03:22 +0000
39@@ -53,7 +53,7 @@
40 from twisted.names import client as dns_client
41 from twisted.python.failure import Failure, DefaultException
42
43-from oauth import oauth
44+from oauthlib.oauth1 import Client
45 from ubuntu_sso.utils.webclient import txweb
46 from ubuntuone import clientdefs
47 from ubuntuone.platform import platform, remove_file
48@@ -784,8 +784,7 @@
49 self.connection_timeout = connection_timeout
50
51 # credentials
52- self.token = None
53- self.consumer = None
54+ self.oauth_client = None
55 self.credentials = None
56
57 self.client = None # an instance of self.protocol
58@@ -833,10 +832,29 @@
59 def handle_SYS_USER_CONNECT(self, access_token):
60 """Stow the access token away for later use."""
61 self.credentials = access_token
62- self.token = oauth.OAuthToken(access_token['token'],
63- access_token['token_secret'])
64- self.consumer = oauth.OAuthConsumer(access_token['consumer_key'],
65- access_token['consumer_secret'])
66+ self.oauth_client = Client(access_token['token'],
67+ access_token['token_secret'],
68+ access_token['consumer_key'],
69+ access_token['consumer_secret'])
70+
71+ # For API backward compatibility.
72+ @property
73+ def token(self):
74+ if self.oauth_client is None:
75+ return None
76+ class _Token:
77+ key = self.oauth_client.client_key
78+ secret = self.oauth_client.client_secret
79+ return _Token()
80+
81+ @property
82+ def consumer(self):
83+ if self.oauth_client is None:
84+ return None
85+ class _Consumer:
86+ key = self.oauth_client.resource_owner_key
87+ secret = self.oauth_client.resource_owner_secret
88+ return _Consumer()
89
90 def _cleanup_connection_state(self, *args):
91 """Reset connection state."""

Subscribers

People subscribed via source and target branches