Your IP : 216.73.216.52


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.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)�.0�field)rr
r�	<genexpr>>sz!Value.__repr__.<locals>.<genexpr>z{}({}))�joinr&r(r)r)r�kwargsr
)rr�__repr__=szValue.__repr__N)rrr�__doc__r.r1r3r:r
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
rrFJrGcCs|jjS)N)rC�module)rr
r
rrFKrGcCs|jjS)N)rK�all)rr
r
rrFLrGcCst|jd|j�S)Nr)�slicer>r?)rr
r
rrFMrGFcCst|gf|j��S)N)rrB)rr
r
r�__iter__PszDefinition.__iter__cCsddd�|jS)N�publicZprivate)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_commentrR)r=�_slicer�reversedr8�list)rZfull_srcrWZfiltered_srcr
r
r�sourceWszDefinition.sourcecCs.d�|j|j|j�}|jr*|d�|j�7}|S)Nz
in {} {} `{}`z (skipping {}))r(rQrIr<rD)r�outr
r
rrbszDefinition.__str__N)rrrr;r&�propertyrI�kindrKrLrX�is_classrNrQr[rr
r
r
rrCsrc@sLeZdZdZdZedd��Zedd��Zedd��Z	edd��Z
d	d
�ZdS)rzA Python source code module.)r<r=r>r?r@rArBrC�_all�future_importsrDcCsttd�|S)N)�def�class)rr)�sr
r
rrForGzModule.<lambda>cCs|S)Nr
)rr
r
rrFprGcCs|jS)N)r`)rr
r
rrFqrGcCs|j�d�p|j�d�S)N�_�__)r<rU)rr
r
rrPsszModule.is_publiccCsdS)Nzat module levelr
)rr
r
rrwszModule.__str__N)rrrr;r&�staticmethod�_nestr]rKrLrPrr
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)rbrc)rr)rdr
r
rrF�szFunction.<lambda>cCs(|jdk	r|j|jkS|j�d�SdS)z:Return True iff this function should be considered public.Nre)rLr<rU)rr
r
rrP�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 ...".

        �testZrunTest)r<rU)rr
r
r�is_test�s	zFunction.is_testN)	rrrr;rgrhr]rPrjr
r
r
rrsrc@seZdZdZdZdS)rz%A Python source code nested function.FN)rrrr;rPr
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__`).rf)r<rU�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^{}\.Fre)
r@rr(r<�matchrUrlrmrCrP)rZ	decoratorZname_is_publicr
r
rrP�s
zMethod.is_publicN)rrrr;r]rmrnrPr
r
r
rr�src@s&eZdZdZedd��ZejZdZdS)rzA Python source code class.cCsttd�|S)N)rbrc)rr)rdr
r
rrF�rGzClass.<lambda>TN)	rrrr;rgrhrrPr_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.re)r<rUrCr_rP)rr
r
rrP�szNestedClass.is_publicN)rrrr;r]rPr
r
r
rr�src@seZdZdZd��ZdS)�	Decoratorz*A decorator for function, method or class.zname argumentsN)rrrr;rJr&r
r
r
rrp�srp)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>rVr�got_logical_newline)r�fileliker
r
rr.�s
zTokenStream.__init__cCsP|j}|��}|dkrdnt|�|_|jr6|jjdn|j|_|j|jk|_|S)Nr)r}�_next_from_generatorr|r>rVr^�LOGICAL_NEWLINESr~)rZpreviousr}r
r
r�move�szTokenStream.movec	Cs<yt|jd�Sttjfk
r6|jjddd�dSXdS)Nzerror generating tokensT)�exc_info)r	r{�SyntaxErrorrx�
TokenErrorrZwarning)rr
r
rr��s
z TokenStream._next_from_generatorccs*x$|jdk	r|jVndS|��qWdS)N)r}r�)rr
r
rrNs


zTokenStream.__iter__N)rrrrx�NEWLINE�INDENT�DEDENTr�r.r�r�rNr
r
r
rrw�s
rwc@seZdZdd�ZdS)�	TokenKindcCsd�tj|�S)Nztk.{})r(rx�tok_name)rr
r
rr:szTokenKind.__repr__N)rrrr:r
r
r
rr�sr�cs$eZdZd��Z�fdd�Z�ZS)r|zkind value start end sourcecs tt|�j|�t|j�|_dS)N)�superr|r.r�r^)rr-)r)r
rr.szToken.__init__)rrrrJr&r.�
__classcell__r
r
)r)rr|sr|c@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.rR�execN)r�	readlinesr[r8rr��six�
raise_fromrrwr�stream�filenamerL�setra�_accumulated_decorators�parse_module)rrr��src�errorr
r
r�parses
 zParser.parsecOs|j||�S)zCall the parse method.)r�)rr-r9r
r
rrq/szParser.__call__cCs|jjS)N)r�r})rr
r
rrF3rGzParser.<lambda>cCs|jjS)N)r�rV)rr
r
rrF4rGcCs|j��}|j|kst�dS)z8Consume one token and verify it is of the expected kind.N)r�r�r^�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)r}r^�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�debugr}r^r�rx�COMMENTr��NLr�r��STRING)rrAr
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))rbrc�@rR�(T�))r}rr�r^r�rx�NAME�OPr��appendrpr8r�r�r�r�)rr<�	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�)rbrc�from)r}rr�r^r�r�r~�	parse_allrxr�r�r��parse_definitionrhr��parse_definitionsr��parse_from_import_statementr�)r�class_rL�
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)r}r�r�r�rxr�rr�rLr^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)rLNz__init__.pyrRzfinished parsing module.)rr�rVr�rZr�rr}r�r�rkrr[rLrBrCra)rr>rArBr?�clsrK�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'rRNz/finished parsing %s '%s'. Next token is %r (%s))rVr�rxr�r}r�rr�rr�r�r^r�r�r�r��parse_skip_commentr�r�r�r�rZr�r[rBrC)rr�r>r<Zparenthesis_levelrDrAr@rBr?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.rRznoqa: rNz# noqarL)r}r^rxr�r�r8rJrU)rrDr
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)rtrur(r}r^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��
__future__N�importF)r�)r}r�r�r�r�r^rx�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)r}r�r�rxr�r��	ENDMARKERr^r�r�r�rr�ra�add)rr�Zexpected_end_kindsr
r
rr�<s2

zParser._parse_from_import_names)N)F)NN)rrrr;r�rqr]r}rVr�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rrs$

-
 4

r))r;Zloggingr�rt�tokenizerx�	itertoolsrrrr�utilsrr�ImportError�ior	�	NameError�objectrr�rsrr#r$rrrrrrrrrprlrrw�intr�r|rr
r
r
r�<module>sF
&'