source: stamper/stamper/http.py@ 65:25b55b621ea4

Last change on this file since 65:25b55b621ea4 was 53:ec3de0325406, checked in by Borja Lopez <borja@…>, 10 years ago

Authenticate the user before actually push the stamps to the server.
Also, cleaned up a bit the http client, no need to pass and store
there the user and password auth credentials.

File size: 709 bytes
RevLine 
[51]1
[53]2from urllib2 import (
3 Request, urlopen, build_opener, install_opener, HTTPCookieProcessor
4 )
[51]5from urllib import urlencode
6from urlparse import urljoin
7
8
9class HTTPClient(object):
10
[53]11 def __init__(self, base_url):
[51]12 self.base_url = base_url
[53]13 self.request = build_opener(HTTPCookieProcessor())
14 install_opener(self.request)
[51]15
16 def send_request(self, url, data=None):
[53]17 response = self.request.open(url, data)
[51]18 return response.read()
19
20 def get(self, url):
21 return self.send_request(urljoin(self.base_url, url))
22
23 def post(self, url, data):
24 encoded_data = urlencode(data)
25 return self.send_request(urljoin(self.base_url, url), encoded_data)
Note: See TracBrowser for help on using the repository browser.