summaryrefslogtreecommitdiffstats
path: root/Lib/sre_compile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-11 19:13:28 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-11 19:13:28 (GMT)
commitab14088141ab749763e35b7a49e79c368940e12d (patch)
tree0369f9a136bfea659c24b0cf9fedf2ee98272308 /Lib/sre_compile.py
parent9a64ccb997a99f85c2538047823c7478bfcff6ed (diff)
downloadcpython-ab14088141ab749763e35b7a49e79c368940e12d.zip
cpython-ab14088141ab749763e35b7a49e79c368940e12d.tar.gz
cpython-ab14088141ab749763e35b7a49e79c368940e12d.tar.bz2
Minor code clean up and improvements in the re module.
Diffstat (limited to 'Lib/sre_compile.py')
-rw-r--r--Lib/sre_compile.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index f5aef7a..1241a01 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -16,11 +16,6 @@ from sre_constants import *
assert _sre.MAGIC == MAGIC, "SRE module mismatch"
-if _sre.CODESIZE == 2:
- MAXCODE = 65535
-else:
- MAXCODE = 0xFFFFFFFF
-
_LITERAL_CODES = {LITERAL, NOT_LITERAL}
_REPEATING_CODES = {REPEAT, MIN_REPEAT, MAX_REPEAT}
_SUCCESS_CODES = {SUCCESS, FAILURE}
@@ -191,7 +186,7 @@ def _compile(code, pattern, flags):
emit(JUMP)
tailappend(_len(code)); emit(0)
code[skip] = _len(code) - skip
- emit(0) # end of branch
+ emit(FAILURE) # end of branch
for tail in tail:
code[tail] = _len(code) - tail
elif op is CATEGORY:
@@ -374,6 +369,7 @@ def _optimize_charset(charset, fixup, fixes):
return out
_CODEBITS = _sre.CODESIZE * 8
+MAXCODE = (1 << _CODEBITS) - 1
_BITS_TRANS = b'0' + b'1' * 255
def _mk_bitmap(bits, _CODEBITS=_CODEBITS, _int=int):
s = bits.translate(_BITS_TRANS)[::-1]
@@ -477,9 +473,9 @@ def _compile_info(code, pattern, flags):
elif op is IN:
charset = av
## if prefix:
-## print "*** PREFIX", prefix, prefix_skip
+## print("*** PREFIX", prefix, prefix_skip)
## if charset:
-## print "*** CHARSET", charset
+## print("*** CHARSET", charset)
# add an info block
emit = code.append
emit(INFO)
@@ -489,9 +485,9 @@ def _compile_info(code, pattern, flags):
if prefix:
mask = SRE_INFO_PREFIX
if len(prefix) == prefix_skip == len(pattern.data):
- mask = mask + SRE_INFO_LITERAL
+ mask = mask | SRE_INFO_LITERAL
elif charset:
- mask = mask + SRE_INFO_CHARSET
+ mask = mask | SRE_INFO_CHARSET
emit(mask)
# pattern length
if lo < MAXCODE: