Beispiel #1
0
 def match_date(self):
     """
     returns: [['operation', <op>], (n, v), (n, v)]
     """
     self.match('(%s)$' % ('|'.join(self.validation.date_ops())))
     op = self.matched(1)
     if op in olist(vars.simple_date_ops):
         val = self.match_any()
         if keyword_cmp(op, 'lt'):
             return [['operation', op], ('end', val)]
         return [['operation', op], ('start', val)]
     elif op == 'in_range':
         nv = self.match_nvpairs(minpairs=2)
         if not keyword_cmp(nv[0][0], 'start'):
             self.err("Expected start=<start>")
         return [['operation', op]] + nv
     else:  # lt, gt, date_spec, ?
         return [['operation', op]] + self.match_nvpairs(minpairs=1)
Beispiel #2
0
 def match_date(self):
     """
     returns: [['operation', <op>], (n, v), (n, v)]
     """
     self.match('(%s)$' % ('|'.join(self.validation.date_ops())))
     op = self.matched(1)
     if op in olist(vars.simple_date_ops):
         val = self.match_any()
         if keyword_cmp(op, 'lt'):
             return [['operation', op], ('end', val)]
         return [['operation', op], ('start', val)]
     elif op == 'in_range':
         nv = self.match_nvpairs(minpairs=2)
         if not keyword_cmp(nv[0][0], 'start'):
             self.err("Expected start=<start>")
         return [['operation', op]] + nv
     else:  # lt, gt, date_spec, ?
         return [['operation', op]] + self.match_nvpairs(minpairs=1)
Beispiel #3
0
def date_exp2cli(node):
    kwmap = {'in_range': 'in', 'date_spec': 'spec'}
    l = []
    operation = node.get("operation")
    l.append(clidisplay.keyword("date"))
    l.append(clidisplay.keyword(kwmap.get(operation, operation)))
    if operation in utils.olist(constants.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append(clidisplay.attr_value(quote_wrap(value)))
    else:
        if operation == 'in_range':
            for name in constants.in_range_attrs:
                if name in node.attrib:
                    l.append(nvpair_format(name, node.attrib[name]))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                l.extend([nvpair_format(name, c.get(name))
                          for name in c.keys() if name != 'id'])
    return ' '.join(l)
Beispiel #4
0
def date_exp2cli(node):
    kwmap = {'in_range': 'in', 'date_spec': 'spec'}
    l = []
    operation = node.get("operation")
    l.append(clidisplay.keyword("date"))
    l.append(clidisplay.keyword(kwmap.get(operation, operation)))
    if operation in utils.olist(constants.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append(clidisplay.attr_value(quote_wrap(value)))
    else:
        if operation == 'in_range':
            for name in constants.in_range_attrs:
                if name in node.attrib:
                    l.append(nvpair_format(name, node.attrib[name]))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                l.extend([nvpair_format(name, c.get(name))
                          for name in c.keys() if name != 'id'])
    return ' '.join(l)
Beispiel #5
0
def date_exp2cli(node):
    l = []
    operation = node.get("operation")
    l.append(cli_display.keyword("date"))
    l.append(cli_display.keyword(operation))
    if operation in utils.olist(vars.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append('"%s"' % cli_display.attr_value(value))
    else:
        if operation == 'in_range':
            for name in vars.in_range_attrs:
                v = node.get(name)
                if v:
                    l.append(nvpair_format(name, v))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                pl = []
                for name in c.keys():
                    if name != "id":
                        pl.append([name, c.get(name)])
                l.append(cli_pairs(pl))
    return ' '.join(l)
Beispiel #6
0
 def match_rules(self, out):
     '''parse rule definitions'''
     while self.try_match('rule'):
         head = []
         rule = ['rule', head]
         idref = False
         if self.try_match_idspec():
             head.append([self.matched(1), self.matched(2)])
             if self.matched(1) == '$id-ref':
                 idref = True
         if self.try_match(self._ROLE_RE):
             head.append(['$role', self.matched(1)])
         if idref:
             out.rules.append(rule)
             continue
         self.match(self._SCORE_RE)
         score = self.validate_score(self.matched(1))
         head.append(score)
         boolop, expr = self.match_rule_expression()
         if boolop and not keyword_cmp(boolop, 'and'):
             head.append(['boolean-op', boolop])
         out.rules.append(rule)
         out.rules.extend(expr)
Beispiel #7
0
 def match_rules(self, out):
     '''parse rule definitions'''
     while self.try_match('rule'):
         head = []
         rule = ['rule', head]
         idref = False
         if self.try_match_idspec():
             head.append([self.matched(1), self.matched(2)])
             if self.matched(1) == '$id-ref':
                 idref = True
         if self.try_match(self._ROLE_RE):
             head.append(['$role', self.matched(1)])
         if idref:
             out.rules.append(rule)
             continue
         self.match(self._SCORE_RE)
         score = self.validate_score(self.matched(1))
         head.append(score)
         boolop, expr = self.match_rule_expression()
         if boolop and not keyword_cmp(boolop, 'and'):
             head.append(['boolean-op', boolop])
         out.rules.append(rule)
         out.rules.extend(expr)
Beispiel #8
0
def date_exp2cli(node):
    l = []
    operation = node.get("operation")
    l.append(cli_display.keyword("date"))
    l.append(cli_display.keyword(operation))
    if operation in utils.olist(vars.simple_date_ops):
        value = node.get(
            utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append('"%s"' % cli_display.attr_value(value))
    else:
        if operation == 'in_range':
            for name in vars.in_range_attrs:
                v = node.get(name)
                if v:
                    l.append(nvpair_format(name, v))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                pl = []
                for name in c.keys():
                    if name != "id":
                        pl.append([name, c.get(name)])
                l.append(cli_pairs(pl))
    return ' '.join(l)