aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@0x00.co>2013-04-04 09:04:26 +0300
committerFilipp Lepalaan <f@0x00.co>2013-04-04 09:04:26 +0300
commitae3069ee23473b5cc3573b5ab90fa4b026805c70 (patch)
tree518354743237d5f5288599190c97d55ae96479ad /gsxws.py
parentd43266f3f34350c16ee7ffdb16584af114e66394 (diff)
downloadpy-gsxws-ae3069ee23473b5cc3573b5ab90fa4b026805c70.tar.gz
py-gsxws-ae3069ee23473b5cc3573b5ab90fa4b026805c70.tar.bz2
py-gsxws-ae3069ee23473b5cc3573b5ab90fa4b026805c70.zip
Use ObjectCache for GSX sessions
Diffstat (limited to 'gsxws.py')
-rwxr-xr-xgsxws.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/gsxws.py b/gsxws.py
index 6062d48..fcbb2b7 100755
--- a/gsxws.py
+++ b/gsxws.py
@@ -28,6 +28,7 @@ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMA
import re
import os
+import md5
import json
import suds
import base64
@@ -37,6 +38,7 @@ import urlparse
import tempfile
from suds.client import Client
+from suds.cache import ObjectCache
import xml.etree.ElementTree as ET
from datetime import datetime, date, time
@@ -44,6 +46,7 @@ from datetime import datetime, date, time
CLIENT = None
SESSION = dict()
LOCALE = 'en_XXX'
+CACHE = ObjectCache(minutes=20)
TIMEZONES = (
('GMT', 'UTC (Greenwich Mean Time)'),
@@ -918,12 +921,20 @@ def connect(
Returns the session ID of the new connection.
"""
- global SESSION
+ global CACHE
global LOCALE
+ global SESSION
SESSION = {}
LOCALE = LOCALE
+ cache_key = md5.new(user_id + sold_to).hexdigest()
+
+ if CACHE.get(cache_key) is not None:
+ SESSION = CACHE.get(cache_key)
+ init(environment, region)
+ return SESSION
+
init(environment, region)
account = CLIENT.factory.create('ns3:authenticateRequestType')
@@ -937,6 +948,7 @@ def connect(
try:
result = CLIENT.service.Authenticate(account)
SESSION['userSessionId'] = result.userSessionId
+ CACHE.put(cache_key, SESSION)
return SESSION
except suds.WebFault, e:
raise GsxError(fault=e)