Skip to content

Commit 67a80c6

Browse files
authored
Added types for olefile (#11416)
1 parent ef94b9e commit 67a80c6

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
olefile.olefile2.*

stubs/olefile/METADATA.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = "0.47.*"
2+
upstream_repository = "https://github.com/decalage2/olefile"

stubs/olefile/olefile/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .olefile import *
2+
from .olefile import __all__ as __all__, __author__ as __author__, __date__ as __date__, __version__ as __version__

stubs/olefile/olefile/olefile.pyi

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
import array
2+
import datetime
3+
import io
4+
import logging
5+
import traceback
6+
from collections.abc import Sequence
7+
from typing import IO
8+
from typing_extensions import Self
9+
10+
__date__: str
11+
__version__: str
12+
__author__: str
13+
14+
__all__ = [
15+
"isOleFile",
16+
"OleFileIO",
17+
"OleMetadata",
18+
"enable_logging",
19+
"MAGIC",
20+
"STGTY_EMPTY",
21+
"STGTY_STREAM",
22+
"STGTY_STORAGE",
23+
"STGTY_ROOT",
24+
"STGTY_PROPERTY",
25+
"STGTY_LOCKBYTES",
26+
"MINIMAL_OLEFILE_SIZE",
27+
"DEFECT_UNSURE",
28+
"DEFECT_POTENTIAL",
29+
"DEFECT_INCORRECT",
30+
"DEFECT_FATAL",
31+
"DEFAULT_PATH_ENCODING",
32+
"MAXREGSECT",
33+
"DIFSECT",
34+
"FATSECT",
35+
"ENDOFCHAIN",
36+
"FREESECT",
37+
"MAXREGSID",
38+
"NOSTREAM",
39+
"UNKNOWN_SIZE",
40+
"WORD_CLSID",
41+
"OleFileIONotClosed",
42+
]
43+
44+
UINT32: str
45+
46+
DEFAULT_PATH_ENCODING: str | None
47+
48+
def get_logger(name: str, level: int = 51) -> logging.Logger: ...
49+
50+
log: logging.Logger
51+
52+
def enable_logging() -> None: ...
53+
54+
MAGIC: bytes
55+
56+
MAXREGSECT: int
57+
DIFSECT: int
58+
FATSECT: int
59+
ENDOFCHAIN: int
60+
FREESECT: int
61+
62+
MAXREGSID: int
63+
NOSTREAM: int
64+
65+
STGTY_EMPTY: int
66+
STGTY_STORAGE: int
67+
STGTY_STREAM: int
68+
STGTY_LOCKBYTES: int
69+
STGTY_PROPERTY: int
70+
STGTY_ROOT: int
71+
72+
UNKNOWN_SIZE: int
73+
74+
VT_EMPTY: int
75+
VT_NULL: int
76+
VT_I2: int
77+
VT_I4: int
78+
VT_R4: int
79+
VT_R8: int
80+
VT_CY: int
81+
VT_DATE: int
82+
VT_BSTR: int
83+
VT_DISPATCH: int
84+
VT_ERROR: int
85+
VT_BOOL: int
86+
VT_VARIANT: int
87+
VT_UNKNOWN: int
88+
VT_DECIMAL: int
89+
VT_I1: int
90+
VT_UI1: int
91+
VT_UI2: int
92+
VT_UI4: int
93+
VT_I8: int
94+
VT_UI8: int
95+
VT_INT: int
96+
VT_UINT: int
97+
VT_VOID: int
98+
VT_HRESULT: int
99+
VT_PTR: int
100+
VT_SAFEARRAY: int
101+
VT_CARRAY: int
102+
VT_USERDEFINED: int
103+
VT_LPSTR: int
104+
VT_LPWSTR: int
105+
VT_FILETIME: int
106+
VT_BLOB: int
107+
VT_STREAM: int
108+
VT_STORAGE: int
109+
VT_STREAMED_OBJECT: int
110+
VT_STORED_OBJECT: int
111+
VT_BLOB_OBJECT: int
112+
VT_CF: int
113+
VT_CLSID: int
114+
VT_VECTOR: int
115+
116+
VT: dict[int, str]
117+
118+
WORD_CLSID: str
119+
DEFECT_UNSURE: int
120+
DEFECT_POTENTIAL: int
121+
DEFECT_INCORRECT: int
122+
DEFECT_FATAL: int
123+
MINIMAL_OLEFILE_SIZE: int
124+
125+
def isOleFile(filename: IO[bytes] | bytes | str | None = None, data: bytes | None = None) -> bool: ...
126+
def i8(c: bytes | int) -> int: ...
127+
def i16(c: bytes, o: int = 0) -> int: ...
128+
def i32(c: bytes, o: int = 0) -> int: ...
129+
def _clsid(clsid: bytes) -> str: ...
130+
def filetime2datetime(filetime: int) -> datetime.datetime: ...
131+
132+
class OleFileError(IOError): ...
133+
class NotOleFileError(OleFileError): ...
134+
135+
class OleMetadata:
136+
SUMMARY_ATTRIBS: list[str]
137+
DOCSUM_ATTRIBS: list[str]
138+
139+
def __init__(self) -> None: ...
140+
def parse_properties(self, ole_file: OleFileIO) -> None: ...
141+
def dump(self) -> None: ...
142+
143+
class OleFileIONotClosed(RuntimeWarning):
144+
def __init__(self, stack_of_open: traceback.FrameSummary | None = None) -> None: ...
145+
146+
class OleStream(io.BytesIO):
147+
def __init__(
148+
self,
149+
fp: IO[bytes],
150+
sect: int,
151+
size: int,
152+
offset: int,
153+
sectorsize: int,
154+
fat: list[int],
155+
filesize: int,
156+
olefileio: OleFileIO,
157+
) -> None: ...
158+
159+
class OleDirectoryEntry:
160+
STRUCT_DIRENTRY: str
161+
DIRENTRY_SIZE: int
162+
163+
def __init__(self, entry: bytes, sid: int, ole_file: OleFileIO) -> None: ...
164+
def build_sect_chain(self, ole_file: OleFileIO) -> None: ...
165+
def build_storage_tree(self) -> None: ...
166+
def append_kids(self, child_sid: int) -> None: ...
167+
def __eq__(self, other: OleDirectoryEntry) -> bool: ... # type: ignore[override]
168+
def __lt__(self, other: OleDirectoryEntry) -> bool: ... # type: ignore[override]
169+
def __ne__(self, other: OleDirectoryEntry) -> bool: ... # type: ignore[override]
170+
def __le__(self, other: OleDirectoryEntry) -> bool: ... # type: ignore[override]
171+
def dump(self, tab: int = 0) -> None: ...
172+
def getmtime(self) -> datetime.datetime | None: ...
173+
def getctime(self) -> datetime.datetime | None: ...
174+
175+
class OleFileIO:
176+
def __init__(
177+
self,
178+
filename: IO[bytes] | bytes | str | None = None,
179+
raise_defects: int = 40,
180+
write_mode: bool = False,
181+
debug: bool = False,
182+
path_encoding: str | None = DEFAULT_PATH_ENCODING, # noqaY011
183+
) -> None: ...
184+
def __del__(self) -> None: ...
185+
def __enter__(self) -> Self: ...
186+
def __exit__(self, *args: object) -> None: ...
187+
def _raise_defect(
188+
self, defect_level: int, message: str, exception_type: type[Exception] = OleFileError # noqaY011
189+
) -> None: ...
190+
def _decode_utf16_str(self, utf16_str: bytes, errors: str = "replace") -> bytes: ...
191+
def open(self, filename: IO[bytes] | bytes | str, write_mode: bool = False) -> None: ...
192+
def close(self) -> None: ...
193+
def _close(self, warn: bool = False) -> None: ...
194+
def _check_duplicate_stream(self, first_sect: int, minifat: bool = False) -> None: ...
195+
def dumpfat(self, fat: Sequence[int], firstindex: int = 0) -> None: ...
196+
def dumpsect(self, sector: bytes, firstindex: int = 0) -> None: ...
197+
def sect2array(self, sect: bytes) -> Sequence[int]: ...
198+
def loadfat_sect(self, sect: bytes | array.array[int]) -> int | None: ...
199+
def loadfat(self, header: bytes) -> None: ...
200+
def loadminifat(self) -> None: ...
201+
def getsect(self, sect: int) -> bytes: ...
202+
def write_sect(self, sect: int, data: bytes, padding: bytes = b"\x00") -> None: ...
203+
def _write_mini_sect(self, fp_pos: int, data: bytes, padding: bytes = b"\x00") -> None: ...
204+
def loaddirectory(self, sect: int) -> None: ...
205+
def _load_direntry(self, sid: int) -> OleDirectoryEntry: ...
206+
def dumpdirectory(self) -> None: ...
207+
def _open(self, start: int, size: int = 0x7FFFFFFF, force_FAT: bool = False) -> OleStream: ...
208+
def _list(
209+
self, files: list[list[bytes]], prefix: list[bytes], node: OleDirectoryEntry, streams: bool = True, storages: bool = False
210+
) -> None: ...
211+
def listdir(self, streams: bool = True, storages: bool = False) -> list[list[bytes]]: ...
212+
def _find(self, filename: str | Sequence[str]) -> int: ...
213+
def openstream(self, filename: str | Sequence[str]) -> OleStream: ...
214+
def _write_mini_stream(self, entry: OleDirectoryEntry, data_to_write: bytes) -> None: ...
215+
def write_stream(self, stream_name: str | Sequence[str], data: bytes) -> None: ...
216+
def get_type(self, filename: str | Sequence[str]) -> bool | int: ...
217+
def getclsid(self, filename: str | Sequence[str]) -> str: ...
218+
def getmtime(self, filename: str | Sequence[str]) -> datetime.datetime | None: ...
219+
def getctime(self, filename: str | Sequence[str]) -> datetime.datetime | None: ...
220+
def exists(self, filename: str | Sequence[str]) -> bool: ...
221+
def get_size(self, filename: str | Sequence[str]) -> int: ...
222+
def get_rootentry_name(self) -> bytes: ...
223+
def getproperties(
224+
self, filename: str | Sequence[str], convert_time: bool = False, no_conversion: list[int] | None = None
225+
) -> dict[int, list[int | str | bytes | bool | None]]: ...
226+
def _parse_property(
227+
self, s: bytes, offset: int, property_id: int, property_type: int, convert_time: bool, no_conversion: list[int]
228+
) -> list[int | str | bytes | bool | None] | None: ...
229+
def _parse_property_basic(
230+
self, s: bytes, offset: int, property_id: int, property_type: int, convert_time: bool, no_conversion: list[int]
231+
) -> tuple[int | str | bytes | bool | None, int]: ...
232+
def get_metadata(self) -> OleMetadata: ...
233+
def get_userdefined_properties(
234+
self, filename: str | Sequence[str], convert_time: bool = False, no_conversion: list[int] | None = None
235+
) -> list[dict[str, bytes | int | None]]: ...
236+
237+
def main() -> None: ...

0 commit comments

Comments
 (0)