# Path: gymnast/exc.py
# class PdfOpWarning(PdfWarning):
#     """Invalid or non-implemented PDF content operation"""
#     pass
# 
# Path: gymnast/misc.py
# def ensure_str(val):
#     """Converts the argument to a string if it isn't one already"""
#     if isinstance(val, str):
#         return val
#     elif isinstance(val, (bytes, bytearray)):
#         return val.decode()
#     else:
#         raise ValueError('Expected bytes or string')
# 
# class MetaGettable(type):
#     """Metaclass to allow classes to be treated as dictlikes with MyClass[key].
#     Instance classes should implement a classmethod __getitem__(cls, key)."""
#     def __getitem__(cls, key):
#         return cls.__getitem__(key)


import inspect
import six
import warnings
from ..exc  import PdfOpWarning
from ..misc import ensure_str, MetaGettable
    XOBJECTS               =  8192
    MARKED_CONTENT         = 16384
    COMPATIBILITY          = 32768

    _opcodes = {}
    _nops    = {} # As we spawn new NOP classes, we'll cache them here
    @classmethod
    def register(cls, opcode, optype, opfunc):
        """Register a new PDF operation.  Arguments are the opcode, the type of
        operation, and the function that actually does the operation."""
        opcode = ensure_str(opcode)
        if not callable(opfunc):
            raise TypeError('opfunc must be callable')
        args = inspect.getfullargspec(opfunc)
        if not (args.varargs or args.args):
            raise ValueError('opfunc must take at least one positional argument')
        opcode = ensure_str(opcode)
        cls._opcodes[opcode] = new_opcode(opcode, optype, opfunc)

    @classmethod
    def __getitem__(cls, operator):
        operator = ensure_str(operator)
        try:
            return cls._opcodes[operator]
        except KeyError:
            return cls._nop(operator)
    @classmethod
    def _nop(cls, operator):
        """Get the corresponding NOP operation, creating it if necessary."""
        warnings.warn("Opcode '{}' not implemented. NOP".format(operator),

# Path: gymnast/exc.py
# class PdfOpWarning(PdfWarning):
#     """Invalid or non-implemented PDF content operation"""
#     pass
# 
# Path: gymnast/misc.py
# def ensure_str(val):
#     """Converts the argument to a string if it isn't one already"""
#     if isinstance(val, str):
#         return val
#     elif isinstance(val, (bytes, bytearray)):
#         return val.decode()
#     else:
#         raise ValueError('Expected bytes or string')
# 
# class MetaGettable(type):
#     """Metaclass to allow classes to be treated as dictlikes with MyClass[key].
#     Instance classes should implement a classmethod __getitem__(cls, key)."""
#     def __getitem__(cls, key):
#         return cls.__getitem__(key)


# Path: gymnast/pdf_operation/pdf_operation.py
import inspect
import six
import warnings
from ..exc  import PdfOpWarning
from ..misc import ensure_str, MetaGettable

    XOBJECTS               =  8192
    MARKED_CONTENT         = 16384
    COMPATIBILITY          = 32768

    _opcodes = {}
    _nops    = {} # As we spawn new NOP classes, we'll cache them here
    @classmethod
    def register(cls, opcode, optype, opfunc):
        """Register a new PDF operation.  Arguments are the opcode, the type of
        operation, and the function that actually does the operation."""
        opcode = ensure_str(opcode)
        if not callable(opfunc):
            raise TypeError('opfunc must be callable')
        args = inspect.getfullargspec(opfunc)
        if not (args.varargs or args.args):
            raise ValueError('opfunc must take at least one positional argument')
        opcode = ensure_str(opcode)
        cls._opcodes[opcode] = new_opcode(opcode, optype, opfunc)

    @classmethod
    def __getitem__(cls, operator):
        operator = ensure_str(operator)
        try:
            return cls._opcodes[operator]
        except KeyError:
            return cls._nop(operator)
    @classmethod
    def _nop(cls, operator):
        """Get the corresponding NOP operation, creating it if necessary."""
        warnings.warn("Opcode '{}' not implemented. NOP".format(operator),

                      PdfOpWarning)