MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / pattern

Method pattern

tools/python-3.11.9-amd64/Lib/_strptime.py:238–259  ·  view source on GitHub ↗

Return regex pattern for the format string. Need to make sure that any characters that might be interpreted as regex syntax are escaped.

(self, format)

Source from the content-addressed store, hash-verified

236 return '%s)' % regex
237
238 def pattern(self, format):
239 """Return regex pattern for the format string.
240
241 Need to make sure that any characters that might be interpreted as
242 regex syntax are escaped.
243
244 """
245 processed_format = ''
246 # The sub() call escapes all characters that might be misconstrued
247 # as regex syntax. Cannot use re.escape since we have to deal with
248 # format directives (%m, etc.).
249 regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
250 format = regex_chars.sub(r"\\\1", format)
251 whitespace_replacement = re_compile(r'\s+')
252 format = whitespace_replacement.sub(r'\\s+', format)
253 while '%' in format:
254 directive_index = format.index('%')+1
255 processed_format = "%s%s%s" % (processed_format,
256 format[:directive_index-1],
257 self[format[directive_index]])
258 format = format[directive_index+1:]
259 return "%s%s" % (processed_format, format)
260
261 def compile(self, format):
262 """Return a compiled re object for the format string."""

Callers 2

__init__Method · 0.95
compileMethod · 0.95

Calls 2

subMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected