diff options
author | Filipp Lepalaan <f@0x00.co> | 2013-01-10 10:58:10 +0200 |
---|---|---|
committer | Filipp Lepalaan <f@0x00.co> | 2013-01-10 10:58:10 +0200 |
commit | f1f5728949f9eabbb77e487d60f41d77d59285c6 (patch) | |
tree | cedec1d881add4ec30305b05dea84046d7d6bb4e /gsx.py | |
parent | 572cc5d53b6908dd4492f7ac1b9520494c03bc11 (diff) | |
download | py-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.tar.gz py-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.tar.bz2 py-gsxws-f1f5728949f9eabbb77e487d60f41d77d59285c6.zip |
Added _process(), langs.json
Diffstat (limited to 'gsx.py')
-rwxr-xr-x | gsx.py | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -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): """ |