From 2b7085c439a7529f776bead711a38110ce6e2907 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Tue, 21 May 2013 21:59:25 +0300 Subject: Do date conversions last --- gsxws/core.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'gsxws/core.py') diff --git a/gsxws/core.py b/gsxws/core.py index d85c72a..4733001 100644 --- a/gsxws/core.py +++ b/gsxws/core.py @@ -394,6 +394,14 @@ 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): + 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('/') @@ -404,19 +412,11 @@ class GsxObject(object): 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') - # convert Y and N to boolean - if re.search(r'^[YN]$', k): - v = (v == 'Y') - setattr(obj, k, v) return obj -- cgit v1.2.3