← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~mterry/duplicity/u1-oauthlib into lp:duplicity

 

Michael Terry has proposed merging lp:~mterry/duplicity/u1-oauthlib into lp:duplicity.

Requested reviews:
  duplicity-team (duplicity-team)

For more details, see:
https://code.launchpad.net/~mterry/duplicity/u1-oauthlib/+merge/132791

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.
-- 
https://code.launchpad.net/~mterry/duplicity/u1-oauthlib/+merge/132791
Your team duplicity-team is requested to review the proposed merge of lp:~mterry/duplicity/u1-oauthlib into lp:duplicity.
=== modified file 'duplicity/backends/u1backend.py'
--- duplicity/backends/u1backend.py	2012-10-27 12:16:19 +0000
+++ duplicity/backends/u1backend.py	2012-11-03 22:16:22 +0000
@@ -25,7 +25,7 @@
 from duplicity import globals
 
 from httplib2 import Http
-from oauth import oauth
+from oauthlib import oauth1
 from urlparse import urlparse, parse_qsl
 from json import loads, dumps
 import urllib
@@ -37,32 +37,31 @@
 class OAuthHttpClient(object):
     """a simple HTTP client with OAuth added on"""
     def __init__(self):
-        self.signature_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
-        self.consumer = None
+        self.consumer_key = None
+        self.consumer_secret = None
         self.token = None
+        self.token_secret = None
         self.client = Http()
 
     def set_consumer(self, consumer_key, consumer_secret):
-        self.consumer = oauth.OAuthConsumer(consumer_key,
-                                            consumer_secret)
+        self.consumer_key = consumer_key
+        self.consumer_secret = consumer_secret
 
     def set_token(self, token, token_secret):
-        self.token = oauth.OAuthToken( token, token_secret)
+        self.token = token
+        self.token_secret = token_secret
 
     def _get_oauth_request_header(self, url, method):
         """Get an oauth request header given the token and the url"""
-        query = urlparse(url).query
-
-        oauth_request = oauth.OAuthRequest.from_consumer_and_token(
-            http_url=url,
-            http_method=method,
-            oauth_consumer=self.consumer,
-            token=self.token,
-            parameters=dict(parse_qsl(query))
-        )
-        oauth_request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
-                                   self.consumer, self.token)
-        return oauth_request.to_header()
+        client = oauth1.Client(
+            unicode(self.consumer_key),
+            client_secret=unicode(self.consumer_secret),
+            resource_owner_key=unicode(self.token),
+            resource_owner_secret=unicode(self.token_secret))
+        url, headers, body = client.sign(
+            unicode(url),
+            http_method=unicode(method))
+        return headers
 
     def request(self, url, method="GET", body=None, headers={}, ignore=None):
         oauth_header = self._get_oauth_request_header(url, method)
@@ -207,7 +206,7 @@
                    "Content-Type": content_type}
         resp, content = self.client.request(remote_full,
                                             method="PUT",
-                                            body=str(data),
+                                            body=bytearray(data),
                                             headers=headers)
 
     def get(self, filename, local_path):


Follow ups