当前位置: 首页>>代码示例>>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;未经允许,请勿转载。