summaryrefslogtreecommitdiff
path: root/meetingtools/ac
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2011-02-01 09:07:22 +0100
committerLeif Johansson <leifj@sunet.se>2011-02-01 09:07:22 +0100
commita20ff434501a099b259da903d88b47bb77e07469 (patch)
tree5749d274242a0e0882f9b3e6d6989f25c1d369cf /meetingtools/ac
import
Diffstat (limited to 'meetingtools/ac')
-rw-r--r--meetingtools/ac/__init__.py0
-rw-r--r--meetingtools/ac/api.py66
2 files changed, 66 insertions, 0 deletions
diff --git a/meetingtools/ac/__init__.py b/meetingtools/ac/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/meetingtools/ac/__init__.py
diff --git a/meetingtools/ac/api.py b/meetingtools/ac/api.py
new file mode 100644
index 0000000..2631987
--- /dev/null
+++ b/meetingtools/ac/api.py
@@ -0,0 +1,66 @@
+'''
+Created on Jan 31, 2011
+
+@author: leifj
+'''
+
+from lxml import etree
+import httplib2
+from urllib import urlencode
+
+class ACPException(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return repr(self.value)
+
+class ACPResult():
+
+ def __init__(self,content):
+ self.et = etree.parse(content)
+ self.status = self.et.find('status')
+
+ def is_error(self):
+ return self.status.get('code') != 'ok'
+
+ def exception(self):
+ raise ACPException,self.status
+
+ def get_principal(self):
+ return self.et.find('principal')
+
+class ACPClient():
+
+ def __init__(self,url,username=None,password=None):
+ self.url = url
+ self.session = None
+ if username and password:
+ self.login(username,password)
+
+ def request(self,method,p={}):
+ url = self.url+"?"+"action=%s" % method
+ if self.session:
+ url = url + "&session=%s" % self.session
+ urlencode(dict([k,v.encode("iso-8859-1")] for (k,v) in p.items()))
+
+ h = httplib2.Http(".cache");
+ resp, content = h.request(url, "GET")
+ if resp.status != 200:
+ raise ACPException,resp.reason
+
+ if resp.has_key('set-cookie'):
+ cookie = resp['set-cookie']
+ if cookie:
+ avp = cookie.split(";")
+ if avp.len > 0:
+ av = avp[0].split('=')
+ self.session = av[1]
+
+ return ACPResult(content)
+
+ def login(self,username,password):
+ result = self.request('login',{'login':username,'password':password})
+ if result.is_error():
+ raise result.exception()
+ \ No newline at end of file