コード例 #1
0
 def make_ctx(self, w_string, pos=0, endpos=sys.maxint, flags=0):
     """Make a StrMatchContext, BufMatchContext or a UnicodeMatchContext for
     searching in the given w_string object."""
     space = self.space
     length, unicodestr, string, buf = self.getstring(w_string)
     if pos < 0:
         pos = 0
     elif pos > length:
         pos = length
     if endpos < pos:
         endpos = pos
     elif endpos > length:
         endpos = length
     flags = self.flags | flags
     #
     if unicodestr is not None:
         if self.is_known_bytes():
             raise oefmt(
                 space.w_TypeError,
                 "can't use a bytes pattern on a string-like "
                 "object")
         return rsre_core.UnicodeMatchContext(unicodestr, pos, endpos,
                                              flags)
     else:
         if self.is_known_unicode():
             raise oefmt(
                 space.w_TypeError,
                 "can't use a string pattern on a bytes-like "
                 "object")
         if string is not None:
             return rsre_core.StrMatchContext(string, pos, endpos, flags)
         else:
             return rsre_core.BufMatchContext(buf, pos, endpos, flags)
コード例 #2
0
 def make_ctx(self, w_string, pos=0, endpos=sys.maxint):
     """Make a StrMatchContext, BufMatchContext or a UnicodeMatchContext for
     searching in the given w_string object."""
     space = self.space
     if pos < 0:
         pos = 0
     if endpos < pos:
         endpos = pos
     if space.isinstance_w(w_string, space.w_unicode):
         unicodestr = space.unicode_w(w_string)
         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)
     elif space.isinstance_w(w_string, space.w_str):
         str = space.str_w(w_string)
         if pos > len(str):
             pos = len(str)
         if endpos > len(str):
             endpos = len(str)
         return rsre_core.StrMatchContext(self.code, str, pos, endpos,
                                          self.flags)
     else:
         buf = space.readbuf_w(w_string)
         size = buf.getlength()
         assert size >= 0
         if pos > size:
             pos = size
         if endpos > size:
             endpos = size
         return rsre_core.BufMatchContext(self.code, buf, pos, endpos,
                                          self.flags)
コード例 #3
0
ファイル: values_regex.py プロジェクト: zeling/pycket
 def make_ctx(self, s, start, end):
     self.ensure_compiled()
     start, end = rsre_core._adjust(start, end, len(s))
     if isinstance(s, unicode):
         return rsre_core.UnicodeMatchContext(s, start, end, self.flags)
     assert isinstance(s, str)
     return rsre_core.StrMatchContext(s, start, end, self.flags)
コード例 #4
0
ファイル: interp_sre.py プロジェクト: Qointum/pypy
 def make_ctx(self, w_string, pos=0, endpos=sys.maxint):
     """Make a BufMatchContext or a UnicodeMatchContext for searching
     in the given w_string object."""
     space = self.space
     if pos < 0:
         pos = 0
     if endpos < pos:
         endpos = pos
     if space.isinstance_w(w_string, space.w_unicode):
         unicodestr = space.unicode_w(w_string)
         if not (space.is_none(self.w_pattern) or
                 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:
         buf = space.readbuf_w(w_string)
         if (not space.is_none(self.w_pattern) and
             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"))
         size = buf.getlength()
         assert size >= 0
         if pos > size:
             pos = size
         if endpos > size:
             endpos = size
         return rsre_core.BufMatchContext(self.code, buf,
                                          pos, endpos, self.flags)
コード例 #5
0
def main(n):
    assert n >= 0
    pattern = [n] * n
    string = chr(n) * n
    rsre_core.search(pattern, string)
    #
    unicodestr = unichr(n) * n
    ctx = rsre_core.UnicodeMatchContext(pattern, unicodestr, 0,
                                        len(unicodestr), 0)
    rsre_core.search_context(ctx)
    #
    return 0