[pypy-svn] r52264 - in pypy/branch/buffer/pypy/module/_sre: . test
arigo at codespeak.net
arigo at codespeak.net
Fri Mar 7 19:11:30 CET 2008
Author: arigo
Date: Fri Mar 7 19:11:29 2008
New Revision: 52264
Modified:
pypy/branch/buffer/pypy/module/_sre/interp_sre.py
pypy/branch/buffer/pypy/module/_sre/test/test_app_sre.py
Log:
Use the buffer protocol in _sre.
Modified: pypy/branch/buffer/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/branch/buffer/pypy/module/_sre/interp_sre.py (original)
+++ pypy/branch/buffer/pypy/module/_sre/interp_sre.py Fri Mar 7 19:11:29 2008
@@ -9,7 +9,7 @@
#
# * THREE_VERSIONS_OF_CORE=True: you get three copies of the whole
# regexp searching and matching code: for strings, for unicode strings,
-# and for generic wrapped objects (like mmap.mmap or array.array).
+# and for generic buffer objects (like mmap.mmap or array.array).
#
# * THREE_VERSIONS_OF_CORE=False: there is only one copy of the code,
# at the cost of an indirect method call to fetch each character.
@@ -162,19 +162,11 @@
rsre.insert_sre_methods(locals(), 'generic')
def unwrap_object(self):
- # cannot unwrap in the general case
- space = self.space
- # some type-checking
- if (space.lookup(self.w_string, '__getitem__') is None or
- space.lookup(self.w_string, 'keys') is not None):
- msg = "string or sequence of characters expected"
- raise OperationError(space.w_TypeError, space.wrap(msg))
- return space.int_w(space.len(self.w_string))
+ self.buffer = self.space.buffer_w(self.w_string)
+ return self.buffer.len
def get_char_ord(self, p):
- space = self.space
- w_char = space.getitem(self.w_string, space.wrap(p))
- return space.int_w(space.ord(w_char))
+ return ord(self.buffer.getitem(p))
def w_search(space, w_state, w_pattern_codes):
Modified: pypy/branch/buffer/pypy/module/_sre/test/test_app_sre.py
==============================================================================
--- pypy/branch/buffer/pypy/module/_sre/test/test_app_sre.py (original)
+++ pypy/branch/buffer/pypy/module/_sre/test/test_app_sre.py Fri Mar 7 19:11:29 2008
@@ -194,6 +194,10 @@
m = re.match('hel+', a)
assert m.end() == 4
+ def test_match_typeerror(self):
+ import re
+ raises(TypeError, re.match, 'hel+', list('hello'))
+
def test_group_bugs(self):
import re
r = re.compile(r"""
More information about the Pypy-commit
mailing list