aboutsummaryrefslogtreecommitdiffstats
path: root/gsxws.py
diff options
context:
space:
mode:
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)