View Single Post
Old 02-16-2010, 06:07 AM   #9
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 74,113
Karma: 315558332
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Oasis
Quote:
Originally Posted by pdurrant View Post
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?

Last edited by pdurrant; 02-16-2010 at 06:09 AM. Reason: added code tags
pdurrant is offline   Reply With Quote