コード例 #1
0
 def handle_request(self, request):
     response = Response(request)
     request_data = request.get_post_data_as_dictionary()
     request_data.update(request.get_query_string_as_dictionary())
     if not (request_data.has_key('type') and request_data.has_key('id')
             and request_data.has_key('method')):
         response.error(400, 'Missnig required param type, id, or method.')
         return
     id = urllib.unquote_plus(request_data.get('id')[0])
     if request_data.get('type')[0] == 'node':
         target = as_node(id)
     elif request_data.get('type')[0] == 'event':
         target = Event.get_event(id)
     else:
         response.error(400, 'Unknown type.')
         return
     methodname = urllib.unquote_plus(request_data.get('method')[0])
     method = getattr(target, methodname)
     args = urllib.unquote_plus(request_data.get('args', ['()'])[0])
     args = eval(args)
     keywords = urllib.unquote_plus(request_data.get('keywords', ['{}'])[0])
     keywords = eval(keywords)
     result = method(*args, **keywords)
     result = repr(result)
     self.message('Invoking %s on %s with %s, %s, returned %s' %
                  (methodname, id, args, keywords, result))
     response.send(result)
コード例 #2
0
ファイル: request_handler.py プロジェクト: mcruse/monotone
 def handle_request(self, request):
     response = Response(request)
     request_data = request.get_post_data_as_dictionary()
     request_data.update(request.get_query_string_as_dictionary())
     if not (request_data.has_key('type') and
             request_data.has_key('id') and
             request_data.has_key('method')):
         response.error(400, 'Missnig required param type, id, or method.')
         return
     id = urllib.unquote_plus(request_data.get('id')[0])
     if request_data.get('type')[0] == 'node':
         target = as_node(id)
     elif request_data.get('type')[0] == 'event':
         target = Event.get_event(id)
     else:
         response.error(400, 'Unknown type.')
         return
     methodname = urllib.unquote_plus(request_data.get('method')[0])
     method = getattr(target, methodname)
     args = urllib.unquote_plus(request_data.get('args', ['()'])[0])
     args = eval(args)
     keywords = urllib.unquote_plus(request_data.get('keywords', ['{}'])[0])
     keywords = eval(keywords)
     result = method(*args, **keywords)
     result = repr(result)
     self.message('Invoking %s on %s with %s, %s, returned %s' % (
                      methodname, id, args, keywords, result))
     response.send(result)
コード例 #3
0
ファイル: adapters.py プロジェクト: mcruse/monotone
 def __call__(self, local=False):
     """
         Get Event instance from pickle adapter.  
         
         If pickled event does not match existing event, 
         instantiate one using class.
         
         If optional parameter 'local' provided and true, 
         override event's 'origin' with None so current 
         LOCALORIGIN is used.  This picks up IP address 
         changes 
         
     """
     if self.event is None:
         try: 
             self.event = Event.get_event(self.state['GUID'])
         except KeyError:
             guid = self.state.get('GUID')
             source = self.state.get('source')(local)
             origin = None if local else self.state.get('origin')
             event_class = self.state.get('class')
             self.event = event_class(source, origin, guid)
             self.event.message('created by AlarmEventPickler.__call__().')
         else: 
             self.event.message('used by AlarmEventPickler.__call__().')
         history = self.state['history']
         self.event.synchronize([IPickles(evt)(local) for evt in history])
     return self.event
コード例 #4
0
ファイル: adapters.py プロジェクト: mcruse/monotone
 def __call__(self, local=False):
     if self.action is None:
         try: 
             self.action = Event.get_event(self.state.get('GUID'))
         except KeyError:
             args = self.state.get("args", ())
             source = self.state.get("source")(local)
             self.action = self.state.get('class')(source, *args)
     return self.action
コード例 #5
0
ファイル: adapters.py プロジェクト: mcruse/monotone
 def __call__(self, local=False):
     if self.event is None:
         try: 
             self.event = Event.get_event(self.state['GUID'])
         except KeyError:
             guid = self.state.get('GUID')
             source = self.state.get('source')(local)
             action = self.state.get('action')(local)
             origin = None if local else self.state.get('origin')
             event_class = self.state.get('class')
             self.event = event_class(source, action, origin, guid)
     return self.event
コード例 #6
0
ファイル: adapters.py プロジェクト: mcruse/monotone
 def __call__(self):
     if self.event is None:
         state = self.state
         guid = state.get('guid')
         try: cloudevent = Event.get_event(guid)
         except KeyError:
             source = state.get('source')()
             topics = state.get('topics')
             origin = state.get('origin')
             targets = state.get('targets')
             event = state.get('event')
             portal=state.get('portal')
             cloudevent = state.get('class')(source, origin, targets,portal,
                                             topics, event, guid)
         self.event = cloudevent
     return self.event
コード例 #7
0
 def __call__(self, local=False):
     if self.__source is None:
         state = self.__state
         if local:
             state["origin"] = Event.LOCALORIGIN
         if state['type'] == 'EventSource':
             self.__source = state['source']
         elif state['type'] == 'Event':
             self.__source = Event.get_event(state['GUID'])
             if local and not self.__source.is_local():
                 message = "%s overriding source %s origin to local."
                 msglog.warn(message % (self, self.__source))
                 self.__source.set_local()
         elif state['origin'] == Event.LOCALORIGIN:
             self.__source = as_node(state['URL'])
         else:
             self.__dict__.update(state['config'])
             self.__source = self
     return self.__source