
    `ik~                    4   U d dl mZ d dlZd dlZd dlZd dlZd dl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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mZmZmZ ddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& er<d dl'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1 d dl2m3Z3 ej4        dk    rd dl	m5Z5 nd dl6m5Z5 d;dZ7d<dZ8 G d d          Z9i e:e9j;        e<e9j=        e>e9j?        e@e9jA        eBe9jC        eDe9jE        de9jF        eGe9jH         eId          e9jJ        eKe9jL        eMe9jL        eNe9jO        ee9jO        ee9jO        e$e9jO         eIe&          e9jP        ee9jQ        ee9jR        ejS        e9jT        de9jU        de9jV        de9jW        d e9jX        d!e9jX        d"e9jY        d#e9jY        e"e9jZ        e#e9j[        e\e9j]        e^e9j]        iZ_d$e`d%<   eBe9ja        eNe9jb        ee9jb        ee9jb        e$e9jb        e\e9jc        e^e9jc        iZdd$e`d&<   	 	 	 	 	 	 	 	 d=d>d6Ze	 	 	 	 	 	 	 	 d=d?d:ZfdS )@    )annotationsN)OrderedDictdefaultdict)Callable	GeneratorMappingSequenceSet)contextmanager)datedatetimetimetzinfowraps)BytesIO)modules)IOTYPE_CHECKINGAnycast   )CBOREncodeTypeErrorCBOREncodeValueErrorCBORSimpleValueCBORTag
FrozenDictUndefinedType	undefined)Decimal)Message)Fraction)IPv4AddressIPv4NetworkIPv6AddressIPv6Network)UUID)      )Bufferfunc"Callable[[CBOREncoder, Any], None]returnc                >     t                     d fd            }|S )	a  
    Wrap the given encoder function to gracefully handle cyclic data
    structures.

    If value sharing is enabled, this marks the given value shared in the
    datastream on the first call. If the value has already been passed to this
    method, a reference marker is instead written to the data stream and the
    wrapped function is not called.

    If value sharing is disabled, only infinite recursion protection is done.
    :rtype: Callable[[cbor2.CBOREncoder, Any], None]
    encoderCBOREncodervaluer   r-   Nonec                4    |                      |           d S N)encode_sharedr/   r1   r+   s     b/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cbor2/_encoder.pywrapperz"shareable_encoder.<locals>.wrapper7   s    dE*****    r/   r0   r1   r   r-   r2   r   r+   r8   s   ` r7   shareable_encoderr<   '   s:      4[[+ + + + + [+ Nr9   !Callable[[CBOREncoder, Any], Any]c                >     t                     d fd            }|S )	ak  
    The given encoder is a container with child values. Handle cyclic or
    duplicate references to the value and strings within the value
    efficiently.

    Containers may contain cyclic data structures or may contain values
    or themselves by referenced multiple times throughout the greater
    encoded value and could thus be more efficiently encoded with shared
    value references and string references where duplication occurs.

    If value sharing is enabled, this marks the given value shared in the
    datastream on the first call. If the value has already been passed to this
    method, a reference marker is instead written to the data stream and the
    wrapped function is not called.

    If value sharing is disabled, only infinite recursion protection is done.

    If string referencing is enabled and this is the first use of this
    method in encoding a value, all repeated references to long strings
    and bytearrays will be replaced with references to the first
    occurrence of those arrays.

    If string referencing is disabled, all strings and bytearrays will
    be encoded directly.
    r/   r0   r1   r   r-   r2   c                4    |                      |           d S r4   )encode_containerr6   s     r7   r8   z"container_encoder.<locals>.wrapper[   s      u-----r9   r:   r   r;   s   ` r7   container_encoderrA   >   s:    : 4[[. . . . . [. Nr9   c                     e Zd ZU dZdZded<   ded<   	 	 	 	 	 	 	 	 dndodZdpdZedqd            Z	e	j
        drd            Z	edsd            Zej
        dtd             Zedud!            Zej
        dvd"            Zedwd#            Zedxd%            Zedxd&            Zedxd'            Zdyd*Zedxd+            Zdzd.Zdzd/Zd{d0Zd|d3Zd|d4Zd}d6Zd~d;Zdd<Zdd=Zdd>Zdd@ZddBZe ddD            Z!e ddF            Z"ddHZ#e ddI            Z$ddKZ%ddMZ&ddOZ'ddQZ(ddRZ)ddTZ*ddVZ+ddXZ,ddZZ-dd[Z.dd]Z/dd^Z0dd`Z1ddbZ2dddZ3ddfZ4ddhZ5ddiZ6ddjZ7ddkZ8ddmZ9dS )r0   a  
    The CBOREncoder class implements a fully featured `CBOR`_ encoder with
    several extensions for handling shared references, big integers, rational
    numbers and so on. Typically the class is not used directly, but the
    :func:`dump` and :func:`dumps` functions are called to indirectly construct
    and use the class.

    When the class is constructed manually, the main entry points are
    :meth:`encode` and :meth:`encode_to_bytes`.

    .. _CBOR: https://cbor.io/
    )datetime_as_timestampdate_as_datetime	_timezone_defaultvalue_sharing_fp	_fp_write_shared_containers	_encoders
_canonicalstring_referencingstring_namespacing_string_referencesindefinite_containers_encode_depth	IO[bytes]rH   zCallable[[Buffer], int]rI   FNfprC   booltimezonetzinfo | NonerG   default(Callable[[CBOREncoder, Any], Any] | None	canonicalrD   rM   rP   c
                >   || _         || _        || _        || _        || _        || _        || _        |	| _        || _        || _	        i | _
        i | _        d| _        t                                          | _        |r!| j                            t"                     dS dS )a  
        :param fp:
            the file to write to (any file-like object opened for writing in binary
            mode)
        :param datetime_as_timestamp:
            set to ``True`` to serialize datetimes as UNIX timestamps (this makes
            datetimes more concise on the wire, but loses the timezone information)
        :param timezone:
            the default timezone to use for serializing naive datetimes; if this is not
            specified naive datetimes will throw a :exc:`ValueError` when encoding is
            attempted
        :param value_sharing:
            set to ``True`` to allow more efficient serializing of repeated values and,
            more importantly, cyclic data structures, at the cost of extra line overhead
        :param default:
            a callable that is called by the encoder with two arguments (the encoder
            instance and the value being encoded) when no suitable encoder has been
            found, and should use the methods on the encoder to encode any objects it
            wants to add to the data stream
        :param canonical:
            when ``True``, use "canonical" CBOR representation; this typically involves
            sorting maps, sets, etc. into a pre-determined order ensuring that
            serializations are comparable without decoding
        :param date_as_datetime:
            set to ``True`` to serialize date objects as datetimes (CBOR tag 0), which
            was the default behavior in previous releases (cbor2 <= 4.1.2).
        :param string_referencing:
            set to ``True`` to allow more efficient serializing of repeated string
            values
        :param indefinite_containers:
            encode containers as indefinite (use stop code instead of specifying length)

        r   N)rS   rC   rD   rU   rG   rM   rN   rP   rW   rL   rJ   rO   rQ   default_encoderscopyrK   updatecanonical_encoders)
selfrS   rC   rU   rG   rW   rY   rD   rM   rP   s
             r7   __init__zCBOREncoder.__init__   s    Z %:" 0 *"4"4%:"#  	 ;=)..00 	6N!!"455555	6 	6r9   obj_typetyper-   )Callable[[CBOREncoder, Any], None] | Nonec                   t          | j                                                  D ]\  }}t          |          t          u rj	 |\  }}n(# t
          t          f$ r t          d|d          w xY wt          t          j
        |          |d           }|| j        |= || j        |<   |}n|}t          ||          r|| j        |<   |c S d S )Nzinvalid deferred encoder type zV (must be a 2-tuple of module name and type name, e.g. ('collections', 'defaultdict')))listrK   itemsrb   tuple	TypeError
ValueErrorr   getattrr   get
issubclass)r_   ra   type_or_tupleencmodnametypenameimported_typetype_s           r7   _find_encoderzCBOREncoder._find_encoder   s   "&t~';';'='=">"> 	 	M3M""e++(5%GXX!:.   .: : : :   !(G(<(<h M M ,}547DN=1)EE%(E** +.x(


 ts   A		%A.c                    | j         S r4   )rH   r_   s    r7   rS   zCBOREncoder.fp   s	    xr9   r1   r2   c                    	 t          |j                  st          d          	 || _        |j        | _        d S # t
          $ r t          d          w xY w)Nzfp.write is not callablezfp object has no write method)callablewriteri   rH   rI   AttributeErrorr_   r1   s     r7   rS   zCBOREncoder.fp   so    	)EK(( = !;<<<=
 DH"[DNNN	  	> 	> 	><===	>s	   #; Ac                    | j         S r4   )rE   ru   s    r7   rU   zCBOREncoder.timezone   s
    ~r9   c                `    |t          |t                    r	|| _        d S t          d          )Nz*timezone must be None or a tzinfo instance)
isinstancer   rE   ri   rz   s     r7   rU   zCBOREncoder.timezone   s/    =Juf55="DNNNIJJJr9   c                    | j         S r4   )rF   ru   s    r7   rW   zCBOREncoder.default   s
    }r9   c                T    |t          |          r	|| _        d S t          d          )Nz"default must be None or a callable)rw   rF   ri   rz   s     r7   rW   zCBOREncoder.default   s+    =HUOO=!DMMMABBBr9   c                    | j         S r4   )rL   ru   s    r7   rY   zCBOREncoder.canonical  s
    r9   Generator[None]c              #  <   K   | j         }d| _         dV  || _         dS )ze
        Disable value sharing in the encoder for the duration of the context
        block.
        FN)rG   )r_   old_value_sharings     r7   disable_value_sharingz!CBOREncoder.disable_value_sharing
  s0       !.".r9   c              #  <   K   | j         }d| _         dV  || _         dS )zf
        Disable tracking of string references for the duration of the
        context block.
        FN)rM   )r_   old_string_referencings     r7   disable_string_referencingz&CBOREncoder.disable_string_referencing  0       "&!8"'"8r9   c              #  <   K   | j         }d| _         dV  || _         dS )zl
        Disable generation of new string namespaces for the duration of the
        context block.
        FN)rN   )r_   old_string_namespacings     r7   disable_string_namespacingz&CBOREncoder.disable_string_namespacing   r   r9   databytesc                0    |                      |           dS )zl
        Write bytes to the data stream.

        :param bytes data:
            the bytes to write
        NrI   )r_   r   s     r7   rx   zCBOREncoder.write+  s     	tr9   c              #  x  K   | xj         dz  c_         	 dV  | xj         dz  c_         | j         dk    r4| j                                         | j                                         dS dS # | xj         dz  c_         | j         dk    r3| j                                         | j                                         w w xY w)a/  
        Context manager for tracking encode depth and clearing shared state.

        Shared state is cleared at the end of each top-level encode to prevent
        shared references from leaking between independent encode operations.
        Nested calls (from hooks) must preserve the state.
        r   Nr   )rQ   rJ   clearrO   ru   s    r7   _encoding_contextzCBOREncoder._encoding_context4  s       	a	0EEE!#!Q&&'--///'--///// '& !#!Q&&'--///'--//// 's   A) )AB9objr   c                    |                                  5  |                     |           ddd           dS # 1 swxY w Y   dS )zk
        Encode the given object using CBOR.

        :param obj:
            the object to encode
        N)r   _encode_value)r_   r   s     r7   encodezCBOREncoder.encodeF  s     ##%% 	$ 	$s###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   8<<c                    |j         }| j                            |          p|                     |          p| j        }|st          d|j                    || |           dS )z
        Internal fast path for encoding - used by built-in encoders.

        External code should use encode() instead, which properly manages
        shared state between independent encode operations.
        zcannot serialize type N)	__class__rK   rk   rs   rF   r   __name__)r_   r   ra   r/   s       r7   r   zCBOREncoder._encode_valueP  sw     =.$$X.._$2D2DX2N2N_RVR_ 	T%&Rx?P&R&RSSScr9   c                    t                      5 }| j        }|| _        |                     |           || _        |                                cddd           S # 1 swxY w Y   dS )a+  
        Encode the given object to a byte buffer and return its value as bytes.

        This method was intended to be used from the ``default`` hook when an
        object needs to be encoded separately from the rest but while still
        taking advantage of the shared value registry.
        N)r   rS   r   getvalue)r_   r   rS   old_fps       r7   encode_to_byteszCBOREncoder.encode_to_bytes^  s     YY 	!"WFDGKKDG;;==	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   >AA!Ar/   r=   c                    | j         r|                     dd           |                                 5  |                     ||           d d d            d S # 1 swxY w Y   d S )N      )rN   encode_lengthr   r5   )r_   r/   r1   s      r7   r@   zCBOREncoder.encode_containerm  s    " 	'q#&&&,,.. 	/ 	/w...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   AAAc                    t          |          }	 | j        t          |                   d         }| j        r@|                     dd           |                     t          t          |                     d S t          d          # t          $ r| | j        rC|t          | j                  f| j        |<   |                     dd            || |           Y d S |d f| j        |<   	  || |           | j        |= Y d S # | j        |= w xY ww xY w)Nr   r      z<cyclic data structure detected but value sharing is disabled   )
idrJ   rG   r   
encode_intr   intr   KeyErrorlen)r_   r/   r1   value_idindexs        r7   r5   zCBOREncoder.encode_sharedu  sV   e99	+BuII6q9E" !  ""1d+++S% 0 011111*R  -  	: 	: 	:! : /005'1 ""1d+++e$$$$$$5:DM'1:GD%(((/9999/99999	:s*    B ADD(C?4D?
D		Dstr | bytesc                \   	 | j         |         }|                     t          d|                     dS # t          $ rm t	          |          }t	          | j                   }|dk     r|dk    }n-|dk     r|dk    }n |dk     r|dk    }n|d	k     r|d
k    }n|dk    }|r
|| j         |<   Y dS w xY w)z
        Try to encode the string or bytestring as a reference.

        Returns True if a reference was generated, False if the string
        must still be emitted.
           T   r(   r                          F)rO   encode_semanticr   r   r   )r_   r1   r   length
next_indexis_referenceds         r7   
_stringrefzCBOREncoder._stringref  s    	+E2E  U!3!34444 	 	 	ZZFT455JB &!c!! &!e## &!j(( &! &" <1;'.55#	s   04 A3B+*B+	major_tagr   r   
int | Nonec                d   |dz  }|-|                      t          j        d|dz                       d S |dk     r-|                      t          j        d||z                       d S |dk     r.|                      t          j        d|dz  |                     d S |dk     r.|                      t          j        d|d	z  |                     d S |d
k     r.|                      t          j        d|dz  |                     d S |                      t          j        d|dz  |                     d S )Nr   >B   r   r   >BBr   z>BHr   r   z>BL   z>BQ   rI   structpack)r_   r   r   s      r7   r   zCBOREncoder.encode_length  s/   a	>NN6;tY^<<=====b[[NN6;tY-?@@AAAAAc\\NN6;ui"nfEEFFFFFe^^NN6;ui"nfEEFFFFFj  NN6;ui"nfEEFFFFFNN6;ui"nfEEFFFFFr9   c                V    |                      t          j        dd                     d S )Nr      r   ru   s    r7   encode_breakzCBOREncoder.encode_break  s&    v{47788888r9   c                V   |dk    s|dk     rd|dk    rd}nd}| dz
  }|                     |                                dz   dz  d	          }|                     t          ||                     d S |dk    r|                     d|           d S |                     d|dz               d S )
Nl            l         r      r(   r   r      big)to_bytes
bit_lengthr   r   r   )r_   r1   
major_typepayloads       r7   r   zCBOREncoder.encode_int  s    (((E4I,I,Izz!

!

nne&6&6&8&81&<%BEJJG  W!=!=>>>>>aZZq%(((((qEAI,/////r9   c                    | j         r|                     |          rd S |                     dt          |                     |                     |           d S )Nr   )rM   r   r   r   rI   rz   s     r7   encode_bytestringzCBOREncoder.encode_bytestring  sZ    " 	u%% 1c%jj)))ur9   	bytearrayc                J    |                      t          |                     d S r4   )r   r   rz   s     r7   encode_bytearrayzCBOREncoder.encode_bytearray  s"    uU||,,,,,r9   strc                    | j         r|                     |          rd S |                    d          }|                     dt	          |                     |                     |           d S )Nzutf-8r(   )rM   r   r   r   r   rI   r_   r1   encodeds      r7   encode_stringzCBOREncoder.encode_string  sk    " 	u%% ,,w''1c'll+++wr9   Sequence[Any]c                    |                      d| j        st          |          nd            |D ]}|                     |           | j        r|                                  d S d S )Nr   )r   rP   r   r   r   )r_   r1   items      r7   encode_arrayzCBOREncoder.encode_array  s~    10JTc%jjjPTUUU 	% 	%Dt$$$$% 	 	  	 r9   Mapping[Any, Any]c                    |                      d| j        st          |          nd            |                                D ]/\  }}|                     |           |                     |           0| j        r|                                  d S d S )Nr   )r   rP   r   rf   r   r   )r_   r1   keyvals       r7   
encode_mapzCBOREncoder.encode_map  s    10JTc%jjjPTUUU 	$ 	$HCs###s####% 	 	  	 r9   tuple[int, bytes]c                    |                                  5  |                     |          }t          |          |fcddd           S # 1 swxY w Y   dS )z
        Takes a key and calculates the length of its optimal byte
        representation, along with the representation itself. This is used as
        the sorting key in CBOR's canonical representations.
        N)r   r   r   r   s      r7   encode_sortable_keyzCBOREncoder.encode_sortable_key  s     ,,.. 	) 	)**511Gw<<(	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   &AAAc                     fd|                                 D             }                     d j        st          |          nd           t	          |          D ]S\  }}} j        r                     |           n                     |d                                         |           T j        r                                  dS dS )z6Reorder keys according to Canonical CBOR specificationc              3  N   K   | ]\  }}                     |          ||fV   d S r4   r   ).0r   r1   r_   s      r7   	<genexpr>z3CBOREncoder.encode_canonical_map.<locals>.<genexpr>  s<      bbjc5t//44c5Abbbbbbr9   r   Nr   )	rf   r   rP   r   sortedrM   r   rI   r   )r_   r1   
keyed_keyssortkeyrealkeys   `    r7   encode_canonical_mapz CBOREncoder.encode_canonical_map  s     cbbbTYT_T_TaTabbb
10JTc%jjjPTUUU'-j'9'9 	& 	&#GWe& + ""7++++wqz***u%%%%% 	 	  	 r9   r   c                    | j         }| j        }|j        dk    rd| _         i | _        |                     d|j                   |                     |j                   || _         || _        d S )Nr   Tr   )rM   rO   tagr   r   r1   )r_   r1   r   old_string_referencess       r7   r   zCBOREncoder.encode_semantic  su    !%!8 $ 79&*D#&(D#1ei(((5;'''"8"7r9   r   c                   |j         s6| j        r|                    | j                  }nt          d|d          | j        rxddlm} |j        s ||                                          }n( ||                                          |j        dz  z   }| 	                    t          d|                     d S |                                                    dd	          }| 	                    t          d|                     d S )
Nr   znaive datetime z1 encountered and no default timezone has been setr   )timegmi@B r   z+00:00Z)r   rE   replacer   rC   calendarr   microsecondutctimetupler   r   	isoformat)r_   r1   r   	timestamp
datestrings        r7   encode_datetimezCBOREncoder.encode_datetime)  s$   | 	~ T^<<*`e```   % 	9''''''$ W#)6%*<*<*>*>#?#?		"F5#5#5#7#7885;Lw;VV	  I!6!677777**228SAAJ  J!7!788888r9   r   c                   | j         rQt          j        |t                                                    | j                  }|                     |           d S | j        r<|                                dz
  }| 	                    t          d|                     d S |                                }| 	                    t          d|                     d S )Nr   i;
 d   i  )rD   r   combiner   r   rE   r   rC   	toordinalr   r   r   )r_   r1   days_since_epochr   s       r7   encode_datezCBOREncoder.encode_date@  s      	<$UDFF33;;4>;RRE  '''''' 	<$0069  .>!?!?@@@@@**J  z!:!:;;;;;r9   r    c                   |                                 r|                     d           d S |                                r|                     |dk    rdnd           d S |                                }d}|j        D ]
}|dz  |z   }|j        r| }|                                 5  |                     t          d|j	        |g                     d d d            d S # 1 swxY w Y   d S )N   ~ r      |     
   r   )
is_nanrI   is_infiniteas_tupledigitssignr   r   r   exponent)r_   r1   dtsigdigits        r7   encode_decimalzCBOREncoder.encode_decimalL  sY   <<>> 	ENN?+++++   
	ENNeaii??_MMMMM!!BC ) )Rx5(w d++-- E E$$WQc0B%C%CDDDE E E E E E E E E E E E E E E E E Es   %+CC!$C!c                ^    |                      |          s|                     |           d S d S r4   )r   r   rz   s     r7   encode_stringrefzCBOREncoder.encode_stringref\  s:    u%% 	&u%%%%%	& 	&r9   r"   c                    |                                  5  |                     t          d|j        |j        g                     d d d            d S # 1 swxY w Y   d S )N   )r   r   r   	numeratordenominatorrz   s     r7   encode_rationalzCBOREncoder.encode_rationala  s    '')) 	T 	T  eou?P-Q!R!RSSS	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T 	T   0AAAre.Pattern[str]c                p    |                      t          dt          |j                                       d S )N#   )r   r   r   patternrz   s     r7   encode_regexpzCBOREncoder.encode_regexpf  s0    WRU]););<<=====r9   r!   c                p    |                      t          d|                                                     d S )N$   )r   r   	as_stringrz   s     r7   encode_mimezCBOREncoder.encode_mimej  s0    WR):):;;<<<<<r9   r'   c                V    |                      t          d|j                             d S )N%   )r   r   r   rz   s     r7   encode_uuidzCBOREncoder.encode_uuidn  s(    WR5566666r9   c                    |                                  5  |                     t          d|                     d d d            d S # 1 swxY w Y   d S )Nr   )r   r   r   rz   s     r7   encode_stringref_namespacez&CBOREncoder.encode_stringref_namespacer  s    ,,.. 	6 	6  e!4!4555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   $AA
A
Set[Any]c                f    |                      t          dt          |                               d S )N  )r   r   rg   rz   s     r7   
encode_setzCBOREncoder.encode_setw  s,    WS%,,7788888r9   c                     t           fd|D                       }                     t          dd |D                                  d S )Nc              3  F   K   | ]}                     |          |fV  d S r4   r   )r   r   r_   s     r7   r   z3CBOREncoder.encode_canonical_set.<locals>.<genexpr>}  s6      NN11#66<NNNNNNr9   r-  c                    g | ]
}|d          S )r    )r   r   s     r7   
<listcomp>z4CBOREncoder.encode_canonical_set.<locals>.<listcomp>~  s    *D*D*Dc3q6*D*D*Dr9   )r   r   r   )r_   r1   valuess   `  r7   encode_canonical_setz CBOREncoder.encode_canonical_set{  sX    NNNNNNNNNWS*D*DV*D*D*DEEFFFFFr9   IPv4Address | IPv6Addressc                V    |                      t          d|j                             d S )Ni  )r   r   packedrz   s     r7   encode_ipaddresszCBOREncoder.encode_ipaddress  s(    WS%,7788888r9   IPv4Network | IPv6Networkc                n    |                      t          d|j        j        |j        i                     d S )Ni  )r   r   network_addressr8  	prefixlenrz   s     r7   encode_ipnetworkzCBOREncoder.encode_ipnetwork  s3    WS5+@+G*YZZ[[[[[r9   r   c                    |j         dk     r2|                     t          j        dd|j         z                       d S |                     t          j        dd|j                              d S )Nr   r      r      )r1   rI   r   r   rz   s     r7   encode_simple_valuezCBOREncoder.encode_simple_value  sb    ;NN6;tTEK-?@@AAAAANN6;udEK@@AAAAAr9   floatc                   t          j        |          r|                     d           d S t          j        |          r|                     |dk    rdnd           d S |                     t	          j        dd|                     d S )Nr  r   r  r	  >Bd   )mathisnanrI   isinfr   r   rz   s     r7   encode_floatzCBOREncoder.encode_float  s    :e 	<NN?+++++Z 	<NNeaii??_MMMMMNN6;udE::;;;;;r9   complexc                    |                                  5  |                     t          d|j        |j        g                     d d d            d S # 1 swxY w Y   d S )Ni  )r   r   r   realimagrz   s     r7   encode_complexzCBOREncoder.encode_complex  s    '')) 	K 	K  UZ0H!I!IJJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	Kr  c                   t          j        |          r|                     d           d S t          j        |          r|                     |dk    rdnd           d S t	          j        dd|          }dD ]Q\  }}	 t	          j        |||          }t	          j        ||          d         |k    r|}n nA# t          $ r Y  nw xY w|                     |           d S )	Nr  r   r  r	  rE  rF  ))z>Bf   )z>Be   r   )rG  rH  rI   rI  r   r   unpackOverflowError)r_   r1   r   formatr   new_encodeds         r7   encode_minimal_floatz CBOREncoder.encode_minimal_float  s   :e 	$NN?+++++Z 	$NNeaii??_MMMMM k%u55G= 	 	"(+fc5"A"AK}V[99!<EE"-   %   EE NN7#####s   =8B88
CCc                8    |                      |rdnd           d S )N      r   rz   s     r7   encode_booleanzCBOREncoder.encode_boolean  s#    %4wwW55555r9   c                0    |                      d           d S )N   r   rz   s     r7   encode_nonezCBOREncoder.encode_none      wr9   r   c                0    |                      d           d S )N   r   rz   s     r7   encode_undefinedzCBOREncoder.encode_undefined  r_  r9   FNFNFFFF)rS   rR   rC   rT   rU   rV   rG   rT   rW   rX   rY   rT   rD   rT   rM   rT   rP   rT   )ra   rb   r-   rc   )r-   rR   )r1   rR   r-   r2   )r-   rV   )r1   rV   r-   r2   )r-   rX   )r1   rX   r-   r2   )r-   rT   )r-   r   )r   r   r-   r2   )r   r   r-   r2   )r   r   r-   r   )r/   r=   r1   r   r-   r2   )r1   r   r-   rT   )r   r   r   r   r-   r2   )r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r   r-   r2   )r1   r    r-   r2   )r1   r   r-   r2   )r1   r"   r-   r2   )r1   r  r-   r2   )r1   r!   r-   r2   )r1   r'   r-   r2   )r1   r   r-   r2   )r1   r+  r-   r2   )r1   r6  r-   r2   )r1   r:  r-   r2   )r1   r   r-   r2   )r1   rC  r-   r2   )r1   rK  r-   r2   )r1   rT   r-   r2   )r1   r2   r-   r2   )r1   r   r-   r2   ):r   
__module____qualname____doc__	__slots____annotations__r`   rs   propertyrS   setterrU   rW   rY   r   r   r   r   rx   r   r   r   r   r@   r5   r   r   r   r   r   r   r   rA   r   r   r   r   r   r   r  r  r  r  r!  r%  r(  r*  r.  r5  r9  r>  rB  rJ  rO  rW  r[  r^  rb  r2  r9   r7   r0   r0   b   s/         I$ NNN&&&&
 ',"&#<@!&#(&+>6 >6 >6 >6 >6@   8    X Y) ) ) Y)    X _K K K _K    X ^C C C ^C    X / / / ^/ 9 9 9 ^9 9 9 9 ^9    0 0 0 ^0"$ $ $ $   ! ! ! !/ / / /   <   <G G G G9 9 9 90 0 0 0    - - - -                       ) ) ) )        "8 8 8 8$9 9 9 9.
< 
< 
< 
<E E E E & & & &
T T T T
> > > >= = = =7 7 7 76 6 6 6
9 9 9 9G G G G
9 9 9 9\ \ \ \B B B B< < < <K K K K
$ $ $ $,6 6 6 6                  r9   r0   )decimalr    )	fractionsr"   )zemail.messager!   )uuidr'   )	ipaddressr#   )rn  r%   )rn  r$   )rn  r&   z@dict[type | tuple[str, str], Callable[[CBOREncoder, Any], None]]r[   r^   Fr   objectrC   rT   rU   rV   rG   rW   rc   rY   rD   rM   rP   r   c	                    t                      5 }	t          |	||||||||	  	                            |            |	                                cddd           S # 1 swxY w Y   dS )a  
    Serialize an object to a bytestring.

    :param obj:
        the object to serialize
    :param datetime_as_timestamp:
        set to ``True`` to serialize datetimes as UNIX timestamps (this makes datetimes
        more concise on the wire, but loses the timezone information)
    :param timezone:
        the default timezone to use for serializing naive datetimes; if this is not
        specified naive datetimes will throw a :exc:`ValueError` when encoding is
        attempted
    :param value_sharing:
        set to ``True`` to allow more efficient serializing of repeated values
        and, more importantly, cyclic data structures, at the cost of extra
        line overhead
    :param default:
        a callable that is called by the encoder with two arguments (the encoder
        instance and the value being encoded) when no suitable encoder has been found,
        and should use the methods on the encoder to encode any objects it wants to add
        to the data stream
    :param canonical:
        when ``True``, use "canonical" CBOR representation; this typically involves
        sorting maps, sets, etc. into a pre-determined order ensuring that
        serializations are comparable without decoding
    :param date_as_datetime:
        set to ``True`` to serialize date objects as datetimes (CBOR tag 0), which was
        the default behavior in previous releases (cbor2 <= 4.1.2).
    :param string_referencing:
        set to ``True`` to allow more efficient serializing of repeated string values
    :param indefinite_containers:
        encode containers as indefinite (use stop code instead of specifying length)
    :return: the serialized output

    rC   rU   rG   rW   rY   rD   rM   rP   N)r   r0   r   r   )
r   rC   rU   rG   rW   rY   rD   rM   rP   rS   s
             r7   dumpsrr    s    \ 
 b"7'-1"7
	
 
	
 
	
 &+++{{}}                 s   ?AA"ArS   rR   r2   c
                \    t          |||||||||		  	                            |            dS )a  
    Serialize an object to a file.

    :param obj:
        the object to serialize
    :param fp:
        the file to write to (any file-like object opened for writing in binary mode)
    :param datetime_as_timestamp:
        set to ``True`` to serialize datetimes as UNIX timestamps (this makes datetimes
        more concise on the wire, but loses the timezone information)
    :param timezone:
        the default timezone to use for serializing naive datetimes; if this is not
        specified naive datetimes will throw a :exc:`ValueError` when encoding is
        attempted
    :param value_sharing:
        set to ``True`` to allow more efficient serializing of repeated values
        and, more importantly, cyclic data structures, at the cost of extra
        line overhead
    :param default:
        a callable that is called by the encoder with two arguments (the encoder
        instance and the value being encoded) when no suitable encoder has been found,
        and should use the methods on the encoder to encode any objects it wants to add
        to the data stream
    :param canonical:
        when ``True``, use "canonical" CBOR representation; this typically involves
        sorting maps, sets, etc. into a pre-determined order ensuring that
        serializations are comparable without decoding
    :param date_as_datetime:
        set to ``True`` to serialize date objects as datetimes (CBOR tag 0), which was
        the default behavior in previous releases (cbor2 <= 4.1.2).
    :param indefinite_containers:
        encode containers as indefinite (use stop code instead of specifying length)
    :param string_referencing:
        set to ``True`` to allow more efficient serializing of repeated string values

    rq  N)r0   r   )
r   rS   rC   rU   rG   rW   rY   rD   rM   rP   s
             r7   dumprt  *  sE    ` 
3#)-3
 
 
 fSkkkkkr9   )r+   r,   r-   r,   )r+   r=   r-   r=   rc  )r   ro  rC   rT   rU   rV   rG   rT   rW   rc   rY   rT   rD   rT   rM   rT   rP   rT   r-   r   )r   ro  rS   rR   rC   rT   rU   rV   rG   rT   rW   rc   rY   rT   rD   rT   rM   rT   rP   rT   r-   r2   )g
__future__r   rG  rer   syscollectionsr   r   collections.abcr   r   r   r	   r
   
contextlibr   r   r   r   r   	functoolsr   ior   r   typingr   r   r   r   _typesr   r   r   r   r   r   r   rk  r    email.messager!   rl  r"   rn  r#   r$   r%   r&   rm  r'   version_infor*   typing_extensionsr<   rA   r0   r   r   r   r   r   r   r   r   rC  rJ  rK  rO  r  rT   r[  rb   r^  rg   r   re   dictr   rb  r   r  Patternr!  r  r%  r(  r9  r>  rB  r   setr.  	frozensetr[   rh  rW  r   r5  r^   rr  rt  r2  r9   r7   <module>r     s   " " " " " " "  				  



 0 0 0 0 0 0 0 0 G G G G G G G G G G G G G G % % % % % % 1 1 1 1 1 1 1 1 1 1 1 1                   / / / / / / / / / / / /                   
-%%%%%%""""""LLLLLLLLLLLL
7""*******,,,,,,   .! ! ! !H[	  [	  [	  [	  [	  [	  [	  [	 |V	;(V{+V 	"V 		V
 
;#V ['V K6V 	+
$V 	DJJ'V 
;#V 	+
"V 	+
 V 'V 'V &V  	DOO[1!V" k)#V$ 	+
!J){: +"9k- +"> +"> +"> +">[4[(	{%=V V     F 
;++
*110	){/X      #("9="$"': : : : :@ #("9="$"': : : : : : :r9   