
    rhS                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
   " S S5      r\" 5       r\R                  r\R                  r\R                  r " S S5      r " S	 S
\5      r\R%                  \R                  5         " S S\5      r\R%                  \R                  5        \R%                  \R(                  5        \R%                  \R*                  5         " S S\5      r\R%                  \" \R0                  " S5      5      5         " S S\5      r\R%                  \R4                  5         " S S5      r " S S\5      r\R%                  \R:                  5         " S S\5      r\R>                  " 5       r \R%                  \ RB                  5         " S S\5      r"\"R%                  \RF                  5        g)a  
Custom handlers may be created to handle other objects. Each custom handler
must derive from :class:`jsonpickle.handlers.BaseHandler` and
implement ``flatten`` and ``restore``.

A handler can be bound to other types by calling
:func:`jsonpickle.handlers.register`.

    N   )utilc                   4    \ rS rSrS rSS jrS	S jrS rSrg)
Registry   c                      0 U l         0 U l        g N)	_handlers_base_handlersselfs    M/home/james-whalen/.local/lib/python3.13/site-packages/jsonpickle/handlers.py__init__Registry.__init__   s         Nc                     U R                   R                  U5      nUcR  [        R                  " U5      (       a7  U R                  R                  5        H  u  pE[        X5      (       d  M  Us  $    Uc  U$ U$ )a$  
:param cls_or_name: the type or its fully qualified name
:param default: default value, if a matching handler is not found

Looks up a handler by type reference or its fully
qualified name. If a direct match
is not found, the search is performed over all
handlers registered with base=True.
)r
   getr   is_typer   items
issubclass)r   cls_or_namedefaulthandlerclsbase_handlers         r   r   Registry.get   sj     ..$$[1?t||K88%)%8%8%>%>%@!k//'' &A "/w6w6r   c                 
  ^ ^^ Uc
  UUU 4S jnU$ [         R                  " T5      (       d  [        T< S35      eU=T R                  [         R                  " T5      '   T R                  T'   T(       a  UT R
                  T'   gg)a  Register the a custom handler for a class

:param cls: The custom object class to handle
:param handler: The custom handler class (if
    None, a decorator wrapper is returned)
:param base: Indicates whether the handler should
    be registered for all subclasses

This function can be also used as a decorator
by omitting the `handler` argument::

    @jsonpickle.handlers.register(Foo, base=True)
    class FooHandler(jsonpickle.handlers.BaseHandler):
        pass

Nc                 *   > TR                  TU TS9  U $ )N)r   base)register)handler_clsr   r   r   s    r   	_register$Registry.register.<locals>._registerA   s    c;TB""r   z is not a class/type)r   r   	TypeErrorr
   importable_namer   )r   r   r   r   r"   s   `` ` r   r    Registry.register.   s|    " ?# ||C  sg%9:;; KRQt++C01DNN34G'.D$ r   c                     U R                   R                  US 5        U R                   R                  [        R                  " U5      S 5        U R                  R                  US 5        g r	   )r
   popr   r%   r   r   r   s     r   
unregisterRegistry.unregisterO   sK    3%4//4d;T*r   )r   r
   r	   )NF)	__name__
__module____qualname____firstlineno__r   r   r    r*   __static_attributes__ r   r   r   r      s    !7$/B+r   r   c                   <    \ rS rSrS rS rS r\S 5       rS r	Sr
g)	BaseHandler[   c                     Xl         g)zt
Initialize a new handler to handle a registered type.

:Parameters:
  - `context`: reference to pickler/unpickler

Ncontextr   r7   s     r   r   BaseHandler.__init__\   s	     r   c                 2    [        SU R                  -  5      e)a
  
Flatten `obj` into a json-friendly form and write result to `data`.

:param object obj: The object to be serialized.
:param dict data: A partially filled dictionary which will contain the
    json-friendly representation of `obj` once this method has
    finished.
z"You must implement flatten() in %sNotImplementedError	__class__r   objdatas      r   flattenBaseHandler.flattenf   s     ""F"WXXr   c                 2    [        SU R                  -  5      e)ze
Restore an object of the registered type from the json-friendly
representation `obj` and return it.
z"You must implement restore() in %sr;   )r   r?   s     r   restoreBaseHandler.restoreq   s    
 ""F"WXXr   c                 0    [         R                  X5        U$ )z
Register this handler for the given class. Suitable as a decorator,
e.g.::

    @MyCustomHandler.handles
    class MyCustomClass:
        def __reduce__(self):
            ...
)registryr    r)   s     r   handlesBaseHandler.handlesx   s     	#$
r   c                     Xl         U $ )zyThis permits registering either Handler instances or classes

:Parameters:
  - `context`: reference to pickler/unpickler
r6   r8   s     r   __call__BaseHandler.__call__   s     r   r6   N)r,   r-   r.   r/   r   rA   rD   classmethodrH   rK   r0   r1   r   r   r3   r3   [   s,    	YY  r   r3   c                   $    \ rS rSrSrS rS rSrg)ArrayHandler   z'Flatten and restore array.array objectsc                 z    UR                   US'   U R                  R                  UR                  5       SS9US'   U$ )NtypecodeFresetvalues)rR   r7   rA   tolistr>   s      r   rA   ArrayHandler.flatten   s8    <<Z--cjjl%-HXr   c                     US   nU R                   R                  US   SS9nUS:X  a  U Vs/ s H  n[        U5      PM     nn[        R                  " X#5      $ s  snf )NrR   rU   FrS   c)r7   rD   bytesarray)r   r@   rR   rU   xs        r   rD   ArrayHandler.restore   s\    
#%%d8nE%Bs?(./1eAhF/{{8,, 0s   Ar1   Nr,   r-   r.   r/   __doc__rA   rD   r0   r1   r   r   rO   rO      s    1
-r   rO   c                   $    \ rS rSrSrS rS rSrg)DatetimeHandler   zCustom handler for datetime objects

Datetime objects use __reduce__, and they generate binary strings encoding
the payload. This handler encodes that payload to reconstruct the
object.

c           	      l   U R                   nUR                  (       d0  [        US5      (       a  UR                  5       nU$ [	        U5      nU$ UR                  5       u  pVUR                  n[        R                  " US   5      nU/USS   V	s/ s H	  o" U	SS9PM     sn	-   nU" USS9U4US'   U$ s  sn	f )N	isoformatr   r   FrS   
__reduce__)	r7   unpicklablehasattrrd   strre   rA   r   	b64encode)
r   r?   r@   picklerresultr   argsrA   payloadis
             r   rA   DatetimeHandler.flatten   s    ,,""sK(( M SMNN$	//..a)yT!"XFXGAU3XFF%c7>\ Gs   B1c                     US   u  p#U R                   nUR                  nU" USS9n[        R                  " US   5      nU4[	        USS   Vs/ s H	  ou" USS9PM     sn5      -   nUR
                  " U/UQ76 $ s  snf )Nre   FrS   r   r   )r7   rD   r   	b64decodetuple__new__)	r   r@   r   rl   	unpicklerrD   valuern   paramss	            r   rD   DatetimeHandler.restore   s    &	LL	##c'tAw'EDH"MHq71E#:H"MNN{{3((( #Ns   A:
r1   Nr^   r1   r   r   ra   ra      s    )r   ra   c                   $    \ rS rSrSrS rS rSrg)RegexHandler   z1Flatten _sre.SRE_Pattern (compiled regex) objectsc                 $    UR                   US'   U$ Npattern)r}   r>   s      r   rA   RegexHandler.flatten   s    ++Yr   c                 4    [         R                  " US   5      $ r|   )recompiler   r@   s     r   rD   RegexHandler.restore   s    zz$y/**r   r1   Nr^   r1   r   r   ry   ry      s    ;+r   ry    c                   $    \ rS rSrSrS rS rSrg)QueueHandler   zOpaquely serializes Queue objects

Queues contains mutex and condition variables which cannot be serialized.
Construct a new Queue instance when restoring.

c                     U$ r	   r1   r>   s      r   rA   QueueHandler.flatten   s    r   c                 ,    [         R                  " 5       $ r	   )queueQueuer   s     r   rD   QueueHandler.restore   s    {{}r   r1   Nr^   r1   r   r   r   r      s    r   r   c                   D    \ rS rSrSrS r\R                  4S jrS rSr	g)CloneFactory   zASerialization proxy for collections.defaultdict's default_factoryc                     Xl         g r	   exemplar)r   r   s     r   r   CloneFactory.__init__   s     r   c                 &    U" U R                   5      $ )z>Create new instances by making copies of the provided exemplarr   )r   clones     r   rK   CloneFactory.__call__   s    T]]##r   c                 <    S[        U 5      S SU R                   S3$ )Nz<CloneFactory object at 0xr\   z (z)>)idr   r   s    r   __repr__CloneFactory.__repr__   s!    +BtHQ<r$--KKr   r   N)
r,   r-   r.   r/   r_   r   copyrK   r   r0   r1   r   r   r   r      s    K! "YY $Lr   r   c                   $    \ rS rSrSrS rS rSrg)UUIDHandler   zSerialize uuid.UUID objectsc                 $    UR                   US'   U$ Nhex)r   r>   s      r   rA   UUIDHandler.flatten   s    ggUr   c                 4    [         R                  " US   5      $ r   )uuidUUIDr   s     r   rD   UUIDHandler.restore   s    yye%%r   r1   Nr^   r1   r   r   r   r      s    %&r   r   c                   $    \ rS rSrSrS rS rSrg)LockHandleri  z Serialize threading.Lock objectsc                 ,    UR                  5       US'   U$ )Nlocked)r   r>   s      r   rA   LockHandler.flatten	  s    Xr   c                 ~    [         R                  " 5       nUR                  SS5      (       a  UR                  5         U$ )Nr   F)	threadingLockr   acquire)r   r@   locks      r   rD   LockHandler.restore  s-    ~~88He$$LLNr   r1   Nr^   r1   r   r   r   r     s    *r   r   c                   $    \ rS rSrSrS rS rSrg)TextIOHandleri  z>Serialize file descriptors as None because we cannot roundtripc                     g r	   r1   r>   s      r   rA   TextIOHandler.flatten  s    r   c                     [        S5      e)z>Restore should never get called because flatten() returns Nonez+Restoring IO.TextIOHandler is not supported)AssertionErrorr   s     r   rD   TextIOHandler.restore  s    JKKr   r1   Nr^   r1   r   r   r   r     s    HLr   r   )$r_   r[   r   datetimeior   r   r   r   r   r   r   rG   r    r*   r   r3   rO   rH   ra   datetimery   typer   r   r   r   r   r   r   r   _lockr=   r   TextIOWrapperr1   r   r   <module>r      s      	  	   ;+ ;+| :  
ll2 2j-; -    U[[ !)k )D   )) *    &    &+; +   T"**R.) *;    U[[ !L L&+ &   DII +  	   EOO $LK L   b&& 'r   