mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
13925 port fromisoformat from python 3.11
This commit is contained in:
@ -651,6 +651,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
def _parse_isoformat_date(self, dtstr):
|
def _parse_isoformat_date(self, dtstr):
|
||||||
# It is assumed that this is an ASCII-only string of lengths 7, 8 or 10,
|
# It is assumed that this is an ASCII-only string of lengths 7, 8 or 10,
|
||||||
# see the comment on Modules/_datetimemodule.c:_find_isoformat_datetime_separator
|
# see the comment on Modules/_datetimemodule.c:_find_isoformat_datetime_separator
|
||||||
|
# TODO: Remove when drop python 3.10
|
||||||
assert len(dtstr) in (7, 8, 10)
|
assert len(dtstr) in (7, 8, 10)
|
||||||
year = int(dtstr[0:4])
|
year = int(dtstr[0:4])
|
||||||
has_sep = dtstr[4] == '-'
|
has_sep = dtstr[4] == '-'
|
||||||
@ -732,11 +733,13 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
return time_comps
|
return time_comps
|
||||||
|
|
||||||
# Helpers for parsing the result of isoformat()
|
# Helpers for parsing the result of isoformat()
|
||||||
|
# TODO: Remove when drop python 3.10
|
||||||
def _is_ascii_digit(self, c):
|
def _is_ascii_digit(self, c):
|
||||||
return c in "0123456789"
|
return c in "0123456789"
|
||||||
|
|
||||||
def _find_isoformat_datetime_separator(self, dtstr):
|
def _find_isoformat_datetime_separator(self, dtstr):
|
||||||
# See the comment in _datetimemodule.c:_find_isoformat_datetime_separator
|
# See the comment in _datetimemodule.c:_find_isoformat_datetime_separator
|
||||||
|
# TODO: Remove when drop python 3.10
|
||||||
len_dtstr = len(dtstr)
|
len_dtstr = len(dtstr)
|
||||||
if len_dtstr == 7:
|
if len_dtstr == 7:
|
||||||
return 7
|
return 7
|
||||||
@ -793,6 +796,7 @@ class CustomField(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|||||||
|
|
||||||
def fromisoformat(self, date_string):
|
def fromisoformat(self, date_string):
|
||||||
"""Construct a datetime from a string in one of the ISO 8601 formats."""
|
"""Construct a datetime from a string in one of the ISO 8601 formats."""
|
||||||
|
# TODO: Remove when drop python 3.10
|
||||||
if not isinstance(date_string, str):
|
if not isinstance(date_string, str):
|
||||||
raise TypeError('fromisoformat: argument must be str')
|
raise TypeError('fromisoformat: argument must be str')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user