1
1
import io
2
2
import sys
3
- from typing import Any , IO , Mapping , Optional , Sequence , Union
3
+ from os .path import _PathType
4
+ from typing import IO , Any , Mapping , Optional , Sequence , TextIO , Union , overload
4
5
5
- if sys .version_info >= (3 , 6 ):
6
- from os import PathLike
7
- _PathOrFile = Union [str , bytes , IO [Any ], PathLike [Any ]]
6
+ if sys .version_info >= (3 , 8 ):
7
+ from typing import Literal
8
8
else :
9
- _PathOrFile = Union [str , bytes , IO [Any ]]
9
+ from typing_extensions import Literal
10
+
11
+ if sys .version_info >= (3 , 4 ):
12
+ # Changed in version 3.4: Added support for the "x", "xb" and "xt" modes.
13
+ _OPEN_BINARY_WRITING_MODE = Literal ["w" , "wb" , "x" , "xb" , "a" , "ab" ]
14
+ _OPEN_TEXT_WRITING_MODE = Literal ["wt" , "xt" , "at" ]
15
+ else :
16
+ _OPEN_BINARY_WRITING_MODE = Literal ["w" , "wb" , "a" , "ab" ]
17
+ _OPEN_TEXT_WRITING_MODE = Literal ["wt" , "at" ]
18
+
19
+ _PathOrFile = Union [_PathType , IO [bytes ]]
10
20
11
21
_FilterChain = Sequence [Mapping [str , Any ]]
12
22
@@ -41,7 +51,9 @@ PRESET_EXTREME: int
41
51
42
52
# from _lzma.c
43
53
class LZMADecompressor (object ):
44
- def __init__ (self , format : Optional [int ] = ..., memlimit : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...) -> None : ...
54
+ def __init__ (
55
+ self , format : Optional [int ] = ..., memlimit : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...
56
+ ) -> None : ...
45
57
def decompress (self , data : bytes , max_length : int = ...) -> bytes : ...
46
58
@property
47
59
def check (self ) -> int : ...
@@ -54,27 +66,25 @@ class LZMADecompressor(object):
54
66
55
67
# from _lzma.c
56
68
class LZMACompressor (object ):
57
- def __init__ (self ,
58
- format : Optional [int ] = ...,
59
- check : int = ...,
60
- preset : Optional [int ] = ...,
61
- filters : Optional [_FilterChain ] = ...) -> None : ...
69
+ def __init__ (
70
+ self , format : Optional [int ] = ..., check : int = ..., preset : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...
71
+ ) -> None : ...
62
72
def compress (self , data : bytes ) -> bytes : ...
63
73
def flush (self ) -> bytes : ...
64
74
65
-
66
75
class LZMAError (Exception ): ...
67
76
68
-
69
77
class LZMAFile (io .BufferedIOBase , IO [bytes ]): # type: ignore # python/mypy#5027
70
- def __init__ (self ,
71
- filename : Optional [_PathOrFile ] = ...,
72
- mode : str = ...,
73
- * ,
74
- format : Optional [int ] = ...,
75
- check : int = ...,
76
- preset : Optional [int ] = ...,
77
- filters : Optional [_FilterChain ] = ...) -> None : ...
78
+ def __init__ (
79
+ self ,
80
+ filename : Optional [_PathOrFile ] = ...,
81
+ mode : str = ...,
82
+ * ,
83
+ format : Optional [int ] = ...,
84
+ check : int = ...,
85
+ preset : Optional [int ] = ...,
86
+ filters : Optional [_FilterChain ] = ...,
87
+ ) -> None : ...
78
88
def close (self ) -> None : ...
79
89
@property
80
90
def closed (self ) -> bool : ...
@@ -90,17 +100,73 @@ class LZMAFile(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#502
90
100
def seek (self , offset : int , whence : int = ...) -> int : ...
91
101
def tell (self ) -> int : ...
92
102
93
-
94
- def open (filename : _PathOrFile ,
95
- mode : str = ...,
96
- * ,
97
- format : Optional [int ] = ...,
98
- check : int = ...,
99
- preset : Optional [int ] = ...,
100
- filters : Optional [_FilterChain ] = ...,
101
- encoding : Optional [str ] = ...,
102
- errors : Optional [str ] = ...,
103
- newline : Optional [str ] = ...) -> IO [Any ]: ...
104
- def compress (data : bytes , format : int = ..., check : int = ..., preset : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...) -> bytes : ...
103
+ @overload
104
+ def open (
105
+ filename : _PathOrFile ,
106
+ mode : Literal ["r" , "rb" ] = ...,
107
+ * ,
108
+ format : Optional [int ] = ...,
109
+ check : Literal [- 1 ] = ...,
110
+ preset : None = ...,
111
+ filters : Optional [_FilterChain ] = ...,
112
+ encoding : None = ...,
113
+ errors : None = ...,
114
+ newline : None = ...,
115
+ ) -> LZMAFile : ...
116
+ @overload
117
+ def open (
118
+ filename : _PathOrFile ,
119
+ mode : _OPEN_BINARY_WRITING_MODE ,
120
+ * ,
121
+ format : Optional [int ] = ...,
122
+ check : int = ...,
123
+ preset : Optional [int ] = ...,
124
+ filters : Optional [_FilterChain ] = ...,
125
+ encoding : None = ...,
126
+ errors : None = ...,
127
+ newline : None = ...,
128
+ ) -> LZMAFile : ...
129
+ @overload
130
+ def open (
131
+ filename : _PathType ,
132
+ mode : Literal ["rt" ],
133
+ * ,
134
+ format : Optional [int ] = ...,
135
+ check : Literal [- 1 ] = ...,
136
+ preset : None = ...,
137
+ filters : Optional [_FilterChain ] = ...,
138
+ encoding : Optional [str ] = ...,
139
+ errors : Optional [str ] = ...,
140
+ newline : Optional [str ] = ...,
141
+ ) -> TextIO : ...
142
+ @overload
143
+ def open (
144
+ filename : _PathType ,
145
+ mode : _OPEN_TEXT_WRITING_MODE ,
146
+ * ,
147
+ format : Optional [int ] = ...,
148
+ check : int = ...,
149
+ preset : Optional [int ] = ...,
150
+ filters : Optional [_FilterChain ] = ...,
151
+ encoding : Optional [str ] = ...,
152
+ errors : Optional [str ] = ...,
153
+ newline : Optional [str ] = ...,
154
+ ) -> TextIO : ...
155
+ @overload
156
+ def open (
157
+ filename : _PathOrFile ,
158
+ mode : str = ...,
159
+ * ,
160
+ format : Optional [int ] = ...,
161
+ check : int = ...,
162
+ preset : Optional [int ] = ...,
163
+ filters : Optional [_FilterChain ] = ...,
164
+ encoding : Optional [str ] = ...,
165
+ errors : Optional [str ] = ...,
166
+ newline : Optional [str ] = ...,
167
+ ) -> Union [LZMAFile , TextIO ]: ...
168
+ def compress (
169
+ data : bytes , format : int = ..., check : int = ..., preset : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...
170
+ ) -> bytes : ...
105
171
def decompress (data : bytes , format : int = ..., memlimit : Optional [int ] = ..., filters : Optional [_FilterChain ] = ...) -> bytes : ...
106
172
def is_check_supported (check : int ) -> bool : ...
0 commit comments