summaryrefslogtreecommitdiffstats
path: root/Lib/xmlrpc
diff options
context:
space:
mode:
authorrtobar <rtobarc@gmail.com>2021-10-13 16:38:36 (GMT)
committerGitHub <noreply@github.com>2021-10-13 16:38:36 (GMT)
commit1c831353816ff699b54e804047a7242a09e98f5b (patch)
tree81c43dd0c8a7a0e3202f86e77849cbf4efb4c70c /Lib/xmlrpc
parent3dee0cb6217db326e844955a7f8b424c67990557 (diff)
downloadcpython-1c831353816ff699b54e804047a7242a09e98f5b.zip
cpython-1c831353816ff699b54e804047a7242a09e98f5b.tar.gz
cpython-1c831353816ff699b54e804047a7242a09e98f5b.tar.bz2
bpo-45386: Handle strftime's ValueError graciously in xmlrpc.client (GH-28765)
At import time, the xmlrpc.client module uses different date formats to test strftime so it can format years with 4 digits consistently. Depending on the underlying C library and its strftime implementation some of these calls can result in ValueErrors, blocking the xmlrpc.client module from being imported. This commit changes the behavior of this bit of code to react to ValueError exceptions, treating the format that caused them as an non-viable option.
Diffstat (limited to 'Lib/xmlrpc')
-rw-r--r--Lib/xmlrpc/client.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py
index 9e7449c..a614cef 100644
--- a/Lib/xmlrpc/client.py
+++ b/Lib/xmlrpc/client.py
@@ -264,16 +264,22 @@ boolean = Boolean = bool
# Issue #13305: different format codes across platforms
_day0 = datetime(1, 1, 1)
-if _day0.strftime('%Y') == '0001': # Mac OS X
+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 _day0.strftime('%4Y') == '0001': # Linux
+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 _strftime(value):