Ports: Patch Python to deal with Serenity's strftime

The xmlrpc.client module has some trial-and-error logic at module import
time to figure out how to properly format years using strftime. There
have already been problems in the past with this code in Python (see
https://bugs.python.org/issue13305, which is still open), and Serenity
only adds to that.

This problem has been reported at https://bugs.python.org/issue45386, so
hopefully in time we won't need this patch anymore.
This commit is contained in:
Rodrigo Tobar 2021-10-06 14:39:46 +08:00 committed by Linus Groh
parent c38c93bff1
commit c3a6d96988
2 changed files with 31 additions and 0 deletions

View file

@ -27,3 +27,7 @@ Make some tweaks to Python's `setup.py` files:
- Add `/usr/local/lib` / `/usr/local/include` to the system lib / include dirs, relative to the sysroot when crosscompiling. These are by default only included when not crosscompiling for some reason.
- Add `/usr/local/include/ncurses` to the curses include paths so it can build the `_curses` module. This is by default included for a bunch of extensions, but not `_curses`.
- Add `/usr/local/includes/uuid` to the uuid include paths so it can build the `_uuid` module. This is by default included for a bunch of extensions, but not `_uuid`.
## `xmlrcp_client.patch`
Fix xmlrpc.client module so it can be imported. It otherwise a call to strftime raises a ValueError that the code is not prepared to handle.

View file

@ -0,0 +1,27 @@
--- Python-3.10.0/Lib/xmlrpc/client.py 2021-10-06 14:28:27.231681509 +0800
+++ Python-3.10.0/Lib/xmlrpc/client.py 2021-10-06 14:31:01.712267885 +0800
@@ -264,16 +264,22 @@
# 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):