1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Better subprocess handling

This commit is contained in:
Tzu-ping Chung 2023-01-13 15:50:59 +08:00 committed by Dos Moonen
parent 0a9ff9de23
commit d325245052
2 changed files with 9 additions and 5 deletions

View file

@ -138,13 +138,14 @@ class KeyRingCliProvider(KeyRingBaseProvider):
"""Mirror the implementation of keyring.set_password using cli"""
if self.keyring is None:
return None
cmd = [self.keyring, "set", service_name, username]
input_ = (password + os.linesep).encode("utf-8")
env = os.environ.copy()
env["PYTHONIOENCODING"] = "utf-8"
res = subprocess.run(cmd, input=input_, env=env)
res.check_returncode()
subprocess.run(
[self.keyring, "set", service_name, username],
input=f"{password}{os.linesep}".encode("utf-8"),
env=env,
check=True,
)
return None

View file

@ -406,11 +406,13 @@ class KeyringSubprocessResult(KeyringModuleV1):
stdin: Optional[Any] = None,
stdout: Optional[Any] = None,
input: Optional[bytes] = None,
check: Optional[bool] = None
) -> Any:
if cmd[1] == "get":
assert stdin == -3 # subprocess.DEVNULL
assert stdout == subprocess.PIPE
assert env["PYTHONIOENCODING"] == "utf-8"
assert check is None
password = self.get_password(*cmd[2:])
if password is None:
@ -426,6 +428,7 @@ class KeyringSubprocessResult(KeyringModuleV1):
assert stdout is None
assert env["PYTHONIOENCODING"] == "utf-8"
assert input is not None
assert check
# Input from stdin is encoded
self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip(os.linesep))