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

Function parse_template

tools/python-3.11.9-amd64/Lib/re/_parser.py:1006–1097  ·  view source on GitHub ↗
(source, state)

Source from the content-addressed store, hash-verified

1004 return p
1005
1006def parse_template(source, state):
1007 # parse 're' replacement string into list of literals and
1008 # group references
1009 s = Tokenizer(source)
1010 sget = s.get
1011 groups = []
1012 literals = []
1013 literal = []
1014 lappend = literal.append
1015 def addgroup(index, pos):
1016 if index > state.groups:
1017 raise s.error("invalid group reference %d" % index, pos)
1018 if literal:
1019 literals.append(''.join(literal))
1020 del literal[:]
1021 groups.append((len(literals), index))
1022 literals.append(None)
1023 groupindex = state.groupindex
1024 while True:
1025 this = sget()
1026 if this is None:
1027 break # end of replacement string
1028 if this[0] == "\\":
1029 # group
1030 c = this[1]
1031 if c == "g":
1032 if not s.match("<"):
1033 raise s.error("missing <")
1034 name = s.getuntil(">", "group name")
1035 if name.isidentifier():
1036 s.checkgroupname(name, 1, -1)
1037 try:
1038 index = groupindex[name]
1039 except KeyError:
1040 raise IndexError("unknown group name %r" % name) from None
1041 else:
1042 try:
1043 index = int(name)
1044 if index < 0:
1045 raise ValueError
1046 except ValueError:
1047 raise s.error("bad character in group name %r" % name,
1048 len(name) + 1) from None
1049 if index >= MAXGROUPS:
1050 raise s.error("invalid group reference %d" % index,
1051 len(name) + 1)
1052 if not (name.isdecimal() and name.isascii()):
1053 import warnings
1054 warnings.warn(
1055 "bad character in group name %s at position %d" %
1056 (repr(name) if s.istext else ascii(name),
1057 s.tell() - len(name) - 1),
1058 DeprecationWarning, stacklevel=5
1059 )
1060 addgroup(index, len(name) + 1)
1061 elif c == "0":
1062 if s.next in OCTDIGITS:
1063 this += sget()

Callers

nothing calls this directly

Calls 15

matchMethod · 0.95
errorMethod · 0.95
getuntilMethod · 0.95
checkgroupnameMethod · 0.95
tellMethod · 0.95
TokenizerClass · 0.85
asciiFunction · 0.85
addgroupFunction · 0.85
isidentifierMethod · 0.80
isdecimalMethod · 0.80
isasciiMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected