Ë
    :vžjw  ã                  óV  — U d Z ddlm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	m
Z
 ddlmZmZmZmZ ddlmZmZ ddlmZmZmZmZmZmZmZmZ dd	lmZ erDdd
lmZm Z m!Z! ddlm"Z"m#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+m,Z,  G d„ de*«      Z-eZ.de/d<   ddgZ0dZ1dZ2dZ3dZ4d/d„Z5d0d„Z6ef	 	 	 	 	 d1d„Z7i Z8de/d<   	 	 	 	 	 	 d2d„Z9 G d„ d«      Z: G d„ d«      Z;d3d „Z<d4d!„Z=d5d"„Z>d6d#„Z?d7d$„Z@d8d%„ZAd9d&„ZBd'ZC	 	 	 	 	 	 d:d(„ZDd8d)„ZEd;d*„ZF	 	 	 	 	 	 d<d+„ZG	 	 	 	 	 	 d<d,„ZHd=d-„ZId>d.„ZJy)?a¦  Descriptor for _repr_mimebundle_ attribute that manages the comm channel.

`MimeBundleDescriptor()` takes the place of a `_repr_mimebundle_` method on a class.

- `MimeBundleDescriptor` is a
  [descriptor](https://docs.python.org/3/howto/descriptor.html). When the
  `_repr_mimebundle_` attribute is accessed on an instance of the decorated class, a
  `ReprMimeBundle` instance is created and returned.
- A `ReprMimeBundle` is first and foremost a callable object that implements the
  `_repr_mimebundle_` protocol that jupyter expects.  However, it also manages a
  Comm instance that is used to send the state of the python model to the
  javascript view.  This is done lazily, so that the Comm is only created when the
  `_repr_mimebundle_` is first accessed.
- `ReprMimeBundle` has the logic to get/set the state of the python model, and will keep
  the two in sync ("bind"/"unbind_instance" methods can be used to control this).
é    )ÚannotationsN)ÚasdictÚis_dataclass)ÚTYPE_CHECKINGÚAnyÚcastÚoverloadé   )ÚFileContentsÚVirtualFileContents)Ú_ANYWIDGET_ID_KEYÚ_DEFAULT_ESMÚ_ESM_KEYÚ_PROTOCOL_VERSIONÚput_buffersÚremove_buffersÚrepr_mimebundleÚtry_file_contents)Ú_ANYWIDGET_SEMVER_VERSION)ÚCallableÚIterableÚSequence)Ú	TypeAliasÚ	TypeGuard)ÚProtocol)ÚCommMessagec                  ó   — e Zd Zdd„Zy)Ú	_GetStatec                 ó   — y ©N© )ÚselfÚobjÚincludes      úf/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/anywidget/_descriptor.pyÚ__call__z_GetState.__call__<   s   € Èó    N)r#   r   r$   úset[str] | NoneÚreturnÚdict)Ú__name__Ú
__module__Ú__qualname__r&   r!   r'   r%   r   r   ;   s   „ ÜKr'   r   r   ÚSerializableÚMimeBundleDescriptorÚReprMimeBundleÚ_repr_mimebundle_Ú_get_anywidget_stateÚ_set_anywidget_statez
anywidget:c                ó  — t        | d«      r&t        | j                  t        «      r| j                  S t	        | t
        d«      }t        |t        «      r|j                  | t        | «      «      }t        |t        «      r|j                  S y)uº  Get model_id from an anywidget object, or None if not an anywidget.

    .. note::
       For protocol objects backed by a ``MimeBundleDescriptor`` (e.g.
       dataclasses), this forces the descriptor's ``__get__`` to run, which
       opens the object's comm. ``ipywidgets``-based widgets open their comm
       eagerly in ``__init__``, so the ``hasattr(obj, "model_id")`` branch
       short-circuits without side effects for them. The descriptor-driven
       side effect only matters if a protocol-based widget is assigned to a
       ``WidgetTrait`` (or otherwise inspected) and its parent is never
       displayed â€” otherwise the comm would have opened at display time
       anyway.
    Úmodel_idN)
ÚhasattrÚ
isinstancer5   ÚstrÚgetattrÚ
_REPR_ATTRr/   Ú__get__Útyper0   )r#   Úbundles     r%   Ú_try_get_model_idr>   I   si   € ô ˆs�JÔ¤J¨s¯|©|¼SÔ$AØ�|‰|Ðä�Sœ* dÓ+€FÜ�&Ô.Ô/à—‘ ¤T¨#£YÓ/ˆÜ�&œ.Ô)Ø�‰ÐØr'   c                óp   ‡— dˆfd„Š| j                  «       D ��ci c]  \  }}| ‰|«      “Œ c}}S c c}}w )zJRecursively replace anywidget objects with 'anywidget:<model_id>' strings.c                óT  •— t        | «      }|�
t        › |› �S t        | t        «      r*| j	                  «       D ��ci c]  \  }}| ‰|«      “Œ c}}S t        | t
        «      r| D �cg c]
  } ‰|«      ‘Œ c}S t        | t        «      rt        ˆfd„| D «       «      S | S c c}}w c c}w )Nc              3  ó.   •K  — | ]  } ‰|«      –— Œ y ­wr    r!   )Ú.0ÚitemÚ_replaces     €r%   Ú	<genexpr>z9_replace_widget_refs.<locals>._replace.<locals>.<genexpr>p   s   øè ø€ Ð6±A¨D™ $Ÿ±Aùs   ƒ)r>   Ú_WIDGET_REF_PREFIXr7   r*   ÚitemsÚlistÚtuple)Úvr5   ÚkÚvalrC   rD   s        €r%   rD   z&_replace_widget_refs.<locals>._replaceg   s    ø€ Ü$ QÓ'ˆØÐÜ(Ð)¨(¨Ð4Ð4Ü�aœÔØ34·7±7´9Ô=±9©¨¨C�A‘x “}Ñ$°9Ò=Ð=Ü�aœÔÙ/0Ó1©q t‘H˜T•N¨qÑ1Ð1Ü�aœÔÜÓ6±AÓ6Ó6Ð6Øˆùó >ùâ1s   ¼BÁ'B%)rJ   Úobjectr)   rM   )rG   )r#   rK   rJ   rD   s      @r%   Ú_replace_widget_refsrN   d   s4   ø€ õ
ð (+§y¡y¤{Ô3¡{™t˜q !ˆA‰x˜‹{‰N {Ò3Ð3ùÓ3s   ›2c                ó˜   — dd l }t        | «      } t        | «      \  }}} |j                  dd|iddt        ddt        d dœ|¥|dœ|¬	«      S )
Nr   zjupyter.widgetÚversionÚ	anywidgetÚAnyModelÚAnyView)Ú_model_moduleÚ_model_nameÚ_model_module_versionÚ_view_moduleÚ
_view_nameÚ_view_module_versionÚ_view_count)ÚstateÚbuffer_paths)Útarget_nameÚmetadataÚdataÚbuffers)ÚcommrN   r   Úcreate_commr   )Úinitial_staterP   ra   r[   r\   r`   s         r%   Ú	open_commrd   v   sw   € ó ä(¨Ó7€MÜ#1°-Ó#@Ñ €Eˆ<˜àˆ4×ÑØ$Ø˜WÐ%ð "-Ø)Ü)BØ +Ø'Ü(AØ#ñ	ð ð	ð )ñ
ð ô!ð r'   z"dict[int, comm.base_comm.BaseComm]Ú_COMMSc                ó2  — t        | «      }|t        vrht         |«       ¬«      t        |<   t        j                  t
        «      5  t        j                  | t        j                  |«       ddd«       t        |   S t        |   S # 1 sw Y   t        |   S xY w)zõGet or create a communication channel for a given object.

    Comms are cached by object id, so that if the same object is used in multiple
    places, the same comm will be used. Comms are deleted when the object is garbage
    collected.
    )rc   N)	Úidre   rd   Ú
contextlibÚsuppressÚ	TypeErrorÚweakrefÚfinalizeÚpop)r#   Ú	get_stateÚobj_ids      r%   Ú_get_or_create_commrp   ™   sw   € ô �‹W€FØ”VÑÜ"±³Ô=Œˆv‰ä× Ñ ¤Õ+ô ×Ñ˜S¤&§*¡*¨fÔ5÷ ,ô �&‰>ÐŒ6�&‰>Ð÷	 ,ô �&‰>Ðús   Á&BÂBc                  ót   — e Zd ZdZddddœ	 	 	 	 	 	 	 	 	 dd„Zdd„Zedd„«       Zedd„«       Z	 	 	 	 	 	 dd	„Zy
)r/   a¹  Descriptor that builds a ReprMimeBundle when accessed on an instance.

    The `__get__` method is called when the descriptor's name is accessed on a class or
    instance.  It returns a `ReprMimeBundle` instance, which is a callable that
    implements the `_repr_mimebundle_` protocol that jupyter expects, but also manages
    the comm channel between the python model and the javascript view.

    For more on descriptors, see: <https://docs.python.org/3/howto/descriptor.html>

    Parameters
    ----------
    follow_changes : bool, optional
        If `True` (default), the state of the python model will be updated whenever the
        state of the javascript view changes (and vice versa).
    autodetect_observer : bool, optional
        If `True` (default), an attempt will be made to find a known observer-pattern
        API on the object (such as a psygnal.SignalGroup or traitlets.HasTraits) and
        use it to automatically send state changes to the javascript view.  If `False`,
        the javascript view will only be updated when the `send_state()` method is
        explicitly called.
    no_view : bool, optional
        If `True`, the callable will return `None` instead of a mimebundle. This is
        useful for cases where you want to use the comm channel to send state updates
        to the front end, but don't want to display anything in the notebook
        (i.e., A DOM-less widget).  Defaults to `False`.
    **extra_state : Any, optional
        Any extra state that should be sent to the javascript view (for example,
        for the `_esm` anywidget field.)  By default, `{'_esm': _DEFAULT_ESM}` is added
        to the state.

    Examples
    --------
    Note that *technically* you could name the attribute anything you want
    but it probably only makes sense to call it '_repr_mimebundle_'.

    >>> class Foo:
    ...     _repr_mimebundle_ = MimeBundleDescriptor()
    >>> foo = Foo()

    in a jupyter notebook, this line will now access `_repr_mimebundle_`, and turn the
    descriptor into an instance of `ReprMimeBundle`, which spins up a comm channel, sets
    up state synchronization, and, when called, returns a mimebundle dict that includes
    the comm id.

    >>> foo
    TF)Úfollow_changesÚautodetect_observerÚno_viewc               ó  — |j                  t        t        «       || _        t        | _        || _        || _        || _        | j                  j                  «       D ]"  \  }}t        |«      }|€Œ|| j                  |<   Œ$ y r    )Ú
setdefaultr   r   Ú_extra_stater:   Ú_nameÚ_follow_changesÚ_autodetect_observerÚ_no_viewrG   r   )r"   rr   rs   rt   Úextra_staterK   rJ   Úfile_contentss           r%   Ú__init__zMimeBundleDescriptor.__init__à   sy   € ð 	×Ñœx¬Ô6Ø'ˆÔÜˆŒ
Ø-ˆÔØ$7ˆÔ!ØˆŒà×%Ñ%×+Ñ+Ö-‰DˆAˆqô .¨aÓ0ˆMØÑ(Ø'4�×!Ñ! !Ò$ñ .r'   c                ó   — || _         y)z´Called when this descriptor is assigned to an attribute on a class.

        In most cases, we won't *want* `name` to be anything other than
        `'_repr_mimebundle_'`.
        N)rx   )r"   ÚownerÚnames      r%   Ú__set_name__z!MimeBundleDescriptor.__set_name__ö   s   € ð ˆ�
r'   c                 ó   — y r    r!   ©r"   Úinstancer€   s      r%   r;   zMimeBundleDescriptor.__get__ÿ   s   € ØLOr'   c                 ó   — y r    r!   r„   s      r%   r;   zMimeBundleDescriptor.__get__  s   € ØHKr'   c                ó�  — |€| S 	 t        || j                  | j                  | j                  ¬«      }| j                  r|j                  «        t        j                  t        t        «      5  t        || j                  |«       ddd«       |S # t        $ r }t        j                  d|› �d¬«       ‚ d}~ww xY w# 1 sw Y   |S xY w)a“  Called when this descriptor's name is accessed on a class or instance.

        Examples
        --------
        >>> class Foo:
        ...     _repr_mimebundle_ = MimeBundleDescriptor()
        ...
        >>> Foo._repr_mimebundle_  # same as Foo._repr_mimebundle_.__get__(None, Foo)
        >>> foo = Foo()
        >>> foo._repr_mimebundle_  # same as Foo._repr_mimebundle_.__get__(foo, Foo)
        N)rs   r|   rt   zError in Anywidget repr:
r
   ©Ú
stacklevel)r0   rz   rw   r{   ry   Úsync_object_with_viewÚ	ExceptionÚwarningsÚwarnrh   ri   ÚAttributeErrorÚ
ValueErrorÚsetattrrx   )r"   r…   r€   Úrepr_objÚes        r%   r;   zMimeBundleDescriptor.__get__  s»   € ð  ÐàˆKð	Ü%ØØ$(×$=Ñ$=Ø ×-Ñ-ØŸ™ô	ˆHð ×#Ò#à×.Ñ.Ô0ô × Ñ ¤´Õ<ô �H˜dŸj™j¨(Ô3÷	 =ð ˆøô# ò 	ô �M‰MÐ6°q°cÐ:ÀqÕIØûð	ú÷ =ð ˆús$   †A	B Á-B;Â	B8ÂB3Â3B8Â;CN)
rr   Úboolrs   r“   rt   r“   r|   rM   r)   ÚNone)r€   r<   r�   r8   r)   r”   )r…   r”   r€   r<   r)   r/   )r…   rM   r€   r<   r)   r0   )r…   zobject | Noner€   r<   r)   z%ReprMimeBundle | MimeBundleDescriptor)r+   r,   r-   Ú__doc__r~   r‚   r	   r;   r!   r'   r%   r/   r/   °   sŽ   „ ñ-ðd  $Ø$(Øñ5ð ð5ð "ð	5ð
 ð5ð ð5ð 
ó5ó,ð ÚOó ØOàÚKó ØKð1àð1ð ð1ð 
/ô	1r'   c                  óˆ   — e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 dd„Zddd„Zddd„Zdd„Zedd„«       Z	dd„Z
	 	 d	 	 	 	 	 dd	„Zdd
„Zy)r0   aO  Callable object that behaves like a `_repr_mimebundle_` method...

    which is to say, it returns a mimebundle (mapping of mimetypes to data) when called.

    This object *also* controls an Comm channel between the front-end js view
    and some python model object (`obj`),

    Parameters
    ----------
    obj : object
        The python model object which is being represented by the view.  Most likely
        this will be a dataclass instance that has been made "evented" by the anywidget
        decorator... but we type it as `object` to allow for other use cases, to make it
        clearer what protocols we expect from the object.
    autodetect_observer : bool, optional
        If `True` (default), an attempt will be made to find a known observer-pattern
        API on the object (such as a psygnal.SignalGroup or traitlets.HasTraits) and
        use it to automatically send state changes to the javascript view.  If `False`,
        the javascript view will only be updated when the `send_state()` method is
        explicitly called.
    no_view : bool, optional
        If `True`, the callable will return `None` instead of a mimebundle. This is
        useful for cases where you want to use the comm channel to send state updates
        to the front end, but don't want to display anything in the notebook
        (i.e., A DOM-less widget).  Defaults to `False`.
    extra_state : dict, optional
        Any extra state that should be sent to the javascript view (for example,
        for the `_esm` anywidget field.)  By default, `{'_esm': DEFAULT_ESM}` is added
        to the state.
    Nc                óÈ  ‡ ‡— |‰ _         |xs i j                  «       ‰ _        ‰ j                  j                  t        t        ‰«      «       |‰ _        	 t        j                  ‰‰ j                  «      ‰ _
        t        «       ‰ _        t!        ‰«      ‰ _        t%        ‰«      ‰ _        ‰ j                  j)                  «       D ]j  \  }}t+        |t,        t.        f«      r9t1        |«      ‰ j                  |<   |j2                  j4                  |fd	ˆ fd„«       }t7        ‰ˆˆ fd„¬«      ‰ _        Œl y # t        $ r( ˆfd„‰ _
        t        j                  d‰› d�d¬«       Y Œçw xY w)
Nc                 ó   •— ‰ S r    r!   ©r#   s   €r%   Ú<lambda>z)ReprMimeBundle.__init__.<locals>.<lambda>i  s   ø€ ¡r'   zAnywidget: z¢ is not weakrefable, so it will not be garbage collected until the view is closed. Please consider adding `__slots__ = ('__weakref__',)` to your class definition.é   rˆ   c                óF   •— | ‰j                   |<   ‰j                  |«       y r    )rw   Ú
send_state)Únew_contentsÚkeyr"   s     €r%   Ú
_on_changez+ReprMimeBundle.__init__.<locals>._on_change}  s   ø€ à-9�D×%Ñ% cÑ*Ø—O‘O CÕ(r'   c                 óF   •— i ‰j                  ‰ d ¬«      ¥‰j                  ¥S )N©r$   )Ú
_get_staterw   )r#   r"   s   €€r%   rš   z)ReprMimeBundle.__init__.<locals>.<lambda>†  s+   ø€ ð #Ø—o‘o c°4�oÓ8ð#à×'Ñ'ñ#r'   )r#   rn   )rž   r8   rŸ   r8   r)   r”   )rz   Úcopyrw   rv   r   Ú_anywidget_idr{   rk   ÚrefÚ_on_obj_deletedÚ_objrj   rŒ   r�   ÚsetÚ_disconnectorsÚdetermine_state_getterr£   Údetermine_state_setterÚ
_set_staterG   r7   r   r   r8   ÚchangedÚconnectrp   Ú_comm)r"   r#   rs   r|   rt   rŸ   Úvaluer    s   ``      r%   r~   zReprMimeBundle.__init__Y  s;  ù€ ð %8ˆÔ!Ø(Ò.¨B×4Ñ4Ó6ˆÔØ×Ñ×$Ñ$Ô%6¼ÀcÓ8JÔKØˆŒð
	Ü.5¯k©k¸#¸t×?SÑ?SÓ.TˆDŒIô .1«UˆÔô 1°Ó5ˆŒÜ0°Ó5ˆŒà×+Ñ+×1Ñ1Ö3‰JˆC�Ü˜%Ô"5´|Ð!DÔEÜ),¨U«�×!Ñ! #Ñ&à—‘×&Ñ&Ø=@õ )ó 'ð)ô -Øôô	ˆD�Jñ 4øô% ò 	ã#ˆDŒIÜ�M‰MØ˜c˜Uð #Kð Kð ÷	ð	ús   Á%D0 Ä0.E!Å E!c                óX   — | j                  «        | j                  j                  «        y)z)Called when the python object is deleted.N)Úunsync_object_with_viewr°   Úclose)r"   r¦   s     r%   r§   zReprMimeBundle._on_obj_deletedŒ  s   € à×$Ñ$Ô&Ø�
‰
×ÑÕr'   c                ó¼  — | j                  «       }|€y|�t        |t        «      r|hn
t        |«      }i | j	                  ||¬«      ¥| j
                  ¥}|�(|j                  «       D ��ci c]  \  }}||v sŒ||“Œ }}}|syt        |«      }t        |«      \  }}}t        | j                  dd«      r$d||dœ}| j                  j                  ||¬«       yyc c}}w )zîSend state update to the front-end view.

        Parameters
        ----------
        include : set of str, optional
            If provided, only send the state for the keys in this set.  Otherwise,
            send all state.
        Nr¢   ÚkernelÚupdate)Úmethodr[   r\   )r_   r`   )r¨   r7   r8   r©   r£   rw   rG   rN   r   r9   r°   Úsend)	r"   r$   r#   r[   rK   rJ   r\   r`   Úmsgs	            r%   r�   zReprMimeBundle.send_state’  sè   € ð �i‰i‹kˆØˆ;ØàÐÜ#-¨g´sÔ#;�w‘iÄÀWÃˆGàN�4—?‘? 3°�?Ó8ÐN¸D×<MÑ<MÐNˆØÐð ',§k¡k¤mÔD¡m™d˜a °q¸G²|�Q˜‘T mˆEÑDáØä$ UÓ+ˆÜ'5°eÓ'<Ñ$ˆˆ|˜WÜ�4—:‘:˜x¨Ô.Ø%°À|ÑTˆCØ�J‰J�O‰OØØð õ ð /ùó Es   Á*CÁ7Cc                ó
  — | j                  «       }|€y|d   d   }|d   dk(  r4d|v r/|d   }d|v rt        ||d   |d   «       | j                  ||«       yy|d   d	k(  r| j                  «        yd
|d   › d�}t	        |«      ‚)zêCalled when a msg is received from the front-end.

        (assuming `sync_object_with_view` has been called.)

        Raises
        ------
        ValueError
            If the method in the comm message is not recognized.
        NÚcontentr_   r¸   r·   r[   r\   r`   Úrequest_statezUnrecognized method: zB.  Please report this at https://github.com/manzt/anywidget/issues)r¨   r   r­   r�   r�   )r"   rº   r#   r_   r[   Úerr_msgs         r%   Ú_handle_msgzReprMimeBundle._handle_msg´  s³   € ð �i‰i‹kˆØˆ;Øà�9‰~˜fÑ%ˆØ�‰>˜XÒ%Ø˜$‰Ø˜W™�Ø! TÑ)Ü  t¨NÑ';¸SÀ¹^ÔLØ—‘  UÕ+ð	 ð �(‰^˜Ò.Ø�O‰OÕð (¨¨X©Ð'7ð 8<ð <ð ô ˜WÓ%Ð%r'   c                ó.   — | j                   j                  S )z,The unique model identifier for this widget.)r°   Úcomm_id©r"   s    r%   r5   zReprMimeBundle.model_idÝ  s   € ð �z‰z×!Ñ!Ð!r'   c                óŒ   — | j                   ryt        | j                  j                  t	        | j                  «       «      ¬«      S )z=Called when _repr_mimebundle_ is called on the python object.N)r5   Ú	repr_text)r{   r   r°   rÁ   Úreprr¨   )r"   Úkwargss     r%   r&   zReprMimeBundle.__call__â  s0   € ð �=Š=ØÜ¨¯
©
×(:Ñ(:ÄdÈ4Ï9É9Ë;ÓFWÔXÐXr'   c                óÔ  — |r5| j                   j                  | j                  «       | j                  «        |r¯| j                  r¢| j                  «       }|€d}t        |«      ‚| j                  rt        j                  dd¬«       yt        t        fD ]4  } ||| j                  «      }|sŒ| j                  j                  |«        y t        j                  d|› d�d¬«       yyy)að  Connect the front-end to changes in the model, and vice versa.

        Parameters
        ----------
        py_to_js : bool, optional
            If True (the default), changes in the python model will be reflected in the
            front-end.
        js_to_py : bool, optional
            If True (the default), changes in the front-end will be reflected in the
            python model.

        Raises
        ------
        RuntimeError
            If the object has been deleted.
        NzCannot sync a deleted objectz$Refusing to re-sync a synced object.r›   rˆ   zCould not find a notifier on z^ (e.g. psygnal, traitlets). Changes to the python object will not be reflected in the JS view.)r°   Úon_msgr¿   r�   rz   r¨   ÚRuntimeErrorrª   rŒ   r�   Ú_connect_psygnalÚ_connect_traitletsÚadd)r"   Úpy_to_jsÚjs_to_pyr#   rº   Ú	connectorÚ
disconnects          r%   rŠ   z$ReprMimeBundle.sync_object_with_viewê  sØ   € ñ* à�J‰J×Ñ˜d×.Ñ.Ô/Ø�O‰OÔá˜×1Ò1à—)‘)“+ˆCØˆ{Ø4�Ü" 3Ó'Ð'à×"Ò"Ü—‘ÐDÐQRÕSØô /Ô0BÓC�	Ù& s¨D¯O©OÓ<�
ÚØ×'Ñ'×+Ñ+¨JÔ7Ùð	 Dô —‘Ø3°C°5ð 9ð ð  !ö	ð/ 2ˆ8r'   c                ó  — | j                   j                  d«       | j                  rOt        j                  t
        «      5   | j                  j                  «       «        ddd«       | j                  rŒNyy# 1 sw Y   ŒxY w)zEDisconnect the view from changes in a model instance, and vice versa.N)r°   rÈ   rª   rh   ri   r‹   rm   rÂ   s    r%   r³   z&ReprMimeBundle.unsync_object_with_view"  sY   € à�
‰
×Ñ˜$Ôà×!Ò!Ü×$Ñ$¤YÕ/Ø)�×#Ñ#×'Ñ'Ó)Ô+÷ 0ð ×!Õ!ß/Ð/ús   Á A8Á8B)TNF)
r#   rM   rs   r“   r|   zdict[str, object] | Nonert   r“   r)   r”   r    )r¦   zweakref.ReferenceType | Noner)   r”   )r$   zstr | Iterable[str] | Noner)   r”   )rº   r   r)   r”   )r)   r8   )rÆ   zSequence[str]r)   ztuple[dict, dict] | None)TT)rÍ   r“   rÎ   r“   r)   r”   ©r)   r”   )r+   r,   r-   r•   r~   r§   r�   r¿   Úpropertyr5   r&   rŠ   r³   r!   r'   r%   r0   r0   9  s£   „ ñðD %)Ø04Øð1àð1ð "ð1ð .ð	1ð
 ð1ð 
ó1ôfô óD"&ðR ò"ó ð"óYð Øð6àð6ð ð6ð 
ó	6ôp,r'   c                ó\   — t        | «      j                  › dt        | «      j                  › �S )z9Return a unique id for an object, to send to the JS side.Ú.)r<   r,   r+   r™   s    r%   r¥   r¥   .  s)   € ä�3‹i×"Ñ"Ð# 1¤T¨#£Y×%7Ñ%7Ð$8Ð9Ð9r'   c                ó.  — t        t        | «      t        «      rt        t        | «      t        «      S t	        | «      rd„ S t        | «      rt        S t        | «      rt        | d«      rt        S t        S t        | «      rt        S d| ›d�}t        |«      ‚)aQ  Autodetect how `obj` can be serialized to a dict.

    This looks for various special methods and patterns on the object (e.g. dataclass,
    pydantic, etc...), and returns a callable that can be used to get the state of the
    object as a dict.

    As an escape hatch it first looks for a special method on the object called
    `_get_anywidget_state`.

    Returns
    -------
    state_getter : Callable[[object], dict]
        A callable that takes an object and returns a dict of its state.

    Raises
    ------
    TypeError
        If no state-getting method can be determined.
    c                ó   — t        | «      S r    )r   ©r#   r$   s     r%   rš   z(determine_state_getter.<locals>.<lambda>P  s   € ¤F¨3¤Kr'   Ú
model_dumpz,Cannot determine a state-getting method for zI. Please implement a `_get_anywidget_state()` method that returns a dict.)r6   r<   Ú_STATE_GETTER_NAMEr9   r   Ú_is_traitlets_objectÚ_get_traitlets_stateÚ_is_pydantic_modelÚ_get_pydantic_state_v2Ú_get_pydantic_state_v1Ú_is_msgspec_structÚ_get_msgspec_staterj   )r#   rº   s     r%   r«   r«   3  s—   € ô* Œt�C‹yÔ,Ô-ô ”t˜C“yÔ"4Ó5Ð5ä�CÔñ 0Ð/ä˜CÔ Ü#Ð#ä˜#ÔÜ�3˜Ô%Ü)Ð)Ü%Ð%ä˜#ÔÜ!Ð!ð 7°s°gð >Rð 	Rð ô �C‹.Ðr'   c                óN   — |j                  «       D ]  \  }}t        | ||«       Œ y)z?A default state setter that just sets attributes on the object.N)rG   r�   )r#   r[   rŸ   rL   s       r%   Ú_default_set_staterã   i  s"   € à—K‘K–M‰ˆˆSÜ��S˜#Õñ "r'   c                ór   — t        t        | «      t        «      rt        t        | «      t        «      S t        S )a7  Autodetect how `obj` can update its state from a dict.

    The default implementation just sets attributes on the object.

    Returns
    -------
    state_setter : Callable[[object, dict], None]
        A callable that takes an object and a dict of its state, and updates the object
        accordingly.
    )r6   r<   Ú_STATE_SETTER_NAMEr9   rã   r™   s    r%   r¬   r¬   o  s+   € ô Œt�C‹yÔ,Ô-Ü”t˜C“yÔ"4Ó5Ð5äÐr'   c                óœ  — t         rddl}nt        j                  j	                  d«      }|€yt        | dd«      }t        ||j                  «      r|S t        j                  t        t        t        «      5  t        | «      j                  «       D ]%  }t        ||j                  «      sŒ|c cddd«       S  	 ddd«       y# 1 sw Y   yxY w)z*Look for a psygnal.SignalGroup on the obj.r   NÚpsygnalÚevents)r   rç   ÚsysÚmodulesÚgetr9   r7   ÚSignalGrouprh   ri   rŽ   ÚRecursionErrorrj   ÚvarsÚvalues)r#   rç   rè   Úattrs       r%   Ú_get_psygnal_signal_grouprñ   ƒ  s­   € åÜä—+‘+—/‘/ )Ó,ˆØ€Øô �S˜( DÓ)€FÜ�&˜'×-Ñ-Ô.Øˆô 
×	Ñ	ÜÜÜõ
ô
 ˜“I×$Ñ$Ö&ˆDÜ˜$ × 3Ñ 3Õ4Ø‘÷
ñ 
ñ
 '÷
ð ÷
ð ús   Á63CÂ*CÂ7CÃCc                ó`   ‡‡‡— t        | «      Š‰�‰j                  dˆfd„«       Šdˆˆfd„}|S y)a  Check if an object has a psygnal.SignalGroup, and connect it to send_state.

    Returns
    -------
    disconnect : Callable | None
        A callable that disconnects the psygnal.SignalGroup from send_state, or None
        if no psygnal.SignalGroup was found.
    Nc                ó@   •—  ‰| j                   j                  h«       y r    )Úsignalr�   )Úeventr�   s    €r%   Ú_on_psygnal_eventz+_connect_psygnal.<locals>._on_psygnal_event«  s   ø€ á˜Ÿ™×)Ñ)Ð*Õ+r'   c                 ó(   •— ‰j                  ‰ «       y r    )rÐ   )rö   rè   s   €€r%   Ú_disconnectz%_connect_psygnal.<locals>._disconnect¯  s   ø€ Ø×ÑÐ/Õ0r'   )rõ   zpsygnal.EmissionInfor)   r”   rÒ   )rñ   r¯   )r#   r�   rø   rö   rè   s    ` @@r%   rÊ   rÊ   ž  s;   ú€ ô ' sÓ+€FàÐà	�‰ô	,ó 
ð	,ö	1ð ÐØr'   c                ót   — t         j                  j                  d«      }|�t        | |j                  «      S dS )zAReturn `True` if an object is an instance of traitlets.HasTraits.Ú	traitletsF)ré   rê   rë   r7   Ú	HasTraits)r#   rú   s     r%   rÛ   rÛ   ¹  s1   € ä—‘—‘ Ó,€IØ3<Ð3HŒ:�c˜9×.Ñ.Ó/ÐSÈeÐSr'   Úsyncc                ó6   — t         di} | j                  di |¤ŽS )z¦Get the state of a traitlets.HasTraits instance.

    Returns
    -------
    state : dict
        A dictionary of the state of the traitlets.HasTraits instance.
    Tr!   )Ú_TRAITLETS_SYNC_FLAGÚtrait_values)r#   r$   rÆ   s      r%   rÜ   rÜ   É  s$   € ô # DÐ)€FØˆ3×ÑÑ%˜fÑ%Ð%r'   c                óÀ   ‡‡‡— t        | «      sydˆfd„Š| j                  ‰t        | j                  d¬«      «      ¬«       t	        j
                  | «      Šdˆˆfd„}|S )	aI  Check if an object is a traitlets.HasTraits, and connect it to send_state.

    Only traits with tagged with `sync=True` will be synced.

    Returns
    -------
    disconnect : Callable | None
        A callable that disconnects the traitlets.HasTraits from send_state, or None
        if no traitlets.HasTraits was found.
    Nc                ó   •—  ‰| d   h«       y )Nr�   r!   )Úchanger�   s    €r%   Ú_on_trait_changez,_connect_traitlets.<locals>._on_trait_changeæ  s   ø€ Ù�F˜6‘NÐ#Õ$r'   T)rü   )Únamesc                 ó<   •—  ‰«       } | �| j                  ‰«       y y r    )Ú	unobserve)r#   r  Úobj_refs    €€r%   rø   z'_connect_traitlets.<locals>._disconnectí  s!   ø€ Ù‹iˆØˆ?Ø�M‰MÐ*Õ+ð r'   )r  r*   r)   r”   rÒ   )rÛ   ÚobserverH   Útraitsrk   r¦   )r#   r�   rø   r  r  s    ` @@r%   rË   rË   Ø  sS   ú€ ô   Ô$Øõ%ð ‡K�KÐ ¬¨S¯Z©Z¸T¨ZÓ-BÓ(C€KÔDä�k‰k˜#Ó€Gö,ð
 Ðr'   c                ót   — t         j                  j                  d«      }|�t        | |j                  «      S dS )z«Whether an object is an instance of pydantic.BaseModel.

    Returns
    -------
        `True` if the object is an instance of pydantic.BaseModel, `False` otherwise.
    ÚpydanticF)ré   rê   rë   r7   Ú	BaseModel)r#   r  s     r%   rÝ   rÝ   ø  s3   € ô �{‰{�‰˜zÓ*€HØ2:Ð2FŒ:�c˜8×-Ñ-Ó.ÐQÈEÐQr'   c                óL   — t        j                  | j                  |¬«      «      S )aS  Get the state of a pydantic BaseModel instance.

    To take advantage of pydantic's support for custom encoders (with json_encoders)
    we call obj.json() here, and then cast back to a dict (which is what
    the comm expects).

    Returns
    -------
    state : dict
        A dictionary copy of state from the pydantic BaseModel
    r¢   )ÚjsonÚloadsrØ   s     r%   rß   rß     s   € ô �:‰:�c—h‘h w�hÓ/Ó0Ð0r'   c                ó(   — | j                  d|¬«      S )z4Get the state of a pydantic (v2) BaseModel instance.r  )Úmoder$   )rÙ   rØ   s     r%   rÞ   rÞ     s   € ð
 �>‰>˜v¨wˆ>Ó7Ð7r'   c                ót   — t         j                  j                  d«      }|�t        | |j                  «      S dS )z<Return `True` if an object is an instance of msgspec.Struct.ÚmsgspecF)ré   rê   rë   r7   ÚStruct)r#   r  s     r%   rà   rà      s/   € ä�k‰k�o‰o˜iÓ(€GØ.5Ð.AŒ:�c˜7Ÿ>™>Ó*ÐLÀuÐLr'   c                óB   — ddl }t        d |j                  | «      «      S )z+Get the state of a msgspec.Struct instance.r   Nr*   )r  r   Úto_builtins)r#   r$   r  s      r%   rá   rá   &  s"   € ãô �Ð+˜×+Ñ+¨CÓ0Ó1Ð1r'   )r#   rM   r)   z
str | None)r#   r*   r)   r*   )rc   r*   rP   r8   r)   úcomm.base_comm.BaseComm)r#   rM   rn   zCallable[[], dict]r)   r  )r#   rM   r)   r8   )r#   rM   r)   r   )r#   rM   r[   r*   r)   r”   )r#   rM   r)   zCallable[[object, dict], None])r#   rM   r)   zpsygnal.SignalGroup | None)r#   rM   r�   r   r)   zCallable | None)r#   rM   r)   zTypeGuard[traitlets.HasTraits])r#   ztraitlets.HasTraitsr$   r(   r)   r.   )r#   rM   r)   zTypeGuard[pydantic.BaseModel])r#   zpydantic.BaseModelr$   r(   r)   r.   )r#   rM   r)   zTypeGuard[msgspec.Struct])r#   zmsgspec.Structr$   r(   r)   r.   )Kr•   Ú
__future__r   rh   r  ré   rŒ   rk   Údataclassesr   r   Útypingr   r   r   r	   Ú_file_contentsr   r   Ú_utilr   r   r   r   r   r   r   r   Ú_versionr   Úcollections.abcr   r   r   r   r   ra   r  rç   r  rú   Útyping_extensionsr   Ú
_protocolsr   r   r.   Ú__annotations__Ú__all__r:   rÚ   rå   rF   r>   rN   rd   re   rp   r/   r0   r¥   r«   rã   r¬   rñ   rÊ   rÛ   rþ   rÜ   rË   rÝ   rß   rÞ   rà   rá   r!   r'   r%   Ú<module>r#     sµ  ðòõ" #ã Û Û 
Û Û ß ,÷ó ÷ >÷	÷ 	ó 	õ 0áß<Ñ<ß+ãÛÛÛÛÝ*å'ôL�Hô Lð "€L�)Ó!à!Ð#3Ð
4€à €
Ø+Ð Ø+Ð Ø!Ð óó64ð( %ðØðàðð óð@ .0€Ð*Ó /ðØ	ðØ.ðàó÷.Fñ F÷Ro,ñ o,ój:ó
3ólóó(ó6ó6Tð Ð ð&Ø	ð&àð&ð ó&óó@Rð1Ø	ð1àð1ð ó1ð$8Ø	ð8àð8ð ó8óMô2r'   