o
    ȷe:*                     @   sZ  d Z ddl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 dBddZ	dBddZ
dBd	d
ZdBddZdBddZdd Zdd Zdd ZejejB dfddZddlZejd dksae dkrue	Ze	ZeZe
Ze	Ze	Ze	ZefZeZ ne
ZeZe	Ze	ZeZeZeZee!fZe!Z ejd dkrdZ"dCddZ#dZ$ddl%Z&ej'Z'dDdd Z(e)Z*d!d" Z+d#d$ Z,ej-Z-ej.Z.dEd%d&Z/e0d'ej1Z2d(d) Z3ed*d+ Z4ed,d- Z5d.d/ Z6nMdZ"dCd0dZ#d1Z$ddl7Z&ddlZe0d2Z8dDd3d Z(e*Z*d4d" Z+d5d$ Z,ej9Z-d6d7 Z.d8d+ Z4d9d/ Z6eZ'ed:d- Z5ejd;krdFd<d&Z/ndFd=d&Z/d>d? Z:d@dA Z;dS )Gz=Compatibility tricks for Python 3. Mainly to do with unicode.    N   )DEFAULT_ENCODINGc                 C      | S N )xencodingr   r   Q/var/www/ideatree/venv/lib/python3.10/site-packages/ipython_genutils/py3compat.pyno_code      r
   c                 C      |pt }| |dS Nreplace)r   decodesr   r   r   r	   r         r   c                 C   r   r   )r   encode)ur   r   r   r	   r      r   r   c                 C   s   t | tr
t| |S | S r   )
isinstancebytesr   r   r   r   r	   cast_unicode      

r   c                 C   s   t | ts
t| |S | S r   )r   r   r   r   r   r   r	   
cast_bytes   r   r   c                 C   s(   t | tr	|  S t | tst| S | S )z+Cast a buffer or memoryview object to bytes)r   
memoryviewtobytesr   )bufr   r   r	   buffer_to_bytes"   s
   

r   c                    s   t   fdd}|S )Nc                    s8   t | tr
d }| }n| }|j} |}|r||_|S |S r   )r   string_types__doc__)func_or_strfuncdocstr_change_funcr   r	   wrapper+   s   
z)_modify_str_or_docstring.<locals>.wrapper)	functoolswraps)r$   r%   r   r#   r	   _modify_str_or_docstring*   s   r(   c                 C   sd   zt | W S  ty   Y nw ztt| W S  ty   Y nw ztt| W S  ty1   Y dS w )zlunicode(e) with various fallbacks. Used for exceptions, which may not be
    safe to call unicode() on.
    zUnrecoverably corrupt evalue)unicode_typeUnicodeErrorstr_to_unicodestrrepr)er   r   r	   safe_unicode<   s    
r/   c                    s"  dd }t j r| |r S dS |du rt jdt j}|s#dS |t j}tj	dkr^t j
|vr:|dt j
 t jddt j}t fd	d
|D rT g}n fdd|D }n g}t }|D ](}t j|}||vr|| |D ]}	t j||	}
||
|r|
    S qyqfdS )an  Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.

    `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
    of os.environ.get("PATH"), or can be overridden with a custom search
    path.
    
    This is a backport of shutil.which from Python 3.4
    c                 S   s&   t j| ot | |ot j|  S r   )ospathexistsaccessisdir)fnmoder   r   r	   _access_check`   s   z$_shutil_which.<locals>._access_checkNPATHwin32r   PATHEXT c                 3   s"    | ]}   |  V  qd S r   )lowerendswith.0extcmdr   r	   	<genexpr>}   s     z _shutil_which.<locals>.<genexpr>c                    s   g | ]} | qS r   r   r>   rA   r   r	   
<listcomp>   s    z!_shutil_which.<locals>.<listcomp>)r0   r1   dirnameenvirongetdefpathsplitpathsepsysplatformcurdirinsertanysetnormcaseaddjoin)rB   r6   r1   r7   pathextfilesseendirnormdirthefilenamer   rA   r	   _shutil_whichR   s<   




r[      
IronPythonTr;   c                 C   
   t | S r   )builtin_modinputpromptr   r   r	   r`         
r`   builtinsFc                 C   s$   |rt dd | dD S |  S )Nc                 s       | ]}t |V  qd S r   isidentifierr?   ar   r   r	   rC          isidentifier.<locals>.<genexpr>.)allrI   rg   r   dottedr   r   r	   rg      s   rg   c                 C      t |  S r   )iteritemsdr   r   r	   	iteritems       ru   c                 C   rp   r   )rq   valuesrs   r   r   r	   
itervalues   rv   rx   c                 C   s`   |d ur|n|}t | d}|pt}t|| | d|| W d    d S 1 s)w   Y  d S )Nrbexec)opencompilerz   read)fnameglobloccompilerfr   r   r	   execfile   s
   "r   z\bprint (?P<expr>.*)$c                 C   s   |  d}d| S )Nexprz	print(%s))groups)matchr   r   r   r	   _print_statement_sub   s   
r   c                 C   s   t t| S )zRefactor 'print x' statements in a doctest to print(x) style. 2to3
        unfortunately doesn't pick up on our doctests.
        
        Can accept a string or a function, so it can be used as a decorator.)_print_statement_resubr   )r"   r   r   r	   doctest_refactor_print   s   r   c                 C      | j ddS )zt"{u}'abc'" --> "'abc'" (Python 3)
        
        Accepts a string or a function, so it can be used as a decorator.r;   r   formatr   r   r   r	   u_format      r   c                 C      | j S z"Get a function's closure attribute)__closure__r   r   r   r	   get_closure      r   c                 C   r^   r   )r_   	raw_inputra   r   r   r	   r`      rc   __builtin__z[a-zA-Z_][a-zA-Z0-9_]*$c                 C   s*   |rt dd | dD S tt| S )Nc                 s   re   r   rf   rh   r   r   r	   rC      rj   rk   rl   )rm   rI   bool_name_rer   rn   r   r   r	   rg      s   c                 C      |   S r   )ru   rs   r   r   r	   ru          c                 C   r   r   )rx   rs   r   r   r	   rx      r   c                 C   s   t | |t|S r   )types
MethodTypetype)r!   instancer   r   r	   r      s   r   c                 C   r   r   r   )r    r   r   r	   r      r   c                 C   r   r   )func_closurer   r   r   r	   r      r   c                 C   r   )zu"{u}'abc'" --> "u'abc'" (Python 2)
        
        Accepts a string or a function, so it can be used as a decorator.r   r   r   r   r   r   r	   r     r   r9   c                 C   sZ   |d ur|n|}t |  d }t| trt| }n| }|p t}t|||d|| d S )N
rz   )r_   r{   r}   r   unicodeunicode_to_strr|   rz   )r~   r   r   r   
scripttextfilenamer   r   r	   r     s   

c                 C   s|   t | tr| t }n| }dd ||fD }|d u r'tj|g|R   d S t|  	 d }t
|||d|| d S )Nc                 S   s   g | ]}|d ur|qS r   r   )r?   nsr   r   r	   rD      s    zexecfile.<locals>.<listcomp>r   rz   )r   r   r   rK   getfilesystemencodingr_   r   r{   r}   rstriprz   )r~   r   r   r   r   wherer   r   r   r	   r     s   
c                     s    st d fdd}|S )z5Python 3 compatible function annotation for Python 2.z1annotations must be provided as keyword argumentsc                    s4   t | dr  D ]	\}}|| j|< q	| S  | _| S )N__annotations__)hasattrrr   r   )r   kvkwargsr   r	   dec,  s   
zannotate.<locals>.dec)
ValueError)r   r   r   r   r	   annotate(  s   r   c                 G   s   | d|i S )z%Create a base class with a metaclass._NewBaser   )metabasesr   r   r	   with_metaclassK  s   r   r   )r;   )F)NN)NNN)<r   r&   r0   rK   reshutilr   r   r   r
   r   r   r   r   r   r(   r/   F_OKX_OKr[   rL   version_infopython_implementationr+   r   str_to_bytesbytes_to_strcast_bytes_py2cast_unicode_py2buffer_to_bytes_py2r,   r   r)   r   PY3r`   builtin_mod_namerd   r_   whichrg   rangexrangeru   rx   getcwdr   r   r|   	MULTILINEr   r   r   r   r   r   r   getcwdur   r   r   r   r   r	   <module>   s   




?










#