# 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/exc.py
# class PdfParseError(PdfError):
#     """Exception parsing PDF file"""
#     pass
# 
# class PdfError(Exception):
#     """Generic PDF exception"""
#     pass
# 
# Path: gymnast/pdf_codec.py
# def register_codec():
#     """Register the 'pdf_doc' codec in the codec registry."""
#     codecs.register(lambda s: getregentry() if s == ENCODING_NAME else None)


import binascii
import codecs
import io
from .common     import PdfType
from ..exc       import PdfParseError, PdfError
from ..pdf_codec import register_codec
            obj = obj.decode(errors='surrogateescape')
        return str.__new__(cls, obj)
    def __init__(self, *args, **kwargs):
        PdfType.__init__(self)
        str.__init__(self)
    def pdf_encode(self):
        return b'%' + bytes(self.parsed_object)

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 {} ({})'

# 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/exc.py
# class PdfParseError(PdfError):
#     """Exception parsing PDF file"""
#     pass
# 
# class PdfError(Exception):
#     """Generic PDF exception"""
#     pass
# 
# Path: gymnast/pdf_codec.py
# def register_codec():
#     """Register the 'pdf_doc' codec in the codec registry."""
#     codecs.register(lambda s: getregentry() if s == ENCODING_NAME else None)


# Path: gymnast/pdf_types/string_types.py
import binascii
import codecs
import io
from .common     import PdfType
from ..exc       import PdfParseError, PdfError
from ..pdf_codec import register_codec

            obj = obj.decode(errors='surrogateescape')
        return str.__new__(cls, obj)
    def __init__(self, *args, **kwargs):
        PdfType.__init__(self)
        str.__init__(self)
    def pdf_encode(self):
        return b'%' + bytes(self.parsed_object)

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]))