improve bad epub error handling

pull/1/head
eric 2013-11-05 00:57:15 -05:00
parent 31512d36b0
commit 499378ccf7
2 changed files with 3 additions and 3 deletions

View File

@ -135,6 +135,7 @@ from regluit.payment.parameters import (
from regluit.utils.localdatetime import now, date_today from regluit.utils.localdatetime import now, date_today
from regluit.booxtream.exceptions import BooXtreamError from regluit.booxtream.exceptions import BooXtreamError
from regluit.pyepub import InvalidEpub
from regluit.libraryauth.views import Authenticator from regluit.libraryauth.views import Authenticator
from regluit.libraryauth.models import Library from regluit.libraryauth.models import Library
@ -436,7 +437,7 @@ def edition_uploads(request, edition_id):
try: try:
test_acq.get_watermarked() test_acq.get_watermarked()
context['watermarked']= test_acq.watermarked context['watermarked']= test_acq.watermarked
except (BooXtreamError, ET.ParseError) as e: except (BooXtreamError, ET.ParseError, InvalidEpub) as e:
context['upload_error']= e context['upload_error']= e
form.instance.delete() form.instance.delete()

View File

@ -137,8 +137,7 @@ class EPUB(zipfile.ZipFile):
self.id = self.opf.find('.//{0}identifier[@id="{1}"]'.format(NAMESPACE["dc"], self.id = self.opf.find('.//{0}identifier[@id="{1}"]'.format(NAMESPACE["dc"],
self.opf.get("unique-identifier"))).text self.opf.get("unique-identifier"))).text
except AttributeError: except AttributeError:
raise InvalidEpub # Cannot process an EPUB without unique-identifier raise InvalidEpub("Cannot process an EPUB without unique-identifier attribute of the package element")
# attribute of the package element
# Get and parse the TOC # Get and parse the TOC
toc_id = self.opf[2].get("toc") toc_id = self.opf[2].get("toc")
expr = ".//{0}item[@id='{1:s}']".format(NAMESPACE["opf"], toc_id) expr = ".//{0}item[@id='{1:s}']".format(NAMESPACE["opf"], toc_id)