View Single Post
Old 09-26-2020, 01:42 PM   #1421
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,449
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by jackie_w View Post
At the risk of me trying to "teach Granny how to suck eggs" ...

When I was migrating my own plugins to python3 I found these 2 items from polyglot.builtins very useful: as_unicode, as_bytes

After I'd finished I don't think I had any .encode(...) or .decode(...) code left to go wrong. However, (full disclosure) I only ever use calibre's current container class to do everything related to epub-wrangling, so it's quite likely Kovid has already catered for everything that's likely to go wrong encoding-wise.
Thanks, but the problem arises elsewhere. The 'etree' package does strange things with encoding, returning byte strings sometimes and unicode other times. Same thing is true when opening files: now sometimes you need 'rb' and sometimes 'r', and sometimes the "newline=" argument. The code made no provision for getting images vs text. And so on.

Also, the plugin has a reimplemented container. I tried to go back to calibre's but that opened more cans than I could handle.
chaley is offline   Reply With Quote