Merge lp:~mterry/duplicity/u1-oauthlib into lp:duplicity/0.6

Proposed by Michael Terry
Status: Merged
Merged at revision: 891
Proposed branch: lp:~mterry/duplicity/u1-oauthlib
Merge into: lp:duplicity/0.6
Diff against target: 70 lines (+18/-19)
1 file modified
duplicity/backends/u1backend.py (+18/-19)
To merge this branch: bzr merge lp:~mterry/duplicity/u1-oauthlib
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+132791@code.launchpad.net

Description of the change

As the Ubuntu packager for duplicity, I would prefer u1backend.py used oauthlib instead of oauth.

oauthlib is well maintained upstream (unlike oauth), has a python3 port (for the future), and is in Ubuntu main (so is oauth right now, but hopefully in the future we can drop it to universe, in which case duplicity can't use it anymore).

Anyway. Here's a branch for the port.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'duplicity/backends/u1backend.py'
2--- duplicity/backends/u1backend.py 2012-10-27 12:16:19 +0000
3+++ duplicity/backends/u1backend.py 2012-11-03 22:16:22 +0000
4@@ -25,7 +25,7 @@
5 from duplicity import globals
6
7 from httplib2 import Http
8-from oauth import oauth
9+from oauthlib import oauth1
10 from urlparse import urlparse, parse_qsl
11 from json import loads, dumps
12 import urllib
13@@ -37,32 +37,31 @@
14 class OAuthHttpClient(object):
15 """a simple HTTP client with OAuth added on"""
16 def __init__(self):
17- self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
18- self.consumer = None
19+ self.consumer_key = None
20+ self.consumer_secret = None
21 self.token = None
22+ self.token_secret = None
23 self.client = Http()
24
25 def set_consumer(self, consumer_key, consumer_secret):
26- self.consumer = oauth.OAuthConsumer(consumer_key,
27- consumer_secret)
28+ self.consumer_key = consumer_key
29+ self.consumer_secret = consumer_secret
30
31 def set_token(self, token, token_secret):
32- self.token = oauth.OAuthToken( token, token_secret)
33+ self.token = token
34+ self.token_secret = token_secret
35
36 def _get_oauth_request_header(self, url, method):
37 """Get an oauth request header given the token and the url"""
38- query = urlparse(url).query
39-
40- oauth_request = oauth.OAuthRequest.from_consumer_and_token(
41- http_url=url,
42- http_method=method,
43- oauth_consumer=self.consumer,
44- token=self.token,
45- parameters=dict(parse_qsl(query))
46- )
47- oauth_request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
48- self.consumer, self.token)
49- return oauth_request.to_header()
50+ client = oauth1.Client(
51+ unicode(self.consumer_key),
52+ client_secret=unicode(self.consumer_secret),
53+ resource_owner_key=unicode(self.token),
54+ resource_owner_secret=unicode(self.token_secret))
55+ url, headers, body = client.sign(
56+ unicode(url),
57+ http_method=unicode(method))
58+ return headers
59
60 def request(self, url, method="GET", body=None, headers={}, ignore=None):
61 oauth_header = self._get_oauth_request_header(url, method)
62@@ -207,7 +206,7 @@
63 "Content-Type": content_type}
64 resp, content = self.client.request(remote_full,
65 method="PUT",
66- body=str(data),
67+ body=bytearray(data),
68 headers=headers)
69
70 def get(self, filename, local_path):

Subscribers

People subscribed via source and target branches

to all changes: