Changeset 53:ec3de0325406 in stamper for stamper/http.py


Ignore:
Timestamp:
Nov 8, 2014, 5:29:03 PM (9 years ago)
Author:
Borja Lopez <borja@…>
Branch:
default
Phase:
public
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • stamper/http.py

    r51 r53  
    11
    2 from urllib2 import Request, urlopen
     2from urllib2 import (
     3    Request, urlopen, build_opener, install_opener, HTTPCookieProcessor
     4    )
    35from urllib import urlencode
    46from urlparse import urljoin
     
    79class HTTPClient(object):
    810
    9     def __init__(self, base_url, user=None, password=None):
     11    def __init__(self, base_url):
    1012        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)
    1615
    1716    def send_request(self, url, data=None):
    18         request = Request(url, data)
    19         response = urlopen(request)
     17        response = self.request.open(url, data)
    2018        return response.read()
    2119
Note: See TracChangeset for help on using the changeset viewer.