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

Method __seqToRE

Lib/_strptime.py:433–451  ·  view source on GitHub ↗

Convert a list to a regex string for matching a directive. Want possible matching values to be from longest to shortest. This prevents the possibility of a match occurring for a value that also a substring of a larger value that should have matched (e.g., 'abc' matc

(self, to_convert, directive, altregex=None)

Source from the content-addressed store, hash-verified

431 base.__setitem__('c', self.pattern(self.locale_time.LC_date_time))
432
433 def __seqToRE(self, to_convert, directive, altregex=None):
434 """Convert a list to a regex string for matching a directive.
435
436 Want possible matching values to be from longest to shortest. This
437 prevents the possibility of a match occurring for a value that also
438 a substring of a larger value that should have matched (e.g., 'abc'
439 matching when 'abcdef' should have been the match).
440
441 """
442 to_convert = sorted(to_convert, key=len, reverse=True)
443 for value in to_convert:
444 if value != '':
445 break
446 else:
447 return ''
448 regex = '|'.join(re_escape(stuff) for stuff in to_convert)
449 if altregex is not None:
450 regex += '|' + altregex
451 return '(?P<%s>%s)' % (directive, regex)
452
453 def pattern(self, format):
454 """Return regex pattern for the format string.

Callers 1

__init__Method · 0.95

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected