コード例 #1
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
    def test_datamodel_forms(self):
        model = s_datamodel.DataModel(load=False)
        forms = model.getTufoForms()
        self.isinstance(forms, list)
        self.notin('syn:prop', forms)
        self.notin('inet:ipv4', forms)

        model = s_datamodel.DataModel()
        forms = model.getTufoForms()
        self.isin('syn:prop', forms)
        self.isin('inet:ipv4', forms)
コード例 #2
0
ファイル: test_datamodel.py プロジェクト: triplekill/synapse
    def test_datamodel_cortex(self):

        model = s_datamodel.DataModel()
        model.addTufoForm('foo')
        model.addTufoProp('foo', 'bar', ptype='int', defval=10)

        core = s_cortex.openurl('ram:///')
        core.setDataModel( model )

        core.formTufoByProp('foo','hehe')
        core.formTufoByProp('foo','haha')

        core.formTufoByProp('foo','blah', bar=99)

        tufo0 = core.formTufoByProp('foo','hehe')
        self.assertEqual( tufo0[1].get('foo:bar'), 10 )

        core.setTufoProp(tufo0,'bar',30)
        self.assertEqual( tufo0[1].get('foo:bar'), 30 )

        tufo1 = core.formTufoByProp('foo','hehe')
        self.assertEqual( tufo0[0], tufo1[0] )

        tufos = core.getTufosByProp('foo')
        self.assertEqual( len(tufos) , 3 )

        tufos = core.getTufosByProp('foo:bar', valu=30, limit=20)
        self.assertEqual( len(tufos) , 1 )

        tufos = core.getTufosByProp('foo:bar', valu=99, limit=20)
        self.assertEqual( len(tufos) , 1 )
コード例 #3
0
ファイル: test_datamodel.py プロジェクト: triplekill/synapse
    def test_datamodel_hash(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')

        model.addTufoProp('foo','md5', ptype='hash:md5')
        model.addTufoProp('foo','sha1', ptype='hash:sha1')
        model.addTufoProp('foo','sha256', ptype='hash:sha256')

        fakemd5 = 'AA' * 16
        fakesha1 = 'AA' * 20
        fakesha256= 'AA' * 32

        self.assertEqual( model.getPropNorm('foo:md5', fakemd5) , fakemd5.lower() )
        self.assertEqual( model.getPropNorm('foo:sha1', fakesha1) , fakesha1.lower() )
        self.assertEqual( model.getPropNorm('foo:sha256', fakesha256) , fakesha256.lower() )

        self.assertRaises( s_datamodel.BadTypeNorm, model.getPropNorm, 'foo:md5', 'asdf' )
        self.assertRaises( s_datamodel.BadTypeNorm, model.getPropNorm, 'foo:sha1', 'asdf' )
        self.assertRaises( s_datamodel.BadTypeNorm, model.getPropNorm, 'foo:sha256', 'asdf' )

        self.assertEqual( model.getPropParse('foo:md5', fakemd5) , fakemd5.lower() )
        self.assertEqual( model.getPropParse('foo:sha1', fakesha1) , fakesha1.lower() )
        self.assertEqual( model.getPropParse('foo:sha256', fakesha256) , fakesha256.lower() )

        self.assertRaises( s_datamodel.BadTypeParse, model.getPropParse, 'foo:md5', 'asdf' )
        self.assertRaises( s_datamodel.BadTypeParse, model.getPropParse, 'foo:sha1', 'asdf' )
        self.assertRaises( s_datamodel.BadTypeParse, model.getPropParse, 'foo:sha256', 'asdf' )
コード例 #4
0
    def test_datamodel_types(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'bar', ptype='int')
        model.addTufoProp('foo', 'baz', ptype='str')
        model.addTufoProp('foo', 'faz', ptype='syn:tag')
        model.addTufoProp('foo', 'zip', ptype='str:lwr')

        self.eq(model.getPropRepr('foo:bar', 10), '10')
        self.eq(model.getPropRepr('foo:baz', 'woot'), 'woot')
        self.eq(model.getPropRepr('foo:faz', 'woot.toow'), 'woot.toow')
        self.eq(model.getPropRepr('foo:zip', 'woot'), 'woot')
        self.eq(model.getPropRepr('foo:nonexistent', 'stillwoot'), 'stillwoot')

        self.eq(model.getPropType('foo:bar').name, 'int')

        self.eq(model.getPropNorm('foo:bar', 10)[0], 10)
        self.eq(model.getPropNorm('foo:baz', 'woot')[0], 'woot')
        self.eq(model.getPropNorm('foo:faz', 'WOOT.toow')[0], 'woot.toow')
        self.eq(model.getPropNorm('foo:zip', 'WOOT')[0], 'woot')

        self.eq(model.getPropParse('foo:bar', '10')[0], 10)
        self.eq(model.getPropParse('foo:baz', 'woot')[0], 'woot')
        self.eq(model.getPropParse('foo:faz', 'WOOT.toow')[0], 'woot.toow')
        self.eq(model.getPropParse('foo:zip', 'WOOT')[0], 'woot')
        self.eq(model.getPropParse('foo:nonexistent', 'stillwoot'), 'stillwoot')
コード例 #5
0
    def test_datamodel_types(self):
        model = s_datamodel.DataModel()
        model.addTufoForm('foo')
        model.addTufoProp('foo', 'bar', ptype='int')
        model.addTufoProp('foo', 'baz', ptype='str')
        model.addTufoProp('foo', 'faz', ptype='syn:tag')
        model.addTufoProp('foo', 'zip', ptype='str:lwr')

        self.assertEqual(model.getPropRepr('foo:bar', 10), '10')
        self.assertEqual(model.getPropRepr('foo:baz', 'woot'), 'woot')
        self.assertEqual(model.getPropRepr('foo:faz', 'woot.toow'),
                         'woot.toow')
        self.assertEqual(model.getPropRepr('foo:zip', 'woot'), 'woot')

        self.assertEqual(model.getPropNorm('foo:bar', 10), 10)
        self.assertEqual(model.getPropNorm('foo:baz', 'woot'), 'woot')
        self.assertEqual(model.getPropNorm('foo:faz', 'WOOT.toow'),
                         'woot.toow')
        self.assertEqual(model.getPropNorm('foo:zip', 'WOOT'), 'woot')

        self.assertEqual(model.getPropParse('foo:bar', '10'), 10)
        self.assertEqual(model.getPropParse('foo:baz', 'woot'), 'woot')
        self.assertEqual(model.getPropParse('foo:faz', 'WOOT.toow'),
                         'woot.toow')
        self.assertEqual(model.getPropParse('foo:zip', 'WOOT'), 'woot')
コード例 #6
0
    def test_datamodel_hash(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')

        model.addTufoProp('foo', 'md5', ptype='hash:md5')
        model.addTufoProp('foo', 'sha1', ptype='hash:sha1')
        model.addTufoProp('foo', 'sha256', ptype='hash:sha256')

        fakemd5 = 'AA' * 16
        fakesha1 = 'AA' * 20
        fakesha256 = 'AA' * 32

        self.eq(model.getPropNorm('foo:md5', fakemd5)[0], fakemd5.lower())
        self.eq(model.getPropNorm('foo:sha1', fakesha1)[0], fakesha1.lower())
        self.eq(model.getPropNorm('foo:sha256', fakesha256)[0], fakesha256.lower())

        self.raises(BadTypeValu, model.getPropNorm, 'foo:md5', 'asdf')
        self.raises(BadTypeValu, model.getPropNorm, 'foo:sha1', 'asdf')
        self.raises(BadTypeValu, model.getPropNorm, 'foo:sha256', 'asdf')

        self.eq(model.getPropParse('foo:md5', fakemd5)[0], fakemd5.lower())
        self.eq(model.getPropParse('foo:sha1', fakesha1)[0], fakesha1.lower())
        self.eq(model.getPropParse('foo:sha256', fakesha256)[0], fakesha256.lower())

        self.raises(BadTypeValu, model.getPropParse, 'foo:md5', 'asdf')
        self.raises(BadTypeValu, model.getPropParse, 'foo:sha1', 'asdf')
        self.raises(BadTypeValu, model.getPropParse, 'foo:sha256', 'asdf')
コード例 #7
0
    def test_datamodel_inet(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'addr', ptype='inet:ipv4')
        model.addTufoProp('foo', 'serv', ptype='inet:srv4')
        model.addTufoProp('foo', 'port', ptype='inet:port')

        self.assertEqual(model.getPropNorm('foo:port', 20)[0], 20)
        self.assertEqual(model.getPropParse('foo:port', '0x10')[0], 16)

        self.assertEqual(model.getPropRepr('foo:addr', 0x01020304), '1.2.3.4')
        self.assertEqual(
            model.getPropNorm('foo:addr', 0x01020304)[0], 0x01020304)
        self.assertEqual(
            model.getPropParse('foo:addr', '1.2.3.4')[0], 0x01020304)

        self.assertEqual(model.getPropRepr('foo:serv', 0x010203040010),
                         '1.2.3.4:16')
        self.assertEqual(
            model.getPropNorm('foo:serv', 0x010203040010)[0], 0x010203040010)
        self.assertEqual(
            model.getPropParse('foo:serv', '1.2.3.4:255')[0], 0x0102030400ff)

        self.assertRaises(BadTypeValu, model.getPropNorm, 'foo:port', 0xffffff)
        self.assertRaises(BadTypeValu, model.getPropParse, 'foo:port',
                          '999999')
コード例 #8
0
    def test_datamodel_badprop(self):
        model = s_datamodel.DataModel()

        self.raises(BadPropName, model.addTufoForm, 'foo.bar')

        model.addTufoForm('foo:bar')
        self.raises(BadPropName, model.addTufoProp, 'foo:bar', 'b*z')
コード例 #9
0
ファイル: test_datamodel.py プロジェクト: galyac/synapse
    def test_datamodel_getPropInfo(self):
        model = s_datamodel.DataModel()

        model.addType('foo:bar', subof='str', doc='foo bar doc')
        model.addType('foo:baz', subof='foo:bar')

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'meow', ptype='foo:baz')
        model.addTufoProp('foo', 'bark', doc='lala')
        model.addTufoProp('foo', 'meow:purr', ptype='foo:baz', title='purr', doc='The sound a purr makes')

        self.eq(model.getPropInfo('foo:meow', 'req'), False)
        self.eq(model.getPropInfo('foo:meow', 'base'), 'meow')
        self.eq(model.getPropInfo('foo:meow', 'relname'), 'meow')
        self.eq(model.getPropInfo('foo:meow', 'defval'), None)
        self.eq(model.getPropInfo('foo:meow', 'title'), '')
        self.eq(model.getPropInfo('foo:meow', 'doc'), 'foo bar doc')

        self.eq(model.getPropInfo('foo:bark', 'doc'), 'lala')
        self.eq(model.getPropInfo('foo:bark', 'title'), '')
        self.eq(model.getPropInfo('foo:bark', 'base'), 'bark')
        self.eq(model.getPropInfo('foo:bark', 'relname'), 'bark')
        self.eq(model.getPropInfo('foo:meow', 'defval'), None)
        self.eq(model.getPropInfo('foo:meow', 'req'), False)

        self.eq(model.getPropInfo('foo:meow:purr', 'req'), False)
        self.eq(model.getPropInfo('foo:meow:purr', 'base'), 'purr')
        self.eq(model.getPropInfo('foo:meow:purr', 'relname'), 'meow:purr')
        self.eq(model.getPropInfo('foo:meow:purr', 'defval'), None)
        self.eq(model.getPropInfo('foo:meow:purr', 'title'), 'purr')
        self.eq(model.getPropInfo('foo:meow:purr', 'doc'), 'The sound a purr makes')

        self.eq(model.getPropInfo('foo:nonexistent', 'doc'), None)
コード例 #10
0
    def test_datamodel_filepath(self):
        model = s_datamodel.DataModel()
        prop = 'file:path'

        data = (
            ('/', ('/', {'dir': '', 'depth': 0}), '/'),
            ('//', ('/', {'dir': '', 'depth': 0}), '//'),
            ('////////////', ('/', {'dir': '', 'depth': 0}), '////////////'),
            ('weirD', ('weird', {'base': 'weird', 'dir': '', 'depth': 1}), 'weirD'),

            ('foo1', ('foo1', {'base': 'foo1', 'dir': '', 'depth': 1}), 'foo1'),
            ('/foo2', ('/foo2', {'base': 'foo2', 'dir': '', 'depth': 1}), '/foo2'),
            ('/foo/bar3', ('/foo/bar3', {'base': 'bar3', 'dir': '/foo', 'depth': 2}), '/foo/bar3'),
            ('/foo/bar4    ', ('/foo/bar4    ', {'base': 'bar4    ', 'dir': '/foo', 'depth': 2}), '/foo/bar4    '),  # These are valid filepaths
            ('/foo/bar5/', ('/foo/bar5', {'base': 'bar5', 'dir': '/foo', 'depth': 2}), '/foo/bar5/'),

            ('C:\\', ('c:', {'base': 'c:', 'depth': 1, 'dir': ''}), 'C:\\'),
            ('C:\\Program Files\\Foo.bAr.BAZ.exe',
                ('c:/program files/foo.bar.baz.exe', {'base': 'foo.bar.baz.exe', 'dir': 'c:/program files', 'depth': 3, 'ext': 'exe'}), 'C:\\Program Files\\Foo.bAr.BAZ.exe')
        )

        for valu, expected, expected_repr in data:

            self.eq(expected, model.getTypeNorm(prop, valu))
            self.eq(expected, model.getTypeParse(prop, valu))
            self.eq(expected_repr, model.getTypeRepr(prop, valu))
コード例 #11
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
    def test_datamodel_istufoform(self):
        modl = s_datamodel.DataModel()
        self.true(modl.isTufoForm('file:bytes'))
        self.false(modl.isTufoForm('file:bytes:size'))
        self.false(modl.isTufoForm('node:ndef'))

        self.none(modl.reqTufoForm('file:bytes'))
        self.raises(NoSuchForm, modl.reqTufoForm, 'file:bytes:size')
コード例 #12
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
 def test_datamodel_cast_json(self):
     modl = s_datamodel.DataModel()
     self.eq(modl.getTypeCast('make:json', 1), '1')
     self.eq(modl.getTypeCast('make:json', 'hehe'), '"hehe"')
     self.eq(modl.getTypeCast('make:json', '"hehe"'), '"\\"hehe\\""')
     self.eq(modl.getTypeCast('make:json', {
         "z": 1,
         'yo': 'dawg',
     }), '{"yo":"dawg","z":1}')
コード例 #13
0
ファイル: test_datamodel.py プロジェクト: triplekill/synapse
    def test_datamodel_fail_noprop(self):
        model = s_datamodel.DataModel()
        self.assertRaises( s_datamodel.NoSuchForm, model.addTufoProp, 'foo', 'bar' )

        model.addTufoForm('foo')
        self.assertRaises( s_datamodel.DupPropName, model.addTufoForm, 'foo' )

        model.addTufoProp('foo','bar')
        self.assertRaises( s_datamodel.DupPropName, model.addTufoProp, 'foo', 'bar' )
コード例 #14
0
    def test_datamodel_fail_notype(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        self.assertRaises(s_datamodel.NoSuchType,
                          model.addTufoProp,
                          'foo',
                          'bar',
                          ptype='hehe')
コード例 #15
0
    def test_datamodel_getPropDef(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'meow', ptype='int')

        self.eq(model.getPropDef('foo:meow'), ('foo:meow', {'doc': None, 'title': None, 'defval': None, 'form': 'foo', 'base': 'meow', 'uniq': False, 'ptype': 'int', 'req': False}))
        self.eq(model.getPropDef('foo:meow:nonexistent'), None)
        self.eq(model.getPropDef('foo:meow:nonexistent', glob=False), None)
コード例 #16
0
    def test_datatype_syn_tag(self):
        model = s_datamodel.DataModel()

        self.raises(BadTypeValu, model.getTypeNorm, 'syn:tag', 'asdf qwer')
        self.raises(BadTypeValu, model.getTypeNorm, 'syn:tag', 'foo..bar')

        self.eq(model.getTypeNorm('syn:tag', 'BAR')[0], 'bar')
        self.eq(model.getTypeParse('syn:tag', 'BAR')[0], 'bar')
        self.eq(model.getTypeNorm('syn:tag', 'foo.BAR')[0], 'foo.bar')
        self.eq(model.getTypeParse('syn:tag', 'foo.BAR')[0], 'foo.bar')
コード例 #17
0
    def test_datatype_syn_prop(self):
        model = s_datamodel.DataModel()

        self.raises(BadTypeValu, model.getTypeNorm, 'syn:prop', 'asdf qwer')
        self.raises(BadTypeValu, model.getTypeNorm, 'syn:prop', 'foo::bar')

        self.eq(model.getTypeNorm('syn:prop', 'BAR')[0], 'bar')
        self.eq(model.getTypeParse('syn:prop', 'BAR')[0], 'bar')
        self.eq(model.getTypeNorm('syn:prop', 'foo:BAR')[0], 'foo:bar')
        self.eq(model.getTypeParse('syn:prop', 'foo:BAR')[0], 'foo:bar')
コード例 #18
0
    def test_datamodel_time(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'meow', ptype='time:epoch')

        jan1_2016 = 1451606400
        self.eq(model.getPropNorm('foo:meow', jan1_2016)[0], jan1_2016)
        self.eq(model.getPropRepr('foo:meow', jan1_2016), '2016/01/01 00:00:00')
        self.eq(model.getPropParse('foo:meow', '2016/01/01 00:00:00')[0], jan1_2016)
コード例 #19
0
    def test_datamodel_getPropInfo(self):
        model = s_datamodel.DataModel()

        model.addType('foo:bar', subof='str', doc='foo bar doc')
        model.addType('foo:baz', subof='foo:bar')

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'meow', ptype='foo:baz')

        self.eq(model.getPropInfo('foo:meow', 'doc'), 'foo bar doc')
        self.eq(model.getPropInfo('foo:nonexistent', 'doc'), None)
コード例 #20
0
    def test_datamodel_formbase(self):

        modl = s_datamodel.DataModel()
        modl.addTufoForm('foo:bar')
        modl.addTufoProp('foo:bar', 'baz')

        form, base = modl.getPropFormBase('foo:bar:baz')

        self.eq(form, 'foo:bar')
        self.eq(base, 'baz')

        self.raises(NoSuchProp, modl.getPropFormBase, 'newp:newp')
コード例 #21
0
ファイル: neutool.py プロジェクト: triplekill/synapse
    def __init__(self, neu):
        cmd.Cmd.__init__(self)
        self.prompt = 'neu> '

        s_eventbus.EventBus.__init__(self)

        self.neu = neu

        self._cmd_print = True

        moddef = self.neu.getModelDict()
        self.model = s_datamodel.DataModel(model=moddef)
コード例 #22
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
    def test_datamodel_type_hook(self):
        defs = []
        modl = s_datamodel.DataModel()
        modl.addType('gronk', subof='guid')
        modl.addPropDef('foo:bar', ptype='gronk')
        modl.addPropTypeHook('gronk', defs.append)

        self.len(1, defs)
        self.eq(defs[0][0], 'foo:bar')

        modl.addPropDef('foo:baz', ptype='gronk')

        self.len(2, defs)
        self.eq(defs[1][0], 'foo:baz')
コード例 #23
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
    def test_datamodel_istufoprop(self):
        modl = s_datamodel.DataModel()

        # Types are not props
        self.false(modl.isTufoProp('str:lwr'))

        # Prop does not yet exist
        self.false(modl.isTufoProp('foo:meow'))
        modl.addTufoForm('foo')
        modl.addTufoProp('foo', 'meow', ptype='str:lwr')
        # Forms are props
        self.true(modl.isTufoProp('foo'))
        # And props are props!
        self.true(modl.isTufoProp('foo:meow'))
コード例 #24
0
ファイル: test_datamodel.py プロジェクト: triplekill/synapse
    def test_datamodel_subs(self):
        model = s_datamodel.DataModel()
        model.addTufoForm('foo')
        model.addTufoProp('foo','bar',ptype='int')

        subs = model.getSubProps('foo')

        self.assertEqual( len(subs), 1 )
        self.assertEqual( subs[0][0], 'foo:bar' )

        model.addTufoProp('foo','baz',ptype='int', defval=20)

        defs = model.getSubPropDefs('foo')
        self.assertEqual( defs.get('foo:baz'), 20 )
コード例 #25
0
    def test_datamodel_bool(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'bar', ptype='bool', defval=0)

        self.eq(model.getPropRepr('foo:bar', 1), 'True')
        self.eq(model.getPropRepr('foo:bar', 0), 'False')

        self.eq(model.getPropNorm('foo:bar', True)[0], 1)
        self.eq(model.getPropNorm('foo:bar', False)[0], 0)

        self.eq(model.getPropParse('foo:bar', '1')[0], 1)
        self.eq(model.getPropParse('foo:bar', '0')[0], 0)

        self.raises(BadTypeValu, model.getPropParse, 'foo:bar', 'asdf')
コード例 #26
0
ファイル: test_datamodel.py プロジェクト: triplekill/synapse
    def test_datamodel_bool(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo','bar',ptype='bool', defval=0)

        self.assertEqual( model.getPropRepr('foo:bar', 1), 'True')
        self.assertEqual( model.getPropRepr('foo:bar', 0), 'False')

        self.assertEqual( model.getPropNorm('foo:bar', True) , 1 )
        self.assertEqual( model.getPropNorm('foo:bar', False) , 0 )

        self.assertEqual( model.getPropParse('foo:bar', 'TRUE'), 1 )
        self.assertEqual( model.getPropParse('foo:bar', 'FaLsE'), 0 )

        self.assertRaises( s_datamodel.BadTypeParse, model.getPropParse, 'foo:bar', 'asdf' )
コード例 #27
0
    def test_datamodel_filebase(self):
        model = s_datamodel.DataModel()
        prop = 'file:base'

        data = (
            ('my_COOL_file', ('my_cool_file', {}), 'my_COOL_file'),
            ('my      file', ('my      file', {}), 'my      file'),
            ('!@#$%^&.jpeg', ('!@#$%^&.jpeg', {}), '!@#$%^&.jpeg'),
        )

        for valu, expected, expected_repr in data:

            self.eq(expected, model.getTypeNorm(prop, valu))
            self.eq(expected, model.getTypeParse(prop, valu))
            self.eq(expected_repr, model.getTypeRepr(prop, valu))

        bads = (None, [], {}, 1, '/teehee', 'hoho/haha')
        for bad in bads:
            self.raises(BadTypeValu, model.getTypeNorm, prop, bad)
            self.raises(BadTypeValu, model.getTypeParse, prop, bad)
コード例 #28
0
    def test_datamodel_glob(self):
        model = s_datamodel.DataModel()

        model.addTufoForm('foo')
        model.addTufoProp('foo', 'bar:*', ptype='str:lwr', glob=1)
        self.eq(model.getPropNorm('foo:bar:baz', 'Woot')[0], 'woot')
コード例 #29
0
ファイル: common.py プロジェクト: triplekill/synapse
    def __init__(self, link):
        EventBus.__init__(self)

        self._link = link

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

        self.auth = None
        self.tagcache = {}
        self.splicefuncs = {}

        self.model = s_datamodel.DataModel()

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

        #############################################################
        # buses to save/load *raw* save events
        #############################################################
        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)

        #############################################################
        # bus for model layer sync
        # sync events are fired on the cortex and may be ingested
        # into another coretx using the sync() method.
        #############################################################
        self.on('tufo:add', self._fireCoreSync)
        self.on('tufo:del', self._fireCoreSync)
        self.on('tufo:tag:add', self._fireCoreSync)
        self.on('tufo:tag:del', self._fireCoreSync)

        self.syncact = s_reactor.Reactor()
        self.syncact.act('tufo:add', self._actSyncTufoAdd)
        self.syncact.act('tufo:del', self._actSyncTufoDel)
        self.syncact.act('tufo:tag:add', self._actSyncTufoTagAdd)
        self.syncact.act('tufo:tag:del', self._actSyncTufoTagDel)

        #############################################################

        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.model.addTufoForm('syn:tag', ptype='str:lwr')
        self.model.addTufoProp('syn:tag', 'up', ptype='str:lwr')
        self.model.addTufoProp('syn:tag', 'doc', defval='', ptype='str')
        self.model.addTufoProp('syn:tag', 'depth', defval=0, ptype='int')
        self.model.addTufoProp('syn:tag', 'title', defval='', ptype='str')

        #self.model.addTufoForm('syn:model',ptype='str')

        #self.model.addTufoForm('syn:type',ptype='str')
        #self.model.addTufoProp('syn:type','base',ptype='str',doc='what base type does this type extend?')
        #self.model.addTufoProp('syn:type','baseinfo',ptype='str',doc='Base type specific info (for example, a regex)')

        #self.model.addTufoForm('syn:form',ptype='str:prop')
        #self.model.addTufoProp('syn:form','doc',ptype='str')

        #self.model.addTufoForm('syn:prop',ptype='str:prop')
        #self.model.addTufoProp('syn:prop','doc',ptype='str')
        #self.model.addTufoProp('syn:prop','form',ptype='str:syn:prop')

        #self.model.addTufoProp('syn:prop','ptype',ptype='str')
        #self.model.addTufoProp('syn:prop','title',ptype='str')
        #self.model.addTufoProp('syn:prop','defval') # ptype='any'

        #self.model.addTufoForm('syn:splice',ptype='guid')
        #self.model.addTufoProp('syn:splice','date',ptype='time:epoch',doc='Time that the splice was requested')
        #self.model.addTufoProp('syn:splice','user',ptype='str',doc='Time user/system which requested the splice')
        #self.model.addTufoProp('syn:splice','note',ptype='str',doc='Filthy humon notes about the change')
        #self.model.addTufoProp('syn:splice','status',ptype='str',doc='Enum for init,done,deny to show the splice status')
        #self.model.addTufoProp('syn:splice','action',ptype='str:lwr',doc='The requested splice action')

        # FIXME load forms / props / etc

        self.model.addTufoForm('syn:splice', ptype='guid')

        self.model.addTufoGlob('syn:splice',
                               'on:*')  # syn:splice:on:fqdn=woot.com
        self.model.addTufoGlob('syn:splice', 'act:*')  # action arguments

        self.model.addTufoProp('syn:splice',
                               'perm',
                               ptype='str',
                               doc='Permissions str for glob matching')
        self.model.addTufoProp('syn:splice',
                               'reqtime',
                               ptype='time:epoch',
                               doc='When was the splice requested')

        self.model.addTufoProp('syn:splice',
                               'user',
                               ptype='str',
                               defval='??',
                               doc='What user is requesting the splice')
        self.model.addTufoProp('syn:splice',
                               'note',
                               ptype='str',
                               defval='',
                               doc='Notes about the splice')
        self.model.addTufoProp('syn:splice',
                               'status',
                               ptype='str',
                               defval='new',
                               doc='Splice status')
        self.model.addTufoProp('syn:splice',
                               'action',
                               ptype='str',
                               doc='What action is the splice requesting')
        #self.model.addTufoProp('syn:splice','actuser', ptype='str', doc='What user is activating the splice')
        #self.model.addTufoProp('syn:splice','acttime', ptype='time:epoch', doc='When was the splice activated')

        self.on('tufo:add:syn:tag', self._onAddSynTag)

        #self.on('tufo:add:syn:type', self._onAddSynType)
        #self.on('tufo:add:syn:form', self._onAddSynForm)
        #self.on('tufo:add:syn:prop', self._onAddSynProp)

        self.on('tufo:del:syn:tag', self._onDelSynTag)
        self.on('tufo:form:syn:tag', self._onFormSynTag)

        self.isok = True

        self.splicers = {}

        self.splicers['tufo:add'] = self._spliceTufoAdd
        self.splicers['tufo:del'] = self._spliceTufoDel
        self.splicers['tufo:set'] = self._spliceTufoSet
        self.splicers['tufo:tag:add'] = self._spliceTufoTagAdd
        self.splicers['tufo:tag:del'] = self._spliceTufoTagDel
コード例 #30
0
ファイル: test_datamodel.py プロジェクト: thpatel/synapse
 def test_datamodel_cast_int10(self):
     modl = s_datamodel.DataModel()
     self.eq(modl.getTypeCast('int:2:str10', 1), '1')
     self.eq(modl.getTypeCast('int:2:str10', 100), '100')
     self.eq(modl.getTypeCast('int:2:str10', 0x11), '17')
     self.eq(modl.getTypeCast('int:2:str10', 'hehe'), 'hehe')