33
33
"""The request ended with bad_request, unauthorized or forbidden."""
36
def build_oauth_headers(method, url, credentials):
36
def build_oauth_headers(method, url, credentials, timestamp):
37
37
"""Build an oauth request given some credentials."""
38
38
consumer = oauth.OAuthConsumer(credentials["consumer_key"],
39
39
credentials["consumer_secret"])
40
40
token = oauth.OAuthToken(credentials["token"],
41
41
credentials["token_secret"])
44
parameters["oauth_timestamp"] = timestamp
42
45
request = oauth.OAuthRequest.from_consumer_and_token(
44
47
http_method=method,
48
parameters=parameters,
45
49
oauth_consumer=consumer,
47
51
sig_method = oauth.OAuthSignatureMethod_HMAC_SHA1()
49
53
return request.to_header()
52
def add_oauth_headers(append_method, method, url, credentials):
56
def add_oauth_headers(append_method, method, url, credentials, timestamp=None):
53
57
"""Sign a libsoup message with oauth headers."""
54
headers = build_oauth_headers(method, url, credentials)
58
headers = build_oauth_headers(method, url, credentials, timestamp)
55
59
for key, value in headers.items():
56
60
append_method(key, value)
59
def web_client_factory(*args, **kwargs):
60
"""Choose the type of the web client dynamically."""
63
def web_client_module():
64
"""Choose the module of the web client."""
61
65
# the reactor can only be imported after Qt is initialized
62
66
# pylint: disable=W0404
63
67
from twisted.internet import reactor
64
68
if getattr(reactor, "qApp", None):
65
from ubuntuone.controlpanel.web_client.txwebclient import WebClient
69
from ubuntuone.controlpanel.web_client import txwebclient as web_module
67
from ubuntuone.controlpanel.web_client.libsoup import WebClient
68
return WebClient(*args, **kwargs)
71
from ubuntuone.controlpanel.web_client import libsoup as web_module
75
def web_client_factory(*args, **kwargs):
76
"""Choose the type of the web client dynamically."""
77
web_module = web_client_module()
78
return web_module.WebClient(*args, **kwargs)