Module refinery.units.meta.iffp
Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from refinery.lib.patterns import formats, indicators, pattern
from refinery.units.meta import Arg, ConditionalUnit
_PATTERNS = {}
_PATTERNS.update({p.name: p.value for p in formats})
_PATTERNS.update({p.name: p.value for p in indicators})
class iffp(ConditionalUnit, extend_docs=True):
"""
Filter incoming chunks depending on whether it matches any of a given set of patterns. The
available patterns are the following: {}.
"""
def __init__(
self,
*patterns: Arg.Choice(metavar='pattern', choices=_PATTERNS),
partial: Arg.Switch('-p', help='Allow partial matches on the data.') = False,
retain=False
):
super().__init__(
retain=retain,
patterns=patterns,
partial=partial
)
def match(self, chunk):
for name in self.args.patterns:
p: pattern = _PATTERNS[name]
matcher = p.match if self.args.partial else p.fullmatch
if matcher(chunk):
return True
return False
iffp.__doc__ = iffp.__doc__.format(", ".join(_PATTERNS))
Classes
class iffp (*patterns, partial=False, retain=False)
-
Filter incoming chunks depending on whether it matches any of a given set of patterns. The available patterns are the following: integer, float, number, string, multiline_string, cmdstr, ps1str, vbastr, vbaint, printable, urlquote, urlquote_coarse, urlquote_narrow, intarray, numarray, word, letters, wshenc, alphanumeric, b32, b64, b85, b92, b64any, b64url, hex, uppercase_hex, spaced_hex, spaced_b64, spaced_b85, utf8, hexdump, hexarray, uuencode, domain, email, guid, ipv4, ipv6, md5, sha1, sha256, hostname, socket, subdomain, url, btc, pem, xmr, path, winpath, nixpath, environment_variable.
Note: The reverse operation of a conditional unit uses the logical negation of its condition.
Expand source code Browse git
class iffp(ConditionalUnit, extend_docs=True): """ Filter incoming chunks depending on whether it matches any of a given set of patterns. The available patterns are the following: {}. """ def __init__( self, *patterns: Arg.Choice(metavar='pattern', choices=_PATTERNS), partial: Arg.Switch('-p', help='Allow partial matches on the data.') = False, retain=False ): super().__init__( retain=retain, patterns=patterns, partial=partial ) def match(self, chunk): for name in self.args.patterns: p: pattern = _PATTERNS[name] matcher = p.match if self.args.partial else p.fullmatch if matcher(chunk): return True return False
Ancestors
Class variables
var required_dependencies
var optional_dependencies
Methods
def match(self, chunk)
-
Expand source code Browse git
def match(self, chunk): for name in self.args.patterns: p: pattern = _PATTERNS[name] matcher = p.match if self.args.partial else p.fullmatch if matcher(chunk): return True return False
Inherited members