Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib/python3.7/site-packages/py/_code/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/py/_code/__pycache__/source.cpython-37.pyc

B

���]�8�@s�ddlmZddlmZddlZddlZddlZddlZddlm	Z	e
ZyddlZddlm
ZWnek
r|dZdZYnXGdd�de�Zddejdfd	d
�Zdd�Zd
d�Zdd�Zddd�Zdd�Zddd�Zddd�ZdS)�)�
generators)�bisect_rightN)�
ModuleType)�
PyCF_ONLY_ASTc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
d%dd�Zd&dd�Zd'dd�Z
d(dd�Zd)dd�Zd*dd�Zd d!�Zdd"ejddfd#d$�ZdS)+�SourcezY a immutable object holding a source code fragment,
        possibly deindenting it.
    rcOs�g|_}|�dd�}|�dd�}x�|D]�}|s4g}t|t�rF|j}njt|ttf�rddd�|D�}nLt|tjj�r�|�	d�}|r�x.|r�|d�
�r�P|��q�Wnt||d�j}|r�t
|�}|�|�q(WdS)	N�deindentT�rstripcSsg|]}|�d��qS)�
)r)�.0�x�r�@/opt/alt/python37/lib/python3.7/site-packages/py/_code/source.py�
<listcomp>!sz#Source.__init__.<locals>.<listcomp>r	���)r)�lines�get�
isinstancer�tuple�list�py�builtinZ_basestring�split�strip�pop�	getsourcer�extend)�self�parts�kwargsr�der�partZ	partlinesrrr
�__init__s*



zSource.__init__cCs<y|j|jkStk
r6t|t�r2t|�|kSdSXdS)NF)r�AttributeErrorr�str)r�otherrrr
�__eq__/s
z
Source.__eq__cCs:t|t�r|j|S|jdkr&td��|�|j|j�SdS)N)N�z!cannot slice a Source with a step)r�intr�step�
IndexError�__getslice__�start�stop)r�keyrrr
�__getitem__7s



zSource.__getitem__cCs
t|j�S)N)�lenr)rrrr
�__len__?szSource.__len__cCst�}|j||�|_|S)N)rr)rr+�end�	newsourcerrr
r*BszSource.__getslice__cCs|dt|�}}x"||kr0|j|��s0|d7}qWx&||krX|j|d��sX|d8}q4Wt�}|j||�|jdd�<|S)z] return new source object with trailing
            and leading blank lines removed.
        rr&N)r/rrr)rr+r1�sourcerrr
rGszSource.strip��    cs@t|�}t|�}t�}�fdd�|jD�}|j||j|_|S)ze return a copy of the source object with
            'before' and 'after' wrapped around it.
        csg|]}�|�qSrr)r
�line)�indentrr
r[sz$Source.putaround.<locals>.<listcomp>)rr)r�before�afterr7r2rr)r7r
�	putaroundTszSource.putaroundcs t�}�fdd�|jD�|_|S)zl return a copy of the source object with
            all lines indented by the given indent-string.
        csg|]}�|�qSrr)r
r6)r7rr
rdsz!Source.indent.<locals>.<listcomp>)rr)rr7r2r)r7r
r7_sz
Source.indentFcCs|�||�\}}|||�S)zc return Source statement which contains the
            given linenumber (counted from 0).
        )�getstatementrange)r�lineno�	assertionr+r1rrr
�getstatementgszSource.getstatementcCs:d|krt|�ks"ntd��t||�\}}}||fS)z{ return (start, end) tuple which spans the minimal
            statement region which containing the given lineno.
        rzlineno out of range)r/r)�getstatementrange_ast)rr<r=�astr+r1rrr
r;nszSource.getstatementrangeNcCs t�}t|j|�|jdd�<|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)rrr)r�offsetr2rrr
rws	zSource.deindentTcCs�yddl}Wntk
r(dd�}YnX|j}|rBt|���}nt|�}y||d�Wn(tk
rp�Yntk
r�dSXdSdS)zb return True if source is parseable, heuristically
            deindenting it by default.
        rNcSst|dd�S)NZasd�exec)�compile)rrrr
�<lambda>��z$Source.isparseable.<locals>.<lambda>r	FT)�parser�ImportErrorZsuiter#r�KeyboardInterrupt�	Exception)rrrFZsyntax_checkerr3rrr
�isparseable�szSource.isparseablecCsd�|j�S)Nr	)�joinr)rrrr
�__str__�szSource.__str__rBcCs`|rtj�|�jdd�r||dkr*t�d�}|jj|j}}d|j	}|j
j	d7_	|sj|d||f}n|d|||f}d�|j�d}	yt
|	|||�}
Wn�tk
�r"t��d}|jd|j�}|jr�|�d	|jd
�|�d|�td�|��}
|j|
_|j|
_|j|
_|
�Yn:X|t@�r2|
Sdd
�|jD�}dd||ftjjj|<|
SdS)z� return compiled code object. if filename is None
            invent an artificial filename which displays
            the source/line position of the caller frame.
        r)�fileNr&z<%d-codegen z%s:%d>z	%r %s:%d>r	� �^z*(code was compiled probably from here: %s)cSsg|]}|d�qS)r	r)r
rrrr
r�sz"Source.compile.<locals>.<listcomp>)r�path�local�check�sys�	_getframe�f_code�co_filename�f_lineno�_compilecounter�	__class__rKr�cpy_compile�SyntaxError�exc_infor<rA�append�text�	_AST_FLAG�std�	linecache�cache)r�filename�mode�flag�dont_inherit�	_genframe�fnr<�baser3�co�exZmsglinesZnewexrrrr
rC�s8



zSource.compile)r4r4r5)r5)F)F)N)T)�__name__�
__module__�__qualname__�__doc__rXr!r%r.r0r*rr:r7r>r;rrJrLr�
compiler_flagrCrrrr
rs$



	

rrBcCsLtdk	r$t|tj�r$t|||||�St�d�}t|�}|j||||d�}|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.
    Nr&)rg)�_astr�ASTrZrSrTrrC)r3rcrd�flagsrfrg�srjrrr
�compile_�s
rucCs�ytj�|�}Wn�tk
r�y tjj�|�p<tjj�|�}Wntk
rTdSX|rftj�	|�phd}d}|r�yt
|�\}}Wntk
r�YnXYnX|j}|j}t
|t�s�t�||fS)zx Return source location (path, lineno) for the given object.
    If the source cannot be determined return ("", -1)
    )r4rNr)r�codeZCode�	TypeErrorr`�inspect�
getsourcefile�getfilerPrQ�
findsource�IOErrorZfirstlinenorr'�AssertionError)�objrvrh�fspathr<�_rrr
�getfslineno�s&r�cCsXytjj�|�\}}Wn"tjjk
r0�Yn
dSt�}dd�|D�|_||fS)N)NrcSsg|]}|���qSr)r)r
r6rrr
rszfindsource.<locals>.<listcomp>)rr`rxr{rZ_sysexrr)r~�sourcelinesr<r3rrr
r{�sr{cKsNtj�|�}yt�|�}Wntk
r2d}YnXt|t�sBt�t	|f|�S)Nz<"Buggy python version consider upgrading, cannot get source")
rrvZ
getrawcoderxr�IndentationErrorrr#r}r)r~rZstrsrcrrr
rs
rc
	sH|dkr@x6|D]*}|��}|��}|rt|�t|�}PqWd}|dkrPt|�Sg}dd�}||��y�x�t��fdd��D]�\}}\}}\}}}|t|�kr�P|t|�kr�||d��}|��r�|d|���r�||d�}|�|�x t||�D]}	|�||	�q�WqzWWnt	tj
fk
�r,YnX|�|t|�d��|S)Nrcss(x|D]}|dVqWx
dVqWdS)Nr	r4r)rr6rrr
�readline_generators
z$deindent.<locals>.readline_generatorcst��S)N)�nextr)�itrr
rD#rEzdeindent.<locals>.<lambda>r&)�
expandtabs�lstripr/r�tokenize�generate_tokens�isspacer]�ranger��
TokenErrorr)
rrAr6rt�newlinesr�r��slineZeline�ir)r�r
r
s8
*
rc
Cs�ddl}g}xp|�|�D]b}t|tj�s4t|tj�r|�|jd�x4dD],}t||d�}|rJ|�|djdd�qJWqW|�	�t
||�}||d}|t|�kr�d}	n||}	||	fS)Nrr&)Z	finalbodyZorelse)r@�walkrrqZstmtZ
ExceptHandlerr]r<�getattr�sortrr/)
r<�noder@�lr�name�valZinsert_indexr+r1rrr
�get_statement_startend27s 
 
r�Fc
	sp|dkr`t|�}tjdkr"|d7}yt|ddd�}Wn*tk
r^t|||�\}}d||fSXt||�\}}|dkr�t|j�}||dk�r(t	�
�}|j|d��|_dd	�|j||�D��y*x$t
��fd
d��D]}|j|�q�WWn:t	jtfk
�r|j|}Yntk
�r&YnXx<|�rd|j|d��}	|	�d��sT|	�s^|d8}nP�q*W|||fS)
N)��r	r3rBir&rcss|]}|dVqdS)r	Nr)r
rrrr
�	<genexpr>fsz(getstatementrange_ast.<locals>.<genexpr>cst��S)N)r�r)r�rr
rDhrEz'getstatementrange_ast.<locals>.<lambda>�#)r#rS�version_inforC�
ValueError�getstatementrange_oldr�r/rrx�BlockFinderr��startedr�r��
tokeneater�
EndOfBlockr��lastrIr��
startswith)
r<r3r=Zastnode�contentr+r1Zblock_finder�tokr6r)r�r
r?Ns:


r?c	Csddlm}x�t|dd�D]�}|r^|j|}d|krLd|krLd|krLtd��d|kr^d	|kr^q|j||d
�}|�dd�d�|�}y||�Wnttt	fk
r�wYnXx:t|d
t
|�d
�D] }|||�}|��r�||fSq�WqWtd
|f��dS)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�superrr!zlikely a subclass�assert�raiser&z
def xxx():z
 z%no valid source range around line %d N)Zcodeopr�r�rr)�insertrKr[�
OverflowErrorr�r/rJ)	r<r3r=r�r+r6ZtrylinesZ	trysourcer1rrr
r�ys(

r�)N)FN)F)�
__future__r�bisectrrSrxr�r�typesrrCrZrqrr_rG�objectrrprur�r{rrr�r?r�rrrr
�<module>s.
:	
*
+