-
Kirill Smelkov authored
bytearray was introduced in Python as a mutable version of bytes. It has all strings methods (e.g. .capitalize() .islower(), etc), and it also supports % formatting. In other words it has all attributes of being a byte-string, with the only difference from bytes in that bytearray is mutable. In other words bytearray is handy to have when a string is being incrementally constructed step by step without hitting overhead of many bytes objects creation/destruction. So, since bytearray is also a bytestring, similarly to bytes, let's add support to interoperate with bytearray to bstr and ustr: - b/u and bstr/ustr now accept bytearray as argument and treat it as bytestring. - bytearray() constructor, similarly to bytes() and unicode() constructors, now also accepts bstr/ustr and create bytearray object corresponding to byte-stream of input. For the latter point to work we need to patch bytearray.__init__() a bit, since, contrary to bytes.__init__(), it does not pay attention to whether provided argument has __bytes__ method or not.
e4d5cb21