diff options
author | Leif Johansson <leifj@sunet.se> | 2012-02-09 00:16:16 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2012-02-09 00:16:16 +0100 |
commit | ad21e8e4e5ac8f9eb38830f3024e19fd9329e288 (patch) | |
tree | 4aa7d7c3a6cd66cae59708e5bba274ce1cdb1eba /src/meetingtools/ac/api.py | |
parent | 635d92fc5ded0faec71849554224608f0424fae2 (diff) |
* refactor api
* now depends on with statement
* object-pool using queues
Diffstat (limited to 'src/meetingtools/ac/api.py')
-rw-r--r-- | src/meetingtools/ac/api.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/meetingtools/ac/api.py b/src/meetingtools/ac/api.py index c17d500..4d5559f 100644 --- a/src/meetingtools/ac/api.py +++ b/src/meetingtools/ac/api.py @@ -10,6 +10,7 @@ import logging from pprint import pformat import os import tempfile +import time from lxml import etree from meetingtools.site_logging import logger import lxml @@ -67,15 +68,29 @@ def _getset(d,key,value=None): class ACPClient(): - def __init__(self,url,username=None,password=None,cache=True): + def __init__(self,url,username=None,password=None,cache=True,cpool=None): + self._cpool = cpool + self.age = 0 + self.createtime = time.time() + self.lastused = self.createtime self.url = url self.session = None if username and password: self.login(username,password) if cache: self._cache = {'login':{},'group':{}} + + def __exit__(self,type,value,traceback): + if self._cpool: + self._cpool._q.put_nowait(self) + + def __enter__(self): + return self + def request(self,method,p={},raise_error=False): + self.age += 1 + self.lastused = time.time() u = [] u.append("action=%s" % method) if self.session: |