Module refinery.units.meta

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

Expand source code Browse git
"""
A package for units that operate primarily on frames of several of inputs.
"""
from __future__ import annotations

import abc

from refinery.lib.types import Param
from refinery.units import Arg, Chunk, Unit


class FrameSlicer(Unit, abstract=True):

    def __init__(self, *slice: Param[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: Param[bool, 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
refinery.units.meta.group
refinery.units.meta.groupby
refinery.units.meta.iff
refinery.units.meta.iffc
refinery.units.meta.iffid
refinery.units.meta.iffp
refinery.units.meta.iffs
refinery.units.meta.iffx
refinery.units.meta.jamv
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: Param[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

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: Param[bool, 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

Methods

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

Inherited members