コード例 #1
0
ファイル: test_client.py プロジェクト: ant0ine/httpclient
    def _test_request(self, method):
        client = HTTPClient()
        client.add_handler('request_send', _test_cb)

        request = Request(method, tests[method]['url'], tests[method]['headers'])

        if 'content' in tests[method]:
            request.content = tests[method]['content']

        resp = client.request(request)

        self.assertTrue(resp)
        self.assertEqual(resp.status, 204)
コード例 #2
0
    def _test_request(self, method):
        client = HTTPClient()
        client.add_handler('request_send', _test_cb)

        request = Request(method, tests[method]['url'],
                          tests[method]['headers'])

        if 'content' in tests[method]:
            request.content = tests[method]['content']

        resp = client.request(request)

        self.assertTrue(resp)
        self.assertEqual(resp.status, 204)
コード例 #3
0
    def test_prepare(self):
        request = Request('FOO', 'http')
        client = HTTPClient()
        client.add_handler('request_prepare', _cb_request_prepare)

        resp = client.request(request)
        self.assertEqual(resp.status, 400)

        handlers = Handlers()
        handlers.add_handler('request_prepare',
                             _cb_request_prepare_change_request)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'PUT')

        handlers = Handlers()
        handlers.add_handler('request_prepare', _cb_request_prepare_do_nothing)
        req = handlers.dispatch('request_prepare', request)
        self.assertEqual(req.method, 'FOO')
        self.assertEqual(req.url, 'http')
コード例 #4
0
ファイル: picasaclient.py プロジェクト: cClaude/xppr
class Service:    

    def __init__(self):
        self.http_client = HTTPClient(None)
        self.ssl = False
        self.port = 80
        self.server = 'picasaweb.google.com'
        self.additional_headers = {}
        self.additional_headers['GData-Version'] = '2'
#        self.additional_headers['User-Agent'] = atom.http_interface.USER_AGENT % (
#            application_name,)
        self.token = None

    def authenticate(self, email, password, num_tried=0):
        auth_request_url = AUTH_SERVER_HOST + '/accounts/ClientLogin'
        request_fields = {'Email': email, 'Passwd': password, 'accountType':
                          'HOSTED_OR_GOOGLE', 'service': 'lh2', 'source': None}
        request_body = urllib.urlencode(request_fields)

        try:
            auth_response = self.http_client.request(auth_request_url,
                                                     data=request_body)
        except urllib2.HTTPError, e:
            response_body = e.read()
            if e.code == 403:
                if response_body.splitlines()[0] == 'Error=BadAuthentication':
                    raise BadAuthentication, 'Incorrect username or password'
                else:
                    raise Exception, 'Server responded with a 403 code. \
                    Message:\n' + response_body
            else:
                raise BadAuthentication, 'Authentication process failed. \
                Message:\n' + response_body
                    
        except urllib2.URLError, e:
            if num_tried < 5:
                #log(self.__class__, "login attempt: %d failed - %s" %
                    #(num_tried + 1, str(e.reason)))
                time.sleep(3)
                return self.authenticate(email, password, num_tried + 1)
            raise BadAuthentication, 'Authentication process failed. \
            Message:\n' + str(e.reason)
コード例 #5
0
 def test_response(self):
     request = Request('GET', 'http')
     client = HTTPClient()
     client.add_handler('request_send', _cb_request_send)
     #client.add_handler('response_done', _cb_response_done)
     resp = client.request(request)