From 80b3d9904424909a80e7704bb3ea9e4ff176ad73 Mon Sep 17 00:00:00 2001 From: rbares Date: Sun, 28 Oct 2018 10:18:30 +0000 Subject: [PATCH] Address review comments Explicitly check passwords for None rather than falsey. Correct read_pdf documentation for Owner/User password. Issue #162 --- camelot/handlers.py | 8 ++++---- camelot/io.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/camelot/handlers.py b/camelot/handlers.py index aebbaab0..bd3ad6d5 100644 --- a/camelot/handlers.py +++ b/camelot/handlers.py @@ -29,7 +29,7 @@ class PDFHandler(object): """ def __init__(self, filename, pages='1', password=None): self.filename = filename - if password and sys.version_info[0] < 3: + if password is not None and sys.version_info[0] < 3: self.password = password.encode('ascii') else: self.password = password @@ -59,7 +59,7 @@ def _get_pages(self, filename, pages): page_numbers.append({'start': 1, 'end': 1}) else: infile = PdfFileReader(open(filename, 'rb'), strict=False) - if infile.isEncrypted and self.password: + if infile.isEncrypted and self.password is not None: infile.decrypt(self.password) if pages == 'all': page_numbers.append({'start': 1, 'end': infile.getNumPages()}) @@ -92,7 +92,7 @@ def _save_page(self, filename, page, temp): """ with open(filename, 'rb') as fileobj: infile = PdfFileReader(fileobj, strict=False) - if infile.isEncrypted and self.password: + if infile.isEncrypted and self.password is not None: infile.decrypt(self.password) fpath = os.path.join(temp, 'page-{0}.pdf'.format(page)) froot, fext = os.path.splitext(fpath) @@ -111,7 +111,7 @@ def _save_page(self, filename, page, temp): fpath_new = ''.join([froot.replace('page', 'p'), '_rotated', fext]) os.rename(fpath, fpath_new) infile = PdfFileReader(open(fpath_new, 'rb'), strict=False) - if infile.isEncrypted and self.password: + if infile.isEncrypted and self.password is not None: infile.decrypt(self.password) outfile = PdfFileWriter() p = infile.getPage(0) diff --git a/camelot/io.py b/camelot/io.py index d4e23bf0..89bd15fb 100644 --- a/camelot/io.py +++ b/camelot/io.py @@ -79,7 +79,7 @@ def read_pdf(filepath, pages='1', flavor='lattice', suppress_warnings=False, PDFMiner char_margin, line_margin and word_margin. For more information, refer `PDFMiner docs `_. - password* : str, optional (default: None) + password : str, optional (default: None) Owner or User password required for file decryption. Returns