source: stamper/stamper/http.py@ 51:2744123f56bf

Last change on this file since 51:2744123f56bf was 51:2744123f56bf, checked in by Borja Lopez <borja@…>, 6 years ago

Minimal http client for stamper.

This client allows us to send GET/POST requests using http.

File size: 719 bytes
Line 
1
2from urllib2 import Request, urlopen
3from urllib import urlencode
4from urlparse import urljoin
5
6
7class HTTPClient(object):
8
9 def __init__(self, base_url, user=None, password=None):
10 self.base_url = base_url
11 self.user = user
12 self.password = password
13
14 def authenticate(self):
15 return 'not ready yet'
16
17 def send_request(self, url, data=None):
18 request = Request(url, data)
19 response = urlopen(request)
20 return response.read()
21
22 def get(self, url):
23 return self.send_request(urljoin(self.base_url, url))
24
25 def post(self, url, data):
26 encoded_data = urlencode(data)
27 return self.send_request(urljoin(self.base_url, url), encoded_data)
Note: See TracBrowser for help on using the repository browser.