Use protocol for FTP.stor* (#3227)

* Use protocol for FTP.stor*

* Reformat ftplib.pyi with black
This commit is contained in:
Sebastian Rittau
2019-09-10 23:40:10 +02:00
committed by Jelle Zijlstra
parent 668988fa8c
commit c9f19b1d72

View File

@@ -1,11 +1,27 @@
# Stubs for ftplib (Python 2.7/3)
import sys
from typing import Optional, BinaryIO, Tuple, TextIO, Iterable, Callable, List, Union, Iterator, Dict, Text, Type, TypeVar, Generic, Any
from typing import (
Any,
BinaryIO,
Callable,
Dict,
Generic,
Iterable,
Iterator,
List,
Optional,
Protocol,
Text,
TextIO,
Tuple,
Type,
TypeVar,
Union,
)
from types import TracebackType
from socket import socket
from ssl import SSLContext
_T = TypeVar('_T')
_T = TypeVar("_T")
_IntOrStr = Union[int, Text]
MSG_OOB: int
@@ -23,6 +39,12 @@ class error_proto(Error): ...
all_errors = Tuple[Exception, ...]
class _Readable(Protocol):
def read(self, __length: int) -> bytes: ...
class _ReadLineable(Protocol):
def readline(self, _length: int) -> bytes: ...
class FTP:
debugging: int
@@ -43,22 +65,31 @@ class FTP:
file: Optional[TextIO]
encoding: str
def __enter__(self: _T) -> _T: ...
def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType]) -> None: ...
def __exit__(
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
) -> None: ...
else:
file: Optional[BinaryIO]
if sys.version_info >= (3, 3):
source_address: Optional[Tuple[str, int]]
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...) -> None: ...
def connect(self, host: Text = ..., port: int = ..., timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...) -> str: ...
def __init__(
self,
host: Text = ...,
user: Text = ...,
passwd: Text = ...,
acct: Text = ...,
timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...,
) -> None: ...
def connect(
self, host: Text = ..., port: int = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...
) -> str: ...
else:
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
timeout: float = ...) -> None: ...
def __init__(
self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., timeout: float = ...
) -> None: ...
def connect(self, host: Text = ..., port: int = ..., timeout: float = ...) -> str: ...
def getwelcome(self) -> str: ...
def set_debuglevel(self, level: int) -> None: ...
def debug(self, level: int) -> None: ...
@@ -78,22 +109,26 @@ class FTP:
def makeport(self) -> socket: ...
def makepasv(self) -> Tuple[str, int]: ...
def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ...) -> str: ...
# In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers.
def ntransfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> Tuple[socket, int]: ...
def transfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> socket: ...
def retrbinary(self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...) -> str: ...
def storbinary(self, cmd: Text, fp: BinaryIO, blocksize: int = ..., callback: Optional[Callable[[bytes], Any]] = ..., rest: Optional[_IntOrStr] = ...) -> str: ...
def retrbinary(
self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...
) -> str: ...
def storbinary(
self,
cmd: Text,
fp: _Readable,
blocksize: int = ...,
callback: Optional[Callable[[bytes], Any]] = ...,
rest: Optional[_IntOrStr] = ...,
) -> str: ...
def retrlines(self, cmd: Text, callback: Optional[Callable[[str], Any]] = ...) -> str: ...
def storlines(self, cmd: Text, fp: BinaryIO, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ...
def storlines(self, cmd: Text, fp: _ReadLineable, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ...
def acct(self, password: Text) -> str: ...
def nlst(self, *args: Text) -> List[str]: ...
# Technically only the last arg can be a Callable but ...
def dir(self, *args: Union[str, Callable[[str], None]]) -> None: ...
if sys.version_info >= (3, 3):
def mlsd(self, path: Text = ..., facts: Iterable[str] = ...) -> Iterator[Tuple[str, Dict[str, str]]]: ...
def rename(self, fromname: Text, toname: Text) -> str: ...
@@ -107,21 +142,26 @@ class FTP:
def close(self) -> None: ...
class FTP_TLS(FTP):
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
keyfile: Optional[str] = ..., certfile: Optional[str] = ...,
context: Optional[SSLContext] = ..., timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...) -> None: ...
def __init__(
self,
host: Text = ...,
user: Text = ...,
passwd: Text = ...,
acct: Text = ...,
keyfile: Optional[str] = ...,
certfile: Optional[str] = ...,
context: Optional[SSLContext] = ...,
timeout: float = ...,
source_address: Optional[Tuple[str, int]] = ...,
) -> None: ...
ssl_version: int
keyfile: Optional[str]
certfile: Optional[str]
context: SSLContext
def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ..., secure: bool = ...) -> str: ...
def auth(self) -> str: ...
def prot_p(self) -> str: ...
def prot_c(self) -> str: ...
if sys.version_info >= (3, 3):
def ccc(self) -> str: ...