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.
"""
from __future__ import annotations

from typing import Iterable, TYPE_CHECKING
from abc import abstractmethod
if TYPE_CHECKING:
    from ...lib.frame import Chunk

from .. import arg, Unit
from ...lib.argformats import sliceobj


class FrameSlicer(Unit, abstract=True):

    def __init__(self, *slice: arg(
        type=sliceobj, nargs='*', default=[slice(None, None)],
        help='Specify start:stop:step in Python slice syntax.'
    ), **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):

    def __init__(
        self,
        negate: arg.switch('-n', help='invert the logic of this filter; drop all matching chunks instead of keeping them') = False,
        temporary: arg.switch('-t', help='do not remove chunks from the frame entirely; move them out of scope instead') = False,
        **kwargs
    ):
        super().__init__(negate=negate, temporary=temporary, **kwargs)

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

    def filter(self, chunks: Iterable[Chunk]):
        temporary = self.args.temporary
        for chunk in chunks:
            if not chunk.visible:
                continue
            if self.match(chunk) is self.args.negate:
                if not temporary:
                    continue
                chunk.visible = False
            yield chunk

Sub-modules

refinery.units.meta.chop
refinery.units.meta.cm
refinery.units.meta.cull
refinery.units.meta.dedup
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.iff
refinery.units.meta.iffp
refinery.units.meta.iffs
refinery.units.meta.iffx
refinery.units.meta.pad
refinery.units.meta.pick
refinery.units.meta.pop
refinery.units.meta.push
refinery.units.meta.put
refinery.units.meta.reduce
refinery.units.meta.scope
refinery.units.meta.sep
refinery.units.meta.sorted
refinery.units.meta.swap
refinery.units.meta.xfcc

Classes

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

    def __init__(self, *slice: arg(
        type=sliceobj, nargs='*', default=[slice(None, None)],
        help='Specify start:stop:step in Python slice syntax.'
    ), **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 (negate=False, temporary=False, **kwargs)
Expand source code Browse git
class ConditionalUnit(Unit, abstract=True):

    def __init__(
        self,
        negate: arg.switch('-n', help='invert the logic of this filter; drop all matching chunks instead of keeping them') = False,
        temporary: arg.switch('-t', help='do not remove chunks from the frame entirely; move them out of scope instead') = False,
        **kwargs
    ):
        super().__init__(negate=negate, temporary=temporary, **kwargs)

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

    def filter(self, chunks: Iterable[Chunk]):
        temporary = self.args.temporary
        for chunk in chunks:
            if not chunk.visible:
                continue
            if self.match(chunk) is self.args.negate:
                if not temporary:
                    continue
                chunk.visible = False
            yield chunk

Ancestors

Subclasses

Methods

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

Inherited members