# 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


import re
from decimal   import Decimal
from .common       import PdfType
from ..exc         import PdfParseError
        in the document, great, otherwise parse it."""
        if self._in_use:
            objs = self._document.indirect_objects
            try:
                return objs[self.key]
            except KeyError:
                self._document.parse_object(self._offset)
                return objs[self.key]
        else:
            return None # TODO: implement free Xrefs
    def pdf_encode(self):
        fstr = '{0d10} {1d05} {2}\r\n'
        return fstr.format(self._offset, self._generation,
                           'n' if self._in_use else 'f').encode()

    def __str__(self):
        return '{:010d} {:010d} '.format(self._offset, self._generation)\
              +('n' if self._in_use else 'f')

    @classmethod
    def from_line(cls, document, obj_id, line):
        """Takes a line in an xref subsection and returns a PdfXref object.

        Arguments:
            document - The PdfDocument in which the line resides
            obj_id   - The xref line's object id based on the subsection header
            line     - The actual 18 to 20 byte line (possibly with whitespace)"""
        # TODO: consider using ReCacher here
        match = re.match(cls.LINE_PAT, line)
        if not match:

# 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


# Path: gymnast/pdf_types/structural_types.py
import re
from decimal   import Decimal
from .common       import PdfType
from ..exc         import PdfParseError

        in the document, great, otherwise parse it."""
        if self._in_use:
            objs = self._document.indirect_objects
            try:
                return objs[self.key]
            except KeyError:
                self._document.parse_object(self._offset)
                return objs[self.key]
        else:
            return None # TODO: implement free Xrefs
    def pdf_encode(self):
        fstr = '{0d10} {1d05} {2}\r\n'
        return fstr.format(self._offset, self._generation,
                           'n' if self._in_use else 'f').encode()

    def __str__(self):
        return '{:010d} {:010d} '.format(self._offset, self._generation)\
              +('n' if self._in_use else 'f')

    @classmethod
    def from_line(cls, document, obj_id, line):
        """Takes a line in an xref subsection and returns a PdfXref object.

        Arguments:
            document - The PdfDocument in which the line resides
            obj_id   - The xref line's object id based on the subsection header
            line     - The actual 18 to 20 byte line (possibly with whitespace)"""
        # TODO: consider using ReCacher here
        match = re.match(cls.LINE_PAT, line)
        if not match:

            raise PdfParseError('Invalid xref line')