Format: application/octet-stream
⬇ Download File (5.2 KB)
   1  import sys
   2  from typing import IO, Any, Callable, Iterable, Iterator, Mapping, Optional, Tuple, Type, Union
   3  
   4  HIGHEST_PROTOCOL: int
   5  if sys.version_info >= (3, 0):
   6      DEFAULT_PROTOCOL: int
   7  
   8  bytes_types: Tuple[Type[Any], ...]  # undocumented
   9  
  10  if sys.version_info >= (3, 8):
  11      # TODO: holistic design for buffer interface (typing.Buffer?)
  12      class PickleBuffer:
  13          # buffer must be a buffer-providing object
  14          def __init__(self, buffer: Any) -> None: ...
  15          def raw(self) -> memoryview: ...
  16          def release(self) -> None: ...
  17      _BufferCallback = Optional[Callable[[PickleBuffer], Any]]
  18      def dump(
  19          obj: Any,
  20          file: IO[bytes],
  21          protocol: Optional[int] = ...,
  22          *,
  23          fix_imports: bool = ...,
  24          buffer_callback: _BufferCallback = ...,
  25      ) -> None: ...
  26      def dumps(
  27          obj: Any, protocol: Optional[int] = ..., *, fix_imports: bool = ..., buffer_callback: _BufferCallback = ...
  28      ) -> bytes: ...
  29      def load(
  30          file: IO[bytes],
  31          *,
  32          fix_imports: bool = ...,
  33          encoding: str = ...,
  34          errors: str = ...,
  35          buffers: Optional[Iterable[Any]] = ...,
  36      ) -> Any: ...
  37      def loads(
  38          __data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ..., buffers: Optional[Iterable[Any]] = ...
  39      ) -> Any: ...
  40  
  41  elif sys.version_info >= (3, 0):
  42      def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> None: ...
  43      def dumps(obj: Any, protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> bytes: ...
  44      def load(file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
  45      def loads(data: bytes, *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> Any: ...
  46  
  47  else:
  48      def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ...) -> None: ...
  49      def dumps(obj: Any, protocol: Optional[int] = ...) -> bytes: ...
  50      def load(file: IO[bytes]) -> Any: ...
  51      def loads(string: bytes) -> Any: ...
  52  
  53  class PickleError(Exception): ...
  54  class PicklingError(PickleError): ...
  55  class UnpicklingError(PickleError): ...
  56  
  57  _reducedtype = Union[
  58      str,
  59      Tuple[Callable[..., Any], Tuple[Any, ...]],
  60      Tuple[Callable[..., Any], Tuple[Any, ...], Any],
  61      Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]]],
  62      Tuple[Callable[..., Any], Tuple[Any, ...], Any, Optional[Iterator[Any]], Optional[Iterator[Any]]],
  63  ]
  64  
  65  class Pickler:
  66      fast: bool
  67      if sys.version_info >= (3, 3):
  68          dispatch_table: Mapping[type, Callable[[Any], _reducedtype]]
  69  
  70      if sys.version_info >= (3, 8):
  71          def __init__(
  72              self,
  73              file: IO[bytes],
  74              protocol: Optional[int] = ...,
  75              *,
  76              fix_imports: bool = ...,
  77              buffer_callback: _BufferCallback = ...,
  78          ) -> None: ...
  79          def reducer_override(self, obj: Any) -> Any: ...
  80      elif sys.version_info >= (3, 0):
  81          def __init__(self, file: IO[bytes], protocol: Optional[int] = ..., *, fix_imports: bool = ...) -> None: ...
  82      else:
  83          def __init__(self, file: IO[bytes], protocol: Optional[int] = ...) -> None: ...
  84      def dump(self, __obj: Any) -> None: ...
  85      def clear_memo(self) -> None: ...
  86      def persistent_id(self, obj: Any) -> Any: ...
  87  
  88  class Unpickler:
  89      if sys.version_info >= (3, 8):
  90          def __init__(
  91              self,
  92              file: IO[bytes],
  93              *,
  94              fix_imports: bool = ...,
  95              encoding: str = ...,
  96              errors: str = ...,
  97              buffers: Optional[Iterable[Any]] = ...,
  98          ) -> None: ...
  99      elif sys.version_info >= (3, 0):
 100          def __init__(self, file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., errors: str = ...) -> None: ...
 101      else:
 102          def __init__(self, file: IO[bytes]) -> None: ...
 103      def load(self) -> Any: ...
 104      def find_class(self, __module_name: str, __global_name: str) -> Any: ...
 105      if sys.version_info >= (3, 0):
 106          def persistent_load(self, pid: Any) -> Any: ...
 107  
 108  MARK: bytes
 109  STOP: bytes
 110  POP: bytes
 111  POP_MARK: bytes
 112  DUP: bytes
 113  FLOAT: bytes
 114  INT: bytes
 115  BININT: bytes
 116  BININT1: bytes
 117  LONG: bytes
 118  BININT2: bytes
 119  NONE: bytes
 120  PERSID: bytes
 121  BINPERSID: bytes
 122  REDUCE: bytes
 123  STRING: bytes
 124  BINSTRING: bytes
 125  SHORT_BINSTRING: bytes
 126  UNICODE: bytes
 127  BINUNICODE: bytes
 128  APPEND: bytes
 129  BUILD: bytes
 130  GLOBAL: bytes
 131  DICT: bytes
 132  EMPTY_DICT: bytes
 133  APPENDS: bytes
 134  GET: bytes
 135  BINGET: bytes
 136  INST: bytes
 137  LONG_BINGET: bytes
 138  LIST: bytes
 139  EMPTY_LIST: bytes
 140  OBJ: bytes
 141  PUT: bytes
 142  BINPUT: bytes
 143  LONG_BINPUT: bytes
 144  SETITEM: bytes
 145  TUPLE: bytes
 146  EMPTY_TUPLE: bytes
 147  SETITEMS: bytes
 148  BINFLOAT: bytes
 149  
 150  TRUE: bytes
 151  FALSE: bytes
 152  
 153  # protocol 2
 154  PROTO: bytes
 155  NEWOBJ: bytes
 156  EXT1: bytes
 157  EXT2: bytes
 158  EXT4: bytes
 159  TUPLE1: bytes
 160  TUPLE2: bytes
 161  TUPLE3: bytes
 162  NEWTRUE: bytes
 163  NEWFALSE: bytes
 164  LONG1: bytes
 165  LONG4: bytes
 166  
 167  if sys.version_info >= (3, 0):
 168      # protocol 3
 169      BINBYTES: bytes
 170      SHORT_BINBYTES: bytes
 171  
 172  if sys.version_info >= (3, 4):
 173      # protocol 4
 174      SHORT_BINUNICODE: bytes
 175      BINUNICODE8: bytes
 176      BINBYTES8: bytes
 177      EMPTY_SET: bytes
 178      ADDITEMS: bytes
 179      FROZENSET: bytes
 180      NEWOBJ_EX: bytes
 181      STACK_GLOBAL: bytes
 182      MEMOIZE: bytes
 183      FRAME: bytes
 184  
 185  def encode_long(x: int) -> bytes: ...  # undocumented
 186  def decode_long(data: bytes) -> int: ...  # undocumented
 187