<s> """<STR_LIT>""" <EOL> from collections import Iterable <EOL> from numbers import Integral <EOL> import string <EOL> from future . utils import istext , isbytes , PY3 , with_metaclass <EOL> from future . types import no , issubset <EOL> from future . types . newobject import newobject <EOL> _builtin_bytes = bytes <EOL> if PY3 : <EOL> unicode = str <EOL> class BaseNewBytes ( type ) : <EOL> def __instancecheck__ ( cls , instance ) : <EOL> if cls == newbytes : <EOL> return isinstance ( instance , _builtin_bytes ) <EOL> else : <EOL> return issubclass ( instance . __class__ , cls ) <EOL> class newbytes ( with_metaclass ( BaseNewBytes , _builtin_bytes ) ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> encoding = None <EOL> errors = None <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> return super ( newbytes , cls ) . __new__ ( cls ) <EOL> elif len ( args ) >= <NUM_LIT:2> : <EOL> args = list ( args ) <EOL> if len ( args ) == <NUM_LIT:3> : <EOL> errors = args . pop ( ) <EOL> encoding = args . pop ( ) <EOL> if type ( args [ <NUM_LIT:0> ] ) == newbytes : <EOL> return args [ <NUM_LIT:0> ] <EOL> elif isinstance ( args [ <NUM_LIT:0> ] , _builtin_bytes ) : <EOL> value = args [ <NUM_LIT:0> ] <EOL> elif isinstance ( args [ <NUM_LIT:0> ] , unicode ) : <EOL> try : <EOL> if '<STR_LIT>' in kwargs : <EOL> assert encoding is None <EOL> encoding = kwargs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in kwargs : <EOL> assert errors is None <EOL> errors = kwargs [ '<STR_LIT>' ] <EOL> except AssertionError : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> if encoding is None : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> newargs = [ encoding ] <EOL> if errors is not None : <EOL> newargs . append ( errors ) <EOL> value = args [ <NUM_LIT:0> ] . encode ( * newargs ) <EOL> elif isinstance ( args [ <NUM_LIT:0> ] , Iterable ) : <EOL> if len ( args [ <NUM_LIT:0> ] ) == <NUM_LIT:0> : <EOL> value = b'<STR_LIT>' <EOL> else : <EOL> try : <EOL> values = [ chr ( x ) for x in args [ <NUM_LIT:0> ] ] <EOL> value = b'<STR_LIT>' . join ( values ) <EOL> except : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> elif isinstance ( args [ <NUM_LIT:0> ] , Integral ) : <EOL> if args [ <NUM_LIT:0> ] < <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> value = b'<STR_LIT:\x00>' * args [ <NUM_LIT:0> ] <EOL> else : <EOL> value = args [ <NUM_LIT:0> ] <EOL> return super ( newbytes , cls ) . __new__ ( cls , value ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT:b>' + super ( newbytes , self ) . __repr__ ( ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT:b>' + "<STR_LIT>" . format ( super ( newbytes , self ) . __str__ ( ) ) <EOL> def __getitem__ ( self , y ) : <EOL> value = super ( newbytes , self ) . __getitem__ ( y ) <EOL> if isinstance ( y , Integral ) : <EOL> return ord ( value ) <EOL> else : <EOL> return newbytes ( value ) <EOL> def __getslice__ ( self , * args ) : <EOL> return self . __getitem__ ( slice ( * args ) ) <EOL> def __contains__ ( self , key ) : <EOL> if isinstance ( key , int ) : <EOL> newbyteskey = newbytes ( [ key ] ) <EOL> elif type ( key ) == newbytes : <EOL> newbyteskey = key <EOL> else : <EOL> newbyteskey = newbytes ( key ) <EOL> return issubset ( list ( newbyteskey ) , list ( self ) ) <EOL> @ no ( unicode ) <EOL> def __add__ ( self , other ) : <EOL> return newbytes ( super ( newbytes , self ) . __add__ ( other ) ) <EOL> @ no ( unicode ) <EOL> def __radd__ ( self , left ) : <EOL> return newbytes ( left ) + self <EOL> @ no ( unicode ) <EOL> def __mul__ ( self , other ) : <EOL> return newbytes ( super ( newbytes , self ) . __mul__ ( other ) ) <EOL> @ no ( unicode ) <EOL> def __rmul__ ( self , other ) : <EOL> return newbytes ( super ( newbytes , self ) . __rmul__ ( other ) ) <EOL> def join ( self , iterable_of_bytes ) : <EOL> errmsg = '<STR_LIT>' <EOL> if isbytes ( iterable_of_bytes ) or istext ( iterable_of_bytes ) : <EOL> raise TypeError ( errmsg . format ( <NUM_LIT:0> , type ( iterable_of_bytes ) ) ) <EOL> for i , item in enumerate ( iterable_of_bytes ) : <EOL> if istext ( item ) : <EOL> raise TypeError ( errmsg . format ( i , type ( item ) ) ) <EOL> return newbytes ( super ( newbytes , self ) . join ( iterable_of_bytes ) ) <EOL> @ classmethod <EOL> def fromhex ( cls , string ) : <EOL> return cls ( string . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . decode ( '<STR_LIT>' ) ) <EOL> @ no ( unicode ) <EOL> def find ( self , sub , * args ) : <EOL> return super ( newbytes , self ) . find ( sub , * args ) <EOL> @ no ( unicode ) <EOL> def rfind ( self , sub , * args ) : <EOL> return super ( newbytes , self ) . rfind ( sub , * args ) <EOL> @ no ( unicode , ( <NUM_LIT:1> , <NUM_LIT:2> ) ) <EOL> def replace ( self , old , new , * args ) : <EOL> return newbytes ( super ( newbytes , self ) . replace ( old , new , * args ) ) <EOL> def encode ( self , * args ) : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> def decode ( self , encoding = '<STR_LIT:utf-8>' , errors = '<STR_LIT:strict>' ) : <EOL> """<STR_LIT>""" <EOL> from future . types . newstr import newstr <EOL> if errors == '<STR_LIT>' : <EOL> from future . utils . surrogateescape import register_surrogateescape <EOL> register_surrogateescape ( ) <EOL> return newstr ( super ( newbytes , self ) . decode ( encoding , errors ) ) <EOL> @ no ( unicode ) <EOL> def startswith ( self , prefix , * args ) : <EOL> return super ( newbytes , self ) . startswith ( prefix , * args ) <EOL> @ no ( unicode ) <EOL> def endswith ( self , prefix , * args ) : <EOL> return super ( newbytes , self ) . endswith ( prefix , * args ) <EOL> @ no ( unicode ) <EOL> def split ( self , sep = None , maxsplit = - <NUM_LIT:1> ) : <EOL> parts = super ( newbytes , self ) . split ( sep , maxsplit ) <EOL> return [ newbytes ( part ) for part in parts ] <EOL> def splitlines ( self , keepends = False ) : <EOL> """<STR_LIT>""" <EOL> parts = super ( newbytes , self ) . splitlines ( keepends ) <EOL> return [ newbytes ( part ) for part in parts ] <EOL> @ no ( unicode ) <EOL> def rsplit ( self , sep = None , maxsplit = - <NUM_LIT:1> ) : <EOL> parts = super ( newbytes , self ) . rsplit ( sep , maxsplit ) <EOL> return [ newbytes ( part ) for part in parts ] <EOL> @ no ( unicode ) <EOL> def partition ( self , sep ) : <EOL> parts = super ( newbytes , self ) . partition ( sep ) <EOL> return tuple ( newbytes ( part ) for part in parts ) <EOL> @ no ( unicode ) <EOL> def rpartition ( self , sep ) : <EOL> parts = super ( newbytes , self ) . rpartition ( sep ) <EOL> return tuple ( newbytes ( part ) for part in parts ) <EOL> @ no ( unicode , ( <NUM_LIT:1> , ) ) <EOL> def rindex ( self , sub , * args ) : <EOL> '''<STR_LIT>''' <EOL> pos = self . rfind ( sub , * args ) <EOL> if pos == - <NUM_LIT:1> : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> @ no ( unicode ) <EOL> def index ( self , sub , * args ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( sub , int ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> start , end = <NUM_LIT:0> , len ( self ) <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> start = args [ <NUM_LIT:0> ] <EOL> elif len ( args ) == <NUM_LIT:2> : <EOL> start , end = args <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> return list ( self ) [ start : end ] . index ( sub ) <EOL> if not isinstance ( sub , bytes ) : <EOL> try : <EOL> sub = self . __class__ ( sub ) <EOL> except ( TypeError , ValueError ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> try : <EOL> return super ( newbytes , self ) . index ( sub , * args ) <EOL> except ValueError : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , ( _builtin_bytes , bytearray ) ) : <EOL> return super ( newbytes , self ) . __eq__ ( other ) <EOL> else : <EOL> return False <EOL> def __ne__ ( self , other ) : <EOL> if isinstance ( other , _builtin_bytes ) : <EOL> return super ( newbytes , self ) . __ne__ ( other ) <EOL> else : <EOL> return True <EOL> unorderable_err = '<STR_LIT>' <EOL> def __lt__ ( self , other ) : <EOL> if not isbytes ( other ) : <EOL> raise TypeError ( self . unorderable_err . format ( type ( other ) ) ) <EOL> return super ( newbytes , self ) . __lt__ ( other ) <EOL> def __le__ ( self , other ) : <EOL> if not isbytes ( other ) : <EOL> raise TypeError ( self . unorderable_err . format ( type ( other ) ) ) <EOL> return super ( newbytes , self ) . __le__ ( other ) <EOL> def __gt__ ( self , other ) : <EOL> if not isbytes ( other ) : <EOL> raise TypeError ( self . unorderable_err . format ( type ( other ) ) ) <EOL> return super ( newbytes , self ) . __gt__ ( other ) <EOL> def __ge__ ( self , other ) : <EOL> if not isbytes ( other ) : <EOL> raise TypeError ( self . unorderable_err . format ( type ( other ) ) ) <EOL> return super ( newbytes , self ) . __ge__ ( other ) <EOL> def __native__ ( self ) : <EOL> return super ( newbytes , self ) . __str__ ( ) <EOL> def __getattribute__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if name in [ '<STR_LIT>' , u'<STR_LIT>' ] : <EOL> raise AttributeError ( "<STR_LIT>" ) <EOL> return super ( newbytes , self ) . __getattribute__ ( name ) <EOL> @ no ( unicode ) <EOL> def rstrip ( self , bytes_to_strip = None ) : <EOL> """<STR_LIT>""" <EOL> return newbytes ( super ( newbytes , self ) . rstrip ( bytes_to_strip ) ) <EOL> @ no ( unicode ) <EOL> def strip ( self , bytes_to_strip = None ) : <EOL> """<STR_LIT>""" <EOL> return newbytes ( super ( newbytes , self ) . strip ( bytes_to_strip ) ) <EOL> def lower ( self ) : <EOL> """<STR_LIT>""" <EOL> return newbytes ( super ( newbytes , self ) . lower ( ) ) <EOL> @ no ( unicode ) <EOL> def upper ( self ) : <EOL> """<STR_LIT>""" <EOL> return newbytes ( super ( newbytes , self ) . upper ( ) ) <EOL> @ classmethod <EOL> @ no ( unicode ) <EOL> def maketrans ( cls , frm , to ) : <EOL> """<STR_LIT>""" <EOL> return newbytes ( string . maketrans ( frm , to ) ) <EOL> __all__ = [ '<STR_LIT>' ] </s>
