1.1 --- a/lib/__builtins__/str.py Fri Dec 02 21:16:06 2016 +0100
1.2 +++ b/lib/__builtins__/str.py Fri Dec 02 22:26:53 2016 +0100
1.3 @@ -19,7 +19,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from __builtins__.operator import _binary_op, _negate
1.8 +from __builtins__.operator import _negate
1.9 from __builtins__.sequence import itemaccess
1.10 import native
1.11
1.12 @@ -54,11 +54,20 @@
1.13
1.14 return result
1.15
1.16 + def _binary_op(self, op, other):
1.17 +
1.18 + "Perform 'op' on this int and 'other' if appropriate."
1.19 +
1.20 + if isinstance(other, basestring):
1.21 + return op(self.__data__, other.__data__)
1.22 + else:
1.23 + return NotImplemented
1.24 +
1.25 def __iadd__(self, other):
1.26
1.27 - "Return a new string for the operation."
1.28 + "Return a string combining this string with 'other'."
1.29
1.30 - return _binary_op(self, other, native._str_add)
1.31 + return self._binary_op(native._str_add, other)
1.32
1.33 __add__ = __radd__ = __iadd__
1.34
1.35 @@ -69,42 +78,45 @@
1.36
1.37 def __lt__(self, other):
1.38
1.39 - "Return a new boolean for the comparison."
1.40 + "Return whether this string is less than 'other'."
1.41
1.42 - return _binary_op(self, other, native._str_lt)
1.43 + return self._binary_op(native._str_lt, other)
1.44
1.45 def __gt__(self, other):
1.46
1.47 - "Return a new boolean for the comparison."
1.48 + "Return whether this string is greater than 'other'."
1.49
1.50 - return _binary_op(self, other, native._str_gt)
1.51 + return self._binary_op(native._str_gt, other)
1.52
1.53 def __le__(self, other):
1.54
1.55 - "Return a new boolean for the comparison."
1.56 + "Return whether this string is less than or equal to 'other'."
1.57
1.58 return _negate(self.__gt__(other))
1.59
1.60 def __ge__(self, other):
1.61
1.62 - "Return a new boolean for the comparison."
1.63 + "Return whether this string is greater than or equal to 'other'."
1.64
1.65 return _negate(self.__lt__(other))
1.66
1.67 def __eq__(self, other):
1.68
1.69 - "Return a new boolean for the comparison."
1.70 + "Return whether this string is equal to 'other'."
1.71
1.72 - return _binary_op(self, other, native._str_eq)
1.73 + return self._binary_op(native._str_eq, other)
1.74
1.75 def __ne__(self, other):
1.76
1.77 - "Return a new boolean for the comparison."
1.78 + "Return whether this string is not equal to 'other'."
1.79
1.80 return _negate(self.__eq__(other))
1.81
1.82 def __len__(self):
1.83 - return native._str_len(self)
1.84 +
1.85 + "Return the length of this string."
1.86 +
1.87 + return native._str_len(self.__data__)
1.88
1.89 def __str__(self):
1.90
1.91 @@ -121,7 +133,7 @@
1.92 return str(b)
1.93
1.94 def __bool__(self):
1.95 - return native._str_nonempty(self)
1.96 + return native._str_nonempty(self.__data__)
1.97
1.98 def endswith(self, s): pass
1.99 def find(self, sub, start=None, end=None): pass
1.100 @@ -146,7 +158,7 @@
1.101 "Return the item at the normalised (positive) 'index'."
1.102
1.103 self._check_index(index)
1.104 - return native._str_substr(self, index, 1)
1.105 + return native._str_substr(self.__data__, index, 1)
1.106
1.107 class string(basestring):
1.108 pass