summaryrefslogtreecommitdiff
path: root/meetingtools/ac
diff options
context:
space:
mode:
authorLeif Johansson <leifj@sunet.se>2012-10-23 12:48:46 +0200
committerLeif Johansson <leifj@sunet.se>2012-10-23 12:48:46 +0200
commitd8fd541f0e07448986f5fbbbf3207f40d4e7f48d (patch)
tree2d9b3ea18f50982193a22d88af1cf2ffc5b6a3f4 /meetingtools/ac
parent2ee5f388df74edce42fdc6b46b5296984926da0e (diff)
shorten hashkeys
Diffstat (limited to 'meetingtools/ac')
-rw-r--r--meetingtools/ac/api.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/meetingtools/ac/api.py b/meetingtools/ac/api.py
index 6f0d994..5594d75 100644
--- a/meetingtools/ac/api.py
+++ b/meetingtools/ac/api.py
@@ -4,6 +4,7 @@ Created on Jan 31, 2011
@author: leifj
'''
from StringIO import StringIO
+import hashlib
from django.core.cache import get_cache
import httplib2
from urllib import quote_plus
@@ -109,7 +110,25 @@ class ACPClient():
def __enter__(self):
return self
-
+ class CacheWrapper():
+
+ def __init__(self,cache):
+ self._cache = cache
+
+ def _shorten(self,key):
+ h = hashlib.sha1()
+ h.update(key)
+ return h.hexdigest()
+
+ def add(self, key, value, timeout=0):
+ return self._cache.add(self._shorten(key),value)
+
+ def get(self, key, default=None):
+ return self._cache.get(self._shorten(key),default)
+
+ def set(self, key, value, timeout=0):
+ return self._cache.set(self._shorten(key),value)
+
def request(self,method,p={},raise_error=False):
self.age += 1
self.lastused = time.time()
@@ -124,7 +143,7 @@ class ACPClient():
u.append('%s=%s' % (k,quote_plus(value.encode("utf-8"))))
url = self.url + '?' + '&'.join(u)
- cache = get_cache('default')
+ cache = ACPClient.CacheWrapper(get_cache('default'))
h = httplib2.Http(cache,disable_ssl_certificate_validation=True);
logging.debug(url)
resp, content = h.request(url, "GET")