Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (5)
......@@ -295,5 +295,5 @@
return rsre_core.StrMatchContext(str,
pos, endpos)
def getmatch(self, ctx, found):
def getmatch(self, ctx, found, w_string):
if found:
......@@ -299,5 +299,5 @@
if found:
return W_SRE_Match(self, ctx)
return W_SRE_Match(self, ctx, w_string)
else:
return self.space.w_None
......@@ -305,10 +305,10 @@
def match_w(self, w_string, pos=0, endpos=sys.maxint):
"""Matches zero or more characters at the beginning of the string."""
ctx = self.make_ctx(w_string, pos, endpos)
return self.getmatch(ctx, matchcontext(self.space, ctx, self.code))
return self.getmatch(ctx, matchcontext(self.space, ctx, self.code), w_string)
@unwrap_spec(pos=int, endpos=int)
def fullmatch_w(self, w_string, pos=0, endpos=sys.maxint):
"""Matches against all of the string."""
ctx = self.make_ctx(w_string, pos, endpos)
ctx.match_mode = rsre_core.MODE_FULL
......@@ -309,10 +309,10 @@
@unwrap_spec(pos=int, endpos=int)
def fullmatch_w(self, w_string, pos=0, endpos=sys.maxint):
"""Matches against all of the string."""
ctx = self.make_ctx(w_string, pos, endpos)
ctx.match_mode = rsre_core.MODE_FULL
return self.getmatch(ctx, matchcontext(self.space, ctx, self.code))
return self.getmatch(ctx, matchcontext(self.space, ctx, self.code), w_string)
@unwrap_spec(pos=int, endpos=int)
def search_w(self, w_string, pos=0, endpos=sys.maxint):
......@@ -320,7 +320,7 @@
Return None if no position in the string matches."""
ctx = self.make_ctx(w_string, pos, endpos)
return self.getmatch(ctx, searchcontext(self.space, ctx, self.code))
return self.getmatch(ctx, searchcontext(self.space, ctx, self.code), w_string)
@unwrap_spec(pos=int, endpos=int)
def findall_w(self, w_string, pos=0, endpos=sys.maxint):
......@@ -356,7 +356,7 @@
# this also works as the implementation of the undocumented
# scanner() method.
ctx = self.make_ctx(w_string, pos, endpos)
scanner = W_SRE_Scanner(self, ctx, self.code)
scanner = W_SRE_Scanner(self, ctx, self.code, w_string)
return scanner
@unwrap_spec(maxsplit=int)
......@@ -487,7 +487,7 @@
if 1: # keeps the following block indented
last_pos = ctx.match_end
if filter_is_callable:
w_match = self.getmatch(ctx, True)
w_match = self.getmatch(ctx, True, w_string)
# make a copy of 'ctx'; see test_sub_matches_stay_valid
ctx = self.fresh_copy(ctx)
w_piece = space.call_function(w_filter, w_match)
......@@ -659,7 +659,7 @@
class W_SRE_Match(W_Root):
flatten_cache = None
def __init__(self, srepat, ctx):
def __init__(self, srepat, ctx, w_string):
self.space = srepat.space
self.srepat = srepat
self.ctx = ctx
......@@ -663,6 +663,7 @@
self.space = srepat.space
self.srepat = srepat
self.ctx = ctx
self.w_string = w_string
def repr_w(self):
space = self.space
......@@ -847,19 +848,7 @@
return space.newtuple(result_w)
def fget_string(self, space):
ctx = self.ctx
if isinstance(ctx, rsre_core.BufMatchContext):
return space.newbytes(ctx._buffer.as_str())
elif isinstance(ctx, UnicodeAsciiMatchContext):
return space.newutf8(ctx._string, len(ctx._string))
elif isinstance(ctx, rsre_core.StrMatchContext):
return space.newbytes(ctx._string)
elif isinstance(ctx, rsre_utf8.Utf8MatchContext):
lgt = rutf8.codepoints_in_utf8(ctx._utf8)
return space.newutf8(ctx._utf8, lgt)
else:
raise SystemError
return self.w_string
W_SRE_Match.typedef = TypeDef(
're.Match',
......@@ -897,8 +886,8 @@
# Our version is also directly iterable, to make finditer() easier.
class W_SRE_Scanner(W_Root):
def __init__(self, pattern, ctx, code):
def __init__(self, pattern, ctx, code, w_string):
self.space = pattern.space
self.srepat = pattern
self.ctx = ctx
self.code = code
......@@ -901,7 +890,8 @@
self.space = pattern.space
self.srepat = pattern
self.ctx = ctx
self.code = code
self.w_string = w_string
# 'self.ctx' is always a fresh context in which no searching
# or matching succeeded so far. It is None when the iterator is
# exhausted.
......@@ -934,7 +924,7 @@
nextstart = ctx.match_end
self.ctx = self.srepat.fresh_copy(ctx)
self.ctx.reset(nextstart, thisstart == nextstart)
match = W_SRE_Match(self.srepat, ctx)
match = W_SRE_Match(self.srepat, ctx, self.w_string)
return match
else:
self.ctx = None
......
......@@ -495,6 +495,14 @@
sre_parse.SubPattern(sre_parse.State()))
assert sre_pattern.scanner('s') is not None
def test_scanner_match_string(self):
import re
class mystr(type(u"")):
pass
s = mystr(u"bla")
p = re.compile(u".").scanner(s)
m = p.match()
assert m.string is s
class AppTestGetlower:
spaceconfig = dict(usemodules=('_locale',))
......@@ -1145,6 +1153,14 @@
match = re.search(u"a", u"bac")
assert match.string == u"bac"
def test_string_attribute_is_original_string(self):
import re
class mystr(type(u"")):
pass
s = mystr(u"\u1233\u1234\u1235")
match = re.search(u"\u1234", s)
assert match.string is s
def test_match_start(self):
import re
match = re.search(u"\u1234", u"\u1233\u1234\u1235")
......
......@@ -408,7 +408,7 @@
def test_strip_doesnt_escape_bytes(self):
log = self.run("""
def main(n):
l = [str(x).decode("ascii") for x in range(10000)]
l = [bytes(x) for x in range(10000)]
res = 0
for data in l:
res += len(data.strip(b'1')) # ID: striparg
......@@ -429,7 +429,7 @@
def test_unicode_strip_doesnt_escape_uniobject(self):
log = self.run("""
def main(n):
uni = b'\xc3\xa4'.decode("utf-8")
uni = bytes(bytearray([0xc3, 0xa4])).decode("utf-8")
l = [str(x) + uni + str(x) for x in range(10000)]
res = 0
for data in l:
......