
    Dg6                         d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlm	Z	 e
Z	 d dlZd dlmZ n# e$ r d ZdZY nw xY w G d de          Zddej        d fd	Zd
 Zd Zd ZddZd ZddZddZdS )    )
generators)bisect_rightN)
ModuleType)PyCF_ONLY_ASTc                       e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
ddZddZddZddZddZddZd Zddej        ddfdZdS )SourcezY a immutable object holding a source code fragment,
        possibly deindenting it.
    r   c                 Z   g x| _         }|                    dd          }|                    dd          }|D ]}|sg }t          |t                    r|j         }nt          |t          t
          f          rd |D             }nt          |t          j        j                  rK|	                    d          }|r3|r1|d         
                                rn|                                 |1nt          ||          j         }|rt          |          }|                    |           d S )NdeindentTrstripc                 8    g | ]}|                     d           S 
r   .0xs     D/var/www/sysmax/venv/lib/python3.11/site-packages/py/_code/source.py
<listcomp>z#Source.__init__.<locals>.<listcomp>!   s"    :::QXXd^^:::    r   )r
   )linesget
isinstancer   tuplelistpybuiltin_basestringsplitstrippop	getsourcer
   extend)selfpartskwargsr   der   part	partliness           r   __init__zSource.__init__   sL   
UZZ
D))Hd++ 	$ 	$D 	$'' ? J		D5$-00 
?::T:::		D"*"899 ? JJt,,	 (# ($R=..00 "!! $ (
 &dR888>	 0$Y//	LL####%	$ 	$r   c                     	 | j         |j         k    S # t          $ r. t          |t                    rt          |           |k    cY S Y dS w xY w)NF)r   AttributeErrorr   str)r$   others     r   __eq__zSource.__eq__/   sa    	:,, 	 	 	%%% *4yyE))))55	s    2A
	A
c                     t          |t                    r| j        |         S |j        dvrt	          d          |                     |j        |j                  S )N)N   z!cannot slice a Source with a step)r   intr   step
IndexError__getslice__startstop)r$   keys     r   __getitem__zSource.__getitem__7   sV    c3 	::c?"xy(( !DEEE$$SY999r   c                 *    t          | j                  S N)lenr   r$   s    r   __len__zSource.__len__?   s    4:r   c                 J    t                      }| j        ||         |_        |S r;   r   r   )r$   r6   end	newsources       r   r5   zSource.__getslice__B   s#    HH	*U3Y/	r   c                    dt          |           }}||k     rI| j        |                                         s*|dz  }||k     r| j        |                                         *||k    rO| j        |dz
                                           s-|dz  }||k    r"| j        |dz
                                           -t                      }| j        ||         |j        dd<   |S )z] return new source object with trailing
            and leading blank lines removed.
        r   r1   N)r<   r   r    r   )r$   r6   rA   sources       r   r    zSource.stripG   s     D		sckk$*U"3"9"9";";kQJE ckk$*U"3"9"9";";kEkk$*SU"3"9"9";";k1HC Ekk$*SU"3"9"9";";k*U3Y/QQQr        c                     t          |          }t          |          }t                      }fd| j        D             }|j        |z   |j        z   |_        |S )ze return a copy of the source object with
            'before' and 'after' wrapped around it.
        c                     g | ]}|z   S  rI   r   lineindents     r   r   z$Source.putaround.<locals>.<listcomp>[   s    999d6D=999r   r@   )r$   beforeafterrL   rB   r   s      `  r   	putaroundzSource.putaroundT   sZ     uHH	9999dj999 ,.%+=	r   c                 T    t                      }fd| j        D             |_        |S )zl return a copy of the source object with
            all lines indented by the given indent-string.
        c                     g | ]}|z   S rI   rI   rJ   s     r   r   z!Source.indent.<locals>.<listcomp>d   s    @@@TF4K@@@r   r@   )r$   rL   rB   s    ` r   rL   zSource.indent_   s1     HH	@@@@TZ@@@	r   Fc                 H    |                      ||          \  }}| ||         S )zc return Source statement which contains the
            given linenumber (counted from 0).
        )getstatementrange)r$   lineno	assertionr6   rA   s        r   getstatementzSource.getstatementg   s+     ++FI>>
sE#Ir   c                     d|cxk    rt          |           k     sn t          d          t          ||           \  }}}||fS )z{ return (start, end) tuple which spans the minimal
            statement region which containing the given lineno.
        r   zlineno out of range)r<   r4   getstatementrange_ast)r$   rT   rU   astr6   rA   s         r   rS   zSource.getstatementrangen   sW     V''''c$ii''''2333/==UCczr   Nc                 `    t                      }t          | j        |          |j        dd<   |S )a:   return a new source object deindented by offset.
            If offset is None then guess an indentation offset from
            the first non-blank line.  Subsequent lines which have a
            lower indentation offset will be copied verbatim as
            they are assumed to be part of multilines.
        N)r   r
   r   )r$   offsetrB   s      r   r
   zSource.deindentw   s/     HH	%dj&99	r   Tc                     	 ddl }|j        }n# t          $ r d }Y nw xY w|r"t          |                                           }nt          |           }	  ||dz              dS # t
          $ r  t          $ r Y dS w xY w)zb return True if source is parseable, heuristically
            deindenting it by default.
        r   Nc                 $    t          | dd          S )Nasdexec)compile)r   s    r   <lambda>z$Source.isparseable.<locals>.<lambda>   s    wq%'@'@ r   r   TF)parsersuiteImportErrorr-   r
   KeyboardInterrupt	Exception)r$   r
   rb   syntax_checkerrD   s        r   isparseablezSource.isparseable   s    	*MMM $\NN  	A 	A 	A@@NNN	A
  	))FFYYF	N6$;''' 4 ! 	 	 	 	 	 	55	s    A% %A=<A=c                 6    d                     | j                  S )Nr   )joinr   r=   s    r   __str__zSource.__str__   s    yy$$$r   r_   c                 r   |r3t           j                            |                              d          r`|t	          j        d          }|j        j        |j        }}d| j	        z  }| j
        xj	        dz  c_	        |s|d||fz  z   }n|d|||fz  z   }d                    | j                  dz   }		 t          |	|||          }
|t          z  r|
S d	 | j        D             }ddl}dd||f|j        |<   |
S # t"          $ r t	          j                    d         }| j        d|j                 }|j        r |                    d
|j        z  dz              |                    d|z             t#          d                    |                    }|j        |_        |j        |_        |j        |_        |w xY w)z return compiled code object. if filename is None
            invent an artificial filename which displays
            the source/line position of the caller frame.
        r   )fileNr1   z<%d-codegen z%s:%d>z	%r %s:%d>r   c                     g | ]}|d z   S r   rI   r   s     r   r   z"Source.compile.<locals>.<listcomp>   s    444Aa$h444r    ^z*(code was compiled probably from here: %s))r   pathlocalchecksys	_getframef_codeco_filenamef_lineno_compilecounter	__class__rj   r   cpy_compile	_AST_FLAG	linecachecacheSyntaxErrorexc_inforT   r[   appendtext)r$   filenamemodeflagdont_inherit	_genframefnrT   baserD   cor   r}   exmsglinesnewexs                   r   r`   zSource.compile   s     		G27==2288a8@@ 		G M!,,	!(4i6HvB!D$88DN**a/** G(b&\"99+2v0F"FF4:&&-	VXtT::B i 	44444E)*D%(BIOH%I%  	 	 	"Bz*29*-Hy 5BI 3444OOH8STTT		( 3 344E9EL9ELEJK	s   4C7 7B?F6)rE   rE   rF   )rF   Fr;   )T)__name__
__module____qualname____doc__ry   r*   r/   r9   r>   r5   r    rO   rL   rV   rS   r
   rh   rk   r   compiler_flagr`   rI   r   r   r   r      s,         O$ $ $0  : : :    
  	 	 	 	               2% % %  $&-$& & & & & &r   r   r_   c                     t           -t          | t           j                  rt          | ||||          S t	          j        d          }t          |           }|                    ||||          }|S )z compile the given source to a raw code object,
        and maintain an internal cache which allows later
        retrieval of the source code for the code object
        and any recursively created code objects.
    Nr1   )r   )_astr   ASTr{   rt   ru   r   r`   )rD   r   r   flagsr   r   sr   s           r   compile_r      si     Jvtx8868T5,GGGa  IvA	
8T5I	>	>BIr   c                    	 t           j                            |           }|j        }|j        }n# t
          $ r 	 t          j        |           pt          j        |           }n# t
          $ r Y Y dS w xY w|rt           j        	                    |          pd}d}|r$	 t          |           \  }}n# t          $ r Y nw xY wY nw xY wt          |t                    sJ ||fS )zx Return source location (path, lineno) for the given object.
    If the source cannot be determined return ("", -1)
    )rE   r   Nr   )r   codeCoderq   firstlineno	TypeErrorinspectgetsourcefilegetfilerr   
findsourceIOErrorr   r2   )objr   fspathrT   r   _s         r   getfslinenor      s    "w||C    !!    	',, '/#&& B 	 	 	666	 )b))1T 	&sOO	66   " fc"""""6>sV   0 
C(A$#C$
A3.C2A33*CB10C1
B>;C=B>>CCc                     	 t          j        |           \  }}n# t          j        j        $ r   Y dS xY wt                      }d |D             |_        ||fS )N)Nr   c                 6    g | ]}|                                 S rI   r   )r   rK   s     r   r   zfindsource.<locals>.<listcomp>  s     :::dDKKMM:::r   )r   r   r   r   _sysexr   r   )r   sourcelinesrT   rD   s       r   r   r      sp    %055VV:   xxXXF::k:::FL6>s    3c                     t           j                            |           } 	 t          j        |           }n# t
          $ r d}Y nw xY wt          |t                    sJ t          |fi |S )Nz<"Buggy python version consider upgrading, cannot get source")	r   r   
getrawcoder   r"   IndentationErrorr   r-   r   )r   r&   strsrcs      r   r"   r"     s    
'

S
!
!CR"3'' R R RQRfc"""""&##F###s   6 AAc                 Z  
 |R| D ]M}|                                 }|                                }|r!t          |          t          |          z
  } nNd}|dk    rt          |           S g }d } ||           
	 t	          j        
fd          D ]\  }}\  }}\  }}}|t          |           k    r n|t          |          k    rl| |dz
                                            }|                                r&|d |                                         r
||d          }|                    |           t          ||          D ]}	|                    | |	                    n# t          t          j
        f$ r Y nw xY w|                    | t          |          d                     |S )Nr   c              3   *   K   | D ]	}|dz   V  
	 dV  )Nr   TrE   rI   )r   rK   s     r   readline_generatorz$deindent.<locals>.readline_generator  s;       	 	D+	HHH	r   c                  "    t                     S r;   nextits   r   ra   zdeindent.<locals>.<lambda>$  s    PTUWPXPX r   r1   )
expandtabslstripr<   r   tokenizegenerate_tokensisspacer   ranger   
TokenErrorr#   )r   r[   rK   r   newlinesr   r   slineelineir   s             @r   r
   r
     s   ~ 	 	D??$$DA T3q66) F{{E{{H   
	E	"	"B/7/GHXHXHXHX/Y/Y 	* 	*+Aq*5!jua!s5zz!!s8}}$$UQY'2244;;== )T'6']%:%:%<%< )=D%%%5%(( * * a))))* h12    OOE#h--..)***Os   <C(E% %E>=E>c                    dd l }g }|                    |          D ]}t          |t          j                  st          |t          j                  r[|                    |j        dz
             dD ];}t          ||d           }|r&|                    |d         j        dz
  dz
             <|	                                 t          ||           }||dz
           }|t          |          k    rd }	n||         }	||	fS )Nr   r1   )	finalbodyorelse)rY   walkr   r   stmtExceptHandlerr   rT   getattrsortr   r<   )
rT   noderY   lr   namevalinsert_indexr6   rA   s
             r   get_statement_startend2r   8  s   JJJ 	AXXd^^ 4 4a## 	4z!T5G'H'H 	4HHQX\"""- 4 4at,, 4HHSV]Q.2333FFHHH6**LlQEs1vvo#:r   Fc                   
 |Lt          |          }	 t          |ddd          }n)# t          $ r t          | ||          \  }}d ||fcY S w xY wt	          | |          \  }}|t          |j                  }||dz   k    rt          j                    }|j        |         d         	                                |_
        d |j        ||         D             
	 t          j        
fd          D ]} |j        |  n1# t          j        t          f$ r |j        |z   }Y nt"          $ r Y nw xY w|rB|j        |dz
                                           }	|	                    d          s|	s|dz  }nn|B|||fS )	NrD   r_   i   r1   r   c              3       K   | ]	}|d z   V  
dS )r   NrI   r   s     r   	<genexpr>z(getstatementrange_ast.<locals>.<genexpr>e  s&      ::Qq4x::::::r   c                  "    t                     S r;   r   r   s   r   ra   z'getstatementrange_ast.<locals>.<lambda>g  s    R r   #)r-   r`   
ValueErrorgetstatementrange_oldr   r<   r   r   BlockFinderr   startedr   r   
tokeneater
EndOfBlockr   lastrf   r   
startswith)rT   rD   rU   astnodecontentr6   rA   block_findertokrK   r   s             @r   rX   rX   O  s   f++	$gx>>GG 	$ 	$ 	$.vvyIIJE3####	$ )99JE3
 {&,
UQY *,,%|E215==??::&,uSy"9:::	/0@0@0@0@AA . .''---."$45 	, 	, 	,#e+CCC 	 	 	D	  |C!G$++--??3 	t 	1HCC   E3s'   ' #AA$C> > D, 	D,+D,c                 (   ddl m} t          | dd          D ]}|r1|j        |         }d|v rd|v rd|v rt	          d          d|vrd	|vr5|j        || d
z            }|                    dd           d                    |          }	  ||           n# t          t          t          f$ r Y w xY wt          | d
z   t          |          d
z             D ](}|||         }|                                r||fc c S )t          d| fz            )z return (start, end) tuple which spans the minimal
        statement region which containing the given lineno.
        raise an IndexError if no such statementrange can be found.
    r   )compile_commandr   superr$   r*   zlikely a subclassassertraiser1   z
def xxx():z
 z%no valid source range around line %d )codeopr   r   r   r4   insertrj   r   OverflowErrorr   r<   rh   )	rT   rD   rU   r   r6   rK   trylines	trysourcerA   s	            r   r   r   x  s    '&&&&&vr2&& " " 	<&D$6T>>jD6H6H !4555t##t(;(;<fQh/ 	<(((JJx((		OI&&&&]J7 	 	 	H	 3v;;q=11 	" 	"CuSy)I$$&& "cz!!!!!"	" =	I
J
JJs   BB10B1r;   )FNr   )
__future__r   bisectr   rt   r   r   r   typesr   r`   r{   r   r   r|   rd   objectr   r   r   r   r   r"   r
   r   rX   r   rI   r   r   <module>r      s   ! ! ! ! ! !       



         				      KKK///////   IDDD
t t t t tV t t tt #$1      <	 	 	$ $ $' ' ' 'T  .& & & &R K  K  K  K  K  Ks   
1 	==