
    j_:*                        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 d-dZ	d-dZ
d-dZd-dZd-d	Zd
 Zd Zd Zej        ej        z  dfdZddlZej        d         dk    s ej                    dk    re	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    rddZ"d.dZ#dZ$ddl%Z&ej'        Z'd/dZ(e)Z*d Z+d Z,ej-        Z-ej.        Z.d0dZ/ ej0        dej1                  Z2d Z3ed             Z4ed             Z5d Z6n]dZ"d.dZ#dZ$ddl7Z&ddlZ ej0        d           Z8d/d!Z(e*Z*d" Z+d# Z,ej9        Z-d$ Z.d% Z4d& Z6eZ'ed'             Z5ej        d(k    rd1d)Z/nd1d*Z/d+ Z:d, Z;dS )2z=Compatibility tricks for Python 3. Mainly to do with unicode.    N   )DEFAULT_ENCODINGc                     | S N )xencodings     :lib/python3.11/site-packages/ipython_genutils/py3compat.pyno_coder      s    H    c                 @    |pt           }|                     |d          S Nreplace)r   decodesr	   s     r
   r   r      !    ++H88Hi(((r   c                 @    |pt           }|                     |d          S r   )r   encode)ur	   s     r
   r   r      r   r   c                 P    t          | t                    rt          | |          S | S r   )
isinstancebytesr   r   s     r
   cast_unicoder      s)    !U #a"""Hr   c                 P    t          | t                    st          | |          S | S r   )r   r   r   r   s     r
   
cast_bytesr      s)    a #a"""Hr   c                     t          | t                    r|                                 S t          | t                    st          |           S | S )z+Cast a buffer or memoryview object to bytes)r   
memoryviewtobytesr   )bufs    r
   buffer_to_bytesr!   "   sE    #z"" {{}}c5!! SzzJr   c                 F     t          j                    fd            }|S )Nc                 z    t          | t                    rd }| }n	| }|j        } |          }|r	||_        |S |S r   )r   string_types__doc__)func_or_strfuncdocstr_change_funcs      r
   wrapperz)_modify_str_or_docstring.<locals>.wrapper+   sU    k<00 	DCCD,Coc"" 	DLK
r   )	functoolswraps)r)   r*   s   ` r
   _modify_str_or_docstringr-   *   s8    __%%    &% Nr   c                     	 t          |           S # t          $ r Y nw xY w	 t          t          |                     S # t          $ r Y nw xY w	 t          t	          |                     S # t          $ r Y nw xY wdS )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)es    r
   safe_unicoder5   <   s    A   c!ff%%%   d1gg&&&    +*s-    
> 
A
AA+ +
A87A8c                 f    d }t           j                                       r | |          r S dS |*t           j                            dt           j                  }|sdS |                    t           j                  }t          j	        dk    rt           j
        |vr |                    dt           j
                   t           j                            dd                              t           j                  }t           fd|D                       r g}n fd	|D             }n g}t                      }|D ]q}t           j                            |          }||vrL|                    |           |D ]4}	t           j                            ||	          }
 ||
|          r|
c c S 5rd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                     t           j                            |           o4t          j        | |          ot           j                            |            S r   )ospathexistsaccessisdir)fnmodes     r
   _access_checkz$_shutil_which.<locals>._access_check`   sD    r"" *ryT':': *b)))	+r   NPATHwin32r   PATHEXT c              3      K   | ]=}                                                     |                                           V  >d S r   )lowerendswith.0extcmds     r
   	<genexpr>z _shutil_which.<locals>.<genexpr>}   sA      DDSsyy{{##CIIKK00DDDDDDr   c                     g | ]}|z   S r   r   rG   s     r
   
<listcomp>z!_shutil_which.<locals>.<listcomp>   s    2223S3Y222r   )r8   r9   dirnameenvirongetdefpathsplitpathsepsysplatformcurdirinsertanysetnormcaseaddjoin)rJ   r>   r9   r?   pathextfilesseendirnormdirthefilenames   `          r
   _shutil_whichrd   R   s   + + + 
ws =d## 	Jt|z~~fbj11 t::bj!!D
|wyD  KK29%%% *..B//55bjAA
 DDDDGDDDDD 	3EEE2222'222EE 55D    '""3''$HHW     w||C11 =t,,  KKKKK 4r      
IronPythonTrC   c                 *    t          j        |           S r   )builtin_modinputprompts    r
   ri   ri      s     (((r   builtinsFc                     |r,t          d |                     d          D                       S |                                 S )Nc              3   4   K   | ]}t          |          V  d S r   isidentifierrH   as     r
   rK   zisidentifier.<locals>.<genexpr>   (      ==1|A======r   .)allrR   rp   r   dotteds     r
   rp   rp      sA     	>========~~r   c                 D    t          |                                           S r   )iteritemsds    r
   	iteritemsr}      s    T!''))__,r   c                 D    t          |                                           S r   )ry   valuesr{   s    r
   
itervaluesr      s    d188::...r   c                     ||n|}t          | d          5 }|pt          }t           ||                                | d          ||           d d d            d S # 1 swxY w Y   d S )Nrbexec)opencompiler   read)fnameglobloccompilerfs        r
   execfiler      s    occD% 	?!*7H!&&((E622D#>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   8AA #A z\bprint (?P<expr>.*)$c                 6    |                      d          }d|z  S )Nexprz	print(%s))groups)matchr   s     r
   _print_statement_subr      s    ||F##T!!r   c                 B    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(   s    r
   doctest_refactor_printr      s     #&&';SAAAr   c                 .    |                      d          S )zt"{u}'abc'" --> "'abc'" (Python 3)
        
        Accepts a string or a function, so it can be used as a decorator.rC   r   formatr   s    r
   u_formatr      s    
 xx"x~~r   c                     | j         S z"Get a function's closure attribute)__closure__r   s    r
   get_closurer      s
    }r   c                 *    t          j        |           S r   )rh   	raw_inputrj   s    r
   ri   ri      s    $V,,,r   __builtin__z[a-zA-Z_][a-zA-Z0-9_]*$c                     |r,t          d |                     d          D                       S t          t                              |                     S )Nc              3   4   K   | ]}t          |          V  d S r   ro   rq   s     r
   rK   zisidentifier.<locals>.<genexpr>   rs   r   rt   )ru   rR   bool_name_rer   rv   s     r
   rp   rp      sK     	>========HNN1%%&&&r   c                 *    |                                  S r   )r}   r{   s    r
   r}   r}      s    Q[[]]*r   c                 *    |                                  S r   )r   r{   s    r
   r   r      s    allnn,r   c                 H    t          j        | |t          |                    S r   )types
MethodTypetype)r'   instances     r
   r   r      s    hX???r   c                     | S r   r   )r&   s    r
   r   r      s    r   c                     | j         S r   )func_closurer   s    r
   r   r      s
    ~r   c                 .    |                      d          S )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   s    r
   r   r     s    
 xx#xr   rA   c                     ||n|}t          j        |                                           dz   }t          | t                    rt          |           }n| }|pt          }t           |||d          ||           d S )N
r   )rh   r   r   r   unicodeunicode_to_strr   r   )r   r   r   r   
scripttextfilenames         r
   r   r     s    /##C$)%005577=J %)) !)%00 *7H*h77sCCCCCr   c                 x   t          | t                    r'|                     t          j                              }n| }d ||fD             }|t          j        |g|R   d S t          j        |                                           	                                dz   }t           |||d          ||           d S )Nc                     g | ]}||S r   r   )rH   nss     r
   rM   zexecfile.<locals>.<listcomp>   s    @@@BRr   r   r   )r   r   r   rT   getfilesystemencodingrh   r   r   r   rstripr   )r   r   r   r   r   wherer   s          r
   r   r     s    %)) ! <<(A(C(CDD @@4+@@@E$X6666666(-e4499;;BBDDtK
XXj(F;;T3GGGGGr   c                  4      st          d           fd}|S )z5Python 3 compatible function annotation for Python 2.z1annotations must be provided as keyword argumentsc                     t          | d          r%                                D ]\  }}|| j        |<   n| _        | S )N__annotations__)hasattrrz   r   )r   kvkwargss      r
   deczannotate.<locals>.dec,  sU    1'(( 	' ) )1'(!!$$) !'Ar   )
ValueError)r   r   s   ` r
   annotater   (  s;     NLMMM     Jr   c                      | d|i           S )z%Create a base class with a metaclass._NewBaser   )metabasess     r
   with_metaclassr   K  s    4
E2&&&r   r   )rC   )F)NN)NNN)<r%   r+   r8   rT   reshutilr   r	   r   r   r   r   r   r   r!   r-   r5   F_OKX_OKrd   rU   version_infopython_implementationr1   r   str_to_bytesbytes_to_strcast_bytes_py2cast_unicode_py2buffer_to_bytes_py2r2   r$   r/   r   PY3ri   builtin_mod_namerl   rh   whichrp   rangexranger}   r   getcwdr   r   r   	MULTILINEr   r   r   r   r   r   r   getcwdur   r   r   r   r
   <module>r      s   C C     				 



 				   & & & & & &   ) ) ) )) ) ) )
   
   
    $+ + +, Gbg-D = = = =~ A!=x=??<OONNLLN!6LLLNNLLN#)>LLA!
C) ) ) ) """""LE       
 F,,,...YF!J? ? ? ? %"*%=r|LL" " " B B B      
 C- - - - %%%%%IIIrz455H' ' ' '
 F***,,,ZF@ @ @     E    |w
	D 
	D 
	D 
	D 
	D
	H 
	H 
	H 
	H  F' ' ' ' 'r   