Skip to content

Commit 8ef221c

Browse files
tharvikmatthiaskramm
authored andcommitted
add zipfile for py2 (#345)
1 parent 932737d commit 8ef221c

File tree

3 files changed

+97
-29
lines changed

3 files changed

+97
-29
lines changed

stdlib/2and3/zipfile.pyi

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Stubs for zipfile
2+
3+
from typing import Callable, IO, Optional, Tuple, Type, Union
4+
from types import TracebackType
5+
import sys
6+
7+
8+
_SZI = Union[str, ZipInfo]
9+
_DT = Tuple[int, int, int, int, int, int]
10+
11+
12+
class BadZipFile(Exception): ...
13+
14+
if sys.version_info >= (3,):
15+
BadZipfile = BadZipFile
16+
17+
class LargeZipFile(Exception): ...
18+
19+
class ZipFile:
20+
debug = ... # type: int
21+
comment = ... # type: bytes
22+
def __init__(self, file: Union[str, IO[bytes]], mode: str = ..., compression: int = ...,
23+
allowZip64: bool = ...) -> None: ...
24+
def __enter__(self) -> ZipFile: ...
25+
def __exit__(self, exc_type: Optional[Type[BaseException]],
26+
exc_val: Optional[Exception],
27+
exc_tb: Optional[TracebackType]) -> bool: ...
28+
def close(self) -> None: ...
29+
def getinfo(self, name: str) -> None: ...
30+
def infolist(self) -> List[ZipInfo]: ...
31+
def namelist(self) -> List[str]: ...
32+
def open(self, name: _SZI, mode: str = ...,
33+
pwd: Optional[bytes] = ...) -> IO[bytes]: ...
34+
def extract(self, member: _SZI, path: Optional[_SZI] = ...,
35+
pwd: bytes = ...) -> str: ...
36+
def extractall(self, path: Optional[str] = ...,
37+
members: Optional[List[str]] = ...,
38+
pwd: Optional[bytes] = ...) -> None: ...
39+
def printdir(self) -> None: ...
40+
def setpassword(self, pwd: bytes) -> None: ...
41+
def read(self, name: _SZI, pwd: Optional[bytes] = ...) -> bytes: ...
42+
def testzip(self) -> Optional[str]: ...
43+
def write(self, filename: str, arcname: Optional[str] = ...,
44+
compress_type: Optional[int] = ...) -> None: ...
45+
if sys.version_info >= (3,):
46+
def writestr(self, zinfo_or_arcname: _SZI, data: Union[bytes, str],
47+
compress_type: Optional[int] = ...) -> None: ...
48+
else:
49+
def writestr(self, # type: ignore
50+
zinfo_or_arcname: _SZI, bytes: bytes,
51+
compress_type: Optional[int] = ...) -> None: ...
52+
53+
class PyZipFile(ZipFile):
54+
if sys.version_info >= (3,):
55+
def __init__(self, file: Union[str, IO[bytes]], mode: str = ...,
56+
compression: int = ..., allowZip64: bool = ...,
57+
opimize: int = ...) -> None: ...
58+
def writepy(self, pathname: str, basename: str = ...,
59+
filterfunc: Optional[Callable[[str], bool]] = ...) \
60+
-> None: ...
61+
else:
62+
def writepy(self, # type: ignore
63+
pathname: str, basename: str = ...) -> None: ...
64+
65+
class ZipInfo:
66+
filename = ... # type: str
67+
date_time = ... # type: _DT
68+
compress_type = ... # type: int
69+
comment = ... # type: bytes
70+
extra = ... # type: bytes
71+
create_system = ... # type: int
72+
create_version = ... # type: int
73+
extract_version = ... # type: int
74+
reserved = ... # type: int
75+
flag_bits = ... # type: int
76+
volume = ... # type: int
77+
internal_attr = ... # type: int
78+
external_attr = ... # type: int
79+
header_offset = ... # type: int
80+
CRC = ... # type: int
81+
compress_size = ... # type: int
82+
file_size = ... # type: int
83+
if sys.version_info < (3,):
84+
def __init__(self, filename: Optional[str] = ...,
85+
date_time: Optional[_DT] = ...) -> None: ...
86+
87+
88+
def is_zipfile(filename: Union[str, IO[bytes]]) -> bool: ...
89+
90+
ZIP_STORED = ... # type: int
91+
ZIP_DEFLATED = ... # type: int
92+
if sys.version_info >= (3, 3):
93+
ZIP_BZIP2 = ... # type: int
94+
ZIP_LZMA = ... # type: int

stdlib/3/zipfile.pyi

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/pytype_blacklist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@
5757
2.7/tempfile.pyi
5858
2and3/argparse.pyi
5959
2and3/bz2.pyi
60+
61+
# fail because of conditionals pytype#28
62+
2and3/zipfile.pyi

0 commit comments

Comments
 (0)