+\hKUdZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z mZmZmZmZmZmZmZddlmZmZmZmZddlmZddlmZmZddlm Z m!Z!m"Z"m#Z#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z*dd l+m,Z,dd l-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ejrejtejvejxejzej|dZ?GddZ@GddZAe r eeeBe fZCneZCdZDGddeCZEeEeAjZGdeHd< eEeAjZJdeHd< eEeAjZLdeHd< eLZMdeHd< dvd ZNdwd!ZOeMfdxd"ZPeMf dyd#ZQeMfdzd$ZRd{d%ZSd|d&ZTd}d'ZUd|d(ZVd|d)ZW d~d*ZXdd+ZYdd,ZZdd-Z[dd.Z\d{d/Z]d{d0Z^dd1Z_dd2Z`dd3Zadd4Zbdd5Zcdd6Zdd|d7Zedd8Zfid9eYd:e]d;eXdedd?eed@e[dAeTdBdCdDe`dEefdFebdGe^dHe\dIeZdJe_dKeaiZgdLeHdM<ehegZiddNZjddOZkddPZlddQZmddRZnddSZoddTZpddUZqddVZrddWZsddXZtddYZuddZZvdd[Zwdd\Zxdd]Zydd^Zzdd_Z{ie|ene}esejere"eke~eqeepeBenedenejeueete*emeele&eye,e{e.eze0eve2eoe4eoe6ewe(exiZd`eHda<iZdbeHdc<eD]Zeedds eeeej <!edeeDZeMfdxdfZddgZddhZddiZddjZe0dkedle*dle(dle6dme.dne,dniZdoeHdp<eBee}eejee2ee&eiZdqeHdr<dddsZddtZdduZy)a\Tools for using Python's :mod:`json` module with BSON documents. This module provides two helper methods `dumps` and `loads` that wrap the native :mod:`json` methods and provide explicit BSON conversion to and from JSON. :class:`~bson.json_util.JSONOptions` provides a way to control how JSON is emitted and parsed, with the default being the Relaxed Extended JSON format. :mod:`~bson.json_util` can also generate Canonical or legacy `Extended JSON`_ when :const:`CANONICAL_JSON_OPTIONS` or :const:`LEGACY_JSON_OPTIONS` is provided, respectively. .. _Extended JSON: https://github.com/mongodb/specifications/blob/master/source/extended-json/extended-json.md Example usage (deserialization): .. doctest:: >>> from bson.json_util import loads >>> loads( ... '[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$scope": {}, "$code": "function x() { return 1; }"}}, {"bin": {"$type": "80", "$binary": "AQIDBA=="}}]' ... ) [{'foo': [1, 2]}, {'bar': {'hello': 'world'}}, {'code': Code('function x() { return 1; }', {})}, {'bin': Binary(b'...', 128)}] Example usage with :const:`RELAXED_JSON_OPTIONS` (the default): .. doctest:: >>> from bson import Binary, Code >>> from bson.json_util import dumps >>> dumps( ... [ ... {"foo": [1, 2]}, ... {"bar": {"hello": "world"}}, ... {"code": Code("function x() { return 1; }")}, ... {"bin": Binary(b"")}, ... ] ... ) '[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "00"}}}]' Example usage (with :const:`CANONICAL_JSON_OPTIONS`): .. doctest:: >>> from bson import Binary, Code >>> from bson.json_util import dumps, CANONICAL_JSON_OPTIONS >>> dumps( ... [ ... {"foo": [1, 2]}, ... {"bar": {"hello": "world"}}, ... {"code": Code("function x() { return 1; }")}, ... {"bin": Binary(b"")}, ... ], ... json_options=CANONICAL_JSON_OPTIONS, ... ) '[{"foo": [{"$numberInt": "1"}, {"$numberInt": "2"}]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "00"}}}]' Example usage (with :const:`LEGACY_JSON_OPTIONS`): .. doctest:: >>> from bson import Binary, Code >>> from bson.json_util import dumps, LEGACY_JSON_OPTIONS >>> dumps( ... [ ... {"foo": [1, 2]}, ... {"bar": {"hello": "world"}}, ... {"code": Code("function x() { return 1; }", {})}, ... {"bin": Binary(b"")}, ... ], ... json_options=LEGACY_JSON_OPTIONS, ... ) '[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }", "$scope": {}}}, {"bin": {"$binary": "AQIDBA==", "$type": "00"}}]' Alternatively, you can manually pass the `default` to :func:`json.dumps`. It won't handle :class:`~bson.binary.Binary` and :class:`~bson.code.Code` instances (as they are extended strings you can't provide custom defaults), but it will be faster as there is less recursion. .. note:: If your application does not need the flexibility offered by :class:`JSONOptions` and spends a large amount of time in the `json_util` module, look to `python-bsonjs `_ for a nice performance improvement. `python-bsonjs` is a fast BSON to MongoDB Extended JSON converter for Python built on top of `libbson `_. `python-bsonjs` works best with PyMongo when using :class:`~bson.raw_bson.RawBSONDocument`. ) annotationsN) TYPE_CHECKINGAnyCallableMappingMutableMappingOptionalSequenceTupleTypeUnioncast)ALL_UUID_SUBTYPES UUID_SUBTYPEBinaryUuidRepresentation)Code) CodecOptionsDatetimeConversion) _MAX_UTC_MS EPOCH_AWARE DatetimeMS_datetime_to_millis_millis_to_datetime)DBRef) Decimal128)Int64)MaxKey)MinKey)ObjectId)Regex)RE_TYPE Timestamp)utc)ilmsuxceZdZdZ dZ dZy)DatetimeRepresentationrN)__name__ __module__ __qualname__LEGACY NUMBERLONGISO8601Q/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/bson/json_util.pyr-r-s$ FJG r7r-ceZdZdZ dZ dZy)JSONModerr.r/N)r0r1r2r3RELAXED CANONICALr6r7r8r:r:s$ FG I r7r:lceZdZUded<ded<ded<ded<ded<dfd Zd d d ej f dfd Zdfd Zdfd Z ddZ xZ S) JSONOptionsint json_modeboolstrict_number_longdatetime_representation strict_uuidzType[MutableMapping[str, Any]]document_classc"t|y)a Encapsulates JSON options for :func:`dumps` and :func:`loads`. :param strict_number_long: If ``True``, :class:`~bson.int64.Int64` objects are encoded to MongoDB Extended JSON's *Strict mode* type `NumberLong`, ie ``'{"$numberLong": "" }'``. Otherwise they will be encoded as an `int`. Defaults to ``False``. :param datetime_representation: The representation to use when encoding instances of :class:`datetime.datetime`. Defaults to :const:`~DatetimeRepresentation.LEGACY`. :param strict_uuid: If ``True``, :class:`uuid.UUID` object are encoded to MongoDB Extended JSON's *Strict mode* type `Binary`. Otherwise it will be encoded as ``'{"$uuid": "" }'``. Defaults to ``False``. :param json_mode: The :class:`JSONMode` to use when encoding BSON types to Extended JSON. Defaults to :const:`~JSONMode.LEGACY`. :param document_class: BSON documents returned by :func:`loads` will be decoded to an instance of this class. Must be a subclass of :class:`collections.MutableMapping`. Defaults to :class:`dict`. :param uuid_representation: The :class:`~bson.binary.UuidRepresentation` to use when encoding and decoding instances of :class:`uuid.UUID`. Defaults to :const:`~bson.binary.UuidRepresentation.UNSPECIFIED`. :param tz_aware: If ``True``, MongoDB Extended JSON's *Strict mode* type `Date` will be decoded to timezone aware instances of :class:`datetime.datetime`. Otherwise they will be naive. Defaults to ``False``. :param tzinfo: A :class:`datetime.tzinfo` subclass that specifies the timezone from which :class:`~datetime.datetime` objects should be decoded. Defaults to :const:`~bson.tz_util.utc`. :param datetime_conversion: Specifies how UTC datetimes should be decoded within BSON. Valid options include 'datetime_ms' to return as a DatetimeMS, 'datetime' to return as a datetime.datetime and raising a ValueError for out-of-range values, 'datetime_auto' to return DatetimeMS objects when the underlying datetime is out-of-range and 'datetime_clamp' to clamp to the minimum and maximum possible datetimes. Defaults to 'datetime'. See :ref:`handling-out-of-range-datetimes` for details. :param args: arguments to :class:`~bson.codec_options.CodecOptions` :param kwargs: arguments to :class:`~bson.codec_options.CodecOptions` .. seealso:: The specification for Relaxed and Canonical `Extended JSON`_. .. versionchanged:: 4.0 The default for `json_mode` was changed from :const:`JSONMode.LEGACY` to :const:`JSONMode.RELAXED`. The default for `uuid_representation` was changed from :const:`~bson.binary.UuidRepresentation.PYTHON_LEGACY` to :const:`~bson.binary.UuidRepresentation.UNSPECIFIED`. .. versionchanged:: 3.5 Accepts the optional parameter `json_mode`. .. versionchanged:: 4.0 Changed default value of `tz_aware` to False. N)super__init__)selfargskwargs __class__s r8rHzJSONOptions.__init__sl r7Nc$|jdd|d<|dr|jdt|d<|tjtjtj dfvr t dttt|(|g|i|}|tjtjtjfvr t d||_|jtjk(r`|r t d|dtj fvr t d|dvr t d d|_tj |_d |_|S|jtjk(rb|dvr t d |dtjfvr t d |dvr t d d |_tj|_d |_|Sd|_tj|_d|_|||_|||_|||_|S) Ntz_awareFtzinfoznJSONOptions.datetime_representation must be one of LEGACY, NUMBERLONG, or ISO8601 from DatetimeRepresentation.zQJSONOptions.json_mode must be one of LEGACY, RELAXED, or CANONICAL from JSONMode.zrG__new__r:r;r<r@rBrCrD) clsrBrCrDr@rJrKrIrLs r8rRzJSONOptions.__new__1s-$ZZ E:z * %zz(C8F8  " " ) ) " - - " * *  +  F K!Ft!Fv!FG X__h.>.>@R@RS S. # >>X-- -! !_``&t5K5S5S.TT ?,. !YZZ&+D #+A+I+ID (#D 0 /^^x11 1!5 !`aa&t5K5V5V.WW B,. !YZZ&*D #+A+L+LD (#D  ',D #+A+H+HD ($D !-*<'&2/F,&#.  r7c dj|j|j|j|jt |S)Nz[strict_number_long={!r}, datetime_representation={!r}, strict_uuid={!r}, json_mode={!r}, {})formatrBrCrDr@rG_arguments_repr)rIrLs r8rVzJSONOptions._arguments_reprtsD 3396'',,  ') 4 r7ct|}|j|j|j|j |j d|S)NrBrCrDr@)rG _options_dictupdaterBrCrDr@)rI options_dictrLs r8rYzJSONOptions._options_dictsMw,. &*&=&=+/+G+G#//!^^   r7c |j}dD]!}|j|t||||<#|j|t di|S)a Make a copy of this JSONOptions, overriding some options:: >>> from bson.json_util import CANONICAL_JSON_OPTIONS >>> CANONICAL_JSON_OPTIONS.tz_aware True >>> json_options = CANONICAL_JSON_OPTIONS.with_options(tz_aware=False, tzinfo=None) >>> json_options.tz_aware False .. versionadded:: 3.12 rXr6)rYrPgetattrrZr>)rIrKoptsopts r8 with_optionszJSONOptions.with_optionssV!!#` )rbstr)rbzdict[Any, Any])rKrrbr>) r0r1r2__annotations__rHr:r;rRrVrYr` __classcell__)rLs@r8r>r>sN  226t.215&*!)) A A*A"/A$ A  A  AA AF   #r7r>)r@LEGACY_JSON_OPTIONSCANONICAL_JSON_OPTIONSRELAXED_JSON_OPTIONSDEFAULT_JSON_OPTIONSct|jdt}tjt ||g|i|S)aQHelper function that wraps :func:`json.dumps`. Recursive function that handles all BSON types including :class:`~bson.binary.Binary` and :class:`~bson.code.Code`. :param json_options: A :class:`JSONOptions` instance used to modify the encoding of MongoDB Extended JSON types. Defaults to :const:`DEFAULT_JSON_OPTIONS`. .. versionchanged:: 4.0 Now outputs MongoDB Relaxed Extended JSON by default (using :const:`DEFAULT_JSON_OPTIONS`). .. versionchanged:: 3.4 Accepts optional parameter `json_options`. See :class:`JSONOptions`. json_options)poprijsondumps _json_convert)objrJrKrks r8rnrns5"::n.BCL ::mC6 H H HHr7c|jdtjtur fd|d<nfd|d<t j |g|i|S)aHelper function that wraps :func:`json.loads`. Automatically passes the object_hook for BSON type conversion. Raises ``TypeError``, ``ValueError``, ``KeyError``, or :exc:`~bson.errors.InvalidId` on invalid MongoDB Extended JSON. :param json_options: A :class:`JSONOptions` instance used to modify the decoding of MongoDB Extended JSON types. Defaults to :const:`DEFAULT_JSON_OPTIONS`. .. versionchanged:: 4.0 Now loads :class:`datetime.datetime` instances as naive by default. To load timezone aware instances utilize the `json_options` parameter. See :ref:`tz_aware_default_change` for an example. .. versionchanged:: 3.5 Parses Relaxed and Canonical Extended JSON as well as PyMongo's legacy format. Now raises ``TypeError`` or ``ValueError`` when parsing JSON type wrappers with values of the wrong type or any extra keys. .. versionchanged:: 3.4 Accepts optional parameter `json_options`. See :class:`JSONOptions`. rkct|SN) object_hookrprks r8zloads..sK\,Jr7rtct|Srs)object_pairs_hookpairsrks r8rvzloads..s4Ee\4Zr7rx)rlrirEdictrmloads)r)rJrKrks @r8r|r|sR2::n.BCL""d* J}&Z"# ::a )$ )& ))r7c @t|dr.|jDcic]\}}|t||c}}St|dr0t|tt fs|Dcgc]}t||c}S t ||Scc}}wcc}w#t$r|cYSwxYw)z]Recursive helper method that converts BSON types so they can be converted into json. items__iter__)hasattrr~ro isinstancercbytesdefault TypeError)rprkkvs r8rorossG>AiikJda=L11JJ j !*S3,*G8;<1 a.<<sL)) K<  sB!B 8 B BBc8t|j||Srs)rtrErys r8rxrx s |2259< HHr7cRd}|D]}|tvs |}n|rt|||S|Srs) _PARSERS_SET_PARSERS)dctrkmatchrs r8rtrtsA E  E  sL11 Jr7c|d}t|ttfs|Sd}|jddD]}|tj|dz}t ||S)N$regexr$options)rrcrrP _RE_OPT_TABLEr!)docdummy0patternflagsr_s r8_parse_legacy_regexrsa(mG gU| , Ewwz2&+ ""3**+ %  r7c<t|dk7rtd|t|dtstd||jt j k(r+tjtj|dStj|dS)z*Decode a JSON legacy $uuid to Python UUID.r.zBad $uuid, extra field(s): $uuidz$uuid must be a string: ) lenrrrcuuid_representationr UNSPECIFIEDr from_uuiduuidUUIDrrks r8_parse_legacy_uuidr)s 3x1}5cU;<< c'lC (23%899''+=+I+II #g, 788yyW&&r7c^|tvr{|j}t||}|tjk(r|S|t k(rtj }n#|tj k(rtj}|j|S|dk(rttj|St||SNr) rrrrrrSTANDARD PYTHON_LEGACYas_uuidrrr)datasubtyperkr binary_values r8_binary_or_uuidr5s##*>>dG, "4"@"@ @  l ""4"="=  $6$?$? ?#5"B"B ##$788!|DIIt$$ $  r7ct|dtr d|dz|d<t|dd}|dk\rt|dddd}tj|dj }t |||S)N$type%02xl$binary)rr?base64 b64decodeencoder)rrkrrs r8_parse_legacy_binaryrJs}#g,$G ,G #g,#G*c'l12&+   C N113 4D 4, 77r7c`|d}|d}|d}t|tstd|t|trt|dkDrtd|t|dk7rtd|t j |j }t|t|d|S) NrrsubTypez!$binary base64 must be a string: r/z7$binary subType must be a string at most 2 characters: z=$binary must include only "base64" and "subType" components: r) rrcrrrrrrr?)rrkbinaryb64rrs r8_parse_canonical_binaryrTs ^F  CYG c3 ;C5ABB gs #s7|a'7QRUQVWXX 6{aWX[W\]^^   CJJL )D 4Wb!1< @@r7c|d}t|dk7rtd|t|tr |ddk(r|dd}d}nB|ddvr|d d k(r |dd}|dd}n(|d dvr |dd }|d d}n|d dvr |dd }|d d}n|}d }|j d}d}|dk7rtt||ddz}|d|}tjj|dj|t}|r|dk7rt|dk(r5|ddjd \} } t| dzt| dzz} nQt|dk(r$t|dddzt|dddzz} nt|dk(rt|dddz} |ddk(r dz} |tj z }|jrQ|j r|j#|j }|j$t&j(k(r t+|S|S|jd} |j$t&j(k(r t+| S| St-t|t/d|S#t$r}t d |d|d}~wwxYw)z3Decode a JSON datetime to python datetime.datetime.$dater.zBad $date, extra field(s): ZNi)+-:rz time data z( does not match ISO-8601 datetime format.ri@B%Y-%m-%dT%H:%M:%S) microsecondrOri<r)secondsrOzCodecOptions[Any])rrrrc IndexErrorrQrfindr?floatdatetimestrptimereplacer%split timedeltarNrO astimezonedatetime_conversionr DATETIME_MSrrr) rrkdtmdtoffsetexc dot_indexrawarehoursminutessecsaware_tzinfo_nones r8_parse_canonical_datetimercs g,C 3x1}5cU;<<#s d2w#~"XRJ&3r7c>"XRSRJ&"XRSRJ&"XRS HHSM  ?eByzN3g=>KJYB!!**2/BCKK#CL  fm6{a!'!1!1#!6w5zD(3w<"+<<V!6!A;'$.VABZ21EEV!6!A;'$.ayC H..t<> v;r7cr|D]}|dvstd|t|d|jdS)z%Decode a JSON code to bson.code.Code.$code$scopezBad $code, extra field(s): rr)scope)rrrP)rrkeys r8_parse_canonical_codersKA ) )9#?@ @A G CGGH$5 66r7c|d}t|dk7rtd|t|dk7rtd||d}t|tstdt |zt |d|S) z(Decode a JSON regex to bson.regex.Regex.$regularExpressionr.z(Bad $regularExpression, extra field(s): r/zLBad $regularExpression must include only "pattern and "options" components: optionszCBad $regularExpression options, options must be string, was type %sr)rrrrctyper!)rrregexr^s r8_parse_canonical_regexrs $ %E 3x1}B3%HII 5zQZ[^Z_ `    D dC  QUYZ^U_ `   y!4 ((r7ct|jdtrkd|vrgt|jdttdfr=t |j d|j dfd|j ddi|S|S)z(Decode a JSON DBRef to bson.dbref.DBRef.$refz$idz$dbNdatabase)rrPrcrrrlrs r8_parse_canonical_dbrefrsp 3776?C( SL swwu~T$Z'8 9SWWV_cggen[swwud?S[WZ[[ Jr7c`|d}t|dk7rtd|t|trp|j }|j td|t|j tstd|t|dk7rtd||Std|) z9Decode a JSON (deprecated) DBPointer to bson.dbref.DBRef. $dbPointerr.z Bad $dbPointer, extra field(s): z!Bad $dbPointer, extra field $db: z)Bad $dbPointer, $id must be an ObjectId: r/z)Bad $dbPointer, extra field(s) in DBRef: z"Bad $dbPointer, expected a DBRef: )rrrras_docridr )rrdbref dbref_docs r8_parse_canonical_dbpointerrs  E 3x1}:3%@AA%LLN >> %? {KL L%((H-G {ST T y>Q G {ST T ?? <r7c|d}t|dk7rtd|t|tstd|t |S)z7Decode a JSON decimal128 to bson.decimal128.Decimal128.$numberDecimalr.z$Bad $numberDecimal, extra field(s): z$numberDecimal must be string: )rrrrcrr s r8_parse_canonical_decimal128r sS  !E 3x1}>seDEE eS !9#?@@ e r7ct|dtus|ddk7rtd|t|dk7rtd|t S)z,Decode a JSON MinKey to bson.min_key.MinKey.$minKeyr.z$minKey value must be 1: Bad $minKey, extra field(s): )rr?rrrrs r8_parse_canonical_minkeyrsV C N3&#i.A*=3C59:: 3x1}7u=>> 8Or7ct|dtus|ddk7r td|ft|dk7rtd|t S)z,Decode a JSON MaxKey to bson.max_key.MaxKey.$maxKeyr.z$maxKey value must be 1: %sr)rr?rrrrs r8_parse_canonical_maxkeyrsS C N3&#i.A*=5v>> 3x1}7u=>> 8Or7c:d|vr t||St||S)Nr)rrrs r8 _parse_binaryr&s##~#C66&sL99r7c0|d}t|d|dS)N $timestamptr&r#)rrtsps r8_parse_timestampr-s! l C SXs3x ((r7rrrrrrrrrz $undefinedcyrsr6)__1s r8rvrv<sr7rrrrrrrr z,dict[str, Callable[[Any, JSONOptions], Any]]rc|jtjk(r)tj|j d|zdSdtj|j d|zdiS)Nr)rrr)rr)r@r:r3r b64encodedecode)rrrks r8_encode_binaryr$Isb0!++D188:VgEUVV &"2"24"8"?"?"AfW^N^_ ``r7c*|jtjk(r5dt|cxkr tkrnnt |j |S|jtjk(r dt|iSddtt|iiS)Nrrr) rCr-r5r?r_encode_datetime as_datetimer3rcrus r8_encode_datetimemsr(Osx,,0F0N0NN S ([ ( 1<@@  - -1G1N1N NS"" mSS]3 44r7cx|j dt|iSt|t|j|dS)Nrr)rrcrorus r8 _encode_coder*Zs5 yyS""S]399l-STTr7cJ|jr dt|iSt|S)Nr)rBrcr?rus r8 _encode_int64r,as#&&s3x((3xr7c|Srsr6rprs r8 _encode_noopr/hs Jr7ctd}|jtjzr|dz }|jtjzr|dz }|jtjzr|dz }|jtj zr|dz }|jtj zr|dz }|jtjzr|dz }t|jtr |j}n|jjd}|jtjk(r||d Sd ||d iS) Nrr&r'r(r)r*r+zutf-8)rrr)rr)rre IGNORECASELOCALE MULTILINEDOTALLUNICODEVERBOSErrrcr#r@r:r3)rprkrrs r8 _encode_regexr8ls E yy2==    yy299   yy2<<   yy299   yy2::   yy2::  #++s#++++$$W-0!u55 g%"H IIr7c|jtjk(r1t |cxkr tkrnn dt |iSdt |iS|S)Nrr)r@r:r< _INT32_MAXrcrus r8 _encode_intr;sH!3!33 ;# * * #c(+ +s3x(( Jr7c|jtjk7rntj|rddiStj |r |dkDrdnd}d|iS|jtj k(rdtt|iS|S)Nr NaNrInfinityz -Infinity) r@r:r3mathisnanisinfr<rcrepr)rprkrepresentations r8 _encode_floatrDs{0 ::c?#U+ + ZZ_+.7Z N#^4 4  # #x'9'9 9$Sc^4 4 Jr7cZ|jtjk(r|js$|j t }|jJ|t k\r|jj|}|j|j|jfdk(rd}n|jd}t|jdz }|rd|fznd}dd j|jd ||iSt|}|jtj k(rd|iSdd t#|iiS) Nr)rrrrz%ziz.%03drrz{}{}{}rr)rCr-r5rOrr%r utcoffsetdaysr microsecondsstrftimer?rrUrr3rc)rprkoff tz_stringmillisfracsecss r8r&r&s++/E/M/MMzz++S+)C::) )) + **&&s+C#++s'7'78IE LL. 4/0F.4w&*"H6I)JHV_` ! %F++/E/L/LL  mS[1 22r7ct|d|Sr)r$rus r8 _encode_bytesrOs #q, //r7c0t||j|Srs)r$rrus r8_encode_binary_objrQs #s{{L 99r7c|jr8tj||j}t ||j |Sd|j iS)N)rr)rDrrrr$rhex)rprkbinvals r8 _encode_uuidrUsE!!#<;[;[\ffnnlCC!!r7cdt|iS)Nrrcr.s r8_encode_objectidrXs CH r7c8d|j|jdiS)Nr)rr&)timeincr.s r8_encode_timestampr\s sww7 88r7cdt|iS)NrrWr.s r8_encode_decimal128r^s c#h ''r7c8t|j|S)N)rk)rorrus r8 _encode_dbrefr`s L AAr7c ddiS)Nrr.r6rdummy1s r8_encode_minkeyrd q>r7c ddiS)Nrr.r6rbs r8_encode_maxkeyrgrer7z-dict[Type, Callable[[Any, JSONOptions], Any]] _ENCODERSz,dict[int, Callable[[Any, JSONOptions], Any]]_MARKERS _type_markerc# K|]}|ywrsr6).0rs r8 rms-a-s cp tt|||S#t$rYnwxYwt|dr8|j}|t vr$t |}|tt|<|||St D]4}t||st|}|tt|<|||cStd|z)Nrjz%r is not JSON serializable) rhrKeyErrorrrjri_BUILT_IN_TYPESrr)rprkmarkerfuncbases r8rrs c#C66    sN#!! X F#D#'Id3i \* * + c4 T?D#'Id3i \* * + 1C7 88s  &&ct|Srs)rrps r8 _get_str_sizervs s8Or7cLdtt|jzS)Nr)rrcrZrus r8_get_datetime_sizerxs s3sxxz?# ##r7c2dt|jzS)N)rrrus r8_get_regex_sizer{#s CKK  r7c2dt|jzS)N")r collectionrus r8_get_dbref_sizer's CNN# ##r7 zdict[Any, int]_CONSTANT_SIZE_TABLEzdict[Any, Callable[[Any], int]]_VARIABLE_SIZE_TABLEcZ||k\r|St|} t|S#t$rYnwxYw t||S#t$rYnwxYw|tk(r`|j rA|dt |j ||zt|zt|j z z }|S|dt|zz }|S|tk(rC|jD].\}}|t |||z }|t |||z }||k\s,|cS|St|dr |D]}|t |||z }||k\s|cS|S)z!Recursively finds size of objectsrr) rrrorrrget_sizerr{r~r)rpmax_size current_sizeobj_typerrr&s r8rr>srxCyH #H--     #H-c22    4 99 HSYY,??#c(JSQTQZQZ^[ L  ACL (L  T IIK $DAq HQ,? ?L HQ,? ?Lx'##  $  j ! $A HQ,? ?Lx'## $ s )) ; AAct|dkry|}t|dr>i}|jD]%\}}t||\}}|r|||<|dks"||fS||fSt|drOt|tt fs9g}|D].}t||\}}|r|j ||dks+||fS||fSt||S)zMRecursively truncate documents as needed to fit inside max_length characters.rrr~r)rr~_truncate_documentsrrcrappend _truncate)rp max_length remaining truncatedrr truncated_vs r8rrgsQIsG IIK DAq%8I%F "K* ! A~)##   )## j !*S3,*G  A%8I%F "K  -A~)##   )##i((r7cnt||}||kr|||z fS |d|}|||z fS#t$r|}YwxYwrs)rr)rprsizers r8rrs^ C #D yI$$$ JYI)d*** I s & 44)rprrJrrKrrbrc)r)zUnion[str, bytes, bytearray]rJrrKrrbr)rprrkr>rbr)rzzSequence[Tuple[str, Any]]rkr>rbr)rzMapping[str, Any]rkr>rbr)rrrrrbr)rrrkr>rbUnion[Binary, uuid.UUID])rrrr?rkr>rbr)rrrkr>rbz$Union[datetime.datetime, DatetimeMS])rrrrrbr )rrrrrbrc)rrrrrbr)rrrrrbz Regex[str])rrrrrbr?)rrrrrbr)rrrrrbr)rrrrrbr)rrrrrbr)rrrrrbr)rrrrrbr$)rrrr?rkr>rbr)rprrkr>rbr{)rprrkr>rbr{)rprrkr>rbr)rprrrrbr)rpr?rkr>rbr)rprrkr>rbr)rpdatetime.datetimerkr>rbr{)rprrkr>rbr{)rprrkr>rbr{)rpz uuid.UUIDrkr>rbr{)rpr rrrbr{)rpr$rrrbr{)rprrkr>rbr{)rrrcrrbr{)rprrbr?)rprrbr?)rpr!rbr?)rprrbr?)r)rprrr?rr?rbr?)rprrr?rbTuple[Any, int])rprrr?rbr)__doc__ __future__rrrrmr?r1rtypingrrrrrr r r r r r bson.binaryrrrr bson.coderbson.codec_optionsrrbson.datetime_msrrrrr bson.dbrefrbson.decimal128r bson.int64r bson.max_keyr bson.min_keyr bson.objectidr bson.regexr!bson.sonr"bson.timestampr$ bson.tz_utilr%ILMSUXrr-r:rc _BASE_CLASSr:r>r3rfrdr<rgr;rhrirnr|rorxrtrrrrrrrrrrrrrrr rrrrrrsetrr$r(r*r,r/r8r;rDr&rOrQrUrXr\r^r`rdrgrArrr?rrrhri_typrrjtuplerprrvrxr{rrrrrrr6r7r8rsbVn#      TS?&"$        !!H((V~c3h78KK  m#+m#`$/#I[I'2H$!$  b 2 r A A(n = ) ? ? 95&R)6 +r7