From 76fa3a16b37e375a8023f7e6870e8b5fc6716e58 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 Jun 2013 10:15:40 +0530 Subject: [PATCH] DOCX: Ensure images always have filenames --- src/calibre/ebooks/docx/images.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index 1a2006beae..52e16c436e 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -104,9 +104,12 @@ class Images(object): if rid in self.used: return self.used[rid] raw = self.docx.read(self.rid_map[rid]) - base = base or ascii_filename(self.rid_map[rid].rpartition('/')[-1]).replace(' ', '_') + base = base or ascii_filename(self.rid_map[rid].rpartition('/')[-1]).replace(' ', '_') or 'image' ext = what(None, raw) or base.rpartition('.')[-1] or 'jpeg' - base = base.rpartition('.')[0] + '.' + ext + base = base.rpartition('.')[0] + if not base: + base = 'image' + base += '.' + ext exists = frozenset(self.used.itervalues()) c = 1 while base in exists: