fix: support flexible type inputs for pages and unpaper_args

Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
James R. Barlow
2025-12-13 11:41:27 -08:00
co-authored by aider
parent f9a4a2e240
commit d18efcbbf1
2 changed files with 14 additions and 5 deletions
+12 -3
View File
@@ -91,7 +91,11 @@ class PageContext:
def __init__(self, pdf_context: PdfContext, pageno):
self.work_folder = pdf_context.work_folder
self.origin = pdf_context.origin
self.options = pdf_context.options
# Always use the legacy options for PageContext to ensure pickling works
if hasattr(pdf_context.options, 'to_namespace'):
self.options = pdf_context.options.to_namespace()
else:
self.options = pdf_context.options
self.pageno = pageno
self.pageinfo = pdf_context.pdfinfo[pageno]
self.plugin_manager = pdf_context.plugin_manager
@@ -107,8 +111,13 @@ class PageContext:
def __getstate__(self):
state = self.__dict__.copy()
state['options'] = copy(self.options)
# Handle both OCROptions and Namespace
# Convert OCROptions to Namespace for pickling compatibility
if hasattr(state['options'], 'to_namespace'):
state['options'] = state['options'].to_namespace()
else:
state['options'] = copy(state['options'])
# Handle stream inputs
if hasattr(state['options'], 'input_file'):
if not isinstance(state['options'].input_file, str | bytes | os.PathLike):
state['options'].input_file = 'stream'
+2 -2
View File
@@ -56,11 +56,11 @@ class OCROptions(BaseModel):
remove_background: bool = False
remove_vectors: bool = False
oversample: int = 0
unpaper_args: str | None = None
unpaper_args: str | list[str] | None = None # Can be string or list after validation
# OCR behavior
skip_big: float | None = None
pages: str | None = None
pages: str | set[int] | None = None # Can be string or set after validation
invalidate_digital_signatures: bool = False
# Metadata