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

Function _compile_info

Lib/re/_compiler.py:525–585  ·  view source on GitHub ↗
(code, pattern, flags)

Source from the content-addressed store, hash-verified

523 return None
524
525def _compile_info(code, pattern, flags):
526 # internal: compile an info block. in the current version,
527 # this contains min/max pattern width, and an optional literal
528 # prefix or a character map
529 lo, hi = pattern.getwidth()
530 if hi > MAXCODE:
531 hi = MAXCODE
532 if lo == 0:
533 code.extend([INFO, 4, 0, lo, hi])
534 return
535 # look for a literal prefix
536 prefix = []
537 prefix_skip = 0
538 charset = None # not used
539 if not (flags & SRE_FLAG_IGNORECASE and flags & SRE_FLAG_LOCALE):
540 # look for literal prefix
541 prefix, prefix_skip, got_all = _get_literal_prefix(pattern, flags)
542 # if no prefix, look for charset prefix
543 if not prefix:
544 charset = _get_charset_prefix(pattern, flags)
545 if charset:
546 charset, hascased = _optimize_charset(charset)
547 assert not hascased
548 if charset == _CHARSET_ALL:
549 charset = None
550## if prefix:
551## print("*** PREFIX", prefix, prefix_skip)
552## if charset:
553## print("*** CHARSET", charset)
554 # add an info block
555 emit = code.append
556 emit(INFO)
557 skip = len(code); emit(0)
558 # literal flag
559 mask = 0
560 if prefix:
561 mask = SRE_INFO_PREFIX
562 if prefix_skip is None and got_all:
563 mask = mask | SRE_INFO_LITERAL
564 elif charset:
565 mask = mask | SRE_INFO_CHARSET
566 emit(mask)
567 # pattern length
568 if lo < MAXCODE:
569 emit(lo)
570 else:
571 emit(MAXCODE)
572 prefix = prefix[:MAXCODE]
573 emit(hi)
574 # add literal prefix
575 if prefix:
576 emit(len(prefix)) # length
577 if prefix_skip is None:
578 prefix_skip = len(prefix)
579 emit(prefix_skip) # skip
580 code.extend(prefix)
581 # generate overlap table
582 code.extend(_generate_overlap_table(prefix))

Callers 1

_codeFunction · 0.85

Calls 7

_get_literal_prefixFunction · 0.85
_get_charset_prefixFunction · 0.85
_optimize_charsetFunction · 0.85
_generate_overlap_tableFunction · 0.85
_compile_charsetFunction · 0.85
getwidthMethod · 0.80
extendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…