Ejemplo n.º 1
0
    def plan(self, opers):
        '''
        Review a list of opers and return a potentially optimized list.

        Args:
            opers ([(str,dict),]):  List of opers in tufo form

        Returns:
            ([(str,dict),]): Optimized list

        '''
        retn = []

        for oper in opers:

            # specify a limit backward from limit oper...
            if oper[0] == 'limit' and retn:
                args = oper[1].get('args', ())
                if args:
                    limt = s_common.intify(args[0])
                    if limt is not None:
                        setkw(retn[-1], 'limit', limt)

            # TODO look for a form lift + tag filter and optimize

            retn.append(oper)

        return retn
Ejemplo n.º 2
0
    def _stormOperLimit(self, query, oper):
        args = oper[1].get('args', ())
        if len(args) != 1:
            raise s_common.BadSyntaxError(mesg='limit(<size>)')

        size = s_common.intify(args[0])
        if size is None:
            raise s_common.BadSyntaxError(mesg='limit(<size>)')

        if query.size() > size:
            [query.add(node) for node in query.take()[:size]]
Ejemplo n.º 3
0
    def _normPyStr(self, valu):

        ival = s_common.intify(valu)
        if ival is not None:
            return int(bool(ival)), {}

        sval = valu.lower().strip()
        if sval in ('true', 't', 'y', 'yes', 'on'):
            return 1, {}

        if sval in ('false', 'f', 'n', 'no', 'off'):
            return 0, {}

        raise s_exc.BadTypeValu(name=self.name, valu=valu,
                                mesg='Failed to norm bool')
Ejemplo n.º 4
0
    def _stormQueryPlanLimit(self, retn, oper):
        '''
        Perform query optimization for limit() operator use.

        Args:
            retn (list):
            oper ((str, dict)):

        Returns:
            bool: True if we performed an optimization, False otherwise.
        '''
        # specify a limit backward from limit oper to the previous operator.
        # This will smash over any already-present limit keyword argument
        args = oper[1].get('args', ())
        if args:
            limt = s_common.intify(args[0])
            if limt is not None:
                setkw(retn[-1], 'limit', limt)
                # Add the limit oper and continue in the for loop
                retn.append(oper)
                return True
        return False
Ejemplo n.º 5
0
 def test_common_intify(self):
     self.eq(s_common.intify(20), 20)
     self.eq(s_common.intify("20"), 20)
     self.none(s_common.intify(None))
     self.none(s_common.intify("woot"))
Ejemplo n.º 6
0
 def test_common_intify(self):
     self.eq(s_common.intify(20), 20)
     self.eq(s_common.intify("20"), 20)
     self.none(s_common.intify(None))
     self.none(s_common.intify("woot"))