MCPcopy Index your code
hub / github.com/python/cpython / _find_isoformat_datetime_separator

Function _find_isoformat_datetime_separator

Lib/_pydatetime.py:301–355  ·  view source on GitHub ↗
(dtstr)

Source from the content-addressed store, hash-verified

299 return c in "0123456789"
300
301def _find_isoformat_datetime_separator(dtstr):
302 # See the comment in _datetimemodule.c:_find_isoformat_datetime_separator
303 len_dtstr = len(dtstr)
304 if len_dtstr == 7:
305 return 7
306
307 assert len_dtstr > 7
308 date_separator = "-"
309 week_indicator = "W"
310
311 if dtstr[4] == date_separator:
312 if dtstr[5] == week_indicator:
313 if len_dtstr < 8:
314 raise ValueError("Invalid ISO string")
315 if len_dtstr > 8 and dtstr[8] == date_separator:
316 if len_dtstr == 9:
317 raise ValueError("Invalid ISO string")
318 if len_dtstr > 10 and _is_ascii_digit(dtstr[10]):
319 # This is as far as we need to resolve the ambiguity for
320 # the moment - if we have YYYY-Www-##, the separator is
321 # either a hyphen at 8 or a number at 10.
322 #
323 # We'll assume it's a hyphen at 8 because it's way more
324 # likely that someone will use a hyphen as a separator than
325 # a number, but at this point it's really best effort
326 # because this is an extension of the spec anyway.
327 # TODO(pganssle): Document this
328 return 8
329 return 10
330 else:
331 # YYYY-Www (8)
332 return 8
333 else:
334 # YYYY-MM-DD (10)
335 return 10
336 else:
337 if dtstr[4] == week_indicator:
338 # YYYYWww (7) or YYYYWwwd (8)
339 idx = 7
340 while idx < len_dtstr:
341 if not _is_ascii_digit(dtstr[idx]):
342 break
343 idx += 1
344
345 if idx < 9:
346 return idx
347
348 if idx % 2 == 0:
349 # If the index of the last number is even, it's YYYYWwwd
350 return 7
351 else:
352 return 8
353 else:
354 # YYYYMMDD (8)
355 return 8
356
357
358def _parse_isoformat_date(dtstr):

Callers 1

fromisoformatMethod · 0.85

Calls 1

_is_ascii_digitFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…