diff options
Diffstat (limited to 'gsxws')
-rw-r--r-- | gsxws/core.py | 40 | ||||
-rw-r--r-- | gsxws/products.py | 2 |
2 files changed, 27 insertions, 15 deletions
diff --git a/gsxws/core.py b/gsxws/core.py index 4733001..da82314 100644 --- a/gsxws/core.py +++ b/gsxws/core.py @@ -394,34 +394,46 @@ class GsxObject(object): v = unicode(v) # "must be unicode, not str" - # strip currency prefix and munge into float - if re.search(r'Price$', k): - v = float(re.sub(r'[A-Z ,]', '', v)) - # convert Y and N to boolean - if re.search(r'^[YN]$', k): + if re.search(r'^[YN]$', v): v = (v == 'Y') - # convert dates to native Python type ("mm/dd/yy") - if re.search(r'^\d{2}/\d{2}/\d{2}$', v): - m, d, y = v.split('/') - v = date(2000+int(y), int(m), int(d)) - - # seems that some dates are in the format "yyyy-mm-dd" - if re.search(r'^\d{4}-\d{2}-\d{2}$', v): - y, m, d = v.split('-') - v = date(int(y), int(m), int(d)) + # strip currency prefix and munge into float + if re.search(r'Price$', k): + v = float(re.sub(r'[A-Z ,]', '', v)) # Convert timestamps to native Python type # 18-Jan-13 14:38:04 if re.search(r'TimeStamp$', k): v = datetime.strptime(v, '%d-%b-%y %H:%M:%S') + if re.search(r'Date$', k): + # looks like some sort of date, let's try to convert + # @TODO: return actual native dates, not isoformat() + try: + # standard GSX format: "mm/dd/yy" + dt = datetime.strptime(v, "%m/%d/%y") + v = dt.date().isoformat() + except ValueError: + pass + + try: + # some dates are formatted as "yyyy-mm-dd" + dt = datetime.strptime(v, "%Y-%m-%d") + v = dt.date().isoformat() + except (ValueError, TypeError): + pass + setattr(obj, k, v) return obj +class GsxRequestObject(GsxObject): + "The GSX-friendly representation of this GsxObject" + pass + + class GsxSession(GsxObject): userId = "" diff --git a/gsxws/products.py b/gsxws/products.py index 38f5b01..04d3fee 100644 --- a/gsxws/products.py +++ b/gsxws/products.py @@ -100,7 +100,7 @@ class Product(GsxObject): >>> Product('013348005376007').activation().unlocked 'true' - >>> Product('W874939YX92').get_activation().unlocked # doctest: +ELLIPSIS + >>> Product('W874939YX92').activation().unlocked # doctest: +ELLIPSIS Traceback (most recent call last): ... GsxError: Provided serial number does not belong to an iOS Device... |