Changes between Version 1 and Version 2 of Python3Support


Ignore:
Timestamp:
05/21/18 08:26:07 (7 years ago)
Author:
annakrat
Comment:

python scripting lib

Legend:

Unmodified
Added
Removed
Modified
  • Python3Support

    v1 v2  
    1111* wxGUI
    1212
    13 == Current state of porting
     13== Python Scripting Library ==
     14Possible approach:
     15* functions need to accept unicode and return unicode
     16* functions wrapping Python Popen class (read_command, run_command, ...) will have parameter encoding
     17 * encoding=None means expects and returns bytes (the current state)
     18 * encoding='default' means it takes current encoding using utils._get_encoding()
     19 * encoding='utf-8' takes whatever encoding user specifies, e.g., utf-8 in this case
     20 * this is similar to [https://docs.python.org/3.6/library/subprocess.html#subprocess.Popen Popen class in Python3.6]
     21 * by default encoding='default' to enable expected behavior by users, the following example shows Python3 behavior if we keep using bytes instead of unicode:
     22
     23{{{
     24# return bytes
     25ret = read_command('r.what', encoding=None, ...
     26
     27for item in ret.splitlines():
     28    line = item.split('|')[3:]
     29
     30Traceback (most recent call last):
     31  File "<stdin>", line 1, in <module>
     32TypeError: a bytes-like object is required, not 'str'
     33
     34# we would have to use:
     35for item in ret.splitlines():
     36    line = item.split(b'|')[3:]
     37}}}