# 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
class PdfOperation(object):
    """PDF content stream operations dispatcher.  Content stream operations are
    registered by calling PdfOperation.register(), passing the opcode, the type
    of operation, and the function that does it."""
    # Operation type constants (see Reference p. 196)
    # These mostly exist to make things easier in PdfRenderer methods
    NOP                    =     0
    GENERAL_GRAPHICS_STATE =     1
    SPECIAL_GRAPHICS_STATE =     2
    PATH_CONSTRUCTION      =     4
    PATH_PAINTING          =     8
    CLIPPING_PATHS         =    16
    TEXT_OBJECTS           =    32
    TEXT_STATE             =    64
    TEXT_POSITIONING       =   128
    TEXT_SHOWING           =   256
    TYPE_3_FONTS           =   512
    COLOR                  =  1024
    SHADING_PATTERNS       =  2048
    INLINE_IMAGES          =  4096
    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."""

# 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

class PdfOperation(object):
    """PDF content stream operations dispatcher.  Content stream operations are
    registered by calling PdfOperation.register(), passing the opcode, the type
    of operation, and the function that does it."""
    # Operation type constants (see Reference p. 196)
    # These mostly exist to make things easier in PdfRenderer methods
    NOP                    =     0
    GENERAL_GRAPHICS_STATE =     1
    SPECIAL_GRAPHICS_STATE =     2
    PATH_CONSTRUCTION      =     4
    PATH_PAINTING          =     8
    CLIPPING_PATHS         =    16
    TEXT_OBJECTS           =    32
    TEXT_STATE             =    64
    TEXT_POSITIONING       =   128
    TEXT_SHOWING           =   256
    TYPE_3_FONTS           =   512
    COLOR                  =  1024
    SHADING_PATTERNS       =  2048
    INLINE_IMAGES          =  4096
    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)