def _endswith(self, space, value, w_prefix, start, end): prefix = self._op_val(space, w_prefix) if self._starts_ends_unicode: # bug-to-bug compat if len(prefix) == 0: return True else: if start > len(value): return False return endswith(value, prefix, start, end)
def PyUnicode_Tailmatch(space, w_str, w_substr, start, end, direction): """Return 1 if substr matches str[start:end] at the given tail end (direction == -1 means to do a prefix match, direction == 1 a suffix match), 0 otherwise. Return -1 if an error occurred.""" str = space.unicode_w(w_str) substr = space.unicode_w(w_substr) if rffi.cast(lltype.Signed, direction) <= 0: return rstring.startswith(str, substr, start, end) else: return rstring.endswith(str, substr, start, end)
def PyUnicode_Tailmatch(space, w_str, w_substr, start, end, direction): """Return 1 if substr matches str[start:end] at the given tail end (direction == -1 means to do a prefix match, direction == 1 a suffix match), 0 otherwise. Return -1 if an error occurred.""" str = space.unicode_w(w_str) substr = space.unicode_w(w_substr) if rffi.cast(lltype.Signed, direction) <= 0: return rstring.startswith(str, substr, start, end) else: return rstring.endswith(str, substr, start, end)
def unicode_endswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_suffixes, w_start, w_end): if not space.isinstance_w(w_suffixes, space.w_tuple): raise FailedToImplement unistr, start, end = _convert_idx_params(space, w_unistr, w_start, w_end, True) for w_suffix in space.fixedview(w_suffixes): suffix = space.unicode_w(w_suffix) if endswith(unistr, suffix, start, end): return space.w_True return space.w_False
def str_endswith__String_ANY_ANY_ANY(space, w_self, w_suffixes, w_start, w_end): if not space.isinstance_w(w_suffixes, space.w_tuple): raise FailedToImplement (u_self, start, end) = _convert_idx_params(space, w_self, w_start, w_end, True) for w_suffix in space.fixedview(w_suffixes): if space.isinstance_w(w_suffix, space.w_unicode): w_u = space.call_function(space.w_unicode, w_self) return space.call_method(w_u, "endswith", w_suffixes, w_start, w_end) suffix = space.str_w(w_suffix) if endswith(u_self, suffix, start, end): return space.w_True return space.w_False
def str_endswith__String_ANY_ANY_ANY(space, w_self, w_suffixes, w_start, w_end): if not space.isinstance_w(w_suffixes, space.w_tuple): raise FailedToImplement (u_self, start, end) = _convert_idx_params(space, w_self, w_start, w_end, True) for w_suffix in space.fixedview(w_suffixes): if space.isinstance_w(w_suffix, space.w_unicode): w_u = space.call_function(space.w_unicode, w_self) return space.call_method(w_u, "endswith", w_suffixes, w_start, w_end) suffix = space.str_w(w_suffix) if endswith(u_self, suffix, start, end): return space.w_True return space.w_False
def _endswith(self, space, value, w_prefix, start, end): prefix = self._op_val(space, w_prefix) if start > len(value): return self._starts_ends_overflow(prefix) return endswith(value, prefix, start, end)
def check_endswith(value, sub, *args, **kwargs): result = kwargs['res'] assert endswith(value, sub, *args) is result assert endswith(list(value), sub, *args) is result
def str_endswith__String_String_ANY_ANY(space, w_self, w_suffix, w_start, w_end): (u_self, start, end) = _convert_idx_params(space, w_self, w_start, w_end, True) return space.newbool(endswith(u_self, w_suffix._value, start, end))
def str_endswith__String_String_ANY_ANY(space, w_self, w_suffix, w_start, w_end): (u_self, start, end) = _convert_idx_params(space, w_self, w_start, w_end, True) return space.newbool(endswith(u_self, w_suffix._value, start, end))
def _endswith(self, space, value, w_prefix, start, end): prefix = self._op_val(space, w_prefix) if start > len(value): return False return endswith(value, prefix, start, end)
def check_endswith(value, sub, *args, **kwargs): result = kwargs['res'] assert endswith(value, sub, *args) is result assert endswith(list(value), sub, *args) is result
def _endswith(self, space, value, w_prefix, start, end): return endswith(value, self._op_val(space, w_prefix), start, end)
def _endswith(self, space, value, w_prefix, start, end): prefix = self._op_val(space, w_prefix) if start > len(value): return self._starts_ends_overflow(prefix) return endswith(value, prefix, start, end)
def test_endswith(): assert endswith('ab', 'ab') is True assert endswith('ab', 'b') is True assert endswith('ab', '') is True assert endswith('x', 'a') is False assert endswith('x', 'x') is True assert endswith('', '') is True assert endswith('', 'a') is False assert endswith('x', 'xx') is False assert endswith('y', 'xx') is False assert endswith('abc', 'ab', 0, 2) is True assert endswith('abc', 'bc', 1) is True assert endswith('abc', 'bc', 2) is False assert endswith('abc', 'b', -3, -1) is True
def unicode_endswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, w_start, w_end): self, start, end = _convert_idx_params(space, w_self, w_start, w_end, True) return space.newbool(endswith(self, w_substr._value, start, end))