event.py
来自「Harvestman-最新版本」· Python 代码 · 共 64 行
PY
64 行
# -- coding: utf-8"""event.py - Module defining an event notification frameworkassociated with the data flow in HarvestMan.Created Anand B Pillai <abpillai at gmail dot com> Feb 28 2008Copyright (C) 2008 Anand B Pillai."""from harvestman.lib.common.common import *from harvestman.lib.common.singleton import Singletonclass Event(object): """ Event class for HarvestMan """ def __init__(self): self.name = '' self.config = objects.config self.url = None self.document = Noneclass HarvestManEvent(Singleton): """ Event manager class for HarvestMan """ alias = 'eventmgr' def __init__(self): self.events = {} def bind(self, event, funktion, *args): """ Register for a function 'funktion' to be bound to a certain event. The return value of the function will be used to determine the behaviour of the original function which raises the event in cases of events which are called before the original function bound to the event. For events which are raised after the original function is called, the behavior of the original function is not changed """ # An event is a string, you can bind only one function to an event # The function should accept a default first argument which is the # event object. The event object will provide 4 attributes, namely # the event name, the url associated to the event (should be valid), # the document associated to the event (could be None) and the configuration # object of the system. self.events[event] = (funktion, args) # print self.events def raise_event(self, event, url, document=None, **kwargs): """ Raise a certain event. This automatically calls back on any function registered for the event and returns the return value of that function. This is an internal method """ try: funktion, args = self.events[event] eventobj = Event() eventobj.name = event eventobj.url = url eventobj.document = document # Other keyword arguments return funktion(eventobj, *args, **kwargs) except KeyError: pass
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?