Format: application/octet-stream
⬇ Download File (5.9 KB)
   1  import sys
   2  from _typeshed import SupportsGetItem, SupportsItemAccess
   3  from builtins import type as _type
   4  from typing import IO, Any, AnyStr, Dict, Iterable, Iterator, List, Mapping, Optional, Protocol, Tuple, TypeVar, Union
   5  
   6  _T = TypeVar("_T", bound=FieldStorage)
   7  
   8  def parse(
   9      fp: Optional[IO[Any]] = ...,
  10      environ: SupportsItemAccess[str, str] = ...,
  11      keep_blank_values: bool = ...,
  12      strict_parsing: bool = ...,
  13  ) -> Dict[str, List[str]]: ...
  14  
  15  if sys.version_info < (3, 8):
  16      def parse_qs(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ...
  17      def parse_qsl(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> List[Tuple[str, str]]: ...
  18  
  19  if sys.version_info >= (3, 7):
  20      def parse_multipart(
  21          fp: IO[Any], pdict: SupportsGetItem[str, bytes], encoding: str = ..., errors: str = ...
  22      ) -> Dict[str, List[Any]]: ...
  23  
  24  else:
  25      def parse_multipart(fp: IO[Any], pdict: SupportsGetItem[str, bytes]) -> Dict[str, List[bytes]]: ...
  26  
  27  class _Environ(Protocol):
  28      def __getitem__(self, __k: str) -> str: ...
  29      def keys(self) -> Iterable[str]: ...
  30  
  31  def parse_header(line: str) -> Tuple[str, Dict[str, str]]: ...
  32  def test(environ: _Environ = ...) -> None: ...
  33  def print_environ(environ: _Environ = ...) -> None: ...
  34  def print_form(form: Dict[str, Any]) -> None: ...
  35  def print_directory() -> None: ...
  36  def print_environ_usage() -> None: ...
  37  
  38  if sys.version_info < (3,):
  39      def escape(s: AnyStr, quote: bool = ...) -> AnyStr: ...
  40  
  41  elif sys.version_info < (3, 8):
  42      def escape(s: str, quote: Optional[bool] = ...) -> str: ...
  43  
  44  class MiniFieldStorage:
  45      # The first five "Any" attributes here are always None, but mypy doesn't support that
  46      filename: Any
  47      list: Any
  48      type: Any
  49      file: Optional[IO[bytes]]
  50      type_options: Dict[Any, Any]
  51      disposition: Any
  52      disposition_options: Dict[Any, Any]
  53      headers: Dict[Any, Any]
  54      name: Any
  55      value: Any
  56      def __init__(self, name: Any, value: Any) -> None: ...
  57      def __repr__(self) -> str: ...
  58  
  59  class FieldStorage(object):
  60      FieldStorageClass: Optional[_type]
  61      keep_blank_values: int
  62      strict_parsing: int
  63      qs_on_post: Optional[str]
  64      headers: Mapping[str, str]
  65      fp: IO[bytes]
  66      encoding: str
  67      errors: str
  68      outerboundary: bytes
  69      bytes_read: int
  70      limit: Optional[int]
  71      disposition: str
  72      disposition_options: Dict[str, str]
  73      filename: Optional[str]
  74      file: Optional[IO[bytes]]
  75      type: str
  76      type_options: Dict[str, str]
  77      innerboundary: bytes
  78      length: int
  79      done: int
  80      list: Optional[List[Any]]
  81      value: Union[None, bytes, List[Any]]
  82  
  83      if sys.version_info >= (3, 6):
  84          def __init__(
  85              self,
  86              fp: Optional[IO[Any]] = ...,
  87              headers: Optional[Mapping[str, str]] = ...,
  88              outerboundary: bytes = ...,
  89              environ: SupportsGetItem[str, str] = ...,
  90              keep_blank_values: int = ...,
  91              strict_parsing: int = ...,
  92              limit: Optional[int] = ...,
  93              encoding: str = ...,
  94              errors: str = ...,
  95              max_num_fields: Optional[int] = ...,
  96          ) -> None: ...
  97      elif sys.version_info >= (3, 0):
  98          def __init__(
  99              self,
 100              fp: Optional[IO[Any]] = ...,
 101              headers: Optional[Mapping[str, str]] = ...,
 102              outerboundary: bytes = ...,
 103              environ: SupportsGetItem[str, str] = ...,
 104              keep_blank_values: int = ...,
 105              strict_parsing: int = ...,
 106              limit: Optional[int] = ...,
 107              encoding: str = ...,
 108              errors: str = ...,
 109          ) -> None: ...
 110      else:
 111          def __init__(
 112              self,
 113              fp: IO[Any] = ...,
 114              headers: Mapping[str, str] = ...,
 115              outerboundary: bytes = ...,
 116              environ: SupportsGetItem[str, str] = ...,
 117              keep_blank_values: int = ...,
 118              strict_parsing: int = ...,
 119          ) -> None: ...
 120      if sys.version_info >= (3, 0):
 121          def __enter__(self: _T) -> _T: ...
 122          def __exit__(self, *args: Any) -> None: ...
 123      def __repr__(self) -> str: ...
 124      def __iter__(self) -> Iterator[str]: ...
 125      def __getitem__(self, key: str) -> Any: ...
 126      def getvalue(self, key: str, default: Any = ...) -> Any: ...
 127      def getfirst(self, key: str, default: Any = ...) -> Any: ...
 128      def getlist(self, key: str) -> List[Any]: ...
 129      def keys(self) -> List[str]: ...
 130      if sys.version_info < (3, 0):
 131          def has_key(self, key: str) -> bool: ...
 132      def __contains__(self, key: str) -> bool: ...
 133      def __len__(self) -> int: ...
 134      if sys.version_info >= (3, 0):
 135          def __bool__(self) -> bool: ...
 136      else:
 137          def __nonzero__(self) -> bool: ...
 138      if sys.version_info >= (3, 0):
 139          # In Python 3 it returns bytes or str IO depending on an internal flag
 140          def make_file(self) -> IO[Any]: ...
 141      else:
 142          # In Python 2 it always returns bytes and ignores the "binary" flag
 143          def make_file(self, binary: Any = ...) -> IO[bytes]: ...
 144  
 145  if sys.version_info < (3, 0):
 146      from UserDict import UserDict
 147      class FormContentDict(UserDict[str, List[str]]):
 148          query_string: str
 149          def __init__(self, environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ...
 150      class SvFormContentDict(FormContentDict):
 151          def getlist(self, key: Any) -> Any: ...
 152      class InterpFormContentDict(SvFormContentDict): ...
 153      class FormContent(FormContentDict):
 154          # TODO this should have
 155          # def values(self, key: Any) -> Any: ...
 156          # but this is incompatible with the supertype, and adding '# type: ignore' triggers
 157          # a parse error in pytype (https://github.com/google/pytype/issues/53)
 158          def indexed_value(self, key: Any, location: int) -> Any: ...
 159          def value(self, key: Any) -> Any: ...
 160          def length(self, key: Any) -> int: ...
 161          def stripped(self, key: Any) -> Any: ...
 162          def pars(self) -> Dict[Any, Any]: ...
 163