diff --git a/bson/__init__.pyi b/bson/__init__.pyi new file mode 100644 index 0000000000..3c9629c1a4 --- /dev/null +++ b/bson/__init__.pyi @@ -0,0 +1,61 @@ +# Stubs for bson (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, BinaryIO, Iterator, List, Mapping, MutableMapping, Sequence + +from bson.binary import Binary as Binary +from bson.code import Code as Code +from bson.codec_options import CodecOptions as CodecOptions +from bson.dbref import DBRef as DBRef +from bson.decimal128 import Decimal128 as Decimal128 +from bson.errors import (InvalidBSON as InvalidBSON, + InvalidDocument as InvalidDocument, + InvalidStringData as InvalidStringData) +from bson.int64 import Int64 as Int64 +from bson.max_key import MaxKey as MaxKey +from bson.min_key import MinKey as MinKey +from bson.objectid import ObjectId as ObjectId +from bson.regex import Regex as Regex +from bson.son import SON as SON +from bson.timestamp import Timestamp as Timestamp +from bson.tz_util import utc as utc + +EPOCH_AWARE: datetime.datetime +EPOCH_NAIVE: datetime.datetime +BSONNUM: bytes +BSONSTR: bytes +BSONOBJ: bytes +BSONARR: bytes +BSONBIN: bytes +BSONUND: bytes +BSONOID: bytes +BSONBOO: bytes +BSONDAT: bytes +BSONNUL: bytes +BSONRGX: bytes +BSONREF: bytes +BSONCOD: bytes +BSONSYM: bytes +BSONCWS: bytes +BSONINT: bytes +BSONTIM: bytes +BSONLON: bytes +BSONDEC: bytes +BSONMIN: bytes +BSONMAX: bytes + +def gen_list_name() -> Iterator[bytes]: ... +def decode_all(data: Sequence[bytes], codec_options: CodecOptions = ...) -> List[Mapping[Any, Any]]: ... + +def decode_iter(data: Sequence[bytes], codec_options: CodecOptions = ...) -> Iterator[MutableMapping[Any, Any]]: ... +def decode_file_iter(file_obj: BinaryIO, codec_options: CodecOptions = ...) -> Iterator[MutableMapping[Any, Any]]: ... +def is_valid(bson: bytes) -> bool: ... + +class BSON(bytes): + @classmethod + def encode(cls, document: Mapping[Any, Any], check_keys: bool = ..., codec_options: CodecOptions = ...) -> BSON: ... # type: ignore + def decode(self, codec_options: CodecOptions = ...) -> MutableMapping[Any, Any]: ... # type: ignore + +def has_c() -> bool: ... diff --git a/bson/binary.pyi b/bson/binary.pyi new file mode 100644 index 0000000000..a4dd8d2f06 --- /dev/null +++ b/bson/binary.pyi @@ -0,0 +1,36 @@ +# Stubs for bson.binary (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Iterable, Tuple +from uuid import UUID + +BINARY_SUBTYPE: int = ... +FUNCTION_SUBTYPE: int = ... +OLD_BINARY_SUBTYPE: int = ... +OLD_UUID_SUBTYPE: int = ... +UUID_SUBTYPE: int = ... +STANDARD: int = ... +PYTHON_LEGACY: int = ... +JAVA_LEGACY: int = ... +CSHARP_LEGACY: int = ... +ALL_UUID_SUBTYPES: Iterable[int] = ... +ALL_UUID_REPRESENTATIONS: Iterable[int] = ... +UUID_REPRESENTATION_NAMES: Dict[int, str] = ... +MD5_SUBTYPE: int = ... +USER_DEFINED_SUBTYPE: int = ... + +class Binary(bytes): + def __new__(cls, data: bytes, subtype: int = ...) -> Binary: ... + @property + def subtype(self) -> int: ... + def __getnewargs__(self) -> Tuple[bytes, int]: ... # type: ignore + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + +class UUIDLegacy(Binary): + def __new__(cls, obj: UUID) -> UUIDLegacy: ... + def __getnewargs__(self) -> Tuple[UUID]: ... # type: ignore + @property + def uuid(self) -> UUID: ... diff --git a/bson/code.pyi b/bson/code.pyi new file mode 100644 index 0000000000..2eb831698e --- /dev/null +++ b/bson/code.pyi @@ -0,0 +1,12 @@ +# Stubs for bson.code (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Mapping, Optional, Union + +class Code(str): + def __new__(cls, code: Union[Code, str], scope: Optional[Mapping[str, Any]] = ..., **kwargs: Any) -> Code: ... + @property + def scope(self) -> Optional[Mapping[str, Any]]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... diff --git a/bson/codec_options.pyi b/bson/codec_options.pyi new file mode 100644 index 0000000000..df5dd45c95 --- /dev/null +++ b/bson/codec_options.pyi @@ -0,0 +1,26 @@ +# Stubs for bson.codec_options (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, NamedTuple, Optional + +_options_base = NamedTuple('_options_base', [ + ('document_class', type), + ('tz_aware', bool), + ('uuid_representation', int), + ('unicode_decode_error_handler', str), + ('tzinfo', datetime.tzinfo), +]) + +class CodecOptions(_options_base): + def __new__( + cls, + document_class: type = ..., + tz_aware: bool = ..., + uuid_representation: int = ..., + unicode_decode_error_handler: str = ..., + tzinfo: Optional[datetime.tzinfo] = ...) -> CodecOptions: ... + def with_options(self, **kwargs: Any) -> CodecOptions: ... + +DEFAULT_CODEC_OPTIONS: CodecOptions = ... diff --git a/bson/dbref.pyi b/bson/dbref.pyi new file mode 100644 index 0000000000..8bee375f09 --- /dev/null +++ b/bson/dbref.pyi @@ -0,0 +1,27 @@ +# Stubs for bson.dbref (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Mapping, Optional + +from bson.son import SON + +class DBRef: + def __init__( + self, + collection: str, + id: Any, database: Optional[str] = ..., + _extra: Mapping[str, Any] = ..., + **kwargs: Any) -> None: ... + @property + def collection(self) -> str: ... + @property + def id(self) -> Any: ... + @property + def database(self) -> Optional[str]: ... + def __getattr__(self, key: str) -> Any: ... + def as_doc(self) -> SON[str, Any]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __deepcopy__(self, memo: Any) -> DBRef: ... diff --git a/bson/decimal128.pyi b/bson/decimal128.pyi new file mode 100644 index 0000000000..74aca6b082 --- /dev/null +++ b/bson/decimal128.pyi @@ -0,0 +1,18 @@ +# Stubs for bson.decimal128 (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import decimal +from typing import Any, Union + +def create_decimal128_context() -> decimal.Context: ... + +class Decimal128: + def __init__(self, value: Union[str, decimal.Decimal]) -> None: ... + def to_decimal(self) -> decimal.Decimal: ... + @classmethod + def from_bid(cls, value: bytes) -> Decimal128: ... + @property + def bid(self) -> bytes: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... diff --git a/bson/errors.pyi b/bson/errors.pyi new file mode 100644 index 0000000000..e2e21195ad --- /dev/null +++ b/bson/errors.pyi @@ -0,0 +1,9 @@ +# Stubs for bson.errors (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +class BSONError(Exception): ... +class InvalidBSON(BSONError): ... +class InvalidStringData(BSONError): ... +class InvalidDocument(BSONError): ... +class InvalidId(BSONError): ... diff --git a/bson/int64.pyi b/bson/int64.pyi new file mode 100644 index 0000000000..bf8765dd90 --- /dev/null +++ b/bson/int64.pyi @@ -0,0 +1,7 @@ +# Stubs for bson.int64 (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +long = int + +class Int64(long): ... diff --git a/bson/json_util.pyi b/bson/json_util.pyi new file mode 100644 index 0000000000..40c891e6e7 --- /dev/null +++ b/bson/json_util.pyi @@ -0,0 +1,42 @@ +# Stubs for bson.json_util (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.codec_options import CodecOptions +from typing import Any + +class DatetimeRepresentation: + LEGACY: int = ... + NUMBERLONG: int = ... + ISO8601: int = ... + +class JSONMode: + LEGACY: int = ... + RELAXED: int = ... + CANONICAL: int = ... + +class JSONOptions(CodecOptions): + json_mode: int = ... + strict_number_long: bool = ... + datetime_representation: int = ... + strict_uuid: bool = ... + def __new__( + cls, + strict_number_long: bool = ..., + datetime_representation: int = ..., + strict_uuid: bool = ..., + json_mode: int = ..., + *args: Any, + **kwargs: Any) -> JSONOptions: ... + +LEGACY_JSON_OPTIONS: JSONOptions = ... +DEFAULT_JSON_OPTIONS: JSONOptions = ... +CANONICAL_JSON_OPTIONS: JSONOptions = ... +RELAXED_JSON_OPTIONS: JSONOptions = ... +STRICT_JSON_OPTIONS: JSONOptions = ... + +def dumps(obj: Any, *args: Any, **kwargs: Any) -> str: ... +def loads(s: str, *args: Any, **kwargs: Any) -> Any: ... +def object_pairs_hook(pairs: Any, json_options: JSONOptions = ...) -> Any: ... +def object_hook(dct: Any, json_options: JSONOptions = ...) -> Any: ... +def default(obj: Any, json_options: JSONOptions = ...) -> Any: ... diff --git a/bson/max_key.pyi b/bson/max_key.pyi new file mode 100644 index 0000000000..ee1bbfb326 --- /dev/null +++ b/bson/max_key.pyi @@ -0,0 +1,14 @@ +# Stubs for bson.max_key (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +class MaxKey: + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __lt__(self, dummy: Any) -> bool: ... + def __ge__(self, dummy: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... diff --git a/bson/min_key.pyi b/bson/min_key.pyi new file mode 100644 index 0000000000..76c0b03eca --- /dev/null +++ b/bson/min_key.pyi @@ -0,0 +1,14 @@ +# Stubs for bson.min_key (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any + +class MinKey: + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __le__(self, dummy: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def __gt__(self, dummy: Any) -> bool: ... diff --git a/bson/objectid.pyi b/bson/objectid.pyi new file mode 100644 index 0000000000..371bfc7ce7 --- /dev/null +++ b/bson/objectid.pyi @@ -0,0 +1,26 @@ +# Stubs for bson.objectid (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, Optional, Union + +from bson.errors import InvalidId as InvalidId + +class ObjectId: + def __init__(self, oid: Optional[Union[str, ObjectId, bytes]] = ...) -> None: ... + @classmethod + def from_datetime(cls, generation_time: datetime.datetime) -> ObjectId: ... + @classmethod + def is_valid(cls, oid: Any) -> bool: ... + @property + def binary(self) -> bytes: ... + @property + def generation_time(self) -> datetime.datetime: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... diff --git a/bson/py.typed b/bson/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bson/raw_bson.pyi b/bson/raw_bson.pyi new file mode 100644 index 0000000000..21c1a3bcec --- /dev/null +++ b/bson/raw_bson.pyi @@ -0,0 +1,16 @@ +# Stubs for bson.raw_bson (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Optional, TypeVar +from bson.codec_options import CodecOptions + +_Key = TypeVar('_Key') +_Value = TypeVar('_Value') + +class RawBSONDocument(Dict[_Key, _Value]): + def __init__(self, bson_bytes: bytes, codec_options: Optional[CodecOptions] = ...) -> None: ... + @property + def raw(self) -> bytes: ... + +DEFAULT_RAW_BSON_OPTIONS: CodecOptions diff --git a/bson/regex.pyi b/bson/regex.pyi new file mode 100644 index 0000000000..08336be0f1 --- /dev/null +++ b/bson/regex.pyi @@ -0,0 +1,17 @@ +# Stubs for bson.regex (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Pattern, Union + +def str_flags_to_int(str_flags: str) -> int: ... + +class Regex: + @classmethod + def from_native(cls, regex: Pattern[str]) -> Regex: ... + pattern: Union[str, bytes] = ... + flags: int = ... + def __init__(self, pattern: Union[str, bytes], flags: int = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def try_compile(self) -> Pattern[str]: ... diff --git a/bson/son.pyi b/bson/son.pyi new file mode 100644 index 0000000000..af754cefe3 --- /dev/null +++ b/bson/son.pyi @@ -0,0 +1,25 @@ +# Stubs for bson.son (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Dict, Iterable, Iterator, List, Mapping, Optional, Tuple, TypeVar, Union + +RE_TYPE: Any + +_Key = TypeVar('_Key') +_Value = TypeVar('_Value') + +class SON(Dict[_Key, _Value]): + def __init__( + self, + data: Optional[Union[Mapping[_Key, _Value], Iterable[Tuple[_Key, _Value]]]] = ..., + **kwargs: _Value) -> None: ... + def __new__(cls, *args: Any, **kwargs: Any) -> SON[_Key, _Value]: ... + def copy(self) -> SON[_Key, _Value]: ... + def has_key(self, key: _Key) -> bool: ... + def iteritems(self) -> Iterator[Tuple[_Key, _Value]]: ... + def iterkeys(self) -> Iterator[_Key]: ... + def itervalues(self) -> Iterator[_Value]: ... + def setdefault(self, key: _Key, default: Optional[_Value] = ...) -> _Value: ... + def popitem(self) -> Tuple[_Key, _Value]: ... + def to_dict(self) -> Dict[_Key, _Value]: ... diff --git a/bson/timestamp.pyi b/bson/timestamp.pyi new file mode 100644 index 0000000000..2d8b3bc539 --- /dev/null +++ b/bson/timestamp.pyi @@ -0,0 +1,23 @@ +# Stubs for bson.timestamp (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +import datetime +from typing import Any, Union + +UPPERBOUND: int + +class Timestamp: + def __init__(self, time: Union[datetime.datetime, int], inc: int) -> None: ... + @property + def time(self) -> int: ... + @property + def inc(self) -> int: ... + def __eq__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __ne__(self, other: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + def as_datetime(self) -> datetime.datetime: ... diff --git a/bson/tz_util.pyi b/bson/tz_util.pyi new file mode 100644 index 0000000000..78c67cf0d0 --- /dev/null +++ b/bson/tz_util.pyi @@ -0,0 +1,17 @@ +# Stubs for bson.tz_util (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from datetime import datetime, timedelta, tzinfo +from typing import Optional, Tuple, Union + +ZERO: timedelta + +class FixedOffset(tzinfo): + def __init__(self, offset: Union[float, timedelta], name: str) -> None: ... + def __getinitargs__(self) -> Tuple[timedelta, str]: ... + def utcoffset(self, dt: Optional[datetime]) -> timedelta: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + def dst(self, dt: Optional[datetime]) -> timedelta: ... + +utc: FixedOffset diff --git a/pymongo/__init__.pyi b/pymongo/__init__.pyi new file mode 100644 index 0000000000..878c62631e --- /dev/null +++ b/pymongo/__init__.pyi @@ -0,0 +1,34 @@ +import typing +from pymongo.collection import ReturnDocument as ReturnDocument +from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION as MIN_SUPPORTED_WIRE_VERSION, + MAX_SUPPORTED_WIRE_VERSION as MAX_SUPPORTED_WIRE_VERSION) +from pymongo.cursor import CursorType as CursorType +from pymongo.mongo_client import MongoClient as MongoClient +from pymongo.mongo_replica_set_client import MongoReplicaSetClient as MongoReplicaSetClient +from pymongo.operations import (IndexModel as IndexModel, + InsertOne as InsertOne, + DeleteOne as DeleteOne, + DeleteMany as DeleteMany, + UpdateOne as UpdateOne, + UpdateMany as UpdateMany, + ReplaceOne as ReplaceOne) +from pymongo.read_preferences import ReadPreference as ReadPreference +from pymongo.write_concern import WriteConcern as WriteConcern + +ASCENDING: int = ... +DESCENDING: int = ... +GEO2D: str = ... +GEOHAYSTACK: str = ... +GEOSPHERE: str = ... +HASHED: str = ... +TEXT: str = ... +OFF: int = ... +SLOW_ONLY: int = ... +ALL: int = ... +version_tuple: typing.Tuple[int, int, int, str] = ... + +def get_version_string() -> str: ... + +__version__ = version = ... + +def has_c() -> bool: ... diff --git a/pymongo/auth.pyi b/pymongo/auth.pyi new file mode 100644 index 0000000000..61edb5439e --- /dev/null +++ b/pymongo/auth.pyi @@ -0,0 +1,21 @@ +from typing import Any, Dict, FrozenSet, NamedTuple + +from pymongo.pool import SocketInfo + +HAVE_KERBEROS: bool = True +MECHANISMS: FrozenSet[str] = ... + +MongoCredential = NamedTuple('MongoCredential', [ + ('mechanism', str), + ('source', str), + ('username', str), + ('password', str), + ('props', Any), +]) +GSSAPIProperties = NamedTuple('GSSAPIProperties', [ + ('service_name', str), + ('canonicalize_host_name', bool), + ('service_realm', Any), +]) +def authenticate(credentials: MongoCredential, sock_info: SocketInfo) -> None: ... +def logout(source: str, sock_info: SocketInfo) -> None: ... diff --git a/pymongo/bulk.pyi b/pymongo/bulk.pyi new file mode 100644 index 0000000000..0f1403b9c1 --- /dev/null +++ b/pymongo/bulk.pyi @@ -0,0 +1,77 @@ +from typing import Any, Dict, Iterator, List, Optional, Tuple, Union + +from pymongo.collation import Collation +from pymongo.collection import Collection +from pymongo.errors import (BulkWriteError as BulkWriteError, + ConfigurationError as ConfigurationError, + InvalidOperation as InvalidOperation, + OperationFailure as OperationFailure) +from pymongo.pool import SocketInfo +from pymongo.write_concern import WriteConcern + + +_DELETE_ALL: int = ... +_DELETE_ONE: int = ... +_BAD_VALUE: int = ... +_UNKNOWN_ERROR: int = ... +_WRITE_CONCERN_ERROR: int = ... +_COMMANDS: Tuple[str, str, str] = ... +_UID: str = ... +_UCODE: str = ... +_UERRMSG: str = ... +_UINDEX: str = ... +_UOP: str = ... + +class _Run(object): + def __init__(self, op_type: int) -> None: ... + def index(self, idx: int) -> int: ... + def add(self, original_index: int, operation: Dict[str, Any]) -> None: ... + +class _Bulk(object): + def __init__(self, collection: Collection, ordered: bool, bypass_document_validation: bool) -> None: ... + def add_insert(self, document: Dict[str, Any]) -> None: ... + def add_update( + self, + selector: Dict[str, Any], + update: Dict[str, Any], + multi: bool = ..., + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... + def add_replace( + self, + selector: Dict[str, Any], + replacement: Dict[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... + def add_delete(self, selector: Dict[str, Any], limit: int, collation: Optional[Collation] = ...) -> None: ... + def gen_ordered(self) -> _Run: ... + def gen_unordered(self) -> _Run: ... + def execute_command( + self, + sock_info: SocketInfo, + generator: Iterator[_Run], + write_concern: WriteConcern) -> Dict[str, Any]: ... + def execute_no_results(self, sock_info: SocketInfo, generator: Iterator[_Run]) -> None: ... + def execute_legacy(self, sock_info: SocketInfo, generator: Iterator[_Run], write_concern: WriteConcern) -> None: ... + def execute(self, write_concern: WriteConcern) -> Union[Dict[str, Any], None]: ... + +class BulkUpsertOperation(object): + def __init__(self, selector: Dict[str, Any], bulk: _Bulk, collation: Collation) -> None: ... + def update_one(self, update: Dict[str, Any]) -> None: ... + def update(self, update: Dict[str, Any]) -> None: ... + def replace_one(self, replacement: Dict[str, Any]) -> None: ... + +class BulkWriteOperation(object): + def __init__(self, selector: Dict[str, Any], bulk: _Bulk, collation: Collation) -> None: ... + def update_one(self, update: Dict[str, Any]) -> None: ... + def update(self, update: Dict[str, Any]) -> None: ... + def replace_one(self, replacement: Dict[str, Any]) -> None: ... + def remove_one(self) -> None: ... + def remove(self) -> None: ... + def upsert(self) -> BulkUpsertOperation: ... + +class BulkOperationBuilder(object): + def __init__(self, collection: Collection, ordered: bool = ..., bypass_document_validation: bool = ...) -> None: ... + def find(self, selector: Dict[str, Any], collation: Optional[Collation] = ...) -> BulkWriteOperation: ... + def insert(self, document: Dict[str, Any]) -> None: ... + def execute(self, write_concern: Optional[WriteConcern] = ...) -> Union[Dict[str, Any], None]: ... diff --git a/pymongo/change_stream.pyi b/pymongo/change_stream.pyi new file mode 100644 index 0000000000..a7d1799b12 --- /dev/null +++ b/pymongo/change_stream.pyi @@ -0,0 +1,31 @@ +# Stubs for pymongo.change_stream (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.timestamp import Timestamp +from pymongo.collation import Collation +from pymongo.client_session import ClientSession +from typing import Any, Mapping, Optional, Sequence + +class ChangeStream: + def __init__( + self, + target: Any, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str, + resume_after: Optional[str], + max_await_time_ms: Optional[int], + batch_size: Optional[int], + collation: Optional[Collation], + start_at_operation_time: Optional[Timestamp], + session: Optional[ClientSession]) -> None: ... + def close(self) -> None: ... + def __iter__(self) -> ChangeStream: ... + def next(self) -> Mapping[str, Any]: ... + def __next__(self) -> Mapping[str, Any]: ... + def __enter__(self) -> ChangeStream: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + +class CollectionChangeStream(ChangeStream): ... +class DatabaseChangeStream(ChangeStream): ... +class ClusterChangeStream(DatabaseChangeStream): ... diff --git a/pymongo/client_options.pyi b/pymongo/client_options.pyi new file mode 100644 index 0000000000..1995dabc50 --- /dev/null +++ b/pymongo/client_options.pyi @@ -0,0 +1,35 @@ +from typing import Any, Dict, Optional, Tuple + +from bson.codec_options import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.pool import PoolOptions +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.ssl_support import SSLContext +from pymongo.write_concern import WriteConcern + + +class ClientOptions(object): + def __init__(self, username: str, password: str, database: str, options: Dict[str, Any]) -> None: ... + @property + def connect(self) -> bool: ... + @property + def codec_options(self) -> CodecOptions: ... + @property + def credentials(self) -> MongoCredential: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def pool_options(self) -> PoolOptions: ... + @property + def read_preference(self) -> _ServerMode: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_concern(self) -> ReadConcern: ... diff --git a/pymongo/client_session.pyi b/pymongo/client_session.pyi new file mode 100644 index 0000000000..7bdd9bfc7c --- /dev/null +++ b/pymongo/client_session.pyi @@ -0,0 +1,74 @@ +# Stubs for pymongo.client_session (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.binary import Binary +from bson.int64 import Int64 +from bson.timestamp import Timestamp +from pymongo.mongo_client import MongoClient +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern +from typing import Any, Dict, Mapping, Optional + +class SessionOptions: + def __init__( + self, + causal_consistency: bool = ..., + default_transaction_options: Optional[TransactionOptions] = ...) -> None: ... + @property + def causal_consistency(self) -> bool: ... + @property + def default_transaction_options(self) -> Optional[TransactionOptions]: ... + +class TransactionOptions: + def __init__( + self, + read_concern: Optional[ReadConcern] = ..., + write_concern: Optional[WriteConcern] = ..., + read_preference: Optional[_ServerMode] = ...) -> None: ... + @property + def read_concern(self) -> ReadConcern: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_preference(self) -> _ServerMode: ... + +class _TransactionContext: + def __init__(self, session: ClientSession) -> None: ... + def __enter__(self) -> _TransactionContext: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + +class ClientSession: + def __init__(self, client: MongoClient, server_session: ServerSession, options: Any, authset: Any, implicit: Any) -> None: ... + def end_session(self) -> None: ... + def __enter__(self) -> ClientSession: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + @property + def client(self) -> MongoClient: ... + @property + def options(self) -> SessionOptions: ... + @property + def session_id(self) -> Dict[str, Binary]: ... + @property + def cluster_time(self) -> Mapping[str, Timestamp]: ... + @property + def operation_time(self) -> Timestamp: ... + def start_transaction( + self, + read_concern: Optional[ReadConcern] = ..., + write_concern: Optional[WriteConcern] = ..., + read_preference: Optional[_ServerMode] = ...) -> _TransactionContext: ... + def commit_transaction(self) -> None: ... + def abort_transaction(self) -> None: ... + def advance_cluster_time(self, cluster_time: Mapping[str, Timestamp]) -> None: ... + def advance_operation_time(self, operation_time: Timestamp) -> None: ... + @property + def has_ended(self) -> bool: ... + +class ServerSession: + def __init__(self) -> None: ... + def timed_out(self, session_timeout_minutes: int) -> bool: ... + @property + def transaction_id(self) -> Int64: ... + def inc_transaction_id(self) -> None: ... diff --git a/pymongo/collation.pyi b/pymongo/collation.pyi new file mode 100644 index 0000000000..71b8f21ffa --- /dev/null +++ b/pymongo/collation.pyi @@ -0,0 +1,38 @@ +from typing import Any, Dict, Optional + + +class CollationStrength(object): + PRIMARY: int = ... + SECONDARY: int = ... + TERTIARY: int = ... + QUATERNARY: int = ... + IDENTICAL: int = ... +class CollationAlternate(object): + NON_IGNORABLE: str = ... + SHIFTED: str = ... +class CollationMaxVariable(object): + PUNCT: str = ... + SPACE: str = ... +class CollationCaseFirst(object): + UPPER: str = ... + LOWER: str = ... + OFF: str = ... +class Collation(object): + def __init__( + self, + locale: str, + caseLevel: Optional[bool] = ..., + caseFirst: Optional[str] = ..., + strength: Optional[int] = ..., + numericOrdering: Optional[bool] = ..., + alternate: Optional[str] = ..., + maxVariable: Optional[str] = ..., + normalization: Optional[bool] = ..., + backwards: Optional[bool] = ..., + **kwargs: Any) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... +def validate_collation_or_none(value: Any) -> Optional[Dict[str, Any]]: ... diff --git a/pymongo/collection.pyi b/pymongo/collection.pyi new file mode 100644 index 0000000000..5f08195277 --- /dev/null +++ b/pymongo/collection.pyi @@ -0,0 +1,244 @@ +from typing import (Any, Callable, Dict, Iterable, Iterator, List, Mapping, + Optional, Sequence, Tuple, Union) + +from bson.codec_options import CodecOptions +from bson.timestamp import Timestamp +from pymongo.bulk import BulkOperationBuilder +from pymongo.change_stream import CollectionChangeStream +from pymongo.client_session import ClientSession +from pymongo.collation import Collation +from pymongo.command_cursor import CommandCursor +from pymongo.common import BaseObject +from pymongo.cursor import Cursor, RawBatchCursor +from pymongo.database import Database +from pymongo.operations import IndexModel, _WriteOp +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.results import (BulkWriteResult, DeleteResult, InsertManyResult, + InsertOneResult, UpdateResult) +from pymongo.write_concern import WriteConcern + + +class ReturnDocument(object): + BEFORE: bool = ... + AFTER: bool = ... +class Collection(BaseObject): + def __init__( + self, + database: Database, + name: str, + create: Optional[bool] = ..., + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> None: ... + def __create(self, options: Mapping[str, Any], collation: Collation) -> None: ... + def __getattr__(self, name: str) -> 'Collection': ... + def __getitem__(self, name: str) -> 'Collection': ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + @property + def full_name(self) -> str: ... + @property + def name(self) -> str: ... + @property + def database(self) -> Database: ... + def with_options( + self, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> 'Collection': ... + def initialize_unordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... + def initialize_ordered_bulk_op(self, bypass_document_validation: bool = ...) -> BulkOperationBuilder: ... + def bulk_write( + self, + requests: Sequence[_WriteOp], + ordered: bool = ..., + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> BulkWriteResult: ... + def insert_one( + self, + document: Any, + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> InsertOneResult: ... + def insert_many( + self, + documents: Iterable[Any], + ordered: bool = ..., + bypass_document_validation: bool = ..., + session: Optional[ClientSession] = ...) -> InsertManyResult: ... + def replace_one( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + upsert: bool = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def update_one( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def update_many( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + bypass_document_validation: bool = ..., + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> UpdateResult: ... + def drop(self, session: Optional[ClientSession] = ...) -> None: ... + def delete_one( + self, + filter: Mapping[str, Any], + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> DeleteResult: ... + def delete_many( + self, + filter: Mapping[str, Any], + collation: Optional[Collation] = ..., + session: Optional[ClientSession] = ...) -> DeleteResult: ... + def find_one(self, filter: Optional[Mapping[str, Any]] = ..., *args: Any, **kwargs: Any) -> Optional[Dict[str, Any]]: ... + def find(self, *args: Any, **kwargs: Any) -> Cursor: ... + def find_raw_batches(self, *args: Any, **kwargs: Any) -> RawBatchCursor: ... + def parallel_scan(self, num_cursors: int, session: Optional[ClientSession] = ..., **kwargs: Any) -> List[CommandCursor]: ... + def estimated_document_count(self, **kwargs: Any) -> int: ... + def count(self, filter: Optional[Mapping[str, Any]] = ..., session: Optional[ClientSession] = ..., **kwargs: Any) -> int: ... + def count_documents(self, filter: Mapping[str, Any], session: Optional[ClientSession] = ..., **kwargs: Any) -> int: ... + def create_indexes( + self, + indexes: Sequence[IndexModel], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> List[str]: ... + def create_index( + self, + keys: Union[str, Sequence[Tuple[str, Union[int, str]]], Mapping[str, Union[int, str]]], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> str: ... + def ensure_index( + self, + key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], + cache_for: int = ..., + **kwargs: Any) -> Optional[str]: ... + def drop_indexes(self, session: Optional[ClientSession] = ...) -> None: ... + def drop_index( + self, + index_or_name: Union[str, Sequence[Tuple[Any, Any]]], + session: Optional[ClientSession] = ...) -> None: ... + def reindex(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def list_indexes(self, session: Optional[ClientSession] = ...) -> CommandCursor: ... + def index_information(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def options(self, session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def aggregate( + self, + pipeline: Sequence[Mapping[str, Any]], + session: Optional[ClientSession] = ..., + **kwargs: Any) -> CommandCursor: ... + def aggregate_raw_batches(self, pipeline: Sequence[Mapping[str, Any]], **kwargs: Any) -> RawBatchCursor: ... + def watch( + self, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str = ..., + resume_after: Optional[str] = ..., + max_await_time_ms: Optional[int] = ..., + batch_size: Optional[int] = ..., + collation: Optional[Collation] = ..., + start_at_operation_time: Optional[Timestamp] = ..., + session: Optional[ClientSession] = ...) -> CollectionChangeStream: ... + def group( + self, + key: Mapping[str, Any], + condition: Mapping[str, Any], + initial: Mapping[str, int], + reduce: str, + finalize: str = ..., + **kwargs: Any) -> List[Dict[str, Any]]: ... + def rename(self, new_name: str, session: Optional[ClientSession] = ..., **kwargs: Any) -> None: ... + def distinct( + self, + key: str, + filter: Optional[Mapping[str, Any]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> List[Any]: ... + def map_reduce( + self, + map: str, + reduce: str, + out: Union[str, Mapping[str, Any]], + full_response: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Union[Dict[str, Any], Database, 'Collection']: ... + def inline_map_reduce( + self, + map: str, + reduce: str, + full_response: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_delete( + self, + filter: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_replace( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + upsert: bool = ..., + return_document: bool = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def find_one_and_update( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + projection: Optional[Union[Sequence[str], Mapping[str, bool]]] = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + upsert: bool = ..., + return_document: bool = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def save(self, to_save: Mapping[str, Any], manipulate: bool = ..., check_keys: bool = ..., **kwargs: Any) -> Any: ... + def insert( + self, + doc_or_docs: Mapping[str, Any], + manipulate: bool = ..., + check_keys: bool = ..., + continue_on_error: bool = ..., + **kwargs: Any) -> Any: ... + def update( + self, + spec: Mapping[str, Any], + document: Mapping[str, Any], + upsert: bool = ..., + manipulate: bool = ..., + multi: bool = ..., + check_keys: bool = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def remove(self, spec_or_id: Optional[Mapping[str, Any]] = ..., multi: bool = ..., **kwargs: Any) -> Dict[str, Any]: ... + def find_and_modify( + self, + query: Mapping[str, Any] = ..., + update: Mapping[str, Any] = ..., + upsert: bool = ..., + sort: Optional[Sequence[Tuple[str, Union[int, str]]]] = ..., + full_response: bool = ..., + manipulate: bool = ..., + **kwargs: Any) -> Dict[str, Any]: ... + def __call__(self, *args: Any, **kwargs: Any) -> None: ... diff --git a/pymongo/command_cursor.pyi b/pymongo/command_cursor.pyi new file mode 100644 index 0000000000..f578acfcd9 --- /dev/null +++ b/pymongo/command_cursor.pyi @@ -0,0 +1,35 @@ +from typing import Any, Dict, Tuple, Union + +from pymongo import message +from pymongo.client_session import ClientSession +from pymongo.collection import Collection +from typing import Optional + + +class CommandCursor(object): + def __init__( + self, + collection: Collection, + cursor_info: Dict[str, Any], + address: Tuple[str, int], + retrieved: int = ..., + batch_size: int = ..., + max_await_time_ms: Optional[int] = ..., + session: Optional[ClientSession] = ..., + explicit_session: bool = ...) -> None: ... + def __del__(self) -> None: ... + def __die(self) -> None: ... + def close(self) -> None: ... + def batch_size(self, batch_size: int) -> 'CommandCursor': ... + def __send_message(self, operation: Union[message._Query, message._GetMore]) -> None: ... + @property + def alive(self) -> bool: ... + @property + def cursor_id(self) -> int: ... + @property + def address(self) -> Tuple[str, int]: ... + def __iter__(self) -> 'CommandCursor': ... + def next(self) -> Dict[str, Any]: ... + def __next__(self) -> Dict[str, Any]: ... + def __enter__(self) -> 'CommandCursor': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... diff --git a/pymongo/common.pyi b/pymongo/common.pyi new file mode 100644 index 0000000000..74e3cca198 --- /dev/null +++ b/pymongo/common.pyi @@ -0,0 +1,91 @@ +import collections +import datetime +from typing import Any, Callable, Dict, FrozenSet, List, Mapping, MutableMapping, Optional, Tuple, Type, TypeVar, Union + +from bson import CodecOptions +from bson.raw_bson import RawBSONDocument +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern + +MAX_BSON_SIZE: int = ... +MAX_MESSAGE_SIZE: int = ... +MIN_WIRE_VERSION: int = ... +MAX_WIRE_VERSION: int = ... +MAX_WRITE_BATCH_SIZE: int = ... +MIN_SUPPORTED_WIRE_VERSION: int = ... +MAX_SUPPORTED_WIRE_VERSION: int = ... +HEARTBEAT_FREQUENCY: int = ... +KILL_CURSOR_FREQUENCY: int = ... +EVENTS_QUEUE_FREQUENCY: int = ... +SERVER_SELECTION_TIMEOUT: int = ... +MIN_HEARTBEAT_INTERVAL: float = ... +CONNECT_TIMEOUT: float = ... +MAX_POOL_SIZE: int = ... +MIN_POOL_SIZE: int = ... +MAX_IDLE_TIME_MS: Optional[int] = ... +LOCAL_THRESHOLD_MS: int = ... +COMMAND_NOT_FOUND_CODES: Tuple[int, int, None] = ... +UNAUTHORIZED_CODES: Tuple[int, int, int] = ... +_UUID_REPRESENTATIONS: Dict[str, int] = ... +_MECHANISM_PROPS: FrozenSet[str] = ... +_UNICODE_DECODE_ERROR_HANDLERS: FrozenSet[str] = ... +WRITE_CONCERN_OPTIONS: FrozenSet[str] = ... +def partition_node(node: str) -> Tuple[str, int]: ... +def clean_node(node: str) -> Tuple[str, int]: ... +def raise_config_error(key: str, dummy: Any) -> None: ... +def validate_boolean(option: str, value: Any) -> bool: ... +def validate_boolean_or_string(option: str, value: Any) -> bool: ... +def validate_integer(option: str, value: Any) -> int: ... +def validate_positive_integer(option: str, value: Any) -> int: ... +def validate_non_negative_integer(option: str, value: Any) -> int: ... +def validate_readable(option: str, value: Any) -> Optional[str]: ... +def validate_positive_integer_or_none(option: str, value: Any) -> Optional[int]: ... +def validate_non_negative_integer_or_none(option: str, value: Any) -> Optional[int]: ... +def validate_string(option: str, value: Any) -> str: ... +def validate_string_or_none(option: str, value: Any) -> Optional[str]: ... +def validate_int_or_basestring(option: str, value: Any) -> Union[int, str]: ... +def validate_positive_float(option: str, value: Any) -> float: ... +def validate_positive_float_or_zero(option: str, value: Any) -> float: ... +def validate_timeout_or_none(option: str, value: Any) -> Optional[float]: ... +def validate_timeout_or_zero(option: str, value: Any) -> float: ... +def validate_max_staleness(option: str, value: Any) -> int: ... +def validate_read_preference(dummy: Any, value: Any) -> _ServerMode: ... +def validate_read_preference_mode(dummy: Any, value: Any) -> _ServerMode: ... +def validate_auth_mechanism(option: str, value: Any) -> str: ... +def validate_uuid_representation(dummy: Any, value: Any) -> int: ... +def validate_read_preference_tags(name: str, value: Any) -> List[Dict[str, str]]: ... +def validate_auth_mechanism_properties(option: str, value: Any) -> Dict[str, Union[bool, str]]: ... +_DocumentClass = TypeVar('_DocumentClass', Type[RawBSONDocument[str, Any]], Type[MutableMapping[str, Any]]) +def validate_document_class(option: str, value: _DocumentClass) -> _DocumentClass: ... +def validate_list(option: str, value: Any) -> List[Any]: ... +def validate_is_mapping(option: str, value: Any) -> Dict[Any, Any]: ... +def validate_is_document_type(option: str, value: Any) -> None: ... +def validate_appname_or_none(option: str, value: Any) -> Optional[str]: ... +def validate_ok_for_replace(replacement: Any) -> None: ... +def validate_ok_for_update(update: Any) -> None: ... +def validate_unicode_decode_error_handler(dummy: Any, value: str) -> str: ... +def validate_tzinfo(dummy: Any, value: Any) -> Optional[datetime.tzinfo]: ... +URI_VALIDATORS: Dict[str, Callable[..., Any]] = ... +TIMEOUT_VALIDATORS: Dict[str, Callable[..., Any]] = ... +KW_VALIDATORS: Dict[str, Callable[..., Any]] = ... +VALIDATORS: Dict[str, Callable[..., Any]] = ... +_AUTH_OPTIONS: FrozenSet[str] = ... +def validate_auth_option(option: str, value: Any) -> Tuple[str, Any]: ... +def validate(option: str, value: Any) -> Tuple[str, Any]: ... +def get_validated_options(options: Mapping[str, Any], warn: bool = ...) -> Dict[str, Any]: ... +class BaseObject(object): + def __init__( + self, + codec_options: CodecOptions, + read_preference: _ServerMode, + write_concern: WriteConcern, + read_concern: ReadConcern) -> None: ... + @property + def codec_options(self) -> CodecOptions: ... + @property + def write_concern(self) -> WriteConcern: ... + @property + def read_preference(self) -> _ServerMode: ... + @property + def read_concern(self) -> ReadConcern: ... diff --git a/pymongo/compression_support.pyi b/pymongo/compression_support.pyi new file mode 100644 index 0000000000..54b5b81aa0 --- /dev/null +++ b/pymongo/compression_support.pyi @@ -0,0 +1,27 @@ +# Stubs for pymongo.compression_support (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from typing import Any, Iterable, List, Sequence, Union + +def validate_compressors(dummy: Any, value: Union[str, Iterable[str]]) -> List[str]: ... +def validate_zlib_compression_level(option: str, value: Any) -> int: ... + +class CompressionSettings: + compressors: Sequence[str] = ... + zlib_compression_level: int = ... + def __init__(self, compressors: Sequence[str], zlib_compression_level: int) -> None: ... + def get_compression_context(self, compressors: Sequence[str]) -> Union[SnappyContext, ZlibContext]: ... + +class SnappyContext: + compressor_id: int = ... + @staticmethod + def compress(data: bytes) -> bytes: ... + +class ZlibContext: + compressor_id: int = ... + @staticmethod + def compress(data: bytes) -> bytes: ... + def __init__(self, level: int) -> None: ... + +def decompress(data: bytes, compressor_id: int) -> bytes: ... diff --git a/pymongo/cursor.pyi b/pymongo/cursor.pyi new file mode 100644 index 0000000000..5309a24add --- /dev/null +++ b/pymongo/cursor.pyi @@ -0,0 +1,92 @@ +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +from pymongo.client_session import ClientSession +from pymongo.collation import Collation +from pymongo.collection import Collection +from pymongo.message import _GetMore, _Query +from pymongo.pool import Pool, SocketInfo + +_QUERY_OPTIONS: Dict[str, int] = ... +class CursorType(object): + NON_TAILABLE: int = ... + TAILABLE: int = ... + TAILABLE_AWAIT: int = ... + EXHAUST: int = ... + +class _SocketManager: + def __init__(self, sock: SocketInfo, pool: Pool) -> None: ... + def __del__(self) -> None: ... + def close(self) -> None: ... + +class Cursor(object): + def __init__( + self, + collection: Collection, + filter: Mapping[str, Any] = ..., + projection: Mapping[str, Any] = ..., + skip: int = ..., + limit: int = ..., + no_cursor_timeout: bool = ..., + cursor_type: int = ..., + sort: Optional[Sequence[Tuple[str, Any]]] = ..., + allow_partial_results: bool = ..., + oplog_replay: bool = ..., + modifiers: Optional[Mapping[str, Any]] = ..., + batch_size: int = ..., + manipulate: bool = ..., + collation: Optional[Mapping[str, Any]] = ..., + hint: Optional[Union[str, Tuple[str, Union[int, str]]]] = ..., + max_scan: Optional[int] = ..., + max_time_ms: Optional[int] = ..., + max: Optional[Sequence[Tuple[str, int]]] = ..., + min: Optional[Sequence[Tuple[str, int]]] = ..., + return_key: bool = ..., + show_record_id: bool = ..., + snapshot: bool = ..., + comment: Optional[Union[str, Mapping[str, Any]]] = ..., + session: Optional[ClientSession] = ...) -> None: ... + @property + def collection(self) -> Collection: ... + @property + def retrieved(self) -> int: ... + def __del__(self) -> None: ... + def rewind(self) -> 'Cursor': ... + def clone(self) -> 'Cursor': ... + def close(self) -> None: ... + def add_option(self, mask: int) -> 'Cursor': ... + def remove_option(self, mask: int) -> 'Cursor': ... + def limit(self, limit: int) -> 'Cursor': ... + def batch_size(self, batch_size: int) -> 'Cursor': ... + def skip(self, skip: int) -> 'Cursor': ... + def max_time_ms(self, max_time_ms: int) -> 'Cursor': ... + def max_await_time_ms(self, max_await_time_ms: int) -> 'Cursor': ... + def __getitem__(self, index: Union[int, Sequence[int]]) -> Union['Cursor', Dict[str, Any]]: ... + def max_scan(self, max_scan: int) -> 'Cursor': ... + def max(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... + def min(self, spec: Sequence[Tuple[str, int]]) -> 'Cursor': ... + def sort( + self, + key_or_list: Union[str, Sequence[Tuple[str, Union[int, str]]]], + direction: Optional[Union[int, str]] = ...) -> 'Cursor': ... + def count(self, with_limit_and_skip: bool = ...) -> int: ... + def distinct(self, key: str) -> List[Any]: ... + def explain(self) -> Dict[str, Any]: ... + def hint(self, index: Union[str, Tuple[str, Union[int, str]]]) -> Cursor: ... + def comment(self, comment: Union[str, Mapping[str, Any]]) -> 'Cursor': ... + def where(self, code: str) -> 'Cursor': ... + def collation(self, collation: Collation) -> 'Cursor': ... + @property + def alive(self) -> bool: ... + @property + def cursor_id(self) -> int: ... + @property + def address(self) -> Tuple[str, int]: ... + def __iter__(self) -> 'Cursor': ... + def next(self) -> Dict[str, Any]: ... + def __next__(self) -> Dict[str, Any]: ... + def __enter__(self) -> 'Cursor': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + def __copy__(self) -> 'Cursor': ... + def __deepcopy__(self, memo: Any) -> 'Cursor': ... + +class RawBatchCursor(Cursor): ... diff --git a/pymongo/cursor_manager.pyi b/pymongo/cursor_manager.pyi new file mode 100644 index 0000000000..a6df6e48f9 --- /dev/null +++ b/pymongo/cursor_manager.pyi @@ -0,0 +1,8 @@ +from typing import Tuple + +from pymongo import MongoClient + + +class CursorManager(object): + def __init__(self, client: MongoClient) -> None: ... + def close(self, cursor_id: int, address: Tuple[str, int]) -> None: ... diff --git a/pymongo/database.pyi b/pymongo/database.pyi new file mode 100644 index 0000000000..1d0c46902f --- /dev/null +++ b/pymongo/database.pyi @@ -0,0 +1,133 @@ +from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Union + +from bson import CodecOptions, DBRef +from bson.timestamp import Timestamp +from pymongo import MongoClient, common +from pymongo.change_stream import DatabaseChangeStream +from pymongo.client_session import ClientSession +from pymongo.collation import Collation +from pymongo.collection import Collection +from pymongo.command_cursor import CommandCursor +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.son_manipulator import SONManipulator +from pymongo.write_concern import WriteConcern + + +class Database(common.BaseObject): + def __init__( + self, + client: MongoClient, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> None: ... + def add_son_manipulator(self, manipulator: SONManipulator) -> None: ... + @property + def system_js(self) -> SystemJS: ... + @property + def client(self) -> MongoClient: ... + @property + def name(self) -> str: ... + @property + def incoming_manipulators(self) -> List[str]: ... + @property + def incoming_copying_manipulators(self) -> List[str]: ... + @property + def outgoing_manipulators(self) -> List[str]: ... + @property + def outgoing_copying_manipulators(self) -> List[str]: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __repr__(self) -> str: ... + def __getattr__(self, name: str) -> Collection: ... + def __getitem__(self, name: str) -> Collection: ... + def get_collection( + self, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> Collection: ... + def create_collection( + self, + name: str, + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Collection: ... + def watch( + self, + pipeline: Optional[Sequence[Mapping[str, Any]]], + full_document: str = ..., + resume_after: Optional[str] = ..., + max_await_time_ms: Optional[int] = ..., + batch_size: Optional[int] = ..., + collation: Optional[Collation] = ..., + start_at_operation_time: Optional[Timestamp] = ..., + session: Optional[ClientSession] = ...) -> DatabaseChangeStream: ... + def command( + self, + command: Union[str, Mapping[str, Any]], + value: int = ..., + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + read_preference: _ServerMode = ..., + codec_options: CodecOptions = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> Any: ... + def list_collections(self, session: Optional[ClientSession] = ..., **kwargs: Any) -> CommandCursor: ... + def list_collection_names(self, session: Optional[ClientSession] = ...) -> List[str]: ... + def collection_names(self, include_system_collections: bool = ..., session: Optional[ClientSession] = ...) -> List[str]: ... + def drop_collection( + self, + name_or_collection: Union[str, Collection], + session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def validate_collection( + self, + name_or_collection: Union[str, Collection], + scandata: bool = ..., + full: bool = ..., + session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def current_op(self, include_all: bool = ..., session: Optional[ClientSession] = ...) -> Dict[str, Any]: ... + def profiling_level(self, session: Optional[ClientSession] = ...) -> int: ... + def set_profiling_level(self, level: int, slow_ms: Optional[int] = ..., session: Optional[ClientSession] = ...) -> None: ... + def profiling_info(self, session: Optional[ClientSession] = ...) -> List[Any]: ... + def error(self) -> Any: ... + def last_status(self) -> Any: ... + def previous_error(self) -> Any: ... + def reset_error_history(self) -> None: ... + def __iter__(self) -> 'Database': ... + def __next__(self) -> None: ... + def add_user( + self, + name: str, + password: Optional[str] = ..., + read_only: Optional[bool] = ..., + session: Optional[ClientSession] = ..., + **kwargs: Any) -> None: ... + def remove_user(self, name: str, session: Optional[ClientSession] = ...) -> None: ... + def authenticate( + self, + name: Optional[str] = ..., + password: Optional[str] = ..., + source: Optional[str] = ..., + mechanism: str = ..., + **kwargs: Any) -> bool: ... + def logout(self) -> None: ... + def dereference(self, dbref: DBRef, session: Optional[ClientSession] = ..., **kwargs: Any) -> Dict[str, Any]: ... + def eval(self, code: str, *args: Any) -> Any: ... + +class SystemJS(object): + def __init__(self, database: Database) -> None: ... + def __setattr__(self, name: str, code: str) -> None: ... + def __setitem__(self, name: str, code: str) -> None: ... + def __delattr__(self, name: str) -> None: ... + def __delitem__(self, name: str) -> None: ... + def __getattr__(self, name: str) -> Callable[..., Any]: ... + def __getitem__(self, name: str) -> Callable[..., Any]: ... + def list(self) -> List[str]: ... diff --git a/pymongo/driver_info.pyi b/pymongo/driver_info.pyi new file mode 100644 index 0000000000..351cfe955b --- /dev/null +++ b/pymongo/driver_info.pyi @@ -0,0 +1,4 @@ +from typing import Optional + +class DriverInfo: + def __new__(cls, name: Optional[str] = ..., version: Optional[str] = ..., platform: Optional[str] = ...) -> DriverInfo: ... diff --git a/pymongo/errors.pyi b/pymongo/errors.pyi new file mode 100644 index 0000000000..59d27b2d28 --- /dev/null +++ b/pymongo/errors.pyi @@ -0,0 +1,39 @@ +from bson.errors import InvalidDocument as InvalidDocument + +from typing import Any, Dict, Iterable, Mapping, Optional + +class PyMongoError(Exception): + def __init__(self, message: str = ..., error_labels: Optional[Iterable[str]] = ...) -> None: ... + def has_error_label(self, label: str) -> bool: ... + +class ProtocolError(PyMongoError): ... +class ConnectionFailure(PyMongoError): ... +class AutoReconnect(ConnectionFailure): + def __init__(self, message: str = ..., errors: Any = ...) -> None: ... + details: Any + errors: Any + +class NetworkTimeout(AutoReconnect): ... +class NotMasterError(AutoReconnect): ... +class ServerSelectionTimeoutError(AutoReconnect): ... +class ConfigurationError(PyMongoError): ... +class OperationFailure(PyMongoError): + def __init__(self, error: str, code: Optional[int] = ..., details: Optional[Mapping[str, Any]] = ...) -> None: ... + @property + def code(self) -> int: ... + @property + def details(self) -> Dict[str, Any]: ... +class CursorNotFound(OperationFailure): ... +class ExecutionTimeout(OperationFailure): ... +class WriteConcernError(OperationFailure): ... +class WriteError(OperationFailure): ... +class WTimeoutError(WriteConcernError): ... +class DuplicateKeyError(WriteError): ... +class BulkWriteError(OperationFailure): + def __init__(self, results: Mapping[str, Any]) -> None: ... +class InvalidOperation(PyMongoError): ... +class InvalidName(PyMongoError): ... +class CollectionInvalid(PyMongoError): ... +class InvalidURI(ConfigurationError): ... +class ExceededMaxWaiters(Exception): ... +class DocumentTooLarge(InvalidDocument): ... diff --git a/pymongo/ismaster.pyi b/pymongo/ismaster.pyi new file mode 100644 index 0000000000..7b4cee03c3 --- /dev/null +++ b/pymongo/ismaster.pyi @@ -0,0 +1,39 @@ +from typing import Any, Dict, List, Mapping, Optional, Tuple + + +class IsMaster(object): + def __init__(self, doc: Mapping[str, Any]) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... + @property + def server_type(self) -> int: ... + @property + def all_hosts(self) -> List[Any]: ... + @property + def tags(self) -> Dict[str, Any]: ... + @property + def primary(self) -> Optional[Tuple[str, int]]: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + @property + def max_wire_version(self) -> int: ... + @property + def set_version(self) -> Any: ... + @property + def election_id(self) -> Any: ... + @property + def is_writable(self) -> bool: ... + @property + def is_readable(self) -> bool: ... + @property + def me(self) -> Optional[Tuple[str, int]]: ... + @property + def last_write_date(self) -> Any: ... diff --git a/pymongo/max_staleness_selectors.pyi b/pymongo/max_staleness_selectors.pyi new file mode 100644 index 0000000000..00493d80b2 --- /dev/null +++ b/pymongo/max_staleness_selectors.pyi @@ -0,0 +1,6 @@ +from pymongo.server_selectors import Selection + + +IDLE_WRITE_PERIOD: int = ... +SMALLEST_MAX_STALENESS: int = ... +def select(max_staleness: int, selection: Selection) -> Selection: ... diff --git a/pymongo/message.pyi b/pymongo/message.pyi new file mode 100644 index 0000000000..69f1227b30 --- /dev/null +++ b/pymongo/message.pyi @@ -0,0 +1,114 @@ +import datetime +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from bson import CodecOptions +from pymongo.database import Database +from pymongo.collection import Collection +from pymongo.collation import Collation +from pymongo.monitoring import _EventListeners +from pymongo.pool import SocketInfo +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode + +MAX_INT32: int = ... +MIN_INT32: int = ... + +class _Query(object): + def __init__( + self, + flags: bool, + db: Database, + coll: Collection, + ntoskip: int, + spec: Mapping[str, Any], + fields: Union[Mapping[str, bool], Sequence[str]], + codec_options: CodecOptions, + read_preference: _ServerMode, + limit: int, + batch_size: int, + read_concern: ReadConcern, + collation: Collation) -> None: ... + def as_command(self) -> Dict[str, Any]: ... + def get_message(self, set_slave_ok: bool, is_mongos: bool, use_cmd: bool = ...) -> Tuple[int, bytes, int]: ... + +class _GetMore(object): + def __init__( + self, + db: Database, + coll: Collection, + ntoreturn: int, + cursor_id: int, + codec_options: CodecOptions, + max_await_time_ms: Optional[int] = ...) -> None: ... + def as_command(self) -> Mapping[str, Any]: ... + def get_message(self, dummy0: Any, dummy1: Any, use_cmd: bool = ...) -> Tuple[Any]: ... + +class _CursorAddress(Tuple[str, int]): + def __new__(cls, address: Tuple[str, int], namespace: Any) -> '_CursorAddress': ... + @property + def namespace(self) -> Any: ... + def __hash__(self) -> int: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +def __last_error(namespace: str, args: Dict[str, Any]) -> Tuple[int, bytes, int]: ... +def __pack_message(operation: Union[_Query, _GetMore], data: bytes) -> Tuple[int, bytes]: ... +def insert( + collection_name: str, + docs: Mapping[str, Any], + check_keys: bool, + safe: bool, + last_error_args: Mapping[str, Any], + continue_on_error: bool, + opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def update( + collection_name: str, + upsert: bool, + multi: bool, + spec: Mapping[str, Any], + doc: Mapping[str, Any], + safe: bool, + last_error_args: Mapping[str, Any], + check_keys: bool, + opts: CodecOptions) -> Tuple[int, bytes, int]: ... +def query( + options: int, + collection_name: str, + num_to_skip: int, + num_to_return: int, + query: Mapping[str, Any], + field_selector: Mapping[str, Any], + opts: CodecOptions, + check_keys: bool = ...) -> Tuple[int, bytes, int]: ... +def get_more(collection_name: str, num_to_return: int, cursor_id: int) -> Tuple[int, bytes]: ... +def delete( + collection_name: str, + spec: Mapping[str, Any], + safe: bool, + last_error_args: Mapping[str, Any], + opts: CodecOptions, flags: int = ...) -> Tuple[int, bytes, int]: ... +def kill_cursors(cursor_ids: Sequence[int]) -> Tuple[int, bytes]: ... +_FIELD_MAP: Dict[str, str] = ... + +class _BulkWriteContext(object): + def __init__( + self, + database_name: str, + command: Mapping[str, Any], + sock_info: SocketInfo, + operation_id: int, + listeners: _EventListeners) -> None: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + def legacy_write( + self, + request_id: int, + msg: bytes, + max_doc_size: int, + acknowledged: bool, + docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... + def write_command(self, request_id: int, msg: bytes, docs: Sequence[Mapping[str, Any]]) -> Dict[str, Any]: ... diff --git a/pymongo/mongo_client.pyi b/pymongo/mongo_client.pyi new file mode 100644 index 0000000000..dbd9d7bef2 --- /dev/null +++ b/pymongo/mongo_client.pyi @@ -0,0 +1,91 @@ +import contextlib +from typing import (Any, Callable, Dict, FrozenSet, List, Optional, + Set, Sequence, Tuple, Type, Union) + +from bson import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.common import BaseObject +from pymongo.cursor_manager import CursorManager +from pymongo.database import Database +from pymongo.message import _CursorAddress, _GetMore, _Query +from pymongo.monitoring import _EventListeners +from pymongo.pool import SocketInfo +from pymongo.topology import Topology +from pymongo.write_concern import WriteConcern +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.response import Response +from pymongo.server import Server + +class MongoClient(BaseObject): + HOST: str = ... + PORT: int = ... + def __init__( + self, + host: str = ..., + port: int = ..., + document_class: Type[Any] = ..., + tz_aware: Optional[bool] = ..., + connect: Optional[bool] = ..., **kwargs: Any) -> None: ... + @property + def event_listeners(self) -> _EventListeners: ... + @property + def address(self) -> Union[Tuple[str, int], None]: ... + @property + def primary(self) -> Union[Tuple[str, int], None]: ... + @property + def secondaries(self) -> Union[Set[str], Set[Tuple[str, int]]]: ... + @property + def arbiters(self) -> Union[Set[str], Set[Tuple[str, int]]]: ... + @property + def is_primary(self) -> bool: ... + @property + def is_mongos(self) -> bool: ... + @property + def max_pool_size(self) -> int: ... + @property + def min_pool_size(self) -> int: ... + @property + def max_idle_time_ms(self) -> int: ... + @property + def nodes(self) -> FrozenSet[Tuple[str, int]]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def close(self) -> None: ... + def set_cursor_manager(self, manager_class: CursorManager) -> None: ... + def __reset_server(self, address: Tuple[str, int]) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __repr__(self) -> str: ... + def __getattr__(self, name: str) -> Database: ... + def __getitem__(self, name: str) -> Database: ... + def close_cursor(self, cursor_id: int, address: Optional[Tuple[str, int]] = ...) -> None: ... + def kill_cursors(self, cursor_ids: Sequence[int], address: Optional[Tuple[str, int]] = ...) -> None: ... + def server_info(self) -> Dict[str, Any]: ... + def database_names(self) -> List[str]: ... + def drop_database(self, name_or_database: Union[str, Database]) -> None: ... + def get_default_database(self) -> Database: ... + def get_database( + self, + name: Optional[str] = ..., + codec_options: Optional[CodecOptions] = ..., + read_preference: Optional[_ServerMode] = ..., + write_concern: Optional[WriteConcern] = ..., + read_concern: Optional[ReadConcern] = ...) -> Database: ... + @property + def is_locked(self) -> bool: ... + def fsync(self, **kwargs: Any) -> Dict[str, Any]: ... + def unlock(self) -> None: ... + def __enter__(self) -> 'MongoClient': ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: ... + def __iter__(self) -> 'MongoClient': ... + def __next__(self) -> None: ... diff --git a/pymongo/mongo_replica_set_client.pyi b/pymongo/mongo_replica_set_client.pyi new file mode 100644 index 0000000000..4625ed1e89 --- /dev/null +++ b/pymongo/mongo_replica_set_client.pyi @@ -0,0 +1,8 @@ +from typing import Any + +from pymongo import mongo_client + + +class MongoReplicaSetClient(mongo_client.MongoClient): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def __repr__(self) -> str: ... diff --git a/pymongo/monitor.pyi b/pymongo/monitor.pyi new file mode 100644 index 0000000000..be8fabe66e --- /dev/null +++ b/pymongo/monitor.pyi @@ -0,0 +1,20 @@ +from typing import Any, Optional, Tuple + +from pymongo.ismaster import IsMaster +from pymongo.pool import Pool, SocketInfo +from pymongo.server_description import ServerDescription +from pymongo.settings import TopologySettings +from pymongo.topology import Topology + + +class Monitor(object): + def __init__( + self, + server_description: ServerDescription, + topology: Topology, + pool: Pool, + topology_settings: TopologySettings) -> None: ... + def open(self) -> None: ... + def close(self) -> None: ... + def join(self, timeout: Optional[int] = ...) -> None: ... + def request_check(self) -> None: ... diff --git a/pymongo/monitoring.pyi b/pymongo/monitoring.pyi new file mode 100644 index 0000000000..75b8bce2ab --- /dev/null +++ b/pymongo/monitoring.pyi @@ -0,0 +1,194 @@ +from typing import (Any, Dict, Mapping, NamedTuple, Optional, Set, Sequence, + Tuple, Union) +import datetime + +from pymongo.ismaster import IsMaster +from pymongo.server_description import ServerDescription + + +_Listeners = NamedTuple('_Listeners', [ + ('command_listeners', Sequence[CommandListener]), + ('server_listeners', Sequence[ServerListener]), + ('server_heartbeat_listeners', Sequence[ServerHeartbeatListener]), + ('topology_listeners', Sequence[TopologyListener]), +]) + +class _EventListener(object): ... + +class CommandListener(_EventListener): + def started(self, event: CommandStartedEvent) -> None: ... + def succeeded(self, event: CommandSucceededEvent) -> None: ... + def failed(self, event: CommandFailedEvent) -> None: ... + +class ServerHeartbeatListener(_EventListener): + def started(self, event: ServerHeartbeatStartedEvent) -> None: ... + def succeeded(self, event: ServerHeartbeatSucceededEvent) -> None: ... + def failed(self, event: ServerHeartbeatFailedEvent) -> None: ... + +class TopologyListener(_EventListener): + def opened(self, event: _ServerEvent) -> None: ... + def description_changed(self, event: _ServerEvent) -> None: ... + def closed(self, event: _ServerEvent) -> None: ... + +class ServerListener(_EventListener): + def opened(self, event: _ServerEvent) -> None: ... + def description_changed(self, event: _ServerEvent) -> None: ... + def closed(self, event: _ServerEvent) -> None: ... + +def register(listener: _EventListener) -> None: ... + +class _CommandEvent(object): + def __init__(self, command_name: str, request_id: int, connection_id: Tuple[str, int], operation_id: int) -> None: ... + @property + def command_name(self) -> str: ... + @property + def request_id(self) -> int: ... + @property + def connection_id(self) -> Tuple[str, int]: ... + @property + def operation_id(self) -> int: ... + +class CommandStartedEvent(_CommandEvent): + def __init__(self, command: Mapping[str, Any], database_name: str, *args: Any) -> None: ... + @property + def command(self) -> Dict[str, Any]: ... + @property + def database_name(self) -> str: ... + +class CommandSucceededEvent(_CommandEvent): + def __init__( + self, + duration: datetime.timedelta, + reply: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + operation_id: int) -> None: ... + @property + def duration_micros(self) -> int: ... + @property + def reply(self) -> Dict[str, Any]: ... + +class CommandFailedEvent(_CommandEvent): + def __init__(self, duration: datetime.timedelta, failure: Mapping[str, Any], *args: Any) -> None: ... + @property + def duration_micros(self) -> int: ... + @property + def failure(self) -> Dict[str, Any]: ... + +class _ServerEvent(object): + def __init__(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + @property + def server_address(self) -> Tuple[str, int]: ... + @property + def topology_id(self) -> int: ... + +class ServerDescriptionChangedEvent(_ServerEvent): + def __init__(self, previous_description: ServerDescription, new_description: ServerDescription, *args: Any) -> None: ... + @property + def previous_description(self) -> ServerDescription: ... + @property + def new_description(self) -> ServerDescription: ... + +class ServerOpeningEvent(_ServerEvent): ... + +class ServerClosedEvent(_ServerEvent): ... + +class TopologyEvent(object): + def __init__(self, topology_id: int) -> None: ... + @property + def topology_id(self) -> int: ... + +class TopologyDescriptionChangedEvent(TopologyEvent): + def __init__(self, previous_description: ServerDescription, + new_description: ServerDescription, *args: Any) -> None: ... + @property + def previous_description(self) -> ServerDescription: ... + @property + def new_description(self) -> ServerDescription: ... + +class TopologyOpenedEvent(TopologyEvent): ... + +class TopologyClosedEvent(TopologyEvent): ... + +class _ServerHeartbeatEvent(object): + def __init__(self, connection_id: Tuple[str, int]) -> None: ... + @property + def connection_id(self) -> Tuple[str, int]: ... + +class ServerHeartbeatStartedEvent(_ServerHeartbeatEvent): ... + +class ServerHeartbeatSucceededEvent(_ServerHeartbeatEvent): + def __init__(self, duration: int, reply: IsMaster, *args: Any) -> None: ... + @property + def duration(self) -> int: ... + @property + def reply(self) -> IsMaster: ... + +class ServerHeartbeatFailedEvent(_ServerHeartbeatEvent): + def __init__(self, duration: int, reply: Exception, *args: Any) -> None: ... + @property + def duration(self) -> int: ... + @property + def reply(self) -> Exception: ... + +class _EventListeners(object): + def __init__(self, listeners: Sequence[_EventListener]) -> None: ... + @property + def enabled_for_commands(self) -> bool: ... + @property + def enabled_for_server(self) -> bool: ... + @property + def enabled_for_server_heartbeat(self) -> bool: ... + @property + def enabled_for_topology(self) -> bool: ... + def event_listeners(self) -> Tuple[Sequence[Any]]: ... + def publish_command_start( + self, + command: Mapping[str, Any], + database_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... + def publish_command_success( + self, + duration: datetime.timedelta, + reply: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... + def publish_command_failure( + self, + duration: datetime.timedelta, + failure: Mapping[str, Any], + command_name: str, + request_id: int, + connection_id: Tuple[str, int], + op_id: Optional[int] = ...) -> None: ... + def publish_server_heartbeat_started(self, connection_id: Tuple[str, int]) -> None: ... + def publish_server_heartbeat_succeeded( + self, + connection_id: Tuple[str, int], + duration: int, + reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_heartbeat_failed( + self, + connection_id: Tuple[str, int], + duration: int, + reply: Union[Mapping[str, Any], Exception]) -> None: ... + def publish_server_opened(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_server_closed(self, server_address: Tuple[str, int], topology_id: int) -> None: ... + def publish_server_description_changed( + self, + previous_description: ServerDescription, + new_description: ServerDescription, + server_address: Tuple[str, int], + topology_id: int) -> None: ... + def publish_topology_opened(self, topology_id: int) -> None: ... + def publish_topology_closed(self, topology_id: int) -> None: ... + def publish_topology_description_changed( + self, + previous_description: ServerDescription, + new_description: ServerDescription, + topology_id: int) -> None: ... diff --git a/pymongo/monotonic.pyi b/pymongo/monotonic.pyi new file mode 100644 index 0000000000..f0bb23fff8 --- /dev/null +++ b/pymongo/monotonic.pyi @@ -0,0 +1 @@ +def time() -> float: ... diff --git a/pymongo/network.pyi b/pymongo/network.pyi new file mode 100644 index 0000000000..5c6643659d --- /dev/null +++ b/pymongo/network.pyi @@ -0,0 +1,32 @@ +from socket import socket +from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union + +from bson import CodecOptions +from pymongo.collation import Collation +from pymongo.monitoring import _EventListeners +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode + + +def command( + sock: socket, + dbname: str, + spec: Mapping[str, Any], + slave_ok: bool, + is_mongos: bool, + read_preference: _ServerMode, + codec_options: CodecOptions, + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + address: Optional[Tuple[str, int]] = ..., + check_keys: bool = ..., + listeners: Optional[_EventListeners] = ..., + max_bson_size: Optional[int] = ..., + read_concern: ReadConcern = ..., + parse_write_concern_error: bool = ..., + collation: Optional[Collation] = ...) -> Dict[str, Any]: ... +def receive_message(sock: socket, operation: int, request_id: int, max_message_size: int = ...) -> bytes: ... + +class SocketChecker(object): + def __init__(self) -> None: ... + def socket_closed(self, sock: socket) -> bool: ... diff --git a/pymongo/operations.pyi b/pymongo/operations.pyi new file mode 100644 index 0000000000..25df024990 --- /dev/null +++ b/pymongo/operations.pyi @@ -0,0 +1,57 @@ +from pymongo.collation import Collation +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +class _WriteOp(object): + def __init__( + self, + filter: Optional[Mapping[str, Any]] = ..., + doc: Optional[Mapping[str, Any]] = ..., + upsert: Optional[bool] = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +class InsertOne(_WriteOp): + def __init__(self, document: Mapping[str, Any]) -> None: ... + def __repr__(self) -> str: ... + +class DeleteOne(_WriteOp): + def __init__(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> None: ... + def __repr__(self) -> str: ... + +class DeleteMany(_WriteOp): + def __init__(self, filter: Mapping[str, Any], collation: Optional[Collation] = ...) -> None: ... + def __repr__(self) -> str: ... + +class ReplaceOne(_WriteOp): + def __init__( + self, + filter: Mapping[str, Any], + replacement: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ...) -> None: ... + def __repr__(self) -> str: ... + +class UpdateOne(_WriteOp): + def __init__( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ...) -> None: ... + def __repr__(self) -> str: ... + +class UpdateMany(_WriteOp): + def __init__( + self, + filter: Mapping[str, Any], + update: Mapping[str, Any], + upsert: bool = ..., + collation: Optional[Collation] = ..., + array_filters: Optional[List[Mapping[str, Any]]] = ...) -> None: ... + def __repr__(self) -> str: ... + +class IndexModel(object): + def __init__(self, keys: Union[str, Sequence[Tuple[str, Union[int, str]]]], **kwargs: Any) -> None: ... + @property + def document(self) -> Dict[str, Any]: ... diff --git a/pymongo/periodic_executor.pyi b/pymongo/periodic_executor.pyi new file mode 100644 index 0000000000..f95eee3198 --- /dev/null +++ b/pymongo/periodic_executor.pyi @@ -0,0 +1,10 @@ +import weakref +from typing import Any, Callable, Optional + + +class PeriodicExecutor(object): + def __init__(self, interval: int, min_interval: int, target: Callable[..., Any], name: Optional[str] = ...) -> None: ... + def open(self) -> None: ... + def close(self, dummy: Optional[Any] = ...) -> None: ... + def join(self, timeout: Optional[int] = ...) -> None: ... + def wake(self) -> None: ... diff --git a/pymongo/pool.pyi b/pymongo/pool.pyi new file mode 100644 index 0000000000..d3ee3ff785 --- /dev/null +++ b/pymongo/pool.pyi @@ -0,0 +1,102 @@ +import contextlib +from socket import socket +from ssl import SSLContext +from typing import Any, Dict, Iterator, Mapping, Optional, Sequence, Tuple, Union + +from bson.codec_options import CodecOptions +from pymongo.auth import MongoCredential +from pymongo.collation import Collation +from pymongo.compression_support import CompressionSettings +from pymongo.driver_info import DriverInfo +from pymongo.ismaster import IsMaster +from pymongo.monitoring import _EventListeners +from pymongo.read_concern import ReadConcern +from pymongo.read_preferences import _ServerMode +from pymongo.write_concern import WriteConcern + + +class PoolOptions(object): + def __init__( + self, + max_pool_size: int = ..., + min_pool_size: int = ..., + max_idle_time_ms: Optional[int] = ..., + connect_timeout: Optional[int] = ..., + socket_timeout: Optional[int] = ..., + wait_queue_timeout: Optional[int] = ..., + wait_queue_multiple: Optional[int] = ..., + ssl_context: Union[SSLContext, None] = ..., + ssl_match_hostname: bool = ..., + socket_keepalive: bool = ..., + event_listeners: Optional[_EventListeners] = ..., + appname: Optional[str] = ..., + driver: Optional[DriverInfo] = ..., + compression_settings: Optional[CompressionSettings] = ...) -> None: ... + @property + def max_pool_size(self) -> int: ... + @property + def min_pool_size(self) -> int: ... + @property + def max_idle_time_ms(self) -> int: ... + @property + def connect_timeout(self) -> int: ... + @property + def socket_timeout(self) -> int: ... + @property + def wait_queue_timeout(self) -> int: ... + @property + def wait_queue_multiple(self) -> int: ... + @property + def ssl_context(self) -> SSLContext: ... + @property + def ssl_match_hostname(self) -> bool: ... + @property + def socket_keepalive(self) -> bool: ... + @property + def event_listeners(self) -> _EventListeners: ... + @property + def appname(self) -> str: ... + @property + def metadata(self) -> Dict[str, Any]: ... + @property + def driver(self) -> DriverInfo: ... + @property + def compression_settings(self) -> CompressionSettings: ... + +class SocketInfo(object): + def __init__(self, sock: socket, pool: Pool, ismaster: IsMaster, address: Tuple[str, int]) -> None: ... + def command( + self, + dbname: str, + spec: Mapping[str, Any], + slave_ok: bool = ..., + read_preference: _ServerMode = ..., + codec_options: CodecOptions = ..., + check: bool = ..., + allowable_errors: Optional[Sequence[str]] = ..., + check_keys: bool = ..., + read_concern: ReadConcern = ..., + write_concern: Optional[WriteConcern] = ..., + parse_write_concern_error: bool = ..., + collation: Optional[Collation] = ...) -> Dict[str, MongoCredential]: ... + def send_message(self, message: bytes, max_doc_size: int) -> None: ... + def receive_message(self, operation: bytes, request_id: int) -> bytes: ... + def legacy_write(self, request_id: int, msg: bytes, max_doc_size: int, with_last_error: bool) -> Dict[str, Any]: ... + def write_command(self, request_id: int, msg: bytes) -> Dict[str, Any]: ... + def check_auth(self, all_credentials: Mapping[str, MongoCredential]) -> None: ... + def authenticate(self, credentials: MongoCredential) -> None: ... + def close(self) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __hash__(self) -> int: ... + def __repr__(self) -> str: ... + +class Pool: + def __init__(self, address: Tuple[str, int], options: PoolOptions, handshake: bool = ...) -> None: ... + def reset(self) -> None: ... + def remove_stale_sockets(self) -> None: ... + def connect(self) -> SocketInfo: ... + @contextlib.contextmanager + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> Iterator[SocketInfo]: ... + def return_socket(self, sock_info: SocketInfo) -> None: ... + def __del__(self) -> None: ... diff --git a/pymongo/py.typed b/pymongo/py.typed new file mode 100644 index 0000000000..e69de29bb2 diff --git a/pymongo/read_concern.pyi b/pymongo/read_concern.pyi new file mode 100644 index 0000000000..d213ad4326 --- /dev/null +++ b/pymongo/read_concern.pyi @@ -0,0 +1,14 @@ +from typing import Any, Dict, Optional + + +class ReadConcern(object): + def __init__(self, level: Optional[str] = ...) -> None: ... + @property + def level(self) -> str: ... + @property + def ok_for_legacy(self) -> bool: ... + @property + def document(self) -> Dict[str, str]: ... + def __eq__(self, other: Any) -> bool: ... + def __repr__(self) -> str: ... +DEFAULT_READ_CONCERN: ReadConcern = ... diff --git a/pymongo/read_preferences.pyi b/pymongo/read_preferences.pyi new file mode 100644 index 0000000000..00c91b4a44 --- /dev/null +++ b/pymongo/read_preferences.pyi @@ -0,0 +1,72 @@ +from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union + +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection + +_PRIMARY: int = ... +_PRIMARY_PREFERRED: int = ... +_SECONDARY: int = ... +_SECONDARY_PREFERRED: int = ... +_NEAREST: int = ... +_MONGOS_MODES: Tuple[str, ...] = ... + +class _ServerMode(object): + def __init__(self, mode: int, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... + @property + def name(self) -> str: ... + @property + def document(self) -> Dict[str, Union[str, List[Dict[str, Any]], int]]: ... + @property + def mode(self) -> int: ... + @property + def tag_sets(self) -> List[Dict[Any, Any]]: ... + @property + def max_staleness(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __getstate__(self) -> Dict[str, Union[int, List[Dict[Any, Any]]]]: ... + def __setstate__(self, value: Mapping[str, Union[int, Sequence[Mapping[Any, Any]]]]) -> None: ... + +class Primary(_ServerMode): + def __init__(self) -> None: ... + def __call__(self, selection: Selection) -> List[ServerDescription]: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + +class PrimaryPreferred(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... + def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... + +class Secondary(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., + max_staleness: int = ...) -> None: ... + def __call__(self, selection: Selection) -> Selection: ... + +class SecondaryPreferred(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... + def __call__(self, selection: Selection) -> Union[List[ServerDescription], Selection]: ... + +class Nearest(_ServerMode): + def __init__(self, tag_sets: Optional[Sequence[Mapping[str, Any]]] = ..., max_staleness: int = ...) -> None: ... + def __call__(self, selection: Selection) -> Selection: ... + +def make_read_preference(mode: int, tag_sets: Sequence[Mapping[str, Any]], max_staleness: int = ...) -> _ServerMode: ... +_MODES: Tuple[str, ...] = ... + +class ReadPreference(object): + PRIMARY: _ServerMode = ... + PRIMARY_PREFERRED: _ServerMode = ... + SECONDARY: _ServerMode = ... + SECONDARY_PREFERRED: _ServerMode = ... + NEAREST: _ServerMode = ... + +def read_pref_mode_from_name(name: str) -> int: ... + +class MovingAverage(object): + def __init__(self) -> None: ... + def add_sample(self, sample: int) -> None: ... + def get(self) -> Optional[float]: ... + def reset(self) -> None: ... diff --git a/pymongo/response.pyi b/pymongo/response.pyi new file mode 100644 index 0000000000..4b9a30945b --- /dev/null +++ b/pymongo/response.pyi @@ -0,0 +1,39 @@ +import datetime + +from typing import Tuple + +from pymongo.pool import Pool, SocketInfo + +class Response(object): + def __init__( + self, + data: bytes, + address: Tuple[str, int], + request_id: int, + duration: datetime.timedelta, + from_command: bool) -> None: ... + @property + def data(self) -> bytes: ... + @property + def address(self) -> Tuple[str, int]: ... + @property + def request_id(self) -> int: ... + @property + def duration(self) -> datetime.timedelta: ... + @property + def from_command(self) -> bool: ... + +class ExhaustResponse(Response): + def __init__( + self, + data: bytes, + address: Tuple[str, int], + socket_info: SocketInfo, + pool: Pool, + request_id: int, + duration: datetime.timedelta, + from_command: bool) -> None: ... + @property + def socket_info(self) -> SocketInfo: ... + @property + def pool(self) -> Pool: ... diff --git a/pymongo/results.pyi b/pymongo/results.pyi new file mode 100644 index 0000000000..4e0015354b --- /dev/null +++ b/pymongo/results.pyi @@ -0,0 +1,53 @@ +from typing import Any, Dict, List, Mapping, Sequence + + +class _WriteResult(object): + def __init__(self, acknowledged: bool) -> None: ... + @property + def acknowledged(self) -> bool: ... + +class InsertOneResult(_WriteResult): + def __init__(self, inserted_id: Sequence[Any], acknowledged: bool) -> None: ... + @property + def inserted_id(self) -> List[Any]: ... + +class InsertManyResult(_WriteResult): + def __init__(self, inserted_ids: Any, acknowledged: bool) -> None: ... + @property + def inserted_ids(self) -> Any: ... + +class UpdateResult(_WriteResult): + def __init__(self, raw_result: Mapping[str, Any], acknowledged: bool) -> None: ... + @property + def raw_result(self) -> Dict[str, Any]: ... + @property + def matched_count(self) -> int: ... + @property + def modified_count(self) -> int: ... + @property + def upserted_id(self) -> Any: ... + +class DeleteResult(_WriteResult): + def __init__(self, raw_result: Mapping[str, Any], acknowledged: bool) -> None: ... + @property + def raw_result(self) -> Dict[str, Any]: ... + @property + def deleted_count(self) -> int: ... + +class BulkWriteResult(_WriteResult): + def __init__(self, bulk_api_result: Mapping[str, Any], acknowledged: bool)\ + -> None: ... + @property + def bulk_api_result(self) -> Dict[str, Any]: ... + @property + def inserted_count(self) -> int: ... + @property + def matched_count(self) -> int: ... + @property + def modified_count(self) -> int: ... + @property + def deleted_count(self) -> int: ... + @property + def upserted_count(self) -> int: ... + @property + def upserted_ids(self) -> Dict[Any, Any]: ... diff --git a/pymongo/saslprep.pyi b/pymongo/saslprep.pyi new file mode 100644 index 0000000000..b09e563c98 --- /dev/null +++ b/pymongo/saslprep.pyi @@ -0,0 +1,3 @@ +from typing import Text + +def saslprep(data: Text) -> Text: ... diff --git a/pymongo/server.pyi b/pymongo/server.pyi new file mode 100644 index 0000000000..14c6232135 --- /dev/null +++ b/pymongo/server.pyi @@ -0,0 +1,50 @@ +import contextlib +import sys + +import sys +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue +from typing import Any, Callable, Iterator, Mapping, Optional, Sequence, Tuple, Union + +from bson import ObjectId +from pymongo.auth import MongoCredential +from pymongo.message import _GetMore, _Query +from pymongo.monitor import Monitor +from pymongo.monitoring import _EventListeners +from pymongo.pool import Pool, SocketInfo +from pymongo.response import Response +from pymongo.server_description import ServerDescription + + +class Server(object): + def __init__( + self, + server_description: ServerDescription, + pool: Pool, + monitor: Monitor, + topology_id: Optional[ObjectId] = ..., + listeners: Optional[_EventListeners] = ..., + events: Optional[Queue[Tuple[Callable[..., Any], Sequence[Any]]]] = ...) -> None: ... + def open(self) -> None: ... + def reset(self) -> None: ... + def close(self) -> None: ... + def request_check(self) -> None: ... + def send_message(self, message: Tuple[int, bytes], all_credentials: Mapping[str, MongoCredential]) -> None: ... + def send_message_with_response( + self, + operation: Union[_Query, _GetMore], + set_slave_okay: bool, + all_credentials: Mapping[str, MongoCredential], + listeners: _EventListeners, + exhaust: bool = ...) -> Response: ... + @contextlib.contextmanager + def get_socket(self, all_credentials: Mapping[str, MongoCredential], checkout: bool = ...) -> Iterator[SocketInfo]: ... + @property + def description(self) -> ServerDescription: ... + @description.setter + def description(self, server_description: ServerDescription) -> None: ... + @property + def pool(self) -> Pool: ... + def __str__(self) -> str: ... diff --git a/pymongo/server_description.pyi b/pymongo/server_description.pyi new file mode 100644 index 0000000000..e071cbc657 --- /dev/null +++ b/pymongo/server_description.pyi @@ -0,0 +1,60 @@ +import datetime +from typing import Any, Dict, Optional, Set, Tuple + +from pymongo.ismaster import IsMaster +from pymongo.server_type import SERVER_TYPE as SERVER_TYPE + + +class ServerDescription(object): + def __init__( + self, + address: Tuple[str, int], + ismaster: Optional[IsMaster] = ..., + round_trip_time: Optional[float] = ..., + error: Optional[Any] = ...) -> None: ... + @property + def address(self) -> Tuple[str, int]: ... + @property + def server_type(self) -> int: ... + @property + def server_type_name(self) -> str: ... + @property + def all_hosts(self) -> Set[Tuple[str, int]]: ... + @property + def tags(self) -> Dict[Any, Any]: ... + @property + def replica_set_name(self) -> Optional[str]: ... + @property + def primary(self) -> Optional[Tuple[str, int]]: ... + @property + def max_bson_size(self) -> int: ... + @property + def max_message_size(self) -> int: ... + @property + def max_write_batch_size(self) -> int: ... + @property + def min_wire_version(self) -> int: ... + @property + def max_wire_version(self) -> int: ... + @property + def set_version(self) -> int: ... + @property + def election_id(self) -> int: ... + @property + def election_tuple(self) -> Tuple[int, int]: ... + @property + def me(self) -> Tuple[str, int]: ... + @property + def last_write_date(self) -> Dict[Any, Any]: ... + @property + def last_update_time(self) -> float: ... + @property + def round_trip_time(self) -> float: ... + @property + def error(self) -> Any: ... + @property + def is_writable(self) -> bool: ... + @property + def is_readable(self) -> bool: ... + @property + def is_server_type_known(self) -> bool: ... diff --git a/pymongo/server_selectors.pyi b/pymongo/server_selectors.pyi new file mode 100644 index 0000000000..eaaaac5f7a --- /dev/null +++ b/pymongo/server_selectors.pyi @@ -0,0 +1,36 @@ +from typing import Any, Mapping, Sequence + +from pymongo.server_description import ServerDescription +from pymongo.topology_description import TopologyDescription + + +class Selection(object): + @classmethod + def from_topology_description(cls: type, topology_description: TopologyDescription) -> 'Selection': ... + def __init__( + self, + topology_description: TopologyDescription, + server_descriptions: Sequence[ServerDescription], + common_wire_version: int, + primary: ServerDescription) -> None: ... + def with_server_descriptions(self, server_descriptions: Sequence[ServerDescription]) -> 'Selection': ... + def secondary_with_max_last_write_date(self) -> ServerDescription: ... + @property + def primary_selection(self) -> 'Selection': ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def topology_type(self) -> int: ... + def __bool__(self) -> bool: ... + def __getitem__(self, item: int) -> ServerDescription: ... + +def any_server_selector(selection: Selection) -> Selection: ... +def readable_server_selector(selection: Selection) -> Selection: ... +def writable_server_selector(selection: Selection) -> Selection: ... +def secondary_server_selector(selection: Selection) -> Selection: ... +def arbiter_server_selector(selection: Selection) -> Selection: ... +def writable_preferred_server_selector(selection: Selection) -> Selection: ... +def apply_single_tag_set(tag_set: Mapping[str, Any], selection: Selection) -> Selection: ... +def apply_tag_sets(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... +def secondary_with_tags_server_selector(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... +def member_with_tags_server_selector(tag_sets: Sequence[Mapping[str, Any]], selection: Selection) -> Selection: ... diff --git a/pymongo/server_type.pyi b/pymongo/server_type.pyi new file mode 100644 index 0000000000..90534598c5 --- /dev/null +++ b/pymongo/server_type.pyi @@ -0,0 +1,14 @@ +from typing import NamedTuple + +ServerType = NamedTuple('ServerType', [ + ('Unknown', int), + ('Mongos', int), + ('RSPrimary', int), + ('RSSecondary', int), + ('RSArbiter', int), + ('RSOther', int), + ('RSGhost', int), + ('Standalone', int), +]) + +SERVER_TYPE: ServerType = ... diff --git a/pymongo/settings.pyi b/pymongo/settings.pyi new file mode 100644 index 0000000000..42e7eb9cbb --- /dev/null +++ b/pymongo/settings.pyi @@ -0,0 +1,42 @@ +import threading +from typing import Dict, List, Optional, Sequence, Tuple + +from pymongo.monitor import Monitor +from pymongo.pool import Pool, PoolOptions +from pymongo.server_description import ServerDescription + + +class TopologySettings(object): + def __init__( + self, + seeds: Optional[Sequence[Tuple[str, int]]] = ..., + replica_set_name: Optional[str] = ..., + pool_class: Optional[Pool] = ..., + pool_options: Optional[PoolOptions] = ..., + monitor_class: Optional[Monitor] = ..., + condition_class: Optional[threading.Condition] = ..., + local_threshold_ms: int = ..., + server_selection_timeout: int = ..., + heartbeat_frequency: int = ...) -> None: ... + @property + def seeds(self) -> List[Tuple[str, int]]: ... + @property + def replica_set_name(self) -> str: ... + @property + def pool_class(self) -> Pool: ... + @property + def pool_options(self) -> PoolOptions: ... + @property + def monitor_class(self) -> Monitor: ... + @property + def condition_class(self) -> threading.Condition: ... + @property + def local_threshold_ms(self) -> int: ... + @property + def server_selection_timeout(self) -> int: ... + @property + def heartbeat_frequency(self) -> int: ... + @property + def direct(self) -> bool: ... + def get_topology_type(self) -> int: ... + def get_server_descriptions(self) -> Dict[Tuple[str, int], ServerDescription]: ... diff --git a/pymongo/son_manipulator.pyi b/pymongo/son_manipulator.pyi new file mode 100644 index 0000000000..55ef98bcba --- /dev/null +++ b/pymongo/son_manipulator.pyi @@ -0,0 +1,26 @@ +from typing import Any, Dict, Mapping + +from pymongo.collection import Collection +from pymongo.database import Database + + +class SONManipulator(object): + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + def transform_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class ObjectIdInjector(SONManipulator): + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class ObjectIdShuffler(SONManipulator): + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class NamespaceInjector(SONManipulator): + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + +class AutoReference(SONManipulator): + def __init__(self, db: Database) -> None: ... + def will_copy(self) -> bool: ... + def transform_incoming(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... + def transform_outgoing(self, son: Mapping[str, Any], collection: Collection) -> Dict[str, Any]: ... diff --git a/pymongo/ssl_context.pyi b/pymongo/ssl_context.pyi new file mode 100644 index 0000000000..33f4a663c1 --- /dev/null +++ b/pymongo/ssl_context.pyi @@ -0,0 +1,24 @@ +from socket import socket +from typing import Any, Optional + +try: + import ssl +except ImportError: + pass + + +class SSLContext(object): + def __init__(self, protocol: int) -> None: ... + @property + def protocol(self) -> int: ... + def __get_verify_mode(self) -> int: ... + def __set_verify_mode(self, value: int) -> None: ... + def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ...) -> None: ... + def load_verify_locations(self, cafile: Optional[str] = ..., dummy: Optional[Any] = ...) -> None: ... + def wrap_socket( + self, + sock: socket, + server_side: bool = ..., + do_handshake_on_connect: bool = ..., + suppress_ragged_eofs: bool = ..., + dummy: Optional[Any] = ...) -> ssl.SSLSocket: ... diff --git a/pymongo/ssl_match_hostname.pyi b/pymongo/ssl_match_hostname.pyi new file mode 100644 index 0000000000..0bf9527f43 --- /dev/null +++ b/pymongo/ssl_match_hostname.pyi @@ -0,0 +1,4 @@ +from typing import Any, Mapping, Match, Union + +class CertificateError(ValueError): ... +def match_hostname(cert: Mapping[str, Any], hostname: str) -> None: ... diff --git a/pymongo/ssl_support.pyi b/pymongo/ssl_support.pyi new file mode 100644 index 0000000000..790d8397f2 --- /dev/null +++ b/pymongo/ssl_support.pyi @@ -0,0 +1,7 @@ +from typing import Any, Optional, Union +from pymongo.ssl_context import SSLContext as SSLContext + +HAVE_SSL: bool = ... + +def validate_cert_reqs(option: str, value: Optional[Union[str, int]]) -> Any: ... +def get_ssl_context(*args: Any) -> Any: ... diff --git a/pymongo/thread_util.pyi b/pymongo/thread_util.pyi new file mode 100644 index 0000000000..0cead115e9 --- /dev/null +++ b/pymongo/thread_util.pyi @@ -0,0 +1,29 @@ +from typing import Any, Optional, Union + + +class Semaphore: + def __init__(self, value: int = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def release(self) -> None: ... + def __exit__(self, t: Any, v: Any, tb: Any) -> None: ... + @property + def counter(self) -> int: ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value: int = ...) -> None: ... + def release(self) -> None: ... + +class DummySemaphore(object): + def __init__(self, value: Optional[int] = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def release(self) -> None: ... + +class MaxWaitersBoundedSemaphore(object): + def __init__(self, semaphore_class: Semaphore, value: int = ..., max_waiters: int = ...) -> None: ... + def acquire(self, blocking: bool = ..., timeout: Optional[int] = ...) -> bool: ... + def __getattr__(self, name: str) -> Any: ... + +class MaxWaitersBoundedSemaphoreThread(MaxWaitersBoundedSemaphore): + def __init__(self, value: int = ..., max_waiters: int = ...) -> None: ... + +def create_semaphore(max_size: int, max_waiters: int) -> Union[Semaphore, MaxWaitersBoundedSemaphore]: ... diff --git a/pymongo/topology.pyi b/pymongo/topology.pyi new file mode 100644 index 0000000000..4315c3a382 --- /dev/null +++ b/pymongo/topology.pyi @@ -0,0 +1,45 @@ +from typing import Any, Callable, List, Optional, Sequence, Set, Tuple, Union +import sys +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue + +from pymongo.pool import Pool +from pymongo.server import Server +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection +from pymongo.settings import TopologySettings +from pymongo.topology_description import TopologyDescription, TOPOLOGY_TYPE as TOPOLOGY_TYPE + + +def process_events_queue(queue_ref: Queue[Tuple[Callable[..., Any], Sequence[Any]]]) -> bool: ... + +class Topology(object): + def __init__(self, topology_settings: TopologySettings) -> None: ... + def open(self) -> None: ... + def select_servers( + self, + selector: Callable[[Sequence[Server]], Sequence[Server]], + server_selection_timeout: Optional[int] = ..., + address: Optional[Tuple[str, int]] = ...) -> List[Server]: ... + def select_server( + self, + selector: Callable[[Sequence[Server]], Sequence[Server]], + server_selection_timeout: Optional[int] = ..., + address: Optional[Tuple[str, int]] = ...) -> Server: ... + def select_server_by_address(self, address: Tuple[str, int], server_selection_timeout: Optional[int] = ...) -> Server: ... + def on_change(self, server_description: ServerDescription) -> None: ... + def get_server_by_address(self, address: Tuple[str, int]) -> Optional[Server]: ... + def has_server(self, address: Tuple[str, int]) -> bool: ... + def get_primary(self) -> Optional[Tuple[str, int]]: ... + def get_secondaries(self) -> Set[Tuple[str, int]]: ... + def get_arbiters(self) -> Set[Tuple[str, int]]: ... + def request_check_all(self, wait_time: int = ...) -> None: ... + def reset_pool(self, address: Tuple[str, int]) -> None: ... + def reset_server(self, address: Tuple[str, int]) -> None: ... + def reset_server_and_request_check(self, address: Tuple[str, int]) -> None: ... + def update_pool(self) -> None: ... + def close(self) -> None: ... + @property + def description(self) -> TopologyDescription: ... diff --git a/pymongo/topology_description.pyi b/pymongo/topology_description.pyi new file mode 100644 index 0000000000..e12164336c --- /dev/null +++ b/pymongo/topology_description.pyi @@ -0,0 +1,59 @@ +from typing import Callable, Dict, List, Mapping, NamedTuple, Optional, Tuple, Union + +from pymongo.read_preferences import _ServerMode +from pymongo.server import Server +from pymongo.server_description import ServerDescription +from pymongo.server_selectors import Selection +from pymongo.settings import TopologySettings + + +TopologyType = NamedTuple('TopologyType', [ + ('Single', int), + ('ReplicaSetNoPrimary', int), + ('ReplicaSetWithPrimary', int), + ('Sharded', int), + ('Unknown', int), +]) +TOPOLOGY_TYPE: TopologyType = ... + +class TopologyDescription(object): + def __init__( + self, + topology_type: int, + server_descriptions: Mapping[Tuple[str, int], + ServerDescription], + replica_set_name: Optional[str], + max_set_version: Optional[int], + max_election_id: Optional[int], + topology_settings: TopologySettings) -> None: ... + def check_compatible(self) -> None: ... + def has_server(self, address: Tuple[str, int]) -> bool: ... + def reset_server(self, address: Tuple[str, int]) -> 'TopologyDescription': ... + def reset(self) -> 'TopologyDescription': ... + def server_descriptions(self) -> Dict[Tuple[str, int], ServerDescription]: ... + @property + def topology_type(self) -> int: ... + @property + def topology_type_name(self) -> str: ... + @property + def replica_set_name(self) -> str: ... + @property + def max_set_version(self) -> int: ... + @property + def max_election_id(self) -> int: ... + @property + def known_servers(self) -> List[Server]: ... + @property + def common_wire_version(self) -> Optional[int]: ... + @property + def heartbeat_frequency(self) -> int: ... + def apply_selector( + self, + selector: Union[Selection, Callable[[Selection], Selection], _ServerMode], + address: Tuple[str, int]) -> List[ServerDescription]: ... + def has_readable_server(self, read_preference: _ServerMode = ...) -> bool: ... + def has_writable_server(self) -> bool: ... + +def updated_topology_description( + topology_description: TopologyDescription, + server_description: ServerDescription) -> TopologyDescription: ... diff --git a/pymongo/uri_parser.pyi b/pymongo/uri_parser.pyi new file mode 100644 index 0000000000..48b2bc67f1 --- /dev/null +++ b/pymongo/uri_parser.pyi @@ -0,0 +1,20 @@ +# Stubs for pymongo.uri_parser (Python 3) +# +# NOTE: This dynamically typed stub was automatically generated by stubgen. + +from bson.py3compat import abc +from typing import Any, Dict, List, Mapping, Optional, Tuple + +SCHEME: str = ... +SCHEME_LEN: int = ... +SRV_SCHEME: str = ... +SRV_SCHEME_LEN: int = ... +DEFAULT_PORT: int = ... + +def parse_userinfo(userinfo: str) -> Tuple[str, str]: ... +def parse_ipv6_literal_host(entity: str, default_port: int) -> Tuple[str, int]: ... +def parse_host(entity: str, default_port: int = ...) -> Tuple[str, int]: ... +def validate_options(opts: Mapping[str, Any], warn: bool = ...) -> Dict[str, Any]: ... +def split_options(opts: str, validate: bool = ..., warn: bool = ..., normalize: bool = ...) -> Dict[str, Any]: ... +def split_hosts(hosts: str, default_port: Any = ...) -> List[Tuple[str, int]]: ... +def parse_uri(uri: str, default_port: int = ..., validate: bool = ..., warn: bool = ...) -> Dict[str, Any]: ... diff --git a/pymongo/write_concern.pyi b/pymongo/write_concern.pyi new file mode 100644 index 0000000000..e6906142ed --- /dev/null +++ b/pymongo/write_concern.pyi @@ -0,0 +1,19 @@ +from typing import Any, Dict, Optional, Union + +class WriteConcern(object): + def __init__( + self, + w: Optional[Union[int, str]] = ..., + wtimeout: Optional[int] = ..., + j: Optional[bool] = ..., + fsync: Optional[bool] = ...) -> None: ... + @property + def is_server_default(self) -> bool: ... + @property + def document(self) -> Dict[str, Any]: ... + @property + def acknowledged(self) -> bool: ... + def __repr__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def __bool__(self) -> bool: ... diff --git a/setup.py b/setup.py index 455313b8a7..2689438720 100755 --- a/setup.py +++ b/setup.py @@ -387,5 +387,9 @@ def build_extension(self, ext): "doc": doc, "test": test}, extras_require=extras_require, + package_data={ + 'bson': ['bson/py.typed', 'bson/*.pyi'], + 'pymongo': ['bson/py.typed', 'bson/*.pyi'], + }, **extra_opts )