HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/__pycache__/pycodestyle.cpython-310.pyc
o

we���@szdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZddl
mZddlmZejdkrSeee
dd��rSee
j�e
_dZd	Zd
Zzejdkrfej�d�Znej�e�d
�psej�d�d�ZWney�dZYnwdZdZ ddd�Z!dZ"dZ#ddd�Z$dZ%e&gd��Z'e&ej(dg�e'Z)e&gd��Z*e&gd��Z+e+�,gd��Z-e&gd ��Z.e&d!�Z/e&e
j0e
j1g�Z1e1�,e
j2e
j3g�Z4e4�,e
j5e
j6g�Z7gd"�Z8e�9d#�Z:e�9d$�Z;e�9d%�Z<e�9d&�Z=e�9d'�Z>e�9d(�Z?e�9d)�Z@e�9d*�ZAe�9d+d,�e)��ZBe�9d-�ZCe�9d.�ZDe�9d/�ZEe�9d0�ZFe�9d1�ZGe�9d2�Hd,�d3d4�d5D����ZIe�9d6�ZJe�9d7�ZKejd8k�rWe
jLZLe
jMZMe
jNZNnd9ZLZMZNiiid:�ZOd;d<�ZPd�d=d>�ZQeQd?d@��ZReQdAdB��ZSeQdCdD��ZTeQdEdF��ZUeQdGdH��ZVdIdJ�ZWeQdKdL��ZXeQdMdN��ZYeQdOdP��ZZeQdQdR��Z[eQdSdT��Z\eQdUdV��Z]eQdWdX��Z^eQdYdZ��Z_eQd[d\��Z`eQd]d^��ZaeQd_d`��ZbeQdadb��ZceQdcdd��ZdeQdedf��ZeeQdgdh��ZfeQdidj��Zge&dk�e&dl�BZhdmdn�Zidodp�ZjeQdqdr��ZkeQdsdt��ZleQdudv��ZmeQdwdx��ZneQdydz��ZoeQd{d|��ZpeQd}d~��ZqeQdd���ZreQd�d���Zsd�d��Ztd�d��Zued��e�9d�ejv�jw�Zxd�d��Zyd�d��Zzd�d�d��Z{ej|fd�d��Z}d�d�d��Z~d�d��Zd�d��Z�Gd�d��d��Z�Gd�d��d��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d��Z�defd�d��Z�d�d��Z�		d�d�d��Z�d�d�d��Z�d�d��Z�e�d�k�r�e��dSdS)�a�
Check Python source code formatting, according to PEP 8.

For usage and a list of options, try this:
$ python pycodestyle.py -h

This program and its regression test suite live here:
https://github.com/pycqa/pycodestyle

Groups of errors and warnings:
E errors
W warnings
100 indentation
200 whitespace
300 blank lines
400 imports
500 line length
600 deprecation
700 statements
900 syntax error
�N��fnmatch)�	lru_cache)�OptionParser)��
�_compilez2.11.1z'.svn,CVS,.bzr,.hg,.git,__pycache__,.toxz&E121,E123,E126,E226,E24,E704,W503,W504�win32z~\.pycodestyle�XDG_CONFIG_HOMEz	~/.config�pycodestyle)z	setup.cfgztox.ini�O��)�	top_level�method�H�z+%(path)s:%(row)d:%(col)d: %(code)s %(text)sz%%(path)s:%(row)d: [%(code)s] %(text)s)�default�pylinti)�False�None�True�print)�>>�**�*�+�-)rr�/z//rr�@)�^�&�|z<<r�%)z**=z*=z/=z//=z+=z-=z!=�<�>z%=z^=z&=z|=�==z<=z>=z<<=z>>=�=�and�in�is�orz->�:=u 	 )�directories�files�
logical lines�physical linesz([ \t]*)z\b[A-Z]\d{3}\bz	u?r?["\']z[\[({][ \t]|[ \t][\]}),;:](?!=)z[,;:]\s*(?:  |\t)z?(\bNone|\bFalse|\bTrue)?\s*([=!]=)\s*(?(1)|(None|False|True))\bz*\b(?<!is\s)(not)\s+[^][)(}{ ]+\s+(in|is)\szU[=!]=\s+type(?:\s*\(\s*([^)]*[^ )])\s*\))|\btype(?:\s*\(\s*([^)]*[^ )])\s*\))\s+[=!]=z(\s*)\b(?:%s)\b(\s*)r"z*(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+|:=)(\s*)z
\blambda\bz*^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$z^(async\s+def|def)\bz#^(async\s+def\s+|def\s+|class\s+|@)z
^\s*({})\bccs�|]	}|�dd�VqdS)� z\s+N)�replace��.0�s�r6�D/home/arjun/projects/env/lib/python3.10/site-packages/pycodestyle.py�	<genexpr>���r8)�defz	async def�forz	async for�if�elif�else�try�except�finally�withz
async with�class�whilez-^__([^\s]+)__(?::\s*[a-zA-Z.0-9_\[\]\"]+)? = z
except\s*:)r����)�
physical_line�logical_line�treecCsdd�t�|�j��D�S)NcSsg|]}|j|jkr|j�qSr6)�kind�POSITIONAL_OR_KEYWORD�name)r4�	parameterr6r6r7�
<listcomp>�s
�z#_get_parameters.<locals>.<listcomp>)�inspect�	signature�
parameters�values)�functionr6r6r7�_get_parameters�s�rTcCs�dd�}t�|�r,t|�}|r*|ddvr*|dur!t�|jpd�}|||d||�|St�|�rEt|j�dd�dd	gkrE||d	|d�|S)
zRegister a new check object.cSsD|t|vrt||d�|pg�dS|pdg|ft||<dS)Nr�)�_checks�extend)�checkrJ�codes�argsr6r6r7�
_add_check�sz"register_check.<locals>._add_checkr)rGrHNrUr
�selfrI)rO�
isfunctionrT�ERRORCODE_REGEX�findall�__doc__�isclass�__init__)rXrYr[rZr6r6r7�register_check�s

�rccCs:t�|��d�}t|�D]\}}||kr|dfSqdS)aNever mix tabs and spaces.

    The most popular way of indenting Python is with spaces only.  The
    second-most popular way is with tabs only.  Code indented with a
    mixture of tabs and spaces should be converted to using spaces
    exclusively.  When invoking the Python command line interpreter with
    the -t option, it issues warnings about code that illegally mixes
    tabs and spaces.  When using -tt these warnings become errors.
    These options are highly recommended!

    Okay: if a == 0:\n    a = 1\n    b = 1
    rz/E101 indentation contains mixed spaces and tabsN)�INDENT_REGEX�match�group�	enumerate)rG�indent_char�indent�offset�charr6r6r7�tabs_or_spaces�s��rlcCs*t�|��d�}d|vr|�d�dfSdS)z�On new projects, spaces-only are strongly recommended over tabs.

    Okay: if True:\n    return
    W191: if True:\n\treturn
    r�	zW191 indentation contains tabsN)rdrerf�index)rGrir6r6r7�
tabs_obsolete�s�rocCsH|�d�}|�d�}|�d�}|�d�}||kr"|r t|�dfSdSdS)aTrailing whitespace is superfluous.

    The warning returned varies on whether the line itself is blank,
    for easier filtering for those who want to indent their blank lines.

    Okay: spam(1)\n#
    W291: spam(1) \n#
    W293: class Foo(object):\n    \n    bang = 12
    �
�
�z 	zW291 trailing whitespace)rz#W293 blank line contains whitespaceN��rstrip�len)rG�strippedr6r6r7�trailing_whitespace�s



�rwcCs>||kr|�d�}|r|sdS||krt|d�dfSdSdS)z�Trailing blank lines are superfluous.

    Okay: spam(1)
    W391: spam(1)\n

    However the last line should end with a new line (warning W292).
    �
)rzW391 blank line at end of filerFzW292 no newline at end of fileNrs)rG�lines�line_number�total_lines�stripped_last_liner6r6r7�trailing_blank_lines�s	
�r}cCs�|��}t|�}||krM|sO|dkr|�d�rdS|��}t|�dkr%|s1t|�dkrA|ddkrAt|�t|d�|dkrAdS||krQ|d	||ffSdSdSdS)
a�Limit all lines to a maximum of 79 characters.

    There are still many devices around that are limited to 80 character
    lines; plus, limiting windows to 80 characters makes it possible to
    have several windows side-by-side.  The default wrapping on such
    devices looks ugly.  Therefore, please limit all lines to a maximum
    of 79 characters. For flowing long blocks of text (docstrings or
    comments), limiting the length to 72 characters is recommended.

    Reports error E501.
    r�#!Nr
r�#rF�z'E501 line too long (%d > %d characters))rtru�
startswith�split)rG�max_line_length�	multilinerz�noqa�line�length�chunksr6r6r7�maximum_line_lengths ��r�cCs�t�|�sdS|d}|dkrd}nt||d�}||kr dS|t|�krA||��}|�d�s7t�|�r7n|d7}|t|�ks&dS|d}|t|�kr^||��rTn|d7}|t|�ksMdSt||�|kS)NFrrrT)�STARTSWITH_TOP_LEVEL_REGEXre�
expand_indentru�stripr�)rH�indent_levelryrz�line_idx�prev_indentr��next_idxr6r6r7�
_is_one_liner-s.
��r�c	cs��td}	td}
|s||	krdS|�d�r|rdVdSdS||	ks+|r4||
dkr4dd|fVdSt�|�r�t||||�rF|dkrFdS|r�||
ks�||ks�t�|�s�|}d	}|||	dd
�D]}
|
��r�t|
�|kr�t|
�}t�|
�	��}|s|dkr�nqb|r�dd|
ffVdSdd�
|
�fVdSdSdSdS||	kr�dd
|	|ffVdSdS|r�|s�||	kr�|�d�r�dd|	|ffVdSdSdSdSdS)aOSeparate top-level function and class definitions with two blank
    lines.

    Method definitions inside a class are separated by a single blank
    line.

    Extra blank lines may be used (sparingly) to separate groups of
    related functions.  Blank lines may be omitted between a bunch of
    related one-liners (e.g. a set of dummy implementations).

    Use blank lines in functions, sparingly, to indicate logical
    sections.

    Okay: def a():\n    pass\n\n\ndef b():\n    pass
    Okay: def a():\n    pass\n\n\nasync def b():\n    pass
    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
    Okay: default = 1\nfoo = 1
    Okay: classify = 1\nfoo = 1

    E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef b(n):\n    pass
    E302: def a():\n    pass\n\nasync def b(n):\n    pass
    E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
    E303: def a():\n\n\n\n    pass
    E304: @decorator\n\ndef a():\n    pass
    E305: def a():\n    pass\na()
    E306: def a():\n    def b():\n        pass\n    def c():\n        pass
    rrNr)rz/E304 blank lines found after function decoratorrrzE303 too many blank lines (%d)FrFz?E306 expected %s blank line before a nested definition, found 0z$E301 expected {} blank line, found 0z&E302 expected %s blank lines, found %d)zdef zclass zIE305 expected %s blank lines after class or function definition, found %d)�BLANK_LINES_CONFIGr�r�rer��DOCSTRING_REGEXr�r��STARTSWITH_DEF_REGEX�lstrip�format)rH�blank_linesr�rz�blank_before�previous_logical� previous_unindented_logical_line�previous_indent_levelry�top_level_lines�method_lines�ancestor_level�nestedr�r6r6r7r�Psv�!

��
�������������r�ccs��|}t�|�D]9}|��}|��}|��}|d��r&|dd|fVq||ddkrA|dvr4dnd}||�d|�d	�fVqd
S)aHAvoid extraneous whitespace.

    Avoid extraneous whitespace in these situations:
    - Immediately inside parentheses, brackets or braces.
    - Immediately before a comma, semicolon, or colon.

    Okay: spam(ham[1], {eggs: 2})
    E201: spam( ham[1], {eggs: 2})
    E201: spam(ham[ 1], {eggs: 2})
    E201: spam(ham[1], { eggs: 2})
    E202: spam(ham[1], {eggs: 2} )
    E202: spam(ham[1 ], {eggs: 2})
    E202: spam(ham[1], {eggs: 2 })

    E203: if x == 4: print x, y; x, y = y , x
    E203: if x == 4: print x, y ; x, y = y, x
    E203: if x == 4 : print x, y; x, y = y, x
    rFrzE201 whitespace after '%s'�,�}])�E202�E203z whitespace before '�'N)�EXTRANEOUS_WHITESPACE_REGEX�finditerrfr��start�isspace)rHr�re�textrk�found�coder6r6r7�extraneous_whitespace�s���r�cc��t�|�D]>}|��\}}d|vr|�d�dfVnt|�dkr)|�d�dfVd|vr6|�d�dfVqt|�dkrD|�d�dfVqdS)	z�Avoid extraneous whitespace around keywords.

    Okay: True and False
    E271: True and  False
    E272: True  and False
    E273: True and\tFalse
    E274: True\tand False
    rmrzE274 tab before keywordz#E272 multiple spaces before keywordr
zE273 tab after keywordz"E271 multiple spaces after keywordN)�
KEYWORD_REGEXr��groupsr�ru�rHre�before�afterr6r6r7�whitespace_around_keywords���
��r�ccs��t||dd��D]:\}}|j|jkrD|jtjkrDt�|j�rD|jt	vrD|jdkr/|jdksD|jdkr9|jdksD|jdvrD|jdfVq
dS)	z�Keywords should be followed by whitespace.

    Okay: from foo import (bar, baz)
    E275: from foo import(bar, baz)
    E275: from importable.module import(bar, baz)
    E275: if(foo): bar
    rNr@r�yield�)z:
z%E275 missing whitespace after keyword)
�zip�endr��type�tokenize�NAME�keyword�	iskeyword�string�
SINGLETONS)rH�tokens�tok0�tok1r6r6r7� missing_whitespace_after_keyword�s�	
�

��r�ccs��|rdnd}|rdnd}||r d|d|dt|�ffV|�d�}|r7||kr7d|d|d	ffVn|sH||krHd|d|d
ffV|rc|dkrPdnd
}	||	}
||
kred|dfVdSdSdS)a�Use indent_size (PEP8 says 4) spaces per indentation level.

    For really old code that you don't want to mess up, you can continue
    to use 8-space tabs.

    Okay: a = 1
    Okay: if a == 0:\n    a = 1
    E111:   a = 1
    E114:   # a = 1

    Okay: for item in items:\n    pass
    E112: for item in items:\npass
    E115: for item in items:\n# Hi\n    pass

    Okay: a = 1\nb = 2
    E113: a = 1\n    b = 2
    E116: a = 1\n    # b = 2
    rrzE11%d %szE11%d %s (comment)rz!indentation is not a multiple of �:r
zexpected an indented blockzunexpected indentationrm�r)r�z
over-indentedN)�str�endswith)rHr�rhr�r��indent_size�c�tmpl�
indent_expect�expected_indent_amount�expected_indent_levelr6r6r7�indentation�s(�

�
�r�c(cs�|ddd}d|ddd|}	|s|	dkrdS|�d�}
d}}|dkr-|fn||df}
dg|	}dg|	}dgg}dg}i}|dd}d}d}|dg}|d	kretd
|dd���|D�]l\}}}}}||d|k}|r�|d|}|o�|tv}|�ru|}|d	kr�td|���t|�|||<|tjko�|d
v}t||�D]}||||}||
v} | r�nq�||r�|||k} |o�|dko�|�|d�}|r�||r�|d||kr�|dfVn�|r�|s�|r�|dfVn|||�r|d||k�r|du�r|dfVnc| �s!|
�r1||d|k�r1|�r,|�s,|dfV|||<nD|du�r=|d||<n8||t	fv�rEn0|dk�rMd}!n!||�rUd}!n|�s`||�r`d}!n|||<||k�rld}!nd}!|d|!fV||�r�|tj
tjfv�r�||�s�|d||<d||d<|dk�r�td|�d|d���nS|tjtjt
fv�r�t	||d<nB|�s�|�s�|dv�r�d||dd<n.|�s�|�s�|�s�|dk�r�d||dd<n|dk�r�||dd����r�||�|�|tjk�r�|dv�r@|d7}|�d�|�d�t|�|k�r|�g�||�|�||d7<|dk�r?td||d||f�ng|dv�r�|dk�r�|���pR|d}"|��t|�D]}#||#|"k�rhd||#<�q[t|�D]}$|$|"k�rx||$=�qn||dd�=|d8}|�r�d|||<t|dd�D]}%||%�r�||%d8<n�q�t|�|dk�s�J�|d|v�r�|||d<|d|dk}|�r�||||d|<qg|
�r�t|�||k�r�|d|d|f}&|�r�d }'nd!}'|&d"|'fVdSdSdS)#a2Continuation lines indentation.

    Continuation lines should align wrapped elements either vertically
    using Python's implicit line joining inside parentheses, brackets
    and braces, or using a hanging indent.

    When using a hanging indent these considerations should be applied:
    - there should be no arguments on the first line, and
    - further indentation should be used to clearly distinguish itself
      as a continuation line.

    Okay: a = (\n)
    E123: a = (\n    )

    Okay: a = (\n    42)
    E121: a = (\n   42)
    E122: a = (\n42)
    E123: a = (\n    42\n    )
    E124: a = (24,\n     42\n)
    E125: if (\n    b):\n    pass
    E126: a = (\n        42)
    E127: a = (24,\n      42)
    E128: a = (24,\n    42)
    E129: if (a or\n    b):\n    pass
    E131: a = (\n    42\n 24)
    rr
rrFNr�rmFrz>>> rz... z]})z6E124 closing bracket does not match visual indentationz+E133 closing bracket is missing indentationTz7E128 continuation line under-indented for visual indentzIE123 closing bracket does not match indentation of opening bracket's line)�E122z missing indentation or outdented)�E127zover-indented for visual indent)�E131zunaligned for hanging indent)�E126z over-indented for hanging indent)�E121z!under-indented for hanging indentz%s continuation line %szbracket depth z indent to )�assert�raiserBr<�([{z.bracket depth %s seen, col %s, visual min = %s�)]}zE129 visually indented linezE125 continuation linez(%s with same indent as next logical line)r�rrt�NEWLINEr�r��OP�reversed�getr��NL�COMMENT�STRING�
FSTRING_STARTr��appendru�pop�range�list)(rHr�r��hang_closingrhr�r��verbose�	first_row�nrows�indent_next�row�depth�valid_hangs�parens�
rel_indent�	open_rows�hangs�indent_chances�last_indent�
visual_indent�last_token_multilineri�
token_typer�r�r�r��newline�
close_bracket�open_row�hang�hanging_indent�errorr��d�ind�idx�posr�r6r6r7�continued_indentation s�

�


��
�
�

�






�
� 




���
�
���r�ccs��|d\}}}}}tdt|��D]O}||\}}}	}
}|tjkrZ|dvrZ|	|krZ|tjks2|dvrZ|dks@||dddkrZt�|�sZtjdksS|dksSt�	|�sZ|d	|fV|}|}|
}qd
S)a�Avoid extraneous whitespace.

    Avoid extraneous whitespace in the following situations:
    - before the open parenthesis that starts the argument list of a
      function call.
    - before the open parenthesis that starts an indexing or slicing.

    Okay: spam(1)
    E211: spam (1)

    Okay: dict['key'] = list[index]
    E211: dict ['key'] = list[index]
    E211: dict['key'] = list [index]
    rr�([r�r
rC�r�	r�zE211 whitespace before '%s'N)
r�rur�r�r�r�r��sys�version_info�
issoftkeyword)rHr��	prev_type�	prev_text�__�prev_endrnr�r�r�r�r6r6r7�whitespace_before_parameters�s(�
�
��r
ccr�)	z�Avoid extraneous whitespace around an operator.

    Okay: a = 12 + 3
    E221: a = 4  + 5
    E222: a = 4 +  5
    E223: a = 4\t+ 5
    E224: a = 4 +\t5
    rmrzE223 tab before operatorz$E221 multiple spaces before operatorr
zE224 tab after operatorz#E222 multiple spaces after operatorN)�OPERATOR_REGEXr�r�r�rur�r6r6r7�whitespace_around_operatorr�rccs\�d}tj}d}}tjtjf}g}|D�]�\}}	}
}}|tjkr+|	dvr+|�|	�nE|tkr5|�d�n;|tjkrD|	dkrD|�d�n,|rp|tjkrT|	dvrT|��n|tkr]|��n|ddkrp|tjkrp|	d	krp|��|tvruq|tjkr�|	d
vr�||d|dd�}
|
tvr�|
dvr�|	d	kr�|dd�d
gkr�n |	d	kr�|dd�ddgkr�n|	dkr�|
dvr�n|
d|	��fV|�r"|
|kr�|dur�|ds�|ddfVd}n�|dkr�|	dvs�|dkr�|	d	kr�n�|dus�|dr�|dfVn'|dk�rd\}}|dk�rd\}}n	|t	v�rd\}}|dd||ffVd}n�||v�r�|du�r�|	dk�rQ|dd�dgk�sP|dd�d gk�sP|dd�ddgk�rQn9|	t
v�rYd}n1|	tv�r�|tjk�ri|d!v�s�|tjk�r�|tv�r�t
jd"k�s�t�|��s�d}n|	tv�r�d}|du�r�||
|kf}n|�r�|
|k�r�|dfVd}|}|	}|}qdS)#aZSurround operators with the correct amount of whitespace.

    - Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
      Booleans (and, or, not).

    - Each comma, semicolon or colon should be followed by whitespace.

    - If operators with different priorities are used, consider adding
      whitespace around the operators with the lowest priorities.

    Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: alpha[:-i]
    Okay: [a, b]
    Okay: (3,)
    Okay: a[3,] = 1
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]

    E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E225: z = 1and 1
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
    FN>�{�(�[�f�lambda�l>�}r��]rFr�>r�r��;rrxr���r
r��)]zE231 missing whitespace after Trz'E225 missing whitespace around operatorr>r�r�r�r�r)�E226�
arithmeticr#)�E228�modulo)�E227zbitwise or shiftz(%s missing whitespace around %s operatorr'rr�r)r�r�r�r�r�r��FSTRING_END�
SKIP_COMMENTS�
WHITESPACE�
ARITHMETIC_OP�WS_NEEDED_OPERATORS�UNARY_OPERATORS�KEYWORDSrrr�r�WS_OPTIONAL_OPERATORS)rHr��
need_spacerrr	�operator_types�brace_stackr�r�r�r�r��	next_charr��optyper6r6r7�missing_whitespace/s��*


�



�



��


�r*ccs`�|}t�|�D]%}|��d}d|��vr"|d|��dfVq|d|��dfVqdS)z�Avoid extraneous whitespace after a comma or a colon.

    Note: these checks are disabled by default

    Okay: a = (1, 2)
    E241: a = (1,  2)
    E242: a = (1,\t2)
    rrmzE242 tab after '%s'rzE241 multiple spaces after '%s'N)�WHITESPACE_AFTER_COMMA_REGEXr�r�rf)rHr��mr�r6r6r7�whitespace_around_comma�s�
�r-ccs4�d}d}d}d}d}tt�|��}d}d}	|D]\}
}}}
}|
tjkr%q|r2d}||kr2||fV|r?d}||kr?||	fV|
tjkr�|dvrM|d7}nD|dvrV|d8}n;|rc|d	krc|dkrcd
}n.|dkrn|dkrnd}n#|r�|dkr�|r�|dkr�d
}||kr�||	fVnd
}||kr�||fV|s�d}|
}qdS)
acDon't use spaces around the '=' sign in function arguments.

    Don't use spaces around the '=' sign when used to indicate a
    keyword argument or a default parameter value, except when
    using a type annotation.

    Okay: def complex(real, imag=0.0):
    Okay: return magic(r=real, i=imag)
    Okay: boolean(a == b)
    Okay: boolean(a != b)
    Okay: boolean(a <= b)
    Okay: boolean(a >= b)
    Okay: def foo(arg: int = 42):
    Okay: async def foo(arg: int = 42):

    E251: def complex(real, imag = 0.0):
    E251: return magic(r = real, i = imag)
    E252: def complex(real, image: float=0.0):
    rFNz8E251 unexpected spaces around keyword / parameter equalsz/E252 missing whitespace around parameter equalsrrrr�Tr�r')�boolr�rer�r�r�)rHr�r��no_space�
require_spacer	�annotated_func_arg�in_def�message�missing_messager�r�r�r�r�r6r6r7�(whitespace_around_named_parameter_equals�sT�






�
�r5c
cs
�d}|D]}\}}}}}|tjkr{|d|d���}|r4|d|dkr4|d|ddkr4|dfV|�d�\}	}
}|	dvoJ|	�d	�dd�pJd	}|r]|sW|dd�tvr\|d
fVq|rz|dksi|ddkrz|d	krs|dfVq|rz|d
fVq|tjkr�|}qdS)u�Separate inline comments by at least two spaces.

    An inline comment is a comment on the same line as a statement.
    Inline comments should be separated by at least two spaces from the
    statement. They should start with a # and a single space.

    Each line of a block comment starts with a # and one or multiple
    spaces as there can be indented text inside the comment.

    Okay: x = x + 1  # Increment x
    Okay: x = x + 1    # Increment x
    Okay: # Block comments:
    Okay: #  - Block comment list
    Okay: #  - Block comment list
    E261: x = x + 1 # Increment x
    E262: x = x + 1  #Increment x
    E262: x = x + 1  #  Increment x
    E262: x = x + 1  #  Increment x
    E265: #Block comment
    E266: ### Block comment
    )rrNrrr
z.E261 at least two spaces before inline commentr1z#:rz*E262 inline comment should start with '# '�!z)E265 block comment should start with '# 'z+E266 too many leading '#' for block comment)r�r�r��	partitionr�rr�)
rHr�r	r�r�r�r�r��inline_comment�symbol�sp�comment�
bad_prefixr6r6r7�whitespace_before_comment%s4�
$�
�
�
��r=ccsL�|}|�d�r |�d�}d|kr"d|d|�vr$|dfVdSdSdSdS)a Place imports on separate lines.

    Okay: import os\nimport sys
    E401: import sys, os

    Okay: from subprocess import Popen, PIPE
    Okay: from myclas import MyClass
    Okay: from foo.bar.yourclass import YourClass
    Okay: import myclass
    Okay: import foo.bar.yourclass
    �import r�rFrNz!E401 multiple imports on one line)r��find)rHr�r�r6r6r7�imports_on_separate_linesRs�

�r@c#s��dd�}d}|rdS|sdS|rdS|���d�s��d�r,|�dd�r*d	VdSdSt�t��r4dSt�fd
d�|D��rAdS|��rW|�dd�rQd
|d<dSd
|d<dSd
|d<dS)a�Place imports at the top of the file.

    Always put imports at the top of the file, just after any module
    comments and docstrings, and before module globals and constants.

    Okay: import os
    Okay: # this is a comment\nimport os
    Okay: '''this is a module docstring'''\nimport os
    Okay: r'''this is a module docstring'''\nimport os
    E402: a=1\nimport os
    E402: 'One string'\n"Two string"\nimport os
    E402: a=1\nfrom sys import x

    Okay: if x:\n    import os
    cSsP|ddvr|dd�}|r|ddvr|dd�}|o'|ddkp'|ddkS)Nr�uUbBr�rR�"r�r6�r�r6r6r7�is_string_literalxs
z8module_imports_on_top_of_file.<locals>.is_string_literal)r?r@r>rArBr<r=Nr>zfrom �seen_non_importsF)rz+E402 module level import not at top of filec3s�|]}��|�VqdS�N�r�)r4�kwrDr6r7r8���z0module_imports_on_top_of_file.<locals>.<genexpr>�seen_docstringT)r�r��rere�DUNDER_REGEX�any)rHr��
checker_stater�rE�allowed_keywordsr6rDr7�module_imports_on_top_of_filefs.�
�rQccs��|}t|�d}|�d�}d}dd�dD�}d|kr!|kr�nnzt|||�|�|d|d	kr�|d
|dkr�|d|d
kr�||ddkr�t�|d|�}|ru|d|�����}|dd�dkrt|dd�����rtdVn(t	�
|�r~dVn
t�
|�r�|dfV|}|�d|d�}d|kr�|ks#n|�d�}d|kr�||kr�|dfVn|dfV|�d|d�}d|ks�dSdS)a�Compound statements (on the same line) are generally
    discouraged.

    While sometimes it's okay to put an if/for/while with a small body
    on the same line, never do this for multi-clause statements.
    Also avoid folding such long lines!

    Always use a def statement instead of an assignment statement that
    binds a lambda expression directly to a name.

    Okay: if foo == 'blah':\n    do_blah_thing()
    Okay: do_one()
    Okay: do_two()
    Okay: do_three()

    E701: if foo == 'blah': do_blah_thing()
    E701: for x in lst: total += x
    E701: while t < 10: t = delay()
    E701: if foo == 'blah': do_blah_thing()
    E701: else: do_non_blah_thing()
    E701: try: something()
    E701: finally: cleanup()
    E701: if foo == 'blah': one(); two(); three()
    E702: do_one(); do_two(); do_three()
    E703: do_four();  # useless semicolon
    E704: def f(x): return 2*x
    E731: f = lambda x: 2*x
    rr�rcSsi|]}|d�qS)rr6)r4rkr6r6r7�
<dictcomp>�sz'compound_statements.<locals>.<dictcomp>z{}[]()rFr
rrrrr�r'N)rz1E731 do not assign a lambda expression, use a def)rz*E704 multiple statements on one line (def)z,E701 multiple statements on one line (colon)rz0E702 multiple statements on one line (semicolon)z$E703 statement ends with a semicolon)rur?�
update_counts�LAMBDA_REGEX�searchr�rtr��isidentifierr�re�!STARTSWITH_INDENT_STATEMENT_REGEX)rHr��	last_charr��
prev_found�counts�	lambda_kwr�r6r6r7�compound_statements�s@�
$


�

�r\ccs��d}}}d}d}|D]_\}}}	}
}|tjkrd}|	d|kr,|r,|r,|s,|dfV|
d|krR|�d��d�rI|
dt|��d�d	f}nd}|
d}}n|	d}|tjkrl|d
vrd|d	7}q
|dvrl|d	8}q
dS)aBAvoid explicit line join between brackets.

    The preferred way of wrapping long lines is by using Python's
    implied line continuation inside parentheses, brackets and braces.
    Long lines can be broken over multiple lines by wrapping expressions
    in parentheses.  These should be used in preference to using a
    backslash for line continuation.

    E502: aaa = [123, \\n       123]
    E502: aaa = ("bbb " \\n       "ccc")

    Okay: aaa = [123,\n       123]
    Okay: aaa = ("bbb "\n       "ccc")
    Okay: aaa = "bbb " \\n    "ccc"
    Okay: aaa = 123  # \\
    rFNTz0E502 the backslash is redundant between bracketsrx�\rFrr�r�)r�r�rtr�ru�
splitlinesr�)rHr��
prev_startr	r�r;�	backslashr�r�r�r�r�r6r6r7�explicit_line_join�s,�



��raz()[]{},:.;@=%~)z...cCs|tjkp|dvo|tvS)N>r+r()r�r��
_SYMBOLIC_OPS)r�r�r6r6r7�_is_binary_operator
s

��rcc
cs~�d}d}d}d}|D]1\}}}}}	|tjkrqd|vs d|vr(|tjkr(d}q|||||||fV|dv}d}|}|}qdS)z�Private function to reduce duplication.

    This factors out the shared details between
    :func:`break_before_binary_operator` and
    :func:`break_after_binary_operator`.
    FTNrprqz([{,;)r�r�r�)
r��
line_break�
unary_context�previous_token_type�
previous_textr�r�r�r�r�r6r6r7�_break_around_binary_operatorss$�
��rhc
csL�t|�D]}|\}}}}}}}	t||�r#|r#|s#t||�s#|	dfVqdS)a�
    Avoid breaks before binary operators.

    The preferred place to break around a binary operator is after the
    operator, not before it.

    W503: (width == 0\n + height == 0)
    W503: (width == 0\n and height == 0)
    W503: var = (1\n       & ~2)
    W503: var = (1\n       / -2)
    W503: var = (1\n       + -1\n       + -2)

    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    z&W503 line break before binary operatorN�rhrc)
rHr��contextr�r�rfrgrdrer�r6r6r7�break_before_binary_operator0s�
����
��rkccsT�d}t|�D] }|\}}}}}}	}
t||�r%|r%|	s%t||�s%|dfV|
}qdS)aF
    Avoid breaks after binary operators.

    The preferred place to break around a binary operator is before the
    operator, not after it.

    W504: (width == 0 +\n height == 0)
    W504: (width == 0 and\n height == 0)
    W504: var = (1 &\n       ~2)

    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: x = '' + '''\n'''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)

    The following should be W504 but unary_context is tricky with these
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)
    Nz%W504 line break after binary operatorri)rHr�r_rjr�r�rfrgrdrer�r6r6r7�break_after_binary_operatorNs �
�
���
�rlccs��|rdSt�|�D]J}|�d�p|�d�}|�d�dk}d|r"dnd|}|d	vr.d
}nd}|dkr6|p<|d
ko<|}|d|rCdnd7}|�d�d|||ffVq
dS)aXComparison to singletons should use "is" or "is not".

    Comparisons to singletons like None should always be done
    with "is" or "is not", never the equality operators.

    Okay: if arg is not None:
    E711: if arg != None:
    E711: if None == arg:
    E712: if arg == True:
    E712: if False == arg:

    Also, beware of writing if x when you really mean if x is not None
    -- e.g. when testing whether a variable or argument that defaults to
    None was set to some other value.  The other value might have a type
    (such as a container) that could be false in a boolean context!
    Nrrr
r&z'if cond is %s:'rUznot )r�E711�E712rrz or 'if %scond:'z %s comparison to %s should be %s)�COMPARE_SINGLETON_REGEXr�rfr�)rHr�re�	singleton�same�msgr��nonzeror6r6r7�comparison_to_singletonqs$��

��rtccsH�t�|�}|r"|�d�}|�d�dkr|dfVdS|dfVdSdS)aGNegative comparison should be done using "not in" and "is not".

    Okay: if x not in y:\n    pass
    Okay: assert (X in Y or X is Z)
    Okay: if not (X in Y):\n    pass
    Okay: zz = x is not y
    E713: Z = not X in Y
    E713: if not X.B in Y:\n    pass
    E714: if not X is Y:\n    pass
    E714: Z = not X.B is Y
    rr
r)z+E713 test for membership should be 'not in'z0E714 test for object identity should be 'is not'N)�COMPARE_NEGATIVE_REGEXrUr�rf)rHrer�r6r6r7�comparison_negative�s�


�rvccsP�t�|�}|r$|s&|�d�}|r|��r|tvrdS|��dfVdSdSdS)z�Object type comparisons should `is` / `is not` / `isinstance()`.

    Do not compare types directly.

    Okay: if isinstance(obj, int):
    Okay: if type(obj) is int:
    E721: if type(obj) == type(1):
    rNzgE721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()`)�COMPARE_TYPE_REGEXrUrfrVr�r�)rHr�re�instr6r6r7�comparison_type�s�



��ryccs.�|rdSt�|�}|r|��dfVdSdS)z�When catching exceptions, mention specific exceptions when
    possible.

    Okay: except Exception:
    Okay: except BaseException:
    E722: except:
    NzE722 do not use bare 'except')�BLANK_EXCEPT_REGEXrer�)rHr�rer6r6r7�bare_except�s�	
�r{ccs��d}d}d}d}|d\}}}}	}
tdt|��D]�}||\}}
}}}d}}|dvr1|}d}n|dur?|
dkr?||kr?d}|
d	vrH|d7}n|
d
vrP|d8}|
dks\|
dkrd|dkrd||vrd|}|}|d
vrp|
|vrp|
}|}|dur�|s�|t|�dkr�||dddvr�|dvr�|
|vr�|
}|}|dkr�|
|vr�|d|
fV|dkr�|
|vr�|d|
fV|r�|d|fV|
}|}qdS)a�Never use the characters 'l', 'O', or 'I' as variable names.

    In some fonts, these characters are indistinguishable from the
    numerals one and zero. When tempted to use 'l', use 'L' instead.

    Okay: L = 0
    Okay: o = 123
    Okay: i = 42
    E741: l = 0
    E741: O = 123
    E741: I = 42

    Variables can be bound in several other contexts, including class
    and function definitions, lambda functions, 'global' and 'nonlocal'
    statements, exception handlers, and 'with' and 'for' statements.
    In addition, we have a special handling for function parameters.

    Okay: except AttributeError as o:
    Okay: with lock as L:
    Okay: foo(l=12)
    Okay: foo(l=I)
    Okay: for a in foo(l=12):
    Okay: lambda arg: arg * l
    Okay: lambda a=l[I:5]: None
    Okay: lambda x=a.I: None
    Okay: if l >= 12:
    E741: except AttributeError as O:
    E741: with lock as l:
    E741: global I
    E741: nonlocal l
    E741: def foo(l):
    E741: def foo(l=12):
    E741: l = foo(l=12)
    E741: for l in range(10):
    E741: [l for l in lines if l]
    E741: lambda l: None
    E741: lambda a=x[1:5], l: None
    E741: lambda **l:
    E741: def f(**l):
    E742: class I(object):
    E743: def l(x):
    NFr)r�O�Ir>r:rr�Tr�r�r,r')�asr;�global�nonlocalz:,=)>rrrr�rrCz$E742 ambiguous class definition '%s'r:z'E743 ambiguous function definition '%s'z!E741 ambiguous variable name '%s')r�ru)rHr��
func_depth�
seen_colon�brace_depth�idents_to_avoidrrr_r	rrnr�r�r�r�r��identr�r6r6r7�ambiguous_identifier�s^�,
�$�r�c	cs*�|rdSgd�}g}|D]�\}}}}}|tjthvr+|�|d|�|d�����|tjthvr�d|dvr�|\}	}
|�d�}|dkr�|d7}|||vr{|	|�dd|�}||	kra|
|}
n||�	dd|�d}
||
dfd	||�d
�fV|�d|d�}|dksE|tjt
hvr�|��q
dS)zsInvalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'
    N)rpr]r�rC�a�br�n�r�t�v�0�1�2�3�4�5�6�7�x�N�u�UrFr�r]rrrpzW605 invalid escape sequence '\r�)r�r�r�r�rn�lower�FSTRING_MIDDLEr?�count�rfindrr�)rHr�r��valid�prefixesr�r�r��_�
start_line�	start_colr�r��colr6r6r7�#python_3000_invalid_escape_sequence7s8� 


����r�ccsx�|dus|r	dSd}t�}|D]\}}}}	}
|t�tjg�vr%|�|
�q|D]�\}}}}	}
|tjkr7|r7q(|tjtjfvr�|dusG|tvr�|
��}t	|�D]g\}}
|d|dkrd|
�
d�rddSt|
�}|
��}|tjkr�t|�dkr�|t|d�t
kr�qOt|�dkr�|dt|�kr�t|�dkr�|t|d�t
kr�qO||kr�|d||f}|d||ffVqO|}q(dS)z�Limit all doc lines to a maximum of 72 characters.

    For flowing long blocks of text (docstrings or comments), limiting
    the length to 72 characters is recommended.

    Reports warning W505
    Nrrr~r
rFz+W505 doc line too long (%d > %d characters))�setr�unionr�r��addr��SKIP_TOKENSr^rgr�rur��MAX_DOC_LENGTH)rH�max_doc_lengthr�r��
prev_token�
skip_linesr�r�r�r�r�ry�line_numrGr�r��	doc_errorr6r6r7�maximum_doc_lengthtsH�	
�
���r�cCs�zt�|��
}|��Wd�WS1swYWdStttfyFt|dd��}|��Wd�YS1s>wYYdSw)zRead the source code.Nzlatin-1)�encoding)r��open�	readlines�LookupError�SyntaxError�UnicodeError)�filenamerr6r6r7r��s(�*��r�cCstjtjjdd���S)zRead the value from stdin.�ignore)�errors)�io�
TextIOWrapperr�stdin�buffer�readr6r6r6r7�stdin_get_value��r�iz# no(?:qa|pep8)\bcCsh|�d�}d|vrt|�t|���Sd}|D]}|dkr&|ddd}q|dkr/|d7}q|S|S)zXReturn the amount of indentation.

    Tabs are expanded to the next multiple of 8.
    z

rmrr�r1r)rtrur�)r��resultrkr6r6r7r��s

r�cCsb|�|d�d}t|�d}|dd�dvr|d7}|d8}|d|�d||||d�S)z7Replace contents with 'xxx' to prevent syntax matching.rFr���N)z"""z'''r
r�)rnru)r�r�r�r6r6r7�mute_string�s$r��.c	s�i}d}}|��D]]}|r|dd�dkr|d8}q
|dd�dkr@t�|�}dd�|��D�\}}||�t|||��q
|dd�dkrg|d	d��d
d�d}|dd�d
vrb|dd�}t�||<q
��fdd�|��D�S)z&Return a dictionary of matching lines.Nrrrz@@ css�|]	}t|pd�VqdS)r�N)�int)r4�gr6r6r7r8�r9zparse_udiff.<locals>.<genexpr>z+++rrmrr
)zb/zw/zi/cs.i|]\}}|rt|��rtj��|�|�qSr6)�filename_match�os�path�join)r4�filepath�rows��parent�patternsr6r7rR�s���zparse_udiff.<locals>.<dictcomp>)	r^�
HUNK_REGEXrer��updater�r�r��items)	�diffr�r��rvr�r�r��
hunk_matchr�r6r�r7�parse_udiff�s(

��r�cCsd|sgSt|t�r|Sg}|�d�D]}|��}d|vr'tj�tj�||��}|�|�	d��q|S)zQParse a comma-separated list of paths.

    Return a list of absolute paths.
    r�r)
�
isinstancer�r�r�r�r��abspathr�r�rt)�valuer��pathsr�r6r6r7�normalize_paths�s
r�Tcs|s|St�fdd�|D��S)z{Check if patterns contains a pattern that matches filename.

    If patterns is unspecified, this always returns True.
    c3s�|]}t�|�VqdSrGr)r4�pattern�r�r6r7r8rJz!filename_match.<locals>.<genexpr>)rN)r�r�rr6r�r7r�
sr�cCs&|D]}||vr||d7<qdS)z^Adds one to the counts of each appearance of characters in s,
        for characters in countsrNr6)r5rZrkr6r6r7rSs
��rScCs,|dtvp|d|ddd���dkS)Nrrrrz\
)r�r�)�tokenr6r6r7�
_is_eol_tokens,r�c@sxeZdZdZ		ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zddd�ZdS)�Checkerz;Load a Python source file, tokenize it, check coding style.Nc	Ks�|dur
t|�j}n|rJ�d|_|j|_|j|_|j|_|j	|_	|j
|_
|j|_d|_d|_
|j|_|j|_|j|_||_i|_|durNd|_|pKg|_n=|dkr]d|_t��d�|_n.|dur�zt|�|_Wn"ty�t��dd�\}}|j�d|��|_g|_Ynw||_|jr�t|jdd�}|dvr�|d	kr�|jdd
d�|jd<n|jddd�dkr�|jddd�|jd<|p�|j|_|jj|_d|_dS)
NrFr�rTr
�: )���r�rru)�
StyleGuide�options�	_io_error�physical_checks�_physical_checks�logical_checks�_logical_checks�
ast_checks�_ast_checksr�r�r��
fstring_startr�r�r�r��_checker_statesryr�r^r��OSErrorr�exc_info�__name__�ord�reportr��report_errorr�)	r\r�ryr�r��kwargs�exc_type�exc�ord0r6r6r7rb(sT
�

zChecker.__init__c	Cs�t��dd�\}}t|j�dkr#|jd}t|�dkr"|dd�}nd}|�|d|dp/dd|j�d|jd��|j�dS)	zCheck if the syntax is valid.Nr
rr)rrrzE901 r�)rr�rurZr�r��report_invalid_syntax)r\r�r�rjr6r6r7r�Ws
��zChecker.report_invalid_syntaxcCsR|j|jkrdS|j|j}|jd7_|jdur'|dd�tvr'|d|_|S)z(Get the next line from the input buffer.rUrNr)rzr{ryrhr)r\r�r6r6r7�readlineds
zChecker.readlinecCs&g}|D]
}|�t||��q||�S)zRun a check plugin.)r��getattr)r\rX�argument_names�	argumentsrLr6r6r7�	run_checknszChecker.run_checkcCs d|vr|j�|i�|_dSdS)z5Prepare custom state for the specific checker plugin.rON)r��
setdefaultrO)r\rLr�r6r6r7�init_checker_stateus�zChecker.init_checker_statecCsp||_|jD]/\}}}|�||�|�||�}|dur5|\}}|�|j|||�|dd�dkr5|d|_qdS)z,Run all physical checks on a raw input line.Nr�E101r)rGr�r�r�r�rzrh)r\r�rLrXr�r�rjr�r6r6r7�check_physicalzs
��zChecker.check_physicalcCs8g}g}d}d}}}|jD]z\}}}	}
}|tvrq|s"d|	fg}|tjkr-|�|�q|tjkr7t|�}n
|tkrAdt|�}|rs|	\}}
||krg|j	|d|d}|dksb|dvrf|dvrfd|}n||
krs|||
�|}|�|�|t|�7}|�||
f�|
\}}qd	�
|�|_|o�td	�
|��|_|S)
z!Build a logical line from tokens.rNr�rr�z{[(r�r1rU)
r�r�r�r�r�r�r�r�ruryr�rHr�)r\�logical�commentsr��prev_row�prev_col�mappingr�r�r�r�r��	start_rowr�rr6r6r7�build_tokens_line�sB




�

zChecker.build_tokens_linec
Cs\|j��|��}|s
dSdd�|D�}|dd\}}|j|d}t|d|��|_|j|jkr6|j|_|jdkrFt	|j
dd����|jD]J\}}}|jdkrYt	d	|�|�
||�|�||�pfd
D]+\}	}
t|	t�s�|t�||	�\}}|d|d|	|f}	|�|	d|	d|
|�qgqI|j
r�|j|_|j
|_|js�|j
|_d|_g|_dS)z:Build a line from tokens and run all logical checks on it.NcSsg|]\}}|�qSr6r6)r4rjr�r6r6r7rN�sz)Checker.check_logical.<locals>.<listcomp>rrr
�Prz   r6)r��increment_logical_linerryr�r�r�r�r�rrHrtr�r�r�r��tuple�bisect�bisect_leftr�r�r�r�r�)
r\r�mapping_offsetsrr�r�rLrXr�rjr��token_offsetr�r6r6r7�
check_logical�s>




��
zChecker.check_logicalc

Cs�z
td�|j�ddt�}Wntttfy|��YSw|jD]*\}}}|||j	�}|�
�D]\}}}}	|jrBt|j|d�sJ|�||||	�q0q!dS)z,Build the file's AST and run all AST checks.rU�execrN)
�compiler�ry�
PyCF_ONLY_AST�
ValueErrorr��	TypeErrorr�r�r��runr�r�)
r\rIrL�clsr�checker�linenorjr�rXr6r6r7�	check_ast�s����zChecker.check_astc	cs��|jr|�ddd|jt�t�|j�}z/d}|D]'}|dd|jkr)WdS|do2t|d�|_|�||�|V|d}qWdSt	tj
fyU|��YdSw)z9Tokenize file, run physical line checks and yield tokens.rrzE902 %srUr
Nr)r�r�r�r��generate_tokensr�r{r��maybe_check_physicalr��
TokenErrorr�)r\�tokengen�
prev_physicalr�r6r6r7r�s"�
��zChecker.generate_tokenscCs�|jtkr
|jd|_dSt|�r%|jdkr|�|�dS|�|j�dS|jtjkr0d|j	vs5|jt
krut|j�r<dS|jt
krE|j}n|jd}|jd}d|_
||_t||�D]}|�|j|dd�|jd7_qZd|_
dSdS)z9If appropriate for token, check current physical line(s).rrUrpNTrF)r�r�r�r�r�r�rr�r�r�rr�r�r�rzr�ry)r\r�rr�r�rzr6r6r7r�s*







�zChecker.maybe_check_physicalrcCs�|j�|j|j||�t|j�|_|jr|��d|_d|_	d|_
|_d|_d|_
g|_d|_|_d}|��D]�}|j�|�|dd�\}}|jdkr�|dd|ddkrkd�|ddpcd|dd�}nd|dd}td	|dd|tj|d|f�|tjkr�|d
vr�|d7}q9|dvr�|d8}q9|s�|tvr�|tjkr�|��d|_q9t|j�dkr�|jd7_|jd=q9|��q9|jr�|�|jd�|��|j��S)
z!Run all checks on the input file.rNrUr
rz[{}:{}]rzl.%sz
l.%s	%s	%s	%rr�r�rF)r��	init_filer�ryrur{r�rrzrhr�r�r�r�r�r�r�rr�r�r�rr��tok_namer�r�rr�get_file_results)r\�expected�line_offsetr�r�r�r�r�r6r6r7�	check_allsT
"�

�

�
zChecker.check_all)NNNN�Nr)r��
__module__�__qualname__r`rbr�r�r�r�rrrrrrr$r6r6r6r7r�%s 
�/

##1r�c@sreZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zddd�Zddd�Z
ddd�Zdd�ZdS)�
BaseReportz"Collect the results of the checks.FcCs6|j|_|j|_d|_d|_t�|jd�|_i|_	dSr%)
�benchmark_keys�_benchmark_keys�ignore_code�_ignore_code�elapsed�total_errors�dict�fromkeys�counters�messages�r\r�r6r6r7rbMs
zBaseReport.__init__cCst��|_dS)zStart the timer.N)�time�_start_time�r\r6r6r7r�VszBaseReport.startcCst��|j|_dS)zStop the timer.N)r4r5r-r6r6r6r7�stopZszBaseReport.stopcCsN||_||_|p	d|_||_d|_|jdd7<|jdt|�7<dS)�Signal a new file.r6rr.rr0N)r�ryr"r#�file_errorsr1ru�r\r�ryr"r#r6r6r7r^s
zBaseReport.init_filecCs|jdd7<dS)zSignal a new logical line.r/rN)r1r6r6r6r7r	hr�z!BaseReport.increment_logical_linecCs�|dd�}|�|�r
dS||jvr|j|d7<nd|j|<|dd�|j|<||jvr1dS|jr<|js<t|j�|jd7_|jd7_|S)�&Report an error, according to options.Nrr�)	r,r1r2r"�print_filenamer9rr�r.�r\rzrjr�rXr�r6r6r7r�ls




zBaseReport.errorcCs|jS)z6Return the count of errors and warnings for this file.)r9r6r6r6r7r!szBaseReport.get_file_resultsrUcst��fdd��jD��S)z.Return the total count of errors and warnings.c3s$�|]
}|���r�j|VqdSrG)r�r1�r4�key��prefixr\r6r7r8�s�
�z'BaseReport.get_count.<locals>.<genexpr>)�sumr2�r\rBr6rAr7�	get_count�s�zBaseReport.get_countcs��fdd�t�j�D�S)a
Get statistics for message codes that start with the prefix.

        prefix='' matches all errors and warnings
        prefix='E' matches all errors
        prefix='W' matches all warnings
        prefix='E4' matches all errors that have to do with imports
        cs0g|]}|���rd�j||�j|f�qS)z
%-7s %s %s)r�r1r2r?rAr6r7rN�s
 �z-BaseReport.get_statistics.<locals>.<listcomp>)�sortedr2rDr6rAr7�get_statistics�s�zBaseReport.get_statisticscCs|�|�D]}t|�qdS)z9Print overall statistics (number of errors and warnings).N)rGr)r\rBr�r6r6r7�print_statistics�s
�zBaseReport.print_statisticscCsPtd�|jd��|jr$|jD]}td|j||j||j|f�qdSdS)zPrint benchmark numbers.z{:<7.2f} {}zseconds elapsedz%-7d %s per second (%d total)N)rr�r-r*r1)r\r@r6r6r7�print_benchmark�s
���zBaseReport.print_benchmarkN�rU)r�r&r'r`r=rbr�r7rr	r�r!rErGrHrIr6r6r6r7r(Hs	



r(c@seZdZdZdZdS)�
FileReportz:Collect the results of the checks and print the filenames.TN)r�r&r'r`r=r6r6r6r7rK�srKcs@eZdZdZ�fdd�Z�fdd�Z�fdd�Zdd	�Z�ZS)
�StandardReportz,Collect and print the results of the checks.cs>t��|�t�|j��|j�|_|j|_|j	|_
|j|_dSrG)
�superrb�
REPORT_FORMATr�r�r��_fmt�repeat�_repeat�show_source�_show_source�	show_pep8�
_show_pep8r3��	__class__r6r7rb�s�zStandardReport.__init__csg|_t��||||�S)r8)�_deferred_printrMrr:rVr6r7r�s�zStandardReport.init_filecsNt��||||�}|r%|j|dks|jr%|j�||||dd�|jf�|S)r;rr<N)rMr�r1rQrXr�r`r>rVr6r7r��s�zStandardReport.errorc	Cs�|j��|jD]U\}}}}}t|j|j|j||d||d��|jrK|t|j�kr/d}n|j|d}t|�	��tt
�dd|d|��d�|jrX|rXtd|�
��tj��q|jS)	z9Print results and return the overall count for this file.r)r�r�r�r�r�rUz\Sr1Nr z    )rX�sortrrOr�r#rSruryrtrL�subrUr�r�stdout�flushr9)r\rzrjr�r��docr�r6r6r7r!�s"

�
zStandardReport.get_file_results)	r�r&r'r`rbrr�r!�
__classcell__r6r6rVr7rL�srLcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�
DiffReportz9Collect and print the results for the changed lines only.cst��|�|j|_dSrG)rMrb�selected_lines�	_selectedr3rVr6r7rb�szDiffReport.__init__cs&||j|jvr
dSt��||||�SrG)rar�rMr�)r\rzrjr�rXrVr6r7r��szDiffReport.error)r�r&r'r`rbr�r^r6r6rVr7r_�sr_c@sXeZdZdZdd�Zddd�Zddd�Zdd
d�Zdd
�Zddd�Z	dd�Z
dd�ZdS)r�z-Initialize a PEP-8 instance with few options.c
OsJ|�dt�|_|�dd�}|�dd�}|�dd�}t|i|��}|r$dn|�dd�}|�dd�}t|||||�\}	|_|rL|	j�|�d|vrL|d|_|j	|_
|	|_|	js^|	j
r[tnt|	_t|	jpcd�|	_|	jsw|	jswtrwtt�d	��|	_n|	jr|d
nt|	j�|	_tdd�|	_|j|	_|�d�|	_|�d�|	_|�d
�|	_|��dS)N�
checker_class�
parse_argvF�config_file�parserr�r�r6r�rJrGrHrI)r�r�rbr/r��process_optionsr��__dict__r��
input_file�runnerr��reporter�quietr(rLr
�selectr��DEFAULT_IGNOREr��BENCHMARK_KEYSr)r+�
get_checksr�r�r��init_report)
r\rZr�rcrdre�options_dict�arglistr�r�r6r6r7rb�s8

�
zStyleGuide.__init__NcCs|p|jj|j�|j_|jjS)zInitialize the report instance.)r�rjr�)r\rjr6r6r7rp	szStyleGuide.init_reportcCs�|dur|j}|jj}|j}|��z|D]}tj�|�r#|�|�q|�	|�s,||�qWn
t
y;td�Ynw|��|S)zRun all checks on the paths.Nz... stopped)
r�r�r�rir�r�r��isdir�	input_dir�excluded�KeyboardInterruptrr7)r\r�r�rir�r6r6r7�check_files	s$
���zStyleGuide.check_filesrcCs4|jjr
td|�|j|||jd�}|j||d�S)z'Run all checks on a Python source file.zchecking %s)ryr�)r"r#)r�r�rrbr$)r\r�ryr"r#�fcheckerr6r6r7rh*	s�zStyleGuide.input_filecCs�|�d�}|�|�rdS|jjj}|jj}|jj}|j}t�	|�D]B\}}}|r.t
d|�|dd7<t|�D]
}	|�|	|�rG|�|	�q:t|�D]}
t
|
|�rb|�|
|�sb|tj�||
��qLq!dS)z9Check all files in this directory and all subdirectories.rrz
directory r-rN)rtrur�r�r1r�r�rir��walkrrF�remover�r�r�)r\�dirnamer1r��filepatternsri�root�dirsr.�subdirr�r6r6r7rt2	s0



��
����zStyleGuide.input_dircCsV|jjsdStj�|�}t||jj�rdS|rtj�||�}tj�|�}t||jj�S)zxCheck if the file should be excluded.

        Check if 'options.exclude' contains a pattern matching filename.
        FT)r��excluder�r��basenamer�r�r�)r\r�r�r�r6r6r7ruJ	szStyleGuide.excludedcsHt��dkrt�fdd�|jjD��rdS��|jj�o#��|jj�S)z�Check if the error code should be ignored.

        If 'options.select' contains a prefix of the error code,
        return False.  Else, if 'options.ignore' contains a prefix of
        the error code, return True.
        rc3s�|]}|���VqdSrGrHr3�r�r6r7r8`	s��z)StyleGuide.ignore_code.<locals>.<genexpr>F)rurNr�rlr�r�)r\r�r6r�r7r+Y	s��zStyleGuide.ignore_codecsRg}t|��D]\}}|\}}t�fdd�|D��r$|�|j||f�qt|�S)z�Get all the checks for this category.

        Find all globally visible functions where the first argument
        name starts with argument_name and which contain selected tests.
        c3s �|]}|o
��|�VqdSrG)r+)r4r�r6r6r7r8o	s�z(StyleGuide.get_checks.<locals>.<genexpr>)rVr�rNr�r�rF)r\�
argument_name�checksrX�attrsrYrZr6r6r7rof	s�zStyleGuide.get_checksrG)NNr)r�r&r'r`rbrprwrhrtrur+ror6r6r6r7r��s
%



r�cCs~t||dd�}gd�|_|jdddddd	�|jd
ddddd	�|jd
ddddd	�|jddddd�|jddtdd�|jddddd�|jddd d!d�|jd"dd d#td�|jd$dd%d&�|jd'dd(d&�|jd)dd*d&�|jd+dd,d&�|jd-d.d/td0d1�|jd2d.d/d3d4d1�|jd5d.d/td6d1�|jd7dd8d&�|jd9d:d;d<d�|jd=dd>d&�|�d?�}|jd@ddAd&�|S)Bz"Create the parser for the program.z%prog [options] input ...)�prog�version�usage)r�r�rlr�zmax-line-lengthzmax-doc-lengthzindent-sizezhang-closingr�r�rkz	show-pep8zshow-source�
statisticsr�z-vz	--verboserr�z(print status messages, or debug with -vv)r�action�helpz-qz--quietz+report only file names, or nothing with -qqz-rz--repeatT�
store_truez1(obsolete) show all occurrences of the same errorz--first�store_falserPz#show first occurrence of each error)r��destr�z	--excluder�z[exclude files or directories which match these comma separated patterns (default: %default)��metavarrr�z
--filenamez*.pyzjwhen parsing directories, only check filenames matching these comma separated patterns (default: %default)z--selectr�rUz&select errors and warnings (e.g. E,W6)z--ignorez2skip errors and warnings (e.g. E4,W) (default: %s)z
--show-sourcezshow source code for each error)r�r�z--show-pep8z3show text of PEP 8 for each error (implies --first)z--statisticszcount errors and warningsz--countzgprint total number of errors and warnings to standard error and set exit code to 1 if total is not nullz--max-line-lengthr�r�z3set maximum allowed line length (default: %default))r�r�rr�z--max-doc-lengthNzSset maximum allowed doc line length and perform these checks (unchecked if not set)z
--indent-sizez9set how many spaces make up an indent (default: %default)z--hang-closingzNhang closing bracket instead of matching indentation of opening bracket's linez--formatr�rz.set the error format [default|pylint|<custom>]z--diffzSreport changes only within line number ranges in the unified diff received on STDINzTesting Optionsz--benchmarkzmeasure processing speed)r�config_options�
add_option�DEFAULT_EXCLUDErm�MAX_LINE_LENGTH�INDENT_SIZE�add_option_group)r�r�rerfr6r6r7�
get_parsert	s��
���
�
�
�
�
������
�
�
��
��
�r�c	s�t��}|j}tj}tr tj�t�r |jrt	dt�|�
t�|o+tj�tj�|���}|rR|�
�fdd�t
D��rH�}|jrGt	d��n
tj���\�}|s0|rhtj�|�rh|jrct	d|�|�
|�d}|�|j�rt|j}n|�d�r�d}t�d�|r�d	d
�|jD�}	|�g�\}
}|�|�D]X}|�dd�|jvr�t	d
|�q�|jdkr�t	d�||�||���|�dd�}
|	|
}|dvr�|�||�}n|dvr�|�||�}n|�||�}|
dkr�t||�}t|
|
|�q�|j||
d�\}}|S)a{Read and parse configurations.

    If a config file is specified on the command line with the
    "--config" option, then only it is used for configuration.

    Otherwise, the user configuration (~/.config/pycodestyle) and any
    local configurations in the current directory or above will be
    merged together (in that order) using the read method of
    ConfigParser.
    zuser configuration: %sc3s�|]
}tj��|�VqdSrG)r�r�r�)r4�fn�r�r6r7r8�	s�zread_config.<locals>.<genexpr>zlocal configuration: in %szcli configuration: %sN�pep8z0[pep8] section is deprecated. Use [pycodestyle].cSsi|]
}|j|jp|j�qSr6)r�r�r��r4�or6r6r7rR�	�zread_config.<locals>.<dictcomp>r�rz  unknown option '%s' ignoredrz	  {} = {})r�r�)r�r�r�)rR)�configparser�RawConfigParser�configr��curdir�USER_CONFIGr��isfiler�rr�r��commonprefix�PROJECT_CONFIGr��has_sectionr��warnings�warn�option_list�
parse_argsr�r2r�r�r��getint�
getbooleanr��setattr)r�rZrrrer��cli_conf�	local_dir�tail�pycodestyle_sectionr��new_optionsr�opt�normalized_opt�opt_typer�r6r�r7�read_config�	sb
�




�
r�Fc	Cs0|st�}|�d�s#|jdd|jd�|j�fd�}|jdd|dd�|s)|s)g}|�|�\}}d	|_|d	ur:||_	|rS|sS|j
sJtd
d�tD��rNdg}n|�
d
�t||||�}|ob|jdkobt|_t|j�|_t|j�|_t|j�|_t|j�|_|j
r�t|_t�}t||j|d�|_t|j�}||fS)z�Process options passed either via arglist or command line args.

    Passing in the ``config_file`` parameter allows other tools, such as
    flake8 to specify their own options to be processed in pycodestyle.
    z--config�
Configurationz�The project options are read from the [%s] section of the tox.ini file or the setup.cfg file located in any parent folder of the path(s) being processed.  Allowed options are: %s.z, )�descriptionr�zuser config file locationr�Ncss�|]	}tj�|�VqdSrG)r�r��exists)r4rLr6r6r7r8
s��z"process_options.<locals>.<genexpr>r�zinput not specifiedrr)r��
has_optionr�r�r�r�r�r�rjr�r�rNr�r�r�rkrK�_parse_multi_optionsr�r�r�rlr�r_r�r�r`rF)	rrrcrdrer�rfr�rZr�r6r6r7rf�	sF
��
��

rfr�cCs|rdd�|�|�D�S|S)zgSplit and strip and discard empties.

    Turns the following:

    A,
    B,

    into ["A", "B"]
    cSsg|]
}|��r|���qSr6)r�r�r6r6r7rN>
r�z(_parse_multi_options.<locals>.<listcomp>)r�)r��split_tokenr6r6r7r�3
s
r�cCs�ddl}z|�|jdd��Wn	tyYnwtdd�}|j}|��}|jr,|��|jr3|�	�|j
rK|jrDtj
�t|j
�d�t�d�dSdS)	z.Parse options and run checks on Python source.rNcSs
t�d�S)Nr)r�exit)�signum�framer6r6r7�<lambda>I
s
z_main.<locals>.<lambda>T)rcrpr)�signal�SIGPIPE�AttributeErrorr�r�rwr�rH�	benchmarkrIr.r�r�stderr�writer�r�)r��style_guider�r�r6r6r7�_mainC
s$�
�r��__main__rG)Nr�)T)NFNNN)r�)�r`rr�rOr�r�r�rLrr4r�r�r�	functoolsr�optparserr�callabler�r�__version__r�rm�platformr��
expanduserr�r��getenv�ImportErrorr�r�r�r�r�rNr�	frozensetr��kwlistr#r"r r�r$r!rr�r��INDENT�DEDENTr�r��
ERRORTOKENrrnrrdr^r�r�r+rorurwr�rrTr�r�r�r�rWrMrzr�r�rrVrTrcrlrorwr}r�r�r�r�r�r�r�r�r
rr*r-r5r=r@rQr\rarbrcrhrkrlrtrvryr{r�r�r�r�r�r}rUr�r�r�r�r�r�r�rSr�r�r(rKrLr_r�r�r�rfr�r�r�r6r6r6r7�<module>sf
�
�����






�




�







%#
U
 


)
N
(

!

A
,

6
@
+	

"
$



c
<
4


	%Z6

AJ
�
4

�