Changeset 53:ec3de0325406 in stamper
- Timestamp:
- Nov 8, 2014, 5:29:03 PM (10 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- stamper
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stamper/http.py
r51 r53 1 1 2 from urllib2 import Request, urlopen 2 from urllib2 import ( 3 Request, urlopen, build_opener, install_opener, HTTPCookieProcessor 4 ) 3 5 from urllib import urlencode 4 6 from urlparse import urljoin … … 7 9 class HTTPClient(object): 8 10 9 def __init__(self, base_url , user=None, password=None):11 def __init__(self, base_url): 10 12 self.base_url = base_url 11 self.user = user 12 self.password = password 13 14 def authenticate(self): 15 return 'not ready yet' 13 self.request = build_opener(HTTPCookieProcessor()) 14 install_opener(self.request) 16 15 17 16 def send_request(self, url, data=None): 18 request = Request(url, data) 19 response = urlopen(request) 17 response = self.request.open(url, data) 20 18 return response.read() 21 19 -
stamper/stamper.py
r52 r53 20 20 SECS_DAY = HOURS_DAY * 60 * 60 21 21 REMOTE_BASE_URL = 'https://localhost' 22 REMOTE_PUSH_URL = '/stamper/listen/' # IMPORTANT: keep the trailing / 22 # IMPORTANT: keep the trailing / on these _URL variables 23 REMOTE_LOGIN_URL = '/stamper/login/' 24 REMOTE_PUSH_URL = '/stamper/listen/' 23 25 REMOTE_USER = None 24 26 REMOTE_PASSWORD = None … … 453 455 stamps.append(stamp) 454 456 stamps = json.dumps(stamps, indent=4) 455 http_client = HTTPClient(REMOTE_BASE_URL, REMOTE_USER, REMOTE_PASSWORD) 457 http_client = HTTPClient(REMOTE_BASE_URL) 458 http_client.post(REMOTE_LOGIN_URL, {'username': REMOTE_USER, 459 'password': REMOTE_PASSWORD}) 456 460 http_client.post(REMOTE_PUSH_URL, {'stamps': stamps})
Note:
See TracChangeset
for help on using the changeset viewer.