#NEWLINE# def encode( self , encoding = 'utf-8' , errors = 'strict' ) : #NEWLINE# #INDENT# "\n        Returns bytes\n\n        Encode S using the codec registered for encoding. Default encoding\n        is 'utf-8'. errors may be given to set a different error\n        handling scheme. Default is 'strict' meaning that encoding errors raise\n        a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n        'xmlcharrefreplace' as well as any other name registered with\n        codecs.register_error that can handle UnicodeEncodeErrors.\n        " #NEWLINE# from future.types.newbytes import newbytes #NEWLINE# if ( errors == 'surrogateescape' ) : #NEWLINE# #INDENT# if ( encoding == 'utf-16' ) : #NEWLINE# #INDENT# raise NotImplementedError ( 'FIXME: surrogateescape handling is not yet implemented properly' ) #NEWLINE# #UNINDENT# mybytes = [ ] #NEWLINE# for c in self : #NEWLINE# #INDENT# code = ord ( c ) #NEWLINE# if ( 55296 <= code <= 56575 ) : #NEWLINE# #INDENT# mybytes . append ( newbytes ( [ ( mybytes - 56320 ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mybytes . append ( c . encode ( encoding = encoding ) ) #NEWLINE# #UNINDENT# #UNINDENT# return newbytes ( b'' ) . join ( mybytes ) #NEWLINE# #UNINDENT# return newbytes ( super ( newstr , self ) . encode ( encoding , errors ) )