From c8705a4f66144c68acb1dbb59c4f85b4920f19fc Mon Sep 17 00:00:00 2001 From: Pierre-Selim Date: Sat, 19 Sep 2020 19:45:13 +0200 Subject: [PATCH] Adding a close() method and context manager methods for class PDFx --- pdfx/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pdfx/__init__.py b/pdfx/__init__.py index 6042e26..af7e52a 100644 --- a/pdfx/__init__.py +++ b/pdfx/__init__.py @@ -205,3 +205,13 @@ def download_pdfs(self, target_dir): # Download urls as a set to avoid duplicates download_urls(urls, dir_referenced_pdfs) + + def close(self): + if self.stream: + self.stream.close() + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.close()