~elopio/ubuntu-sso-client/autopilot

« back to all changes in this revision

Viewing changes to ubuntu_sso/utils/webclient/common.py

  • Committer: leo.arias at canonical
  • Date: 2013-02-23 18:49:59 UTC
  • mfrom: (1021.2.2 ubuntu-sso-client)
  • Revision ID: leo.arias@canonical.com-20130223184959-qk02det611b0f9j4
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
#
3
 
# Copyright 2011-2012 Canonical Ltd.
 
3
# Copyright 2011-2013 Canonical Ltd.
4
4
#
5
5
# This program is free software: you can redistribute it and/or modify it
6
6
# under the terms of the GNU General Public License version 3, as published
28
28
# files in the program, then also delete it here.
29
29
"""The common bits of a webclient."""
30
30
 
31
 
import cgi
32
31
import collections
33
32
 
34
33
from httplib2 import iri2uri
37
36
    SIGNATURE_TYPE_QUERY)
38
37
from twisted.internet import defer
39
38
 
40
 
try:
41
 
    # pylint: disable=E0611,F0401
42
 
    from urllib.parse import urlparse
43
 
    # pylint: enable=E0611,F0401
44
 
except ImportError:
45
 
    from urlparse import urlparse
46
 
 
47
39
from ubuntu_sso import (USER_SUCCESS,
48
40
                        UI_PROXY_CREDS_DIALOG,
49
41
                        UI_SSL_DIALOG)
151
143
                            parameters=None, as_query=True):
152
144
        """Build an oauth request given some credentials."""
153
145
 
 
146
        # oauthlib is requiring the timestamp to be a string, because
 
147
        # it tries to escape all the parameters.
154
148
        oauth_client = Client(credentials['consumer_key'],
155
149
                              credentials['consumer_secret'],
156
150
                              credentials['token'],
161
155
                              signature_type=(SIGNATURE_TYPE_QUERY
162
156
                                              if as_query
163
157
                                              else SIGNATURE_TYPE_AUTH_HEADER),
164
 
                              timestamp=timestamp)
165
 
        if not parameters:
166
 
            _, _, _, _, query, _ = urlparse(uri)
167
 
            parameters = dict(cgi.parse_qsl(query))
 
158
                              timestamp=str(timestamp))
168
159
 
169
160
        url, signed_headers, body = oauth_client.sign(
170
 
            uri, method, parameters,
 
161
            uri, method, parameters if parameters is not None else {},
171
162
            {'Content-Type': 'application/x-www-form-urlencoded'})
172
163
 
173
164
        return url, signed_headers, body