[PATCH v2 0/3] git-p4.py: Cast byte strings to unicode strings in python3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 PR covers updating the git-p4.py
python script to work with unicode strings in python3.

Changes since v1: Commit: (0435d0e) 2019-11-14

The problem was caused by the ustring() function being called on a string
that had already been cast as a unicode string. This second call to
ustring() would fail with an error of "decoding str is not supported"

The following changes were made to fix this:

The call to ustring() in the gitConfig() function is actually unnecessary
because the read_pipe() function returns unicode strings so the call has
been removed.

The ustring() function was given a new conditional test to see if the value
is already a unicode value. If it is, the value will be returned without any
casting.

These two changes should fix the immediate fail. However, I do not have an
environment that I can run the test suite against so I don't know if another
error will be uncovered yet. I'm still working on it.

v1: (Initial Commit)

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@xxxxxxxxx [seraphire@xxxxxxxxx]

Ben Keene (3):
  Cast byte strings to unicode strings in python3
  FIX: cast as unicode fails when a value is already unicode
  FIX: wrap return for read_pipe_lines in ustring() and wrap GitLFS read
    of the pointer file in ustring()

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


base-commit: d9f6f3b6195a0ca35642561e530798ad1469bd41
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-463%2Fseraphire%2Fseraphire%2Fp4-python3-unicode-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-463/seraphire/seraphire/p4-python3-unicode-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/463

Range-diff vs v1:

 1:  0bca930ff8 = 1:  0bca930ff8 Cast byte strings to unicode strings in python3
 -:  ---------- > 2:  0435d0e2cb FIX: cast as unicode fails when a value is already unicode
 -:  ---------- > 3:  2288690b94 FIX: wrap return for read_pipe_lines in ustring() and wrap GitLFS read of the pointer file in ustring()

-- 
gitgitgadget



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux