aboutsummaryrefslogtreecommitdiffstats
path: root/gsx.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@0x00.co>2013-01-10 10:58:10 +0200
committerFilipp Lepalaan <f@0x00.co>2013-01-10 10:58:10 +0200
commitf1f5728949f9eabbb77e487d60f41d77d59285c6 (patch)
treecedec1d881add4ec30305b05dea84046d7d6bb4e /gsx.py
parent572cc5d53b6908dd4492f7ac1b9520494c03bc11 (diff)
downloadpy-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.tar.gz
py-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.tar.bz2
py-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.zip
Added _process(), langs.json
Diffstat (limited to 'gsx.py')
-rwxr-xr-xgsx.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/gsx.py b/gsx.py
index 2f42fcc..5adc33c 100755
--- a/gsx.py
+++ b/gsx.py
@@ -1,8 +1,9 @@
-#!/usr/bin/env python
#coding=utf-8
import re
+import base64
from suds.client import Client
+from datetime import date, time
import logging
logging.basicConfig(level=logging.INFO)
@@ -87,6 +88,29 @@ class GsxObject(object):
def __make_type(self, new_dt):
return CLIENT.factory.create(new_dt)
+ def _process(self, data):
+ """
+ Tries to coerce some types to their Python counterparts
+ """
+ for k, v in data:
+ # decode binary data
+ if k in ['packingList', 'proformaFileData', 'returnLabelFileData']:
+ v = base64.b64decode(v)
+
+ if isinstance(v, basestring):
+ # convert dates to native Python
+ if re.search('^\d{2}/\d{2}/\d{2}$', v):
+ m, d, y = v.split('/')
+ v = date(2000+int(y), int(m), int(d)).isoformat()
+
+ # strip currency prefix and munge into float
+ if re.search('Price$', k):
+ v = float(re.sub('[A-Z ,]', '', v))
+
+ setattr(data, k, v)
+
+ return data
+
class Lookup(GsxObject):
def parts(self):
"""
@@ -320,7 +344,7 @@ class Product(GsxObject):
"""
self.set_request('ns3:warrantyStatusRequestType', 'unitDetail')
result = self.submit('WarrantyStatus')
- return result.warrantyDetailInfo
+ return self._process(result.warrantyDetailInfo)
def get_activation(self):
"""