1
- # Stubs for ftplib (Python 2.7/3)
2
1
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
+ )
4
20
from types import TracebackType
5
21
from socket import socket
6
22
from ssl import SSLContext
7
23
8
- _T = TypeVar ('_T' )
24
+ _T = TypeVar ("_T" )
9
25
_IntOrStr = Union [int , Text ]
10
26
11
27
MSG_OOB : int
@@ -23,6 +39,12 @@ class error_proto(Error): ...
23
39
24
40
all_errors = Tuple [Exception , ...]
25
41
42
+ class _Readable (Protocol ):
43
+ def read (self , __length : int ) -> bytes : ...
44
+
45
+ class _ReadLineable (Protocol ):
46
+ def readline (self , _length : int ) -> bytes : ...
47
+
26
48
class FTP :
27
49
debugging : int
28
50
@@ -43,22 +65,31 @@ class FTP:
43
65
file : Optional [TextIO ]
44
66
encoding : str
45
67
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 : ...
48
71
else :
49
72
file : Optional [BinaryIO ]
50
73
51
74
if sys .version_info >= (3 , 3 ):
52
75
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 : ...
57
88
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 : ...
60
92
def connect (self , host : Text = ..., port : int = ..., timeout : float = ...) -> str : ...
61
-
62
93
def getwelcome (self ) -> str : ...
63
94
def set_debuglevel (self , level : int ) -> None : ...
64
95
def debug (self , level : int ) -> None : ...
@@ -78,22 +109,26 @@ class FTP:
78
109
def makeport (self ) -> socket : ...
79
110
def makepasv (self ) -> Tuple [str , int ]: ...
80
111
def login (self , user : Text = ..., passwd : Text = ..., acct : Text = ...) -> str : ...
81
-
82
112
# In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers.
83
113
def ntransfercmd (self , cmd : Text , rest : Optional [_IntOrStr ] = ...) -> Tuple [socket , int ]: ...
84
114
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 : ...
88
126
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 : ...
91
128
def acct (self , password : Text ) -> str : ...
92
129
def nlst (self , * args : Text ) -> List [str ]: ...
93
-
94
130
# Technically only the last arg can be a Callable but ...
95
131
def dir (self , * args : Union [str , Callable [[str ], None ]]) -> None : ...
96
-
97
132
if sys .version_info >= (3 , 3 ):
98
133
def mlsd (self , path : Text = ..., facts : Iterable [str ] = ...) -> Iterator [Tuple [str , Dict [str , str ]]]: ...
99
134
def rename (self , fromname : Text , toname : Text ) -> str : ...
@@ -107,21 +142,26 @@ class FTP:
107
142
def close (self ) -> None : ...
108
143
109
144
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 : ...
115
157
ssl_version : int
116
158
keyfile : Optional [str ]
117
159
certfile : Optional [str ]
118
160
context : SSLContext
119
-
120
161
def login (self , user : Text = ..., passwd : Text = ..., acct : Text = ..., secure : bool = ...) -> str : ...
121
162
def auth (self ) -> str : ...
122
163
def prot_p (self ) -> str : ...
123
164
def prot_c (self ) -> str : ...
124
-
125
165
if sys .version_info >= (3 , 3 ):
126
166
def ccc (self ) -> str : ...
127
167
0 commit comments