diff options
author | Victor Stinner <vstinner@python.org> | 2023-06-14 15:00:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 15:00:40 (GMT) |
commit | 307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba (patch) | |
tree | 28e9348487d8452d982253ef5c2cdfb868964691 /Lib/xmlrpc | |
parent | 7b1f0f204a785485de1daf9d26828a81953537e4 (diff) | |
download | cpython-307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba.zip cpython-307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba.tar.gz cpython-307bceaa65c4f1a8e110cd7a9cce6e93a1b021ba.tar.bz2 |
xmlrpc.client uses datetime.datetime.isoformat() (#105741)
Reimplement _iso8601_format() using the datetime isoformat() method.
Ignore the timezone.
Co-Authored-by: Paul Ganssle <1377457+pganssle@users.noreply.github.com>
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r-- | Lib/xmlrpc/client.py | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index ea8da76..f441376 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -245,41 +245,15 @@ class Fault(Error): ## # Backwards compatibility - boolean = Boolean = bool -## -# Wrapper for XML-RPC DateTime values. This converts a time value to -# the format used by XML-RPC. -# <p> -# The value can be given as a datetime object, as a string in the -# format "yyyymmddThh:mm:ss", as a 9-item time tuple (as returned by -# time.localtime()), or an integer value (as returned by time.time()). -# The wrapper uses time.localtime() to convert an integer to a time -# tuple. -# -# @param value The time, given as a datetime object, an ISO 8601 string, -# a time tuple, or an integer time value. - -# Issue #13305: different format codes across platforms -_day0 = datetime(1, 1, 1) -def _try(fmt): - try: - return _day0.strftime(fmt) == '0001' - except ValueError: - return False -if _try('%Y'): # Mac OS X - def _iso8601_format(value): - return value.strftime("%Y%m%dT%H:%M:%S") -elif _try('%4Y'): # Linux - def _iso8601_format(value): - return value.strftime("%4Y%m%dT%H:%M:%S") -else: - def _iso8601_format(value): - return value.strftime("%Y%m%dT%H:%M:%S").zfill(17) -del _day0 -del _try +def _iso8601_format(value): + if value.tzinfo is not None: + # XML-RPC only uses the naive portion of the datetime + value = value.replace(tzinfo=None) + # XML-RPC doesn't use '-' separator in the date part + return value.isoformat(timespec='seconds').replace('-', '') def _strftime(value): |