示例#1
0
 def __init__(self, handler):
     Parser.__init__(self, handler)
     self.addRule(ListRule())
     self.addRule(ListItemRule())
     self.addRule(TitleRule())
     self.addRule(HeadingRule())
     self.addRule(ParagraphRule())
     self.addFilter(r'\*(.+?)\*', 'emphasis')
     self.addFilter(r'(http://[\.a-zA-Z/]+)', 'url')
     self.addFilter(r'([\.a-zA-Z]+@[\.a-zA-Z]+[a-zA-Z]+)', 'mail')
示例#2
0
    def __init__(self):
        self.rules = ListRule()
        self.mods = {}
        self.facts = []

        self.resolved_absences = []
        self.violations = []

        # to be constructed on def init()
        self.reporter = None
示例#3
0
    def __init__(self, handler):
        Parser.__init__(self, handler)
        self.add_rule(ListRule())
        self.add_rule(ListItemRule())
        self.add_rule(TitleRule())
        self.add_rule(HeadingRule())
        self.add_rule(ParagraphRule())

        self.add_filter(r"\*(.+?)\*", "emphasis")
        self.add_filter(r"(http://[\.a-zA-Z/]+)", "url")
        self.add_filter(r"([\.a-zA-Z]+@[\.a-zA-Z]+[a-zA-Z])", "mail")
示例#4
0
    def __init__(self):
        self.rules = ListRule()
        self.mods = {}
        self.facts = []

        self.resolved_absences = []
示例#5
0
class _DCL(object):
    rules = ListRule()
    mods = {}
    facts = []

    # the abscence that the system founded
    resolved_absences = []

    def __init__(self):
        self.rules = ListRule()
        self.mods = {}
        self.facts = []

        self.resolved_absences = []

    def mod(self, name_mod, *path_mods):
        self.mods[name_mod] = ModuleDef(name_mod, path_mods)

    def get_mod(self, name_mod):
        module = self.mods.get(name_mod, None)
        if not module:
            raise ModuleDefNotFound(name_mod)

        return module

    def the(self, mod_name, type_interaction, mod_target):
        self.rules.append(
            TheRule(
                self.get_mod(mod_name), 
                type_interaction, 
                self.get_mod(mod_target)
            )
        )

    def only(self, mod_name, type_interaction, mod_target):
        self.rules.append(
            OnlyRule(
                self.get_mod(mod_name), 
                type_interaction, 
                self.get_mod(mod_target)
            )
        )

    def init(self):
        from trace import set_listening
        set_listening()

    def conclude(self):
        #if not self.resolved_absences: return

        print "\n\n"
        print 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
        print "%d abscences found " % len(self.resolved_absences)
        print 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
        print 

        for exp in self.resolved_absences:
            print exp.message


    def notify_fact(self, fact):
        rules = self.rules.filter_by_type(fact['type'])

        for rule in rules:
            try:
                rule.verify(fact)
            except DivergenceException as e:
                # TODO: do it in a best way
                # print e.message
                pass
            except ResolvedAbsenceException as e:
                # stores to report on the end of the executing
                self.resolved_absences.append(e)
示例#6
0
class _DCL(object):
    rules = ListRule()
    mods = {}
    facts = []

    # the abscence that the system founded
    resolved_absences = []

    def __init__(self):
        self.rules = ListRule()
        self.mods = {}
        self.facts = []

        self.resolved_absences = []
        self.violations = []

        # to be constructed on def init()
        self.reporter = None

    def mod(self, name_mod, *path_mods):
        self.mods[name_mod] = ModuleDef(name_mod, path_mods)

    def get_mod(self, name_mod):
        module = self.mods.get(name_mod, None)
        if not module:
            raise ModuleDefNotFound(name_mod)

        return module

    def the(self, mod_name, type_interaction, mod_target):
        self.rules.append(TheRule(self.get_mod(mod_name), type_interaction, self.get_mod(mod_target)))

    def only(self, mod_name, type_interaction, mod_target):
        self.rules.append(OnlyRule(self.get_mod(mod_name), type_interaction, self.get_mod(mod_target)))

    def init(self, report_file=None):
        from trace import set_listening

        set_listening()

        self.reporter = Reporter(report_file)

    def conclude(self):
        """
        Now we show the must rules not satisfied
        """
        from copy import deepcopy

        must_rules = self.rules.filter_must()
        abscences = []

        for must in must_rules:
            if must.constraint not in self.resolved_absences:
                abscences.append(must)

        if not abscences:
            return

        self.reporter.report(self.violations, abscences)

    def notify_fact(self, fact):
        rules = self.rules.filter_by_type(fact["type"])

        for rule in rules:
            try:
                rule.verify(fact)
            except DivergenceException as e:
                self.violations.append(e)
            except ResolvedAbsenceException as e:
                # stores to report on the end of the executing
                self.resolved_absences.append(e.rule)