8000 xmlrpc.client uses datetime.datetime.isoformat() by vstinner · Pull Request #105741 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

xmlrpc.client uses datetime.datetime.isoformat() #105741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
xmlrpc.client uses datetime.datetime.isoformat()
Reimplement _iso8601_format() using the datetime isoformat() method.
  • Loading branch information
vstinner committed Jun 13, 2023
commit 58411db7caf8bd2930c31fb64f05f62224cd7767
35 changes: 3 additions & 32 deletions Lib/xmlrpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,41 +245,12 @@ def __repr__(self):

##
# Backwards compatibility

boolean = Boolean = bool

##
# Wrapper for XML-RPC DateTime values. This converts a time value to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that this comment is outdated, since it seems like _iso8601_format defined below does not accept strings or time tuples...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was surprised by this comment. It looks outdated, _iso8601_format() is now only called with datetime.datetime instances.

# 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):
# XML-RPC doesn't use '-' separator in the date part
return value.isoformat(timespec='seconds').replace('-', '')


def _strftime(value):
Expand Down
0