Module refinery.units.meta.iffx

Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from ..pattern import arg, RegexUnit
from . import ConditionalUnit


class iffx(RegexUnit, ConditionalUnit):
    """
    Filter incoming chunks by discarding those that do not match the given
    regular expression.
    """
    def __init__(
        self, regex, multiline=False, ignorecase=False, negate=False, temporary=False,
        match: arg.switch('-m',
            help='Perform a full match rather than matching anywhere in the chunk.') = False
    ):
        super().__init__(regex=regex, negate=negate, temporary=temporary, multiline=multiline, ignorecase=ignorecase, match=match)

    def match(self, chunk):
        return bool(self._matcher(chunk))

    def filter(self, chunks):
        self._matcher = self.regex.fullmatch if self.args.match else self.regex.search
        yield from super().filter(chunks)

Classes

class iffx (regex, multiline=False, ignorecase=False, negate=False, temporary=False, match=False)

Filter incoming chunks by discarding those that do not match the given regular expression.

Expand source code Browse git
class iffx(RegexUnit, ConditionalUnit):
    """
    Filter incoming chunks by discarding those that do not match the given
    regular expression.
    """
    def __init__(
        self, regex, multiline=False, ignorecase=False, negate=False, temporary=False,
        match: arg.switch('-m',
            help='Perform a full match rather than matching anywhere in the chunk.') = False
    ):
        super().__init__(regex=regex, negate=negate, temporary=temporary, multiline=multiline, ignorecase=ignorecase, match=match)

    def match(self, chunk):
        return bool(self._matcher(chunk))

    def filter(self, chunks):
        self._matcher = self.regex.fullmatch if self.args.match else self.regex.search
        yield from super().filter(chunks)

Ancestors

Methods

def match(self, chunk)
Expand source code Browse git
def match(self, chunk):
    return bool(self._matcher(chunk))

Inherited members