Quote:
Originally Posted by pdurrant
Calibre-provided temporary_file method.
|
Hmm.. I've been looking at this bit of code and the documentation, and I can see a potential problem or two.
Here's the guts of the plugin:
Code:
def run(self, path_to_ebook):
of = self.temporary_file('.mobi')
data_file = file(path_to_ebook, 'rb').read()
file(of.name, 'wb').write(data_file)
return of.name
Now the documentation describes temporary_file as returning a file-like object. It doesn't say whether this file object is open, and if it is, whether it's open in binary of text mode.
So the plug-in uses the file path from the open to make a new file object, open it for binary writing, and writes the input file to the temporary file.
* Should the plug-in be using the of.name in this way, and opening the file as binary write itself?
* Should the plug-in be closing the temporary_file in seom explicit way?