Skip to content

Commit c9f19b1

Browse files
srittauJelleZijlstra
authored andcommitted
Use protocol for FTP.stor* (#3227)
* Use protocol for FTP.stor* * Reformat ftplib.pyi with black
1 parent 668988f commit c9f19b1

File tree

1 file changed

+67
-27
lines changed

1 file changed

+67
-27
lines changed

stdlib/2and3/ftplib.pyi

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
# Stubs for ftplib (Python 2.7/3)
21
import sys
3-
from typing import Optional, BinaryIO, Tuple, TextIO, Iterable, Callable, List, Union, Iterator, Dict, Text, Type, TypeVar, Generic, Any
2+
from typing import (
3+
Any,
4+
BinaryIO,
5+
Callable,
6+
Dict,
7+
Generic,
8+
Iterable,
9+
Iterator,
10+
List,
11+
Optional,
12+
Protocol,
13+
Text,
14+
TextIO,
15+
Tuple,
16+
Type,
17+
TypeVar,
18+
Union,
19+
)
420
from types import TracebackType
521
from socket import socket
622
from ssl import SSLContext
723

8-
_T = TypeVar('_T')
24+
_T = TypeVar("_T")
925
_IntOrStr = Union[int, Text]
1026

1127
MSG_OOB: int
@@ -23,6 +39,12 @@ class error_proto(Error): ...
2339

2440
all_errors = Tuple[Exception, ...]
2541

42+
class _Readable(Protocol):
43+
def read(self, __length: int) -> bytes: ...
44+
45+
class _ReadLineable(Protocol):
46+
def readline(self, _length: int) -> bytes: ...
47+
2648
class FTP:
2749
debugging: int
2850

@@ -43,22 +65,31 @@ class FTP:
4365
file: Optional[TextIO]
4466
encoding: str
4567
def __enter__(self: _T) -> _T: ...
46-
def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException],
47-
exc_tb: Optional[TracebackType]) -> None: ...
68+
def __exit__(
69+
self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]
70+
) -> None: ...
4871
else:
4972
file: Optional[BinaryIO]
5073

5174
if sys.version_info >= (3, 3):
5275
source_address: Optional[Tuple[str, int]]
53-
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
54-
timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...) -> None: ...
55-
def connect(self, host: Text = ..., port: int = ..., timeout: float = ...,
56-
source_address: Optional[Tuple[str, int]] = ...) -> str: ...
76+
def __init__(
77+
self,
78+
host: Text = ...,
79+
user: Text = ...,
80+
passwd: Text = ...,
81+
acct: Text = ...,
82+
timeout: float = ...,
83+
source_address: Optional[Tuple[str, int]] = ...,
84+
) -> None: ...
85+
def connect(
86+
self, host: Text = ..., port: int = ..., timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...
87+
) -> str: ...
5788
else:
58-
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
59-
timeout: float = ...) -> None: ...
89+
def __init__(
90+
self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., timeout: float = ...
91+
) -> None: ...
6092
def connect(self, host: Text = ..., port: int = ..., timeout: float = ...) -> str: ...
61-
6293
def getwelcome(self) -> str: ...
6394
def set_debuglevel(self, level: int) -> None: ...
6495
def debug(self, level: int) -> None: ...
@@ -78,22 +109,26 @@ class FTP:
78109
def makeport(self) -> socket: ...
79110
def makepasv(self) -> Tuple[str, int]: ...
80111
def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ...) -> str: ...
81-
82112
# In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers.
83113
def ntransfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> Tuple[socket, int]: ...
84114
def transfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> socket: ...
85-
def retrbinary(self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...) -> str: ...
86-
def storbinary(self, cmd: Text, fp: BinaryIO, blocksize: int = ..., callback: Optional[Callable[[bytes], Any]] = ..., rest: Optional[_IntOrStr] = ...) -> str: ...
87-
115+
def retrbinary(
116+
self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...
117+
) -> str: ...
118+
def storbinary(
119+
self,
120+
cmd: Text,
121+
fp: _Readable,
122+
blocksize: int = ...,
123+
callback: Optional[Callable[[bytes], Any]] = ...,
124+
rest: Optional[_IntOrStr] = ...,
125+
) -> str: ...
88126
def retrlines(self, cmd: Text, callback: Optional[Callable[[str], Any]] = ...) -> str: ...
89-
def storlines(self, cmd: Text, fp: BinaryIO, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ...
90-
127+
def storlines(self, cmd: Text, fp: _ReadLineable, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ...
91128
def acct(self, password: Text) -> str: ...
92129
def nlst(self, *args: Text) -> List[str]: ...
93-
94130
# Technically only the last arg can be a Callable but ...
95131
def dir(self, *args: Union[str, Callable[[str], None]]) -> None: ...
96-
97132
if sys.version_info >= (3, 3):
98133
def mlsd(self, path: Text = ..., facts: Iterable[str] = ...) -> Iterator[Tuple[str, Dict[str, str]]]: ...
99134
def rename(self, fromname: Text, toname: Text) -> str: ...
@@ -107,21 +142,26 @@ class FTP:
107142
def close(self) -> None: ...
108143

109144
class FTP_TLS(FTP):
110-
def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ...,
111-
keyfile: Optional[str] = ..., certfile: Optional[str] = ...,
112-
context: Optional[SSLContext] = ..., timeout: float = ...,
113-
source_address: Optional[Tuple[str, int]] = ...) -> None: ...
114-
145+
def __init__(
146+
self,
147+
host: Text = ...,
148+
user: Text = ...,
149+
passwd: Text = ...,
150+
acct: Text = ...,
151+
keyfile: Optional[str] = ...,
152+
certfile: Optional[str] = ...,
153+
context: Optional[SSLContext] = ...,
154+
timeout: float = ...,
155+
source_address: Optional[Tuple[str, int]] = ...,
156+
) -> None: ...
115157
ssl_version: int
116158
keyfile: Optional[str]
117159
certfile: Optional[str]
118160
context: SSLContext
119-
120161
def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ..., secure: bool = ...) -> str: ...
121162
def auth(self) -> str: ...
122163
def prot_p(self) -> str: ...
123164
def prot_c(self) -> str: ...
124-
125165
if sys.version_info >= (3, 3):
126166
def ccc(self) -> str: ...
127167

0 commit comments

Comments
 (0)