View Single Post
Old 04-22-2019, 02:14 PM   #6
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Note that you don't actually need to use polyglot at all, but if you do, it's simple enough to just import from it and bump the minimum calibre version. But they are mostly pretty simple things.

I'd suggest going forward, to reduce the cognitive burden you should rely on any __future__ imports available (especially unicode_literals), make sure to mark all relevant strings as b'' and use modern python idioms that work natively on both. The latter two are things that any relatively recent code should probably have been doing anyway.

...

It's quite easy to reimplement the bits that you need, since they are, by and large, very simple try/except blocks. You could also rely on the fact that calibre has always had dependencies (dateutil, more recently html5lib) which require python-six, and just import needed functionality from e.g. six.moves which would make things a lot simpler. I think six 1.10 has been available at a minimum since a very long time...

Kovid has decided that he does not wish to rely on python-six, but you're not required to hold the same opinions.

Note: polyglot has been available since calibre 3.32 with the following contents (many more things were only added in the latest release):

Code:
from polyglot.builtins import is_py3, reraise, zip, map, filter, iteritems, iterkeys, itervalues
from polyglot.urllib import urlopen, urlencode
eschwartz is offline   Reply With Quote