
    @hP                       % S r SSKJr  SSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJrJrJrJrJrJrJr  SSKJrJrJr  SSKJr  SrSS	 jr " S
 S\R<                  5      r " S S\R<                  5      r  " S S\\ 5      r!\\\ \!4   r"\\/\4   r# " S S5      r$ " S S\%\RL                  5      r' " S S\5      r(\
(       a   " S S\\   \\   5      r)O " S S\(5      r)\)" 5       r*S\+S'   SS jr,g)z(Tools for specifying BSON codec options.    )annotationsN)MutableMapping)TYPE_CHECKINGAnyCallableGenericIterableMapping
NamedTupleOptionalTupleTypeUnioncast)ALL_UUID_REPRESENTATIONSUUID_REPRESENTATION_NAMESUuidRepresentation)_DocumentTypee   c                .    [        U SS5      nU[        :H  $ )z9Determine if a document_class is a RawBSONDocument class._type_markerN)getattr_RAW_BSON_DOCUMENT_MARKER)document_classmarkers     WC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\bson/codec_options.py_raw_document_classr   /   s    ^^T:F...    c                  h    \ rS rSrSr\R                  SS j5       r\R                  SS j5       r	Sr
g)	TypeEncoder5   a<  Base class for defining type codec classes which describe how a
custom type can be transformed to one of the types BSON understands.

Codec classes must implement the ``python_type`` attribute, and the
``transform_python`` method to support encoding.

See :ref:`custom-type-type-codec` documentation for an example.
c                    g)z<The Python type to be converted into something serializable.N selfs    r   python_typeTypeEncoder.python_type?       r   c                    g)z<Convert the given Python object into something serializable.Nr#   r%   values     r   transform_pythonTypeEncoder.transform_pythonC   r(   r   r#   Nreturnr   r+   r   r/   r   )__name__
__module____qualname____firstlineno____doc__abcabstractpropertyr&   abstractmethodr,   __static_attributes__r#   r   r   r    r    5   s?     	K K 	K Kr   r    c                  h    \ rS rSrSr\R                  SS j5       r\R                  SS j5       r	Sr
g)	TypeDecoderH   a"  Base class for defining type codec classes which describe how a
BSON type can be transformed to a custom type.

Codec classes must implement the ``bson_type`` attribute, and the
``transform_bson`` method to support decoding.

See :ref:`custom-type-type-codec` documentation for an example.
c                    g)z0The BSON type to be converted into our own type.Nr#   r$   s    r   	bson_typeTypeDecoder.bson_typeR   r(   r   c                    g)z/Convert the given BSON value into our own type.Nr#   r*   s     r   transform_bsonTypeDecoder.transform_bsonV   r(   r   r#   Nr.   r0   )r1   r2   r3   r4   r5   r6   r7   r>   r8   rA   r9   r#   r   r   r;   r;   H   s;     	? ? 	> >r   r;   c                      \ rS rSrSrSrg)	TypeCodec[   a  Base class for defining type codec classes which describe how a
custom type can be transformed to/from one of the types :mod:`bson`
can already encode/decode.

Codec classes must implement the ``python_type`` attribute, and the
``transform_python`` method to support encoding, as well as the
``bson_type`` attribute, and the ``transform_bson`` method to support
decoding.

See :ref:`custom-type-type-codec` documentation for an example.
r#   N)r1   r2   r3   r4   r5   r9   r#   r   r   rD   rD   [   s    
r   rD   c                  z    \ rS rSrSr  S     SS jjr\SS j5       r\SS j5       rSS jr	SS jr
SS	 jrS
rg)TypeRegistrym   a4  Encapsulates type codecs used in encoding and / or decoding BSON, as
well as the fallback encoder. Type registries cannot be modified after
instantiation.

``TypeRegistry`` can be initialized with an iterable of type codecs, and
a callable for the fallback encoder::

  >>> from bson.codec_options import TypeRegistry
  >>> type_registry = TypeRegistry([Codec1, Codec2, Codec3, ...],
  ...                              fallback_encoder)

See :ref:`custom-type-type-registry` documentation for an example.

:param type_codecs: iterable of type codec instances. If
    ``type_codecs`` contains multiple codecs that transform a single
    python or BSON type, the transformation specified by the type codec
    occurring last prevails. A TypeError will be raised if one or more
    type codecs modify the encoding behavior of a built-in :mod:`bson`
    type.
:param fallback_encoder: callable that accepts a single,
    unencodable python value and transforms it into a type that
    :mod:`bson` can encode. See :ref:`fallback-encoder-callable`
    documentation for an example.
Nc                |   [        U=(       d    / 5      U l        X l        0 U l        0 U l        U R                  b  [        U5      (       d  [        SU-  5      eU R                   H  nSn[        U[        5      (       a6  U R                  U5        SnUR                  U R                  UR                  '   [        U[        5      (       a%  SnUR                  U R                  UR                  '   U(       a  M  [        S[        R                   S[        R                   S[         R                   SU< S3	5      e   g )	Nz%fallback_encoder %r is not a callableFTzExpected an instance of z, z, or z, got z instead)list_TypeRegistry__type_codecs_fallback_encoder_encoder_map_decoder_mapcallable	TypeError
isinstancer    _validate_type_encoderr,   r&   r;   rA   r>   r1   rD   )r%   type_codecsfallback_encodercodecis_valid_codecs        r   __init__TypeRegistry.__init__   s-   
 "+"34!1,.,.!!-,-- GK[ \]]''E"N%--++E2!%7<7M7M!!%"3"34%--!%5:5I5I!!%//2!>.{/C/C.DB{G[G[F\\abkbtbtauu{  }B  |E  EM  N  (r   c                    U R                   $ )z)The list of type codecs in this registry.)rK   r$   s    r   codecsTypeRegistry.codecs   s     !!!r   c                    U R                   $ )z&The fallback encoder in this registry.)rL   r$   s    r   rT   TypeRegistry.fallback_encoder   s     %%%r   c                    SSK Jn  U H@  n[        [        [        U5      R
                  U5      (       d  M.  SU SU S3n[        U5      e   g )Nr   )_BUILT_IN_TYPESzCTypeEncoders cannot change how built-in types are encoded (encoder z transforms type ))bsonr_   
issubclassr   rD   r&   rP   )r%   rU   r_   pytypeerr_msgs        r   rR   #TypeRegistry._validate_type_encoder   sT    (%F$y%0<<fEE((-w.?xqJ   (( &r   c                x    SR                  U R                  R                  U R                  U R                  5      $ )Nz+{}(type_codecs={!r}, fallback_encoder={!r}))format	__class__r1   rK   rL   r$   s    r   __repr__TypeRegistry.__repr__   s4    <CCNN##""
 	
r   c                    [        U[        U 5      5      (       d  [        $ U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ N)rQ   typeNotImplementedrN   rM   rL   )r%   others     r   __eq__TypeRegistry.__eq__   sf    %d,,!!%"4"44 D""e&8&88D''5+B+BB	
r   )__type_codecsrN   rM   rL   )NN)rS   zOptional[Iterable[_Codec]]rT   Optional[_Fallback]r/   None)r/   z+list[TypeEncoder | TypeDecoder | TypeCodec])r/   rs   )rU   _Codecr/   rt   r/   str)ro   r   r/   r   )r1   r2   r3   r4   r5   rW   propertyrZ   rT   rR   ri   rp   r9   r#   r   r   rG   rG   m   sg    6 3704/ . 
	8 " " & &	)

r   rG   c                  .    \ rS rSrSrSr Sr Sr SrSr	g)	DatetimeConversion   z$Options for decoding BSON datetimes.            r#   N)
r1   r2   r3   r4   r5   DATETIMEDATETIME_CLAMPDATETIME_MSDATETIME_AUTOr9   r#   r   r   rz   rz      s3    .H N K Mr   rz   c                  \    \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'   Srg)_BaseCodecOptions   zType[Mapping[str, Any]]r   booltz_awareintuuid_representationrw   unicode_decode_error_handlerOptional[datetime.tzinfo]tzinforG   type_registryOptional[DatetimeConversion]datetime_conversionr#   N)r1   r2   r3   r4   __annotations__r9   r#   r   r   r   r      s+    ++N"%%%%55r   r   c                      \ rS rSr% S\S'   S\S'   S\S'   S\S	'   S
\S'   S\S'   S\S'          S                 SS jjrSS jrS S jrS!S jr\	S"S j5       r
S#S jrS$S jrS\S'   S\S'   Srg)%CodecOptions   zType[_DocumentType]r   r   r   r   r   Optional[str]r   r   r   rG   r   Optional[int]r   c                    g rl   r#   )clsr   r   r   r   r   r   r   s           r   __new__CodecOptions.__new__  s     r   c                    g rl   r#   r%   kwargss     r   with_optionsCodecOptions.with_options      r   rw   c                    g rl   r#   r$   s    r   _arguments_reprCodecOptions._arguments_repr  r   r   c                    g rl   r#   r$   s    r   _options_dictCodecOptions._options_dict  r   r   c                    g rl   r#   )r   objs     r   _makeCodecOptions._make  s    r   c                    g rl   r#   r$   s    r   _asdictCodecOptions._asdict  r   r   c                    g rl   r#   r   s     r   _replaceCodecOptions._replace  r   r   _sourcez
Tuple[str]_fieldsr#   N).......)r   z!Type[CodecOptions[_DocumentType]]r   zOptional[Type[_DocumentType]]r   r   r   r   r   r   r   r   r   Optional[TypeRegistry]r   r   r/   CodecOptions[_DocumentType])r   r   r/   CodecOptions[Any]rv   )r/   zdict[Any, Any])r   zIterable[Any]r/   r   r/   zdict[str, Any])r   r   r/   r   )r1   r2   r3   r4   r   r   r   r   r   classmethodr   r   r   r9   r#   r   r   r   r      s    ++  &33))##** =@ 14:=034714
	2
	9
	 
	 "/	
	
 +8
	 .
	 2
	 "/
	 )
				 
	 
			 r   r   c                     ^  \ rS rSrSrU 4S jrSS\R                  SSS\R                  4                 SS jjr
SS jrSS	 jrSS
 jrSS jrSrU =r$ )r   i'  z:Encapsulates options used encoding and / or decoding BSON.c                "   > [         TU ]  5         g)a}  Encapsulates options used encoding and / or decoding BSON.

The `document_class` option is used to define a custom type for use
decoding BSON documents. Access to the underlying raw BSON bytes for
a document is available using the :class:`~bson.raw_bson.RawBSONDocument`
type::

  >>> from bson.raw_bson import RawBSONDocument
  >>> from bson.codec_options import CodecOptions
  >>> codec_options = CodecOptions(document_class=RawBSONDocument)
  >>> coll = db.get_collection('test', codec_options=codec_options)
  >>> doc = coll.find_one()
  >>> doc.raw
  '\x16\x00\x00\x00\x07_id\x00[0\x165\x91\x10\xea\x14\xe8\xc5\x8b\x93\x00'

The document class can be any type that inherits from
:class:`~collections.abc.MutableMapping`::

  >>> class AttributeDict(dict):
  ...     # A dict that supports attribute access.
  ...     def __getattr__(self, key):
  ...         return self[key]
  ...     def __setattr__(self, key, value):
  ...         self[key] = value
  ...
  >>> codec_options = CodecOptions(document_class=AttributeDict)
  >>> coll = db.get_collection('test', codec_options=codec_options)
  >>> doc = coll.find_one()
  >>> doc._id
  ObjectId('5b3016359110ea14e8c58b93')

See :doc:`/examples/datetimes` for examples using the `tz_aware` and
`tzinfo` options.

See :doc:`/examples/uuid` for examples using the `uuid_representation`
option.

:param document_class: BSON documents returned in queries will be decoded
    to an instance of this class. Must be a subclass of
    :class:`~collections.abc.MutableMapping`. Defaults to :class:`dict`.
:param tz_aware: If ``True``, BSON datetimes will be decoded to timezone
    aware instances of :class:`~datetime.datetime`. Otherwise they will be
    naive. Defaults to ``False``.
:param uuid_representation: The BSON representation to use when encoding
    and decoding instances of :class:`~uuid.UUID`. Defaults to
    :data:`~bson.binary.UuidRepresentation.UNSPECIFIED`. New
    applications should consider setting this to
    :data:`~bson.binary.UuidRepresentation.STANDARD` for cross language
    compatibility. See :ref:`handling-uuid-data-example` for details.
:param unicode_decode_error_handler: The error handler to apply when
    a Unicode-related error occurs during BSON decoding that would
    otherwise raise :exc:`UnicodeDecodeError`. Valid options include
    'strict', 'replace', 'backslashreplace', 'surrogateescape', and
    'ignore'. Defaults to 'strict'.
:param tzinfo: A :class:`~datetime.tzinfo` subclass that specifies the
    timezone to/from which :class:`~datetime.datetime` objects should be
    encoded/decoded.
:param type_registry: Instance of :class:`TypeRegistry` used to customize
    encoding and decoding behavior.
: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'.

.. versionchanged:: 4.0
   The default for `uuid_representation` was changed from
   :const:`~bson.binary.UuidRepresentation.PYTHON_LEGACY` to
   :const:`~bson.binary.UuidRepresentation.UNSPECIFIED`.

.. versionadded:: 3.8
   `type_registry` attribute.

.. warning:: Care must be taken when changing
   `unicode_decode_error_handler` from its default value ('strict').
   The 'replace' and 'ignore' modes should not be used when documents
   retrieved from the server will be modified in the client application
   and stored back to the server.
N)superrW   )r%   argsr   rh   s      r   rW   CodecOptions.__init__*  s    d Gr   NFstrictc           
        U=(       d    [         nSn	 [        U[        5      n	U	(       d  [        U5      (       d  [        S5      e[        U[        5      (       d  [        SU 35      eU[        ;  a  [        S5      e[        U[        5      (       d  [        S[        U5       35      eUbH  [        U[        R                  5      (       d  [        S[        U5       35      eU(       d  [        S5      eU=(       d
    [        5       n[        U[        5      (       d  [        S	[        U5       35      e[         R#                  U UUUUUUU45      $ ! [         a/    [	        US5      (       a  [        UR
                  [        5      n	 GNef = f)
NF
__origin__zydocument_class must be dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a subclass of collections.abc.MutableMappingz.tz_aware must be True or False, was: tz_aware=zGuuid_representation must be a value from bson.binary.UuidRepresentationz3unicode_decode_error_handler must be a string, not z3tzinfo must be an instance of datetime.tzinfo, not z8cannot specify tzinfo without also setting tz_aware=Truez7type_registry must be an instance of TypeRegistry, not )dictrb   _MutableMappingrP   hasattrr   r   rQ   r   r   
ValueErrorrw   rm   datetimer   rG   tupler   )
r   r   r   r   r   r   r   r   	doc_class
is_mappings
             r   r   r   ~  s    '.$I JS'	?C
 "5i"@"@A 
 h--"PQYPZ [\\"*BB ]  :C@@ I$OkJlImn  !!&(//::#MdSYl^\   $%_``);\^Mm\::MdS`NaMbc  =='0!' E  S9l33!+I,@,@/!RJSs   E 5F	F	c           	     >   U R                   [        L a  SO[        U R                   5      n[        R                  " U R
                  U R
                  5      nSR                  UU R                  UU R                  U R                  U R                  U R                  5      $ )z;Representation of the arguments used to create this object.r   zdocument_class={}, tz_aware={!r}, uuid_representation={}, unicode_decode_error_handler={!r}, tzinfo={!r}, type_registry={!r}, datetime_conversion={!s})r   r   reprr   getr   rg   r   r   r   r   r   )r%   document_class_repruuid_rep_reprs      r   r   r     s     --54@S@S;T   699(($*B*BM
??Ev'MM!55KK&&,,@r   c                    U R                   U R                  U R                  U R                  U R                  U R
                  U R                  S.$ )z7Dictionary of the arguments used to create this object.r   r   r   r   r   r   r   r   r$   s    r   r   r     sI     #'"5"5 MM'+'?'?040Q0Q++!%!3!3'+'?'? r   c                V    U R                   R                   SU R                  5        S3$ )N(r`   )rh   r1   r   r$   s    r   ri   CodecOptions.__repr__  s*    nn--.a0D0D0F/GqIIr   c                Z    U R                  5       nUR                  U5        [        S0 UD6$ )a(  Make a copy of this CodecOptions, overriding some options::

    >>> from bson.codec_options import DEFAULT_CODEC_OPTIONS
    >>> DEFAULT_CODEC_OPTIONS.tz_aware
    False
    >>> options = DEFAULT_CODEC_OPTIONS.with_options(tz_aware=True)
    >>> options.tz_aware
    True

.. versionadded:: 3.5
r#   )r   updater   )r%   r   optss      r   r   r     s,     %%'DKK'$''r   r#   )r   zType[CodecOptions]r   z!Optional[Type[Mapping[str, Any]]]r   r   r   r   r   rw   r   r   r   r   r   r   r/   r   rv   r   )r   r   r/   r   )r1   r2   r3   r4   r5   rW   r   UNSPECIFIEDrz   r   r   r   r   ri   r   r9   __classcell__)rh   s   @r   r   r   '  s    HR	l AE"1C1O1O080448@R@[@[=	#=	==	 =	 "/	=	
 +.=	 .=	 2=	 ">=	 =	~	0		J	( 	(r   zCodecOptions[dict[str, Any]]DEFAULT_CODEC_OPTIONSc                t    0 n[        U 5      1 Sk-   H  nUS:X  a	  X   US'   M  X   X'   M     [        S0 UD6$ )zParse BSON codec options.>   r   r   r   r   uuidrepresentationr   r   r   r   r#   )setr   )optionsr   ks      r   _parse_codec_optionsr     sP    F\   $$,3JF()
FI !&!!r   )r   r   r/   r   )r   r   r/   r   )-r5   
__future__r   r6   r   enumcollections.abcr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   bson.binaryr   r   r   bson.typingsr   r   r   ABCr    r;   rD   ru   	_FallbackrG   r   Enumrz   r   r   r   r   r   r#   r   r   <module>r      s
   / " 
   =    
 ' /K#'' K&>#'' >&[  
{K2	3cUCZ 	Y
 Y
x dii  F6
 6 +u]+W]-C +^L(( L(^ 7Cn 3 D"r   