23
23
from oauth import oauth
24
24
from urlparse import urlparse
26
from twisted.internet import defer
26
28
from ubuntu_sso.logger import setup_logging
29
from ubuntu_sso.utils import webclient
29
32
logger = setup_logging("ubuntu_sso.utils")
119
122
headers = oauth_req.to_header()
127
@defer.inlineCallbacks
128
def ping_url(url, email, credentials):
129
"""Ping the 'url' with the 'email' attached to it.
131
Sign the request with 'credentials'. The url must not be None.
134
logger.info('Pinging server using url: %r, email: %r.',
136
assert isinstance(url, unicode), 'Url %r must be unicode' % url
140
target_url = url.format(email=email)
141
except IndexError: # tuple index out of range
142
target_url = url.format(email) # format the first substitution
144
if target_url == url:
145
logger.debug('Original url (%r) could not be formatted, '
146
'appending email (%r).', url, email)
147
assert url.endswith(u'/'), 'Url %r must end with /.' % url
148
target_url = url + email
150
wc = webclient.webclient_factory()
152
logger.debug('Opening the url %r with webclient.request.', url)
153
response = yield wc.request(target_url, oauth_credentials=credentials)
154
logger.debug('Url %r opened. Response content: %r.',
155
url, response.content)
156
defer.returnValue(response)