mirror of https://github.com/python/cpython
resolve issue 2014
This commit is contained in:
parent
08923177b4
commit
b131f0468f
|
@ -55,6 +55,17 @@ class XMLRPCTestCase(unittest.TestCase):
|
|||
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
|
||||
self.assertEquals(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
|
||||
|
||||
def test_datetime_before_1900(self):
|
||||
# same as before but with an date before 1900
|
||||
dt = datetime.datetime(1, 02, 10, 11, 41, 23)
|
||||
s = xmlrpclib.dumps((dt,))
|
||||
(newdt,), m = xmlrpclib.loads(s, use_datetime=1)
|
||||
self.assertEquals(newdt, dt)
|
||||
self.assertEquals(m, None)
|
||||
|
||||
(newdt,), m = xmlrpclib.loads(s, use_datetime=0)
|
||||
self.assertEquals(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
|
||||
|
||||
def test_cmp_datetime_DateTime(self):
|
||||
now = datetime.datetime.now()
|
||||
dt = xmlrpclib.DateTime(now.timetuple())
|
||||
|
|
|
@ -346,6 +346,20 @@ else:
|
|||
# @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, (TupleType, 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
|
||||
|
@ -353,16 +367,10 @@ class DateTime:
|
|||
"""
|
||||
|
||||
def __init__(self, value=0):
|
||||
if not isinstance(value, StringType):
|
||||
if datetime and isinstance(value, datetime.datetime):
|
||||
self.value = value.strftime("%Y%m%dT%H:%M:%S")
|
||||
return
|
||||
if not isinstance(value, (TupleType, 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, StringType):
|
||||
self.value = value
|
||||
else:
|
||||
self.value = _strftime(value)
|
||||
|
||||
def make_comparable(self, other):
|
||||
if isinstance(other, DateTime):
|
||||
|
@ -772,7 +780,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
|
||||
|
||||
|
|
Loading…
Reference in New Issue