defoe icon indicating copy to clipboard operation
defoe copied to clipboard

Upgrade to be Python 3-compliant

Open mikej888 opened this issue 6 years ago • 0 comments

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])

mikej888 avatar Jan 15 '19 14:01 mikej888