Fix various things for python 3 compatibility

Review Request #9652 — Created Feb. 16, 2018 and discarded

Information

RBTools
master

Reviewers

Fix various things for python 3 compatibility

Python 2.7 tests all ran fine.

Python 3.6
Ran 211 tests in 48.853s
FAILED (SKIP=30, errors=27) - Will update to fix some of these.

Description From Last Updated

We need to keep Python 2.7 compatibility. Can you verify there's no bug on Python 2.7 (including early 2.7.x releases)?

chipx86chipx86

This seems unrelated to the rest of this change, and I'm not sure -pp is even valid?

chipx86chipx86

This is unrelated to this change.

chipx86chipx86

Our modern formatting would be more like: question = ( "Update Review Request ....?" % (review_request.id, get_draft_or_current_value(...)) )

chipx86chipx86

Is this Python 2.7-compatible?

chipx86chipx86

Same question.

chipx86chipx86

Please revert these. We want to keep those errors.

chipx86chipx86

I haven't seen any problems connecting to HTTPS, on Python 3 or otherwise. Is this with self-signed certificates?

daviddavid

Please revert the change in this line (we prefer trailing commas everywhere)

daviddavid
solarmist
chipx86
  1. 
      
  2. rbtools/commands/__init__.py (Diff revision 1)
     
     
     
     
     
     
     
     
     
    Show all issues

    We need to keep Python 2.7 compatibility. Can you verify there's no bug on Python 2.7 (including early 2.7.x releases)?

    1. Will do.

    2. This is good from Python 2.6 on.
      Changed in version 2.6: On Unix it defaults to using /dev/tty before falling back to sys.stdin and sys.stderr.
      https://docs.python.org/2/library/getpass.html

    3. Did you actually test redirecting stdout to a file and verifying that you could still see the Username/Password prompts?

  3. rbtools/commands/api_get.py (Diff revision 1)
     
     
    Show all issues

    This seems unrelated to the rest of this change, and I'm not sure -pp is even valid?

    1. These two unrelated changes user just making things consistent with other commands.

      Yes, it doesn't seem to have any problems with two character short codes. I think that was an issue in 2.6 and lower though if I remember correctly.

    2. I think it's a worthwhile change. Might just be better as its own change, so it can be reviewed on its own merits. We generally try to keep porting changes focused on the porting without any additional changes.

    3. Making into it's own commit.

  4. rbtools/commands/login.py (Diff revision 1)
     
     
    Show all issues

    This is unrelated to this change.

    1. This fixes a bug that prevented displaying the help for login.

  5. rbtools/commands/post.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    Our modern formatting would be more like:

    question = (
        "Update Review Request ....?"
        % (review_request.id,
           get_draft_or_current_value(...))
    )
    
    1. Will fix when I go through the 30 test failures.

  6. rbtools/utils/console.py (Diff revision 1)
     
     
    Show all issues

    Is this Python 2.7-compatible?

    1. You mean is input compatible with unicode strings? Yes.

      % python2.7     
      Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
      [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import six
      >>> print(six.moves.input(u'Ho how [asdf]'))
      Ho how [asdf]Yup
      Yup
      >>> print(getpass.getpass(u'hi asdfa [asdf]'))
      hi asdfa [asdf]
      Yup
      >>>
      
    2. Unicode string types aren't the issue. Python 2.x's input doesn't work fully with Unicode characters. It expects the text to be ASCII-compatible. See this example:

      >>> from six.moves import input
      >>> input(u'\U0001f355')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
      

      The encode is needed instead.

      >>> from six.moves import input
      >>> input(u'\U0001f355'.encode('utf-8'))
      
    3. Okay, but are you planning on locallizing rbtools?

    4. We are. New code is utilizing gettext for strings shown to users. We're updating older code as we go.

    5. Sorry, let me clarify. RBTools doesn't have localizations yet, but other modules we're building are. RBTools will be getting gettext support.

    6. Also worth noting that, even without localization, this function gets passed strings coming from user data (like review request summaries) that need to be in the proper encoding for input(). RBTools is also used as a Python API for interfacing with Review Board and for building custom commands by companies around the world, many of which don't use English in their text.

    7. David already made a change here. It's no longer in my diff.

  7. rbtools/utils/users.py (Diff revision 1)
     
     
    Show all issues

    Same question.

    1. Yes

      % python2.7     
      Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
      [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import six
      >>> print(six.moves.input(u'Ho how [asdf]'))
      Ho how [asdf]Yup
      Yup
      >>> print(getpass.getpass(u'hi asdfa [asdf]'))
      hi asdfa [asdf]
      Yup
      >>>
      
    2. Same issue here.

    3. This should be fine for localization, but arbitrary user input would need more careful handling.

      Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 26 2016, 12:10:39)
      [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> from six.moves import input
      >>> tmp = open('unicode_test.txt').read().strip()
      >>> input(tmp)
      ??????sadf
      'sadf'
      
      >>> from getpass import getpass
      >>> getpass(tmp)
      ?????
      'asdf'
      
  8. setup.py (Diff revision 1)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    Show all issues

    Please revert these. We want to keep those errors.

  9. 
      
solarmist
solarmist
david
  1. 
      
  2. README.md (Diff revision 3)
     
     
    Show all issues

    I haven't seen any problems connecting to HTTPS, on Python 3 or otherwise. Is this with self-signed certificates?

    1. From the python 3.6 readme:

      macOS users: If you are using the Python 3.6 from the python.org binary installer linked on this page, please carefully read the 
      Important Information displayed during installation; this information is also available after installation by clicking on     
      /Applications/Python 3.6/ReadMe.rtf. There is important information there about changes in the 3.6.0 installer-supplied Python, 
      particularly with regard to SSL certificate validation.
      

      https://bugs.python.org/issue29065

  3. rbtools/commands/post.py (Diff revision 3)
     
     
    Show all issues

    Please revert the change in this line (we prefer trailing commas everywhere)

    1. This is also a comment that doesn't add anything to the discussion.

  4. 
      
solarmist
david
Review request changed
Status:
Discarded
Change Summary:

Discarded in favor of /r/9880/