1. Pypy
  2. Untitled project
  3. pypy

Commits

Simon Cross  committed dece801

Remove bytearray.decode multimethod (fijal, hodgestar).

  • Participants
  • Parent commits 55e0a79
  • Branches remove-string-smm

Comments (0)

Files changed (3)

File pypy/objspace/std/bytearrayobject.py

View file
  • Ignore whitespace
     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)

File pypy/objspace/std/bytearraytype.py

View file
  • Ignore whitespace
 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,
         """
         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):
     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())

File pypy/objspace/std/test/test_bytearrayobject.py

View file
  • Ignore whitespace
         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'