Ejemplo n.º 1
0
    def descr_count(self, space, w_sub, w_start=None, w_end=None):
        value, start, end = self._convert_idx_params(space, w_start, w_end)

        if self._use_rstr_ops(space, w_sub):
            return space.newint(
                value.count(self._op_val(space, w_sub), start, end))

        from pypy.objspace.std.bytearrayobject import W_BytearrayObject
        from pypy.objspace.std.bytesobject import W_BytesObject
        if isinstance(w_sub, W_BytearrayObject):
            res = count(value, w_sub.data, start, end)
        elif isinstance(w_sub, W_BytesObject):
            res = count(value, w_sub._value, start, end)
        else:
            buffer = _get_buffer(space, w_sub)
            res = count(value, buffer, start, end)

        return space.wrap(max(res, 0))
Ejemplo n.º 2
0
    def descr_count(self, space, w_sub, w_start=None, w_end=None):
        value, start, end = self._convert_idx_params(space, w_start, w_end)

        if self._use_rstr_ops(space, w_sub):
            return space.newint(value.count(self._op_val(space, w_sub), start,
                                            end))

        from pypy.objspace.std.bytearrayobject import W_BytearrayObject
        from pypy.objspace.std.bytesobject import W_BytesObject
        if isinstance(w_sub, W_BytearrayObject):
            res = count(value, w_sub.data, start, end)
        elif isinstance(w_sub, W_BytesObject):
            res = count(value, w_sub._value, start, end)
        else:
            buffer = _get_buffer(space, w_sub)
            res = count(value, buffer, start, end)

        return space.wrap(max(res, 0))
Ejemplo n.º 3
0
    def descr_count(self, space, w_sub, w_start=None, w_end=None):
        value, start, end, _ = self._convert_idx_params(space, w_start, w_end)

        sub = self._op_val(space, w_sub, allow_char=True)
        if self._use_rstr_ops(space, w_sub):
            return space.newint(value.count(sub, start, end))
        else:
            res = count(value, sub, start, end)
            assert res >= 0
        return space.newint(res)
Ejemplo n.º 4
0
 def fn():
     res = True
     res = res and find('a//b//c//d', StringBuffer('//'), 0, 10) != -1
     res = res and rfind('a//b//c//d', StringBuffer('//'), 0, 10) != -1
     res = res and count('a//b//c//d', StringBuffer('//'), 0, 10) != 0
     return res
Ejemplo n.º 5
0
 def fn():
     res = True
     res = res and find('a//b//c//d', StringBuffer('//'), 0, 10) != -1
     res = res and rfind('a//b//c//d', StringBuffer('//'), 0, 10) != -1
     res = res and count('a//b//c//d', StringBuffer('//'), 0, 10) != 0
     return res
Ejemplo n.º 6
0
 def fn():
     res = True
     res = res and find("a//b//c//d", StringBuffer("//"), 0, 10) != -1
     res = res and rfind("a//b//c//d", StringBuffer("//"), 0, 10) != -1
     res = res and count("a//b//c//d", StringBuffer("//"), 0, 10) != 0
     return res