Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1319954?usp=email )
Change subject: [bugfix] Support custom Timestamp ISO separators
......................................................................
[bugfix] Support custom Timestamp ISO separators
Pass the requested separator to the ISO 8601 parser and escape it when
building the regular expression. This restores round-trip compatibility
between Timestamp.isoformat() and Timestamp.fromISOformat() for arbitrary
one-character separators.
Bug: T396723
Change-Id: Id0e01793dec13beb644393dbcbce750cf04b086a
---
M pywikibot/time.py
M tests/time_tests.py
2 files changed, 6 insertions(+), 4 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/time.py b/pywikibot/time.py
index e345f95..0603390 100644
--- a/pywikibot/time.py
+++ b/pywikibot/time.py
@@ -133,7 +133,8 @@
return cls.strptime(timestr, cls.mediawikiTSFormat)
@classmethod
- def _from_iso8601(cls, timestr: str) -> Timestamp:
+ def _from_iso8601(cls, timestr: str,
+ separators: str = 'T ') -> Timestamp:
"""Convert a string in ISO8601 format to a Timestamp object.
ISO8601 format:
@@ -141,7 +142,8 @@
.. version-added:: 7.5
"""
- RE_ISO8601 = (r'(?:\d{4}-\d{2}-\d{2})(?P<sep>[T ])' # noqa: N806
+ RE_ISO8601 = (rf'(?:\d{{4}}-\d{{2}}-\d{{2}})' # noqa: N806
+ rf'(?P<sep>[{re.escape(separators)}])'
r'(?:\d{2}:\d{2}:\d{2})(?P<u>[.,]\d{1,6})?'
r'(?P<tz>Z|[+\-]\d{2}:?\d{,2})?'
)
@@ -253,7 +255,8 @@
f'ts argument must be a string or a Timestamp object,'
f' not {type(ts).__name__}')
- return cls._from_iso8601(f'{ts[:10]}{sep}{ts[11:]}')
+ assert len(sep) == 1
+ return cls._from_iso8601(ts, sep)
@classmethod
def fromtimestampformat(cls,
diff --git a/tests/time_tests.py b/tests/time_tests.py
index e0e1967..0a90bef 100755
--- a/tests/time_tests.py
+++ b/tests/time_tests.py
@@ -163,7 +163,6 @@
self.assertEqual(date, str(t1.date()))
self.assertEqual(time, str(t1.time()))
- @unittest.expectedFailure # T396723
def test_iso_format_with_sep(self) -> None:
"""Test conversion from and to ISO format with separator."""
sep = '*'
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1319954?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id0e01793dec13beb644393dbcbce750cf04b086a
Gerrit-Change-Number: 1319954
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]