Ejemplo n.º 1
0
 def __init__(self, ruleset, props, data, flags, replace):
     Rule.__init__(
         self, ruleset, data.get('name', ''), data.get('comments', []), {
             'prefix': data.get('prefix', props['prefix']),
             'suffix': data.get('suffix', props['suffix']),
         })
     for prop, value in self.props.items():
         if '\b' in value:
             LOG.warn(r'\b found in {0}. \
                 To match word boundaries use \\b instead.'.format(prop))
     self.data = data
     self.flags = process_flags(data.get('flags', ''), flags)
     self.replace = data.get('replace', replace)
     self.re = data.get('re', [])
     if isinstance(self.re, str):
         patterns = [self.re]
     elif hasattr(self.re, '__getitem__'):
         patterns = self.re
     for patern in patterns:
         if '\b' in patern:
             LOG.warn(r'\b found in pattern {0}. \
                 To match word boundaries use \\b instead.'.format(
                 patern.replace('\b', r'\b')))
     self.patterns = []
     for patern in patterns:
         original_pattern = patern
         for search_string, replacement in self.replace.items():
             patern = re.sub(search_string, replacement, patern)
         compiled = re.compile(
             self.props['prefix'] + patern + self.props['suffix'],
             self.flags)
         self.patterns.append({
             'compiled': compiled,
             'original': original_pattern
         })
Ejemplo n.º 2
0
 def __init__(self, ruleset, props, data, flags, replace):
     Rule.__init__(self, ruleset,
         data.get('name', ''),
         data.get('comments', []),
         {
             'prefix': data.get('prefix', props['prefix']),
             'suffix': data.get('suffix', props['suffix']),
         }
     )
     for prop, value in self.props.iteritems():
         if '\b' in value:
             LOG.warn(r'\b found in {0}. \
                 To match word boundaries use \\b instead.'.format(prop))
     self.data = data
     self.flags = process_flags(data.get('flags', ''), flags)
     self.replace = data.get('replace', replace)
     self.re = data.get('re', [])
     if isinstance(self.re, basestring):
         patterns = [self.re]
     elif hasattr(self.re, '__getitem__'):
         patterns = self.re
     for patern in patterns:
         if '\b' in patern:
             LOG.warn(r'\b found in pattern {0}. \
                 To match word boundaries use \\b instead.'
                 .format(patern.replace('\b', r'\b')))
     self.patterns = []
     for patern in patterns:
         original_pattern = patern
         for search_string, replacement in self.replace.iteritems():
             patern = re.sub(search_string, replacement, patern)
         compiled = re.compile(
             self.props['prefix'] + patern + self.props['suffix'],
             self.flags
         )
         self.patterns.append({'compiled': compiled,
                               'original': original_pattern})
 def __init__(self, ruleset):
     Rule.__init__(self, ruleset, 'All sentences')
 def __init__(self, ruleset):
     Rule.__init__(self, ruleset, 'Short sentences')
 def __init__(self, ruleset):
     Rule.__init__(self, ruleset, 'Long sentences')