defoe
defoe copied to clipboard
Upgrade to be Python 3-compliant
Run 2to3
to get recommendations for changes.
The key challenge will be handling Unicode. For example:
from cStringIO import StringIO
can be replaced by either of:
from io import BytesIO # for handling byte strings
from io import StringIO # for handling unicode strings
2to3
recommends changing:
try:
return str(result[0])
except UnicodeEncodeError:
return unicode(result[0])
to:
try:
return str(result[0])
except UnicodeEncodeError:
return str(result[0])
and
self.bwords = list(map(unicode, self.query(Page.words_path)))
to:
self.bwords = list(map(str, self.query(Page.words_path)))
https://python-future.org/compatible_idioms.html#unicode suggests something like:
from builtins import str as text
try:
return str(result[0])
except UnicodeEncodeError:
return text(result[0])