Skip to content

pr-463/seraphire/seraphire/p4-python3-unicode-v1

commit: git-p4.py: Cast byte strings to unicode strings in python3

I tried to run git-p4 under python3 and it failed with an error that it
could not connect to the P4 server. This is caused by the return values from
the process.popen returning byte strings and the code is failing when it is
comparing these with literal strings which are Unicode in Python 3.

To support this, I added a new function ustring() in the code that
determines if python is natively supporting Unicode (Python 3) or not
(Python 2).

 * If the python version supports Unicode (Python 3), it will cast the text
   (expected a byte string) to UTF-8. This allows the existing code to match
   literal strings as expected.

 * If the python version does not natively support Unicode (Python 2) the
   ustring() function does not change the byte string, maintaining current
   behavior.

There are a few notable methods changed:

 * pipe functions have their output passed through the ustring() function:

    * read_pipe_full(c)
    * p4_has_move_command()

 * p4CmdList has new conditional code to parse the dictionary marshaled from
   the process call. Both the keys and values are converted to Unicode.

 * gitConfig passes the return value through ustring() so all calls to
   gitConfig return unicode values.

Signed-off-by: Ben Keene seraphire@gmail.com [seraphire@gmail.com]

Ben Keene (1):
  Cast byte strings to unicode strings in python3

 git-p4.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

base-commit: d9f6f3b6195a0ca35642561e530798ad1469bd41

Submitted-As: https://public-inbox.org/git/pull.463.git.1573679258.gitgitgadget@gmail.com
Assets 2