# Path: tools/dumppdf.py
# def dumppdf(
#     outfp: TextIO,
#     fname: str,
#     objids: Iterable[int],
#     pagenos: Container[int],
#     password: str = "",
#     dumpall: bool = False,
#     codec: Optional[str] = None,
#     extractdir: Optional[str] = None,
#     show_fallback_xref: bool = False,
# ) -> None:
#     fp = open(fname, "rb")
#     parser = PDFParser(fp)
#     doc = PDFDocument(parser, password)
#     if objids:
#         for objid in objids:
#             obj = doc.getobj(objid)
#             dumpxml(outfp, obj, codec=codec)
#     if pagenos:
#         for (pageno, page) in enumerate(PDFPage.create_pages(doc)):
#             if pageno in pagenos:
#                 if codec:
#                     for obj in page.contents:
#                         obj = stream_value(obj)
#                         dumpxml(outfp, obj, codec=codec)
#                 else:
#                     dumpxml(outfp, page.attrs)
#     if dumpall:
#         dumpallobjs(outfp, doc, codec, show_fallback_xref)
#     if (not objids) and (not pagenos) and (not dumpall):
#         dumptrailers(outfp, doc, show_fallback_xref)
#     fp.close()
#     if codec not in ("raw", "binary"):
#         outfp.write("\n")
#     return


import unittest
import pytest
from helpers import absolute_sample_path
from tempfilepath import TemporaryFilePath
from tools import dumppdf




def run(filename, options=None):
    absolute_path = absolute_sample_path(filename)
    with TemporaryFilePath() as output_file_name:
        if options:
            s = "dumppdf -o %s %s %s" % (output_file_name, options, absolute_path)
        else:
            s = "dumppdf -o %s %s" % (output_file_name, absolute_path)


# Path: tools/dumppdf.py
# def dumppdf(
#     outfp: TextIO,
#     fname: str,
#     objids: Iterable[int],
#     pagenos: Container[int],
#     password: str = "",
#     dumpall: bool = False,
#     codec: Optional[str] = None,
#     extractdir: Optional[str] = None,
#     show_fallback_xref: bool = False,
# ) -> None:
#     fp = open(fname, "rb")
#     parser = PDFParser(fp)
#     doc = PDFDocument(parser, password)
#     if objids:
#         for objid in objids:
#             obj = doc.getobj(objid)
#             dumpxml(outfp, obj, codec=codec)
#     if pagenos:
#         for (pageno, page) in enumerate(PDFPage.create_pages(doc)):
#             if pageno in pagenos:
#                 if codec:
#                     for obj in page.contents:
#                         obj = stream_value(obj)
#                         dumpxml(outfp, obj, codec=codec)
#                 else:
#                     dumpxml(outfp, page.attrs)
#     if dumpall:
#         dumpallobjs(outfp, doc, codec, show_fallback_xref)
#     if (not objids) and (not pagenos) and (not dumpall):
#         dumptrailers(outfp, doc, show_fallback_xref)
#     fp.close()
#     if codec not in ("raw", "binary"):
#         outfp.write("\n")
#     return


# Path: tests/test_tools_dumppdf.py
import unittest
import pytest
from helpers import absolute_sample_path
from tempfilepath import TemporaryFilePath
from tools import dumppdf





def run(filename, options=None):
    absolute_path = absolute_sample_path(filename)
    with TemporaryFilePath() as output_file_name:
        if options:
            s = "dumppdf -o %s %s %s" % (output_file_name, options, absolute_path)
        else:
            s = "dumppdf -o %s %s" % (output_file_name, absolute_path)


        dumppdf.main(s.split(" ")[1:])