aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-06-03 19:53:54 +0300
committerFilipp Lepalaan <f@230.to>2013-06-03 19:53:54 +0300
commit8325735ef9d557f8d52825988daf2ebc9ae694d5 (patch)
tree6dd16e829447a9c503ca8e2374df51993ea3c6c6 /gsxws
parent2619ed1d7a7a1a83271a59a43d798115dd9f997c (diff)
downloadpy-gsxws-8325735ef9d557f8d52825988daf2ebc9ae694d5.tar.gz
py-gsxws-8325735ef9d557f8d52825988daf2ebc9ae694d5.tar.bz2
py-gsxws-8325735ef9d557f8d52825988daf2ebc9ae694d5.zip
Fixed some conflict
Diffstat (limited to 'gsxws')
-rw-r--r--gsxws/core.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/gsxws/core.py b/gsxws/core.py
index b6b237a..a49ea6f 100644
--- a/gsxws/core.py
+++ b/gsxws/core.py
@@ -145,40 +145,42 @@ class GsxError(Exception):
class GsxCache(object):
"""
- >>> GsxCache('spam').set('eggs').get()
+ The cache creates a separate shelf for each GSX session.
+
+ >>> GsxCache('test').set('spam', 'eggs').get('spam')
'eggs'
"""
shelf = None
tmpdir = tempfile.gettempdir()
- filename = os.path.join(tmpdir, "gsxws.tmp")
def __init__(self, key, expires=timedelta(minutes=20)):
self.key = key
self.expires = expires
self.now = datetime.now()
- self.shelf = shelve.open(self.filename, protocol=-1)
+ filename = os.path.join(self.tmpdir, "gsxws_%s.db" % key)
+ self.shelf = shelve.open(filename, protocol=-1)
if not self.shelf.get(key):
# Initialize the key
- self.set(None)
+ self.set(key, None)
- def get(self):
+ def get(self, key):
try:
- d = self.shelf[self.key]
+ d = self.shelf[key]
if d['expires'] > self.now:
return d['value']
else:
- del self.shelf[self.key]
+ del self.shelf[key]
except KeyError:
return None
- def set(self, value):
+ def set(self, key, value):
d = {
'value': value,
'expires': self.now + self.expires
}
- self.shelf[self.key] = d
+ self.shelf[key] = d
return self
@@ -465,14 +467,14 @@ class GsxSession(GsxObject):
def login(self):
global GSX_SESSION
- if not self._cache.get() is None:
- GSX_SESSION = self._cache.get()
+ if not self._cache.get("session") is None:
+ GSX_SESSION = self._cache.get("session")
else:
self._req = GsxRequest(AuthenticateRequest=self)
result = self._req._submit("Authenticate")
self._session_id = result[0].userSessionId
GSX_SESSION = self.get_session()
- self._cache.set(GSX_SESSION)
+ self._cache.set("session", GSX_SESSION)
return GSX_SESSION