From 7d2b052ef0cc77ed50b1d328184faad90bc8f742 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 29 Jul 2018 20:56:05 -0400 Subject: [PATCH] really fix pyepub --- core/validation.py | 11 +++++++++-- pyepub/__init__.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/validation.py b/core/validation.py index aed5a3fd..d5613972 100644 --- a/core/validation.py +++ b/core/validation.py @@ -4,6 +4,7 @@ methods to validate and clean identifiers ''' import re import datetime +import logging from dateutil.parser import parse from PyPDF2 import PdfFileReader @@ -15,6 +16,8 @@ from regluit.pyepub import EPUB from regluit.mobi import Mobi from .isbn import ISBN +logger = logging.getLogger(__name__) + ID_VALIDATION = { 'http': (re.compile(r"(https?|ftp)://(-\.)?([^\s/?\.#]+\.?)+(/[^\s]*)?$", flags=re.IGNORECASE|re.S), @@ -105,17 +108,21 @@ def test_file(the_file, fformat): try: book = EPUB(the_file.file) except Exception as e: + logger.exception(e) raise ValidationError(_('Are you sure this is an EPUB file?: %s' % e)) elif fformat == 'mobi': try: book = Mobi(the_file.file) book.parse() except Exception as e: - raise ValidationError(_('Are you sure this is a MOBI file?: %s' % e)) + logger.exception(e) + #raise ValidationError(_('Are you sure this is a MOBI file?: %s' % e)) + raise e elif fformat == 'pdf': try: PdfFileReader(the_file.file) - except Exception, e: + except Exception as e: + logger.exception(e) raise ValidationError(_('%s is not a valid PDF file' % the_file.name)) return True diff --git a/pyepub/__init__.py b/pyepub/__init__.py index b5de61e6..279a0782 100644 --- a/pyepub/__init__.py +++ b/pyepub/__init__.py @@ -107,7 +107,7 @@ class EPUB(zipfile.ZipFile): # Iterate over section, fill EPUB.info["metadata"] dictionary for i in self.opf.find("{0}metadata".format(NAMESPACE["opf"])): - if i.tag: + if i.tag and isinstance(i.tag, str): tag = ns.sub('', i.tag) if tag not in self.info["metadata"]: self.info["metadata"][tag] = i.text or i.attrib