示例#1
0
    def setConfOpt(self, name, valu):
        '''
        Set a single config option for the object.
        '''
        oldval = self._conf_opts.get(name)

        cdef = self.getConfDef(name)

        ctype = cdef[1].get('type')
        if ctype != None:
            valu, _ = getTypeFrob(ctype, valu)

        if valu == oldval:
            return False

        asloc = cdef[1].get('asloc')
        if asloc != None:
            setattr(self, asloc, valu)

        self._conf_opts[name] = valu
        self._conf_defs[name][1]['valu'] = valu

        self.fire('syn:conf:set', name=name, valu=valu, oldval=oldval)
        self.fire('syn:conf:set:%s' % name,
                  name=name,
                  valu=valu,
                  oldval=oldval)
示例#2
0
    def _initDbConn(self):
        import psycopg2

        retry = self._link[1].get('retry',0)

        dbinfo = self._initDbInfo()

        db = None
        tries = 0
        while db == None:
            try:
                db = psycopg2.connect(**dbinfo)
            except Exception as e:
                tries += 1
                if tries > retry:
                    raise

                time.sleep(1)

        seqscan = self._link[1].get('pg:seqscan',0)
        seqscan = s_datamodel.getTypeFrob('bool',seqscan)

        c = db.cursor()
        c.execute('SET enable_seqscan=%s', (seqscan,))
        c.close()

        return db
示例#3
0
    def test_datamodel_typefns(self):
        self.eq(s_datamodel.getTypeRepr('str', 'haha'), 'haha')
        self.eq(s_datamodel.getTypeRepr('inet:ipv4', 0x01020304), '1.2.3.4')

        self.eq(s_datamodel.getTypeNorm('str', 'haha'), ('haha', {}))
        self.eq(s_datamodel.getTypeNorm('inet:ipv4', 0x01020304),
                (16909060, {}))

        self.eq(s_datamodel.getTypeFrob('str', 'haha'), ('haha', {}))
        self.eq(s_datamodel.getTypeFrob('inet:ipv4', '1.2.3.4'),
                (16909060, {}))
        self.eq(s_datamodel.getTypeFrob('inet:ipv4', 0x01020304),
                (16909060, {}))
        self.eq(s_datamodel.getTypeFrob('inet:ipv4', 'haha'), (None, {}))

        self.eq(s_datamodel.getTypeParse('str', 'haha'), ('haha', {}))
        self.eq(s_datamodel.getTypeParse('inet:ipv4', '1.2.3.4'),
                (16909060, {}))
示例#4
0
    def setConfOpt(self, name, valu):
        '''
        Set a single config option for the object.
        '''
        oldval = self._conf_opts.get(name)

        cdef = self.getConfDef(name)

        ctype = cdef[1].get('type')
        if ctype != None:
            valu = getTypeFrob(ctype,valu)

        if valu == oldval:
            return False

        asloc = cdef[1].get('asloc')
        if asloc != None:
            setattr(self,asloc,valu)

        self._conf_opts[name] = valu
        self._conf_defs[name][1]['valu'] = valu

        self.fire('syn:conf:set', name=name, valu=valu, oldval=oldval)
        self.fire('syn:conf:set:%s' % name, name=name, valu=valu, oldval=oldval)
示例#5
0
 def getConfFrob(self, name, valu):
     cdef = self.getConfDef(name)
     ctype = cdef[1].get('type')
     if ctype == None:
         return valu
     return getTypeFrob(ctype, valu)
示例#6
0
 def getConfFrob(self, name, valu):
     cdef = self.getConfDef(name)
     ctype = cdef[1].get('type')
     if ctype == None:
         return valu
     return getTypeFrob(ctype,valu)