o
    AD©i+  ã                   @   s¦   d dl mZ d dlZd dlZddlmZ ddlmZ dZe	eddd	„ ƒZ
G d
d„ deƒZeƒ Zdd„ Zdd„ Zdd„ Zdd„ Zi ZG dd„ deƒZG dd„ deƒZdS )é    )Úabsolute_importNé   )Úcached_property)Úinspect)ÚCallableÚiscoroutinefunctionc                 C   s   dS ©NF© )Úfr	   r	   úJ/var/www/Datamplify/venv/lib/python3.10/site-packages/wirerope/callable.pyÚ<lambda>   s    r   c                   @   s   e Zd ZdS )Ú_ReagentN)Ú__name__Ú
__module__Ú__qualname__r	   r	   r	   r   r      s    r   c                 C   s   | S ©Nr	   )Úownerr	   r	   r   Ú_f   s   r   c                 C   s   |d fS r   r	   ©Ú
descriptorÚobjÚtyper	   r	   r   Ú_name_binder   ó   r   c                 C   s   ||fS r   r	   r   r	   r	   r   Ú_type_binder   r   r   c                 C   s   ||fS r   r	   r   r	   r	   r   Ú_obj_binder"   r   r   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
Ú
Descriptorc                 C   s   || _ t|ƒ| _d S r   )r   r   Údescriptor_class)Úselfr   r	   r	   r   Ú__init__+   s   zDescriptor.__init__c              	   C   sX   t ƒ }|  |¡}t|ƒD ]}zt||ƒ}W n	 ty   Y qw ||u r'|  S qtdƒ‚)Nz_The given function doesn't hold the given function as an attribute. Is it a correct descriptor?)Úobjectr   ÚdirÚgetattrÚAttributeErrorÚRuntimeError)r   Ú	indicatorr   ÚnameÚattrr	   r	   r   Údetect_function_attr_name/   s   
ÿþÿz$Descriptor.detect_function_attr_namec                 C   s&   |   t¡}| ||¡}||u p||u S r   )r   r   Ú__get__)r   r   Útype_ÚdÚmethod_or_valuer	   r	   r   Údetect_property?   s   
zDescriptor.detect_propertyc                 C   sÄ   | j |d uf}|tvr\|   t¡}| ||¡}t|tjƒrt}n/||u r&t}n(||u r-t	}n!t
|ƒrE|ƒ }||u r;t	}n||u rBt}nd }n	||u rLt}nd }|d u rVtdƒ‚|t|< |S t| }|S )NzŠ'descriptor_bind' fails to auto-detect binding rule of the given descriptor. Specify the rule by 'wirerope.wire.descriptor_bind.register'.)r   Ú_descriptor_binder_cacher   r)   Ú
isinstanceÚtypesÚFunctionTyper   r   r   ÚcallableÚ	TypeError)r   r   r*   Úkeyr+   ÚmethodÚbinderr   r	   r	   r   Údetect_binderD   s8   
ÿÿzDescriptor.detect_binderN)r   r   r   r   r(   r-   r7   r	   r	   r	   r   r   )   s
    r   c                   @   sÂ   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZ	ed
d„ ƒZ
ejr+edd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZejrGedd„ ƒZnedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )r   z9A wrapper object including more information of callables.c                 C   sf   || _ t| ƒtju | _| jrt|ƒ| _t|| j 	¡ ƒ}nd | _|| _
t|dd ƒ| _| jp/t|ƒ| _d S )NÚ_is_coroutine)Úwrapped_objectr   r0   r1   Úis_function_typeÚis_descriptorr   r   r"   r(   Úwrapped_callableÚis_wrapped_coroutineÚ_inspect_iscoroutinefunctionÚis_coroutine)r   r
   r	   r	   r   r   k   s   
ÿzCallable.__init__c                 C   s   t  | j¡S r   )r   Ú	signaturer<   ©r   r	   r	   r   r@   x   s   zCallable.signaturec                 C   s   t | jj ¡ ƒS r   )Úlistr@   Ú
parametersÚvaluesrA   r	   r	   r   rC   |   ó   zCallable.parametersc                 C   s   | j r| j d S d S )Nr   )rC   rA   r	   r	   r   Úfirst_parameter€   ó   zCallable.first_parameterc                 C   sZ   | j s| jrdS | j tƒ ¡}ztjr|| ju W S t|ƒt| jƒu W S  ty,   Y dS w r   )	r:   Úis_builtin_propertyr9   r)   r    ÚsixÚPY2r   Ú	Exception)r   Ú	new_boundr	   r	   r   Úis_boundmethod„   s   ÿzCallable.is_boundmethodc                 C   s   t | jƒt tjƒu S r   )r   r9   r   r   rA   r	   r	   r   Úis_unboundmethod’   rG   zCallable.is_unboundmethodc                 C   s:   | j rdS t| jƒjtjju}tjr|o| jp| j  }|S r   )	rM   r   r9   r)   r0   r1   rI   rJ   rN   )r   r;   r	   r	   r   r;   –   s   
ÿÿzCallable.is_descriptorc                 C   s   t t| jƒtƒS r   )Ú
issubclassr   r9   ÚpropertyrA   r	   r	   r   rH   ¡   rE   zCallable.is_builtin_propertyc                 C   s   | j p| jo| j tt¡S r   )rH   r;   r   r-   Ú_reagentr   rA   r	   r	   r   Úis_property¥   s
   ÿÿzCallable.is_propertyc                 C   s(   | j }|j d¡d }||jkrdS dS )Nz	<locals>.éÿÿÿÿTF)r<   r   Úsplitr   )r   ÚccÚmethod_namer	   r	   r   Úis_barefunction¬   s
   
zCallable.is_barefunctionc                 C   s(   | j rdS tjr| jrdS | jp| j S r   )r;   rI   rJ   rN   Úis_membermethodÚis_classmethodrA   r	   r	   r   rW   ´   s   c                 C   s0   t jr| jrdS | jsdS | jduo| jjdkS )ú»Test given argument is a method or not.

        :rtype: bool

        :note: The test is partially based on the first parameter name.
            The test result might be wrong.
        FTNr   )rI   ÚPY34rW   r;   rF   r&   rA   r	   r	   r   Ú	is_member¾   s   	

ÿzCallable.is_memberc                 C   s   | j rdS | jr
dS | jS )rZ   F)rM   rR   r\   rA   r	   r	   r   rX   Ï   s
   	zCallable.is_membermethodc                 C   s@   t | jtƒrdS tjr| jrdS | jsdS | jduo| jjdkS )zÀTest given argument is a classmethod or not.

        :rtype: bool

        :note: The test is partially based on the first parameter name.
            The test result might be wrong.
        TFNÚcls)	r/   r9   ÚclassmethodrI   r[   rW   r;   rF   r&   rA   r	   r	   r   rY   Þ   s   	

ÿzCallable.is_classmethodN)r   r   r   Ú__doc__r   r   r@   rC   rP   rF   rM   rI   rJ   rN   r;   rH   rR   r[   rW   r\   rX   rY   r	   r	   r	   r   r   h   s>    









	

r   )Ú
__future__r   r0   rI   Ú_utilr   Ú_compatr   Ú__all__r"   r>   r    r   rQ   r   r   r   r   r.   r   r   r	   r	   r	   r   Ú<module>   s$    
ÿ?