+\hUdZddlmZddlZddlZddlZddlmZddl m Z m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZdd lmZdd lmZmZmZmZm Z m!Z!dd l"m#Z#dd l$m%Z%dd l&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0e rddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8m9Z9dZ:GddZ;GddZ< d4dZ=GddZ>GddZ?Gd d!Z@d5d"ZAd6d#ZBe#eCd$d%gzZDd&eEd'<d(ZFd7d)ZGed*ZHe rdd+lImJZJGd,d-ZKGd.d/ZLGd0d1ZMGd2d3ejZOy)8aLogical sessions for ordering sequential operations. .. versionadded:: 3.6 Causally Consistent Reads ========================= .. code-block:: python with client.start_session(causal_consistency=True) as session: collection = client.db.collection collection.update_one({"_id": 1}, {"$set": {"x": 10}}, session=session) secondary_c = collection.with_options(read_preference=ReadPreference.SECONDARY) # A secondary read waits for replication of the write. secondary_c.find_one({"_id": 1}, session=session) If `causal_consistency` is True (the default), read operations that use the session are causally after previous read and write operations. Using a causally consistent session, an application can read its own writes and is guaranteed monotonic reads, even when reading from replica set secondaries. .. seealso:: The MongoDB documentation on `causal-consistency `_. .. _transactions-ref: Transactions ============ .. versionadded:: 3.7 MongoDB 4.0 adds support for transactions on replica set primaries. A transaction is associated with a :class:`ClientSession`. To start a transaction on a session, use :meth:`ClientSession.start_transaction` in a with-statement. Then, execute an operation within the transaction by passing the session to the operation: .. code-block:: python orders = client.db.orders inventory = client.db.inventory with client.start_session() as session: with session.start_transaction(): orders.insert_one({"sku": "abc123", "qty": 100}, session=session) inventory.update_one( {"sku": "abc123", "qty": {"$gte": 100}}, {"$inc": {"qty": -100}}, session=session, ) Upon normal completion of ``with session.start_transaction()`` block, the transaction automatically calls :meth:`ClientSession.commit_transaction`. If the block exits with an exception, the transaction automatically calls :meth:`ClientSession.abort_transaction`. In general, multi-document transactions only support read/write (CRUD) operations on existing collections. However, MongoDB 4.4 adds support for creating collections and indexes with some limitations, including an insert operation that would result in the creation of a new collection. For a complete description of all the supported and unsupported operations see the `MongoDB server's documentation for transactions `_. A session may only have a single active transaction at a time, multiple transactions on the same session can be executed in sequence. Sharded Transactions ^^^^^^^^^^^^^^^^^^^^ .. versionadded:: 3.9 PyMongo 3.9 adds support for transactions on sharded clusters running MongoDB >=4.2. Sharded transactions have the same API as replica set transactions. When running a transaction against a sharded cluster, the session is pinned to the mongos server selected for the first operation in the transaction. All subsequent operations that are part of the same transaction are routed to the same mongos server. When the transaction is completed, by running either commitTransaction or abortTransaction, the session is unpinned. .. seealso:: The MongoDB documentation on `transactions `_. .. _snapshot-reads-ref: Snapshot Reads ============== .. versionadded:: 3.12 MongoDB 5.0 adds support for snapshot reads. Snapshot reads are requested by passing the ``snapshot`` option to :meth:`~pymongo.mongo_client.MongoClient.start_session`. If ``snapshot`` is True, all read operations that use this session read data from the same snapshot timestamp. The server chooses the latest majority-committed snapshot timestamp when executing the first read operation using the session. Subsequent reads on this session read from the same snapshot timestamp. Snapshot reads are also supported when reading from replica set secondaries. .. code-block:: python # Each read using this session reads data from the same point in time. with client.start_session(snapshot=True) as session: order = orders.find_one({"sku": "abc123"}, session=session) inventory = inventory.find_one({"sku": "abc123"}, session=session) Snapshot Reads Limitations ^^^^^^^^^^^^^^^^^^^^^^^^^^ Snapshot reads sessions are incompatible with ``causal_consistency=True``. Only the following read operations are supported in a snapshot reads session: - :meth:`~pymongo.collection.Collection.find` - :meth:`~pymongo.collection.Collection.find_one` - :meth:`~pymongo.collection.Collection.aggregate` - :meth:`~pymongo.collection.Collection.count_documents` - :meth:`~pymongo.collection.Collection.distinct` (on unsharded collections) Classes ======= ) annotationsN)Mapping) TYPE_CHECKINGAnyCallableContextManagerrMutableMappingNoReturnOptionalTypeTypeVar)Binary)Int64) Timestamp)_csot)ConfigurationErrorConnectionFailureInvalidOperationOperationFailure PyMongoError WTimeoutError)_RETRYABLE_ERROR_CODES)_Op) ReadConcern)ReadPreference _ServerMode) SERVER_TYPE)_ConnectionManager) WriteConcern) TracebackType) Connection)Server) ClusterTime_AddressTcdeZdZdZ d ddZed dZed dZed dZy) SessionOptionsatOptions for a new :class:`ClientSession`. :param causal_consistency: If True, read operations are causally ordered within the session. Defaults to True when the ``snapshot`` option is ``False``. :param default_transaction_options: The default TransactionOptions to use for transactions started on this session. :param snapshot: If True, then all reads performed using this session will read from the same snapshot. This option is incompatible with ``causal_consistency=True``. Defaults to ``False``. .. versionchanged:: 3.12 Added the ``snapshot`` parameter. Nc|r|r tdd}n|d}||_|*t|tst dj |||_||_y)Nz5snapshot reads do not support causal_consistency=TrueFTzgdefault_transaction_options must be an instance of pymongo.client_session.TransactionOptions, not: {!r})r_causal_consistency isinstanceTransactionOptions TypeErrorformat_default_transaction_options _snapshot)selfcausal_consistencydefault_transaction_optionssnapshots e/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/synchronous/client_session.py__init__zSessionOptions.__init__su !()`aa!&   '!% #5 & 29;MNKKQ63L -H)!c|jS)z)Whether causal consistency is configured.)r(r/s r3r0z!SessionOptions.causal_consistencys'''r5c|jS)zThe default TransactionOptions to use for transactions started on this session. .. versionadded:: 3.7 )r-r7s r3r1z*SessionOptions.default_transaction_optionss000r5c|jS)zOWhether snapshot reads are configured. .. versionadded:: 3.12 )r.r7s r3r2zSessionOptions.snapshots ~~r5)NNF)r0Optional[bool]r1Optional[TransactionOptions]r2r:returnNoner<bool)r<r;)r<r:) __name__ __module__ __qualname____doc__r4propertyr0r1r2r5r3r&r&sz ".2DH#( "*"&B"! "  "0((11r5r&c|eZdZdZ d d dZed dZed dZed dZed dZ y)r*aOptions for :meth:`ClientSession.start_transaction`. :param read_concern: The :class:`~pymongo.read_concern.ReadConcern` to use for this transaction. If ``None`` (the default) the :attr:`read_preference` of the :class:`MongoClient` is used. :param write_concern: The :class:`~pymongo.write_concern.WriteConcern` to use for this transaction. If ``None`` (the default) the :attr:`read_preference` of the :class:`MongoClient` is used. :param read_preference: The read preference to use. If ``None`` (the default) the :attr:`read_preference` of this :class:`MongoClient` is used. See :mod:`~pymongo.read_preferences` for options. Transactions which read must use :attr:`~pymongo.read_preferences.ReadPreference.PRIMARY`. :param max_commit_time_ms: The maximum amount of time to allow a single commitTransaction command to run. This option is an alias for maxTimeMS option on the commitTransaction command. If ``None`` (the default) maxTimeMS is not used. .. versionchanged:: 3.9 Added the ``max_commit_time_ms`` option. .. versionadded:: 3.7 Nc||_||_||_||_|t |t st d||8t |tst d||jstd||t |tst |d|(t |tst dt|yy)NzKread_concern must be an instance of pymongo.read_concern.ReadConcern, not: zNwrite_concern must be an instance of pymongo.write_concern.WriteConcern, not: z:transactions do not support unacknowledged write concern: zR is not valid for read_preference. See pymongo.read_preferences for valid options.z3max_commit_time_ms must be an integer or None, not ) _read_concern_write_concern_read_preference_max_commit_time_msr)rr+r acknowledgedrrinttype)r/ read_concern write_concernread_preferencemax_commit_time_mss r3r4zTransactionOptions.__init__s*+ /#5  #lK8>>J=MO  $m\:@@M?PR!--(&)+  &o{;&)*  )0#6I$OaJbIcd7 *r5c|jS)z>This transaction's :class:`~pymongo.read_concern.ReadConcern`.)rHr7s r3rOzTransactionOptions.read_concern<s!!!r5c|jS)z@This transaction's :class:`~pymongo.write_concern.WriteConcern`.)rIr7s r3rPz TransactionOptions.write_concernAs"""r5c|jS)zEThis transaction's :class:`~pymongo.read_preferences.ReadPreference`.)rJr7s r3rQz"TransactionOptions.read_preferenceFs$$$r5c|jS)zfThe maxTimeMS to use when running a commitTransaction command. .. versionadded:: 3.9 )rKr7s r3rRz%TransactionOptions.max_commit_time_msKs '''r5NNNN) rOOptional[ReadConcern]rPOptional[WriteConcern]rQOptional[_ServerMode]rR Optional[int]r<r=)r<rX)r<rYr<rZ)r<r[) r@rArBrCr4rDrOrPrQrRrEr5r3r*r*s8/30415,0 '+'.'/ ' * '  'R""##%%((r5r*c\|r)|'|js|jrytd||S)zValidate that an explicit session is not used with an unack'ed write. Returns the session to use for the next operation. NzFExplicit sessions are incompatible with unacknowledged write concern: )rL _implicitr)sessionrPs r3_validate_session_write_concernr`TsH  $]-G-G   (55B4EG Nr5c8eZdZdZddZddZ ddZy) _TransactionContextz;Internal transaction context manager for start_transaction.c||_yN)_TransactionContext__session)r/r_s r3r4z_TransactionContext.__init__os  r5c|SrdrEr7s r3 __enter__z_TransactionContext.__enter__r r5c|jjr8||jjy|jjyyrd)rein_transactioncommit_transactionabort_transactionr/exc_typeexc_valexc_tbs r3__exit__z_TransactionContext.__exit__us; >> ( (113002 )r5N)r_ ClientSession)r<rb)rnzOptional[Type[BaseException]]rozOptional[BaseException]rpzOptional[TracebackType]r<r=)r@rArBrCr4rgrqrEr5r3rbrbls:E! 3/ 3) 3( 3  3r5rbc$eZdZdZdZdZdZdZdZy) _TxnStateN) r@rArBNONESTARTING IN_PROGRESS COMMITTEDCOMMITTED_EMPTYABORTEDrEr5r3rtrts DHKIOGr5rtcZeZdZdZd dZd dZd dZed dZddZ ddZ ddZ dd Z y ) _TransactionzBInternal class to hold transaction information in a ClientSession.c||_tj|_d|_d|_d|_d|_d|_||_ yNFr) optsrtr{stateshardedpinned_addressconn_mgrrecovery_tokenattemptclient)r/rrs r3r4z_Transaction.__init__s@ ^^  266: "  r5cZ|jtjtjfvSrd)rrtr|r}r7s r3activez_Transaction.actives"zzi00)2G2GHHHr5c<|jtjk(Srd)rrtr|r7s r3startingz_Transaction.startingszzY////r5ch|jr"|jr|jjSyrd)rrconnr7s r3 pinned_connz_Transaction.pinned_conns$ ;;=T]]==%% %r5cd|_|jj|_|jjt j k(r"|jt|d|_ yy)NTF) r descriptionaddressr server_typer LoadBalancerpin_txnrrr/serverrs r3pinz_Transaction.pinsT $0088    ) )[-E-E E LLN.tU;DM Fr5cld|_|jr|jjd|_yrd)rrcloser7s r3unpinz_Transaction.unpins(" == MM   ! r5cx|jtj|_d|_d|_d|_yr)rrtr{rrrrr7s r3resetz_Transaction.resets, ^^  " r5cz|jr/|jjdd|jd|_yyNr)rr_close_cursor_soonr7s r3__del__z_Transaction.__del__s1 == KK * *1dDMM B DM r5N)rr;r MongoClientr>r<zOptional[Connection]rr"rr!r<r=r<r=) r@rArBrCr4rrrDrrrrrrEr5r3rrs=LI0 < !r5rc&|jd)zDRe-raise an exception with the UnknownTransactionCommitResult label.UnknownTransactionCommitResult)_add_error_labelexcs r3_reraise_with_unknown_commitrs9: r5cDt|txr|jdk(S)z/Return true if exc is a MaxTimeMSExpired error.2)r)rcoders r3_max_time_expired_errorrs c+ , ?R?r5@r frozenset_UNKNOWN_COMMIT_ERROR_CODESxc>tj|z tkS)z/Are we within the with_transaction retry limit?)time monotonic"_WITH_TRANSACTION_RETRY_TIME_LIMIT) start_times r3_within_time_limitrs >> j (+M MMr5_T)rceZdZdZ d)dZd*dZd+dZd*dZd*dZd,dZ d-dZ e d.d Z e d/d Z e d0d Ze d1d Ze d2d Ze d3dZd4dZ d5 d6dZ d5 d7dZd*dZd*dZd8dZd9dZd:dZd;dZddZe d?dZe d?dZe d?dZ e d@dZ!e dAd Z"dBd!Z#d*d"Z$dCd#Z%dDdEd$Z& dFd%Z'd*d&Z(dGd'Z)dHd(Z*y)IrraA session for ordering sequential operations. :class:`ClientSession` instances are **not thread-safe or fork-safe**. They can only be used by one thread or process at a time. A single :class:`ClientSession` cannot be used to run multiple operations concurrently. Should not be initialized directly by application developers - to create a :class:`ClientSession`, call :meth:`~pymongo.mongo_client.MongoClient.start_session`. c||_||_||_d|_d|_d|_||_td||_yrd) _client_server_session_options _cluster_time_operation_time_snapshot_timer^r _transaction)r/rserver_sessionoptionsimplicits r3r4zClientSession.__init__sH%+ - :>48"!(v6r5c(|jdy)zFinish this session. If a transaction has started, abort it. It is an error to use the session after the session has ended. TlockN _end_sessionr7s r3 end_sessionzClientSession.end_sessions t$r5c2|jZ |jr|j|j|jj |jd|_yy#|jj |jd|_wxYwrd)rrjrl_unpinr_return_server_session)r/rs r3rzClientSession._end_session s|    + ,&&**,  33D4H4HI'+$ , 33D4H4HI'+$s ,A((.Bcv|j-|jj|jd|_yyrd)rrrr7s r3_end_implicit_sessionz#ClientSession._end_implicit_sessions3    + LL / /0D0D E#'D  ,r5c2|j tdy)NzCannot use ended session)rrr7s r3 _check_endedzClientSession._check_endeds    '"#=> > (r5c|SrdrEr7s r3rgzClientSession.__enter__"rhr5c(|jdy)NTrrrms r3rqzClientSession.__exit__%s t$r5c|jS)z^The :class:`~pymongo.mongo_client.MongoClient` this session was created from. )rr7s r3rzClientSession.client(s ||r5c|jS)z:The :class:`SessionOptions` this session was created with.)rr7s r3rzClientSession.options/s}}r5c|j|j|jjj|j j S)z6A BSON document, the opaque server session identifier.)r _materializertopology_descriptionlogical_session_timeout_minutesr session_idr7s r3rzClientSession.session_id4s@  $,,;;[[\##...r5c|j|jjj|jj S)z=The current transaction id for the underlying server session.)rrrrrtransaction_idr7s r3_transaction_idzClientSession._transaction_id;s4 $,,;;[[\##222r5c|jS)zZThe cluster time returned by the last operation executed in this session. rr7s r3 cluster_timezClientSession.cluster_timeAs !!!r5c|jS)z\The operation time returned by the last operation executed in this session. rr7s r3operation_timezClientSession.operation_timeHs ###r5c|r|S|jj}|xr t||}|r|St|j|S)z-Return the inherited TransactionOption value.)rr1getattrr)r/namevaltxn_opts parent_vals r3_inherit_optionzClientSession._inherit_optionOsD J<<;;9'(D"9  t{{D))r5Nc(tj} |j|||| ||}|js|S |j|S#t$rS}|jr|j t |tr!|jdrt|rYd}~d}~wwxYw#t$rS}|jdrt|rt|sYd}~|jdrt|rYd}~n d}~wwxYw)a%Execute a callback in a transaction. This method starts a transaction on this session, executes ``callback`` once, and then commits the transaction. For example:: def callback(session): orders = session.client.db.orders inventory = session.client.db.inventory orders.insert_one({"sku": "abc123", "qty": 100}, session=session) inventory.update_one({"sku": "abc123", "qty": {"$gte": 100}}, {"$inc": {"qty": -100}}, session=session) with client.start_session() as session: session.with_transaction(callback) To pass arbitrary arguments to the ``callback``, wrap your callable with a ``lambda`` like this:: def callback(session, custom_arg, custom_kwarg=None): # Transaction operations... with client.start_session() as session: session.with_transaction( lambda s: callback(s, "custom_arg", custom_kwarg=1)) In the event of an exception, ``with_transaction`` may retry the commit or the entire transaction, therefore ``callback`` may be invoked multiple times by a single call to ``with_transaction``. Developers should be mindful of this possibility when writing a ``callback`` that modifies application state or has any other side-effects. Note that even when the ``callback`` is invoked multiple times, ``with_transaction`` ensures that the transaction will be committed at-most-once on the server. The ``callback`` should not attempt to start new transactions, but should simply run operations meant to be contained within a transaction. The ``callback`` should also not commit the transaction; this is handled automatically by ``with_transaction``. If the ``callback`` does commit or abort the transaction without error, however, ``with_transaction`` will return without taking further action. :class:`ClientSession` instances are **not thread-safe or fork-safe**. Consequently, the ``callback`` must not attempt to execute multiple operations concurrently. When ``callback`` raises an exception, ``with_transaction`` automatically aborts the current transaction. When ``callback`` or :meth:`~ClientSession.commit_transaction` raises an exception that includes the ``"TransientTransactionError"`` error label, ``with_transaction`` starts a new transaction and re-executes the ``callback``. The ``callback`` MUST NOT silently handle command errors without allowing such errors to propagate. Command errors may abort the transaction on the server, and an attempt to commit the transaction will be rejected with a ``NoSuchTransaction`` error. For more information see the `transactions specification`_. When :meth:`~ClientSession.commit_transaction` raises an exception with the ``"UnknownTransactionCommitResult"`` error label, ``with_transaction`` retries the commit until the result of the transaction is known. This method will cease retrying after 120 seconds has elapsed. This timeout is not configurable and any exception raised by the ``callback`` or by :meth:`ClientSession.commit_transaction` after the timeout is reached will be re-raised. Applications that desire a different timeout duration should not use this method. :param callback: The callable ``callback`` to run inside a transaction. The callable must accept a single argument, this session. Note, under certain error conditions the callback may be run multiple times. :param read_concern: The :class:`~pymongo.read_concern.ReadConcern` to use for this transaction. :param write_concern: The :class:`~pymongo.write_concern.WriteConcern` to use for this transaction. :param read_preference: The read preference to use for this transaction. If ``None`` (the default) the :attr:`read_preference` of this :class:`Database` is used. See :mod:`~pymongo.read_preferences` for options. :return: The return value of the ``callback``. .. versionadded:: 3.9 .. _transactions specification: https://github.com/mongodb/specifications/blob/master/source/transactions-convenient-api/transactions-convenient-api.md#handling-errors-inside-the-callback TransientTransactionErrorNr) rrstart_transaction BaseExceptionrjrlr)rhas_error_labelrrkr) r/callbackrOrPrQrRrretrs r3with_transactionzClientSession.with_transactionYsH^^%   " "<Qc d tn&& ++-$ I! &&**,sL1++,GH*:6 &$++,LM.z: 7 <!**+FGL^"M1sBAB4 B1AB,+B,,B14 D='D )D  D  Dc,|j|jjr td|jr td|j d|}|j d|}|j d|}|$|jj }|r |j}t|||||j_ |jjtj|j_|jt!|S)zStart a multi-statement transaction. Takes the same arguments as :class:`TransactionOptions`. .. versionchanged:: 3.9 Added the ``max_commit_time_ms`` option. .. versionadded:: 3.7 z3Transactions are not supported in snapshot sessionszTransaction already in progressrOrPrQ)rrr2rrjrr1rRr*rrrrtr|r_start_retryable_writerb)r/rOrPrQrRrs r3rzClientSession.start_transactions  << "#XY Y   "#DE E++NLI ,,_mL ../@/R  %<<;;D%)%<%<"!3 -:L"  !"+"4"4 ##%"4((r5cN|j|jj}|tjur t d|tj tjfvr tj|j_y|tjur t d|tjurtj|j_ |jdtj|j_y#t$r&}|jdt|Yd}~Jd}~wt$r}t|Yd}~fd}~wt $r(}|j"t$vrt|Yd}~d}~wwxYw#tj|j_wxYw)zMCommit a multi-statement transaction. .. versionadded:: 3.7 No transaction startedNz.func^s++D,? ?r5NT) retryable operation)rOptional[ClientSession]rr!rr?r<dict[str, Any])r_retry_internalrABORT)r/rrs`` r3rz,ClientSession._finish_transaction_with_retryXsV  @- @5? @MQ @  @ ||++D$X[XaXa+bbr5cD|jxjdz c_|jj}|sJ|j}|di}|dk(rz|jr#t j |j|d<|jjdkDr2|sJ|j}d|d<|jddtd i|}|jjr|jj|d<|jjj||||d S) Nrur maxTimeMSmajoritywwtimeouti' recoveryTokenT)r_rPparse_write_concern_errorrE)rrrrPrRr get_timeoutdocument setdefaultrrradmin_command)r/rrrwccmdwc_docs r3rz!ClientSession._finish_transactiones !!Q&!  %% t   Q . .&&5+<+<+>+F#'#:#:K   ((1, r(s !!*e4!+F+    + +#'#4#4#C#CC ||!!** #t2QU+  r5cl|j||_y||d|jdkDr||_yyy)zInternal cluster time helper.N clusterTimerr/rs r3_advance_cluster_timez#ClientSession._advance_cluster_timesG    %!-D   %M*T-?-? -NN%1"O&r5ct|tstdt|t|j dt s t d|j|y)zUpdate the cluster time for this session. :param cluster_time: The :data:`~pymongo.client_session.ClientSession.cluster_time` from another `ClientSession` instance. z>()`aa   $>>? <<  % %gt 4(,(8%..99 #'#7#7#F#FGK    ."8"88&MoM`a  &&)*<*<<*3*?*?!!'.2*+((----$$))66**//<<EEB13 .))'48#'#7#7#F#FGK $)GL !' r5cX|j|jjyrd)rrrFr7s r3rz$ClientSession._start_retryable_writes   //1r5cN|jjr+|j|j|jdid<|jjrN|j dkr t d|jdi}d|d<|j|j|d<yyy)NrLafterClusterTime z+Snapshot reads require MongoDB 5.0 or laterr2levelr/)rr0rrr2max_wire_versionrr)r/rrrTs r3rOz"ClientSession._update_read_concern!s << * *t/B/B/NDHDWDWCNN=" -.@ A << $$r)()VWW r2B$BwK"".&*&9&9?#/ !r5ctd)Nz>A ClientSession cannot be copied, create a new session instead)r+r7s r3__copy__zClientSession.__copy__,sXYYr5) rrrrrr&rr?r<r=r)rr?r<r=)r<rr)rnrrorrprr<r=)r<r)r<r&)r<Mapping[str, Any]r<r)r<zOptional[ClusterTime])r<Optional[Timestamp])rstrrrr<rrW) rzCallable[[ClientSession], _T]rOrXrPrYrQrZrRr[r<r) rOrXrPrYrQrZrRr[r<r)rrar<r )rr!rrar<r )rzOptional[Mapping[str, Any]]r<r=)rr^r<r=)rr`r<r=)rrr<r=)r0r^r<r=r>)r<zOptional[_Address]rrr\rd)rr[r<r=) rRMutableMapping[str, Any]rSr?rQrrr!r<r=)rrbrr!r<r=)r<r )+r@rArBrCr4rrrrrgrqrDrrrrrrrrrrkrlrrr!r&r)r+r2r4rjr7r9r;r=rr@rrUrrOr]rEr5r3rrrrs^ 777 7  7  7$% ,( ?% // 33 "" $$ */30415,0 N/N,N. N / N * N Nd/30415,0 &)+&).&)/ &) * &)  &)P):V8 c 62 16 5 B,,**,, --,":**)****% **  **  **X2 :Zr5rrc(eZdZdZddZddZddZy)rBdirtyrEc d|_d|_y)NFrdr7s r3r4z_EmptyServerSession.__init__3s ',$r5cd|_yNTrer7s r3 mark_dirtyz_EmptyServerSession.mark_dirty7s  r5cd|_yrh)rEr7s r3rFz&_EmptyServerSession.inc_transaction_id:s '+$r5Nr)r@rArB __slots__r4rjrFrEr5r3rBrB0s2I-,r5rBc>eZdZddZddZd dZed dZddZy) _ServerSessioncdttjjdi|_t j |_d|_d|_ ||_ y)NidrxrF) ruuiduuid4bytesrrrrPrre generation)r/rts r3r4z_ServerSession.__init__?sE (:(:A!>?(   $r5cd|_y)zMark this session as dirty. A server session is marked dirty when a command fails with a network error. Dirty sessions are later discarded from the server session pool. TNrir7s r3rjz_ServerSession.mark_dirtyGs  r5c`|ytj|jz }||dz dzkDS)NFru<)rrrP)r/session_timeout_minutes idle_secondss r3 timed_outz_ServerSession.timed_outOs8 " *~~'$--7 6:b@@@r5c,t|jS)zPositive 64-bit integer.)rrr7s r3rz_ServerSession.transaction_idXsT))**r5c.|xjdz c_yNru)rr7s r3rFz!_ServerSession.inc_transaction_id]s !r5N)rtrMr)rxr[r<r?r_) r@rArBr4rjrzrDrrFrEr5r3rnrn>s+%A++"r5rncLeZdZdZdfd Zd dZd dZd dZd dZd dZ xZ S)_ServerSessionPoolzDPool of _ServerSession objects. This class is thread-safe. c2t||i|d|_yr)superr4rt)r/argskwargs __class__s r3r4z_ServerSessionPool.__init__gs $)&)r5cN|xjdz c_|jyr})rtclearr7s r3rz_ServerSessionPool.resetks 1 r5c~g} |j|jj+#t$rY|SwxYwrd)appendpopr IndexError)r/idss r3pop_allz_ServerSessionPool.pop_allosE  488:001   s )/ <<c|j| |j}|j|s|S%#t$rYnwxYwt |j Srd) _clear_stalepopleftrrzrnrtr/rxss r3rDz%_ServerSessionPool.get_server_sessionxsf 12 LLN;;67    doo..s8 AAct|j|jk(r|js|j|yyyrd)rtre appendleft)r/rs r3return_server_sessionz(_ServerSessionPool.return_server_sessions4  $ $ 7@T@T OON +AU 7r5c |j}|j|s|j|y5#t$rYywxYwrd)rrrzrrs r3rz_ServerSessionPool._clear_stalesK HHJ;;67 A  s7 AA)rrrrr)r<zlist[_ServerSession])rxr[r<rn)rrnr<r=)rxr[r<r=) r@rArBrCr4rrrDrr __classcell__)rs@r3rras& /&, r5r)r_r rPrYr<r )rrr<r )rrr<r?)rfloatr<r?)PrC __future__r collectionsrrqcollections.abcrr#typingrrrrr r r r r bson.binaryr bson.int64rbson.timestamprpymongorpymongo.errorsrrrrrrpymongo.helpers_sharedrpymongo.operationsrpymongo.read_concernrpymongo.read_preferencesrrpymongo.server_typerpymongo.synchronous.cursorrpymongo.write_concernrtypesr pymongo.synchronous.poolr!pymongo.synchronous.serverr"pymongo.typingsr#r$_IS_SYNCr&r*r`rbrtrrrrr__annotations__rrr pymongo.synchronous.mongo_clientrrrrBrndequerrEr5r3rsKwr# /   $:",@+9.#315 <<~Y(Y(x $5K033,2!2!j @*@)  C*Y&)"N  T]<G ZG ZT , , " "F:**:r5