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

Class TimeRE

Lib/_strptime.py:340–493  ·  view source on GitHub ↗

Handle conversion from format directives to regexes.

Source from the content-addressed store, hash-verified

338
339
340class TimeRE(dict):
341 """Handle conversion from format directives to regexes."""
342
343 def __init__(self, locale_time=None):
344 """Create keys/values.
345
346 Order of execution is important for dependency reasons.
347
348 """
349 if locale_time:
350 self.locale_time = locale_time
351 else:
352 self.locale_time = LocaleTime()
353 base = super()
354 mapping = {
355 # The " [1-9]" part of the regex is to make %c from ANSI C work
356 'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
357 'f': r"(?P<f>[0-9]{1,6})",
358 'H': r"(?P<H>2[0-3]|[0-1]\d|\d| \d)",
359 'k': r"(?P<H>2[0-3]|[0-1]\d|\d| \d)",
360 'I': r"(?P<I>1[0-2]|0[1-9]|[1-9]| [1-9])",
361 'l': r"(?P<I>1[0-2]|0[1-9]|[1-9]| [1-9])",
362 'G': r"(?P<G>\d\d\d\d)",
363 'j': r"(?P<j>36[0-6]|3[0-5]\d|[1-2]\d\d|0[1-9]\d|00[1-9]|[1-9]\d|0[1-9]|[1-9])",
364 'm': r"(?P<m>1[0-2]|0[1-9]|[1-9])",
365 'M': r"(?P<M>[0-5]\d|\d)",
366 'S': r"(?P<S>6[0-1]|[0-5]\d|\d)",
367 'U': r"(?P<U>5[0-3]|[0-4]\d|\d)",
368 'w': r"(?P<w>[0-6])",
369 'u': r"(?P<u>[1-7])",
370 'V': r"(?P<V>5[0-3]|0[1-9]|[1-4]\d|\d)",
371 # W is set below by using 'U'
372 'y': r"(?P<y>\d\d)",
373 'Y': r"(?P<Y>\d\d\d\d)",
374 # See gh-121237: "z" must support colons for backwards compatibility.
375 'z': r"(?P<z>([+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?)|(?-i:Z))?",
376 ':z': r"(?P<colon_z>([+-]\d\d:[0-5]\d(:[0-5]\d(\.\d{1,6})?)?)|(?-i:Z))?",
377 'A': self.__seqToRE(self.locale_time.f_weekday, 'A'),
378 'a': self.__seqToRE(self.locale_time.a_weekday, 'a'),
379 'B': self.__seqToRE(_fixmonths(self.locale_time.f_month[1:]), 'B'),
380 'b': self.__seqToRE(_fixmonths(self.locale_time.a_month[1:]), 'b'),
381 'p': self.__seqToRE(self.locale_time.am_pm, 'p'),
382 'Z': self.__seqToRE((tz for tz_names in self.locale_time.timezone
383 for tz in tz_names),
384 'Z'),
385 'n': r'\s*',
386 't': r'\s*',
387 '%': '%',
388 }
389 if self.locale_time.LC_alt_digits is None:
390 for d in 'dmyCHIMS':
391 mapping['O' + d] = r'(?P<%s>\d\d|\d| \d)' % d
392 mapping['Ow'] = r'(?P<w>\d)'
393 else:
394 mapping.update({
395 'Od': self.__seqToRE(self.locale_time.LC_alt_digits[1:32], 'd',
396 '3[0-1]|[1-2][0-9]|0[1-9]|[1-9]'),
397 'Om': self.__seqToRE(self.locale_time.LC_alt_digits[1:13], 'm',

Callers 2

_strptime.pyFile · 0.85
_strptimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…