Module refinery.units.meta

A package for units that operate primarily on frames of several of inputs.

Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A package for units that operate primarily on frames of several of inputs.
"""
import abc

from refinery.units import Arg, Unit, Chunk


class FrameSlicer(Unit, abstract=True):

    def __init__(self, *slice: Arg.Bounds(nargs='*', default=[slice(None, None)]), **keywords):
        super().__init__(slice=list(slice), **keywords)
        for s in self.args.slice:
            if s.step and s.step < 0:
                raise ValueError('negative slice steps are not supported here')


class ConditionalUnit(Unit, abstract=True):
    """
    Note: The reverse operation of a conditional unit uses the logical negation of its condition.
    """

    def __init__(
        self,
        retain: Arg.Switch('-r',
            help='Move non-matching chunks out of scope rather than discarding them.') = False,
        **kwargs
    ):
        super().__init__(retain=retain, **kwargs)

    @abc.abstractmethod
    def match(self, chunk) -> bool:
        ...

    def process(self, chunk: Chunk):
        if not self.match(chunk):
            if not self.args.retain:
                return
            chunk.visible = False
        yield chunk

    def reverse(self, chunk: Chunk):
        if self.match(chunk):
            if not self.args.retain:
                return
            chunk.visible = False
        yield chunk

Sub-modules

refinery.units.meta.chop
refinery.units.meta.cm
refinery.units.meta.dedup
refinery.units.meta.eat
refinery.units.meta.ef
refinery.units.meta.emit

A simple tool to output binary data. Multiple arguments are output in framed format, see refinery.lib.frame.

refinery.units.meta.group
refinery.units.meta.groupby
refinery.units.meta.iff
refinery.units.meta.iffp
refinery.units.meta.iffs
refinery.units.meta.iffx
refinery.units.meta.loop
refinery.units.meta.max
refinery.units.meta.min
refinery.units.meta.mvg
refinery.units.meta.pad
refinery.units.meta.pick
refinery.units.meta.pop
refinery.units.meta.push
refinery.units.meta.put
refinery.units.meta.queue

A simple tool to queue binary data as one or more chunks in the current frame.

refinery.units.meta.reduce
refinery.units.meta.rmv
refinery.units.meta.scope
refinery.units.meta.sep
refinery.units.meta.sorted
refinery.units.meta.swap
refinery.units.meta.transpose
refinery.units.meta.urn
refinery.units.meta.xfcc

Classes

class FrameSlicer (*slice, **keywords)
Expand source code Browse git
class FrameSlicer(Unit, abstract=True):

    def __init__(self, *slice: Arg.Bounds(nargs='*', default=[slice(None, None)]), **keywords):
        super().__init__(slice=list(slice), **keywords)
        for s in self.args.slice:
            if s.step and s.step < 0:
                raise ValueError('negative slice steps are not supported here')

Ancestors

Subclasses

Class variables

var required_dependencies
var optional_dependencies

Inherited members

class ConditionalUnit (retain=False, **kwargs)

Note: The reverse operation of a conditional unit uses the logical negation of its condition.

Expand source code Browse git
class ConditionalUnit(Unit, abstract=True):
    """
    Note: The reverse operation of a conditional unit uses the logical negation of its condition.
    """

    def __init__(
        self,
        retain: Arg.Switch('-r',
            help='Move non-matching chunks out of scope rather than discarding them.') = False,
        **kwargs
    ):
        super().__init__(retain=retain, **kwargs)

    @abc.abstractmethod
    def match(self, chunk) -> bool:
        ...

    def process(self, chunk: Chunk):
        if not self.match(chunk):
            if not self.args.retain:
                return
            chunk.visible = False
        yield chunk

    def reverse(self, chunk: Chunk):
        if self.match(chunk):
            if not self.args.retain:
                return
            chunk.visible = False
        yield chunk

Ancestors

Subclasses

Class variables

var required_dependencies
var optional_dependencies

Methods

def match(self, chunk)
Expand source code Browse git
@abc.abstractmethod
def match(self, chunk) -> bool:
    ...

Inherited members