Package pology :: Module rules :: Class Rule

Class Rule

object --+
         |
        Rule

Represent a single rule

Instance Methods
 
__init__(self, pattern, msgpart, hint=None, valid=[], stat=False, casesens=True, ident=None, disabled=False, manual=False, environ=None, mfilter=None, rfilter=None, trigger=None)
Create a rule
 
setPattern(self, pattern)
Compile pattern
 
setTrigger(self, trigger)
Use trigger function instead of pattern.
 
setValid(self, valid)
Parse valid key=value arguments of valid list
 
process(self, msg, cat, envs=set([]), nofilter=False)
Apply rule to the message.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, pattern, msgpart, hint=None, valid=[], stat=False, casesens=True, ident=None, disabled=False, manual=False, environ=None, mfilter=None, rfilter=None, trigger=None)
(Constructor)

 

Create a rule

Parameters:
  • pattern (unicode) - valid regexp pattern that trigger the rule
  • msgpart (string) - part of the message to be matched by pattern
  • hint (unicode) - hint given to user when rule match
  • valid (list of unicode key=value) - list of cases that should make or not make rule matching
  • casesens (bool) - whether regex matching will be case-sensitive
  • ident (unicode or None) - rule identifier
  • disabled (bool) - whether rule is disabled
  • manual (bool) - whether rule is manually applied
  • environ (string or None) - environment in which the rule applies
  • mfilter ((msg, cat, envs) -> <anything>) - filter to apply to message before checking
  • rfilter ((string) -> string) - filter to apply to rule strings (e.g. on regex patterns)
  • trigger ((msg, cat, envs) -> highlight) - function to act as trigger instead of pattern applied to msgpart
Overrides: object.__init__

setPattern(self, pattern)

 

Compile pattern

Parameters:
  • pattern - pattern as an unicode string

setTrigger(self, trigger)

 

Use trigger function instead of pattern.

Parameters:
  • trigger ((msg, cat, envs) -> {highlight<msgreport.report_msg_content>}) - function to act as trigger

setValid(self, valid)

 

Parse valid key=value arguments of valid list

Parameters:
  • valid - valid line as an unicode string

process(self, msg, cat, envs=set([]), nofilter=False)

 

Apply rule to the message.

If the rule matches, highlight specification of offending spans is returned (see report_msg_content); otherwise an empty list.

Rule will normally apply its own filters to the message before matching (on a local copy, the original message will not be affected). If the message is already appropriately filtered, this self-filtering can be prevented by setting nofilter to {True}.

Parameters:
  • msg (instance of Message_base) - message to which the texts belong
  • cat (Catalog) - catalog to which the message belongs
  • envs (set) - environments in which the rule is applied
  • nofilter (bool) - avoid filtering the message if True
Returns:
highlight specification (may be empty list)