a
    xd                     @   s   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mZm	Z	 dd Z
dd Zdd	 Zd
d Zdd Zdd ZG dd de	ZG dd dedZdej_ej`eje dS )    )wrapspartialN)async_wrapsFinalc                 C   s   t | tjrt| } | S N)
isinstancepathlibPath)value r   B/var/www/html/Ranjet/env/lib/python3.9/site-packages/trio/_path.pyrewrap_path   s    r   c                    s   t | fdd}|S )Nc                    s"   t | j }||i |}t|S r   )getattr_wrappedr   )selfargskwargsattrr
   	attr_namer   r   wrapper   s    z!_forward_factory.<locals>.wrapper)r   )clsr   r   r   r   r   r   _forward_factory   s    r   c                    s&   t  t f fdd	}|S )Nc                    s6   |u r | j S t|r"|j } | j |}t|S r   )r   r   r   )r   otherr
   r   r   sentinelr   r   r       s    

z_forward_magic.<locals>.wrapper)objectr   )r   r   r   r   r   r   _forward_magic   s    r   c                    s   t | | j  fdd}|S )Nc                    sJ   t | j}t|g|R i | tj fddI d H }dd |D S )Nc                      s
   t   S r   )listr   funcr   r   <lambda>3       z7iter_wrapper_factory.<locals>.wrapper.<locals>.<lambda>c                 s   s   | ]}t |V  qd S r   )r   ).0itemr   r   r   	<genexpr>4   r"   z8iter_wrapper_factory.<locals>.wrapper.<locals>.<genexpr>)r   r   r   trio	to_threadrun_sync)r   r   r   methitems	meth_namer   r   r   -   s    z%iter_wrapper_factory.<locals>.wrapperr   _wrapsr   r,   r   r   r+   r   iter_wrapper_factory,   s    r0   c                    s   t | | j  fdd}|S )Nc                    s<   t | j }t|g|R i |}tj|I d H }t|S r   )r   r   r   r&   r'   r(   r   )r   r   r   r)   r    r
   r+   r   r   r   :   s    z'thread_wrapper_factory.<locals>.wrapperr-   r/   r   r+   r   thread_wrapper_factory9   s    r1   c                    s"   t t| | j  fdd}|S )Nc                    s<   t | j }t|g|R i |}tj|I d H }t|S r   )r   r.   r   r&   r'   r(   r   )r   r   r   r)   r    r
   r+   r   r   r   E   s    z,classmethod_wrapper_factory.<locals>.wrapper)classmethodr   r.   r/   r   r+   r   classmethod_wrapper_factoryD   s    r3   c                       s<   e Zd Z fddZdd Zdd Zdd Zd	d
 Z  ZS )AsyncAutoWrapperTypec                    sZ   t  ||| g | _t| | | t| | | t| | | t| | | d S r   )super__init___forwardtypegenerate_forwardsgenerate_wrapsgenerate_magicgenerate_iter)r   namebasesattrs	__class__r   r   r6   Q   s    zAsyncAutoWrapperType.__init__c                 C   sz   | j j D ]h\}}|ds||v r(qt|tr@| j| qt|tj	rft
| ||}t| || qt|t|qd S N_)	_forwards__dict__r*   
startswithr   propertyr7   appendtypesFunctionTyper   setattr	TypeErrorr8   r   r?   r   r   r   r   r   r   r9   Z   s    
z&AsyncAutoWrapperType.generate_forwardsc                 C   s   | j j D ]p\}}|ds||v r(qt|trJt| |}t| || qt|tj	rnt
| |}t| || qt|t|qd S rB   )r.   rE   r*   rF   r   r2   r3   rK   rI   rJ   r1   rL   r8   rM   r   r   r   r:   h   s    


z#AsyncAutoWrapperType.generate_wrapsc                 C   s2   | j D ]&}t| j|}t | |}t| || qd S r   )r   r   rD   rK   rM   r   r   r   r;   w   s    

z#AsyncAutoWrapperType.generate_magicc                 C   s:   | j j D ](\}}|| jv rt| |}t| || qd S r   )r.   rE   r*   
_wrap_iterr0   rK   rM   r   r   r   r<   ~   s    

z"AsyncAutoWrapperType.generate_iter)	__name__
__module____qualname__r6   r9   r:   r;   r<   __classcell__r   r   r@   r   r4   P   s
   	r4   c                       sp   e Zd ZdZejZejZg dZ	g dZ
dd Zdd Z fdd	Zd
d Zdd Zeejjdd Z  ZS )r	   zlA :class:`pathlib.Path` wrapper that executes blocking methods in
    :meth:`trio.to_thread.run_sync`.

    )
__str__	__bytes____truediv____rtruediv____eq____lt____le____gt____ge____hash__)globrglobiterdirc                 G   s   t j| | _d S r   )r   r	   r   )r   r   r   r   r   r6      s    zPath.__init__c                 C   s*   || j v rt| j|}t|S t|d S r   )r7   r   r   r   AttributeError)r   r=   r
   r   r   r   __getattr__   s    
zPath.__getattr__c                    s   t   | j S r   )r5   __dir__r7   r   r@   r   r   rb      s    zPath.__dir__c                 C   s   d tt| S )Nztrio.Path({}))formatreprstrrc   r   r   r   __repr__   s    zPath.__repr__c                 C   s   t | jS r   )osfspathr   rc   r   r   r   
__fspath__   s    zPath.__fspath__c                    s6   t | jjg|R i |}tj|I dH }t|S )zfOpen the file pointed to by the path, like the :func:`trio.open_file`
        function does.

        N)r   r   openr&   r'   r(   Z	wrap_file)r   r   r   r    r
   r   r   r   rk      s    z	Path.open)rO   rP   rQ   __doc__r   r	   r.   PurePathrD   r   rN   r6   ra   rb   rg   rj   r   rk   rR   r   r   r@   r   r	      s   
r	   )	metaclassa  
    Like :meth:`pathlib.Path.iterdir`, but async.

    This is an async method that returns a synchronous iterator, so you
    use it like::

       for subpath in await mypath.iterdir():
           ...

    Note that it actually loads the whole directory list into memory
    immediately, during the initial call. (See `issue #501
    <https://github.com/python-trio/trio/issues/501>`__ for discussion.)

)	functoolsr   r   rh   rI   r   r&   Z
trio._utilr   r   r   r   r   r0   r1   r3   r4   r	   r_   rl   absolutePathLikeregisterr   r   r   r   <module>   s    
64