Author: Simon Cross <[email protected]>
Branch: remove-string-smm
Changeset: r63438:dece801042c2
Date: 2013-04-16 23:30 +0200
http://bitbucket.org/pypy/pypy/changeset/dece801042c2/
Log: Remove bytearray.decode multimethod (fijal, hodgestar).
diff --git a/pypy/objspace/std/bytearrayobject.py
b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -453,10 +453,6 @@
return stringobject.str_endswith__String_Tuple_ANY_ANY(space, w_str,
w_suffix,
w_start, w_stop)
-def str_decode__Bytearray_ANY_ANY(space, w_bytearray, w_encoding, w_errors):
- w_str = str__Bytearray(space, w_bytearray)
- return stringobject.str_decode__String_ANY_ANY(space, w_str, w_encoding,
w_errors)
-
def str_islower__Bytearray(space, w_bytearray):
w_str = str__Bytearray(space, w_bytearray)
return stringobject.str_islower__String(space, w_str)
diff --git a/pypy/objspace/std/bytearraytype.py
b/pypy/objspace/std/bytearraytype.py
--- a/pypy/objspace/std/bytearraytype.py
+++ b/pypy/objspace/std/bytearraytype.py
@@ -5,7 +5,6 @@
from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
from pypy.objspace.std.stringtype import (
- str_decode,
str_count, str_index, str_rindex, str_find, str_rfind, str_replace,
str_startswith, str_endswith, str_islower, str_isupper, str_isalpha,
str_isalnum, str_isdigit, str_isspace, str_istitle,
@@ -116,6 +115,22 @@
"""
raise NotImplementedError
+ def descr_decode(self, space, w_encoding=None, w_errors=None):
+ """B.decode([encoding[,errors]]) -> object
+
+ Decodes B using the codec registered for encoding. encoding defaults
+ to the default encoding. errors may be given to set a different error
+ handling scheme. Default is 'strict' meaning that encoding errors raise
+ a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'
+ as well as any other name registerd with codecs.register_error that is
+ able to handle UnicodeDecodeErrors.
+ """
+ from pypy.objspace.std.unicodetype import (
+ _get_encoding_and_errors, decode_object)
+ encoding, errors = _get_encoding_and_errors(
+ space, w_encoding, w_errors)
+ return decode_object(space, self, encoding, errors)
+
def getbytevalue(space, w_value):
if space.isinstance_w(w_value, space.w_str):
@@ -250,5 +265,6 @@
strip=interpindirect2app(W_AbstractBytearrayObject.descr_strip),
lstrip=interpindirect2app(W_AbstractBytearrayObject.descr_lstrip),
rstrip=interpindirect2app(W_AbstractBytearrayObject.descr_rstrip),
+ decode=interpindirect2app(W_AbstractBytearrayObject.descr_decode),
)
bytearray_typedef.registermethods(globals())
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py
b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -431,8 +431,12 @@
assert b == 'abcDEFghi'
def test_decode(self):
+ b = bytearray(u'abcdefghi\xe1'.encode('utf-8'))
+ u = b.decode('utf-8')
+ assert isinstance(u, unicode)
+ assert u == u'abcdefghi\xe1'
b = bytearray('abcdefghi')
- u = b.decode('utf-8')
+ u = b.decode()
assert isinstance(u, unicode)
assert u == u'abcdefghi'
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit