DOCX Input: Fix image name generation

DOCX Input: When converting docx files with large numbers of unnamed
images, do not crash on windows. Fixes #1191354 [Word docx conversion](https://bugs.launchpad.net/calibre/+bug/1191354)
This commit is contained in:
Kovid Goyal 2013-06-16 08:31:05 +05:30
parent bf9263b007
commit b63e0df73f

View File

@ -112,15 +112,16 @@ class Images(object):
base += '.' + ext
exists = frozenset(self.used.itervalues())
c = 1
while base in exists:
name = base
while name in exists:
n, e = base.rpartition('.')[0::2]
base = '%s-%d.%s' % (n, c, e)
name = '%s-%d.%s' % (n, c, e)
c += 1
self.used[rid] = base
with open(os.path.join(self.dest_dir, base), 'wb') as f:
self.used[rid] = name
with open(os.path.join(self.dest_dir, name), 'wb') as f:
f.write(raw)
self.all_images.add('images/' + base)
return base
self.all_images.add('images/' + name)
return name
def pic_to_img(self, pic, alt=None):
name = None