[pypy-svn] r15547 - in pypy/dist: lib-python/modified-2.4.1 pypy/module/_sre
nik at codespeak.net
nik at codespeak.net
Wed Aug 3 11:24:10 CEST 2005
Author: nik
Date: Wed Aug 3 11:24:08 2005
New Revision: 15547
Modified:
pypy/dist/lib-python/modified-2.4.1/sre_constants.py
pypy/dist/pypy/module/_sre/app_sre.py
Log:
put hack for _sre faking on 2.3 back into place. sorry for breaking
translation with the integration yesterday, didn't think an app-level
MixedModule could affect it.
Modified: pypy/dist/lib-python/modified-2.4.1/sre_constants.py
==============================================================================
--- pypy/dist/lib-python/modified-2.4.1/sre_constants.py (original)
+++ pypy/dist/lib-python/modified-2.4.1/sre_constants.py Wed Aug 3 11:24:08 2005
@@ -129,13 +129,10 @@
# PyPy hack to make the sre_*.py files from 2.4.1 work on the _sre
# engine of 2.3.
-# XXX This hack doesn't work anymore because it creates a circular import
-# problem. Maybe think about a different hack, otherwise we're not able to run
-# faked _sre on CPython 2.3.
-#import _sre
-#if _sre.MAGIC < 20031017:
-# OPCODES.remove(GROUPREF_EXISTS)
-#del _sre
+import _sre
+if _sre.MAGIC < 20031017:
+ OPCODES.remove(GROUPREF_EXISTS)
+del _sre
ATCODES = [
AT_BEGINNING, AT_BEGINNING_LINE, AT_BEGINNING_STRING, AT_BOUNDARY,
Modified: pypy/dist/pypy/module/_sre/app_sre.py
==============================================================================
--- pypy/dist/pypy/module/_sre/app_sre.py (original)
+++ pypy/dist/pypy/module/_sre/app_sre.py Wed Aug 3 11:24:08 2005
@@ -8,8 +8,11 @@
"""
import array, operator, sys
-import sre_constants
-from sre_constants import ATCODES, OPCODES, CHCODES, MAXREPEAT
+# XXX Avoiding sre_constants import on module level to cater for a hack in
+# sre_constants concerned with _sre faking on 2.3. Fix this when _sre faking is
+# not an issue anymore.
+#import sre_constants
+#from sre_constants import ATCODES, OPCODES, CHCODES, MAXREPEAT
# Identifying as _sre from Python 2.3 or 2.4
if sys.version_info[:2] == (2, 4):
@@ -40,6 +43,7 @@
return SRE_Pattern(pattern, flags, code, groups, groupindex, indexgroup)
def getlower(char_ord, flags):
+ import sre_constants
if (char_ord < 128) or (flags & sre_constants.SRE_FLAG_UNICODE) \
or (flags & sre_constants.SRE_FLAG_LOCALE and char_ord < 256):
return ord(unichr(char_ord).lower())
@@ -365,6 +369,7 @@
return has_matched
def search(self, pattern_codes):
+ from sre_constants import OPCODES
if pattern_codes[0] == OPCODES["info"]:
pattern_codes = pattern_codes[pattern_codes[1] + 1:]
# XXX USE_FAST_SEARCH optimizations missing here
@@ -484,6 +489,8 @@
raise NotImplementedError()
def build_dispatch_table(cls, code_dict, method_prefix):
+ if cls.DISPATCH_TABLE is not None:
+ return
table = {}
for key, value in code_dict.items():
if hasattr(cls, "%s%s" % (method_prefix, key)):
@@ -497,10 +504,15 @@
def __init__(self):
self.executing_contexts = {}
+ from sre_constants import ATCODES, OPCODES, CHCODES
+ _OpcodeDispatcher.build_dispatch_table(OPCODES, "op_")
+ _AtcodeDispatcher.build_dispatch_table(ATCODES, "")
+ _ChcodeDispatcher.build_dispatch_table(CHCODES, "")
+ _CharsetDispatcher.build_dispatch_table(OPCODES, "set_")
self.at_dispatcher = _AtcodeDispatcher()
self.ch_dispatcher = _ChcodeDispatcher()
self.set_dispatcher = _CharsetDispatcher()
-
+
def match(self, context):
"""Returns True if the current context matches, False if it doesn't and
None if matching is not finished, ie must be resumed after child
@@ -694,6 +706,7 @@
# this operator only works if the repeated item is exactly one character
# wide, and we're not already collecting backtracking points.
# <REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail
+ from sre_constants import OPCODES
mincount = ctx.peek_code(2)
maxcount = ctx.peek_code(3)
#self._log(ctx, "REPEAT_ONE", mincount, maxcount)
@@ -735,6 +748,7 @@
def op_min_repeat_one(self, ctx):
# match repeated sequence (minimizing)
# <MIN_REPEAT_ONE> <skip> <1=min> <2=max> item <SUCCESS> tail
+ from sre_constants import OPCODES, MAXREPEAT
mincount = ctx.peek_code(2)
maxcount = ctx.peek_code(3)
#self._log(ctx, "MIN_REPEAT_ONE", mincount, maxcount)
@@ -793,6 +807,7 @@
def op_max_until(self, ctx):
# maximizing repeat
# <REPEAT> <skip> <1=min> <2=max> item <MAX_UNTIL> tail
+ from sre_constants import MAXREPEAT
repeat = ctx.state.repeat
if repeat is None:
raise RuntimeError("Internal re error: MAX_UNTIL without REPEAT.")
@@ -844,6 +859,7 @@
def op_min_until(self, ctx):
# minimizing repeat
# <REPEAT> <skip> <1=min> <2=max> item <MIN_UNTIL> tail
+ from sre_constants import MAXREPEAT
repeat = ctx.state.repeat
if repeat is None:
raise RuntimeError("Internal re error: MIN_UNTIL without REPEAT.")
@@ -975,6 +991,7 @@
"""Returns the number of repetitions of a single item, starting from the
current string position. The code pointer is expected to point to a
REPEAT_ONE operation (with the repeated 4 ahead)."""
+ from sre_constants import MAXREPEAT
count = 0
real_maxcount = ctx.state.end - ctx.string_position
if maxcount < real_maxcount and maxcount != MAXREPEAT:
@@ -1004,8 +1021,6 @@
_log("|%s|%s|%s %s" % (context.pattern_codes,
context.string_position, opname, arg_string))
-_OpcodeDispatcher.build_dispatch_table(OPCODES, "op_")
-
class _CharsetDispatcher(_Dispatcher):
@@ -1076,9 +1091,6 @@
return False
-_CharsetDispatcher.build_dispatch_table(OPCODES, "set_")
-
-
class _AtcodeDispatcher(_Dispatcher):
def at_beginning(self, ctx):
@@ -1107,8 +1119,6 @@
def unknown(self, ctx):
return False
-_AtcodeDispatcher.build_dispatch_table(ATCODES, "")
-
class _ChcodeDispatcher(_Dispatcher):
@@ -1151,8 +1161,6 @@
def unknown(self, ctx):
return False
-_ChcodeDispatcher.build_dispatch_table(CHCODES, "")
-
_ascii_char_info = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 6, 2,
2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
More information about the Pypy-commit
mailing list