[paramiko] Add missing stubs (#14363)

This commit is contained in:
Semyon Moroz
2025-07-07 11:11:31 +00:00
committed by GitHub
parent 3370aa6cf6
commit ef966a1251
18 changed files with 250 additions and 123 deletions
@@ -1,3 +1 @@
paramiko.SFTPServer.__init__
paramiko.sftp_server.SFTPServer.__init__
paramiko.util.SupportsClose
@@ -1,2 +1,3 @@
paramiko._winapi
paramiko.win_openssh.*
paramiko.win_pageant
@@ -1,2 +1,3 @@
paramiko._winapi
paramiko.win_openssh.*
paramiko.win_pageant
-2
View File
@@ -2,9 +2,7 @@ version = "3.5.*"
upstream_repository = "https://github.com/paramiko/paramiko"
# Requires a version of cryptography where cryptography.hazmat.primitives.ciphers.Cipher is generic
requires = ["cryptography>=37.0.0"]
partial_stub = true
[tool.stubtest]
ignore_missing_stub = true
# linux and darwin are equivalent
platforms = ["linux", "win32"]
+45 -3
View File
@@ -1,3 +1,4 @@
from paramiko import util as util
from paramiko.agent import Agent as Agent, AgentKey as AgentKey
from paramiko.channel import Channel as Channel, ChannelFile as ChannelFile
from paramiko.client import (
@@ -41,6 +42,47 @@ from paramiko.transport import SecurityOptions as SecurityOptions, Transport as
__author__: str
__license__: str
# Names in __all__ with no definition:
# util
__all__ = [
"Agent",
"AgentKey",
"AuthenticationException",
"AutoAddPolicy",
"BadAuthenticationType",
"BadHostKeyException",
"BufferedFile",
"Channel",
"ChannelException",
"ConfigParseError",
"CouldNotCanonicalize",
"DSSKey",
"ECDSAKey",
"Ed25519Key",
"HostKeys",
"Message",
"MissingHostKeyPolicy",
"PKey",
"PasswordRequiredException",
"ProxyCommand",
"ProxyCommandFailure",
"RSAKey",
"RejectPolicy",
"SFTP",
"SFTPAttributes",
"SFTPClient",
"SFTPError",
"SFTPFile",
"SFTPHandle",
"SFTPServer",
"SFTPServerInterface",
"SSHClient",
"SSHConfig",
"SSHConfigDict",
"SSHException",
"SecurityOptions",
"ServerInterface",
"SubsystemHandler",
"Transport",
"WarningPolicy",
"io_sleep",
"util",
]
+25 -16
View File
@@ -3,7 +3,6 @@ import ctypes
import sys
from _typeshed import Incomplete
from types import TracebackType
from typing import Any
from typing_extensions import Self
if sys.platform == "win32":
@@ -18,14 +17,14 @@ if sys.platform == "win32":
def handle_nonzero_success(result: int) -> None: ...
GMEM_MOVEABLE: int
GlobalAlloc: Any
GlobalLock: Any
GlobalUnlock: Any
GlobalSize: Any
CreateFileMapping: Any
MapViewOfFile: Any
UnmapViewOfFile: Any
RtlMoveMemory: Any
GlobalAlloc: Incomplete
GlobalLock: Incomplete
GlobalUnlock: Incomplete
GlobalSize: Incomplete
CreateFileMapping: Incomplete
MapViewOfFile: Incomplete
UnmapViewOfFile: Incomplete
RtlMoveMemory: Incomplete
class MemoryMap:
name: str
@@ -75,21 +74,31 @@ if sys.platform == "win32":
class TOKEN_USER(ctypes.Structure):
num: int
SID: Incomplete
ATTRIBUTES: Incomplete
class SECURITY_DESCRIPTOR(ctypes.Structure):
SECURITY_DESCRIPTOR_CONTROL: Any
SECURITY_DESCRIPTOR_CONTROL: Incomplete
REVISION: int
Revision: int
Sbz1: Incomplete
Control: Incomplete
Owner: Incomplete
Group: Incomplete
Sacl: Incomplete
Dacl: Incomplete
class SECURITY_ATTRIBUTES(ctypes.Structure):
nLength: int
lpSecurityDescriptor: Any
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
lpSecurityDescriptor: int
bInheritHandle: bool
def __init__(self, *args, **kwargs) -> None: ...
@property
def descriptor(self) -> Any: ...
def descriptor(self): ...
@descriptor.setter
def descriptor(self, value: Any) -> None: ...
def descriptor(self, value) -> None: ...
def GetTokenInformation(token: Any, information_class: Any) -> Any: ...
def OpenProcessToken(proc_handle: Any, access: Any) -> Any: ...
def GetTokenInformation(token, information_class): ...
def OpenProcessToken(proc_handle, access): ...
def get_current_user() -> TOKEN_USER: ...
def get_security_attributes_for_user(user: TOKEN_USER | None = None) -> SECURITY_ATTRIBUTES: ...
+33 -5
View File
@@ -1,7 +1,10 @@
import sys
from _typeshed import ReadableBuffer
from collections.abc import Mapping
from logging import _ExcInfoType
from socket import _RetAddress, socket
from threading import Thread
from typing import Protocol
from typing import Final, Protocol
from paramiko.channel import Channel
from paramiko.message import Message, _LikeBytes
@@ -12,10 +15,16 @@ class _AgentProxy(Protocol):
def connect(self) -> None: ...
def close(self) -> None: ...
cSSH2_AGENTC_REQUEST_IDENTITIES: bytes
SSH2_AGENT_IDENTITIES_ANSWER: int
cSSH2_AGENTC_SIGN_REQUEST: bytes
SSH2_AGENT_SIGN_RESPONSE: int
cSSH2_AGENTC_REQUEST_IDENTITIES: Final[bytes]
SSH2_AGENT_IDENTITIES_ANSWER: Final = 12
cSSH2_AGENTC_SIGN_REQUEST: Final[bytes]
SSH2_AGENT_SIGN_RESPONSE: Final = 14
SSH_AGENT_RSA_SHA2_256: Final = 2
SSH_AGENT_RSA_SHA2_512: Final = 4
ALGORITHM_FLAG_MAP: Final[dict[str, int]]
key: str
value: int
class AgentSSH:
def __init__(self) -> None: ...
@@ -33,6 +42,15 @@ class AgentRemoteProxy(AgentProxyThread):
def __init__(self, agent: AgentClientProxy, chan: Channel) -> None: ...
def get_connection(self) -> tuple[socket, _RetAddress]: ...
if sys.platform == "win32":
from .win_openssh import OpenSSHAgentConnection
from .win_pageant import PageantConnection
def get_agent_connection() -> PageantConnection | OpenSSHAgentConnection | None: ...
else:
def get_agent_connection() -> socket | None: ...
class AgentClientProxy:
thread: Thread
def __init__(self, chanRemote: Channel) -> None: ...
@@ -64,6 +82,16 @@ class AgentKey(PKey):
name: str
comment: str
def __init__(self, agent: AgentSSH, blob: ReadableBuffer, comment: str = "") -> None: ...
def log(
self,
level: int,
msg: object,
*args: object,
exc_info: _ExcInfoType = None,
stack_info: bool = False,
stacklevel: int = 1,
extra: Mapping[str, object] | None = None,
) -> None: ...
def asbytes(self) -> bytes: ...
def get_name(self) -> str: ...
def sign_ssh_data(self, data: _LikeBytes, algorithm: str | None = None) -> Message: ...
+10
View File
@@ -2,6 +2,7 @@ from collections.abc import Callable
from threading import Event
from typing_extensions import TypeAlias
from paramiko.message import Message
from paramiko.pkey import PKey
from paramiko.ssh_gss import _SSH_GSSAuth
from paramiko.transport import Transport
@@ -46,3 +47,12 @@ class GssapiWithMicAuthHandler:
def auth_username(self) -> str: ...
@property
def gss_host(self) -> str: ...
class AuthOnlyHandler(AuthHandler):
def send_auth_request(
self, username: str, method: str, finish_message: Callable[[Message], None] | None = None
) -> list[str]: ...
def auth_none(self, username: str) -> list[str]: ... # type: ignore[override]
def auth_publickey(self, username: str, key: PKey) -> list[str]: ... # type: ignore[override]
def auth_password(self, username: str, password: str) -> list[str]: ... # type: ignore[override]
def auth_interactive(self, username: str, handler: _InteractiveCallback, submethods: str = "") -> list[str]: ... # type: ignore[override]
+97 -92
View File
@@ -1,97 +1,102 @@
import logging
from typing import Final
def byte_ord(c: int | str) -> int: ...
def byte_chr(c: int) -> bytes: ...
def byte_mask(c: int, mask: int) -> bytes: ...
MSG_DISCONNECT: int
MSG_IGNORE: int
MSG_UNIMPLEMENTED: int
MSG_DEBUG: int
MSG_SERVICE_REQUEST: int
MSG_SERVICE_ACCEPT: int
MSG_KEXINIT: int
MSG_NEWKEYS: int
MSG_USERAUTH_REQUEST: int
MSG_USERAUTH_FAILURE: int
MSG_USERAUTH_SUCCESS: int
MSG_USERAUTH_BANNER: int
MSG_USERAUTH_PK_OK: int
MSG_USERAUTH_INFO_REQUEST: int
MSG_USERAUTH_INFO_RESPONSE: int
MSG_USERAUTH_GSSAPI_RESPONSE: int
MSG_USERAUTH_GSSAPI_TOKEN: int
MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE: int
MSG_USERAUTH_GSSAPI_ERROR: int
MSG_USERAUTH_GSSAPI_ERRTOK: int
MSG_USERAUTH_GSSAPI_MIC: int
HIGHEST_USERAUTH_MESSAGE_ID: int
MSG_GLOBAL_REQUEST: int
MSG_REQUEST_SUCCESS: int
MSG_REQUEST_FAILURE: int
MSG_CHANNEL_OPEN: int
MSG_CHANNEL_OPEN_SUCCESS: int
MSG_CHANNEL_OPEN_FAILURE: int
MSG_CHANNEL_WINDOW_ADJUST: int
MSG_CHANNEL_DATA: int
MSG_CHANNEL_EXTENDED_DATA: int
MSG_CHANNEL_EOF: int
MSG_CHANNEL_CLOSE: int
MSG_CHANNEL_REQUEST: int
MSG_CHANNEL_SUCCESS: int
MSG_CHANNEL_FAILURE: int
MSG_DISCONNECT: Final = 1
MSG_IGNORE: Final = 2
MSG_UNIMPLEMENTED: Final = 3
MSG_DEBUG: Final = 4
MSG_SERVICE_REQUEST: Final = 5
MSG_SERVICE_ACCEPT: Final = 6
MSG_EXT_INFO: Final = 7
MSG_KEXINIT: Final = 20
MSG_NEWKEYS: Final = 21
MSG_USERAUTH_REQUEST: Final = 50
MSG_USERAUTH_FAILURE: Final = 51
MSG_USERAUTH_SUCCESS: Final = 52
MSG_USERAUTH_BANNER: Final = 53
MSG_USERAUTH_PK_OK: Final = 60
MSG_USERAUTH_INFO_REQUEST: Final = 60
MSG_USERAUTH_INFO_RESPONSE: Final = 61
MSG_USERAUTH_GSSAPI_RESPONSE: Final = 60
MSG_USERAUTH_GSSAPI_TOKEN: Final = 61
MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE: Final = 63
MSG_USERAUTH_GSSAPI_ERROR: Final = 64
MSG_USERAUTH_GSSAPI_ERRTOK: Final = 65
MSG_USERAUTH_GSSAPI_MIC: Final = 66
HIGHEST_USERAUTH_MESSAGE_ID: Final = 79
MSG_GLOBAL_REQUEST: Final = 80
MSG_REQUEST_SUCCESS: Final = 81
MSG_REQUEST_FAILURE: Final = 82
MSG_CHANNEL_OPEN: Final = 90
MSG_CHANNEL_OPEN_SUCCESS: Final = 91
MSG_CHANNEL_OPEN_FAILURE: Final = 92
MSG_CHANNEL_WINDOW_ADJUST: Final = 93
MSG_CHANNEL_DATA: Final = 94
MSG_CHANNEL_EXTENDED_DATA: Final = 95
MSG_CHANNEL_EOF: Final = 96
MSG_CHANNEL_CLOSE: Final = 97
MSG_CHANNEL_REQUEST: Final = 98
MSG_CHANNEL_SUCCESS: Final = 99
MSG_CHANNEL_FAILURE: Final = 100
cMSG_DISCONNECT: bytes
cMSG_IGNORE: bytes
cMSG_UNIMPLEMENTED: bytes
cMSG_DEBUG: bytes
cMSG_SERVICE_REQUEST: bytes
cMSG_SERVICE_ACCEPT: bytes
cMSG_KEXINIT: bytes
cMSG_NEWKEYS: bytes
cMSG_USERAUTH_REQUEST: bytes
cMSG_USERAUTH_FAILURE: bytes
cMSG_USERAUTH_SUCCESS: bytes
cMSG_USERAUTH_BANNER: bytes
cMSG_USERAUTH_PK_OK: bytes
cMSG_USERAUTH_INFO_REQUEST: bytes
cMSG_USERAUTH_INFO_RESPONSE: bytes
cMSG_USERAUTH_GSSAPI_RESPONSE: bytes
cMSG_USERAUTH_GSSAPI_TOKEN: bytes
cMSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE: bytes
cMSG_USERAUTH_GSSAPI_ERROR: bytes
cMSG_USERAUTH_GSSAPI_ERRTOK: bytes
cMSG_USERAUTH_GSSAPI_MIC: bytes
cMSG_GLOBAL_REQUEST: bytes
cMSG_REQUEST_SUCCESS: bytes
cMSG_REQUEST_FAILURE: bytes
cMSG_CHANNEL_OPEN: bytes
cMSG_CHANNEL_OPEN_SUCCESS: bytes
cMSG_CHANNEL_OPEN_FAILURE: bytes
cMSG_CHANNEL_WINDOW_ADJUST: bytes
cMSG_CHANNEL_DATA: bytes
cMSG_CHANNEL_EXTENDED_DATA: bytes
cMSG_CHANNEL_EOF: bytes
cMSG_CHANNEL_CLOSE: bytes
cMSG_CHANNEL_REQUEST: bytes
cMSG_CHANNEL_SUCCESS: bytes
cMSG_CHANNEL_FAILURE: bytes
cMSG_DISCONNECT: Final[bytes]
cMSG_IGNORE: Final[bytes]
cMSG_UNIMPLEMENTED: Final[bytes]
cMSG_DEBUG: Final[bytes]
cMSG_SERVICE_REQUEST: Final[bytes]
cMSG_SERVICE_ACCEPT: Final[bytes]
cMSG_EXT_INFO: Final[bytes]
cMSG_KEXINIT: Final[bytes]
cMSG_NEWKEYS: Final[bytes]
cMSG_USERAUTH_REQUEST: Final[bytes]
cMSG_USERAUTH_FAILURE: Final[bytes]
cMSG_USERAUTH_SUCCESS: Final[bytes]
cMSG_USERAUTH_BANNER: Final[bytes]
cMSG_USERAUTH_PK_OK: Final[bytes]
cMSG_USERAUTH_INFO_REQUEST: Final[bytes]
cMSG_USERAUTH_INFO_RESPONSE: Final[bytes]
cMSG_USERAUTH_GSSAPI_RESPONSE: Final[bytes]
cMSG_USERAUTH_GSSAPI_TOKEN: Final[bytes]
cMSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE: Final[bytes]
cMSG_USERAUTH_GSSAPI_ERROR: Final[bytes]
cMSG_USERAUTH_GSSAPI_ERRTOK: Final[bytes]
cMSG_USERAUTH_GSSAPI_MIC: Final[bytes]
cMSG_GLOBAL_REQUEST: Final[bytes]
cMSG_REQUEST_SUCCESS: Final[bytes]
cMSG_REQUEST_FAILURE: Final[bytes]
cMSG_CHANNEL_OPEN: Final[bytes]
cMSG_CHANNEL_OPEN_SUCCESS: Final[bytes]
cMSG_CHANNEL_OPEN_FAILURE: Final[bytes]
cMSG_CHANNEL_WINDOW_ADJUST: Final[bytes]
cMSG_CHANNEL_DATA: Final[bytes]
cMSG_CHANNEL_EXTENDED_DATA: Final[bytes]
cMSG_CHANNEL_EOF: Final[bytes]
cMSG_CHANNEL_CLOSE: Final[bytes]
cMSG_CHANNEL_REQUEST: Final[bytes]
cMSG_CHANNEL_SUCCESS: Final[bytes]
cMSG_CHANNEL_FAILURE: Final[bytes]
MSG_NAMES: dict[int, str]
AUTH_SUCCESSFUL: int
AUTH_PARTIALLY_SUCCESSFUL: int
AUTH_FAILED: int
AUTH_SUCCESSFUL: Final = 0
AUTH_PARTIALLY_SUCCESSFUL: Final = 1
AUTH_FAILED: Final = 2
OPEN_SUCCEEDED: int
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED: int
OPEN_FAILED_CONNECT_FAILED: int
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE: int
OPEN_FAILED_RESOURCE_SHORTAGE: int
OPEN_SUCCEEDED: Final = 0
OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED: Final = 1
OPEN_FAILED_CONNECT_FAILED: Final = 2
OPEN_FAILED_UNKNOWN_CHANNEL_TYPE: Final = 3
OPEN_FAILED_RESOURCE_SHORTAGE: Final = 4
CONNECTION_FAILED_CODE: dict[int, str]
DISCONNECT_SERVICE_NOT_AVAILABLE: int
DISCONNECT_AUTH_CANCELLED_BY_USER: int
DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE: int
DISCONNECT_SERVICE_NOT_AVAILABLE: Final = 7
DISCONNECT_AUTH_CANCELLED_BY_USER: Final = 13
DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE: Final = 14
zero_byte: bytes
one_byte: bytes
@@ -112,17 +117,17 @@ o777: int
o700: int
o70: int
DEBUG: int
INFO: int
WARNING: int
ERROR: int
CRITICAL: int
DEBUG = logging.DEBUG
INFO = logging.INFO
WARNING = logging.WARNING
ERROR = logging.ERROR
CRITICAL = logging.CRITICAL
io_sleep: float
DEFAULT_WINDOW_SIZE: int
DEFAULT_MAX_PACKET_SIZE: int
DEFAULT_WINDOW_SIZE: Final[int]
DEFAULT_MAX_PACKET_SIZE: Final[int]
MIN_WINDOW_SIZE: int
MIN_PACKET_SIZE: int
MAX_WINDOW_SIZE: int
MIN_WINDOW_SIZE: Final[int]
MIN_PACKET_SIZE: Final[int]
MAX_WINDOW_SIZE: Final[int]
+1
View File
@@ -6,6 +6,7 @@ from typing_extensions import Self
from paramiko.ssh_exception import ConfigParseError as ConfigParseError, CouldNotCanonicalize as CouldNotCanonicalize
invoke_import_error: ImportError | None
SSH_PORT: int
class SSHConfig:
+2
View File
@@ -23,6 +23,8 @@ class Packetizer:
def __init__(self, socket: socket) -> None: ...
@property
def closed(self) -> bool: ...
def reset_seqno_out(self) -> None: ...
def reset_seqno_in(self) -> None: ...
def set_log(self, log: Logger) -> None: ...
def set_outbound_cipher(
self,
+7
View File
@@ -12,7 +12,14 @@ _BytesT = TypeVar("_BytesT", bound=bytes | bytearray)
def _unpad_openssh(data: _BytesT) -> _BytesT: ...
class UnknownKeyType(Exception):
key_type: str | type | None
key_bytes: bytes | None
def __init__(self, key_type: str | type | None = None, key_bytes: bytes | None = None) -> None: ...
class PKey:
name: str
HASHES: dict[str, type]
public_blob: PublicBlob | None
BEGIN_TAG: Pattern[str]
END_TAG: Pattern[str]
+2
View File
@@ -4,6 +4,8 @@ from typing import Any
from paramiko.util import ClosingContextManager
subprocess_import_error: ImportError | None
class ProxyCommand(ClosingContextManager):
cmd: list[str]
process: Popen[Any]
+1
View File
@@ -51,6 +51,7 @@ SFTP_FLAG_EXCL: int
CMD_NAMES: dict[int, str]
class int64(int): ...
class SFTPError(Exception): ...
class BaseSFTP:
+7 -1
View File
@@ -19,7 +19,13 @@ class SFTPServer(BaseSFTP, SubsystemHandler):
server: SFTPServerInterface
sock: Channel | None
def __init__(
self, channel: Channel, name: str, server: ServerInterface, sftp_si: type[SFTPServerInterface], *largs: Any, **kwargs: Any
self,
channel: Channel,
name: str,
server: ServerInterface,
sftp_si: type[SFTPServerInterface] = ...,
*args: Any,
**kwargs: Any,
) -> None: ...
def start_subsystem(self, name: str, transport: Transport, channel: Channel) -> None: ...
def finish_subsystem(self) -> None: ...
@@ -16,6 +16,8 @@ class PartialAuthentication(AuthenticationException):
allowed_types: list[str]
def __init__(self, types: list[str]) -> None: ...
class UnableToAuthenticate(AuthenticationException): ...
class ChannelException(SSHException):
code: int
text: str
@@ -27,6 +29,8 @@ class BadHostKeyException(SSHException):
expected_key: PKey
def __init__(self, hostname: str, got_key: PKey, expected_key: PKey) -> None: ...
class IncompatiblePeer(SSHException): ...
class ProxyCommandFailure(SSHException):
command: str
error: str
+9 -1
View File
@@ -7,7 +7,7 @@ from types import ModuleType
from typing import Any, Protocol
from typing_extensions import TypeAlias
from paramiko.auth_handler import AuthHandler, _InteractiveCallback
from paramiko.auth_handler import AuthHandler, AuthOnlyHandler, _InteractiveCallback
from paramiko.channel import Channel
from paramiko.message import Message
from paramiko.packet import Packetizer
@@ -96,6 +96,8 @@ class Transport(Thread, ClosingContextManager):
@property
def preferred_keys(self) -> Sequence[str]: ...
@property
def preferred_pubkeys(self) -> Sequence[str]: ...
@property
def preferred_kex(self) -> Sequence[str]: ...
@property
def preferred_compression(self) -> Sequence[str]: ...
@@ -201,3 +203,9 @@ class ChannelMap:
def delete(self, chanid: int) -> None: ...
def values(self) -> list[Channel]: ...
def __len__(self) -> int: ...
class ServiceRequestingTransport(Transport):
def ensure_session(self) -> None: ...
def get_auth_handler(self) -> AuthOnlyHandler: ...
def auth_password(self, username: str, password: str, fallback: bool = True) -> list[str]: ... # type: ignore[override]
def auth_publickey(self, username: str, key: PKey) -> list[str]: ... # type: ignore[override]
+5 -1
View File
@@ -1,5 +1,6 @@
import ctypes
import sys
from _typeshed import Incomplete
from typing import Literal
from typing_extensions import TypeAlias
@@ -9,7 +10,10 @@ if sys.platform == "win32":
ULONG_PTR: TypeAlias = ctypes.c_uint64 | ctypes.c_uint32
class COPYDATASTRUCT(ctypes.Structure): ...
class COPYDATASTRUCT(ctypes.Structure):
num_data: Incomplete
data_size: Incomplete
data_loc: Incomplete
class PageantConnection:
def __init__(self) -> None: ...