From 548325c4e9221703526154172e54f15198657cd4 Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Sat, 10 Aug 2013 15:06:06 +0200 Subject: [PATCH] Avoid confusing PIL warning for vector graphics (epub builder). --- sphinx/builders/epub.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index cd02c157a..28969acdf 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -155,6 +155,8 @@ _media_types = { '.ttf': 'application/x-font-ttf', } +_vector_graphics_extensions = ('.svg',) + # Regular expression to match colons only in local fragment identifiers. # If the URI contains a colon before the #, # it is an external link that should not change. @@ -393,6 +395,11 @@ class EpubBuilder(StandaloneHTMLBuilder): subentrylinks[i] = (ismain, self.fix_fragment(m.group(1), m.group(2))) + def is_vector_graphics(self, filename): + """Does the filename extension indicate a vector graphic format?""" + ext = path.splitext(filename)[-1] + return ext in _vector_graphics_extensions + def copy_image_files_pil(self): """Copy images using the PIL. The method tries to read and write the files with the PIL, @@ -405,8 +412,9 @@ class EpubBuilder(StandaloneHTMLBuilder): try: img = Image.open(path.join(self.srcdir, src)) except IOError: - self.warn('cannot read image file %r: copying it instead' % - (path.join(self.srcdir, src), )) + if not self.is_vector_graphics(src): + self.warn('cannot read image file %r: copying it instead' % + (path.join(self.srcdir, src), )) try: copyfile(path.join(self.srcdir, src), path.join(self.outdir, '_images', dest))