Add error handling for invalid pdfs

master
Dan Howe 7 years ago
parent 4b0ffa8c05
commit a003581825

@ -76,14 +76,21 @@ def isencrypted(pdf_name):
Returns: Returns:
True if encrypted, otherwise False True if encrypted, otherwise False
"""
pdf_info = pdfinfo(pdf_name)
status = pdf_info['Encrypted'].split(' ')[0]
if status == 'yes': Raises:
return True AttributeError if pdf info cannot be obtained
else: """
return False try:
pdf_info = pdfinfo(pdf_name)
status = pdf_info['Encrypted'].split(' ')[0]
if status == 'yes':
return True
elif status == 'no':
return False
else:
raise ValueError
except (SyntaxError, KeyError, ValueError):
raise AttributeError('Could not read pdf info.')
def pdf_unlock(pdf_file, overwrite=False): def pdf_unlock(pdf_file, overwrite=False):

Loading…
Cancel
Save