openrvdas.logger.transforms.regex_filter_transform
No module-level documentation available.
1#!/usr/bin/env python3 2 3import re 4 5from logger.transforms.transform import Transform # noqa: E402 6 7 8################################################################################ 9class RegexFilterTransform(Transform): 10 """Only return records matching the specified regular expression.""" 11 ############################ 12 13 def __init__(self, pattern, flags=0, negate=False, **kwargs): 14 """If negate=True, only return records that *don't* match the pattern.""" 15 super().__init__(**kwargs) # processes 'quiet' and type hints 16 17 self.pattern = re.compile(pattern, flags) 18 self.negate = negate 19 20 ############################ 21 def transform(self, record: str) -> str: 22 """Does record contain pattern?""" 23 24 # See if it's something we can process, and if not, try digesting 25 if not self.can_process_record(record): # inherited from BaseModule() 26 return self.digest_record(record) # inherited from BaseModule() 27 28 match = self.pattern.search(record) 29 if match is None: 30 if self.negate: 31 return record 32 return None 33 else: 34 if self.negate: 35 return None 36 return record
class
RegexFilterTransform(logger.transforms.transform.Transform):
10class RegexFilterTransform(Transform): 11 """Only return records matching the specified regular expression.""" 12 ############################ 13 14 def __init__(self, pattern, flags=0, negate=False, **kwargs): 15 """If negate=True, only return records that *don't* match the pattern.""" 16 super().__init__(**kwargs) # processes 'quiet' and type hints 17 18 self.pattern = re.compile(pattern, flags) 19 self.negate = negate 20 21 ############################ 22 def transform(self, record: str) -> str: 23 """Does record contain pattern?""" 24 25 # See if it's something we can process, and if not, try digesting 26 if not self.can_process_record(record): # inherited from BaseModule() 27 return self.digest_record(record) # inherited from BaseModule() 28 29 match = self.pattern.search(record) 30 if match is None: 31 if self.negate: 32 return record 33 return None 34 else: 35 if self.negate: 36 return None 37 return record
Only return records matching the specified regular expression.
RegexFilterTransform(pattern, flags=0, negate=False, **kwargs)
14 def __init__(self, pattern, flags=0, negate=False, **kwargs): 15 """If negate=True, only return records that *don't* match the pattern.""" 16 super().__init__(**kwargs) # processes 'quiet' and type hints 17 18 self.pattern = re.compile(pattern, flags) 19 self.negate = negate
If negate=True, only return records that don't match the pattern.
def
transform(self, record: str) -> str:
22 def transform(self, record: str) -> str: 23 """Does record contain pattern?""" 24 25 # See if it's something we can process, and if not, try digesting 26 if not self.can_process_record(record): # inherited from BaseModule() 27 return self.digest_record(record) # inherited from BaseModule() 28 29 match = self.pattern.search(record) 30 if match is None: 31 if self.negate: 32 return record 33 return None 34 else: 35 if self.negate: 36 return None 37 return record
Does record contain pattern?