§
    ¹³Ùg  ã            	       ó”   — d Z ddlZddlZddlZddlmZmZ dhZddhZ G d„ d¦  «        Z	 G d	„ d
¦  «        Z
dddœdedededefd„ZdS )zETools useful for creating decorators, and other high-level callables.é    N)ÚTypeÚCallableÚ__new__Ú__init_subclass__Ú__prepare__c                   ó2   ‡ — e Zd ZdZdZˆ fd„Zd„ Zd„ Zˆ xZS )Ú_lift_to_methodaa  A decorator that ensures that an input callable object implements ``__get__``.  It is
    returned unchanged if so, otherwise it is turned into the default implementation for functions,
    which makes them bindable to instances.

    Python-space functions and lambdas already have this behavior, but builtins like ``print``
    don't; using this class allows us to do::

        wrap_method(MyClass, "maybe_mutates_arguments", before=print, after=print)

    to simply print all the arguments on entry and exit of the function, which otherwise wouldn't be
    valid, since ``print`` isn't a descriptor.
    ©Ú_methodc                 ój   •— t          |d¦  «        r|S t          ¦   «                              | ¦  «        S )NÚ__get__)ÚhasattrÚsuperr   )ÚclsÚmethodÚ	__class__s     €úM/granary/edev/quantum/lib/python3.11/site-packages/qiskit/utils/classtools.pyr   z_lift_to_method.__new__-   s0   ø€ Ý�6˜9Ñ%Ô%ð 	ØˆMÝ‰wŒw�Š˜sÑ#Ô#Ð#ó    c                 ó    — || u rd S || _         d S ©Nr
   )Úselfr   s     r   Ú__init__z_lift_to_method.__init__2   s   € Ø�Tˆ>ˆ>àˆFØˆŒˆˆr   c                 óH   — |€| j         S t          j        | j         |¦  «        S r   )r   ÚtypesÚ
MethodType)r   ÚobjÚobjtypes      r   r   z_lift_to_method.__get__8   s&   € ð ˆ;Ø”<ÐÝÔ ¤¨cÑ2Ô2Ð2r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   Ú__classcell__)r   s   @r   r	   r	      sg   ø€ € € € € ðð ð €Ið$ð $ð $ð $ð $ð
ð ð ð3ð 3ð 3ð 3ð 3ð 3ð 3r   r	   c                   ó&   — e Zd ZdZdZdd„Zdd„ZdS )Ú_WrappedMethoda€  Descriptor which calls its two arguments in succession, correctly handling instance- and
    class-method calls.

    It is intended that this class will replace the attribute that ``inner`` previously was on a
    class or instance.  When accessed as that attribute, this descriptor will behave it is the same
    function call, but with the ``function`` called before or after.
    )Ú_method_decoratorÚ_method_has_getr   Ú_beforeÚ_afterNc                 ó¾  — t          |t          t          f¦  «        rt          |¦  «        | _        n€t          |t          | ¦  «        ¦  «        r|j        | _        nVt          |dd ¦  «        t          v rt          | _        n1t          |dd ¦  «        t          v rt          | _        nt          | _        |�|                      |¦  «        fnd}|�|                      |¦  «        fnd}t          |t          | ¦  «        ¦  «        r+|j	        | _	        ||j
        z   | _
        |j        |z   | _        n|| _
        || _        || _	        t          | j	        d¦  «        | _        d S )Nr   © r   )Ú
isinstanceÚclassmethodÚstaticmethodÚtyper&   ÚgetattrÚ_MAGIC_STATICMETHODSÚ_MAGIC_CLASSMETHODSr	   r   r(   r)   r   r'   )r   r   ÚbeforeÚafters       r   r   z_WrappedMethod.__init__L   sN  € Ý�f�{­LÐ9Ñ:Ô:ð 		5Ý%)¨&¡\¤\ˆDÔ"Ð"Ý˜¥ T¡
¤
Ñ+Ô+ð 	5Ø%+Ô%=ˆDÔ"Ð"Ý�V˜Z¨Ñ.Ô.Õ2FÐFÐFÝ%1ˆDÔ"Ð"Ý�V˜Z¨Ñ.Ô.Õ2EÐEÐEÝ%0ˆDÔ"Ð"å%4ˆDÔ"Ø6<Ð6H�$×(Ò(¨Ñ0Ô0Ð2Ð2ÈbˆØ49Ð4E�×'Ò'¨Ñ.Ô.Ð0Ð0È2ˆÝ�f�d 4™jœjÑ)Ô)ð 	"Ø!œ>ˆDŒLØ! F¤NÑ2ˆDŒLØ œ-¨%Ñ/ˆDŒKˆKà!ˆDŒLØˆDŒKØ!ˆDŒLõ  ' t¤|°YÑ?Ô?ˆÔÐÐr   c                 ó¤   ‡ ‡‡‡— ‰ j         r‰ j                             ‰‰¦  «        n‰ j        Št          j        ‰¦  «        ˆˆˆˆ fd„¦   «         }|S )Nc                  ó°   •— ‰j         D ]} |                     ‰‰¦  «        | i |¤Ž Œ ‰| i |¤Ž}‰j        D ]} |                     ‰‰¦  «        | i |¤Ž Œ|S r   )r(   r   r)   )ÚargsÚkwargsÚcallbackÚretvalr   r   r   r   s       €€€€r   Úoutz#_WrappedMethod.__get__.<locals>.outl   s’   ø€ à œLð @ð @�Ø.�× Ò   gÑ.Ô.°Ð?¸Ð?Ð?Ð?Ð?Ø�V˜TÐ, VÐ,Ð,ˆFØ œKð @ð @�Ø.�× Ò   gÑ.Ô.°Ð?¸Ð?Ð?Ð?Ð?ØˆMr   )r'   r   r   Ú	functoolsÚwraps)r   r   r   r;   r   s   ``` @r   r   z_WrappedMethod.__get__f   st   øøøø€ ð 8<Ô7KÐ]�”×%Ò% c¨7Ñ3Ô3Ð3ÐQUÔQ]ˆå	Œ˜Ñ	 Ô	 ð	ð 	ð 	ð 	ð 	ð 	ð 	ñ 
!Ô	 ð	ð ˆ
r   )NNr   )r   r   r    r!   r"   r   r   r+   r   r   r%   r%   A   sR   € € € € € ðð ð Y€Ið@ð @ð @ð @ð4ð ð ð ð ð r   r%   )r3   r4   r   Únamer3   r4   c          	      óp   — t          j        | |¦  «        }t          | |t          |||¦  «        ¦  «         dS )aË  Wrap the functionality the instance- or class method ``cls.name`` with additional behavior
    ``before`` and ``after``.

    This mutates ``cls``, replacing the attribute ``name`` with the new functionality.  This is
    useful when creating class decorators.  The method is allowed to be defined on any parent class
    instead.

    If either ``before`` or ``after`` are given, they should be callables with a compatible
    signature to the method referred to.  They will be called immediately before or after the method
    as appropriate, and any return value will be ignored.

    Args:
        cls: the class to modify.
        name: the name of the method on the class to wrap.
        before: a callable that should be called before the method that is being wrapped.
        after: a callable that should be called after the method that is being wrapped.

    Raises:
        ValueError: if the named method is not defined on the class or any parent class.
    N)ÚinspectÚgetattr_staticÚsetattrr%   )r   r>   r3   r4   r   s        r   Úwrap_methodrC   x   s:   € õ2 Ô# C¨Ñ.Ô.€FÝˆC�•~ f¨f°eÑ<Ô<Ñ=Ô=Ð=Ð=Ð=r   )r!   r<   r@   r   Útypingr   r   r1   r2   r	   r%   ÚstrrC   r+   r   r   ú<module>rF      sø   ðð LÐ Kà Ð Ð Ð Ø €€€Ø €€€Ø !Ð !Ð !Ð !Ð !Ð !Ð !Ð !ð "�{Ð Ø*¨MÐ:Ð ð!3ð !3ð !3ð !3ð !3ñ !3ô !3ð !3ðH4ð 4ð 4ð 4ð 4ñ 4ô 4ð 4ðn =AÐTXð >ð >ð >�Tð > ð >°ð >Èð >ð >ð >ð >ð >ð >r   