Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: sre_parse.py
#
[0] Fix | Delete
# Secret Labs' Regular Expression Engine
[1] Fix | Delete
#
[2] Fix | Delete
# convert re-style regular expression to sre pattern
[3] Fix | Delete
#
[4] Fix | Delete
# Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
[5] Fix | Delete
#
[6] Fix | Delete
# See the sre.py file for information on usage and redistribution.
[7] Fix | Delete
#
[8] Fix | Delete
[9] Fix | Delete
"""Internal support module for sre"""
[10] Fix | Delete
[11] Fix | Delete
# XXX: show string offset and offending character for all errors
[12] Fix | Delete
[13] Fix | Delete
from sre_constants import *
[14] Fix | Delete
[15] Fix | Delete
SPECIAL_CHARS = ".\\[{()*+?^$|"
[16] Fix | Delete
REPEAT_CHARS = "*+?{"
[17] Fix | Delete
[18] Fix | Delete
DIGITS = frozenset("0123456789")
[19] Fix | Delete
[20] Fix | Delete
OCTDIGITS = frozenset("01234567")
[21] Fix | Delete
HEXDIGITS = frozenset("0123456789abcdefABCDEF")
[22] Fix | Delete
ASCIILETTERS = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
[23] Fix | Delete
[24] Fix | Delete
WHITESPACE = frozenset(" \t\n\r\v\f")
[25] Fix | Delete
[26] Fix | Delete
_REPEATCODES = frozenset({MIN_REPEAT, MAX_REPEAT})
[27] Fix | Delete
_UNITCODES = frozenset({ANY, RANGE, IN, LITERAL, NOT_LITERAL, CATEGORY})
[28] Fix | Delete
[29] Fix | Delete
ESCAPES = {
[30] Fix | Delete
r"\a": (LITERAL, ord("\a")),
[31] Fix | Delete
r"\b": (LITERAL, ord("\b")),
[32] Fix | Delete
r"\f": (LITERAL, ord("\f")),
[33] Fix | Delete
r"\n": (LITERAL, ord("\n")),
[34] Fix | Delete
r"\r": (LITERAL, ord("\r")),
[35] Fix | Delete
r"\t": (LITERAL, ord("\t")),
[36] Fix | Delete
r"\v": (LITERAL, ord("\v")),
[37] Fix | Delete
r"\\": (LITERAL, ord("\\"))
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
CATEGORIES = {
[41] Fix | Delete
r"\A": (AT, AT_BEGINNING_STRING), # start of string
[42] Fix | Delete
r"\b": (AT, AT_BOUNDARY),
[43] Fix | Delete
r"\B": (AT, AT_NON_BOUNDARY),
[44] Fix | Delete
r"\d": (IN, [(CATEGORY, CATEGORY_DIGIT)]),
[45] Fix | Delete
r"\D": (IN, [(CATEGORY, CATEGORY_NOT_DIGIT)]),
[46] Fix | Delete
r"\s": (IN, [(CATEGORY, CATEGORY_SPACE)]),
[47] Fix | Delete
r"\S": (IN, [(CATEGORY, CATEGORY_NOT_SPACE)]),
[48] Fix | Delete
r"\w": (IN, [(CATEGORY, CATEGORY_WORD)]),
[49] Fix | Delete
r"\W": (IN, [(CATEGORY, CATEGORY_NOT_WORD)]),
[50] Fix | Delete
r"\Z": (AT, AT_END_STRING), # end of string
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
FLAGS = {
[54] Fix | Delete
# standard flags
[55] Fix | Delete
"i": SRE_FLAG_IGNORECASE,
[56] Fix | Delete
"L": SRE_FLAG_LOCALE,
[57] Fix | Delete
"m": SRE_FLAG_MULTILINE,
[58] Fix | Delete
"s": SRE_FLAG_DOTALL,
[59] Fix | Delete
"x": SRE_FLAG_VERBOSE,
[60] Fix | Delete
# extensions
[61] Fix | Delete
"a": SRE_FLAG_ASCII,
[62] Fix | Delete
"t": SRE_FLAG_TEMPLATE,
[63] Fix | Delete
"u": SRE_FLAG_UNICODE,
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
GLOBAL_FLAGS = (SRE_FLAG_ASCII | SRE_FLAG_LOCALE | SRE_FLAG_UNICODE |
[67] Fix | Delete
SRE_FLAG_DEBUG | SRE_FLAG_TEMPLATE)
[68] Fix | Delete
[69] Fix | Delete
class Verbose(Exception):
[70] Fix | Delete
pass
[71] Fix | Delete
[72] Fix | Delete
class Pattern:
[73] Fix | Delete
# master pattern object. keeps track of global attributes
[74] Fix | Delete
def __init__(self):
[75] Fix | Delete
self.flags = 0
[76] Fix | Delete
self.groupdict = {}
[77] Fix | Delete
self.groupwidths = [None] # group 0
[78] Fix | Delete
self.lookbehindgroups = None
[79] Fix | Delete
@property
[80] Fix | Delete
def groups(self):
[81] Fix | Delete
return len(self.groupwidths)
[82] Fix | Delete
def opengroup(self, name=None):
[83] Fix | Delete
gid = self.groups
[84] Fix | Delete
self.groupwidths.append(None)
[85] Fix | Delete
if self.groups > MAXGROUPS:
[86] Fix | Delete
raise error("too many groups")
[87] Fix | Delete
if name is not None:
[88] Fix | Delete
ogid = self.groupdict.get(name, None)
[89] Fix | Delete
if ogid is not None:
[90] Fix | Delete
raise error("redefinition of group name %r as group %d; "
[91] Fix | Delete
"was group %d" % (name, gid, ogid))
[92] Fix | Delete
self.groupdict[name] = gid
[93] Fix | Delete
return gid
[94] Fix | Delete
def closegroup(self, gid, p):
[95] Fix | Delete
self.groupwidths[gid] = p.getwidth()
[96] Fix | Delete
def checkgroup(self, gid):
[97] Fix | Delete
return gid < self.groups and self.groupwidths[gid] is not None
[98] Fix | Delete
[99] Fix | Delete
def checklookbehindgroup(self, gid, source):
[100] Fix | Delete
if self.lookbehindgroups is not None:
[101] Fix | Delete
if not self.checkgroup(gid):
[102] Fix | Delete
raise source.error('cannot refer to an open group')
[103] Fix | Delete
if gid >= self.lookbehindgroups:
[104] Fix | Delete
raise source.error('cannot refer to group defined in the same '
[105] Fix | Delete
'lookbehind subpattern')
[106] Fix | Delete
[107] Fix | Delete
class SubPattern:
[108] Fix | Delete
# a subpattern, in intermediate form
[109] Fix | Delete
def __init__(self, pattern, data=None):
[110] Fix | Delete
self.pattern = pattern
[111] Fix | Delete
if data is None:
[112] Fix | Delete
data = []
[113] Fix | Delete
self.data = data
[114] Fix | Delete
self.width = None
[115] Fix | Delete
def dump(self, level=0):
[116] Fix | Delete
nl = True
[117] Fix | Delete
seqtypes = (tuple, list)
[118] Fix | Delete
for op, av in self.data:
[119] Fix | Delete
print(level*" " + str(op), end='')
[120] Fix | Delete
if op is IN:
[121] Fix | Delete
# member sublanguage
[122] Fix | Delete
print()
[123] Fix | Delete
for op, a in av:
[124] Fix | Delete
print((level+1)*" " + str(op), a)
[125] Fix | Delete
elif op is BRANCH:
[126] Fix | Delete
print()
[127] Fix | Delete
for i, a in enumerate(av[1]):
[128] Fix | Delete
if i:
[129] Fix | Delete
print(level*" " + "OR")
[130] Fix | Delete
a.dump(level+1)
[131] Fix | Delete
elif op is GROUPREF_EXISTS:
[132] Fix | Delete
condgroup, item_yes, item_no = av
[133] Fix | Delete
print('', condgroup)
[134] Fix | Delete
item_yes.dump(level+1)
[135] Fix | Delete
if item_no:
[136] Fix | Delete
print(level*" " + "ELSE")
[137] Fix | Delete
item_no.dump(level+1)
[138] Fix | Delete
elif isinstance(av, seqtypes):
[139] Fix | Delete
nl = False
[140] Fix | Delete
for a in av:
[141] Fix | Delete
if isinstance(a, SubPattern):
[142] Fix | Delete
if not nl:
[143] Fix | Delete
print()
[144] Fix | Delete
a.dump(level+1)
[145] Fix | Delete
nl = True
[146] Fix | Delete
else:
[147] Fix | Delete
if not nl:
[148] Fix | Delete
print(' ', end='')
[149] Fix | Delete
print(a, end='')
[150] Fix | Delete
nl = False
[151] Fix | Delete
if not nl:
[152] Fix | Delete
print()
[153] Fix | Delete
else:
[154] Fix | Delete
print('', av)
[155] Fix | Delete
def __repr__(self):
[156] Fix | Delete
return repr(self.data)
[157] Fix | Delete
def __len__(self):
[158] Fix | Delete
return len(self.data)
[159] Fix | Delete
def __delitem__(self, index):
[160] Fix | Delete
del self.data[index]
[161] Fix | Delete
def __getitem__(self, index):
[162] Fix | Delete
if isinstance(index, slice):
[163] Fix | Delete
return SubPattern(self.pattern, self.data[index])
[164] Fix | Delete
return self.data[index]
[165] Fix | Delete
def __setitem__(self, index, code):
[166] Fix | Delete
self.data[index] = code
[167] Fix | Delete
def insert(self, index, code):
[168] Fix | Delete
self.data.insert(index, code)
[169] Fix | Delete
def append(self, code):
[170] Fix | Delete
self.data.append(code)
[171] Fix | Delete
def getwidth(self):
[172] Fix | Delete
# determine the width (min, max) for this subpattern
[173] Fix | Delete
if self.width is not None:
[174] Fix | Delete
return self.width
[175] Fix | Delete
lo = hi = 0
[176] Fix | Delete
for op, av in self.data:
[177] Fix | Delete
if op is BRANCH:
[178] Fix | Delete
i = MAXREPEAT - 1
[179] Fix | Delete
j = 0
[180] Fix | Delete
for av in av[1]:
[181] Fix | Delete
l, h = av.getwidth()
[182] Fix | Delete
i = min(i, l)
[183] Fix | Delete
j = max(j, h)
[184] Fix | Delete
lo = lo + i
[185] Fix | Delete
hi = hi + j
[186] Fix | Delete
elif op is CALL:
[187] Fix | Delete
i, j = av.getwidth()
[188] Fix | Delete
lo = lo + i
[189] Fix | Delete
hi = hi + j
[190] Fix | Delete
elif op is SUBPATTERN:
[191] Fix | Delete
i, j = av[-1].getwidth()
[192] Fix | Delete
lo = lo + i
[193] Fix | Delete
hi = hi + j
[194] Fix | Delete
elif op in _REPEATCODES:
[195] Fix | Delete
i, j = av[2].getwidth()
[196] Fix | Delete
lo = lo + i * av[0]
[197] Fix | Delete
hi = hi + j * av[1]
[198] Fix | Delete
elif op in _UNITCODES:
[199] Fix | Delete
lo = lo + 1
[200] Fix | Delete
hi = hi + 1
[201] Fix | Delete
elif op is GROUPREF:
[202] Fix | Delete
i, j = self.pattern.groupwidths[av]
[203] Fix | Delete
lo = lo + i
[204] Fix | Delete
hi = hi + j
[205] Fix | Delete
elif op is GROUPREF_EXISTS:
[206] Fix | Delete
i, j = av[1].getwidth()
[207] Fix | Delete
if av[2] is not None:
[208] Fix | Delete
l, h = av[2].getwidth()
[209] Fix | Delete
i = min(i, l)
[210] Fix | Delete
j = max(j, h)
[211] Fix | Delete
else:
[212] Fix | Delete
i = 0
[213] Fix | Delete
lo = lo + i
[214] Fix | Delete
hi = hi + j
[215] Fix | Delete
elif op is SUCCESS:
[216] Fix | Delete
break
[217] Fix | Delete
self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
[218] Fix | Delete
return self.width
[219] Fix | Delete
[220] Fix | Delete
class Tokenizer:
[221] Fix | Delete
def __init__(self, string):
[222] Fix | Delete
self.istext = isinstance(string, str)
[223] Fix | Delete
self.string = string
[224] Fix | Delete
if not self.istext:
[225] Fix | Delete
string = str(string, 'latin1')
[226] Fix | Delete
self.decoded_string = string
[227] Fix | Delete
self.index = 0
[228] Fix | Delete
self.next = None
[229] Fix | Delete
self.__next()
[230] Fix | Delete
def __next(self):
[231] Fix | Delete
index = self.index
[232] Fix | Delete
try:
[233] Fix | Delete
char = self.decoded_string[index]
[234] Fix | Delete
except IndexError:
[235] Fix | Delete
self.next = None
[236] Fix | Delete
return
[237] Fix | Delete
if char == "\\":
[238] Fix | Delete
index += 1
[239] Fix | Delete
try:
[240] Fix | Delete
char += self.decoded_string[index]
[241] Fix | Delete
except IndexError:
[242] Fix | Delete
raise error("bad escape (end of pattern)",
[243] Fix | Delete
self.string, len(self.string) - 1) from None
[244] Fix | Delete
self.index = index + 1
[245] Fix | Delete
self.next = char
[246] Fix | Delete
def match(self, char):
[247] Fix | Delete
if char == self.next:
[248] Fix | Delete
self.__next()
[249] Fix | Delete
return True
[250] Fix | Delete
return False
[251] Fix | Delete
def get(self):
[252] Fix | Delete
this = self.next
[253] Fix | Delete
self.__next()
[254] Fix | Delete
return this
[255] Fix | Delete
def getwhile(self, n, charset):
[256] Fix | Delete
result = ''
[257] Fix | Delete
for _ in range(n):
[258] Fix | Delete
c = self.next
[259] Fix | Delete
if c not in charset:
[260] Fix | Delete
break
[261] Fix | Delete
result += c
[262] Fix | Delete
self.__next()
[263] Fix | Delete
return result
[264] Fix | Delete
def getuntil(self, terminator):
[265] Fix | Delete
result = ''
[266] Fix | Delete
while True:
[267] Fix | Delete
c = self.next
[268] Fix | Delete
self.__next()
[269] Fix | Delete
if c is None:
[270] Fix | Delete
if not result:
[271] Fix | Delete
raise self.error("missing group name")
[272] Fix | Delete
raise self.error("missing %s, unterminated name" % terminator,
[273] Fix | Delete
len(result))
[274] Fix | Delete
if c == terminator:
[275] Fix | Delete
if not result:
[276] Fix | Delete
raise self.error("missing group name", 1)
[277] Fix | Delete
break
[278] Fix | Delete
result += c
[279] Fix | Delete
return result
[280] Fix | Delete
@property
[281] Fix | Delete
def pos(self):
[282] Fix | Delete
return self.index - len(self.next or '')
[283] Fix | Delete
def tell(self):
[284] Fix | Delete
return self.index - len(self.next or '')
[285] Fix | Delete
def seek(self, index):
[286] Fix | Delete
self.index = index
[287] Fix | Delete
self.__next()
[288] Fix | Delete
[289] Fix | Delete
def error(self, msg, offset=0):
[290] Fix | Delete
return error(msg, self.string, self.tell() - offset)
[291] Fix | Delete
[292] Fix | Delete
def _class_escape(source, escape):
[293] Fix | Delete
# handle escape code inside character class
[294] Fix | Delete
code = ESCAPES.get(escape)
[295] Fix | Delete
if code:
[296] Fix | Delete
return code
[297] Fix | Delete
code = CATEGORIES.get(escape)
[298] Fix | Delete
if code and code[0] is IN:
[299] Fix | Delete
return code
[300] Fix | Delete
try:
[301] Fix | Delete
c = escape[1:2]
[302] Fix | Delete
if c == "x":
[303] Fix | Delete
# hexadecimal escape (exactly two digits)
[304] Fix | Delete
escape += source.getwhile(2, HEXDIGITS)
[305] Fix | Delete
if len(escape) != 4:
[306] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[307] Fix | Delete
return LITERAL, int(escape[2:], 16)
[308] Fix | Delete
elif c == "u" and source.istext:
[309] Fix | Delete
# unicode escape (exactly four digits)
[310] Fix | Delete
escape += source.getwhile(4, HEXDIGITS)
[311] Fix | Delete
if len(escape) != 6:
[312] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[313] Fix | Delete
return LITERAL, int(escape[2:], 16)
[314] Fix | Delete
elif c == "U" and source.istext:
[315] Fix | Delete
# unicode escape (exactly eight digits)
[316] Fix | Delete
escape += source.getwhile(8, HEXDIGITS)
[317] Fix | Delete
if len(escape) != 10:
[318] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[319] Fix | Delete
c = int(escape[2:], 16)
[320] Fix | Delete
chr(c) # raise ValueError for invalid code
[321] Fix | Delete
return LITERAL, c
[322] Fix | Delete
elif c in OCTDIGITS:
[323] Fix | Delete
# octal escape (up to three digits)
[324] Fix | Delete
escape += source.getwhile(2, OCTDIGITS)
[325] Fix | Delete
c = int(escape[1:], 8)
[326] Fix | Delete
if c > 0o377:
[327] Fix | Delete
raise source.error('octal escape value %s outside of '
[328] Fix | Delete
'range 0-0o377' % escape, len(escape))
[329] Fix | Delete
return LITERAL, c
[330] Fix | Delete
elif c in DIGITS:
[331] Fix | Delete
raise ValueError
[332] Fix | Delete
if len(escape) == 2:
[333] Fix | Delete
if c in ASCIILETTERS:
[334] Fix | Delete
raise source.error('bad escape %s' % escape, len(escape))
[335] Fix | Delete
return LITERAL, ord(escape[1])
[336] Fix | Delete
except ValueError:
[337] Fix | Delete
pass
[338] Fix | Delete
raise source.error("bad escape %s" % escape, len(escape))
[339] Fix | Delete
[340] Fix | Delete
def _escape(source, escape, state):
[341] Fix | Delete
# handle escape code in expression
[342] Fix | Delete
code = CATEGORIES.get(escape)
[343] Fix | Delete
if code:
[344] Fix | Delete
return code
[345] Fix | Delete
code = ESCAPES.get(escape)
[346] Fix | Delete
if code:
[347] Fix | Delete
return code
[348] Fix | Delete
try:
[349] Fix | Delete
c = escape[1:2]
[350] Fix | Delete
if c == "x":
[351] Fix | Delete
# hexadecimal escape
[352] Fix | Delete
escape += source.getwhile(2, HEXDIGITS)
[353] Fix | Delete
if len(escape) != 4:
[354] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[355] Fix | Delete
return LITERAL, int(escape[2:], 16)
[356] Fix | Delete
elif c == "u" and source.istext:
[357] Fix | Delete
# unicode escape (exactly four digits)
[358] Fix | Delete
escape += source.getwhile(4, HEXDIGITS)
[359] Fix | Delete
if len(escape) != 6:
[360] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[361] Fix | Delete
return LITERAL, int(escape[2:], 16)
[362] Fix | Delete
elif c == "U" and source.istext:
[363] Fix | Delete
# unicode escape (exactly eight digits)
[364] Fix | Delete
escape += source.getwhile(8, HEXDIGITS)
[365] Fix | Delete
if len(escape) != 10:
[366] Fix | Delete
raise source.error("incomplete escape %s" % escape, len(escape))
[367] Fix | Delete
c = int(escape[2:], 16)
[368] Fix | Delete
chr(c) # raise ValueError for invalid code
[369] Fix | Delete
return LITERAL, c
[370] Fix | Delete
elif c == "0":
[371] Fix | Delete
# octal escape
[372] Fix | Delete
escape += source.getwhile(2, OCTDIGITS)
[373] Fix | Delete
return LITERAL, int(escape[1:], 8)
[374] Fix | Delete
elif c in DIGITS:
[375] Fix | Delete
# octal escape *or* decimal group reference (sigh)
[376] Fix | Delete
if source.next in DIGITS:
[377] Fix | Delete
escape += source.get()
[378] Fix | Delete
if (escape[1] in OCTDIGITS and escape[2] in OCTDIGITS and
[379] Fix | Delete
source.next in OCTDIGITS):
[380] Fix | Delete
# got three octal digits; this is an octal escape
[381] Fix | Delete
escape += source.get()
[382] Fix | Delete
c = int(escape[1:], 8)
[383] Fix | Delete
if c > 0o377:
[384] Fix | Delete
raise source.error('octal escape value %s outside of '
[385] Fix | Delete
'range 0-0o377' % escape,
[386] Fix | Delete
len(escape))
[387] Fix | Delete
return LITERAL, c
[388] Fix | Delete
# not an octal escape, so this is a group reference
[389] Fix | Delete
group = int(escape[1:])
[390] Fix | Delete
if group < state.groups:
[391] Fix | Delete
if not state.checkgroup(group):
[392] Fix | Delete
raise source.error("cannot refer to an open group",
[393] Fix | Delete
len(escape))
[394] Fix | Delete
state.checklookbehindgroup(group, source)
[395] Fix | Delete
return GROUPREF, group
[396] Fix | Delete
raise source.error("invalid group reference %d" % group, len(escape) - 1)
[397] Fix | Delete
if len(escape) == 2:
[398] Fix | Delete
if c in ASCIILETTERS:
[399] Fix | Delete
raise source.error("bad escape %s" % escape, len(escape))
[400] Fix | Delete
return LITERAL, ord(escape[1])
[401] Fix | Delete
except ValueError:
[402] Fix | Delete
pass
[403] Fix | Delete
raise source.error("bad escape %s" % escape, len(escape))
[404] Fix | Delete
[405] Fix | Delete
def _parse_sub(source, state, verbose, nested):
[406] Fix | Delete
# parse an alternation: a|b|c
[407] Fix | Delete
[408] Fix | Delete
items = []
[409] Fix | Delete
itemsappend = items.append
[410] Fix | Delete
sourcematch = source.match
[411] Fix | Delete
start = source.tell()
[412] Fix | Delete
while True:
[413] Fix | Delete
itemsappend(_parse(source, state, verbose, nested + 1,
[414] Fix | Delete
not nested and not items))
[415] Fix | Delete
if not sourcematch("|"):
[416] Fix | Delete
break
[417] Fix | Delete
[418] Fix | Delete
if len(items) == 1:
[419] Fix | Delete
return items[0]
[420] Fix | Delete
[421] Fix | Delete
subpattern = SubPattern(state)
[422] Fix | Delete
subpatternappend = subpattern.append
[423] Fix | Delete
[424] Fix | Delete
# check if all items share a common prefix
[425] Fix | Delete
while True:
[426] Fix | Delete
prefix = None
[427] Fix | Delete
for item in items:
[428] Fix | Delete
if not item:
[429] Fix | Delete
break
[430] Fix | Delete
if prefix is None:
[431] Fix | Delete
prefix = item[0]
[432] Fix | Delete
elif item[0] != prefix:
[433] Fix | Delete
break
[434] Fix | Delete
else:
[435] Fix | Delete
# all subitems start with a common "prefix".
[436] Fix | Delete
# move it out of the branch
[437] Fix | Delete
for item in items:
[438] Fix | Delete
del item[0]
[439] Fix | Delete
subpatternappend(prefix)
[440] Fix | Delete
continue # check next one
[441] Fix | Delete
break
[442] Fix | Delete
[443] Fix | Delete
# check if the branch can be replaced by a character set
[444] Fix | Delete
for item in items:
[445] Fix | Delete
if len(item) != 1 or item[0][0] is not LITERAL:
[446] Fix | Delete
break
[447] Fix | Delete
else:
[448] Fix | Delete
# we can store this as a character set instead of a
[449] Fix | Delete
# branch (the compiler may optimize this even more)
[450] Fix | Delete
subpatternappend((IN, [item[0] for item in items]))
[451] Fix | Delete
return subpattern
[452] Fix | Delete
[453] Fix | Delete
subpattern.append((BRANCH, (None, items)))
[454] Fix | Delete
return subpattern
[455] Fix | Delete
[456] Fix | Delete
def _parse_sub_cond(source, state, condgroup, verbose, nested):
[457] Fix | Delete
item_yes = _parse(source, state, verbose, nested + 1)
[458] Fix | Delete
if source.match("|"):
[459] Fix | Delete
item_no = _parse(source, state, verbose, nested + 1)
[460] Fix | Delete
if source.next == "|":
[461] Fix | Delete
raise source.error("conditional backref with more than two branches")
[462] Fix | Delete
else:
[463] Fix | Delete
item_no = None
[464] Fix | Delete
subpattern = SubPattern(state)
[465] Fix | Delete
subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no)))
[466] Fix | Delete
return subpattern
[467] Fix | Delete
[468] Fix | Delete
def _parse(source, state, verbose, nested, first=False):
[469] Fix | Delete
# parse a simple pattern
[470] Fix | Delete
subpattern = SubPattern(state)
[471] Fix | Delete
[472] Fix | Delete
# precompute constants into local variables
[473] Fix | Delete
subpatternappend = subpattern.append
[474] Fix | Delete
sourceget = source.get
[475] Fix | Delete
sourcematch = source.match
[476] Fix | Delete
_len = len
[477] Fix | Delete
_ord = ord
[478] Fix | Delete
[479] Fix | Delete
while True:
[480] Fix | Delete
[481] Fix | Delete
this = source.next
[482] Fix | Delete
if this is None:
[483] Fix | Delete
break # end of pattern
[484] Fix | Delete
if this in "|)":
[485] Fix | Delete
break # end of subpattern
[486] Fix | Delete
sourceget()
[487] Fix | Delete
[488] Fix | Delete
if verbose:
[489] Fix | Delete
# skip whitespace and comments
[490] Fix | Delete
if this in WHITESPACE:
[491] Fix | Delete
continue
[492] Fix | Delete
if this == "#":
[493] Fix | Delete
while True:
[494] Fix | Delete
this = sourceget()
[495] Fix | Delete
if this is None or this == "\n":
[496] Fix | Delete
break
[497] Fix | Delete
continue
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function