Skip to content

Commit 70ea8b3

Browse files
authored
Add stubs for xlrd (#13676)
1 parent 643e57e commit 70ea8b3

File tree

11 files changed

+832
-0
lines changed

11 files changed

+832
-0
lines changed

stubs/xlrd/METADATA.toml

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

stubs/xlrd/xlrd/__init__.pyi

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import sys
2+
from _typeshed import SupportsWrite
3+
from typing import Final
4+
5+
from . import timemachine as timemachine
6+
from .biffh import (
7+
XL_CELL_BLANK as XL_CELL_BLANK,
8+
XL_CELL_BOOLEAN as XL_CELL_BOOLEAN,
9+
XL_CELL_DATE as XL_CELL_DATE,
10+
XL_CELL_EMPTY as XL_CELL_EMPTY,
11+
XL_CELL_ERROR as XL_CELL_ERROR,
12+
XL_CELL_NUMBER as XL_CELL_NUMBER,
13+
XL_CELL_TEXT as XL_CELL_TEXT,
14+
biff_text_from_num as biff_text_from_num,
15+
error_text_from_code as error_text_from_code,
16+
)
17+
from .book import Book as Book, colname as colname, open_workbook_xls as open_workbook_xls
18+
from .formula import *
19+
from .info import __VERSION__ as __VERSION__, __version__ as __version__
20+
from .sheet import empty_cell as empty_cell
21+
from .xldate import XLDateError as XLDateError, xldate_as_datetime as xldate_as_datetime, xldate_as_tuple as xldate_as_tuple
22+
23+
FILE_FORMAT_DESCRIPTIONS: Final[dict[str, str]]
24+
ZIP_SIGNATURE: Final[bytes]
25+
PEEK_SIZE: Final[int]
26+
27+
def inspect_format(path: str | None = None, content: bytes | None = None) -> str | None: ...
28+
def open_workbook(
29+
filename: str | None = None,
30+
logfile: SupportsWrite[str] = sys.stdout,
31+
verbosity: int = 0,
32+
use_mmap: bool = True,
33+
file_contents: bytes | None = None,
34+
encoding_override: str | None = None,
35+
formatting_info: bool = False,
36+
on_demand: bool = False,
37+
ragged_rows: bool = False,
38+
ignore_workbook_corruption: bool = False,
39+
) -> Book: ...
40+
def dump(filename: str, outfile: SupportsWrite[str] = sys.stdout, unnumbered: bool = False) -> None: ...
41+
def count_records(filename: str, outfile: SupportsWrite[str] = sys.stdout) -> None: ...

stubs/xlrd/xlrd/biffh.pyi

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import sys
2+
from collections.abc import Callable
3+
from typing import Any, Final, TextIO
4+
5+
from .timemachine import *
6+
7+
DEBUG: Final[int]
8+
9+
class XLRDError(Exception): ...
10+
11+
class BaseObject:
12+
_repr_these: list[str]
13+
def dump(self, f: TextIO | None = None, header: str | None = None, footer: str | None = None, indent: int = 0) -> None: ...
14+
15+
FUN: Final[int]
16+
FDT: Final[int]
17+
FNU: Final[int]
18+
FGE: Final[int]
19+
FTX: Final[int]
20+
DATEFORMAT: Final[int]
21+
NUMBERFORMAT: Final[int]
22+
XL_CELL_EMPTY: Final[int]
23+
XL_CELL_TEXT: Final[int]
24+
XL_CELL_NUMBER: Final[int]
25+
XL_CELL_DATE: Final[int]
26+
XL_CELL_BOOLEAN: Final[int]
27+
XL_CELL_ERROR: Final[int]
28+
XL_CELL_BLANK: Final[int]
29+
biff_text_from_num: Final[dict[int, str]]
30+
error_text_from_code: Final[dict[int, str]]
31+
BIFF_FIRST_UNICODE: Final[int]
32+
XL_WORKBOOK_GLOBALS: Final[int]
33+
WBKBLOBAL: Final[int]
34+
XL_WORKBOOK_GLOBALS_4W: Final[int]
35+
XL_WORKSHEET: Final[int]
36+
WRKSHEET: Final[int]
37+
XL_BOUNDSHEET_WORKSHEET: Final[int]
38+
XL_BOUNDSHEET_CHART: Final[int]
39+
XL_BOUNDSHEET_VB_MODULE: Final[int]
40+
XL_ARRAY: Final[int]
41+
XL_ARRAY2: Final[int]
42+
XL_BLANK: Final[int]
43+
XL_BLANK_B2: Final[int]
44+
XL_BOF: Final[int]
45+
XL_BOOLERR: Final[int]
46+
XL_BOOLERR_B2: Final[int]
47+
XL_BOUNDSHEET: Final[int]
48+
XL_BUILTINFMTCOUNT: Final[int]
49+
XL_CF: Final[int]
50+
XL_CODEPAGE: Final[int]
51+
XL_COLINFO: Final[int]
52+
XL_COLUMNDEFAULT: Final[int]
53+
XL_COLWIDTH: Final[int]
54+
XL_CONDFMT: Final[int]
55+
XL_CONTINUE: Final[int]
56+
XL_COUNTRY: Final[int]
57+
XL_DATEMODE: Final[int]
58+
XL_DEFAULTROWHEIGHT: Final[int]
59+
XL_DEFCOLWIDTH: Final[int]
60+
XL_DIMENSION: Final[int]
61+
XL_DIMENSION2: Final[int]
62+
XL_EFONT: Final[int]
63+
XL_EOF: Final[int]
64+
XL_EXTERNNAME: Final[int]
65+
XL_EXTERNSHEET: Final[int]
66+
XL_EXTSST: Final[int]
67+
XL_FEAT11: Final[int]
68+
XL_FILEPASS: Final[int]
69+
XL_FONT: Final[int]
70+
XL_FONT_B3B4: Final[int]
71+
XL_FORMAT: Final[int]
72+
XL_FORMAT2: Final[int]
73+
XL_FORMULA: Final[int]
74+
XL_FORMULA3: Final[int]
75+
XL_FORMULA4: Final[int]
76+
XL_GCW: Final[int]
77+
XL_HLINK: Final[int]
78+
XL_QUICKTIP: Final[int]
79+
XL_HORIZONTALPAGEBREAKS: Final[int]
80+
XL_INDEX: Final[int]
81+
XL_INTEGER: Final[int]
82+
XL_IXFE: Final[int]
83+
XL_LABEL: Final[int]
84+
XL_LABEL_B2: Final[int]
85+
XL_LABELRANGES: Final[int]
86+
XL_LABELSST: Final[int]
87+
XL_LEFTMARGIN: Final[int]
88+
XL_TOPMARGIN: Final[int]
89+
XL_RIGHTMARGIN: Final[int]
90+
XL_BOTTOMMARGIN: Final[int]
91+
XL_HEADER: Final[int]
92+
XL_FOOTER: Final[int]
93+
XL_HCENTER: Final[int]
94+
XL_VCENTER: Final[int]
95+
XL_MERGEDCELLS: Final[int]
96+
XL_MSO_DRAWING: Final[int]
97+
XL_MSO_DRAWING_GROUP: Final[int]
98+
XL_MSO_DRAWING_SELECTION: Final[int]
99+
XL_MULRK: Final[int]
100+
XL_MULBLANK: Final[int]
101+
XL_NAME: Final[int]
102+
XL_NOTE: Final[int]
103+
XL_NUMBER: Final[int]
104+
XL_NUMBER_B2: Final[int]
105+
XL_OBJ: Final[int]
106+
XL_PAGESETUP: Final[int]
107+
XL_PALETTE: Final[int]
108+
XL_PANE: Final[int]
109+
XL_PRINTGRIDLINES: Final[int]
110+
XL_PRINTHEADERS: Final[int]
111+
XL_RK: Final[int]
112+
XL_ROW: Final[int]
113+
XL_ROW_B2: Final[int]
114+
XL_RSTRING: Final[int]
115+
XL_SCL: Final[int]
116+
XL_SHEETHDR: Final[int]
117+
XL_SHEETPR: Final[int]
118+
XL_SHEETSOFFSET: Final[int]
119+
XL_SHRFMLA: Final[int]
120+
XL_SST: Final[int]
121+
XL_STANDARDWIDTH: Final[int]
122+
XL_STRING: Final[int]
123+
XL_STRING_B2: Final[int]
124+
XL_STYLE: Final[int]
125+
XL_SUPBOOK: Final[int]
126+
XL_TABLEOP: Final[int]
127+
XL_TABLEOP2: Final[int]
128+
XL_TABLEOP_B2: Final[int]
129+
XL_TXO: Final[int]
130+
XL_UNCALCED: Final[int]
131+
XL_UNKNOWN: Final[int]
132+
XL_VERTICALPAGEBREAKS: Final[int]
133+
XL_WINDOW2: Final[int]
134+
XL_WINDOW2_B2: Final[int]
135+
XL_WRITEACCESS: Final[int]
136+
XL_WSBOOL: Final[int]
137+
XL_XF: Final[int]
138+
XL_XF2: Final[int]
139+
XL_XF3: Final[int]
140+
XL_XF4: Final[int]
141+
boflen: Final[dict[int, int]]
142+
bofcodes: Final[tuple[int, int, int, int]]
143+
XL_FORMULA_OPCODES: Final[tuple[int, int, int]]
144+
145+
def is_cell_opcode(c: int) -> bool: ...
146+
def upkbits(
147+
tgt_obj: object, src: int, manifest: list[tuple[int, int, str]], local_setattr: Callable[[Any, str, Any], None] = ...
148+
) -> None: ...
149+
def upkbitsL(
150+
tgt_obj: object,
151+
src: int,
152+
manifest: list[tuple[int, int, str]],
153+
local_setattr: Callable[[Any, str, Any], None] = ...,
154+
local_int: Callable[[Any], int] = ...,
155+
) -> None: ...
156+
def unpack_string(data: bytes, pos: int, encoding: str, lenlen: int = 1) -> str: ...
157+
def unpack_string_update_pos(
158+
data: bytes, pos: int, encoding: str, lenlen: int = 1, known_len: int | None = None
159+
) -> tuple[str, int]: ...
160+
def unpack_unicode(data: bytes, pos: int, lenlen: int = 2) -> str: ...
161+
def unpack_unicode_update_pos(data: bytes, pos: int, lenlen: int = 2, known_len: int | None = None) -> tuple[str, int]: ...
162+
def unpack_cell_range_address_list_update_pos(
163+
output_list: list[tuple[int, int, int, int]], data: bytes, pos: int, biff_version: int, addr_size: int = 6
164+
) -> int: ...
165+
166+
biff_rec_name_dict: Final[dict[int, str]]
167+
168+
def hex_char_dump(
169+
strg: bytes, ofs: int, dlen: int, base: int = 0, fout: TextIO = sys.stdout, unnumbered: bool = False
170+
) -> None: ...
171+
def biff_dump(
172+
mem: bytes, stream_offset: int, stream_len: int, base: int = 0, fout: TextIO = sys.stdout, unnumbered: bool = False
173+
) -> None: ...
174+
def biff_count_records(mem: bytes, stream_offset: int, stream_len: int, fout: TextIO = sys.stdout) -> None: ...
175+
176+
encoding_from_codepage: Final[dict[int, str]]

stubs/xlrd/xlrd/book.pyi

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import sys
2+
from _typeshed import SupportsWrite
3+
from collections.abc import Iterator
4+
from types import TracebackType
5+
from typing import Final, Literal
6+
from typing_extensions import Self
7+
8+
from .biffh import *
9+
from .formatting import XF, Font, Format
10+
from .formula import *
11+
from .sheet import Cell, Sheet
12+
from .timemachine import *
13+
14+
empty_cell: Final[Cell]
15+
MY_EOF: Final[int]
16+
SUPBOOK_UNK: Final[int]
17+
SUPBOOK_INTERNAL: Final[int]
18+
SUPBOOK_EXTERNAL: Final[int]
19+
SUPBOOK_ADDIN: Final[int]
20+
SUPBOOK_DDEOLE: Final[int]
21+
SUPPORTED_VERSIONS: Final[tuple[int, ...]]
22+
builtin_name_from_code: Final[dict[str, str]]
23+
code_from_builtin_name: Final[dict[str, str]]
24+
25+
def open_workbook_xls(
26+
filename: str | None = None,
27+
logfile: SupportsWrite[str] = sys.stdout,
28+
verbosity: int = 0,
29+
use_mmap: bool = True,
30+
file_contents: bytes | None = None,
31+
encoding_override: str | None = None,
32+
formatting_info: bool = False,
33+
on_demand: bool = False,
34+
ragged_rows: bool = False,
35+
ignore_workbook_corruption: bool = False,
36+
) -> Book: ...
37+
38+
class Name(BaseObject):
39+
_repr_these: list[str]
40+
book: Book | None = None
41+
hidden: Literal[0, 1]
42+
func: Literal[0, 1]
43+
vbasic: Literal[0, 1]
44+
macro: Literal[0, 1]
45+
complex: Literal[0, 1]
46+
builtin: Literal[0, 1]
47+
funcgroup: Literal[0, 1]
48+
binary: Literal[0, 1]
49+
name_index: int
50+
name: str
51+
raw_formula: bytes
52+
scope: Literal[-1, -2, -3, 0]
53+
result: Operand | None
54+
def cell(self) -> Cell: ...
55+
def area2d(self, clipped: bool = True) -> tuple[Sheet, int, int, int, int]: ...
56+
57+
class Book(BaseObject):
58+
nsheets: int
59+
datemode: Literal[0, 1]
60+
biff_version: int
61+
name_obj_list: list[Name]
62+
codepage: int | None
63+
encoding: str | None
64+
countries: tuple[int, int]
65+
user_name: str
66+
font_list: list[Font]
67+
xf_list: list[XF]
68+
format_list: list[Format]
69+
format_map: dict[int, Format]
70+
style_name_map: dict[str, tuple[int, int]]
71+
colour_map: dict[int, tuple[int, int, int] | None]
72+
palette_record: list[tuple[int, int, int]]
73+
load_time_stage_1: float
74+
load_time_stage_2: float
75+
def sheets(self) -> list[Sheet]: ...
76+
def sheet_by_index(self, sheetx: int) -> Sheet: ...
77+
def __iter__(self) -> Iterator[Sheet]: ...
78+
def sheet_by_name(self, sheet_name: str) -> Sheet: ...
79+
def __getitem__(self, item: int | str) -> Sheet: ...
80+
def sheet_names(self) -> list[str]: ...
81+
def sheet_loaded(self, sheet_name_or_index: int | str) -> bool: ...
82+
def unload_sheet(self, sheet_name_or_index: int | str) -> None: ...
83+
mem: bytes | None = None
84+
filestr: bytes | None = None
85+
def release_resources(self) -> None: ...
86+
def __enter__(self) -> Self: ...
87+
def __exit__(
88+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_tb: TracebackType | None
89+
) -> None: ...
90+
name_and_scope_map: dict[tuple[str, int], Name]
91+
name_map: dict[str, list[Name]]
92+
raw_user_name: bool
93+
builtinfmtcount: int
94+
addin_func_names: list[str]
95+
def __init__(self) -> None: ...
96+
logfile: SupportsWrite[str]
97+
verbosity: int
98+
use_mmap: bool
99+
encoding_override: str | None
100+
formatting_info: bool
101+
on_demand: bool
102+
ragged_rows: bool
103+
stream_len: int
104+
base: int
105+
def biff2_8_load(
106+
self,
107+
filename: str | None = None,
108+
file_contents: bytes | None = None,
109+
logfile: SupportsWrite[str] = sys.stdout,
110+
verbosity: int = 0,
111+
use_mmap: bool = True,
112+
encoding_override: str | None = None,
113+
formatting_info: bool = False,
114+
on_demand: bool = False,
115+
ragged_rows: bool = False,
116+
ignore_workbook_corruption: bool = False,
117+
) -> None: ...
118+
xfcount: int
119+
actualfmtcount: int
120+
def initialise_format_info(self) -> None: ...
121+
def get2bytes(self) -> int: ...
122+
def get_record_parts(self) -> tuple[int, int, bytes]: ...
123+
def get_record_parts_conditional(self, reqd_record: int) -> tuple[int | None, int, bytes]: ...
124+
def get_sheet(self, sh_number: int, update_pos: bool = True) -> Sheet: ...
125+
def get_sheets(self) -> None: ...
126+
def fake_globals_get_sheet(self) -> None: ...
127+
def handle_boundsheet(self, data: bytes) -> None: ...
128+
def handle_builtinfmtcount(self, data: bytes) -> None: ...
129+
def derive_encoding(self) -> str: ...
130+
def handle_codepage(self, data: bytes) -> None: ...
131+
def handle_country(self, data: bytes) -> None: ...
132+
def handle_datemode(self, data: bytes) -> None: ...
133+
def handle_externname(self, data: bytes) -> None: ...
134+
def handle_externsheet(self, data: bytes) -> None: ...
135+
def handle_filepass(self, data: bytes) -> None: ...
136+
def handle_name(self, data: bytes) -> None: ...
137+
def names_epilogue(self) -> None: ...
138+
def handle_obj(self, data: bytes) -> None: ...
139+
def handle_supbook(self, data: bytes) -> None: ...
140+
def handle_sheethdr(self, data: bytes) -> None: ...
141+
def handle_sheetsoffset(self, data: bytes) -> None: ...
142+
def handle_sst(self, data: bytes) -> None: ...
143+
def handle_writeaccess(self, data: bytes) -> None: ...
144+
def parse_globals(self) -> None: ...
145+
def read(self, pos: int, length: int) -> bytes: ...
146+
def getbof(self, rqd_stream: int) -> int | None: ...
147+
148+
# Helper functions
149+
def expand_cell_address(inrow: int, incol: int) -> tuple[int, int, int, int]: ...
150+
def display_cell_address(rowx: int, colx: int, relrow: int, relcol: int) -> str: ...
151+
def unpack_SST_table(datatab: list[bytes], nstrings: int) -> tuple[list[str], dict[int, list[tuple[int, int]]]]: ...

0 commit comments

Comments
 (0)