[pypy-commit] pypy py3k: Fix test: don't mix unicode and byte strings in regexp search/replace.

amauryfa noreply at buildbot.pypy.org
Sat Oct 20 20:37:45 CEST 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r58279:071daa233191
Date: 2012-10-20 20:34 +0200
http://bitbucket.org/pypy/pypy/changeset/071daa233191/

Log:	Fix test: don't mix unicode and byte strings in regexp
	search/replace.

diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py
--- a/pypy/module/_sre/interp_sre.py
+++ b/pypy/module/_sre/interp_sre.py
@@ -113,12 +113,18 @@
         if endpos < pos: endpos = pos
         if space.is_true(space.isinstance(w_string, space.w_unicode)):
             unicodestr = space.unicode_w(w_string)
+            if not space.isinstance_w(self.w_pattern, space.w_unicode):
+                raise OperationError(space.w_TypeError, space.wrap(
+                        "can't use a string pattern on a bytes-like object"))
             if pos > len(unicodestr): pos = len(unicodestr)
             if endpos > len(unicodestr): endpos = len(unicodestr)
             return rsre_core.UnicodeMatchContext(self.code, unicodestr,
                                                  pos, endpos, self.flags)
         else:
             str = space.bufferstr_w(w_string)
+            if space.isinstance_w(self.w_pattern, space.w_unicode):
+                raise OperationError(space.w_TypeError, space.wrap(
+                        "can't use a bytes pattern on a string-like object"))
             if pos > len(str): pos = len(str)
             if endpos > len(str): endpos = len(str)
             return rsre_core.StrMatchContext(self.code, str,


More information about the pypy-commit mailing list