Author: Jeremy Thurgood <[email protected]>
Branch: unicode-utf8
Changeset: r92653:c46107c45a6e
Date: 2017-10-08 12:01 +0200
http://bitbucket.org/pypy/pypy/changeset/c46107c45a6e/
Log: getslice and fix {starts,ends}with.
diff --git a/pypy/objspace/std/stringmethods.py
b/pypy/objspace/std/stringmethods.py
--- a/pypy/objspace/std/stringmethods.py
+++ b/pypy/objspace/std/stringmethods.py
@@ -619,6 +619,7 @@
strs.append(value[pos:length])
return self._newlist_unwrapped(space, strs)
+ # This is overridden in unicodeobject, _startswith_tuple is not.
def descr_startswith(self, space, w_prefix, w_start=None, w_end=None):
value, start, end, _ = self._convert_idx_params(space, w_start, w_end)
if space.isinstance_w(w_prefix, space.w_tuple):
@@ -632,13 +633,14 @@
return space.w_True
return space.w_False
- # This is overridden in unicodeobject, but the two above are not.
+ # This is overridden in unicodeobject, _startswith_tuple is not.
def _startswith(self, space, value, w_prefix, start, end):
prefix = self._op_val(space, w_prefix)
if start > len(value):
return False
return startswith(value, prefix, start, end)
+ # This is overridden in unicodeobject, _endswith_tuple is not.
def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
value, start, end, _ = self._convert_idx_params(space, w_start, w_end)
if space.isinstance_w(w_suffix, space.w_tuple):
@@ -652,7 +654,7 @@
return space.w_True
return space.w_False
- # This is overridden in unicodeobject, but the two above are not.
+ # This is overridden in unicodeobject, but _endswith_tuple is not.
def _endswith(self, space, value, w_prefix, start, end):
prefix = self._op_val(space, w_prefix)
if start > len(value):
diff --git a/pypy/objspace/std/unicodeobject.py
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -21,9 +21,10 @@
from pypy.objspace.std import newformat
from pypy.objspace.std.basestringtype import basestring_typedef
from pypy.objspace.std.formatting import mod_format
+from pypy.objspace.std.sliceobject import (
+ unwrap_start_stop, normalize_simple_slice)
from pypy.objspace.std.stringmethods import StringMethods
from pypy.objspace.std.util import IDTAG_SPECIAL, IDTAG_SHIFT
-from pypy.objspace.std.sliceobject import unwrap_start_stop
__all__ = ['W_UnicodeObject', 'wrapunicode', 'plain_str2unicode',
'encode_object', 'decode_object', 'unicode_from_object',
@@ -142,10 +143,6 @@
return True
@staticmethod
- def _op_utf8(space, w_other, strict=None):
- return W_UnicodeObject.convert_arg_to_w_unicode(space, w_other,
strict)._utf8
-
- @staticmethod
def _op_val(space, w_other, strict=None):
return W_UnicodeObject.convert_arg_to_w_unicode(space, w_other,
strict)._utf8.decode('utf8')
@@ -550,14 +547,30 @@
i = rutf8.next_codepoint_pos(val, i)
return space.newbool(cased)
+ def descr_startswith(self, space, w_prefix, w_start=None, w_end=None):
+ start, end = unwrap_start_stop(space, self._length, w_start, w_end)
+ value = self._utf8
+ if space.isinstance_w(w_prefix, space.w_tuple):
+ return self._startswith_tuple(space, value, w_prefix, start, end)
+ return space.newbool(self._startswith(space, value, w_prefix, start,
+ end))
+
def _startswith(self, space, value, w_prefix, start, end):
- prefix = self._op_utf8(space, w_prefix)
+ prefix = self.convert_arg_to_w_unicode(space, w_prefix)._utf8
if start > len(value):
return len(prefix) == 0
return startswith(value, prefix, start, end)
+ def descr_endswith(self, space, w_suffix, w_start=None, w_end=None):
+ start, end = unwrap_start_stop(space, self._length, w_start, w_end)
+ value = self._utf8
+ if space.isinstance_w(w_suffix, space.w_tuple):
+ return self._endswith_tuple(space, value, w_suffix, start, end)
+ return space.newbool(self._endswith(space, value, w_suffix, start,
+ end))
+
def _endswith(self, space, value, w_prefix, start, end):
- prefix = self._op_utf8(space, w_prefix)
+ prefix = self.convert_arg_to_w_unicode(space, w_prefix)._utf8
if start > len(value):
return len(prefix) == 0
return endswith(value, prefix, start, end)
@@ -683,6 +696,15 @@
return space.newlist_utf8(res)
+ def descr_getslice(self, space, w_start, w_stop):
+ selfvalue = self._utf8
+ start, stop = normalize_simple_slice(
+ space, self._len(), w_start, w_stop)
+ if start == stop:
+ return self._empty()
+ else:
+ return self._sliced(space, selfvalue, start, stop, self)
+
def descr_capitalize(self, space):
value = self._utf8
if len(value) == 0:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit