Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Explicitly check passwords for None rather than falsey.
Correct read_pdf documentation for Owner/User password.

Issue atlanhq#162
  • Loading branch information
rbares committed Oct 28, 2018
1 parent d18e6f4 commit 80b3d99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions camelot/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()})
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion camelot/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://euske.github.io/pdfminer/>`_.
password* : str, optional (default: None)
password : str, optional (default: None)
Owner or User password required for file decryption.
Returns
Expand Down

0 comments on commit 80b3d99

Please sign in to comment.