<s> '''<STR_LIT>''' <EOL> import os <EOL> import sys <EOL> import types <EOL> ispy3k = int ( sys . version [ <NUM_LIT:0> ] ) >= <NUM_LIT:3> <EOL> if ispy3k : <EOL> string_type = str <EOL> itervalues = lambda d : d . values ( ) <EOL> iteritems = lambda d : d . items ( ) <EOL> int_type = int <EOL> zip = zip <EOL> map = map <EOL> long = int <EOL> range = range <EOL> from urllib import parse as urlparse <EOL> from io import StringIO , BytesIO <EOL> from itertools import zip_longest <EOL> urlencode = urlparse . urlencode <EOL> class UnicodeMixin ( object ) : <EOL> def __unicode__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ ) <EOL> def __str__ ( self ) : <EOL> return self . __unicode__ ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self ) <EOL> def native_str ( s , encoding = '<STR_LIT:utf-8>' ) : <EOL> if isinstance ( s , bytes ) : <EOL> return s . decode ( encoding ) <EOL> return s <EOL> else : <EOL> string_type = unicode <EOL> itervalues = lambda d : d . itervalues ( ) <EOL> iteritems = lambda d : d . iteritems ( ) <EOL> int_type = ( types . IntType , types . LongType ) <EOL> from itertools import izip as zip , imap as map , izip_longest as zip_longest <EOL> range = xrange <EOL> long = long <EOL> import urlparse <EOL> from urllib import urlencode <EOL> from cStringIO import StringIO <EOL> BytesIO = StringIO <EOL> class UnicodeMixin ( object ) : <EOL> def __unicode__ ( self ) : <EOL> return unicode ( '<STR_LIT>' . format ( self . __class__ . __name__ ) ) <EOL> def __str__ ( self ) : <EOL> return self . __unicode__ ( ) . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:ignore>' ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self ) <EOL> def native_str ( s , encoding = '<STR_LIT:utf-8>' ) : <EOL> if isinstance ( s , unicode ) : <EOL> return s . encode ( encoding ) <EOL> return s <EOL> is_string = lambda x : isinstance ( x , string_type ) <EOL> is_int = lambda x : isinstance ( x , int_type ) <EOL> def to_bytes ( s , encoding = None , errors = '<STR_LIT:strict>' ) : <EOL> """<STR_LIT>""" <EOL> encoding = encoding or '<STR_LIT:utf-8>' <EOL> if isinstance ( s , bytes ) : <EOL> if encoding != '<STR_LIT:utf-8>' : <EOL> return s . decode ( '<STR_LIT:utf-8>' , errors ) . encode ( encoding , errors ) <EOL> else : <EOL> return s <EOL> if not is_string ( s ) : <EOL> s = string_type ( s ) <EOL> return s . encode ( encoding , errors ) <EOL> def to_string ( s , encoding = None , errors = '<STR_LIT:strict>' ) : <EOL> """<STR_LIT>""" <EOL> encoding = encoding or '<STR_LIT:utf-8>' <EOL> if isinstance ( s , bytes ) : <EOL> return s . decode ( encoding , errors ) <EOL> if not is_string ( s ) : <EOL> s = string_type ( s ) <EOL> return s </s>
