<s> import sys <EOL> import types <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> <EOL> if PY3 : <EOL> string_types = str , <EOL> integer_types = int , <EOL> class_types = type , <EOL> text_type = str <EOL> long = int <EOL> else : <EOL> string_types = basestring , <EOL> integer_types = ( int , long ) <EOL> class_types = ( type , types . ClassType ) <EOL> text_type = unicode <EOL> long = long <EOL> def text_ ( s , encoding = '<STR_LIT>' , errors = '<STR_LIT:strict>' ) : <EOL> if isinstance ( s , bytes ) : <EOL> return s . decode ( encoding , errors ) <EOL> return s <EOL> def bytes_ ( s , encoding = '<STR_LIT>' , errors = '<STR_LIT:strict>' ) : <EOL> if isinstance ( s , text_type ) : <EOL> return s . encode ( encoding , errors ) <EOL> return s <EOL> if PY3 : <EOL> def native_ ( s , encoding = '<STR_LIT>' , errors = '<STR_LIT:strict>' ) : <EOL> if isinstance ( s , text_type ) : <EOL> return s <EOL> return str ( s , encoding , errors ) <EOL> else : <EOL> def native_ ( s , encoding = '<STR_LIT>' , errors = '<STR_LIT:strict>' ) : <EOL> if isinstance ( s , text_type ) : <EOL> return s . encode ( encoding , errors ) <EOL> return str ( s ) <EOL> try : <EOL> from queue import Queue , Empty <EOL> except ImportError : <EOL> from Queue import Queue , Empty <EOL> if PY3 : <EOL> from urllib import parse <EOL> urlparse = parse <EOL> from urllib . parse import quote as url_quote <EOL> from urllib . parse import urlencode as url_encode , quote_plus <EOL> from urllib . request import urlopen as url_open <EOL> else : <EOL> import urlparse <EOL> from urllib import quote_plus <EOL> from urllib import quote as url_quote <EOL> from urllib import unquote as url_unquote <EOL> from urllib import urlencode as url_encode <EOL> from urllib2 import urlopen as url_open <EOL> if PY3 : <EOL> def reraise ( exc_info ) : <EOL> etype , exc , tb = exc_info <EOL> if exc . __traceback__ is not tb : <EOL> raise exc . with_traceback ( tb ) <EOL> raise exc <EOL> else : <EOL> exec ( "<STR_LIT>" ) <EOL> if PY3 : <EOL> def iteritems_ ( d ) : <EOL> return d . items ( ) <EOL> def itervalues_ ( d ) : <EOL> return d . values ( ) <EOL> else : <EOL> def iteritems_ ( d ) : <EOL> return d . iteritems ( ) <EOL> def itervalues_ ( d ) : <EOL> return d . itervalues ( ) <EOL> if PY3 : <EOL> def unquote ( string ) : <EOL> if not string : <EOL> return b'<STR_LIT>' <EOL> res = string . split ( b'<STR_LIT:%>' ) <EOL> if len ( res ) != <NUM_LIT:1> : <EOL> string = res [ <NUM_LIT:0> ] <EOL> for item in res [ <NUM_LIT:1> : ] : <EOL> try : <EOL> string += bytes ( [ int ( item [ : <NUM_LIT:2> ] , <NUM_LIT:16> ) ] ) + item [ <NUM_LIT:2> : ] <EOL> except ValueError : <EOL> string += b'<STR_LIT:%>' + item <EOL> return string <EOL> def url_unquote ( s ) : <EOL> return unquote ( s . encode ( '<STR_LIT:ascii>' ) ) . decode ( '<STR_LIT>' ) <EOL> def parse_qsl_text ( qs , encoding = '<STR_LIT:utf-8>' ) : <EOL> qs = qs . encode ( '<STR_LIT>' ) <EOL> qs = qs . replace ( b'<STR_LIT:+>' , b'<STR_LIT:U+0020>' ) <EOL> pairs = [ s2 for s1 in qs . split ( b'<STR_LIT:&>' ) for s2 in s1 . split ( b'<STR_LIT:;>' ) if s2 ] <EOL> for name_value in pairs : <EOL> nv = name_value . split ( b'<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> if len ( nv ) != <NUM_LIT:2> : <EOL> nv . append ( '<STR_LIT>' ) <EOL> name = unquote ( nv [ <NUM_LIT:0> ] ) <EOL> value = unquote ( nv [ <NUM_LIT:1> ] ) <EOL> yield ( name . decode ( encoding ) , value . decode ( encoding ) ) <EOL> else : <EOL> from urlparse import parse_qsl <EOL> def parse_qsl_text ( qs , encoding = '<STR_LIT:utf-8>' ) : <EOL> qsl = parse_qsl ( <EOL> qs , <EOL> keep_blank_values = True , <EOL> strict_parsing = False <EOL> ) <EOL> for ( x , y ) in qsl : <EOL> yield ( x . decode ( encoding ) , y . decode ( encoding ) ) <EOL> if PY3 : <EOL> from html import escape <EOL> else : <EOL> from cgi import escape </s>
