Your IP : 216.73.216.196


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

B

���]�F�@sdZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
m
Z
yddlmZddlmZWn ek
r�ddlmZYnXdZd	Zd
Zy<ejdkr�ej�d�Zn ej�e�d
�p�ej�d�d�ZWnek
�rdZYnXdZej�ej�e�d�Z dZ!ddd�Z"dZ#e$dddg�Z%e$ej&dg�e%Z'e$dddddg�Z(e$ddd d!ddg�Z)e)�*d"d#d$d%dd&g�Z+e$d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:g�Z,e$d;�Z-e$e	j.e	j/g�Z/e/�*e	j0e	j1g�Z2e2�*e	j3e	j4g�Z5d<d=d>d?gZ6e�7d@�Z8e�7dA�Z9e�7dB�Z:e�7dC�Z;e�7dD�Z<e�7dE�Z=e�7dF�Z>e�7dG�Z?e�7dH�Z@e�7dI�ZAe�7dJd$�e'��ZBe�7dK�ZCe�7dL�ZDe�7dM�ZEe	�FdNgjG��Hd�dOdNkZIdPdQ�ZJdRdS�ZKdTdU�ZLdVdW�ZMdXdY�ZNdZd[�ZOd\d]�ZPd^d_�ZQd`da�ZRdbdc�ZSddde�ZTdfdg�ZUdhdi�ZVdjdk�ZWdldm�ZXdndo�ZYdpdq�ZZdrds�Z[dtdu�Z\dvdw�Z]dxdy�Z^dzd{�Z_d|d}�Z`d~d�Zad�d��Zbd�d��Zcd�d��Zdd�d��Zed�d��Zfd�d��Zgejhd�k�r�d�d��Zie�7d��jjZkejljmZnnd�d��ZieojkZkd�d��Zne�7d�ejp�jqZrd�d��Zsd�d��Ztd�d�d��Zuejvfd�d��Zwd�d�d��Zxd�d��ZyeI�rJeyfd�d��Zyiiid��Zzd�d��Z{d�d�d��Z|d�d��Z}e}�Gd�d��d�e~�ZGd�d��d�e~�Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e~�Z�defd�d��Z�d�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�e�d�k�re��dS)�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
�)�with_statementN)�OptionParser)�fnmatch)�RawConfigParser)�
TextIOWrapperz2.0.0z'.svn,CVS,.bzr,.hg,.git,__pycache__,.toxz!E121,E123,E126,E226,E24,E704,W503�win32z~\.pep8ZXDG_CONFIG_HOMEz	~/.configZpep8)z	setup.cfgztox.ini�	testsuite�Oz+%(path)s:%(row)d:%(col)d: %(code)s %(text)sz%%(path)s:%(row)d: [%(code)s] %(text)s)�defaultZpylinti�False�None�True�printz>>z**�*�+�-�/z//�^�&�|z<<�%z**=z*=z/=z//=z+=z-=z!=z<>�<�>z%=z^=z&=z|=z==z<=z>=z<<=z>>=�=z 	�directories�filesz
logical lineszphysical linesz([ \t]*)zraise\s+\w+\s*,zraise\s+\w+\s*,.*,\s*\w+\s*$z\b[A-Z]\d{3}\bz	u?r?["\']z[[({] | []}),;:]z[,;:]\s*(?:  |\t)z?(\bNone|\bFalse|\bTrue)?\s*([=!]=)\s*(?(1)|(None|False|True))\bz!\b(not)\s+[^][)(}{ ]+\s+(in|is)\szE(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type|\s*\(\s*([^)]*[^ )])\s*\))z(\s*)\b(?:%s)\b(\s*)z'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)z
\blambda\bz*^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$z#
�cCs:t�|��d�}x$t|�D]\}}||kr|dfSqWdS)aINever 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
    E101: if a == 0:\n        a = 1\n\tb = 1
    rz/E101 indentation contains mixed spaces and tabsN)�INDENT_REGEX�match�group�	enumerate)�
physical_line�indent_char�indent�offset�char�r&�</opt/alt/python37/lib/python3.7/site-packages/pycodestyle.py�tabs_or_spaces�s
r(cCs*t�|��d�}d|kr&|�d�dfSdS)z�For new projects, spaces-only are strongly recommended over tabs.

    Okay: if True:\n    return
    W191: if True:\n\treturn
    r�	zW191 indentation contains tabsN)rrr�index)r!r#r&r&r'�
tabs_obsolete�sr+cCsH|�d�}|�d�}|�d�}|�d�}||krD|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)r!�strippedr&r&r'�trailing_whitespace�s




r2cCs0||kr,|��}|sdS||kr,t|�dfSdS)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 filezW292 no newline at end of fileN)r/r0)r!�lines�line_number�total_linesZstripped_last_liner&r&r'�trailing_blank_lines�sr6cCs�|��}t|�}||kr�t|�s�|��}t|�dkr8|sPt|�dkrp|ddkrpt|�t|d�|dkrpdSt|d�r�yt|�d	��}Wntk
r�YnX||kr�|d
||ffSdS)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�r�#����N�decodezutf-8z'E501 line too long (%d > %d characters))r/r0�noqa�split�hasattrr;�UnicodeError)r!�max_line_length�	multiline�line�lengthZchunksr&r&r'�maximum_line_length�s 
rDccs�|dkr|sdS|�d�r&|r�dVnf|dks:|rJ|dkrJdd|fVnB|�d�r�|rv|s�||ks�t�|�s�d	Vn|dkr�dd
|fVdS)a"Separate 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\n# Foo\n# Bar\n\ndef b():\n    pass

    E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef 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
    �N�@)rz/E304 blank lines found after function decoratorr7rzE303 too many blank lines (%d))zdef zclass rF)rz#E301 expected 1 blank line, found 0z%E302 expected 2 blank lines, found %d)�
startswith�DOCSTRING_REGEXr)�logical_line�blank_lines�indent_levelr4�blank_before�previous_logical�previous_indent_levelr&r&r'rJ�s


rJccs�|}x|t�|�D]n}|��}|��}|��}||dkrL|dd|fVq||ddkr|dkrhdnd}|d||ffVqWd	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
    � rzE201 whitespace after '%s'�,z}])ZE202ZE203z%s whitespace before '%s'N)�EXTRANEOUS_WHITESPACE_REGEX�finditerr�strip�start)rIrBr�textr%�found�coder&r&r'�extraneous_whitespacesrXccs�x�t�|�D]|}|��\}}d|kr6|�d�dfVnt|�dkrR|�d�dfVd|krl|�d�dfVqt|�dkr|�d�dfVqWdS)	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
    r)rzE274 tab before keywordz#E272 multiple spaces before keywordr7zE273 tab after keywordz"E271 multiple spaces after keywordN)�
KEYWORD_REGEXrR�groupsrTr0)rIr�before�afterr&r&r'�whitespace_around_keywords3s	r]ccsB|}d}|�d�r>|�|�}d|kr>|t|�d}|dfVdS)z�Multiple imports in form from x import (a, b, c) should have space
    between import statement and parenthesised name list.

    Okay: from foo import (bar, baz)
    E275: from foo import(bar, baz)
    E275: from importable.module import(bar, baz)
    z import(zfrom r9rz%E275 missing whitespace after keywordN)rG�findr0)rIrBZ	indicatorrV�posr&r&r'�'missing_whitespace_after_import_keywordJs

r`ccs�|}x�tt|�d�D]�}||}|dkr||dtkr|d|�}|dkrx|�d�|�d�krx|�d�|�d�krxq|dkr�||dd	kr�q|d
|fVqWdS)z�Each comma, semicolon or colon should be followed by whitespace.

    Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
    rz,;:N�:�[�]�{rP�)z"E231 missing whitespace after '%s')�ranger0�
WHITESPACE�count�rfind)rIrBr*r%r[r&r&r'�missing_whitespace[s
rjccs�|rdnd}|rdnd}|dr6d|d|dffV|�d�}|rd||krdd|d	|d
ffVn"|s�||kr�d|d|dffVdS)
a�Use 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
    rrEzE11%d %szE11%d %s (comment)�rz%indentation is not a multiple of fourrar7zexpected an indented blockzunexpected indentationN)�endswith)rIrMr"rKrN�cZtmplZ
indent_expectr&r&r'�indentationus
rnc'cs�|ddd}d|ddd|}|s4|dkr8dS|�d�}	d}
}|dkrVdnd	}dg|}
dg|}dgg}dg}i}|dd}d}d
}|dg}|dkr�td|dd
����x�|D�]�\}}}}}|
|d|k}|�r|d|}
|�o|tk}|�r|}|dk�r,td|���t|�|||
<|tjk�oN|dk}x6t||�D]&}||
||}||k}|�r^P�q^W||�r�|||k}|�o�|dk�o�|�|d�}|�r�||�r�|d||k�r|dfV�n|�r|�s|�r|dfVn�||�r>|d||k�r>|dk	�r|dfVn�|�sX|	�rx||
dk�rx|�rn|�sn|dfV|||<n�|dk�r�|d||<np||t	fk�r�n`|dk�r�d} nB||�r�d} n2|�s�||�r�d} n|||<|d
k�r�d} nd} |d| fV|
|
�r^|tj
tjfk�r^||�s^|d||<d||d<|d
k�r�td||df�n�|tjtjfk�sz|dk�r�t	||d<n\|�s�|
�s�|�s�|dk�r�d||dd<n.|dk�r�||dd��
��r�||�|
�|tjk�rz|dk�rr|d7}|�d�|�d�t|�|k�r.|�g�||�|
�|
|
d7<|d
k�rJtd ||d||f�n�|d!k�rJ|dk�rJ|���p�|d}!|��x(t|�D]}"||"|!k�r�d||"<�q�Wx"t|�D]}#|#|!k�r�||#=�q�W||dd�=|d8}|�rd|||<x2t|
dd�D]"}$|
|$�r$|
|$d8<P�q$Wt|�|dk�s`t�|d|k�rz|||d<|d|dk}|r�||
||d|<q�W|	�r�t|�|d
k�r�|d|dd
f}%|�r�d"}&nd#}&|%d$|&fVdS)%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)
    rr7rr9Nrar))rk)rk�FrEz>>> rkz... z]})z6E124 closing bracket does not match visual indentationz+E133 closing bracket is missing indentationTz7E128 continuation line under-indented for visual indentrozIE123 closing bracket does not match indentation of opening bracket's line)ZE122z missing indentation or outdented)ZE127zover-indented for visual indent)ZE131zunaligned for hanging indent)ZE126z over-indented for hanging indent)ZE121z!under-indented for hanging indentz%s continuation line %szbracket depth %s indent to %s)�uZur�b�br�ifz([{z.bracket depth %s seen, col %s, visual min = %sz)]}zE129 visually indented linezE125 continuation linez(%s with same indent as next logical line)rlrr/�NEWLINE�
expand_indent�tokenize�OP�reversed�get�str�NL�COMMENT�STRING�isspace�appendr0�poprf�list�AssertionError)'rI�tokensrK�hang_closingr"r<�verboseZ	first_row�nrowsZindent_next�rowZdepthZvalid_hangs�parensZ
rel_indentZ	open_rowsZhangsZindent_chancesZlast_indentZ
visual_indentZlast_token_multiliner#�
token_typerUrT�endrB�newlineZ
close_bracketZopen_rowZhangZhanging_indent�errorZprev_indent�dZind�idxr_rWr&r&r'�continued_indentation�s�
















 






r�ccs�|d\}}}}}x�tdt|��D]�}||\}}}	}
}|tjkr�|dkr�|	|kr�|tjksd|dkr�|dks�||dddkr�t�|�s�|d|fV|}|}|
}q"WdS)	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]
    rrz([z}])r7�classzE211 whitespace before '%s'N)rfr0rvrw�NAME�keyword�	iskeyword)rIr��	prev_type�	prev_text�__�prev_endr*r�rUrTr�r&r&r'�whitespace_before_parameters[s

r�ccs�x�t�|�D]|}|��\}}d|kr6|�d�dfVnt|�dkrR|�d�dfVd|krl|�d�dfVqt|�dkr|�d�dfVqWdS)	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
    r)rzE223 tab before operatorz$E221 multiple spaces before operatorr7zE224 tab after operatorz#E222 multiple spaces after operatorN)�OPERATOR_REGEXrRrZrTr0)rIrr[r\r&r&r'�whitespace_around_operator{s	r�ccs�d}d}tj}d}}�x�|D�]�\}}}	}
}|tkr8q|dkrJ|d7}n|dkrZ|d8}|�r
|	|kr�|dk	r�|ds�|ddfVd}n||d	kr�|d
kr�nj|dks�|dr�|dfVnJ|dk�rd\}}
|d
kr�d\}}
n|tkr�d\}}
|dd||
ffVd}n�|tjk�r�|dk	�r�|dk�r2|�r2nP|tk�rBd}n@|tk�rt|tjk�rd|dk�r�n
|tk�r�d}n|tk�r�d}|dk�r�||	|kf}n|�r�|	|k�r�|dfVd}|}|}|
}qWdS)aASurround operators with a single space on either side.

    - 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).

    - 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]

    E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)
    rFN)�(�lambdarreTz'E225 missing whitespace around operatorr)rrz**)ZE226Z
arithmeticr)ZE228Zmodulo)ZE227zbitwise or shiftz(%s missing whitespace around %s operatorrz}]))rvrw�
SKIP_COMMENTS�
ARITHMETIC_OP�WS_NEEDED_OPERATORS�UNARY_OPERATORS�KEYWORDS�WS_OPTIONAL_OPERATORS)rIr�r�Z
need_spacer�r�r�r�rUrTr�rBrWZoptyper&r&r'�"missing_whitespace_around_operator�sb








r�ccsb|}xXt�|�D]J}|��d}d|��krD|d|��dfVq|d|��dfVqWdS)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)
    rr)zE242 tab after '%s'rzE241 multiple spaces after '%s'N)�WHITESPACE_AFTER_COMMA_REGEXrRrTr)rIrB�mrVr&r&r'�whitespace_around_comma�s	r�c
cs�d}d}d}d}|�d�}d}x�|D]�\}}	}
}}|tjkr>q$|rXd}|
|krX||fV|tjkr�|	dkrt|d7}nl|	dkr�|d8}nZ|r�|	d	kr�|dkr�d
}n@|r�|	dkr�|dkr�d}n&|r�|	dkr�|s�d
}|
|kr�||fV|s�d}|}q$WdS)
aDon'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.

    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)
    rFN)�defz	async defz8E251 unexpected spaces around keyword / parameter equalsz([rz)]raTrPr)rGrvr{rw)
rIr�r�Zno_spacer�Zannotated_func_argZin_def�messager�rUrTr�rBr&r&r'�(whitespace_around_named_parameter_equalss:






r�c
csd}�x|D]�\}}}}}|tjkr�|d|d���}|rj|d|dkrj|d|ddkrj|dfV|�d�\}	}
}|	dko�|	�d	�dd�p�d	}|r�|s�|dd�tkr�|d
fVn:|r�|dks�|ddkr�|d	kr�|dfVn|r�|d
fVq|tjkr|}qWdS)a{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 a single space
    (unless it is indented text inside the comment).

    Okay: x = x + 1  # Increment x
    Okay: x = x + 1    # Increment x
    Okay: # Block comment
    E261: x = x + 1 # Increment x
    E262: x = x + 1  #Increment x
    E262: x = x + 1  #  Increment x
    E265: #Block comment
    E266: ### Block comment
    )rrNrrr7z.E261 at least two spaces before inline commentrOz#:r8z*E262 inline comment should start with '# '�!z)E265 block comment should start with '# 'z+E266 too many leading '#' for block comment)rvr|rS�	partition�lstriprgr{)
rIr�r�r�rUrTr�rBZinline_commentZsymbolZsp�commentZ
bad_prefixr&r&r'�whitespace_before_comment2s(
$
r�ccs>|}|�d�r:|�d�}d|kr:d|d|�kr:|dfVdS)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
    zimport rPr9�;Nz!E401 multiple imports on one line)rGr^)rIrBrVr&r&r'�imports_on_separate_lines[s


r�c#s�dd�}d}|rdS|sdS|r$dS|���d�s<��d�rP|�dd�r�d	VnJt�fd
d�|D��rjdS|��r�|�dd�r�d
|d<q�d
|d<nd
|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
    Okay: try:\n    import x\nexcept:\n    pass\nelse:\n    pass\nimport y
    Okay: try:\n    import x\nexcept:\n    pass\nfinally:\n    pass\nimport y
    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|ddkr|dd�}|r4|ddkr4|dd�}|oN|ddkpN|ddkS)NrZuUbBrZrR�"�'r&)rBr&r&r'�is_string_literal�s
z8module_imports_on_top_of_file.<locals>.is_string_literal)�try�except�else�finallyNzimport zfrom Zseen_non_importsF)rz+E402 module level import not at top of filec3s|]}��|�VqdS)N)rG)�.0�kw)rBr&r'�	<genexpr>�sz0module_imports_on_top_of_file.<locals>.<genexpr>Zseen_docstringT)rGry�any)rIrK�
checker_stater<r�Zallowed_try_keywordsr&)rBr'�module_imports_on_top_of_filens&

r�ccsJ|}t|�d}|�d�}x�d|kr0|kr�nn�|d|�}|�d�|�d�kr�|�d�|�d�kr�|�d	�|�d
�kr�t�|�}|r�|d|�����}|dd�dkr�t|dd����r�dVP|�	d
�r�dVn
|dfV|�d|d�}qW|�d�}x@d|k�rD||k�r&|dfVn
|dfV|�d|d�}�qWdS)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
    rrar9Nrd�}rbrcr�rer)rz1E731 do not assign a lambda expression, use a defzdef )rz*E704 multiple statements on one line (def)z,E701 multiple statements on one line (colon)r�z0E702 multiple statements on one line (semicolon)z$E703 statement ends with a semicolon)
r0r^rh�LAMBDA_REGEX�searchrTr/�isidentifierrSrG)rIrBZ	last_charrVr[Z	lambda_kwr&r&r'�compound_statements�s0

$




r�ccs�d}}}d}d}x�|D]�\}}}	}
}|tjkr6d}|	d|krX|rX|rX|sX|dfV|
d|kr�|�d��d�r�|
dt|��d�d	f}nd}|
d}}n|	d}|tjkr|d
kr�|d	7}q|dkr|d	8}qWdS)a?Avoid 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 bracketsz
�\r9rz([{z)]})rvr|r/rlr0�
splitlinesrw)rIr�Z
prev_startr�r�r�Z	backslashr�rUrTr�rBr&r&r'�explicit_line_join�s&



r�ccs�dd�}d}d}d}d}x||D]t\}}}	}
}|tjkr8qd|ksHd|krX|tjkrXd}q|||�r~|r~|s~|||�s~|	dfV|d	k}d}|}|}qWdS)
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)

    Okay: (width == 0 +\n height == 0)
    Okay: foo(\n    -x)
    Okay: foo(x\n    [])
    Okay: x = '''\n''' + ''
    Okay: foo(x,\n    -y)
    Okay: foo(x,  # comment\n    -y)
    Okay: var = (1 &\n       ~2)
    Okay: var = (1 /\n       -2)
    Okay: var = (1 +\n       -1 +\n       -2)
    cSs|tjks|dko|dkS)N)�and�orz()[]{},:.;@=%~)rvrw)r�rUr&r&r'�is_binary_operatorsz8break_around_binary_operator.<locals>.is_binary_operatorFTNr,r-z&W503 line break before binary operatorz([{,;)rvr|r})rIr�r�Z
line_breakZ
unary_contextZprevious_token_typeZ
previous_textr�rUrTr�rBr&r&r'�break_around_binary_operators&

r�ccs�|ot�|�}|r�|�d�p&|�d�}|�d�dk}d|r@dnd|}|dkrXd	}n2d
}|dkrh|pt|dkot|}|d
|r�dnd7}|�d�d|||ffVdS)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!
    rrEr7z==z'if cond is %s:'�znot )rZE711ZE712r
rz or 'if %scond:'z %s comparison to %s should be %sN)�COMPARE_SINGLETON_REGEXr�rrT)rIr<rZ	singletonZsame�msgrWZnonzeror&r&r'�comparison_to_singleton3s
r�ccs@t�|�}|r<|�d�}|�d�dkr2|dfVn
|dfVdS)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
    rr7�inz+E713 test for membership should be 'not in'z0E714 test for object identity should be 'is not'N)�COMPARE_NEGATIVE_REGEXr�rTr)rIrr_r&r&r'�comparison_negativeUs

r�ccsFt�|�}|rB|sB|�d�}|r4t|�r4|tkr4dS|��dfVdS)a�Object type comparisons should always use isinstance().

    Do not compare types directly.

    Okay: if isinstance(obj, int):
    E721: if type(obj) is type(1):

    When checking if an object is a string, keep in mind that it might be a
    unicode string too! In Python 2.3, str and unicode have a common base
    class, basestring, so you can do:

    Okay: if isinstance(obj, basestring):
    Okay: if type(a1) is type(b1):
    rNz-E721 do not compare types, use 'isinstance()')�COMPARE_TYPE_REGEXr�rr��
SINGLETONSrT)rIr<r�instr&r&r'�comparison_typejs

r�ccs$|�d�}|dkr |s |dfVdS)z�The {}.has_key() method is removed in Python 3: use the 'in' operator.

    Okay: if "alph" in d:\n    print d["alph"]
    W601: assert d.has_key('alph')
    z	.has_key(r9z'W601 .has_key() is deprecated, use 'in'N)r^)rIr<r_r&r&r'�python_3000_has_key�s
r�ccs.t�|�}|r*t�|�s*|��ddfVdS)z�When raising an exception, use "raise ValueError('message')".

    The older form is removed in Python 3.

    Okay: raise DummyError("Message")
    W602: raise DummyError, "Message"
    rz)W602 deprecated form of raising exceptionN)�RAISE_COMMA_REGEXr�RERAISE_COMMA_REGEXr�)rIrr&r&r'�python_3000_raise_comma�s
r�ccs |�d�}|dkr|dfVdS)z�New code should always use != instead of <>.

    The older syntax is removed in Python 3.

    Okay: if a != 'no':
    W603: if a <> 'no':
    z<>r9z!W603 '<>' is deprecated, use '!='N)r^)rIr_r&r&r'�python_3000_not_equal�s
r�ccs |�d�}|dkr|dfVdS)zfUse repr() instead of backticks in Python 3.

    Okay: val = repr(1 + 2)
    W604: val = `1 + 2`
    �`r9z+W604 backticks are deprecated, use 'repr()'N)r^)rIr_r&r&r'�python_3000_backticks�s
r�)rEc	Cst|d��
}|��SQRXdS)zRead the source code.ZrUN)�open�	readlines)�filename�fr&r&r'r��sr�z
[a-zA-Z_]\w*$cs�yNt|d��:}t�|j�\�}t|�dd�}�fdd�|D�|��SQRXWn6tttfk
r�t|dd��
}|��SQRXYnXdS)	zRead the source code.�rbT)�line_bufferingcsg|]}|����qSr&)r;)r��l)�codingr&r'�
<listcomp>�szreadlines.<locals>.<listcomp>Nzlatin-1)�encoding)	r�rv�detect_encoding�readlinerr��LookupError�SyntaxErrorr?)r�r�r3r&)r�r'r��s$cCsttjjdd���S)zRead the value from stdin.�ignore)�errors)r�sys�stdin�buffer�readr&r&r&r'�stdin_get_value�sr�z# no(?:qa|pep8)\bcCs`d|krt|�t|���Sd}x:|D]2}|dkrD|ddd}q&|dkrV|d7}q&Pq&W|S)z�Return the amount of indentation.

    Tabs are expanded to the next multiple of 8.

    >>> expand_indent('    ')
    4
    >>> expand_indent('\t')
    8
    >>> expand_indent('       \t')
    8
    >>> expand_indent('        \t')
    16
    r)rrorOr)r0r�)rB�resultr%r&r&r'ru�s

rucCsb|�|d�d}t|�d}|dd�dkr>|d7}|d8}|d|�d||||d�S)z�Replace contents with 'xxx' to prevent syntax matching.

    >>> mute_string('"abc"')
    '"xxx"'
    >>> mute_string("'''abc'''")
    "'''xxx'''"
    >>> mute_string("r'abc'")
    "r'xxx'"
    r9r���N)z"""z'''r7�x)r*r0)rUrTr�r&r&r'�mute_string�sr��.c	s�i}d}}x�|��D]�}|r8|dd�dkr|d8}q|dd�dkr�t�|�}dd�|��D�\}}||�t|||��q|dd�dkr|d	d��d
d�d}|dd�d
kr�|dd�}t�||<qWt��fdd�|�	�D��S)z&Return a dictionary of matching lines.NrrrEz@@ cSsg|]}t|pd��qS)�1)�int)r��gr&r&r'r�szparse_udiff.<locals>.<listcomp>z+++rkr)rr7zb/cs0g|](\}}|rt|��rtj��|�|f�qSr&)�filename_match�os�path�join)r�r�Zrows)�parent�patternsr&r'r�s)
r��
HUNK_REGEXrrZ�updaterfr=�set�dict�items)	�diffr�r��rvr�r�rBZ
hunk_matchr�r&)r�r�r'�parse_udiffs$
rcCsh|sgSt|t�r|Sg}xH|�d�D]:}|��}d|krPtj�tj�||��}|�|�	d��q&W|S)zQParse a comma-separated list of paths.

    Return a list of absolute paths.
    rPr)
�
isinstancer�r=rSr�r��abspathr�rr/)�valuer��pathsr�r&r&r'�normalize_pathss
rTcs|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�|�VqdS)N)r)r��pattern)r�r&r'r�5sz!filename_match.<locals>.<genexpr>)r�)r�r�r
r&)r�r'r�.sr�cCs,|dtkp*|d|ddd���dkS)NrrkrErz\
)rtr�)�tokenr&r&r'�
_is_eol_token8srcCs&||�p$|dtjko$|d|dkS)Nrrrk)rvr|)r
Z
_eol_tokenr&r&r'r;s)r!rI�treecCs6tjdkr$dd�t�|�j��D�St�|�dSdS)N)rErEcSsg|]}|j|jkr|j�qSr&)�kindZPOSITIONAL_OR_KEYWORD�name)r�Z	parameterr&r&r'r�Isz#_get_parameters.<locals>.<listcomp>r)r��version_info�inspectZ	signatureZ
parameters�valuesZ
getargspec)�functionr&r&r'�_get_parametersGs
rcCs�dd�}t�|�rVt|�}|r�|ddkr�|dkrBt�|jp>d�}|||d||�n2t�|�r�t|j�dd�dd	gkr�||d	|d�dS)
zRegister a new check object.cSsB|t|kr(t||d�|p"g�n|p0dg|ft||<dS)Nrr�)�_checks�extend)�checkr�codes�argsr&r&r'�
_add_checkSsz"register_check.<locals>._add_checkr)r!rINr�r7�selfr)r�
isfunctionr�ERRORCODE_REGEX�findall�__doc__Zisclass�__init__)rrrrr&r&r'�register_checkQs

r#cCs2t�t�}x"t�|tj�D]\}}t|�qWdS)zwRegister all globally visible functions.

    The first argument name is either 'physical_line' or 'logical_line'.
    N)rZ	getmoduler#Z
getmembersr)�modrrr&r&r'�init_checks_registrycs
r%c@steZdZdZddd�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�|dkrt|�j}n|rt�d|_|j|_|j|_|j|_	|j
|_
d|_|j|_|j
|_
||_i|_|dkr~d|_|pxg|_n||dkr�d|_t��d�|_n^|dkr�yt|�|_Wq�tk
r�t��dd�\}}d|j|f|_g|_Yq�Xn||_|j�rrt|jdd�}|dk�rr|d	k�rB|jdd
d�|jd<n0|jddd�dk�rr|jddd�|jd<|�p||j|_|jj|_dS)
NFr�rTr7z%s: %sr)��i��i��rrEu)�
StyleGuide�optionsr��	_io_error�physical_checks�_physical_checks�logical_checks�_logical_checks�
ast_checks�_ast_checksr@rAr�r�r��_checker_statesr3r�r�r��IOErrorr��exc_info�__name__�ord�reportr��report_error)	rr�r3r)r6�kwargs�exc_type�excZord0r&r&r'r"qsH

zChecker.__init__cCs|t��dd�\}}t|j�dkrF|jd}t|�dkrJ|dd�}nd}|�|d|dp^dd|j|jdf|j�dS)zCheck if the syntax is valid.Nr7rrE)rrrzE901 %s: %s)r�r3r0rr7r4�report_invalid_syntax)rr9r:r$r&r&r'r;�s
zChecker.report_invalid_syntaxcCsR|j|jkrdS|j|j}|jd7_|jdkrN|dd�tkrN|d|_|S)z(Get the next line from the input buffer.r�rNr)r4r5r3r"rg)rrBr&r&r'r��s
zChecker.readlinecCs*g}x|D]}|�t||��q
W||�S)zRun a check plugin.)r�getattr)rr�argument_namesZ	argumentsrr&r&r'�	run_check�s
zChecker.run_checkcCsd|kr|j�|i�|_dS)z5Prepare custom state for the specific checker plugin.r�N)r1�
setdefaultr�)rrr=r&r&r'�init_checker_state�szChecker.init_checker_statecCst||_xh|jD]^\}}}|�||�|�||�}|dk	r|\}}|�|j|||�|dd�dkr|d|_qWdS)z,Run all physical checks on a raw input line.NrkZE101r)r!r,r@r>r7r4r")rrBrrr=r�r$rUr&r&r'�check_physical�szChecker.check_physicalcCs(g}g}d}d}}}x�|jD]�\}}}	}
}|tkr8q |sFd|	fg}|tjkr\|�|�q |tjkrnt|�}|r�|	\}}
||kr�|j|d|d}|dks�|dkr�|dkr�d|}n||
kr�|||
�|}|�|�|t|�7}|�||
f�|
\}}q Wd�	|�|_
|�o td�	|��|_|S)	z!Build a logical line from tokens.rNrrPz{[(z}])rOr�)r��SKIP_TOKENSrvr|rr}r�r3r0r�rIr<)rZlogicalZcommentsrC�prev_row�prev_col�mappingr�rUrTr�rB�	start_row�	start_colr�r&r&r'�build_tokens_line�s<





zChecker.build_tokens_linecCsT|j��|��}|sdS|dd\}}|j|d}t|d|��|_|j|jkr^|j|_|jdkr~t	|j
dd����x�|jD]�\}}}|jdkr�t	d|�|�
||�xt|�||�p�dD]`\}}	t|t��sx|D]\}
}||
kr�Pq�W|d|d||
f}|�|d|d|	|�q�Wq�W|j
�rD|j|_|j
|_d|_g|_dS)	z:Build a line from tokens and run all logical checks on it.Nrrr7�Prkz   r&)r6�increment_logical_linerHr3rurKrLrJr�rrIr/r.r@r>r�tupler7rNrMr�)rrErFrGZ
start_linerrr=r$rUZtoken_offsetr_r&r&r'�
check_logical�s6


 zChecker.check_logicalc

Cs�ytd�|j�ddt�}Wntttfk
r8|��SXxb|jD]X\}}}|||j	�}x@|�
�D]4\}}}}	|jr�t|j|d�sb|�||||	�qbWqBWdS)z,Build the file's AST and run all AST checks.r��execrN)
�compiler�r3�
PyCF_ONLY_AST�
ValueErrorr��	TypeErrorr;r0r��runr<r7)
rrr�clsr�Zchecker�linenor$rUrr&r&r'�	check_asts
zChecker.check_astc	cs�|jr|�ddd|jt�t�|j�}y8x2|D]*}|dd|jkrJdS|�|�|Vq0WWn"ttj	fk
r�|�
�YnXdS)z=Tokenize the file, run physical line checks and yield tokens.rrzE902 %sr7N)r*r7r�rv�generate_tokensr�r5�maybe_check_physicalr��
TokenErrorr;)rZtokengenr
r&r&r'rVs

zChecker.generate_tokenscCs�t|�r|�|d�n�|dtjkr�d|dkr�t|d�rBdSd|_|dd|_x:|d�d�dd�D] }|�|d�|jd7_qnWd	|_dS)
z@If appropriate (based on token), check current physical line(s).rkrr,rNTr7r9F)rrArvr}r<rAr4r=)rr
rBr&r&r'rW%szChecker.maybe_check_physicalrcCs:|j�|j|j||�t|j�|_|jr0|��d|_d|_	d|_
|_d|_g|_
d|_|_d}�x�|��D�]�}|j
�|�|dd�\}}|jdk�r|dd|ddkr�d|ddp�d|ddf}nd|dd}td	|dd|tj|d|f�|tjk�rB|d
k�r.|d7}n|dk�r|d8}qp|sp|tk�r�|tjk�rl|��d|_n0t|j
�dk�r�|jd7_|j
d=n|��qptrp|tjkrpt|j
�dkrpt|�}|�d�|d<|dd|ddt|d�f|d<t|�g|_
|��qpW|j
�r0|�|jd
�|��|j��S)z!Run all checks on the input file.rNr�r7rEz[%s:%s]rzl.%sz
l.%s	%s	%s	%rz([{z}])z
r9) r6�	init_filer�r3r0r5r0rUr4r"rKrNrMr�rJrLrVrr�rrv�tok_namerwrtrL�COMMENT_WITH_NLr|r�r/rKrA�get_file_results)r�expected�line_offsetr�r
r�rUr_r&r&r'�	check_allCsZ""






(zChecker.check_all)NNNN)Nr)r4�
__module__�__qualname__r!r"r;r�r>r@rArHrLrUrVrWr_r&r&r&r'r&ns
)

! r&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|_	dS)Nr)
�benchmark_keys�_benchmark_keys�ignore_code�_ignore_code�elapsed�total_errorsr�fromkeys�counters�messages)rr)r&r&r'r"}szBaseReport.__init__cCst��|_dS)zStart the timer.N)�time�_start_time)rr&r&r'rT�szBaseReport.startcCst��|j|_dS)zStop the timer.N)rlrmrg)rr&r&r'�stop�szBaseReport.stopcCsN||_||_|pd|_||_d|_|jdd7<|jdt|�7<dS)zSignal a new file.r&rrrzphysical linesN)r�r3r]r^�file_errorsrjr0)rr�r3r]r^r&r&r'rY�s
zBaseReport.init_filecCs|jdd7<dS)zSignal a new logical line.z
logical linesrN)rj)rr&r&r'rJ�sz!BaseReport.increment_logical_linecCs�|dd�}|�|�rdS||jkr8|j|d7<nd|j|<|dd�|j|<||jkrbdS|jrx|jsxt|j�|jd7_|jd7_|S)z&Report an error, according to options.Nrkr�)	rfrjrkr]�print_filenamerorr�rh)rr4r$rUrrWr&r&r'r��s




zBaseReport.errorcCs|jS)z6Return the count of errors and warnings for this file.)ro)rr&r&r'r\�szBaseReport.get_file_resultsr�cst��fdd��jD��S)z.Return the total count of errors and warnings.cs g|]}|���r�j|�qSr&)rGrj)r��key)�prefixrr&r'r��sz(BaseReport.get_count.<locals>.<listcomp>)�sumrk)rrsr&)rsrr'�	get_count�szBaseReport.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)rGrjrk)r�rr)rsrr&r'r��sz-BaseReport.get_statistics.<locals>.<listcomp>)�sortedrk)rrsr&)rsrr'�get_statistics�szBaseReport.get_statisticscCs x|�|�D]}t|�qWdS)z9Print overall statistics (number of errors and warnings).N)rwr)rrsrBr&r&r'�print_statistics�szBaseReport.print_statisticscCsPtd|jdf�|jrLx2|jD](}td|j||j||j|f�q WdS)zPrint benchmark numbers.z	%-7.2f %szseconds elapsedz%-7d %s per second (%d total)N)rrgrdrj)rrrr&r&r'�print_benchmark�szBaseReport.print_benchmarkN)r�)r�)r�)r4r`rar!rqr"rTrnrYrJr�r\rurwrxryr&r&r&r'rbxs	



rbc@seZdZdZdZdS)�
FileReportz?Collect the results of the checks and print only the filenames.TN)r4r`rar!rqr&r&r&r'rz�srzcs@eZdZdZ�fdd�Z�fdd�Z�fdd�Zdd	�Z�ZS)
�StandardReportz,Collect and print the results of the checks.csBtt|��|�t�|j��|j�|_|j|_	|j
|_|j|_
dS)N)�superr{r"�
REPORT_FORMATry�format�lower�_fmt�repeat�_repeatZshow_source�_show_sourceZ	show_pep8�
_show_pep8)rr))�	__class__r&r'r"�s
zStandardReport.__init__csg|_tt|��||||�S)zSignal a new file.)�_deferred_printr|r{rY)rr�r3r]r^)r�r&r'rY�s
zStandardReport.init_filecsRtt|��||||�}|rN|j|dks.|jrN|j�||||dd�|jf�|S)z&Report an error, according to options.rrpN)r|r{r�rjr�r�rr!)rr4r$rUrrW)r�r&r'r��szStandardReport.errorc	Cs�|j��x�|jD]�\}}}}}t|j|j|j||d||d��|jr�|t|j�kr`d}n|j|d}t|�	��tt
�dd|d|��d�|jr�|r�td|�
��tj��qW|jS)	z<Print the result and return the overall count for this file.r)r�r��colrWrUr�z\SrONrz    )r��sortrr�r�r^r�r0r3r/�re�subr�rSr��stdout�flushro)rr4r$rWrU�docrBr&r&r'r\�s 

zStandardReport.get_file_results)	r4r`rar!r"rYr�r\�
__classcell__r&r&)r�r'r{�s
	r{cs,eZdZdZ�fdd�Z�fdd�Z�ZS)�
DiffReportz9Collect and print the results for the changed lines only.cstt|��|�|j|_dS)N)r|r�r"�selected_lines�	_selected)rr))r�r&r'r"szDiffReport.__init__cs*||j|jkrdStt|��||||�S)N)r�r�r|r�r�)rr4r$rUr)r�r&r'r�szDiffReport.error)r4r`rar!r"r�r�r&r&)r�r'r�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	OsD|�dt�|_|�dd�}|�dd�}|�dd�}t||�}|rDdn
|�dd�}t||||�\}|_|r�|j�|�d|kr�|d|_|j	|_
||_|js�|j
r�tnt|_t|jp�d�|_|js�|js�|js�|js�tr�tt�d��|_n|jr�d	nt|j�|_tdd�|_|j|_|�d
�|_|�d�|_|�d�|_|��dS)
N�
checker_class�
parse_argvF�config_file�parserr
r&rP)r�r!rIr)r�r&r�rry�process_optionsr
�__dict__r�
input_file�runnerr)�reporter�quietrbr{rK�selectr�r�doctest�DEFAULT_IGNOREr=�BENCHMARK_KEYSrcre�
get_checksr+r-r/�init_report)	rrr8r�r�r�Zoptions_dict�arglistr)r&r&r'r"s6

zStyleGuide.__init__NcCs|p
|jj|j�|j_|jjS)zInitialize the report instance.)r)r�r6)rr�r&r&r'r�DszStyleGuide.init_reportcCs�|dkr|j}|jj}|j}|��y<x6|D].}tj�|�rH|�|�q,|�	|�s,||�q,WWnt
k
r|td�YnX|��|S)zRun all checks on the paths.Nz... stopped)
r
r)r6r�rTr�r��isdir�	input_dir�excluded�KeyboardInterruptrrn)rr
r6r�r�r&r&r'�check_filesIs

zStyleGuide.check_filesrcCs4|jjrtd|�|j|||jd�}|j||d�S)z'Run all checks on a Python source file.zchecking %s)r3r))r]r^)r)r�rr�r_)rr�r3r]r^Zfcheckerr&r&r'r�[s
zStyleGuide.input_filecCs�|�d�}|�|�rdS|jjj}|jj}|jj}|j}x�t�	|�D]�\}}}|r^t
d|�|dd7<x&t|�D]}	|�|	|�rx|�|	�qxWx8t|�D],}
t
|
|�r�|�|
|�s�|tj�||
��q�WqDWdS)z9Check all files in this directory and all subdirectories.rrz
directory rrN)r/r�r)r6rjr�r�r�r��walkrrv�remover�r�r�)r�dirnamerjr�Zfilepatternsr��root�dirsrZsubdirr�r&r&r'r�cs$



zStyleGuide.input_dircCsV|jjsdStj�|�}t||jj�r*dS|r<tj�||�}tj�|�}t||jj�S)z|Check if the file should be excluded.

        Check if 'options.exclude' contains a pattern that matches filename.
        FT)r)�excluder�r��basenamer�r�r)rr�r�r�r&r&r'r�yszStyleGuide.excludedcsHt��dkr*t�fdd�|jjD��r*dS��|jj�oF��|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.
        rkc3s|]}|���VqdS)N)rG)r��s)rWr&r'r��sz)StyleGuide.ignore_code.<locals>.<genexpr>F)r0r�r)r�rGr�)rrWr&)rWr're�s
zStyleGuide.ignore_codecsVg}xHt|��D]8\}}|\}}t�fdd�|D��r|�|j||f�qWt|�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��|�VqdS)N)re)r�rW)rr&r'r��sz(StyleGuide.get_checks.<locals>.<genexpr>)rrr�rr4rv)rZ
argument_nameZchecksrZattrsrrr&)rr'r��szStyleGuide.get_checks)N)N)NNr)N)r4r`rar!r"r�r�r�r�r�rer�r&r&r&r'r(s%




r(c
Cs�t||dd�}ddddddd	d
ddd
ddg
|_|jdddd	dd�|jdddd	dd�|jdddddd�|jdddd d!�|jd"d#td$d%�|jd&d#d'd(d%�|jd)d*d+d,d%�|jd-d*d+d.td%�|jd/dd0d1�|jd2dd3d1�|jd4dd5d1�|jd6dd7d1�|jd8d9d:td;d<�|jd=dd>d1�|jd?d
d@dAd%�|jdBddCd1�|�dD�}tj�	t
��r�|jdEdFdGdH�|jdIddJd1�|jdKddLd1�|S)Mz"Create the parser for the program.z%prog [options] input ...)�prog�versionZusager�r�r�r�zmax-line-lengthzhang-closingrhr~r�z	show-pep8zshow-source�
statisticsr�z-vz	--verboserz(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_falser�z#show first occurrence of each error)r��destr�z	--excluder�z[exclude files or directories which match these comma separated patterns (default: %default))�metavarr
r�z
--filenamez*.pyzjwhen parsing directories, only check filenames matching these comma separated patterns (default: %default)z--selectr�r�z&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��nz3set maximum allowed line length (default: %default))�typer�r
r�z--hang-closingzNhang closing bracket instead of matching indentation of opening bracket's linez--formatr
z.set the error format [default|pylint|<custom>]z--diffzSreport changes only within line number ranges in the unified diff received on STDINzTesting Optionsz--testsuite�dirzrun regression tests from dir)r�r�z	--doctestzrun doctest on myselfz--benchmarkzmeasure processing speed)r�config_options�
add_option�DEFAULT_EXCLUDEr��MAX_LINE_LENGTH�add_option_groupr�r��exists�TESTSUITE_PATH)r�r�r�rr&r&r'�
get_parser�s`










r�cst�}|j}tj}tr>tj�t�r>|jr4tdt�|�	t�|oTtj�
tj�|���}xH|r�|�	�fdd�tD��r��}|jr�td��Ptj�
��\�}q\W|r�tj�|�r�|jr�td|�|�	|�|j}|�|��r�tdd�|jD��}	|�g�\}
}x�|�|�D]�}|�dd	�|jk�r8td
|��q|jdk�r\td||�||�f�|�d	d�}
|	|
}|d
k�r�|�||�}nF|dk�r�|�||�}|
dk�r�t||�}n|dk�s�t�|�||�}t|
|
|��qW|j||
d�\}}d|_|_|S)apRead 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/pep8) 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��|�VqdS)N)r�r�r�)r��fn)r�r&r'r��szread_config.<locals>.<genexpr>zlocal configuration: in %szcli configuration: %scSsg|]}|j|jp|jf�qSr&)r�r�r�)r��or&r&r'r�szread_config.<locals>.<listcomp>�_rz  unknown option '%s' ignoredrz	  %s = %s)r�rh�stringr�)r�r�)rF)r�configr��curdir�USER_CONFIGr��isfiler�rr�r�commonprefix�PROJECT_CONFIGr=r�Zhas_sectionr�option_list�
parse_argsr)�replacer�ryZgetintrr�Z
getboolean�setattrr�r)r)rr�r�r�Zcli_confZ	local_dir�tailZpep8_sectionr�Znew_optionsr��optZnormalized_optZopt_typer	r&)r�r'�read_config�sX





r�FcCsJ|s
t�}|�d�sF|jdd|jd�|j�fd�}|jdd|dd�|sR|sRg}|�|�\}}d	|_|�	d
d�r�|�
|j�n`|�	dd�s�|r�|s�|js�t
d
d�tD��r�dg}n
|�d�t||||�}|o�|jdko�t|_t|j�|_t|j�|_t|j�|_t|j�|_|j�rBt|_t�}t||j|d�|_t|j�}||fS)z�Process options passed either via arglist or via command line args.

    Passing in the ``config_file`` parameter allows other tools, such as flake8
    to specify their own options to be processed in pep8.
    z--configZ
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, )Zdescriptionr�zuser config file location)r�r
r�NrFr�css|]}tj�|�VqdS)N)r�r�r�)r�rr&r&r'r�Csz"process_options.<locals>.<genexpr>r�zinput not specifiedrr)r�Z
has_optionr�r�r�r�r�r�r�Zensure_valuerrrr�r�r�r�r�rz�_parse_multi_optionsr�rr�r�r�r�r�rr�rv)r�r�r�r�rr)rr�r&r&r'r�&s@




r�rPcCs |rdd�|�|�D�S|SdS)zgSplit and strip and discard empties.

    Turns the following:

    A,
    B,

    into ["A", "B"]
    cSsg|]}|��r|���qSr&)rS)r�r�r&r&r'r�dsz(_parse_multi_options.<locals>.<listcomp>N)r=)r)Zsplit_tokenr&r&r'r�Ys
r�cCs�ddl}y|�|jdd��Wntk
r2YnXtdd�}|j}|jsP|jrfddlm}||�}n|�	�}|j
r||��|jr�|�
�|jr�|js�|��|jr�|jr�tj�t|j�d�t�d	�dS)
z.Parse options and run checks on Python source.rNcSs
t�d�S)Nr)r��exit)Zsignum�framer&r&r'�<lambda>o�z_main.<locals>.<lambda>T)r�)�	run_testsr,r)�signal�SIGPIPE�AttributeErrorr(r)r�rZtestsuite.supportr�r�r�rxZ	benchmarkryr�Z
print_resultsrhrhr��stderr�writerzr�)r�Zstyle_guider)r�r6r&r&r'�_mainis*

r��__main__)Nr�)T)N)NFNN)rP)�r!Z
__future__rr�r�r�rlrr�rv�warningsZoptparserrZconfigparserr�ior�ImportErrorZConfigParser�__version__r�r��platformr��
expanduserr�r��getenvr�r��__file__r�r�r}rO�	frozensetr��kwlistr�r�r��unionr�r�rgr{rt�INDENT�DEDENTrBr|�
ERRORTOKENr�r�rNrr�r�rrHrQr�r�r�r�rYr�r�r�rVr��sendr[r(r+r2r6rDrJrXr]r`rjrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�rr�r�r�r�rz�Ir�r<rur�rr�rr�rrrr#r%�objectr&rbrzr{r�r(r�r�r�r�r�r4r&r&r&r'�<module>0s















&% H \2)49'1"





	

Z7
>E
2
"