o
    Åîï]3|  ã                   @   s˜  d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
Z
ddl
mZmZmZmZ ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ej1ej2ej3ej4ej5ej6dœZ7e8g d¢ƒZ9G dd„ dƒZ:G dd„ dƒZ;G dd„ deƒZ<e<e;j=d�Z>	 e>Z?	 e<e;j@d�ZA	 e<e;jBd�ZC	 e<de:jDdd�ZE	 dd„ ZFdd „ ZGe?fd!d"„ZHe?fd#d$„ZIe?fd%d&„ZJd'd(„ ZKd)d*„ ZLd+d,„ ZMd-d.„ ZNd/d0„ ZOd1d2„ ZPd3d4„ ZQd5d6„ ZRd7d8„ ZSd9d:„ ZTd;d<„ ZUd=d>„ ZVd?d@„ ZWdAdB„ ZXdCdD„ ZYdEdF„ ZZdGdH„ Z[dIdJ„ Z\dKdL„ Z]e?fdMdN„Z^dS )Oaá  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 legacy PyMongo format.
:mod:`~bson.json_util` can also generate Canonical or Relaxed `Extended JSON`_
when :const:`CANONICAL_JSON_OPTIONS` or :const:`RELAXED_JSON_OPTIONS` is
provided, respectively.

.. _Extended JSON: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst

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=="}}]')
   [{u'foo': [1, 2]}, {u'bar': {u'hello': u'world'}}, {u'code': Code('function x() { return 1; }', {})}, {u'bin': Binary('...', 128)}]

Example usage (serialization):

.. 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; }", "$scope": {}}}, {"bin": {"$binary": "AQIDBA==", "$type": "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:`RELAXED_JSON_OPTIONS`):

.. doctest::

   >>> from bson import Binary, Code
   >>> from bson.json_util import dumps, RELAXED_JSON_OPTIONS
   >>> dumps([{'foo': [1, 2]},
   ...        {'bar': {'hello': 'world'}},
   ...        {'code': Code("function x() { return 1; }")},
   ...        {'bin': Binary(b"")}],
   ...       json_options=RELAXED_JSON_OPTIONS)
   '[{"foo": [1, 2]}, {"bar": {"hello": "world"}}, {"code": {"$code": "function x() { return 1; }"}}, {"bin": {"$binary": {"base64": "AQIDBA==", "subType": "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 <https://pypi.python.org/pypi/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 <https://github.com/mongodb/libbson>`_. `python-bsonjs` works best
   with PyMongo when using :class:`~bson.raw_bson.RawBSONDocument`.

.. versionchanged:: 2.8
   The output format for :class:`~bson.timestamp.Timestamp` has changed from
   '{"t": <int>, "i": <int>}' to '{"$timestamp": {"t": <int>, "i": <int>}}'.
   This new format will be decoded to an instance of
   :class:`~bson.timestamp.Timestamp`. The old format will continue to be
   decoded to a python dict as before. Encoding to the old format is no longer
   supported as it was never correct and loses type information.
   Added support for $numberLong and $undefined - new in MongoDB 2.6 - and
   parsing $date in ISO-8601 format.

.. versionchanged:: 2.7
   Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
   instances.

.. versionchanged:: 2.3
   Added dumps and loads helpers to automatically handle conversion to and
   from json and supports :class:`~bson.binary.Binary` and
   :class:`~bson.code.Code`
é    N)ÚConfigurationError)ÚEPOCH_AWAREÚEPOCH_NAIVEÚRE_TYPEÚSON)ÚBinaryÚJAVA_LEGACYÚCSHARP_LEGACYÚOLD_UUID_SUBTYPEÚUUID_SUBTYPE)ÚCode)ÚCodecOptions)ÚDBRef)Ú
Decimal128)ÚInt64)ÚMaxKey)ÚMinKey)ÚObjectId)ÚPY3Ú	iteritemsÚinteger_typesÚstring_typeÚ	text_type)ÚRegex)Ú	Timestamp)Úutc)ÚiÚlÚmÚsÚuÚx)ú$idú$refú$dbc                   @   ó   e Zd ZdZ	 dZ	 dZdS )ÚDatetimeRepresentationr   é   é   N)Ú__name__Ú
__module__Ú__qualname__ÚLEGACYÚ
NUMBERLONGÚISO8601© r/   r/   ú@/var/www/html/env/lib/python3.10/site-packages/bson/json_util.pyr&   –   s    

r&   c                   @   r%   )ÚJSONModer   r'   r(   N)r)   r*   r+   r,   ÚRELAXEDÚ	CANONICALr/   r/   r/   r0   r1   º   s    
r1   c                       s:   e Zd ZdZdejdejf‡ fdd„	Z‡ fdd„Z‡  Z	S )ÚJSONOptionsa*  Encapsulates JSON options for :func:`dumps` and :func:`loads`.

    :Parameters:
      - `strict_number_long`: If ``True``, :class:`~bson.int64.Int64` objects
        are encoded to MongoDB Extended JSON's *Strict mode* type
        `NumberLong`, ie ``'{"$numberLong": "<number>" }'``. Otherwise they
        will be encoded as an `int`. Defaults to ``False``.
      - `datetime_representation`: The representation to use when encoding
        instances of :class:`datetime.datetime`. Defaults to
        :const:`~DatetimeRepresentation.LEGACY`.
      - `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": "<hex>" }'``. Defaults to ``False``.
      - `json_mode`: The :class:`JSONMode` to use when encoding BSON types to
        Extended JSON. Defaults to :const:`~JSONMode.LEGACY`.
      - `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`.
      - `uuid_representation`: The BSON representation to use when encoding
        and decoding instances of :class:`uuid.UUID`. Defaults to
        :const:`~bson.binary.PYTHON_LEGACY`.
      - `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 ``True``.
      - `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`.
      - `args`: arguments to :class:`~bson.codec_options.CodecOptions`
      - `kwargs`: arguments to :class:`~bson.codec_options.CodecOptions`

    .. seealso:: The specification for Relaxed and Canonical `Extended JSON`_.

    .. versionadded:: 3.4

    .. versionchanged:: 3.5
       Accepts the optional parameter `json_mode`.

    Fc                    sâ   |  dd¡|d< |d r|  dt¡|d< |tjtjtjfvr"tdƒ‚tt| ƒj	| g|¢R i |¤Ž}|t
jt
jt
jfvr?tdƒ‚||_|jt
jkrTd|_tj|_d|_|S |jt
jkrfd|_tj|_d|_|S ||_||_||_|S )NÚtz_awareTÚtzinfoznJSONOptions.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.F)Úgetr   r&   r,   r-   r.   r   Úsuperr4   Ú__new__r1   r2   r3   Ú	json_modeÚstrict_number_longÚdatetime_representationÚstrict_uuid)Úclsr;   r<   r=   r:   ÚargsÚkwargsÚself©Ú	__class__r/   r0   r9     sB   þÿþÿ	øýzJSONOptions.__new__c                    s$   d| j | j| j| jtt| ƒ ¡ f S )NzSstrict_number_long=%r, datetime_representation=%r, strict_uuid=%r, json_mode=%r, %s)r;   r<   r=   r:   r8   r4   Ú_arguments_repr)rA   rB   r/   r0   rD   1  s   ûþzJSONOptions._arguments_repr)
r)   r*   r+   Ú__doc__r&   r,   r1   r9   rD   Ú__classcell__r/   r/   rB   r0   r4   å   s    (þ#r4   )r:   T)r;   r<   r=   c                 O   s*   |  dt¡}tjt| |ƒg|¢R i |¤ŽS )aW  Helper function that wraps :func:`json.dumps`.

    Recursive function that handles all BSON types including
    :class:`~bson.binary.Binary` and :class:`~bson.code.Code`.

    :Parameters:
      - `json_options`: A :class:`JSONOptions` instance used to modify the
        encoding of MongoDB Extended JSON types. Defaults to
        :const:`DEFAULT_JSON_OPTIONS`.

    .. versionchanged:: 3.4
       Accepts optional parameter `json_options`. See :class:`JSONOptions`.

    .. versionchanged:: 2.7
       Preserves order when rendering SON, Timestamp, Code, Binary, and DBRef
       instances.
    Újson_options)ÚpopÚDEFAULT_JSON_OPTIONSÚjsonÚdumpsÚ_json_convert)Úobjr?   r@   rG   r/   r/   r0   rK   l  s   rK   c                    s4   |  dt¡‰ ‡ fdd„|d< tj| g|¢R i |¤ŽS )a  Helper 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.

    :Parameters:
      - `json_options`: A :class:`JSONOptions` instance used to modify the
        decoding of MongoDB Extended JSON types. Defaults to
        :const:`DEFAULT_JSON_OPTIONS`.

    .. 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`.
    rG   c                    s
   t | ˆ ƒS ©N)Úobject_pairs_hook)Úpairs©rG   r/   r0   Ú<lambda>˜  s    ÿzloads.<locals>.<lambda>rO   )rH   rI   rJ   Úloads)r   r?   r@   r/   rQ   r0   rS   ‚  s   rS   c                    s€   t | dƒs
t | dƒrt‡ fdd„t| ƒD ƒƒS t | dƒr.t| ttfƒs.t‡ fdd„| D ƒƒS zt| ˆ ƒW S  ty?   |  Y S w )z]Recursive helper method that converts BSON types so they can be
    converted into json.
    r   Úitemsc                 3   s"   � | ]\}}|t |ˆ ƒfV  qd S rN   ©rL   )Ú.0ÚkÚvrQ   r/   r0   Ú	<genexpr>¢  s   € ÿz _json_convert.<locals>.<genexpr>Ú__iter__c                 3   s   � | ]}t |ˆ ƒV  qd S rN   rU   )rV   rX   rQ   r/   r0   rY   ¥  s   € )	Úhasattrr   r   Ú
isinstancer   ÚbytesÚlistÚdefaultÚ	TypeError)rM   rG   r/   rQ   r0   rL   �  s   ÿÿrL   c                 C   s   t | | ¡|ƒS rN   )Úobject_hookÚdocument_class)rP   rG   r/   r/   r0   rO   ¬  s   rO   c                 C   sH  d| v rt | ƒS d| v rt| ƒS d| v rt| |ƒS d| v r!t| ƒS d| v r)t| ƒS d| v r1t| ƒS d| v rCd| v r>t| |ƒS t| |ƒS d	| v rKt| ƒS d
| v rSt	| ƒS d| v rYd S d| v rat
| ƒS d| v rr| d }t|d |d ƒS d| v rzt| ƒS d| v r‚t| ƒS d| v rŠt| ƒS d| v r’t| ƒS d| v ršt| ƒS d| v r¢t| ƒS | S )Nú$oidr#   ú$dateú$regexú$minKeyú$maxKeyú$binaryú$typeú$codeú$uuidz
$undefinedú$numberLongú
$timestampÚtr   ú$numberDecimalú
$dbPointerú$regularExpressionú$symbolú
$numberIntú$numberDouble)Ú_parse_canonical_oidÚ_parse_canonical_dbrefÚ_parse_canonical_datetimeÚ_parse_legacy_regexÚ_parse_canonical_minkeyÚ_parse_canonical_maxkeyÚ_parse_legacy_binaryÚ_parse_canonical_binaryÚ_parse_canonical_codeÚ_parse_legacy_uuidÚ_parse_canonical_int64r   Ú_parse_canonical_decimal128Ú_parse_canonical_dbpointerÚ_parse_canonical_regexÚ_parse_canonical_symbolÚ_parse_canonical_int32Ú_parse_canonical_double)ÚdctrG   Útspr/   r/   r0   ra   °  sP   


ra   c                 C   sF   | d }t |tƒr| S d}|  dd¡D ]
}|t |d¡O }qt||ƒS )Nre   r   ú$optionsÚ )r\   r   r7   Ú_RE_OPT_TABLE)ÚdocÚpatternÚflagsÚoptr/   r/   r0   rx   Ü  s   

rx   c                 C   s(   t | ƒdkrtd| f ƒ‚t | d ¡S )z*Decode a JSON legacy $uuid to Python UUID.r'   zBad $uuid, extra field(s): %srk   )Úlenr`   ÚuuidÚUUID©r‹   r/   r/   r0   r~   è  s   r~   c                 C   s~   |t kr(|jtkrtj| d�S |jtkr"| dd d… | d dd…  } tj| d�S |tkr2tj| d�S tr:|dkr:| S t| |ƒS )N)Úbytes_leé   éÿÿÿÿ)r]   r   )	r
   Úuuid_representationr	   r�   r‘   r   r   r   r   ©ÚdataÚsubtyperG   r/   r/   r0   Ú_binary_or_uuidï  s   


rš   c                 C   sh   t | d tƒrd| d  | d< t| d dƒ}|dkr%t| d dd … dƒ}t | d  ¡ ¡}t|||ƒS )Nri   ú%02xé   l   €ÿ é   rh   )r\   ÚintÚbase64Ú	b64decodeÚencoderš   )r‹   rG   r™   r˜   r/   r/   r0   r{   þ  s   r{   c                 C   sŽ   | d }|d }|d }t |tƒstd| f ƒ‚t |tƒr#t|ƒdkr*td| f ƒ‚t|ƒdkr7td| f ƒ‚t | ¡ ¡}t|t|dƒ|ƒS )	Nrh   rŸ   ÚsubTypez#$binary base64 must be a string: %sr(   z9$binary subType must be a string at most 2 characters: %sz?$binary must include only "base64" and "subType" components: %srœ   )	r\   r   r`   r�   rŸ   r    r¡   rš   rž   )r‹   rG   ÚbinaryÚb64r™   r˜   r/   r/   r0   r|     s   
ÿÿr|   c                 C   s"  | d }t | ƒdkrtd| f ƒ‚t|tƒ�r	|d dkr&|dd… }d}nC|d dv r?|d	 d
kr?|dd… }|dd… }n*|d dv rR|dd… }|dd… }n|d	 dv re|dd	… }|d	d… }n|}d}| d¡}d}|dkr†tt||d… ƒd ƒ}|d|… }tj |d¡j	|t
d�}|ró|dkrót |ƒdkr¶|dd…  d
¡\}}	t|ƒd t|	ƒd  }
n+t |ƒdkrÑt|dd… ƒd t|dd… ƒd  }
nt |ƒdkrát|dd… ƒd }
|d dkrë|
d9 }
|tj|
d� }|j�r|j�r| |j¡}|S |j	dd�S t t|ƒ|¡S )z3Decode a JSON datetime to python datetime.datetime.rd   r'   zBad $date, extra field(s): %sr•   ÚZNiúÿÿÿ)ú+ú-éýÿÿÿú:éûÿÿÿr‰   Ú.r   i@B ú%Y-%m-%dT%H:%M:%S)Úmicrosecondr6   r�   i  é<   é   é   r§   )Úseconds©r6   )r�   r`   r\   r   Úrfindrž   ÚfloatÚdatetimeÚstrptimeÚreplacer   ÚsplitÚ	timedeltar5   r6   Ú
astimezoneÚbsonÚ_millis_to_datetime)r‹   rG   ÚdtmÚdtÚoffsetÚ	dot_indexr­   ÚawareÚhoursÚminutesÚsecsr/   r/   r0   rw     s\   
ÿþ*rw   c                 C   s&   t | ƒdkrtd| f ƒ‚t| d ƒS )z1Decode a JSON ObjectId to bson.objectid.ObjectId.r'   zBad $oid, extra field(s): %src   )r�   r`   r   r’   r/   r/   r0   ru   T  s   ru   c                 C   ó*   | d }t | ƒdkrtd| f ƒ‚t|ƒS )z&Decode a JSON symbol to Python string.rr   r'   zBad $symbol, extra field(s): %s)r�   r`   r   )r‹   Úsymbolr/   r/   r0   rƒ   [  ó   rƒ   c                 C   s6   | D ]}|dvrt d| f ƒ‚qt| d |  d¡d�S )z%Decode a JSON code to bson.code.Code.)rj   ú$scopezBad $code, extra field(s): %srj   rÈ   )Úscope)r`   r   r7   ©r‹   Úkeyr/   r/   r0   r}   c  s
   ÿr}   c                 C   sN   | d }t | ƒdkrtd| f ƒ‚t |ƒdkrtd| f ƒ‚t|d |d ƒS )z(Decode a JSON regex to bson.regex.Regex.rq   r'   z*Bad $regularExpression, extra field(s): %sr(   zNBad $regularExpression must include only "pattern"and "options" components: %srŒ   Úoptions)r�   r`   r   )r‹   Úregexr/   r/   r0   r‚   k  s   ÿr‚   c                 C   sN   | D ]}|  d¡r|tvr|   S qt|  d¡|  d¡fd|  dd¡i| ¤ŽS )z(Decode a JSON DBRef to bson.dbref.DBRef.ú$r#   r"   Údatabaser$   N)Ú
startswithÚ_DBREF_KEYSr   rH   rÊ   r/   r/   r0   rv   v  s   €
ÿÿrv   c                 C   s’   | d }t | ƒdkrtd| f ƒ‚t|tƒrB| ¡ }|jdur&td|f ƒ‚t|jtƒs3td|f ƒ‚t |ƒdkr@td|f ƒ‚|S td	| f ƒ‚)
z9Decode a JSON (deprecated) DBPointer to bson.dbref.DBRef.rp   r'   z"Bad $dbPointer, extra field(s): %sNz#Bad $dbPointer, extra field $db: %sz+Bad $dbPointer, $id must be an ObjectId: %sr(   z+Bad $dbPointer, extra field(s) in DBRef: %sz$Bad $dbPointer, expected a DBRef: %s)r�   r`   r\   r   Úas_docrÏ   Úidr   )r‹   ÚdbrefÚ	dbref_docr/   r/   r0   r�   €  s&   

ÿÿÿr�   c                 C   óB   | d }t | ƒdkrtd| f ƒ‚t|tƒstd| f ƒ‚t|ƒS )z"Decode a JSON int32 to python int.rs   r'   z"Bad $numberInt, extra field(s): %sz$numberInt must be string: %s)r�   r`   r\   r   rž   )r‹   Úi_strr/   r/   r0   r„   –  ó   
r„   c                 C   rÅ   )z(Decode a JSON int64 to bson.int64.Int64.rl   r'   z#Bad $numberLong, extra field(s): %s)r�   r`   r   )r‹   Úl_strr/   r/   r0   r      rÇ   r   c                 C   rÖ   )z%Decode a JSON double to python float.rt   r'   z%Bad $numberDouble, extra field(s): %sz $numberDouble must be string: %s)r�   r`   r\   r   r´   ©r‹   Úd_strr/   r/   r0   r…   ¨  rØ   r…   c                 C   rÖ   )z7Decode a JSON decimal128 to bson.decimal128.Decimal128.ro   r'   z&Bad $numberDecimal, extra field(s): %sz!$numberDecimal must be string: %s)r�   r`   r\   r   r   rÚ   r/   r/   r0   r€   ²  rØ   r€   c                 C   sJ   t | d ƒtus| d dkrtd| f ƒ‚t| ƒdkr"td| f ƒ‚tƒ S )z,Decode a JSON MinKey to bson.min_key.MinKey.rf   r'   z$minKey value must be 1: %súBad $minKey, extra field(s): %s)Útyperž   r`   r�   r   r’   r/   r/   r0   ry   ¼  s
   ry   c                 C   sH   t | d ƒtus| d dkrtd| fƒ‚t| ƒdkr!td| f ƒ‚tƒ S )z,Decode a JSON MaxKey to bson.max_key.MaxKey.rg   r'   z$maxKey value must be 1: %srÜ   )rÝ   rž   r`   r�   r   r’   r/   r/   r0   rz   Å  s
   rz   c                 C   sT   |j tjkrtdt | ¡ ¡ fdd| fgƒS dtdt | ¡ ¡ fdd| fgƒiS )Nrh   ri   r›   rŸ   r¢   )r:   r1   r,   r   rŸ   Ú	b64encodeÚdecoder—   r/   r/   r0   Ú_encode_binaryÎ  s   
þ
þrà   c                 C   s:  t | tƒrdt| ƒiS t | tƒrt|  ¡ |d�S t | tjƒr||jtj	kre| j
s-| jtd�} | tkre| j
 | ¡}|j|j|jfdkrDd}n|  d¡}t| jd ƒ}|rWd|f nd	}d
d|  d¡||f iS t | ¡}|jtjkrtd
|iS d
dt|ƒiiS |jrŠt | tƒrŠdt| ƒiS t | ttfƒrûd	}| jtj@ r�|d7 }| jtj@ r§|d7 }| jtj @ r±|d7 }| jtj!@ r»|d7 }| jtj"@ rÅ|d7 }| jtj#@ rÏ|d7 }t | j$t%ƒrÙ| j$}n| j$ &d¡}|j't(jkrït)d|fd|fgƒS dt)d|fd|fgƒiS t | t*ƒ�rddiS t | t+ƒ�rddiS t | t,ƒ�r#dt)d| j-fd| j.fgƒiS t | t/ƒ�rE| j0d u �r5dt| ƒiS t)dt| ƒfd t| j0|ƒfgƒS t | t1ƒ�rRt2| | j3|ƒS t4�rat | t5ƒ�rat2| d!|ƒS t | t6j7ƒ�r£|j8�rž| j5}t9}	|j:t;k�r{| j<}n|j:t=k�r�|d"d d#… |d d"d#…  }n|j:t>k�r˜t>}	t2||	|ƒS d$| j?iS t | t@ƒ�r¯d%t| ƒiS t | tAƒ�r·| S |j't(jBk�rÞt | tCƒ�rÞd&|   k�rÐd'k �rØn nd(t%| ƒiS dt%| ƒiS |j't(jk�rt | tDƒ�rtE F| ¡�rõd)d*iS tE G| ¡�r| d!k�rd+nd,}
d)|
iS |j't(jBk�rd)t%tH| ƒƒiS tId-|  ƒ‚).Nrc   rQ   r²   )r   r   r   r¥   z%ziè  z.%03dr‰   rd   z%s%s%sr¬   rl   r   r   r   r   r    r!   zutf-8re   rˆ   rq   rŒ   rÌ   rf   r'   rg   rm   rn   rj   rÈ   r   r”   r•   rk   ro   i   €l        rs   rt   ÚNaNÚInfinityz	-Infinityz%r is not JSON serializable)Jr\   r   Ústrr   rL   rÒ   rµ   r<   r&   r.   r6   r·   r   r   Ú	utcoffsetÚdaysr±   ÚmicrosecondsÚstrftimerž   r­   r»   Ú_datetime_to_millisr,   r;   r   r   r   r�   ÚreÚ
IGNORECASEÚLOCALEÚ	MULTILINEÚDOTALLÚUNICODEÚVERBOSErŒ   r   rß   r:   r1   r   r   r   r   ÚtimeÚincr   rÉ   r   rà   r™   r   r]   r�   r‘   r=   r
   r–   r	   r“   r   r   Úhexr   Úboolr3   r   r´   ÚmathÚisnanÚisinfÚreprr`   )rM   rG   ÚoffÚ	tz_stringÚmillisÚfracsecsr�   rŒ   r˜   r™   Úrepresentationr/   r/   r0   r_   Ø  sÄ   

ÿ
ÿ
ÿ
ÿ
þ
ÿr_   )_rE   rŸ   rµ   rJ   rô   ré   Úsysr�   Úpymongo.errorsr   r»   r   r   r   r   Úbson.binaryr   r   r	   r
   r   Ú	bson.coder   Úbson.codec_optionsr   Ú
bson.dbrefr   Úbson.decimal128r   Ú
bson.int64r   Úbson.max_keyr   Úbson.min_keyr   Úbson.objectidr   Úbson.py3compatr   r   r   r   r   Ú
bson.regexr   Úbson.timestampr   Úbson.tz_utilr   ÚIÚLÚMÚSÚUÚXrŠ   Ú	frozensetrÑ   r&   r1   r4   r,   ÚLEGACY_JSON_OPTIONSrI   r3   ÚCANONICAL_JSON_OPTIONSr2   ÚRELAXED_JSON_OPTIONSr.   ÚSTRICT_JSON_OPTIONSrK   rS   rL   rO   ra   rx   r~   rš   r{   r|   rw   ru   rƒ   r}   r‚   rv   r�   r„   r   r…   r€   ry   rz   rà   r_   r/   r/   r/   r0   Ú<module>   s”   ]ú
$+Wý,
;



		
