<s> import binascii <EOL> import base64 <EOL> import collections <EOL> import urllib <EOL> class MultiDict ( collections . UserDict ) : <EOL> def getlist ( self , key ) : <EOL> return self . data [ key ] <EOL> def to_dict ( self ) : <EOL> return self . data <EOL> def __getitem__ ( self , key ) : <EOL> return self . data [ key ] [ - <NUM_LIT:1> ] <EOL> def __setitem__ ( self , key , value ) : <EOL> if isinstance ( value , ( list , tuple ) ) : <EOL> self . data [ key ] = list ( value ) <EOL> else : <EOL> self . data [ key ] = [ value ] <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( self . __class__ . __name__ , self . data ) <EOL> def json_dumps_default ( obj ) : <EOL> if isinstance ( obj , collections . UserDict ) : <EOL> return obj . to_dict ( ) <EOL> return obj <EOL> def parse_query_string ( query_string , encoding = '<STR_LIT:utf-8>' ) : <EOL> query_dict = collections . defaultdict ( list ) <EOL> for query_item in query_string . split ( '<STR_LIT:&>' ) : <EOL> if '<STR_LIT:=>' not in query_item : <EOL> continue <EOL> keyword , value = query_item . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> value = urllib . parse . unquote_plus ( value ) <EOL> query_dict [ keyword ] . append ( to_text ( value , encoding = encoding ) ) <EOL> return query_dict <EOL> def to_header_key ( key ) : <EOL> return '<STR_LIT:->' . join ( x . capitalize ( ) for x in key . split ( '<STR_LIT:->' ) ) <EOL> def to_text ( st , encoding = '<STR_LIT:utf-8>' ) : <EOL> if isinstance ( st , str ) : <EOL> return st <EOL> elif isinstance ( st , collections . ByteString ) : <EOL> return st . decode ( encoding ) <EOL> else : <EOL> return str ( st ) <EOL> def to_bytes ( bt , encoding = '<STR_LIT:utf-8>' ) : <EOL> if isinstance ( bt , collections . ByteString ) : <EOL> return bt <EOL> elif isinstance ( bt , str ) : <EOL> return bt . encode ( encoding ) <EOL> else : <EOL> return bytes ( bt ) <EOL> class Authorization : <EOL> def __init__ ( self , _type , username , password ) : <EOL> self . type = _type <EOL> self . username = username <EOL> self . password = password <EOL> def __eq__ ( self , other ) : <EOL> return ( <EOL> self . type == other . type and <EOL> self . username == other . username and <EOL> self . password == other . password <EOL> ) <EOL> __hash__ = object . __hash__ <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self . __class__ . __name__ , self . type , self . username <EOL> ) <EOL> def parse_basic_auth_header ( value ) : <EOL> try : <EOL> auth_type , auth_info = to_bytes ( value ) . split ( None , <NUM_LIT:1> ) <EOL> except ValueError : <EOL> return <EOL> auth_type = auth_type . lower ( ) <EOL> if auth_type == b'<STR_LIT>' : <EOL> try : <EOL> username , password = base64 . b64decode ( auth_info ) . split ( b'<STR_LIT::>' , <NUM_LIT:1> ) <EOL> except ( binascii . Error , ValueError ) : <EOL> return <EOL> return Authorization ( <EOL> to_text ( auth_type ) , <EOL> username = to_text ( username ) , <EOL> password = to_text ( password ) <EOL> ) <EOL> def cookie_date ( ) : <EOL> pass </s>
