<s> import sys <EOL> import operator <EOL> import functools <EOL> try : <EOL> import builtins <EOL> except ImportError : <EOL> import __builtin__ as builtins <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> _identity = lambda x : x <EOL> if PY2 : <EOL> unichr = unichr <EOL> text_type = unicode <EOL> string_types = ( str , unicode ) <EOL> integer_types = ( int , long ) <EOL> int_to_byte = chr <EOL> iterkeys = lambda d , * args , ** kwargs : d . iterkeys ( * args , ** kwargs ) <EOL> itervalues = lambda d , * args , ** kwargs : d . itervalues ( * args , ** kwargs ) <EOL> iteritems = lambda d , * args , ** kwargs : d . iteritems ( * args , ** kwargs ) <EOL> iterlists = lambda d , * args , ** kwargs : d . iterlists ( * args , ** kwargs ) <EOL> iterlistvalues = lambda d , * args , ** kwargs : d . iterlistvalues ( * args , ** kwargs ) <EOL> iter_bytes = lambda x : iter ( x ) <EOL> exec ( '<STR_LIT>' ) <EOL> def fix_tuple_repr ( obj ) : <EOL> def __repr__ ( self ) : <EOL> cls = self . __class__ <EOL> return '<STR_LIT>' % ( cls . __name__ , '<STR_LIT:U+002CU+0020>' . join ( <EOL> '<STR_LIT>' % ( field , self [ index ] ) <EOL> for index , field in enumerate ( cls . _fields ) <EOL> ) ) <EOL> obj . __repr__ = __repr__ <EOL> return obj <EOL> def implements_iterator ( cls ) : <EOL> cls . next = cls . __next__ <EOL> del cls . __next__ <EOL> return cls <EOL> def implements_to_string ( cls ) : <EOL> cls . __unicode__ = cls . __str__ <EOL> cls . __str__ = lambda x : x . __unicode__ ( ) . encode ( '<STR_LIT:utf-8>' ) <EOL> return cls <EOL> def native_string_result ( func ) : <EOL> def wrapper ( * args , ** kwargs ) : <EOL> return func ( * args , ** kwargs ) . encode ( '<STR_LIT:utf-8>' ) <EOL> return functools . update_wrapper ( wrapper , func ) <EOL> def implements_bool ( cls ) : <EOL> cls . __nonzero__ = cls . __bool__ <EOL> del cls . __bool__ <EOL> return cls <EOL> from itertools import imap , izip , ifilter <EOL> range_type = xrange <EOL> from StringIO import StringIO <EOL> from cStringIO import StringIO as BytesIO <EOL> NativeStringIO = BytesIO <EOL> def make_literal_wrapper ( reference ) : <EOL> return lambda x : x <EOL> def normalize_string_tuple ( tup ) : <EOL> """<STR_LIT>""" <EOL> if any ( isinstance ( x , text_type ) for x in tup ) : <EOL> return tuple ( to_unicode ( x ) for x in tup ) <EOL> return tup <EOL> def try_coerce_native ( s ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return str ( s ) <EOL> except UnicodeError : <EOL> return s <EOL> wsgi_get_bytes = _identity <EOL> def wsgi_decoding_dance ( s , charset = '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) : <EOL> return s . decode ( charset , errors ) <EOL> def wsgi_encoding_dance ( s , charset = '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) : <EOL> if isinstance ( s , bytes ) : <EOL> return s <EOL> return s . encode ( charset , errors ) <EOL> def to_bytes ( x , charset = sys . getdefaultencoding ( ) , errors = '<STR_LIT:strict>' ) : <EOL> if x is None : <EOL> return None <EOL> if isinstance ( x , ( bytes , bytearray , buffer ) ) : <EOL> return bytes ( x ) <EOL> if isinstance ( x , unicode ) : <EOL> return x . encode ( charset , errors ) <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> def to_native ( x , charset = sys . getdefaultencoding ( ) , errors = '<STR_LIT:strict>' ) : <EOL> if x is None or isinstance ( x , str ) : <EOL> return x <EOL> return x . encode ( charset , errors ) <EOL> else : <EOL> unichr = chr <EOL> text_type = str <EOL> string_types = ( str , ) <EOL> integer_types = ( int , ) <EOL> iterkeys = lambda d , * args , ** kwargs : iter ( d . keys ( * args , ** kwargs ) ) <EOL> itervalues = lambda d , * args , ** kwargs : iter ( d . values ( * args , ** kwargs ) ) <EOL> iteritems = lambda d , * args , ** kwargs : iter ( d . items ( * args , ** kwargs ) ) <EOL> iterlists = lambda d , * args , ** kwargs : iter ( d . lists ( * args , ** kwargs ) ) <EOL> iterlistvalues = lambda d , * args , ** kwargs : iter ( d . listvalues ( * args , ** kwargs ) ) <EOL> int_to_byte = operator . methodcaller ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT>' ) <EOL> def iter_bytes ( b ) : <EOL> return map ( int_to_byte , b ) <EOL> def reraise ( tp , value , tb = None ) : <EOL> if value . __traceback__ is not tb : <EOL> raise value . with_traceback ( tb ) <EOL> raise value <EOL> fix_tuple_repr = _identity <EOL> implements_iterator = _identity <EOL> implements_to_string = _identity <EOL> implements_bool = _identity <EOL> native_string_result = _identity <EOL> imap = map <EOL> izip = zip <EOL> ifilter = filter <EOL> range_type = range <EOL> from io import StringIO , BytesIO <EOL> NativeStringIO = StringIO <EOL> def make_literal_wrapper ( reference ) : <EOL> if isinstance ( reference , text_type ) : <EOL> return lambda x : x <EOL> return lambda x : x . encode ( '<STR_LIT>' ) <EOL> def normalize_string_tuple ( tup ) : <EOL> """<STR_LIT>""" <EOL> tupiter = iter ( tup ) <EOL> is_text = isinstance ( next ( tupiter , None ) , text_type ) <EOL> for arg in tupiter : <EOL> if isinstance ( arg , text_type ) != is_text : <EOL> raise TypeError ( '<STR_LIT>' <EOL> % repr ( tup ) ) <EOL> return tup <EOL> try_coerce_native = _identity <EOL> def wsgi_get_bytes ( s ) : <EOL> return s . encode ( '<STR_LIT>' ) <EOL> def wsgi_decoding_dance ( s , charset = '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) : <EOL> return s . encode ( '<STR_LIT>' ) . decode ( charset , errors ) <EOL> def wsgi_encoding_dance ( s , charset = '<STR_LIT:utf-8>' , errors = '<STR_LIT:replace>' ) : <EOL> if isinstance ( s , bytes ) : <EOL> return s . decode ( '<STR_LIT>' , errors ) <EOL> return s . encode ( charset ) . decode ( '<STR_LIT>' , errors ) <EOL> def to_bytes ( x , charset = sys . getdefaultencoding ( ) , errors = '<STR_LIT:strict>' ) : <EOL> if x is None : <EOL> return None <EOL> if isinstance ( x , ( bytes , bytearray , memoryview ) ) : <EOL> return bytes ( x ) <EOL> if isinstance ( x , str ) : <EOL> return x . encode ( charset , errors ) <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> def to_native ( x , charset = sys . getdefaultencoding ( ) , errors = '<STR_LIT:strict>' ) : <EOL> if x is None or isinstance ( x , str ) : <EOL> return x <EOL> return x . decode ( charset , errors ) <EOL> def to_unicode ( x , charset = sys . getdefaultencoding ( ) , errors = '<STR_LIT:strict>' , <EOL> allow_none_charset = False ) : <EOL> if x is None : <EOL> return None <EOL> if not isinstance ( x , bytes ) : <EOL> return text_type ( x ) <EOL> if charset is None and allow_none_charset : <EOL> return x <EOL> return x . decode ( charset , errors ) </s>
