Format: application/octet-stream
⬇ Download File (9.9 KB)
   1  import sys
   2  from _typeshed import AnyPath, StrPath, SupportsWrite
   3  from typing import (
   4      AbstractSet,
   5      Any,
   6      Callable,
   7      ClassVar,
   8      Dict,
   9      Iterable,
  10      Iterator,
  11      List,
  12      Mapping,
  13      MutableMapping,
  14      Optional,
  15      Pattern,
  16      Sequence,
  17      Tuple,
  18      Type,
  19      TypeVar,
  20      Union,
  21      overload,
  22  )
  23  from typing_extensions import Literal
  24  
  25  # Internal type aliases
  26  _section = Mapping[str, str]
  27  _parser = MutableMapping[str, _section]
  28  _converter = Callable[[str], Any]
  29  _converters = Dict[str, _converter]
  30  _T = TypeVar("_T")
  31  
  32  if sys.version_info >= (3, 7):
  33      _Path = AnyPath
  34  else:
  35      _Path = StrPath
  36  
  37  DEFAULTSECT: str
  38  MAX_INTERPOLATION_DEPTH: int
  39  
  40  class Interpolation:
  41      def before_get(self, parser: _parser, section: str, option: str, value: str, defaults: _section) -> str: ...
  42      def before_set(self, parser: _parser, section: str, option: str, value: str) -> str: ...
  43      def before_read(self, parser: _parser, section: str, option: str, value: str) -> str: ...
  44      def before_write(self, parser: _parser, section: str, option: str, value: str) -> str: ...
  45  
  46  class BasicInterpolation(Interpolation): ...
  47  class ExtendedInterpolation(Interpolation): ...
  48  class LegacyInterpolation(Interpolation): ...
  49  
  50  class RawConfigParser(_parser):
  51      _SECT_TMPL: ClassVar[str] = ...  # Undocumented
  52      _OPT_TMPL: ClassVar[str] = ...  # Undocumented
  53      _OPT_NV_TMPL: ClassVar[str] = ...  # Undocumented
  54  
  55      SECTCRE: Pattern[str] = ...
  56      OPTCRE: ClassVar[Pattern[str]] = ...
  57      OPTCRE_NV: ClassVar[Pattern[str]] = ...  # Undocumented
  58      NONSPACECRE: ClassVar[Pattern[str]] = ...  # Undocumented
  59  
  60      BOOLEAN_STATES: ClassVar[Mapping[str, bool]] = ...  # Undocumented
  61      default_section: str
  62      @overload
  63      def __init__(
  64          self,
  65          defaults: Optional[Mapping[str, Optional[str]]] = ...,
  66          dict_type: Type[Mapping[str, str]] = ...,
  67          allow_no_value: Literal[True] = ...,
  68          *,
  69          delimiters: Sequence[str] = ...,
  70          comment_prefixes: Sequence[str] = ...,
  71          inline_comment_prefixes: Optional[Sequence[str]] = ...,
  72          strict: bool = ...,
  73          empty_lines_in_values: bool = ...,
  74          default_section: str = ...,
  75          interpolation: Optional[Interpolation] = ...,
  76          converters: _converters = ...,
  77      ) -> None: ...
  78      @overload
  79      def __init__(
  80          self,
  81          defaults: Optional[_section] = ...,
  82          dict_type: Type[Mapping[str, str]] = ...,
  83          allow_no_value: bool = ...,
  84          *,
  85          delimiters: Sequence[str] = ...,
  86          comment_prefixes: Sequence[str] = ...,
  87          inline_comment_prefixes: Optional[Sequence[str]] = ...,
  88          strict: bool = ...,
  89          empty_lines_in_values: bool = ...,
  90          default_section: str = ...,
  91          interpolation: Optional[Interpolation] = ...,
  92          converters: _converters = ...,
  93      ) -> None: ...
  94      def __len__(self) -> int: ...
  95      def __getitem__(self, section: str) -> SectionProxy: ...
  96      def __setitem__(self, section: str, options: _section) -> None: ...
  97      def __delitem__(self, section: str) -> None: ...
  98      def __iter__(self) -> Iterator[str]: ...
  99      def defaults(self) -> _section: ...
 100      def sections(self) -> List[str]: ...
 101      def add_section(self, section: str) -> None: ...
 102      def has_section(self, section: str) -> bool: ...
 103      def options(self, section: str) -> List[str]: ...
 104      def has_option(self, section: str, option: str) -> bool: ...
 105      def read(self, filenames: Union[_Path, Iterable[_Path]], encoding: Optional[str] = ...) -> List[str]: ...
 106      def read_file(self, f: Iterable[str], source: Optional[str] = ...) -> None: ...
 107      def read_string(self, string: str, source: str = ...) -> None: ...
 108      def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = ...) -> None: ...
 109      def readfp(self, fp: Iterable[str], filename: Optional[str] = ...) -> None: ...
 110      # These get* methods are partially applied (with the same names) in
 111      # SectionProxy; the stubs should be kept updated together
 112      @overload
 113      def getint(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> int: ...
 114      @overload
 115      def getint(
 116          self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...
 117      ) -> Union[int, _T]: ...
 118      @overload
 119      def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> float: ...
 120      @overload
 121      def getfloat(
 122          self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...
 123      ) -> Union[float, _T]: ...
 124      @overload
 125      def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> bool: ...
 126      @overload
 127      def getboolean(
 128          self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...
 129      ) -> Union[bool, _T]: ...
 130      def _get_conv(
 131          self,
 132          section: str,
 133          option: str,
 134          conv: Callable[[str], _T],
 135          *,
 136          raw: bool = ...,
 137          vars: Optional[_section] = ...,
 138          fallback: _T = ...,
 139      ) -> _T: ...
 140      # This is incompatible with MutableMapping so we ignore the type
 141      @overload  # type: ignore
 142      def get(self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> str: ...
 143      @overload
 144      def get(
 145          self, section: str, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T
 146      ) -> Union[str, _T]: ...
 147      @overload
 148      def items(self, *, raw: bool = ..., vars: Optional[_section] = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ...
 149      @overload
 150      def items(self, section: str, raw: bool = ..., vars: Optional[_section] = ...) -> List[Tuple[str, str]]: ...
 151      def set(self, section: str, option: str, value: Optional[str] = ...) -> None: ...
 152      def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = ...) -> None: ...
 153      def remove_option(self, section: str, option: str) -> bool: ...
 154      def remove_section(self, section: str) -> bool: ...
 155      def optionxform(self, optionstr: str) -> str: ...
 156  
 157  class ConfigParser(RawConfigParser): ...
 158  class SafeConfigParser(ConfigParser): ...
 159  
 160  class SectionProxy(MutableMapping[str, str]):
 161      def __init__(self, parser: RawConfigParser, name: str) -> None: ...
 162      def __getitem__(self, key: str) -> str: ...
 163      def __setitem__(self, key: str, value: str) -> None: ...
 164      def __delitem__(self, key: str) -> None: ...
 165      def __contains__(self, key: object) -> bool: ...
 166      def __len__(self) -> int: ...
 167      def __iter__(self) -> Iterator[str]: ...
 168      @property
 169      def parser(self) -> RawConfigParser: ...
 170      @property
 171      def name(self) -> str: ...
 172      def get(self, option: str, fallback: Optional[str] = ..., *, raw: bool = ..., vars: Optional[_section] = ..., _impl: Optional[Any] = ..., **kwargs: Any) -> str: ...  # type: ignore
 173      # These are partially-applied version of the methods with the same names in
 174      # RawConfigParser; the stubs should be kept updated together
 175      @overload
 176      def getint(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> int: ...
 177      @overload
 178      def getint(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...) -> Union[int, _T]: ...
 179      @overload
 180      def getfloat(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> float: ...
 181      @overload
 182      def getfloat(
 183          self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...
 184      ) -> Union[float, _T]: ...
 185      @overload
 186      def getboolean(self, option: str, *, raw: bool = ..., vars: Optional[_section] = ...) -> bool: ...
 187      @overload
 188      def getboolean(
 189          self, option: str, *, raw: bool = ..., vars: Optional[_section] = ..., fallback: _T = ...
 190      ) -> Union[bool, _T]: ...
 191      # SectionProxy can have arbitrary attributes when custon converters are used
 192      def __getattr__(self, key: str) -> Callable[..., Any]: ...
 193  
 194  class ConverterMapping(MutableMapping[str, Optional[_converter]]):
 195      GETTERCRE: Pattern[Any]
 196      def __init__(self, parser: RawConfigParser) -> None: ...
 197      def __getitem__(self, key: str) -> _converter: ...
 198      def __setitem__(self, key: str, value: Optional[_converter]) -> None: ...
 199      def __delitem__(self, key: str) -> None: ...
 200      def __iter__(self) -> Iterator[str]: ...
 201      def __len__(self) -> int: ...
 202  
 203  class Error(Exception):
 204      message: str
 205      def __init__(self, msg: str = ...) -> None: ...
 206  
 207  class NoSectionError(Error):
 208      section: str
 209      def __init__(self, section: str) -> None: ...
 210  
 211  class DuplicateSectionError(Error):
 212      section: str
 213      source: Optional[str]
 214      lineno: Optional[int]
 215      def __init__(self, section: str, source: Optional[str] = ..., lineno: Optional[int] = ...) -> None: ...
 216  
 217  class DuplicateOptionError(Error):
 218      section: str
 219      option: str
 220      source: Optional[str]
 221      lineno: Optional[int]
 222      def __init__(self, section: str, option: str, source: Optional[str] = ..., lineno: Optional[str] = ...) -> None: ...
 223  
 224  class NoOptionError(Error):
 225      section: str
 226      option: str
 227      def __init__(self, option: str, section: str) -> None: ...
 228  
 229  class InterpolationError(Error):
 230      section: str
 231      option: str
 232      def __init__(self, option: str, section: str, msg: str) -> None: ...
 233  
 234  class InterpolationDepthError(InterpolationError):
 235      def __init__(self, option: str, section: str, rawval: object) -> None: ...
 236  
 237  class InterpolationMissingOptionError(InterpolationError):
 238      reference: str
 239      def __init__(self, option: str, section: str, rawval: object, reference: str) -> None: ...
 240  
 241  class InterpolationSyntaxError(InterpolationError): ...
 242  
 243  class ParsingError(Error):
 244      source: str
 245      errors: List[Tuple[int, str]]
 246      def __init__(self, source: Optional[str] = ..., filename: Optional[str] = ...) -> None: ...
 247      def append(self, lineno: int, line: str) -> None: ...
 248  
 249  class MissingSectionHeaderError(ParsingError):
 250      lineno: int
 251      line: str
 252      def __init__(self, filename: str, lineno: int, line: str) -> None: ...
 253