View Single Post
Old 09-09-2014, 03:15 PM   #16
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,487
Karma: 5703586
Join Date: Nov 2009
Device: many
Hi,

I think it is coming from the tempfile or from the plugin launcher outdir. Perhaps on Windows mkdtemp returns a unicode path? Or it could come from the unicode literal string for the name of the new epub 'new.epub'.

Code:
@contextmanager
def make_temp_directory():
    import tempfile, shutil
    temp_dir = tempfile.mkdtemp()
    yield temp_dir
    shutil.rmtree(temp_dir)
If so we should probably change this to be:

Code:
@contextmanager
def make_temp_directory():
    import tempfile, shutil
    from utf8_utils import utf8_str
    temp_dir = utf8_str(tempfile.mkdtemp())
    yield temp_dir
    shutil.rmtree(temp_dir)
utf8_utils is already imported as part of the launcher so importing from it should be no issue. Either that or it is the outdir that needs to be converted to utf8 by the launcher (but I think it already does that).

The problem is all it takes is one full unicode path piece to exist and when joining paths to it, all of the resulting path will be upconverted to full unicode. So tracking down which is the culprit will take some time but I will find it.

Perhaps simply removing the unicode literals and seeing what happens might be easiest as now I am wondering what happens with the following code:

self.bk.addotherfile('new.epub', data)

The 'new.epub" is a literal and so probably is full unicode. Then concatenating its name to the outdir path probably forces the whole thing to be full unicode.


Thanks,

KevinH

Quote:
Originally Posted by DiapDealer View Post
Hey Kevin, the full unicode strings are probably coming from me using the "from __future__ import unicode_literals" (or whatever) in my code. But it works in the calibre plugin without warning, so I'm not sure. I've not gotten that particular warning in my preliminary testing so far (mostly on Linux--a little Windows).

Last edited by KevinH; 09-09-2014 at 04:00 PM.
KevinH is offline