+\h%UdZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m ZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-dd l.m/Z/dd l0m1Z1m2Z2m3Z3m4Z4dd l5m6Z6m7Z7m8Z8m9Z9m:Z:dd l;mZ>ddl?m@Z@mAZAmBZBddlCmDZDddlEmFZFddlGmHZHddlImJZJddlKmLZLddlMmNZNmOZOddlPmQZQddlRmSZSerddlTmUZUddlVmWZWmXZX ddlYmZZZdZ[gdZ]dZ^dZ_dZ`d Zad!Zbd"Zcd#Zdd$Zed%Zfd&Zgd'Zhd(Zid)Zjd*Zkd+Zld,Zmd-Znd.Zod/Zpd0Zqd1Zrejd2jZuejd3jZwejd3jZxejd4jZyejd5jZzejd6jZ{dd7Z|dd8Z} dd9Z~dd:Z dd;Z dd<Zdd=Z dd>Z dd?Z dd@Z ddAZ ddBZ ddCZ ddDZ ddEZ ddFZ ddGZ ddHZ ddIZ ddJZiee^eee_eee`eeeaeeebeeecdKeedeeeeeeefeeegdLeeheeeieeejeeekeeeleeeme~eeneeeoeeepeeeqdMeerdNiZdOedP<e[r d ddQZn d ddRZe!dSeeefTZ d ddUZ d ddVZddWZe[r eZj0Zejd2j2Zejd3j2Zejd4j2Zejd5j2Zejd6j2ZedXedYDZddZZdd[Zdd\Zdd]Zdd^Zdd_Zdd`ZddaZ ddbZddcZdddZddeZddfZddgZddhZddiZddjZddkZddlZddmZddnZddoZddpZddqZddrZieeeeejee8eeeeeeeeeeeeeedee jee,eeDee/eeeej4eiZiZeD]Zeedss eeeeŐj<!edteDZ d dduZddvZ d ddwZe[r eZjZedxZde1f ddyZe$dddzZe$dd{Z d dd|Zdd}Ze[r eZjZe$ddd~Ze$ ddZ d ddZ ddZddZe[r eZjZddZ ddZe$dddZe$ddZ d ddZe$ d ddZe$ ddZ d ddZddZGddeZddZddZeedreje۬yy#e\$rdZ[YMwxYw)av BSON (Binary JSON) encoding and decoding. The mapping from Python types to BSON types is as follows: ======================================= ============= =================== Python Type BSON Type Supported Direction ======================================= ============= =================== None null both bool boolean both int [#int]_ int32 / int64 py -> bson :class:`bson.int64.Int64` int64 both float number (real) both str string both list array both dict object both :class:`~bson.son.SON` object both :py:class:`~collections.abc.Mapping` object py -> bson :class:`~bson.raw_bson.RawBSONDocument` object both [#raw]_ datetime.datetime [#dt]_ [#dt2]_ UTC datetime both :class:`~bson.datetime_ms.DatetimeMS` UTC datetime both [#dt3]_ :class:`~bson.regex.Regex` regex both compiled re [#re]_ regex py -> bson :class:`~bson.binary.Binary` binary both :py:class:`uuid.UUID` [#uuid]_ binary both :class:`~bson.objectid.ObjectId` oid both :class:`~bson.dbref.DBRef` dbref both :class:`~bson.dbref.DBRef` dbpointer bson -> py None undefined bson -> py :class:`~bson.code.Code` code both str symbol bson -> py bytes [#bytes]_ binary both :class:`~bson.timestamp.Timestamp` timestamp both :class:`~bson.decimal128.Decimal128` decimal128 both :class:`~bson.min_key.MinKey` min key both :class:`~bson.max_key.MaxKey` max key both ======================================= ============= =================== .. [#int] A Python int will be saved as a BSON int32 or BSON int64 depending on its size. A BSON int32 will always decode to a Python int. A BSON int64 will always decode to a :class:`~bson.int64.Int64`. .. [#raw] Decoding a bson object to :class:`~bson.raw_bson.RawBSONDocument` can be optionally configured via :attr:`~bson.codec_options.CodecOptions.document_class`. .. [#dt] datetime.datetime instances are encoded with millisecond precision so the microsecond field is truncated. .. [#dt2] all datetime.datetime instances are encoded as UTC. By default, they are decoded as *naive* but timezone aware datetimes are also supported. See :doc:`/examples/datetimes` for examples. .. [#dt3] To enable decoding a bson UTC datetime to a :class:`~bson.datetime_ms.DatetimeMS` instance see :ref:`handling-out-of-range-datetimes`. .. [#uuid] For :py:class:`uuid.UUID` encoding and decoding behavior see :doc:`/examples/uuid`. .. [#re] :class:`~bson.regex.Regex` instances and regular expression objects from ``re.compile()`` are both saved as BSON regular expressions. BSON regular expressions are decoded as :class:`~bson.regex.Regex` instances. .. [#bytes] The bytes type is encoded as BSON binary with subtype 0. It will be decoded back to bytes. ) annotationsN) utf_8_decode) utf_8_encode)abc)IO TYPE_CHECKINGAnyBinaryIOCallable GeneratorIteratorMappingMutableMappingNoReturnOptionalSequenceTupleTypeTypeVarUnioncastoverload)ALL_UUID_SUBTYPES CSHARP_LEGACY JAVA_LEGACYOLD_UUID_SUBTYPESTANDARD UUID_SUBTYPEBinaryUuidRepresentation)Code)DEFAULT_CODEC_OPTIONS CodecOptionsDatetimeConversion_raw_document_class) EPOCH_AWARE EPOCH_NAIVE DatetimeMS_datetime_to_millis_millis_to_datetime)DBRef) Decimal128) InvalidBSONInvalidDocumentInvalidStringData)Int64MaxKeyMinKeyObjectId)Regex)RE_TYPESON) Timestamp)utcRawBSONDocument) _DocumentType_ReadableBuffer)_cbsonTF)4 cftdjt|j|)zUnknown type helper.z\Detected unknown BSON type {!r} for fieldname '{}'. Are you using the latest driver version?)r-formatchrrX) element_type element_names r~_raise_unknown_typers/  //5vc,6G6N6N6PR^/_ rc*t||d|dzfS)z"Decode a BSON int32 to python int.r)_UNPACK_INT_FROMr|_viewpositiondummy0dummy1dummy2s r~_get_intrs D( +A .1 <>rct||d}|dz }|dks||z |kr td||zdz }||dk7r tdt||||jdd|dzfS)z#Decode a BSON string to python str.rrrzinvalid string lengthzinvalid end of stringT)rr-rr)r|r}robj_endrdummylengthrs r~ _get_stringrsdH -a 0F MH zWx'&0122 V a C CyA~122 hs+T-N-NPT UVW XZ]`aZa aarc  t||d}||zdz }||k\r td||dk7r td|dk(r||k7r td||fS#tj$r}tt |dd}~wwxYw)z+Validate and return a BSON document's size.rNrzinvalid object lengthbad eoo)rstructerrorr-str)r|rrobj_sizeexcrs r~_get_object_sizer(s.#D(3A6 X  !C g~122 CyA~)$$1}W,122 S= <<.#c(#-.sAB(A==Bct|||\}}t|jr|j|||dz|||zfSt|||dz||}||z }t |j dt rmd|vrit |j dt tdfr?t|jd|jdd|jdd||fS||fS)zEDecode a BSON subdocument to opts.document_class or bson.dbref.DBRef.rrz$refz$idz$dbN) rr%document_class_elements_to_dictrwgetrtyper+pop) r|r}rrrrrrobjs r~ _get_objectr9s%T8W=MHc4../##DC!G$tt||d||dzfS)z3Decode a BSON datetime to python datetime.datetime.rr)r*_UNPACK_LONG_FROM)r|rrrrrs r~ _get_daters( 0x@CT JHWXL XXrcBt||||||\}}t||fS)z%Decode a BSON code to bson.code.Code.)rr!)r|r}rrrrcodes r~ _get_coders+!tXwlSND( :x rc|t||dz}t|||dz|||\}}t||||||\}}||k7r tdt |||fS)z-Decode a BSON code_w_scope to bson.code.Code.rrz+scope outside of javascript code boundaries)rrrr-r!) r|r}r_obj_endrrcode_endrscopes r~_get_code_w_scopersu*4:1==H tX\8T<XND(!$h$ UOE88GHH e h &&rcft||||\}}t||||\}}t||}||fS)zCDecode a BSON regex to bson.regex.Regex or a python pattern object.)rr7) r|r}rrrrpattern bson_flagsbson_res r~ _get_regexrsE&dD(DAGX(tXtDJGZ(G H rcjt||||||\}}t||||||\}}t|||fS)z7Decode (deprecated) BSON DBPointer to bson.dbref.DBRef.)rrr+)r|r}rrrr collectionoids r~_get_refrsG'tT8WdLYJT47D,OMC S !8 ++rcBt||\}}t|||dzfS)z4Decode a BSON timestamp to bson.timestamp.Timestamp.r)_UNPACK_TIMESTAMP_FROMr:)r|rrrrrinc timestamps r~_get_timestamprs*,D(;NC Y $hl 22rc<tt||d|dzfS)z(Decode a BSON int64 to bson.int64.Int64.rr)r0rrs r~ _get_int64rs% "4215 61 DDrc@|dz}tj||||fS)z7Decode a BSON decimal128 to bson.decimal128.Decimal128.)r,from_bidrs r~_get_decimal128rs* R-C   tHS1 2C 77rc d|fSrvuvwxyzs r~r D!9rc d|fSrvrrs r~rrrrct|fSrvr3rs r~rr FHa=rct|fSrvr1rs r~rrrrz)dict[int, Callable[..., Tuple[Any, int]]]rc Htdtj|||||S)NTuple[str, Any, int])rr@_element_to_dict)r|r}rrr raw_arrays r~rrs* "  # #D(GT9 M  rc||}|dz }t||||\}}|r9|ttk(r't||t |\}} |||| dz| dzfS t |||||||\} }|jjr8|jjjt } | | | } | |fS#t $rt||YjwxYw)z Decode a single key, value pair.r) rordrDrlenrrrrrrr) r|r}rrrrrr_rrrs r~rr'sH~ A !.tT8T!J h W5%dHc$i@FAshq!937B B <-l;dHgt\OE8    * *!//<<@@eMN)&u-UH,, <  l ; rN) rVr%rrrrrr- Exceptionsysexc_inforwith_traceback)r|rr}rr exc_valueexc_tbs r~ _bson_to_dictrms"4(JD$ K t22 3&&tT2 2!$3t953O%6tT1c4%PQQ  K"||~9f#i.)88@dJKs&A)1A))AB8c#VK|]!}t|dzjd#yw)utf8N)rrX).0is r~ rs#JSVf_,,V4Js')c#KtEd{tjd} tt |dzj d)7Cw)zGenerate "keys" for encoded lists in the sequence b"0", b"1", b"2", ... The first 1000 keys are returned from a pre-built cache. All subsequent keys are generated on the fly. Nrrr) _LIST_NAMES itertoolscountrnextrX)counters r~rWrWsKood#G 4=!F*226:: s AAAAct|tr"d|vr td t|dd|dzSd|vr tdt |ddzS#t$rt d|zdwxYw)z8Make a 'C' string, checking for embedded NUL characters.rz;BSON keys / regex patterns must not contain a NUL characterNT,strings in documents must be valid UTF-8: %rrr)rwrxr.r UnicodeErrorr/ _utf_8_encodestrings r~_make_c_string_checkr+s&% f !"_` `  &$ -G# # V !"_` `V$Q''11 #>G  s AA,ct|tr t|dd|dzSt |ddzS#t$rt d|zdwxYw)zMake a 'C' string.NTrr&r)rwrxrr'r/r(r)s r~_make_c_stringr-sh&%   &$ -G# # V$Q''11  #>G  s 5AcBd|vr tdt|ddzS)z*Make a 'C' string suitable for a BSON key.rz*BSON keys must not contain a NUL characterrr)r.r(r)s r~ _make_namer/s+ JKK   #g --rc$d|zt|zS)zEncode a float.r`) _PACK_FLOATnamerrrs r~ _encode_floatr4s T>K. ..rcBd|ztt|zdz|zS)zEncode a python bytes.rdr) _PACK_INTrr2s r~ _encode_bytesr7s& T>Ic%j1 1G ;e CCrc &t|r d|ztt|jzSdj |j Dcgc]\}}t ||||c}}}d|ztt|dzz|zdzScc}}w)zEncode a mapping type.rbrrr) r%rrxrawjoinitems_element_to_bsonr6r)r3r check_keysrrvalr|s r~_encode_mappingr?s5!~UEII 666 88RWR]R]R_`hc3%c3 DA` aD T>Ic$i!m4 4t ;g EEas B ctd|zdz}t|dz }|td|j||z }|td|j||z }|j |td|j ||z }|j jD]\}}|t||||z }|dz }tt||z |||dzt|S)zEncode bson.dbref.DBRef.rbsrs$refs$ids$dbr) ryr_name_value_to_bsonriddatabase_DBRef__kwargsr;r<r6rx)r3rr=rbufbeginrr>s r~ _encode_dbrefrGs GdN%88 9C HqLE {E,<,Ic$i!m4 4t ;g EEasA"cdt|d}d|ztt|dzz|zdzS)zEncode a python str.rrarr)r(r6r)r3rrrbvalues r~ _encode_textrNs7 5 !! $F T>Ic&kAo6 6 ?' IIrc|j}|dk(rtt||z}d|ztt||z|zS)zEncode bson.binary.Binary.rrd)rr6r_PACK_LENGTH_SUBTYPE)r3rrrrs r~_encode_binaryrQsEmmG!|#e*%- T>0UWE E MMrcd|j}tj||}t||||S)zEncode uuid.UUID.)r)rr from_uuidrQ)r3rrrrbinvals r~ _encode_uuidrUs222   e9L MF $t 44rc&d|z|jzS)zEncode bson.objectid.ObjectId.rf)binary)r3rrrs r~_encode_objectidrXs T>ELL ((rc"d|z|xrdxsdzS)z%Encode a python boolean (True/False).rgr`rrr2s r~ _encode_boolrZs T>U.w9' ::rc:t|}d|zt|zSzEncode datetime.datetime.rh)r) _PACK_LONGr3rrrmilliss r~_encode_datetimer` s  'F T>Jv. ..rc:t|}d|zt|zSr\)intr]r^s r~_encode_datetime_msrcs ZF T>Jv. ..rc d|zS)zEncode python None.rirr3rrrs r~ _encode_nonerf T>rc,|j}|tjk(rd|zt|jzdzS|dk(rd|zt|jzdzSd}|tj zr|dz }|tj zr|dz }|tjzr|dz }|tjzr|d z }|tjzr|d z }|tjzr|d z }|dz }d|zt|jz|zS) z*Encode a python regex or bson.regex.Regex.rjsurrrilmsux) flagsreUNICODEr+r IGNORECASELOCALE MULTILINEDOTALLVERBOSE)r3rrrrosflagss r~ _encode_regexrxs KKE  ~ 4U]] CChNN !~ 4U]] CCgMM 2== dNF 299  dNF 2<<  dNF 299  dNF 2::  dNF 2::  dNF'~ 4U]] CCfLLrct|}t|}|jd|zt|z|zSt |jd|d}td|zt|z}d|z|zt|z|z|zS)zEncode bson.code.Code.rlFrrn)r-rrr6 _dict_to_bson)r3rrrcstringcstrlenr full_lengths r~ _encode_coder~5sU#G'lG {{~ ' 22W<< %++udE :EAK#e*45K T>K ')G*< Ju$55 5|| T HIt S Ts 2 AcNd|zt|j|jzS)z Encode bson.timestamp.Timestamp.rp)_PACK_TIMESTAMPrtimer2s r~_encode_timestamprKs T>OEIIuzzB BBrcl d|zt|zS#tj$r tddwxYw)zEncode a bson.int64.Int64.rqrN)r]rrrr2s r~ _encode_longrPs?P~ 5 111 <<PDE4OPs 3c&d|z|jzS)z"Encode bson.decimal128.Decimal128.rr)bidr2s r~_encode_decimal128rXs T>EII %%rc d|zS)zEncode bson.min_key.MinKey.rsrres r~_encode_minkeyr]rgrc d|zS)zEncode bson.max_key.MaxKey.rtrres r~_encode_maxkeyrbrgr _type_markerc# K|]}|ywrvr)rts r~rrs-a-s cd} tt|||||S#t$rYn!t$rt |t sd}YnwxYwt |dd}t |t r.|tvr&t|}|tt|<|||||S|s\|jjrF|jjjt|} | t|| |||dStD]9} |rt || st| }|tt|<|||||cS|jj} |s| t|| |||dS|r tdtd|d t|) z!Encode a single name, value pair.FTrN)in_custom_call)in_fallback_callrzcannot encode object: z , of type: ) _ENCODERSrrrrwrbgetattr_MARKERSr _encoder_maprrA_BUILT_IN_TYPES_fallback_encoderr.) r3rr=rrrwas_integer_overflowmarkerfunccustom_encoderbasefallback_encoders r~rArAs! $e%dE:tDD   $%%  $ $UND 1F&#6X#5!% $u+D%T22 d00==++88<># !D/G"HI I #:!D/D"EF F c?D tUJ ==rc t|rtt|jS g}|r$d|vr |j t d|d|||j D]+\}}|r|dk7s |j t||||- dj|}tt|dz|zd zS#t$r}td|d||d}~wwxYw#t$rtd|dwxYw) zEncode a document to BSON._ids_idzInvalid document z | Nz)encoder expected a mapping type but got: rrr)r%rrxr9rrAr;r<r.AttributeError TypeErrorr:r6r) docr=r top_levelelementsrrerrencodeds r~rzrzs3E377## W # OO/ CJ TXY Z))+ VJCu VOO$4S%T$RS Vhhx G S\A% & 07 :: 'V),=cU#cU*KLRUUV WCC7KLRVVWs0AC.B< C< CCCCC8z1codec_options must be an instance of CodecOptionscHt|tstt|||S)aEncode a document to BSON. A document can be any mapping type (like :class:`dict`). Raises :class:`TypeError` if `document` is not a mapping type, or contains keys that are not instances of :class:`str`. Raises :class:`~bson.errors.InvalidDocument` if `document` cannot be converted to :class:`BSON`. :param document: mapping type representing a document :param check_keys: check if keys start with '$' or contain '.', raising :class:`~bson.errors.InvalidDocument` in either case :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. .. versionadded:: 3.9 )rwr#_CODEC_OPTIONS_TYPE_ERRORrz)documentr= codec_optionss r~rXrXs#. m\ 2'' :} ==rcyrvrr|rs r~rYrY rcyrvrrs r~rYrY%rrcn|xst}t|tstt dt ||S)aDecode BSON to a document. By default, returns a BSON document represented as a Python :class:`dict`. To use a different :class:`MutableMapping` class, configure a :class:`~bson.codec_options.CodecOptions`:: >>> import collections # From Python standard library. >>> import bson >>> from bson.codec_options import CodecOptions >>> data = bson.encode({'a': 1}) >>> decoded_doc = bson.decode(data) >>> options = CodecOptions(document_class=collections.OrderedDict) >>> decoded_doc = bson.decode(data, codec_options=options) >>> type(decoded_doc) :param data: the BSON to decode. Any bytes-like object that implements the buffer protocol. :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. .. versionadded:: 3.9 $Union[dict[str, Any], _DocumentType])r"rwr#rrr)r|rrs r~rYrY*s46,D/DD dL )'' 6 dD8Q RRrc Jt|\}}t|}g}d}|dz }t|j} ||krt ||d}||z |kr t d||zdz } || dk7r t d|r(|j |j||| dz|n!|j t|||dz| |||z }||kr|S#t $rt$r=tj\} } } t t| j| dwxYw)z)Decode a BSON data to multiple documents.rrzinvalid object sizerrN) rVrr%rrr-rrrrrrr) r|rr}data_lendocsrruse_rawrrrrrs r~ _decode_allrLsC"4(JD$4yH "DH Q,C!$"5"56GKn'h7:H("X-!"788)A-GG}!!),, D//X! 0LdST -dD(Q,QUVW  Hn  K"||~9f#i.)88@dJKsBCCAD"cyrvrrs r~rZrZnrrcyrvrrs r~rZrZsrcj|t|tSt|tstt||S)a+Decode BSON data to multiple documents. `data` must be a bytes-like object implementing the buffer protocol that provides concatenated, valid, BSON-encoded documents. :param data: BSON data :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. .. versionchanged:: 3.9 Supports bytes-like objects that implement the buffer protocol. .. versionchanged:: 3.0 Removed `compile_re` option: PyMongo now always represents BSON regular expressions as :class:`~bson.regex.Regex` objects. Use :meth:`~bson.regex.Regex.try_compile` to attempt to convert from a BSON regular expression to a Python regular expression object. Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with `codec_options`. )rr"rwr#rrs r~rZrZzs504!677 m\ 2'' t] ++rc t|jri}n|j}|jD]G\}}||vr9||dk(rt|j||||</t ||||||<C|||<I|S)Nr)r%rr;rr9_decode_selective)rawdocfieldsrrrrs r~rrs=778 **,lln  U &=c{a(]CCHC,6#; CCH  JrcTd}t|}t||t|\}}|dz }g}|j}||dz krG||dk7r|dz }||dk7r|dz }t|||\}}|||||z||z }||dz krG||k7r t ddj |S)Nrrrrr)rzrrrr-r:)r|rr}rrbuffersrrs r~_array_of_documents_to_bufferrsH d D dHc$i 8FAs MH "G ^^F S1W 8n! MH8n!A &tXs; !tHx(234H S1W 3899 88G rc|jd}|sydD]/}|j|}|st|}|r|g||<+g||<1y)z=Convert raw array of documents to a stream of BSON documents.cursorN) firstBatch nextBatch)rr)rrrbatchr|s r~&_convert_raw_document_lists_to_streamsrsY \\( #F * 3 ,U3 &F3KF3Krc|jjs t||S|st||jdSddlm}|j|d}t ||}t|||gS)aWDecode BSON data to a single document while using user-provided custom decoding logic. `data` must be a string representing a valid, BSON-encoded document. :param data: BSON data :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions` with user-specified type decoders. If no decoders are found, this method is the same as ``decode_all``. :param fields: Map of document namespaces where data that needs to be custom decoded lives or None. For example, to custom decode a list of objects in 'field1.subfield1', the specified value should be ``{'field1': {'subfield1': 1}}``. If ``fields`` is an empty map or None, this method is the same as ``decode_all``. :return: Single-member list containing the decoded document. .. versionadded:: 3.8 N)rrr<)rr)rrrZ with_options bson.raw_bsonr=rr)r|rrr=internal_codec_options_docs r~_decode_all_selectivers.  & & 3 3$ .. $ : : : NOO.>Hd++ sA8A:ct|tstdt| t |t y#t $rYywxYw)aCheck that the given string represents valid :class:`BSON` data. Raises :class:`TypeError` if `bson` is not an instance of :class:`bytes`. Returns ``True`` if `bson` is valid :class:`BSON`, ``False`` otherwise. :param bson: the data to be validated z:BSON data must be an instance of a subclass of bytes, not TF)rwrxrrrr"r)bsons r~r]r]csN dE "TUYZ^U_T`abbd12 s: AAcLeZdZdZedef ddZef ddZy)r^zBSON (Binary JSON) data. .. warning:: Using this class to encode and decode BSON adds a performance cost. For better performance use the module level functions :func:`encode` and :func:`decode` instead. Fc(|t|||S)aEncode a document to a new :class:`BSON` instance. A document can be any mapping type (like :class:`dict`). Raises :class:`TypeError` if `document` is not a mapping type, or contains keys that are not instances of :class:`str'. Raises :class:`~bson.errors.InvalidDocument` if `document` cannot be converted to :class:`BSON`. :param document: mapping type representing a document :param check_keys: check if keys start with '$' or contain '.', raising :class:`~bson.errors.InvalidDocument` in either case :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. .. versionchanged:: 3.0 Replaced `uuid_subtype` option with `codec_options`. )rX)clsrr=rs r~rXz BSON.encode~s46(J >??rct||S)aDecode this BSON data. By default, returns a BSON document represented as a Python :class:`dict`. To use a different :class:`MutableMapping` class, configure a :class:`~bson.codec_options.CodecOptions`:: >>> import collections # From Python standard library. >>> import bson >>> from bson.codec_options import CodecOptions >>> data = bson.BSON.encode({'a': 1}) >>> decoded_doc = bson.BSON(data).decode() >>> options = CodecOptions(document_class=collections.OrderedDict) >>> decoded_doc = bson.BSON(data).decode(codec_options=options) >>> type(decoded_doc) :param codec_options: An instance of :class:`~bson.codec_options.CodecOptions`. .. versionchanged:: 3.0 Removed `compile_re` option: PyMongo now always represents BSON regular expressions as :class:`~bson.regex.Regex` objects. Use :meth:`~bson.regex.Regex.try_compile` to attempt to convert from a BSON regular expression to a Python regular expression object. Replaced `as_class`, `tz_aware`, and `uuid_subtype` options with `codec_options`. )rY)selfrs r~rYz BSON.decodes@dM**rN) rz Type[BSON]rMapping[str, Any]r=boolrCodecOptions[Any]returnr^)rrrdict[str, Any])__name__ __module__ __qualname____doc__ classmethodr"rXrYrrr~r^r^vss!+@ @ @#@@) @  @@82G +. +  +rr^ctS)zIs the C extension installed?)_USE_Crrr~r_r_s Mrc~tjjrtjjyy)z!Releases the ObjectID lock child.N)r6 _inc_locklockedreleaserrr~ _after_forkrs+  """$#rregister_at_fork)after_in_child)r|r rzTuple[Any, memoryview])rrbrrrr)r|r rr rrbrr rr rr rTuple[int, int]) r|r r}r rrbrrrTuple[str, int])r|r rr rrbrr rr rr rzTuple[float, int])r|r r}r rrbrrbrrrr rr)r|r rrbrrbrr)r|r r}r rrbrrbrrrr rTuple[Any, int])r|r r}r rrbrrbrrrrrr)r|r rr rrbrrbrrrr rz$Tuple[Union[Binary, uuid.UUID], int])r|r rr rrbrr rr rr rzTuple[ObjectId, int])r|r rr rrbrr rr rr rzTuple[bool, int])r|r rr rrbrrbrrrr rz0Tuple[Union[datetime.datetime, DatetimeMS], int])r|r r}r rrbrrbrrrrrTuple[Code, int])r|r r}r rrbrrbrrrrrr)r|r r}r rrbrr rrrr rzTuple[Regex[Any], int])r|r r}r rrbrrbrrrrrzTuple[DBRef, int])r|r rr rrbrr rr rr rzTuple[Timestamp, int])r|r rr rrbrr rr rr rzTuple[Int64, int])r|r rr rrbrr rr rr rzTuple[Decimal128, int])F)r|r r}r rrbrrbrrrrrr)r|r rrbrrbrzCodecOptions[RawBSONDocument]rrrrrr)NF)r|r r}r rrbrrbrrrr rrrr )r|r rCodecOptions[_DocumentType]rr>)rzGenerator[bytes, None, None])r*zUnion[str, bytes]rrx)r*rrrx) r3rxrfloatrr rr rrx) r3rxrrxrr rr rrx) r3rxrr r=rrrrrx) r3rxrr+r=rrrrrx) r3rxrz Sequence[Any]r=rrrrrx) r3rxrrrr rr rrx) r3rxrrrr rr rrx) r3rxrz uuid.UUIDrr rrrrx) r3rxrr6rr rr rrx) r3rxrrrr rr rrx) r3rxrzdatetime.datetimerr rr rrx) r3rxrr(rr rr rrx) r3rxrr rr rr rrx) r3rxrz Regex[Any]rr rr rrx) r3rxrr!rr rrrrx) r3rxrrbrr rr rrx) r3rxrr rr rr rrx) r3rxrr,rr rr rrx)FF)r3rxrr r=rrrrrrrrrx) rr rr r=rrrrrx)T) rr r=rrrrrrrx)rrr=rrrrrxrv)r|r?rNonerr)r|r?rrrr>)r|r?r%Optional[CodecOptions[_DocumentType]]rr)r|r?rrrlist[_DocumentType])r|r?rrrzlist[dict[str, Any]])r|r?rrrr)r|r?rrrz0Union[list[dict[str, Any]], list[_DocumentType]])rr rr rrrr>)r|zUnion[memoryview, bytes]rrx)rr rr)r|r rrrr rr)r|rxrrrIterator[dict[str, Any]])r|rxrrrIterator[_DocumentType])r|rxrrr8Union[Iterator[dict[str, Any]], Iterator[_DocumentType]])rUnion[BinaryIO, IO[bytes]]rrrr)rrrrrr)rrrrrr)rrxrr)rr)rr)r __future__rdatetimer!osrprruuidcodecsrrrr( collectionsr_abctypingrrr r r r r rrrrrrrrrrr bson.binaryrrrrrrrr bson.coder!bson.codec_optionsr"r#r$r%bson.datetime_msr&r'r(r)r* bson.dbrefr+bson.decimal128r, bson.errorsr-r.r/ bson.int64r0 bson.max_keyr2 bson.min_keyr4 bson.objectidr6 bson.regexr7bson.sonr8r9bson.timestampr: bson.tz_utilr;rr= bson.typingsr>r?rr@r ImportError__all__rArBrCrDrErFrGrHrIrJrKrLrMrNrOrPrQrRrSrTrUStruct unpack_fromrunpack _UNPACK_INTrrrrrVrrrrrrrrrrrrrrrrrrrrr__annotations__rrrr rrpackr1r6rPr]rtupleranger rWr+r-r/r4r7r?rGrKrNrQrUrXrZr`rcrfrxr~rrrrrrrrxdictrrblistrUUIDrr_typhasattrrrrAr<rzrrrXrYrrZrrrrr[r\r]r^r_rrrrr~r.sA8r# 00#*    &GG"!$-; F= ~                     #V]]4(44fmmD!((  6==&22+fmmE2>>!FMM$'33&u-99 = ==%(=25=?B=LO==b ? ??%(?25??B?LO?? b  b b$' b25 b=N bWZ b b" $'25=NWZ*' ' ' $'' 25' =N' ^a' ' T" ""%("36">O"Y\")"J- --%(-25-?B-LO-- B  B B%( B25 B?B BLO B BY YY%(Y25Y=NYX[Y5Y   $' 25 =N ^a   '  ' '$' '36 '>O '_b ' ' $'14L*>L+>L+>L* > L+ > L4 >L(>L,>L)>L4>L*>L(>L)>L+>L#> L(!>"L.#>$L*L/L8L8+>:2                  * ---- -  -  - -< TS12      (      (        . K  ((MfmmD!&& FMM$  $ $ $v}}U+00 V]]4 % % &--&++JeDkJJ  ;2$ 2./ D F"F F%F37F?PF FJ N5) ; / /  M4OTC P&   ,  =  ' #    /    =    ,   <  J   II|  N  <  ,   =! " N# $ N  = ]  "LL/5  <  6Dt^$&/o""#6 -9--!" AX AX AXAX  AX  AX  AX AXH >LP; ;;&7;DH; ;. ((M&&YZ '<>>>%> >:     SWS S*OS)SDK< $$K    *E SW, ,*O,5,B -H.* $*$H$H!  * *9*CF**Z     IM ,  , E ,= ,F @D(9=   (9T <@,(,8,>,@&D+5D+N %  2!"B{3 #e) Fs-\88]]