Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #116 #117

Merged
merged 1 commit into from
Sep 12, 2015
Merged

Fix #116 #117

merged 1 commit into from
Sep 12, 2015

Conversation

mhils
Copy link
Contributor

@mhils mhils commented Jul 21, 2015

getpass.getpass only accepts str as its first parameter on Windows.

Closes #116

Python 2: getpass.getpass only accepts str as its first parameter on Windows.
Python 3: getpass.getpass only accepts unicode as its first parameter on Windows.

@sigmavirus24
Copy link
Member

If getpass only accepts str then this will break users running Twine on Python 3. Further, passing bytes doesn't make sense. Did you mean to do b'...'.decode('utf8')? That will do the right thing on all versions of Python

@mhils
Copy link
Contributor Author

mhils commented Jul 21, 2015

As it seems, you can only pass bytes on Python 2 - on Python 3, it's the other way around:

> python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass

>>> getpass.getpass(u"test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\getpass.py", line 95, in win_getpass
    msvcrt.putch(c)
TypeError: must be char, not unicode

>>> getpass.getpass(b"test")
test
''
> python3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass

>>> getpass.getpass(u"test")
test
''

>>> getpass.getpass(b"test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\getpass.py", line 104, in win_getpass
    msvcrt.putwch(c)
TypeError: must be a unicode character, not int

How do you work around py2/3 issues usually here?

@sigmavirus24
Copy link
Member

So I would write a function that does the proper checks for windows and then version in twine/utils.py such that it does something like

def password_prompt(prompt_text):  # Always expects unicode for our own sanity
    prompt = prompt_text
    if 'nt' in platform_info:
        if sys.version_info < (3, 0):
            prompt = prompt_text.encode('utf8')
    return functools.partial(getpass.getpass, prompt=prompt)

get_password = functools.partial(
    # ...
    prompt_strategy=password_prompt("Enter your password:"),
)

@mhils
Copy link
Contributor Author

mhils commented Aug 7, 2015

I just updated the PR - sorry that it took so long. 😃

@mhils
Copy link
Contributor Author

mhils commented Aug 8, 2015

Travis is happy now as well.

@sigmavirus24
Copy link
Member

Sorry I missed that you had updated this @mhils! Thanks for fixing this! 🍰

@sigmavirus24 sigmavirus24 added this to the next milestone Sep 12, 2015
@sigmavirus24 sigmavirus24 self-assigned this Sep 12, 2015
sigmavirus24 added a commit that referenced this pull request Sep 12, 2015
@sigmavirus24 sigmavirus24 merged commit 2b48128 into pypa:master Sep 12, 2015
@mhils mhils deleted the patch-1 branch September 13, 2015 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants