# HG changeset patch # User Paul Boddie # Date 1487018999 -3600 # Node ID 3481d146208c0dca64ba13bdaa2d7989f8d65730 # Parent dad54a3a60f9b28a8bab0a0c334715ca0041404a# Parent 65cadf3264bc5c4a7e58adee53ff9be36300a33e Merged changes from the attr-strvalue-without-size branch. diff -r dad54a3a60f9 -r 3481d146208c lib/__builtins__/unicode.py --- a/lib/__builtins__/unicode.py Mon Feb 13 21:26:38 2017 +0100 +++ b/lib/__builtins__/unicode.py Mon Feb 13 21:49:59 2017 +0100 @@ -40,7 +40,7 @@ self.encoding = encoding self.length = None - def _binary_op(self, op, other): + def _binary_op(self, op, other, sizes=False): "Perform 'op' on this object and 'other' if appropriate." @@ -51,16 +51,17 @@ # Combining text with bytes. - elif not _isinstance(other, utf8string): + if not _isinstance(other, utf8string): s = self.encode() + else: + s = self + + if sizes: + return op(s.__data__, other.__data__, s.__size__, other.__size__) + else: return op(s.__data__, other.__data__) - # Otherwise, perform the operation on the operands' data. - - else: - return op(self.__data__, other.__data__) - - def _binary_op_rev(self, op, other): + def _binary_op_rev(self, op, other, sizes=False): "Perform 'op' on 'other' and this object if appropriate." @@ -71,14 +72,15 @@ # Combining text with bytes. - elif not _isinstance(other, utf8string): + if not _isinstance(other, utf8string): s = self.encode() - return op(other.__data__, s.__data__) + else: + s = self - # Otherwise, perform the operation on the operands' data. - + if sizes: + return op(other.__data__, s.__data__, other.__size__, s.__size__) else: - return op(other.__data__, self.__data__) + return op(other.__data__, s.__data__) def _convert(self, result, other): @@ -118,7 +120,7 @@ "Return a string combining this string with 'other'." - return self._convert(self._binary_op(str_add, other), other) + return self._convert(self._binary_op(str_add, other, True), other) __add__ = __iadd__ @@ -126,7 +128,7 @@ "Return a string combining this string with 'other'." - return self._convert(self._binary_op_rev(str_add, other), other) + return self._convert(self._binary_op_rev(str_add, other, True), other) def __len__(self):