Module refinery.units.meta.iffp
Expand source code Browse git
from __future__ import annotations
from refinery.lib.patterns import formats, indicators, pattern
from refinery.lib.types import Param
from refinery.units.meta import Arg, ConditionalUnit
_PATTERNS = {
name: p.value for d in (formats, indicators) for name, p in d.__members__.items()
}
class iffp(ConditionalUnit, docs='{0}{p}{1}'):
"""
Filter incoming chunks depending on whether it matches any of a given set of patterns.
The available format patterns are:
{0}
The available indicator patterns are:
{1}
"""
def __init__(
self,
*patterns: Param[str, Arg.Choice(metavar='pattern', choices=list(_PATTERNS))],
partial: Param[bool, 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
if __doc := iffp.__doc__:
_f = formats
_i = indicators
iffp.__doc__ = __doc.format(
_f.make_table('PATTERN', 0),
_i.make_table('PATTERN', 0),
)
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 format patterns are:
PATTERN DESCRIPTION integer any integer literal expression float floating point literals number either an integer or a float string c-syntax string literal cmdstr Windows command line escaped string literal ps1str PowerShell escaped string literal vbastr VBS/VBA string literal vbaint VBS/VBA integer literal printable printable strings (includes whitespace) urlquote url-encoded characters, default char set urlhex hex-encoded buffer using URL escape sequences htmlesc sequence of HTML-escape characters intarray integers separated by commas or semicolons strarray strings separated by commas or semicolons numarray numbers separated by commas or semicolons hexarray hex sequences separated by commas or semicolons letters alphabetic characters wshenc encoded Windows Scripting Host Scripts (JS/VBS) alnum alphanumeric characters base32 Base32 encoded strings base58 Base58 encoded strings base62 Base62 encoded strings base64 Base64 encoded strings base85 Base85 encoded strings ascii85 Ascii85 encoded strings z85 Z85 encoded strings base92 Base92 encoded strings base64u Base64 encoded strings using URL-safe alphabet hex hexadecimal strings base16 uppercase hexadecimal strings base16s hexadecimal strings base64s Base64 encoded strings, separated by whitespace base85s Base85 encoded string, separated by whitespace a85s Ascii85 encoded string, separated by whitespace z85s Z85 encoded string, separated by whitespace utf8 sequences of bytes that can be decoded as UTF8 hexdump typical hexdump output uuenc UUEncoded dataThe available indicator patterns are:
PATTERN DESCRIPTION date date or timestamp value in a common format domain domain names email email addresses guid Windows GUID ipv4 IPv4 address string ipv6 IPv6 address string host domain or IPv4 optionally followed by colon and port socket domain or IPv4 followed by colon and port number url uniform resource locator addresses md5 hex strings of length 32 sha1 hex strings of length 40 sha256 hex strings of length 64 subdomain domain containing at least three parts including TLD pem PEM encoded cryptographic parameters path any file path nixpath file paths (Linux) winpath file paths (Windows) tpath file paths without whitespace nixtpath tpath for Linux wintpath tpath for Windows evar Windows environment variable, i.e. %AppData%Note: The reverse operation of a conditional unit uses the logical negation of its condition.
Expand source code Browse git
class iffp(ConditionalUnit, docs='{0}{p}{1}'): """ Filter incoming chunks depending on whether it matches any of a given set of patterns. The available format patterns are: {0} The available indicator patterns are: {1} """ def __init__( self, *patterns: Param[str, Arg.Choice(metavar='pattern', choices=list(_PATTERNS))], partial: Param[bool, 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 FalseAncestors
Subclasses
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