summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/sre_parse.py
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/tools/python3/src/Lib/sre_parse.py
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/sre_parse.py')
-rw-r--r--contrib/tools/python3/src/Lib/sre_parse.py104
1 files changed, 52 insertions, 52 deletions
diff --git a/contrib/tools/python3/src/Lib/sre_parse.py b/contrib/tools/python3/src/Lib/sre_parse.py
index 83119168e63..c98218e3d85 100644
--- a/contrib/tools/python3/src/Lib/sre_parse.py
+++ b/contrib/tools/python3/src/Lib/sre_parse.py
@@ -71,8 +71,8 @@ GLOBAL_FLAGS = SRE_FLAG_DEBUG | SRE_FLAG_TEMPLATE
class Verbose(Exception):
pass
-class State:
- # keeps track of state for parsing
+class State:
+ # keeps track of state for parsing
def __init__(self):
self.flags = 0
self.groupdict = {}
@@ -108,8 +108,8 @@ class State:
class SubPattern:
# a subpattern, in intermediate form
- def __init__(self, state, data=None):
- self.state = state
+ def __init__(self, state, data=None):
+ self.state = state
if data is None:
data = []
self.data = data
@@ -163,7 +163,7 @@ class SubPattern:
del self.data[index]
def __getitem__(self, index):
if isinstance(index, slice):
- return SubPattern(self.state, self.data[index])
+ return SubPattern(self.state, self.data[index])
return self.data[index]
def __setitem__(self, index, code):
self.data[index] = code
@@ -202,7 +202,7 @@ class SubPattern:
lo = lo + 1
hi = hi + 1
elif op is GROUPREF:
- i, j = self.state.groupwidths[av]
+ i, j = self.state.groupwidths[av]
lo = lo + i
hi = hi + j
elif op is GROUPREF_EXISTS:
@@ -264,19 +264,19 @@ class Tokenizer:
result += c
self.__next()
return result
- def getuntil(self, terminator, name):
+ def getuntil(self, terminator, name):
result = ''
while True:
c = self.next
self.__next()
if c is None:
if not result:
- raise self.error("missing " + name)
+ raise self.error("missing " + name)
raise self.error("missing %s, unterminated name" % terminator,
len(result))
if c == terminator:
if not result:
- raise self.error("missing " + name, 1)
+ raise self.error("missing " + name, 1)
break
result += c
return result
@@ -322,18 +322,18 @@ def _class_escape(source, escape):
c = int(escape[2:], 16)
chr(c) # raise ValueError for invalid code
return LITERAL, c
- elif c == "N" and source.istext:
- import unicodedata
- # named unicode escape e.g. \N{EM DASH}
- if not source.match('{'):
- raise source.error("missing {")
- charname = source.getuntil('}', 'character name')
- try:
- c = ord(unicodedata.lookup(charname))
- except KeyError:
- raise source.error("undefined character name %r" % charname,
- len(charname) + len(r'\N{}'))
- return LITERAL, c
+ elif c == "N" and source.istext:
+ import unicodedata
+ # named unicode escape e.g. \N{EM DASH}
+ if not source.match('{'):
+ raise source.error("missing {")
+ charname = source.getuntil('}', 'character name')
+ try:
+ c = ord(unicodedata.lookup(charname))
+ except KeyError:
+ raise source.error("undefined character name %r" % charname,
+ len(charname) + len(r'\N{}'))
+ return LITERAL, c
elif c in OCTDIGITS:
# octal escape (up to three digits)
escape += source.getwhile(2, OCTDIGITS)
@@ -382,18 +382,18 @@ def _escape(source, escape, state):
c = int(escape[2:], 16)
chr(c) # raise ValueError for invalid code
return LITERAL, c
- elif c == "N" and source.istext:
- import unicodedata
- # named unicode escape e.g. \N{EM DASH}
- if not source.match('{'):
- raise source.error("missing {")
- charname = source.getuntil('}', 'character name')
- try:
- c = ord(unicodedata.lookup(charname))
- except KeyError:
- raise source.error("undefined character name %r" % charname,
- len(charname) + len(r'\N{}'))
- return LITERAL, c
+ elif c == "N" and source.istext:
+ import unicodedata
+ # named unicode escape e.g. \N{EM DASH}
+ if not source.match('{'):
+ raise source.error("missing {")
+ charname = source.getuntil('}', 'character name')
+ try:
+ c = ord(unicodedata.lookup(charname))
+ except KeyError:
+ raise source.error("undefined character name %r" % charname,
+ len(charname) + len(r'\N{}'))
+ return LITERAL, c
elif c == "0":
# octal escape
escape += source.getwhile(2, OCTDIGITS)
@@ -430,7 +430,7 @@ def _escape(source, escape, state):
raise source.error("bad escape %s" % escape, len(escape))
def _uniq(items):
- return list(dict.fromkeys(items))
+ return list(dict.fromkeys(items))
def _parse_sub(source, state, verbose, nested):
# parse an alternation: a|b|c
@@ -697,13 +697,13 @@ def _parse(source, state, verbose, nested, first=False):
# python extensions
if sourcematch("<"):
# named group: skip forward to end of name
- name = source.getuntil(">", "group name")
+ name = source.getuntil(">", "group name")
if not name.isidentifier():
msg = "bad character in group name %r" % name
raise source.error(msg, len(name) + 1)
elif sourcematch("="):
# named backreference
- name = source.getuntil(")", "group name")
+ name = source.getuntil(")", "group name")
if not name.isidentifier():
msg = "bad character in group name %r" % name
raise source.error(msg, len(name) + 1)
@@ -766,7 +766,7 @@ def _parse(source, state, verbose, nested, first=False):
elif char == "(":
# conditional backreference group
- condname = source.getuntil(")", "group name")
+ condname = source.getuntil(")", "group name")
if condname.isidentifier():
condgroup = state.groupdict.get(condname)
if condgroup is None:
@@ -934,28 +934,28 @@ def fix_flags(src, flags):
raise ValueError("ASCII and LOCALE flags are incompatible")
return flags
-def parse(str, flags=0, state=None):
+def parse(str, flags=0, state=None):
# parse 're' pattern into list of (opcode, argument) tuples
source = Tokenizer(str)
- if state is None:
- state = State()
- state.flags = flags
- state.str = str
+ if state is None:
+ state = State()
+ state.flags = flags
+ state.str = str
try:
- p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
+ p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
except Verbose:
# the VERBOSE flag was switched on inside the pattern. to be
# on the safe side, we'll parse the whole thing again...
- state = State()
- state.flags = flags | SRE_FLAG_VERBOSE
- state.str = str
+ state = State()
+ state.flags = flags | SRE_FLAG_VERBOSE
+ state.str = str
source.seek(0)
- p = _parse_sub(source, state, True, 0)
+ p = _parse_sub(source, state, True, 0)
- p.state.flags = fix_flags(str, p.state.flags)
+ p.state.flags = fix_flags(str, p.state.flags)
if source.next is not None:
assert source.next == ")"
@@ -966,7 +966,7 @@ def parse(str, flags=0, state=None):
return p
-def parse_template(source, state):
+def parse_template(source, state):
# parse 're' replacement string into list of literals and
# group references
s = Tokenizer(source)
@@ -976,14 +976,14 @@ def parse_template(source, state):
literal = []
lappend = literal.append
def addgroup(index, pos):
- if index > state.groups:
+ if index > state.groups:
raise s.error("invalid group reference %d" % index, pos)
if literal:
literals.append(''.join(literal))
del literal[:]
groups.append((len(literals), index))
literals.append(None)
- groupindex = state.groupindex
+ groupindex = state.groupindex
while True:
this = sget()
if this is None:
@@ -995,7 +995,7 @@ def parse_template(source, state):
name = ""
if not s.match("<"):
raise s.error("missing <")
- name = s.getuntil(">", "group name")
+ name = s.getuntil(">", "group name")
if name.isidentifier():
try:
index = groupindex[name]