Skip to content

Commit ebe5552

Browse files
qingshi163youknowone
authored andcommitted
Replace Lib/sre_* from CPython
1 parent 280337a commit ebe5552

File tree

6 files changed

+27
-2065
lines changed

6 files changed

+27
-2065
lines changed

Lib/re/_compiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def _compile(code, pattern, flags):
101101
else:
102102
emit(ANY)
103103
elif op in REPEATING_CODES:
104+
if flags & SRE_FLAG_TEMPLATE:
105+
raise error("internal: unsupported template operator %r" % (op,))
104106
if _simple(av[2]):
105107
emit(REPEATING_CODES[op][2])
106108
skip = _len(code); emit(0)
@@ -761,3 +763,4 @@ def compile(p, flags=0):
761763
p.state.groups-1,
762764
groupindex, tuple(indexgroup)
763765
)
766+

Lib/re/_constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# update when constants are added or removed
1515

16-
MAGIC = 20230612
16+
MAGIC = 20221023
1717

1818
from _sre import MAXREPEAT, MAXGROUPS
1919

@@ -204,6 +204,7 @@ def _makecodes(*names):
204204
}
205205

206206
# flags
207+
SRE_FLAG_TEMPLATE = 1 # template mode (unknown purpose, deprecated)
207208
SRE_FLAG_IGNORECASE = 2 # case insensitive
208209
SRE_FLAG_LOCALE = 4 # honour system locale
209210
SRE_FLAG_MULTILINE = 8 # treat target as multiline string
@@ -217,3 +218,4 @@ def _makecodes(*names):
217218
SRE_INFO_PREFIX = 1 # has prefix
218219
SRE_INFO_LITERAL = 2 # entire pattern is literal (given by prefix)
219220
SRE_INFO_CHARSET = 4 # pattern starts with character from given set
221+
RE_INFO_CHARSET = 4 # pattern starts with character from given set

Lib/re/_parser.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@
6161
"x": SRE_FLAG_VERBOSE,
6262
# extensions
6363
"a": SRE_FLAG_ASCII,
64+
"t": SRE_FLAG_TEMPLATE,
6465
"u": SRE_FLAG_UNICODE,
6566
}
6667

6768
TYPE_FLAGS = SRE_FLAG_ASCII | SRE_FLAG_LOCALE | SRE_FLAG_UNICODE
68-
GLOBAL_FLAGS = SRE_FLAG_DEBUG
69+
GLOBAL_FLAGS = SRE_FLAG_DEBUG | SRE_FLAG_TEMPLATE
6970

7071
# Maximal value returned by SubPattern.getwidth().
7172
# Must be larger than MAXREPEAT, MAXCODE and sys.maxsize.
@@ -780,10 +781,8 @@ def _parse(source, state, verbose, nested, first=False):
780781
source.tell() - start)
781782
if char == "=":
782783
subpatternappend((ASSERT, (dir, p)))
783-
elif p:
784-
subpatternappend((ASSERT_NOT, (dir, p)))
785784
else:
786-
subpatternappend((FAILURE, ()))
785+
subpatternappend((ASSERT_NOT, (dir, p)))
787786
continue
788787

789788
elif char == "(":

0 commit comments

Comments
 (0)