當前位置: 首頁>>代碼示例>>Python>>正文


Python EventBus.dist方法代碼示例

本文整理匯總了Python中synapse.eventbus.EventBus.dist方法的典型用法代碼示例。如果您正苦於以下問題:Python EventBus.dist方法的具體用法?Python EventBus.dist怎麽用?Python EventBus.dist使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在synapse.eventbus.EventBus的用法示例。


在下文中一共展示了EventBus.dist方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Cortex

# 需要導入模塊: from synapse.eventbus import EventBus [as 別名]
# 或者: from synapse.eventbus.EventBus import dist [as 別名]
class Cortex(EventBus):
    '''
    Top level Cortex key/valu storage object.
    '''
    def __init__(self, link, model=None):
        EventBus.__init__(self)

        self.link = link

        self.lock = threading.Lock()
        self.statfuncs = {}

        self.model = model
        self.sizebymeths = {}
        self.rowsbymeths = {}

        self.savebus = EventBus()
        self.loadbus = EventBus()

        self.loadbus.on('core:save:add:rows', self._loadAddRows)

        self.loadbus.on('core:save:del:rows:by:iden', self._loadDelRowsById)
        self.loadbus.on('core:save:del:rows:by:prop', self._loadDelRowsByProp)

        self.loadbus.on('core:save:set:rows:by:idprop', self._loadSetRowsByIdProp)
        self.loadbus.on('core:save:del:rows:by:idprop', self._loadDelRowsByIdProp)

        self.onfini( self.savebus.fini )
        self.onfini( self.loadbus.fini )

        self.addStatFunc('any',self._calcStatAny)
        self.addStatFunc('all',self._calcStatAll)
        self.addStatFunc('min',self._calcStatMin)
        self.addStatFunc('max',self._calcStatMax)
        self.addStatFunc('sum',self._calcStatSum)
        self.addStatFunc('count',self._calcStatCount)
        self.addStatFunc('histo',self._calcStatHisto)
        self.addStatFunc('average',self._calcStatAverage)

        self._initCortex()

        self.isok = True

    def setSaveFd(self, fd, load=True):
        '''
        Set a save fd for the cortex and optionally load.

        Example:

            core.setSaveFd(fd)

        '''
        if load:
            for mesg in msgpackfd(fd):
                self.loadbus.dist(mesg)

        def savemesg(mesg):
            fd.write( msgenpack(mesg) )

        self.savebus.link(savemesg)

    def setDataModel(self, model):
        '''
        Set a DataModel instance to enforce when using Tufo API.

        Example:

            core.setDataModel(model)

        '''
        self.model = model

    def getDataModel(self):
        '''
        Return the DataModel instance for this Cortex.

        Example:

            model = core.getDataModel()
            if model != None:
                dostuff(model)

        '''
        return self.model

    def genDataModel(self):
        '''
        Return (and create if needed) the DataModel instance for this Cortex.

        Example:

            model = core.genDataModel()

        '''
        if self.model == None:
            self.model = s_datamodel.DataModel()
        return self.model

    def getDataModelDict(self):
        '''
#.........這裏部分代碼省略.........
開發者ID:imjonsnooow,項目名稱:synapse,代碼行數:103,代碼來源:common.py

示例2: Cortex

# 需要導入模塊: from synapse.eventbus import EventBus [as 別名]
# 或者: from synapse.eventbus.EventBus import dist [as 別名]

#.........這裏部分代碼省略.........
            [ self.delTufoTag(t,valu) for t in self.getTufosByTag(form,valu) ]

    def _onAddSynTag(self, mesg):
        tufo = mesg[1].get('tufo')
        uptag = tufo[1].get('syn:tag:up')

        if uptag != None:
            self._genTufoTag(uptag)

    def _onFormSynTag(self, mesg):
        valu = mesg[1].get('valu')
        props = mesg[1].get('props')

        tags = valu.split('.')

        tlen = len(tags)

        if tlen > 1:
            props['syn:tag:up'] = '.'.join(tags[:-1])

        props['syn:tag:depth'] = tlen - 1

    def setSaveFd(self, fd, load=True, fini=False):
        '''
        Set a save fd for the cortex and optionally load.

        Example:

            core.setSaveFd(fd)

        '''
        if load:
            for mesg in msgpackfd(fd):
                self.loadbus.dist(mesg)

        self.onfini( fd.flush )
        if fini:
            self.onfini( fd.close )

        def savemesg(mesg):
            fd.write( msgenpack(mesg) )

        self.savebus.link(savemesg)

    def setDataModel(self, model):
        '''
        Set a DataModel instance to enforce when using Tufo API.

        Example:

            core.setDataModel(model)

        '''
        self.model = model

    def getDataModel(self):
        '''
        Return the DataModel instance for this Cortex.

        Example:

            model = core.getDataModel()
            if model != None:
                dostuff(model)

        '''
開發者ID:jhsmith,項目名稱:synapse,代碼行數:70,代碼來源:common.py


注:本文中的synapse.eventbus.EventBus.dist方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。