diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index d378eee..b8bc3c0 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -69,7 +69,7 @@ class IsolationProvider(ABC): self.progress_callback = progress_callback document.mark_as_converting() try: - conversion_proc = self.start_doc_to_pixels_proc() + conversion_proc = self.start_doc_to_pixels_proc(document) with tempfile.TemporaryDirectory() as t: Path(f"{t}/pixels").mkdir() self.doc_to_pixels(document, t, conversion_proc) @@ -192,7 +192,7 @@ class IsolationProvider(ABC): return armor_start + conversion_string + armor_end @abstractmethod - def start_doc_to_pixels_proc(self) -> subprocess.Popen: + def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: pass diff --git a/dangerzone/isolation_provider/container.py b/dangerzone/isolation_provider/container.py index cbadcc3..ef5dd91 100644 --- a/dangerzone/isolation_provider/container.py +++ b/dangerzone/isolation_provider/container.py @@ -251,7 +251,7 @@ class Container(IsolationProvider): ) shutil.move(container_output_filename, document.output_filename) - def start_doc_to_pixels_proc(self) -> subprocess.Popen: + def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: # Convert document to pixels command = [ "/usr/bin/python3", diff --git a/dangerzone/isolation_provider/dummy.py b/dangerzone/isolation_provider/dummy.py index fa671f1..af5a263 100644 --- a/dangerzone/isolation_provider/dummy.py +++ b/dangerzone/isolation_provider/dummy.py @@ -74,7 +74,7 @@ class Dummy(IsolationProvider): ) -> None: pass - def start_doc_to_pixels_proc(self) -> subprocess.Popen: + def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: return subprocess.Popen("True") def get_max_parallel_conversions(self) -> int: diff --git a/dangerzone/isolation_provider/qubes.py b/dangerzone/isolation_provider/qubes.py index 0b607f8..b26d390 100644 --- a/dangerzone/isolation_provider/qubes.py +++ b/dangerzone/isolation_provider/qubes.py @@ -51,7 +51,7 @@ class Qubes(IsolationProvider): def get_max_parallel_conversions(self) -> int: return 1 - def start_doc_to_pixels_proc(self) -> subprocess.Popen: + def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: dev_mode = getattr(sys, "dangerzone_dev", False) == True if dev_mode: # Use dz.ConvertDev RPC call instead, if we are in development mode. diff --git a/tests/isolation_provider/base.py b/tests/isolation_provider/base.py index 2640773..ac7cc97 100644 --- a/tests/isolation_provider/base.py +++ b/tests/isolation_provider/base.py @@ -37,7 +37,7 @@ class IsolationProviderTest: provider.progress_callback = mocker.MagicMock() doc = Document(pdf_11k_pages) - p = provider.start_doc_to_pixels_proc() + p = provider.start_doc_to_pixels_proc(doc) with pytest.raises(errors.ConverterProcException): provider.doc_to_pixels(doc, tmpdir, p) assert provider.get_proc_exception(p) == errors.MaxPagesException @@ -54,7 +54,7 @@ class IsolationProviderTest: "dangerzone.conversion.errors.MAX_PAGES", 1 ) # sample_doc has 4 pages > 1 doc = Document(sample_doc) - p = provider.start_doc_to_pixels_proc() + p = provider.start_doc_to_pixels_proc(doc) with pytest.raises(errors.MaxPagesException): provider.doc_to_pixels(doc, tmpdir, p) @@ -67,10 +67,12 @@ class IsolationProviderTest: tmpdir: str, ) -> None: provider.progress_callback = mocker.MagicMock() - p = provider.start_doc_to_pixels_proc() + doc = Document(sample_bad_width) + p = provider.start_doc_to_pixels_proc(doc) with pytest.raises(errors.MaxPageWidthException): - provider.doc_to_pixels(Document(sample_bad_width), tmpdir, p) + provider.doc_to_pixels(doc, tmpdir, p) - p = provider.start_doc_to_pixels_proc() + doc = Document(sample_bad_height) + p = provider.start_doc_to_pixels_proc(doc) with pytest.raises(errors.MaxPageHeightException): - provider.doc_to_pixels(Document(sample_bad_height), tmpdir, p) + provider.doc_to_pixels(doc, tmpdir, p)