#NEWLINE# def UrlMock( self , req , num_messages = 10 , **kwargs ) : #NEWLINE# #INDENT# "A mock for url handler processing from the server's POV." #NEWLINE# if ( 'server.pem' in req . get_full_url ( ) ) : #NEWLINE# #INDENT# return StringIO . StringIO ( config_lib . CONFIG [ 'Frontend.certificate' ] ) #NEWLINE# #UNINDENT# _ = kwargs #NEWLINE# try : #NEWLINE# #INDENT# self . client_communication = rdf_flows . ClientCommunication ( self . data ) #NEWLINE# ( self . messages , source , ts ) = self . server_communicator . DecodeMessages ( self . client_communication ) #NEWLINE# self . assertEqual ( source , self . client_cn ) #NEWLINE# for ( i , message ) in enumerate ( self . messages ) : #NEWLINE# #INDENT# if message . request_id : #NEWLINE# #INDENT# self . assertEqual ( message . response_id , i ) #NEWLINE# self . assertEqual ( message . request_id , 1 ) #NEWLINE# self . assertEqual ( message . session_id , 'aff4:/W:session' ) #NEWLINE# #UNINDENT# #UNINDENT# response_comms = rdf_flows . ClientCommunication ( ) #NEWLINE# message_list = rdf_flows . MessageList ( ) #NEWLINE# for i in range ( 0 , num_messages ) : #NEWLINE# #INDENT# message_list . job . Append ( request_id = i , ** self . server_response ) #NEWLINE# #UNINDENT# self . server_communicator . EncodeMessages ( message_list , response_comms , destination = source , timestamp = ts , api_version = self . client_communication . api_version ) #NEWLINE# return StringIO . StringIO ( response_comms . SerializeToString ( ) ) #NEWLINE# #UNINDENT# except communicator . UnknownClientCert : #NEWLINE# #INDENT# raise urllib2 . HTTPError ( url = None , code = 406 , msg = None , hdrs = None , fp = None ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# logging . info ( 'Exception in mock urllib2.Open: %s.' , e ) #NEWLINE# self . last_urlmock_error = e #NEWLINE# if flags . FLAGS . debug : #NEWLINE# #INDENT# pdb . post_mortem ( ) #NEWLINE# #UNINDENT# raise urllib2 . HTTPError ( url = None , code = 500 , msg = None , hdrs = None , fp = None )