Commits

Sanghyeon Seo committed 0394ac1

login and logout

Comments (0)

Files changed (1)

 
 prefix = 'http://fluiddb.fluidinfo.com'
 
+global_headers = {
+    'Accept': 'application/json',
+}
+
+def login(username, password):
+    userpass = username + ':' + password
+    auth = 'Basic ' + userpass.encode('base64').strip()
+    global_headers['Authorization'] = auth
+
+def logout():
+    del global_headers['Authorization']
+
 def call(method, path, body=None, **kw):
     http = httplib2.Http()
     url = prefix + urllib.quote(path)
     if kw:
         url = url + '?' + urllib.urlencode(kw)
-    headers = {}
-    headers['Accept'] = 'application/json'
+    headers = global_headers.copy()
     if body:
         headers['content-type'] = 'application/json'
     response, content = http.request(url, method, body, headers)