summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2005-02-10 18:33:30 (GMT)
committerFred Drake <fdrake@acm.org>2005-02-10 18:33:30 (GMT)
commitba613c3410c5a0ff547e43d2e9cdd9ffff1fca54 (patch)
treec58837f84f4915095cdf13393d0be4a0c7dcfdb4 /Lib/xmlrpclib.py
parentbfd7d6a0eac396d80efe43fa4f03e056ac57f58d (diff)
downloadcpython-ba613c3410c5a0ff547e43d2e9cdd9ffff1fca54.zip
cpython-ba613c3410c5a0ff547e43d2e9cdd9ffff1fca54.tar.gz
cpython-ba613c3410c5a0ff547e43d2e9cdd9ffff1fca54.tar.bz2
accept datetime.datetime instances when marshalling;
dateTime.iso8601 elements still unmarshal into xmlrpclib.DateTime objects
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 7b68196..21cc3d0 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -149,6 +149,11 @@ except NameError:
unicode = None # unicode support not available
try:
+ import datetime
+except ImportError:
+ datetime = None
+
+try:
_bool_is_builtin = False.__class__.__name__ == "bool"
except NameError:
_bool_is_builtin = 0
@@ -349,7 +354,10 @@ class DateTime:
def __init__(self, value=0):
if not isinstance(value, StringType):
- if not isinstance(value, (TupleType, time.struct_time)):
+ if datetime and isinstance(value, datetime.datetime):
+ self.value = value.strftime("%Y%m%dT%H:%M:%S")
+ return
+ elif not isinstance(value, (TupleType, time.struct_time)):
if value == 0:
value = time.time()
value = time.localtime(value)
@@ -699,6 +707,13 @@ class Marshaller:
del self.memo[i]
dispatch[DictType] = dump_struct
+ if datetime:
+ def dump_datetime(self, value, write):
+ write("<value><dateTime.iso8601>")
+ write(value.strftime("%Y%m%dT%H:%M:%S"))
+ write("</dateTime.iso8601></value>\n")
+ dispatch[datetime.datetime] = dump_datetime
+
def dump_instance(self, value, write):
# check for special wrappers
if value.__class__ in WRAPPERS: