source: stamper/stamper/http.py@ 53:ec3de0325406

Last change on this file since 53:ec3de0325406 was 53:ec3de0325406, checked in by Borja Lopez <borja@…>, 6 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
Line 
1
2from urllib2 import (
3 Request, urlopen, build_opener, install_opener, HTTPCookieProcessor
4 )
5from urllib import urlencode
6from urlparse import urljoin
7
8
9class HTTPClient(object):
10
11 def __init__(self, base_url):
12 self.base_url = base_url
13 self.request = build_opener(HTTPCookieProcessor())
14 install_opener(self.request)
15
16 def send_request(self, url, data=None):
17 response = self.request.open(url, data)
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.