aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@230.to>2013-07-16 16:44:20 +0300
committerFilipp Lepalaan <f@230.to>2013-07-16 16:44:20 +0300
commit4d9c2b0a47dd9336d9df7222013ade0c1763856d (patch)
tree02b83107c49f555b7b86116347560d96d004c0e8
parent4961dbd10c80ac963bb76fd358342fbb981134ce (diff)
downloadpy-gsxws-4d9c2b0a47dd9336d9df7222013ade0c1763856d.tar.gz
py-gsxws-4d9c2b0a47dd9336d9df7222013ade0c1763856d.tar.bz2
py-gsxws-4d9c2b0a47dd9336d9df7222013ade0c1763856d.zip
Return date in standard format in GsxDateElement.__repr__
-rw-r--r--gsxws/objectify.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/gsxws/objectify.py b/gsxws/objectify.py
index f1dd7ae..fd6ceda 100644
--- a/gsxws/objectify.py
+++ b/gsxws/objectify.py
@@ -4,7 +4,7 @@ import os
import re
import base64
import tempfile
-from lxml import objectify
+from lxml import objectify, etree
from lxml.objectify import StringElement
from datetime import datetime
@@ -57,6 +57,9 @@ class GsxDateElement(GsxElement):
except (ValueError, TypeError):
pass
+ def __repr__(self):
+ return str(datetime.strftime(self.pyval, '%Y-%m-%d'))
+
class GsxBooleanElement(GsxElement):
@property
@@ -95,7 +98,7 @@ class GsxTimestampElement(GsxElement):
return datetime.strptime(self.text, "%d-%b-%y %H:%M:%S")
-class GsxClassLookup(objectify.ObjectifyElementClassLookup):
+class GsxClassLookup(etree.CustomElementClassLookup):
def lookup(self, node_type, document, namespace, name):
if name == 'dispatchSentDate':
return GsxDatetimeElement
@@ -116,7 +119,7 @@ class GsxClassLookup(objectify.ObjectifyElementClassLookup):
def parse(root, response):
"""
>>> parse('../tests/warranty_status.xml', 'warrantyDetailInfo').estimatedPurchaseDate
- Sdt7tXp2XytTEVwHBeDx6lHTXI3w9s+M
+ 2010-08-25
"""
parser = objectify.makeparser(remove_blank_text=True)
parser.set_element_class_lookup(GsxClassLookup())