# Path: gymnast/pdf_types/string_types.py
# class PdfName(PdfType, str):
#     """PDF name objects, mostly use for dict keys"""
#     def __new__(cls, *args, **kwargs):
#         return str.__new__(cls, *args, **kwargs)
#     def __init__(self, *args, **kwargs):
#         PdfType.__init__(self)
#         str.__init__(self)
#     @classmethod
#     def from_token(cls, token):
#         """Parse names by stripping the leading / and replacing instances of
#         #YY with the character b'\\xYY' and decoding to unicode."""
#         try:
#             name = bytearray(token[token[0] == '/':].encode())
#         except AttributeError:
#             # Hopefully this means that it's bytes
#             name = bytearray(token[token[:1] == b'/':])
#         hash_pos = name.find(b'#')
#         while hash_pos > 0:
#             try:
#                 new_char = bytes((int(name[hash_pos+1:hash_pos+3], 16),))
#             except ValueError:
#                 msg = 'Invalid hex code in name {} ({})'
#                 raise PdfError(msg.format(token, name[hash_pos:hash_pos+3]))
#             name[hash_pos:hash_pos+3] = new_char
#             hash_pos = name.find(b'#', hash_pos)
#         return cls(bytes(name).decode())
# 
# Path: gymnast/pdf_types/common.py
# class PdfType(object):
#     """Abstract base class for PDF objects"""
#     def pdf_encode(self):
#         """Translate the object into bytes in PDF format"""
#         raise NotImplementedError
#     @property
#     def value(self):
#         """Objects, references, and such will override this in clever
#         ways."""
#         return self
#     @property
#     def parsed_object(self):
#         """Objects, references, and such will override this in clever
#         ways."""
#         return self


import six
from pprint     import pformat
    from collections.abc import MutableMapping
    from collections     import MutableMapping
    from functools       import reduce
from ..pdf_types import PdfType, PdfName
    def parsed_object(self):
        """Return the PdfElement"""
        return self
    def __init__(self, obj, obj_key=None, document=None):
        """Create a new PdfElement"""
        super(PdfElement, self).__init__()
        self._object   = obj.value
        self._obj_key  = obj_key
        self._document = document

    @property
    def document(self):
        """The docuement to which this element belongs"""
        return self._document

    @document.setter
    def document(self, document):
        """Set the element's document"""
        self._document = document

    #Mapping stuff
    def __getitem__(self, key):
        val = self._object[key]
        if isinstance(val, PdfType):
            return val#.parsed_object
        else:
            return val
    def __setitem__(self, name, value):
        if name == 'Type':
            raise KeyError('A document object\'s type cannot be changed')

# Path: gymnast/pdf_types/string_types.py
# class PdfName(PdfType, str):
#     """PDF name objects, mostly use for dict keys"""
#     def __new__(cls, *args, **kwargs):
#         return str.__new__(cls, *args, **kwargs)
#     def __init__(self, *args, **kwargs):
#         PdfType.__init__(self)
#         str.__init__(self)
#     @classmethod
#     def from_token(cls, token):
#         """Parse names by stripping the leading / and replacing instances of
#         #YY with the character b'\\xYY' and decoding to unicode."""
#         try:
#             name = bytearray(token[token[0] == '/':].encode())
#         except AttributeError:
#             # Hopefully this means that it's bytes
#             name = bytearray(token[token[:1] == b'/':])
#         hash_pos = name.find(b'#')
#         while hash_pos > 0:
#             try:
#                 new_char = bytes((int(name[hash_pos+1:hash_pos+3], 16),))
#             except ValueError:
#                 msg = 'Invalid hex code in name {} ({})'
#                 raise PdfError(msg.format(token, name[hash_pos:hash_pos+3]))
#             name[hash_pos:hash_pos+3] = new_char
#             hash_pos = name.find(b'#', hash_pos)
#         return cls(bytes(name).decode())
# 
# Path: gymnast/pdf_types/common.py
# class PdfType(object):
#     """Abstract base class for PDF objects"""
#     def pdf_encode(self):
#         """Translate the object into bytes in PDF format"""
#         raise NotImplementedError
#     @property
#     def value(self):
#         """Objects, references, and such will override this in clever
#         ways."""
#         return self
#     @property
#     def parsed_object(self):
#         """Objects, references, and such will override this in clever
#         ways."""
#         return self


# Path: gymnast/pdf_elements/pdf_element.py
import six
from pprint     import pformat
    from collections.abc import MutableMapping
    from collections     import MutableMapping
    from functools       import reduce
from ..pdf_types import PdfType, PdfName

    def parsed_object(self):
        """Return the PdfElement"""
        return self
    def __init__(self, obj, obj_key=None, document=None):
        """Create a new PdfElement"""
        super(PdfElement, self).__init__()
        self._object   = obj.value
        self._obj_key  = obj_key
        self._document = document

    @property
    def document(self):
        """The docuement to which this element belongs"""
        return self._document

    @document.setter
    def document(self, document):
        """Set the element's document"""
        self._document = document

    #Mapping stuff
    def __getitem__(self, key):
        val = self._object[key]
        if isinstance(val, PdfType):
            return val#.parsed_object
        else:
            return val
    def __setitem__(self, name, value):
        if name == 'Type':
            raise KeyError('A document object\'s type cannot be changed')

        self._object[PdfName(name)] = value