<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import urllib <EOL> from pyactiveresource import connection <EOL> from pyactiveresource import formats <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class FakeConnection ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , format = formats . XMLFormat ) : <EOL> """<STR_LIT>""" <EOL> self . format = format <EOL> self . _request_map = { } <EOL> self . _debug_only = False <EOL> def _split_path ( self , path ) : <EOL> """<STR_LIT>""" <EOL> path_only , query_string = urllib . splitquery ( path ) <EOL> if query_string : <EOL> query_dict = dict ( [ i . split ( '<STR_LIT:=>' ) for i in query_string . split ( '<STR_LIT:&>' ) ] ) <EOL> else : <EOL> query_dict = { } <EOL> return path_only , query_dict <EOL> def debug_only ( self , debug = True ) : <EOL> self . _debug_only = debug <EOL> def respond_to ( self , method , path , headers , data , body , <EOL> response_headers = None ) : <EOL> """<STR_LIT>""" <EOL> path_only , query = self . _split_path ( path ) <EOL> if response_headers is None : <EOL> response_headers = { } <EOL> self . _request_map . setdefault ( method , [ ] ) . append ( <EOL> ( ( path_only , query , headers , data ) , ( body , response_headers ) ) ) <EOL> def _lookup_response ( self , method , path , headers , data ) : <EOL> path_only , query = self . _split_path ( path ) <EOL> for key , value in self . _request_map . get ( method , { } ) : <EOL> if key == ( path_only , query , headers , data ) : <EOL> response_body , response_headers = value <EOL> return connection . Response ( <NUM_LIT:200> , response_body , response_headers ) <EOL> raise Error ( '<STR_LIT>' % <EOL> ( path , headers , data ) ) <EOL> def get ( self , path , headers = None ) : <EOL> """<STR_LIT>""" <EOL> return self . format . decode ( <EOL> self . _lookup_response ( '<STR_LIT>' , path , headers , None ) . body ) <EOL> def post ( self , path , headers = None , data = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _lookup_response ( '<STR_LIT>' , path , headers , data ) <EOL> def put ( self , path , headers = None , data = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _lookup_response ( '<STR_LIT>' , path , headers , data ) <EOL> def delete ( self , path , headers = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _lookup_response ( '<STR_LIT>' , path , headers , None ) </s>
