(
self,
source: Iterable[Union[Path, str, DocumentStream]], # TODO review naming
headers: Optional[Dict[str, str]] = None,
raises_on_error: bool = True, # True: raises on first conversion error; False: does not raise on conv error
max_num_pages: int = sys.maxsize,
max_file_size: int = sys.maxsize,
page_range: PageRange = DEFAULT_PAGE_RANGE,
)
| 204 | |
| 205 | @validate_call(config=ConfigDict(strict=True)) |
| 206 | def convert_all( |
| 207 | self, |
| 208 | source: Iterable[Union[Path, str, DocumentStream]], # TODO review naming |
| 209 | headers: Optional[Dict[str, str]] = None, |
| 210 | raises_on_error: bool = True, # True: raises on first conversion error; False: does not raise on conv error |
| 211 | max_num_pages: int = sys.maxsize, |
| 212 | max_file_size: int = sys.maxsize, |
| 213 | page_range: PageRange = DEFAULT_PAGE_RANGE, |
| 214 | ) -> Iterator[ConversionResult]: |
| 215 | limits = DocumentLimits( |
| 216 | max_num_pages=max_num_pages, |
| 217 | max_file_size=max_file_size, |
| 218 | page_range=page_range, |
| 219 | ) |
| 220 | conv_input = _DocumentConversionInput( |
| 221 | path_or_stream_iterator=source, limits=limits, headers=headers |
| 222 | ) |
| 223 | conv_res_iter = self._convert(conv_input, raises_on_error=raises_on_error) |
| 224 | |
| 225 | had_result = False |
| 226 | for conv_res in conv_res_iter: |
| 227 | had_result = True |
| 228 | if raises_on_error and conv_res.status not in { |
| 229 | ConversionStatus.SUCCESS, |
| 230 | ConversionStatus.PARTIAL_SUCCESS, |
| 231 | }: |
| 232 | raise ConversionError( |
| 233 | f"Conversion failed for: {conv_res.input.file} with status: {conv_res.status}" |
| 234 | ) |
| 235 | else: |
| 236 | yield conv_res |
| 237 | |
| 238 | if not had_result and raises_on_error: |
| 239 | raise ConversionError( |
| 240 | f"Conversion failed because the provided file has no recognizable format or it wasn't in the list of allowed formats." |
| 241 | ) |
| 242 | |
| 243 | def _convert( |
| 244 | self, conv_input: _DocumentConversionInput, raises_on_error: bool |
no test coverage detected