o
    ADi                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ dZG dd	 d	e	Z
G d
d de	ZG dd de	ZG dd de	ZG dd de	ZG dd de	ZdS )z:mod:`wirerope.rope` --- Wire access dispatcher for descriptor type.
=======================================================================
    N   )Callable)descriptor_bind)	functools)WireRopeRopeCorec                       s,   e Zd ZdZ fddZedd Z  ZS )r   zThe base rope object.

    To change rope behavior, create a subclass or compatible class
    and pass it to `core_class` argument of :class wirerope.rope.WireRope`.
    c                    s   t t|   || _|| _d S N)superr   __init__callablerope)selfr   r   	__class__ F/var/www/Datamplify/venv/lib/python3.10/site-packages/wirerope/rope.pyr
      s   
zRopeCore.__init__c                 C   s   | j jS r   )r   
wire_class)r   r   r   r   r      s   zRopeCore.wire_class)__name__
__module____qualname____doc__r
   propertyr   __classcell__r   r   r   r   r      s
    r   c                       .   e Zd Z fddZdd ZdddZ  ZS )	MethodRopeMixinc                    &   t t| j|i | | jjrJ d S r   )r	   r   r
   r   is_barefunctionr   argskwargsr   r   r   r
         zMethodRopeMixin.__init__c                 C      d d|j|g| _d S N|__wirejoinr   	wire_namer   ownernamer   r   r   __set_name__#      zMethodRopeMixin.__set_name__Nc           
      C   s   | j }|j}t|||\}}|d u r|d ur|n|}t| dr)| j}|j|}nd|jjg}	||u r;|		d|jf d
|	}t||d }|d u rY| | |||f}t||| t |js`J |S Nr'   __wire__ )r   wrapped_objectr   hasattrr'   __dict__getwrapped_callabler   extendr&   getattrr   setattr__func__
r   objtypecwcor)   r/   r'   wirewire_name_partsr   r   r   __get__'   s$   

zMethodRopeMixin.__get__r   r   r   r   r
   r+   rA   r   r   r   r   r   r          r   c                       r   )	PropertyRopeMixinc                    r   r   )r	   rD   r
   r   r   r   r   r   r   r
   A   r    zPropertyRopeMixin.__init__c                 C   r!   r"   r%   r(   r   r   r   r+   E   r,   zPropertyRopeMixin.__set_name__Nc           
      C   s   | j }|j}t|||\}}|d u r|d ur|n|}t| dr)| j}|j|}nd|jjg}	||u r;|		d|jf d
|	}t||d }|d u rY| | |||f}t||| | S r-   )r   r1   r   r2   r'   r3   r4   r5   r   r6   r&   r7   r   r8   _on_propertyr:   r   r   r   rA   I   s"   

zPropertyRopeMixin.__get__r   rB   r   r   r   r   rD   ?   rC   rD   c                       $   e Zd Z fddZdd Z  ZS )FunctionRopeMixinc                    s>   t t| j|i | | jjs| jjsJ | | d d | _d S r   )r	   rG   r
   r   r   is_boundmethodr   _wirer   r   r   r   r
   b   s   zFunctionRopeMixin.__init__c                 C   s,   z|  |W S  ty   Y nw t| j|S r   )__getattribute__AttributeErrorr7   rI   )r   r*   r   r   r   __getattr__g   s   zFunctionRopeMixin.__getattr__)r   r   r   r
   rL   r   r   r   r   r   rG   `   s    rG   c                       rF   )CallableRopeMixinc                    s.   t t| j|i | t| jj| | _d S r   )r	   rM   r
   r   wrapsr   r1   __call__r   r   r   r   r
   q   s   zCallableRopeMixin.__init__c                 O   s   | j |i |S r   )rI   r   r   r   r   rO   u   s   zCallableRopeMixin.__call__)r   r   r   r
   rO   r   r   r   r   r   rM   o   s    rM   c                   @   s(   e Zd ZdZeddfddZdd ZdS )r   a  The end-user wrapper for callables.

    Any callable can be wrapped by this class regardless of its concept -
    free function, method, property or even more weird one.
    The calling type is decided by each call and redirected to proper
    RopeMixin.

    The rope will detect method or property owner by needs. It also will return
    or call their associated `wirerope.wire.Wire` object - which are the user
    defined behavior.
    FNc                 C   s|   || _ tdt|fi | _tdt|fi | _tdt|fi | _tdtt|fi | _	| | j| j| j| j	fD ]}||_
||_q3d S )N_MethodRope_PropertyRope_FunctionRope_CallableFunctionRope)r   r<   r   method_roperD   property_roperG   function_roperM   callable_function_rope_wrapped_args)r   r   
core_classrN   	rope_argsr   r   r   r   r
      s(   




zWireRope.__init__c                 C   s   t |}|js
|jr-| j}| jj}tjr|jdkr| j	}nt
|jdks)|jt
kr,| j	}n
|jr4| j}n| j}||| d}|jrHt|j|}|S )zWrap a function/method definition.

        :return: Rope object. The return type is up to given callable is
                 function, method or property.
        ztype.__call__zmethod-wrapper)r   )r   r   rH   rW   r   rO   sixPY3r   rV   r<   r   im_classis_propertyrU   rT   rX   r   rN   r5   )r   functionr=   
rope_classwire_class_callr   r   r   r   rO      s&   

zWireRope.__call__)r   r   r   r   r   r
   rO   r   r   r   r   r   y   s    
r   )r   r\   r   r   r?   r   _compatr   __all__objectr   r   rD   rG   rM   r   r   r   r   r   <module>   s    "!
