From bd8843a775b84735ebdbc3ea70f24e14de333450 Mon Sep 17 00:00:00 2001 From: Matthew Leather <39400458+matthew16550@users.noreply.github.com> Date: Tue, 23 Apr 2024 02:49:03 +1200 Subject: [PATCH] paramiko: Replace str with FileDescriptorOrPath in many locations (#11800) --- stubs/paramiko/paramiko/client.pyi | 7 ++++--- stubs/paramiko/paramiko/config.pyi | 3 ++- stubs/paramiko/paramiko/dsskey.pyi | 6 +++--- stubs/paramiko/paramiko/ecdsakey.pyi | 6 +++--- stubs/paramiko/paramiko/ed25519key.pyi | 4 ++-- stubs/paramiko/paramiko/hostkeys.pyi | 7 ++++--- stubs/paramiko/paramiko/pkey.pyi | 7 ++++--- stubs/paramiko/paramiko/primes.pyi | 4 +++- stubs/paramiko/paramiko/rsakey.pyi | 6 +++--- stubs/paramiko/paramiko/sftp_server.pyi | 3 ++- stubs/paramiko/paramiko/transport.pyi | 3 ++- stubs/paramiko/paramiko/util.pyi | 6 +++--- 12 files changed, 35 insertions(+), 27 deletions(-) diff --git a/stubs/paramiko/paramiko/client.pyi b/stubs/paramiko/paramiko/client.pyi index 379031815..6462fcd8c 100644 --- a/stubs/paramiko/paramiko/client.pyi +++ b/stubs/paramiko/paramiko/client.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from collections.abc import Iterable, Mapping from typing import NoReturn, Protocol @@ -22,9 +23,9 @@ class _TransportFactory(Protocol): class SSHClient(ClosingContextManager): def __init__(self) -> None: ... - def load_system_host_keys(self, filename: str | None = None) -> None: ... - def load_host_keys(self, filename: str) -> None: ... - def save_host_keys(self, filename: str) -> None: ... + def load_system_host_keys(self, filename: FileDescriptorOrPath | None = None) -> None: ... + def load_host_keys(self, filename: FileDescriptorOrPath) -> None: ... + def save_host_keys(self, filename: FileDescriptorOrPath) -> None: ... def get_host_keys(self) -> HostKeys: ... def set_log_channel(self, name: str) -> None: ... def set_missing_host_key_policy(self, policy: type[MissingHostKeyPolicy] | MissingHostKeyPolicy) -> None: ... diff --git a/stubs/paramiko/paramiko/config.pyi b/stubs/paramiko/paramiko/config.pyi index 7c35f82ae..831dccfca 100644 --- a/stubs/paramiko/paramiko/config.pyi +++ b/stubs/paramiko/paramiko/config.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from collections.abc import Iterable from re import Pattern from typing import IO @@ -14,7 +15,7 @@ class SSHConfig: @classmethod def from_text(cls, text: str) -> Self: ... @classmethod - def from_path(cls, path: str) -> Self: ... + def from_path(cls, path: FileDescriptorOrPath) -> Self: ... @classmethod def from_file(cls, flo: IO[str]) -> Self: ... def parse(self, file_obj: IO[str]) -> None: ... diff --git a/stubs/paramiko/paramiko/dsskey.pyi b/stubs/paramiko/paramiko/dsskey.pyi index 979812821..59b419275 100644 --- a/stubs/paramiko/paramiko/dsskey.pyi +++ b/stubs/paramiko/paramiko/dsskey.pyi @@ -1,4 +1,4 @@ -from _typeshed import ReadableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer from collections.abc import Callable from typing import IO @@ -17,7 +17,7 @@ class DSSKey(PKey): self, msg: Message | None = None, data: ReadableBuffer | None = None, - filename: str | None = None, + filename: FileDescriptorOrPath | None = None, password: str | None = None, vals: tuple[int, int, int, int] | None = None, file_obj: IO[str] | None = None, @@ -29,7 +29,7 @@ class DSSKey(PKey): def can_sign(self) -> bool: ... def sign_ssh_data(self, data: bytes, algorithm: str | None = None) -> Message: ... def verify_ssh_sig(self, data: bytes, msg: Message) -> bool: ... - def write_private_key_file(self, filename: str, password: str | None = None) -> None: ... + def write_private_key_file(self, filename: FileDescriptorOrPath, password: str | None = None) -> None: ... def write_private_key(self, file_obj: IO[str], password: str | None = None) -> None: ... @staticmethod def generate(bits: int = 1024, progress_func: Callable[..., object] | None = None) -> DSSKey: ... diff --git a/stubs/paramiko/paramiko/ecdsakey.pyi b/stubs/paramiko/paramiko/ecdsakey.pyi index 515e7e85e..b6b757167 100644 --- a/stubs/paramiko/paramiko/ecdsakey.pyi +++ b/stubs/paramiko/paramiko/ecdsakey.pyi @@ -1,4 +1,4 @@ -from _typeshed import ReadableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer from collections.abc import Callable, Sequence from typing import IO, Any @@ -32,7 +32,7 @@ class ECDSAKey(PKey): self, msg: Message | None = None, data: ReadableBuffer | None = None, - filename: str | None = None, + filename: FileDescriptorOrPath | None = None, password: str | None = None, vals: tuple[EllipticCurvePrivateKey, EllipticCurvePublicKey] | None = None, file_obj: IO[str] | None = None, @@ -47,7 +47,7 @@ class ECDSAKey(PKey): def can_sign(self) -> bool: ... def sign_ssh_data(self, data: bytes, algorithm: str | None = None) -> Message: ... def verify_ssh_sig(self, data: bytes, msg: Message) -> bool: ... - def write_private_key_file(self, filename: str, password: str | None = None) -> None: ... + def write_private_key_file(self, filename: FileDescriptorOrPath, password: str | None = None) -> None: ... def write_private_key(self, file_obj: IO[str], password: str | None = None) -> None: ... @classmethod def generate( diff --git a/stubs/paramiko/paramiko/ed25519key.pyi b/stubs/paramiko/paramiko/ed25519key.pyi index d5d269a12..dcfb76cbe 100644 --- a/stubs/paramiko/paramiko/ed25519key.pyi +++ b/stubs/paramiko/paramiko/ed25519key.pyi @@ -1,4 +1,4 @@ -from _typeshed import ReadableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer from typing import IO from paramiko.message import Message @@ -10,7 +10,7 @@ class Ed25519Key(PKey): self, msg: Message | None = None, data: ReadableBuffer | None = None, - filename: str | None = None, + filename: FileDescriptorOrPath | None = None, password: str | None = None, file_obj: IO[str] | None = None, ) -> None: ... diff --git a/stubs/paramiko/paramiko/hostkeys.pyi b/stubs/paramiko/paramiko/hostkeys.pyi index 214b701b2..5c9031b7d 100644 --- a/stubs/paramiko/paramiko/hostkeys.pyi +++ b/stubs/paramiko/paramiko/hostkeys.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from collections.abc import Iterator, Mapping, MutableMapping from typing_extensions import Self @@ -14,10 +15,10 @@ class _SubDict(MutableMapping[str, PKey]): def keys(self) -> list[str]: ... # type: ignore[override] class HostKeys(MutableMapping[str, _SubDict]): - def __init__(self, filename: str | None = None) -> None: ... + def __init__(self, filename: FileDescriptorOrPath | None = None) -> None: ... def add(self, hostname: str, keytype: str, key: PKey) -> None: ... - def load(self, filename: str) -> None: ... - def save(self, filename: str) -> None: ... + def load(self, filename: FileDescriptorOrPath) -> None: ... + def save(self, filename: FileDescriptorOrPath) -> None: ... def lookup(self, hostname: str) -> _SubDict | None: ... def check(self, hostname: str, key: PKey) -> bool: ... def clear(self) -> None: ... diff --git a/stubs/paramiko/paramiko/pkey.pyi b/stubs/paramiko/paramiko/pkey.pyi index 0f26d291a..c6defb22e 100644 --- a/stubs/paramiko/paramiko/pkey.pyi +++ b/stubs/paramiko/paramiko/pkey.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from pathlib import Path from re import Pattern from typing import IO, TypeVar @@ -38,10 +39,10 @@ class PKey: def sign_ssh_data(self, data: bytes, algorithm: str | None = None) -> Message: ... def verify_ssh_sig(self, data: bytes, msg: Message) -> bool: ... @classmethod - def from_private_key_file(cls, filename: str, password: str | None = None) -> Self: ... + def from_private_key_file(cls, filename: FileDescriptorOrPath, password: str | None = None) -> Self: ... @classmethod def from_private_key(cls, file_obj: IO[str], password: str | None = None) -> Self: ... - def write_private_key_file(self, filename: str, password: str | None = None) -> None: ... + def write_private_key_file(self, filename: FileDescriptorOrPath, password: str | None = None) -> None: ... def write_private_key(self, file_obj: IO[str], password: str | None = None) -> None: ... def load_certificate(self, value: Message | str) -> None: ... @@ -51,7 +52,7 @@ class PublicBlob: comment: str def __init__(self, type_: str, blob: bytes, comment: str | None = None) -> None: ... @classmethod - def from_file(cls, filename: str) -> Self: ... + def from_file(cls, filename: FileDescriptorOrPath) -> Self: ... @classmethod def from_string(cls, string: str) -> Self: ... @classmethod diff --git a/stubs/paramiko/paramiko/primes.pyi b/stubs/paramiko/paramiko/primes.pyi index 3d7cccd9a..a59dedce5 100644 --- a/stubs/paramiko/paramiko/primes.pyi +++ b/stubs/paramiko/paramiko/primes.pyi @@ -1,6 +1,8 @@ +from _typeshed import FileDescriptorOrPath + class ModulusPack: pack: dict[int, list[tuple[int, int]]] discarded: list[tuple[int, str]] def __init__(self) -> None: ... - def read_file(self, filename: str) -> None: ... + def read_file(self, filename: FileDescriptorOrPath) -> None: ... def get_modulus(self, min: int, prefer: int, max: int) -> tuple[int, int]: ... diff --git a/stubs/paramiko/paramiko/rsakey.pyi b/stubs/paramiko/paramiko/rsakey.pyi index d0596f8a7..60541e26a 100644 --- a/stubs/paramiko/paramiko/rsakey.pyi +++ b/stubs/paramiko/paramiko/rsakey.pyi @@ -1,4 +1,4 @@ -from _typeshed import ReadableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer from collections.abc import Callable from typing import IO @@ -13,7 +13,7 @@ class RSAKey(PKey): self, msg: Message | None = None, data: ReadableBuffer | None = None, - filename: str | None = None, + filename: FileDescriptorOrPath | None = None, password: str | None = None, key: None | RSAPublicKey | RSAPrivateKey = None, file_obj: IO[str] | None = None, @@ -29,7 +29,7 @@ class RSAKey(PKey): def can_sign(self) -> bool: ... def sign_ssh_data(self, data: bytes, algorithm: str | None = None) -> Message: ... def verify_ssh_sig(self, data: bytes, msg: Message) -> bool: ... - def write_private_key_file(self, filename: str, password: str | None = None) -> None: ... + def write_private_key_file(self, filename: FileDescriptorOrPath, password: str | None = None) -> None: ... def write_private_key(self, file_obj: IO[str], password: str | None = None) -> None: ... @staticmethod def generate(bits: int, progress_func: Callable[..., object] | None = None) -> RSAKey: ... diff --git a/stubs/paramiko/paramiko/sftp_server.pyi b/stubs/paramiko/paramiko/sftp_server.pyi index 8e8dddef1..656ebc5fd 100644 --- a/stubs/paramiko/paramiko/sftp_server.pyi +++ b/stubs/paramiko/paramiko/sftp_server.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from logging import Logger from typing import Any @@ -25,4 +26,4 @@ class SFTPServer(BaseSFTP, SubsystemHandler): @staticmethod def convert_errno(e: int) -> int: ... @staticmethod - def set_file_attr(filename: str, attr: SFTPAttributes) -> None: ... + def set_file_attr(filename: FileDescriptorOrPath, attr: SFTPAttributes) -> None: ... diff --git a/stubs/paramiko/paramiko/transport.pyi b/stubs/paramiko/paramiko/transport.pyi index 25e68fdfc..0186b6489 100644 --- a/stubs/paramiko/paramiko/transport.pyi +++ b/stubs/paramiko/paramiko/transport.pyi @@ -1,3 +1,4 @@ +from _typeshed import FileDescriptorOrPath from collections.abc import Callable, Iterable, Mapping, Sequence from logging import Logger from socket import socket @@ -105,7 +106,7 @@ class Transport(Thread, ClosingContextManager): def add_server_key(self, key: PKey) -> None: ... def get_server_key(self) -> PKey | None: ... @staticmethod - def load_server_moduli(filename: str | None = None) -> bool: ... + def load_server_moduli(filename: FileDescriptorOrPath | None = None) -> bool: ... def close(self) -> None: ... def get_remote_server_key(self) -> PKey: ... def is_active(self) -> bool: ... diff --git a/stubs/paramiko/paramiko/util.pyi b/stubs/paramiko/paramiko/util.pyi index f7388e665..f45123625 100644 --- a/stubs/paramiko/paramiko/util.pyi +++ b/stubs/paramiko/paramiko/util.pyi @@ -1,4 +1,4 @@ -from _typeshed import ReadableBuffer +from _typeshed import FileDescriptorOrPath, ReadableBuffer from collections.abc import Iterable from hashlib import _Hash from logging import Logger, LogRecord @@ -20,12 +20,12 @@ def safe_string(s: Iterable[int | str]) -> bytes: ... def bit_length(n: int) -> int: ... def tb_strings() -> list[str]: ... def generate_key_bytes(hash_alg: type[_Hash], salt: ReadableBuffer, key: bytes | str, nbytes: int) -> bytes: ... -def load_host_keys(filename: str) -> HostKeys: ... +def load_host_keys(filename: FileDescriptorOrPath) -> HostKeys: ... def parse_ssh_config(file_obj: IO[str]) -> SSHConfig: ... def lookup_ssh_host_config(hostname: str, config: SSHConfig) -> SSHConfigDict: ... def mod_inverse(x: int, m: int) -> int: ... def get_thread_id() -> int: ... -def log_to_file(filename: str, level: int = 10) -> None: ... +def log_to_file(filename: FileDescriptorOrPath, level: int = 10) -> None: ... class PFilter: def filter(self, record: LogRecord) -> bool: ...