Your IP : 216.73.216.196


Current Path : /opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/pydocstyle/__pycache__/parser.cpython-37.opt-1.pyc

B

;��Y�X�@s�dZddlZddlZddlZddlZddlmZmZddl	m
Z	ddlmZyddl
m
Z
Wn ek
r|ddlm
Z
YnXyeWn&ek
r�e�Zefdd	�ZYnXd
ZGdd�de�Zd
d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd �d e�Z Gd!d"�d"e�Z!d#Z"Gd$d%�d%e�Z#Gd&d'�d'e�Z$Gd(d)�d)e%�Z&Gd*d+�d+e�Z'Gd,d-�d-e�Z(dS).zPython code parser.�N)�chain�	dropwhile)�compile�)�log)�StringIOcCs2|tkr|��Sy|��Stk
r,|SXdS)N)�nothing�next�
StopIteration)�obj�default�r
�B/opt/alt/python37/lib/python3.7/site-packages/pydocstyle/parser.pyr	sr	)�Parser�
Definition�Module�Package�Function�NestedFunction�Method�Class�NestedClass�AllErrorr�
ParseErrorc@seZdZdd�ZdS)rcCsdS)NzCannot parse file.r
)�selfr
r
r�__str__%szParseError.__str__N)�__name__�
__module__�__qualname__rr
r
r
rr$srcCstd��d|���S)Nz(.)([A-Z]+)z\1 \2)�re�sub�lower)�stringr
r
r�humanize)sr#c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Valuez.A generic object with a list of preset fields.cGsPt|j�t|�kr6td�t|�t|j�|jj|j���t|��t|j|��dS)Nz)got {} arguments for {} fields for {}: {})	�len�_fields�
ValueError�format�	__class__r�vars�update�zip)r�argsr
r
r�__init__0s
zValue.__init__cCstt|��S)N)�hash�repr)rr
r
r�__hash__7szValue.__hash__cCs|ot|�t|�kS)N)r*)r�otherr
r
r�__eq__:szValue.__eq__cs*d��fdd��jD��}d��jj|�S)Nz, c3s |]}d�|t�|��VqdS)z{}={!r}N)r(�getattr)�.0Zfield)rr
r�	<genexpr>>sz!Value.__repr__.<locals>.<genexpr>z{}({}))�joinr&r(r)r)r�kwargsr
)rr�__repr__=szValue.__repr__N)rrr�__doc__r.r1r3r9r
r
r
rr$-s
r$c@s|eZdZdZdZedd��Zedd��Zedd��Zedd��Z	edd��Z
d	Zd
d�Zedd
��Z
edd��Zdd�ZdS)rz@A Python source code definition (could be class, function, etc).)	�name�_source�start�end�
decorators�	docstring�children�parent�skipped_error_codescCstt|�j�S)N)r#�typer)rr
r
r�<lambda>I�zDefinition.<lambda>cCs|j��dS)N���)�_human�split)rr
r
rrEJrFcCs|jjS)N)rB�module)rr
r
rrEKrFcCs|jjS)N)rJ�all)rr
r
rrELrFcCst|jd|j�S)Nr)�slicer=r>)rr
r
rrEMrFFcCst|gf|j��S)N)rrA)rr
r
r�__iter__PszDefinition.__iter__cCsddd�|jS)NZpublicZprivate)TF)�	is_public)rr
r
r�
_publicitySszDefinition._publicitycCs4|j|j}dd�}t|t|��}d�tt|���S)z*Return the source code for the definition.cSs|��dkp|���d�S)N��#)�strip�
startswith)�liner
r
r�is_empty_or_comment\sz.Definition.source.<locals>.is_empty_or_commentrP)r<�_slicer�reversedr7�list)rZfull_srcrUZfiltered_srcr
r
r�sourceWszDefinition.sourcecCs.d�|j|j|j�}|jr*|d�|j�7}|S)Nz
in {} {} `{}`z (skipping {}))r(rOrHr;rC)r�outr
r
rrbszDefinition.__str__N)rrrr:r&�propertyrH�kindrJrKrV�is_classrMrOrYrr
r
r
rrCsrc@sLeZdZdZdZedd��Zedd��Zedd��Z	edd��Z
d	d
�ZdS)rzA Python source code module.)r;r<r=r>r?r@rArB�_all�future_importsrCcCsttd�|S)N)�def�class)rr)�sr
r
rrEorFzModule.<lambda>cCs|S)Nr
)rr
r
rrEprFcCs|jS)N)r^)rr
r
rrEqrFcCs|j�d�p|j�d�S)N�_�__)r;rS)rr
r
rrNsszModule.is_publiccCsdS)Nzat module levelr
)rr
r
rrwszModule.__str__N)rrrr:r&�staticmethod�_nestr[rJrKrNrr
r
r
rrisrc@seZdZdZdS)rz"A package is a __init__.py module.N)rrrr:r
r
r
rr{src@s4eZdZdZedd��Zedd��Zedd��ZdS)	rzA Python source code function.cCsttd�|S)N)r`ra)rr)rbr
r
rrE�szFunction.<lambda>cCs(|jdk	r|j|jkS|j�d�SdS)z:Return True iff this function should be considered public.Nrc)rKr;rS)rr
r
rrN�s
zFunction.is_publiccCs|j�d�p|jdkS)aReturn True if this function is a test function/method.

        We exclude tests from the imperative mood check, because to phrase
        their docstring in the imperative mood, they would have to start with
        a highly redundant "Test that ...".

        ZtestZrunTest)r;rS)rr
r
r�is_test�s	zFunction.is_testN)	rrrr:rerfr[rNrgr
r
r
rrsrc@seZdZdZdZdS)rz%A Python source code nested function.FN)rrrr:rNr
r
r
rr�src@s4eZdZdZedd��Zedd��Zedd��ZdS)	rzA Python source code method.cCs"|j�d�o |j�d�o |jtkS)z@Return True iff this method is a magic method (e.g., `__str__`).rd)r;rS�endswith�VARIADIC_MAGIC_METHODS)rr
r
r�is_magic�szMethod.is_magiccCs
|jdkS)z*Return True iff this method is `__init__`.r.)r;)rr
r
r�is_init�szMethod.is_initcCsVx*|jD] }td�|j���|j�rdSqW|j�d�pH|jtkpH|j}|jj	oT|S)z8Return True iff this method should be considered public.z^{}\.Frc)
r?rr(r;�matchrSrirjrBrN)rZ	decoratorZname_is_publicr
r
rrN�s
zMethod.is_publicN)rrrr:r[rjrkrNr
r
r
rr�src@s&eZdZdZedd��ZejZdZdS)rzA Python source code class.cCsttd�|S)N)r`ra)rr)rbr
r
rrE�rFzClass.<lambda>TN)	rrrr:rerfrrNr]r
r
r
rr�src@seZdZdZedd��ZdS)rz"A Python source code nested class.cCs|j�d�o|jjo|jjS)z7Return True iff this class should be considered public.rc)r;rSrBr]rN)rr
r
rrN�szNestedClass.is_publicN)rrrr:r[rNr
r
r
rr�src@seZdZdZd��ZdS)�	Decoratorz*A decorator for function, method or class.zname argumentsN)rrrr:rIr&r
r
r
rrm�srm)r.�__call__�__new__c@seZdZdZdd�ZdS)rz9Raised when there is a problem with __all__ when parsing.cCst�||t�d��dS)z2Initialize the error with a more specific message.a]
                That means pydocstyle cannot decide which definitions are
                public. Variable __all__ should be present at most once in
                each file, in form
                `__all__ = ('a_public_function', 'APublicClass', ...)`.
                More info on __all__: http://stackoverflow.com/q/44834/. ')
                N)�	Exceptionr.�textwrap�dedent)r�messager
r
rr.�szAllError.__init__N)rrrr:r.r
r
r
rr�src@s<eZdZejejejhZdd�Zdd�Z	dd�Z
dd�Zd	S)
�TokenStreamcCs>t�|j�|_tt|jd��|_|jjd|_t	|_	d|_
dS)NrT)�tk�generate_tokens�readline�
_generator�Tokenr	�currentr=rTr�got_logical_newline)r�fileliker
r
rr.�s
zTokenStream.__init__cCsP|j}|��}|dkrdnt|�|_|jr6|jjdn|j|_|j|jk|_|S)Nr)rz�_next_from_generatorryr=rTr\�LOGICAL_NEWLINESr{)rZpreviousrzr
r
r�move�szTokenStream.movec	Cs<yt|jd�Sttjfk
r6|jjddd�dSXdS)Nzerror generating tokensT)�exc_info)r	rx�SyntaxErrorru�
TokenErrorrZwarning)rr
r
rr}�s
z TokenStream._next_from_generatorccs*x$|jdk	r|jVndS|��qWdS)N)rzr)rr
r
rrMs


zTokenStream.__iter__N)rrrru�NEWLINE�INDENT�DEDENTr~r.rr}rMr
r
r
rrt�s
rtc@seZdZdd�ZdS)�	TokenKindcCsd�tj|�S)Nztk.{})r(ru�tok_name)rr
r
rr9szTokenKind.__repr__N)rrrr9r
r
r
rr�sr�cs$eZdZd��Z�fdd�Z�ZS)ryzkind value start end sourcecs tt|�j|�t|j�|_dS)N)�superryr.r�r\)rr-)r)r
rr.szToken.__init__)rrrrIr&r.�
__classcell__r
r
)r)rrysryc@s�eZdZdZdd�Zdd�Zedd��Zedd��Zd	d
�Z	d%dd
�Z
dd�Zdd�Zd&dd�Z
dd�Zdd�Zdd�Zdd�Zd'dd�Zdd �Zd!d"�Zd#d$�ZdS)(rzA Python source code parser.c
Cs�t|_|��|_d�|j�}yt||d�Wn0tk
r\}zt�t�|�Wdd}~XYnXt	t
|��|_||_d|_
t�|_g|_|��S)z>Parse the given file-like object and return its Module object.rP�execN)r�	readlinesrYr7rr��sixZ
raise_fromrrtr�stream�filenamerK�setr_�_accumulated_decorators�parse_module)rr|r��src�errorr
r
r�parses
 zParser.parsecOs|j||�S)zCall the parse method.)r�)rr-r8r
r
rrn/szParser.__call__cCs|jjS)N)r�rz)rr
r
rrE3rFzParser.<lambda>cCs|jjS)N)r�rT)rr
r
rrE4rFcCs|j��}|j|kst�dS)z8Consume one token and verify it is of the expected kind.N)r�rr\�AssertionError)rr\Z
next_tokenr
r
r�consume6s
zParser.consumeNcCsLxF|jdk	rF|jj|kr:|dks,|jj|kr:|�|�dS|j��qWdS)z�Skip tokens in the stream until a certain token kind is reached.

        If `value` is specified, tokens whose values are different will also
        be skipped.
        N)rzr\�valuer�r�r)rr\r�r
r
r�leapfrog;s
zParser.leapfrogcCs�|j�d|jj|jj�x>|jjtjtjtjfkrV|j	�
�|j�d|jj|jj�qW|jjtjkr||jj}|j	�
�|SdS)z.Parse a single docstring and return its value.z#parsing docstring, token is %r (%s)N)r�debugrzr\r�ru�COMMENTr��NLr�r�STRING)rr@r
r
r�parse_docstringHs

zParser.parse_docstringcCsFg}g}d}�x|jdk	�r"|j�d|jj|jj�|jjtjkrR|jjdkrRPn�|jjtjkr�|jjdkr�|j�	t
d�|�d�|���g}g}d}n~|jjtjkr�|jjdkr�d}n^|jjtjkr�|jjd	kr�nB|jjtjks�|jjtj
kr�n$|�s|�	|jj�n|�	|jj�|j��qW|j�	t
d�|�d�|���dS)
z�Called after first @ is found.

        Parse decorators into self._accumulated_decorators.
        Continue to do so until encountering the 'def' or 'class' start token.
        FNz,parsing decorators, current token is %r (%s))r`ra�@rP�(T�))rzrr�r\r�ru�NAME�OPr��appendrmr7r�r�r�r)rr;Z	argumentsZat_argumentsr
r
r�parse_decoratorsVs6zParser.parse_decoratorsFccs0�x(|jdk	�r*|j�d|jj|jj�|j�d|jj�|rT|jjdkrT|��q|jjtj	kr�|jjdkr�|jjr�|�
tj	�|��q|jjdkr�|�|�
|jj��Vq|jjtjkr�|�
tj�x\|�|�D]
}|Vq�Wq|jjtjk�r|�
tj�dS|jjdk�r|��q|j��qWdS)z*Parse multiple definitions and yield them.Nz1parsing definition list, current token is %r (%s)zgot_newline: %s�__all__r�)r`ra�from)rzrr�r\r�r�r{�	parse_allrur�r�r��parse_definitionrfr��parse_definitionsr��parse_from_import_statementr)r�class_rK�
definitionr
r
rr��s.


zParser.parse_definitionsc
Cs>|jjdkst�|�tj�|jjdkr0td��|�tj�|jjdkrPtd��|�tj�g|_d}xx|jj	tjks�|jjdkr�|jj	tj
tjfkr�n:|jj	tjks�|jjdkr�||jj7}ntd�
|jj	���|j��qhW|�tj�|d	7}yt|i�|_Wn4tk
�r8}ztd
�
||���Wdd}~XYnXdS)z)Parse the __all__ definition in a module.r��=z(Could not evaluate contents of __all__. z([r�z)]�,z)Unexpected token kind in  __all__: {!r}. r�zOCould not evaluate contents of __all__.The value was {}. The exception was:
{}N)rzr�r�r�rur�rr�rKr\r�r�r�r(r�r�eval�
BaseException)rZall_content�er
r
rr��s4zParser.parse_allcCs�|j�d�|j}|��}t|jtdd��}|jdks@t|j��|j}t}|j	�
d�rZt}||j	|j||g||d|j
dd�}x|jD]
}||_q�W|j|_|j�d�|S)z=Parse a module (and its children) and return a Module object.zparsing module.T)rKNz__init__.pyrPzfinished parsing module.)rr�rTr�rXr�rrzr�r�rhrrYrKrArBr_)rr=r@rAr>�clsrJ�childr
r
rr��s 
zParser.parse_modulec
Cs�|j}|�tj�|jj}|j�d|j|�|j	�
�|jjtjkr�|jjdkr�d}xP|jjtjkr�|jjdkrz|d7}n|jjdkr�|d8}|dkr�P|j	�
�qVW|jjtjks�|jjdkr�|j
tjdd�n|�tj�|jjtjtjfk�rr|��}|�
tj�|jjtjk�st�|��}|j}|j�d|�g|_|j�d	�t|�|��}|j�d
|�|jd}	n&d}|��}g}g}|j}	|�
tj�|||j||	|||d|�	}
x|
jD]}|
|_�q�W|j�d
|j||jj|jj�|
S)z=Parse a definition and return its value in a `class_` object.zparsing %s '%s'r�rrr��:)r�z"current accumulated decorators: %szparsing nested definitions.z,finished parsing nested definitions for '%s'rPNz/finished parsing %s '%s'. Next token is %r (%s))rTr�rur�rzr�rr�rr�rr\r�r�r�r��parse_skip_commentr�r�r�r�rXr�rYrArB)rr�r=r;Zparenthesis_levelrCr@r?rAr>r�r�r
r
rr��s^


zParser.parse_definitioncCsRd}|jjtjkrNd|jjkr<d�|jj�d�dd��}n|jj�d�rNd}|S)z*Parse a definition comment for noqa skips.rPznoqa: rNz# noqarK)rzr\rur�r�r7rIrS)rrCr
r
rr�szParser.parse_skip_commentcCsNt�dj|d��}|r"|jj|knd}|r6|jj|knd}|rB|sJt|��dS)z>Verify the current token is of type `kind` and equals `value`.z�
        Unexpected token at line {self.line}:

        In file: {self.filename}

        Got kind {self.current.kind!r}
        Got value {self.current.value}
        )rTN)rqrrr(rzr\r�r�)rr\r��msgZ
kind_validZvalue_validr
r
r�
check_currents
zParser.check_currentcCs"|j�d�|��}|�|�dS)zeParse a 'from x import y' statement.

        The purpose is to find __future__ statements.

        zparsing from/import statement.N)rr��_parse_from_import_source�_parse_from_import_names)r�is_future_importr
r
rr�sz"Parser.parse_from_import_statementcCs�|jjdkst|jj��|j��|jjdk}|j��x<|jdk	rt|jjtjtjtj	fkrt|jjdkrt|j��q:W|jdks�|jjdkr�dS|j
dd�|jjdks�t|jj��|j��|S)zuParse the 'from x import' part in a 'from x import y' statement.

        Return true iff `x` is __future__.
        r�Z
__future__N�importF)r�)rzr�r�r�rr\ru�DOTr�r�r�)rr�r
r
rr�(s


z Parser._parse_from_import_sourcecCsX|jjdkr"|�tj�tjf}ntjtjf}�x"|jj|k�rR|jjtjkr\|jjdk�sR|jjtjkrv|j	�
�q2|j�d|jj|jj�|r�|j�d|jj�|j
�|jj�|�tj�|j�d|jj|jj�|jjtjk�r|jjdk�r|�tj�|jjtjk�r|�tj�|jjdk�r8|�tj�|j�d|jj|jj�q2WdS)z4Parse the 'y' part in a 'from x import y' statement.r��;z parsing import, token is %r (%s)zfound future import: %s�asr�N)rzr�r�rur�r��	ENDMARKERr\r�r�rrr�r_�add)rr�Zexpected_end_kindsr
r
rr�<s2

zParser._parse_from_import_names)N)F)NN)rrrr:r�rnr[rzrTr�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rrs$

-
 4

r))r:Zloggingr�rq�tokenizeru�	itertoolsrrrrZutilsrr�ImportError�ior	�	NameError�objectrr�rprr#r$rrrrrrrrrmrirrt�intr�ryrr
r
r
r�<module>sF
&'