summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpclib.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/xmlrpclib.py')
-rw-r--r--Lib/xmlrpclib.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 2e68a1b..522df4d 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -287,6 +287,20 @@ boolean = Boolean = bool
# @param value The time, given as an ISO 8601 string, a time
# tuple, or a integer time value.
+def _strftime(value):
+ if datetime:
+ if isinstance(value, datetime.datetime):
+ return "%04d%02d%02dT%02d:%02d:%02d" % (
+ value.year, value.month, value.day,
+ value.hour, value.minute, value.second)
+
+ if not isinstance(value, (tuple, time.struct_time)):
+ if value == 0:
+ value = time.time()
+ value = time.localtime(value)
+
+ return "%04d%02d%02dT%02d:%02d:%02d" % value[:6]
+
class DateTime:
"""DateTime wrapper for an ISO 8601 string or time tuple or
localtime integer value to generate 'dateTime.iso8601' XML-RPC
@@ -294,16 +308,10 @@ class DateTime:
"""
def __init__(self, value=0):
- if not isinstance(value, str):
- if datetime and isinstance(value, datetime.datetime):
- self.value = value.strftime("%Y%m%dT%H:%M:%S")
- return
- if not isinstance(value, (tuple, time.struct_time)):
- if value == 0:
- value = time.time()
- value = time.localtime(value)
- value = time.strftime("%Y%m%dT%H:%M:%S", value)
- self.value = value
+ if isinstance(value, str):
+ self.value = value
+ else:
+ self.value = _strftime(value)
def make_comparable(self, other):
if isinstance(other, DateTime):
@@ -700,7 +708,7 @@ class Marshaller:
if datetime:
def dump_datetime(self, value, write):
write("<value><dateTime.iso8601>")
- write(value.strftime("%Y%m%dT%H:%M:%S"))
+ write(_strftime(value))
write("</dateTime.iso8601></value>\n")
dispatch[datetime.datetime] = dump_datetime