Changeset 53:ec3de0325406 in stamper


Ignore:
Timestamp:
Nov 8, 2014, 5:29:03 PM (6 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.

Location:
stamper
Files:
2 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
  • stamper/stamper.py

    r52 r53  
    2020SECS_DAY = HOURS_DAY * 60 * 60
    2121REMOTE_BASE_URL = 'https://localhost'
    22 REMOTE_PUSH_URL = '/stamper/listen/'  # IMPORTANT: keep the trailing /
     22# IMPORTANT: keep the trailing / on these _URL variables
     23REMOTE_LOGIN_URL = '/stamper/login/'
     24REMOTE_PUSH_URL = '/stamper/listen/'
    2325REMOTE_USER = None
    2426REMOTE_PASSWORD = None
     
    453455                stamps.append(stamp)
    454456        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})
    456460        http_client.post(REMOTE_PUSH_URL, {'stamps': stamps})
Note: See TracChangeset for help on using the changeset viewer.