1 # Based on http://docs.python.org/3.5/library/configparser.html and on
\r
2 # reading configparser.py.
\r
5 from typing import (AbstractSet, MutableMapping, Mapping, Dict, Sequence, List,
\r
6 Union, Iterable, Iterator, Callable, Any, IO, overload,
\r
7 Optional, Pattern, Type, TypeVar)
\r
8 # Types only used in type comments only
\r
9 from typing import Optional, Tuple # noqa
\r
11 if sys.version_info >= (3, 6):
\r
12 from os import PathLike
\r
14 # Internal type aliases
\r
15 _section = Mapping[str, str]
\r
16 _parser = MutableMapping[str, _section]
\r
17 _converter = Callable[[str], Any]
\r
18 _converters = Dict[str, _converter]
\r
21 if sys.version_info >= (3, 6):
\r
22 _Path = Union[str, PathLike[str]]
\r
27 MAX_INTERPOLATION_DEPTH: int
\r
29 class Interpolation:
\r
30 def before_get(self, parser: _parser,
\r
34 defaults: _section) -> str: ...
\r
36 def before_set(self, parser: _parser,
\r
39 value: str) -> str: ...
\r
41 def before_read(self, parser: _parser,
\r
44 value: str) -> str: ...
\r
46 def before_write(self, parser: _parser,
\r
49 value: str) -> str: ...
\r
52 class BasicInterpolation(Interpolation): ...
\r
53 class ExtendedInterpolation(Interpolation): ...
\r
54 class LegacyInterpolation(Interpolation): ...
\r
57 class RawConfigParser(_parser):
\r
59 defaults: Optional[_section] = ...,
\r
60 dict_type: Type[Mapping[str, str]] = ...,
\r
61 allow_no_value: bool = ...,
\r
63 delimiters: Sequence[str] = ...,
\r
64 comment_prefixes: Sequence[str] = ...,
\r
65 inline_comment_prefixes: Optional[Sequence[str]] = ...,
\r
67 empty_lines_in_values: bool = ...,
\r
68 default_section: str = ...,
\r
69 interpolation: Optional[Interpolation] = ...) -> None: ...
\r
71 def __len__(self) -> int: ...
\r
73 def __getitem__(self, section: str) -> SectionProxy: ...
\r
75 def __setitem__(self, section: str, options: _section) -> None: ...
\r
77 def __delitem__(self, section: str) -> None: ...
\r
79 def __iter__(self) -> Iterator[str]: ...
\r
81 def defaults(self) -> _section: ...
\r
83 def sections(self) -> List[str]: ...
\r
85 def add_section(self, section: str) -> None: ...
\r
87 def has_section(self, section: str) -> bool: ...
\r
89 def options(self, section: str) -> List[str]: ...
\r
91 def has_option(self, section: str, option: str) -> bool: ...
\r
93 def read(self, filenames: Union[_Path, Iterable[_Path]],
\r
94 encoding: Optional[str] = ...) -> List[str]: ...
\r
96 def readfp(self, fp: IO[str], filename: Optional[str] = ...) -> None: ...
\r
98 def read_file(self, f: Iterable[str], source: Optional[str] = ...) -> None: ...
\r
100 def read_string(self, string: str, source: str = ...) -> None: ...
\r
102 def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]],
\r
103 source: str = ...) -> None: ...
\r
105 # These get* methods are partially applied (with the same names) in
\r
106 # SectionProxy; the stubs should be kept updated together
\r
107 def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ...
\r
109 def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ...
\r
111 def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ...
\r
113 def _get_conv(self, section: str, option: str, conv: Callable[[str], _T], *, raw: bool = ..., vars: _section = ..., fallback: _T = ...) -> _T: ...
\r
115 # This is incompatible with MutableMapping so we ignore the type
\r
116 def get(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: str = ...) -> str: # type: ignore
\r
120 def items(self, *, raw: bool = ..., vars: _section = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ...
\r
123 def items(self, section: str, raw: bool = ..., vars: _section = ...) -> List[Tuple[str, str]]: ...
\r
125 def set(self, section: str, option: str, value: str) -> None: ...
\r
128 fileobject: IO[str],
\r
129 space_around_delimiters: bool = ...) -> None: ...
\r
131 def remove_option(self, section: str, option: str) -> bool: ...
\r
133 def remove_section(self, section: str) -> bool: ...
\r
135 def optionxform(self, option: str) -> str: ...
\r
138 class ConfigParser(RawConfigParser):
\r
140 defaults: Optional[_section] = ...,
\r
141 dict_type: Mapping[str, str] = ...,
\r
142 allow_no_value: bool = ...,
\r
143 delimiters: Sequence[str] = ...,
\r
144 comment_prefixes: Sequence[str] = ...,
\r
145 inline_comment_prefixes: Optional[Sequence[str]] = ...,
\r
146 strict: bool = ...,
\r
147 empty_lines_in_values: bool = ...,
\r
148 default_section: str = ...,
\r
149 interpolation: Optional[Interpolation] = ...,
\r
150 converters: _converters = ...) -> None: ...
\r
152 class SafeConfigParser(ConfigParser): ...
\r
154 class SectionProxy(MutableMapping[str, str]):
\r
155 def __init__(self, parser: RawConfigParser, name: str) -> None: ...
\r
156 def __getitem__(self, key: str) -> str: ...
\r
157 def __setitem__(self, key: str, value: str) -> None: ...
\r
158 def __delitem__(self, key: str) -> None: ...
\r
159 def __contains__(self, key: object) -> bool: ...
\r
160 def __len__(self) -> int: ...
\r
161 def __iter__(self) -> Iterator[str]: ...
\r
163 def parser(self) -> RawConfigParser: ...
\r
165 def name(self) -> str: ...
\r
166 def get(self, option: str, fallback: Optional[str] = ..., *, raw: bool = ..., vars: Optional[_section] = ..., **kwargs: Any) -> str: ... # type: ignore
\r
168 # These are partially-applied version of the methods with the same names in
\r
169 # RawConfigParser; the stubs should be kept updated together
\r
170 def getint(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ...
\r
171 def getfloat(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ...
\r
172 def getboolean(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ...
\r
174 # SectionProxy can have arbitrary attributes when custon converters are used
\r
175 def __getattr__(self, key: str) -> Callable[..., Any]: ...
\r
177 class ConverterMapping(MutableMapping[str, Optional[_converter]]):
\r
179 def __init__(self, parser: RawConfigParser) -> None: ...
\r
180 def __getitem__(self, key: str) -> _converter: ...
\r
181 def __setitem__(self, key: str, value: Optional[_converter]) -> None: ...
\r
182 def __delitem__(self, key: str) -> None: ...
\r
183 def __iter__(self) -> Iterator[str]: ...
\r
184 def __len__(self) -> int: ...
\r
187 class Error(Exception): ...
\r
190 class NoSectionError(Error): ...
\r
193 class DuplicateSectionError(Error):
\r
194 section = ... # type: str
\r
195 source = ... # type: Optional[str]
\r
196 lineno = ... # type: Optional[int]
\r
199 class DuplicateOptionError(Error):
\r
200 section = ... # type: str
\r
201 option = ... # type: str
\r
202 source = ... # type: Optional[str]
\r
203 lineno = ... # type: Optional[int]
\r
206 class NoOptionError(Error):
\r
207 section = ... # type: str
\r
208 option = ... # type: str
\r
211 class InterpolationError(Error):
\r
212 section = ... # type: str
\r
213 option = ... # type: str
\r
216 class InterpolationDepthError(InterpolationError): ...
\r
219 class InterpolationMissingOptionError(InterpolationError):
\r
220 reference = ... # type: str
\r
223 class InterpolationSyntaxError(InterpolationError): ...
\r
226 class ParsingError(Error):
\r
227 source = ... # type: str
\r
228 errors = ... # type: Sequence[Tuple[int, str]]
\r
231 class MissingSectionHeaderError(ParsingError):
\r
232 lineno = ... # type: int
\r
233 line = ... # type: str
\r