Your IP : 216.73.216.213


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

B

A!p\{�@s`dZddlZddlZddlZddlZddlmZddlZddlm	Z	ddl
mZddlm
Z
mZmZddlmZmZddlmZdd	lmZd
Zejdd�dkZejdd�d
kZddddddddddddddddddd �Zejejejejejejej fZ!ej"d!Z#ej"d"Z$ej"d#Z%d$d%�Z&d&d'�Z'Gd(d)�d)e�Z(Gd*d+�d+e�Z)d,d-�Z*d.d/�Z+dS)0z*Checker for string formatting operations.
�N)�Counter)�CallSite)�Const)�
ITokenChecker�IAstroidChecker�IRawChecker)�BaseChecker�BaseTokenChecker)�utils)�check_messages)z__builtin__.unicodez__builtin__.strzbuiltins.str�)�r)r�)z3Unsupported format character %r (%#02x) at index %dzbad-format-characterzEUsed when an unsupported format character is used in a format string.)z4Format string ends in middle of conversion specifierztruncated-format-stringzNUsed when a format string terminates before the end of a conversion specifier.)z?Mixing named and unnamed conversion specifiers in format stringzmixed-format-stringz�Used when a format string contains both named (e.g. '%(foo)d') and unnamed (e.g. '%d') conversion specifiers.  This is also used when a named conversion specifier contains * for the minimum field width and/or precision.)z*Expected mapping for format string, not %szformat-needs-mappingzoUsed when a format string that uses named conversion specifiers is used with an argument that is not a mapping.)z7Format string dictionary key should be a string, not %szbad-format-string-keyzyUsed when a format string that uses named conversion specifiers is used with a dictionary whose keys are not all strings.)z)Unused key %r in format string dictionaryzunused-format-string-keyz�Used when a format string that uses named conversion specifiers is used with a dictionary that contains keys not required by the format string.)z*Missing key %r in format string dictionaryzmissing-format-string-keyz�Used when a format string that uses named conversion specifiers is used with a dictionary that doesn't contain all the keys required by the format string.)z$Too many arguments for format stringztoo-many-format-argsz^Used when a format string that uses unnamed conversion specifiers is given too many arguments.)z&Not enough arguments for format stringztoo-few-format-argsz\Used when a format string that uses unnamed conversion specifiers is given too few arguments)z)Argument %r does not match format type %rzbad-string-format-typezSUsed when a type required by format string is not suitable for actual argument type)z!Suspicious argument in %s.%s callzbad-str-strip-callzGThe argument to a str.{l,r,}strip call contains a duplicate character, )zInvalid format stringzbad-format-stringz.Used when a PEP 3101 format string is invalid.)z-Missing keyword argument %r for format stringzmissing-format-argument-keyzhUsed when a PEP 3101 format string that uses named fields doesn't receive one or more required keywords.)zUnused format argument %rzunused-format-string-argumentz}Used when a PEP 3101 format string that uses named fields is used with an argument that is not required by the format string.)zTFormat string contains both automatic field numbering and manual field specificationzformat-combined-specificationz�Used when a PEP 3101 format string contains both automatic field numbering (e.g. '{}') and manual field specification (e.g. '{0}').)z2Missing format attribute %r in format specifier %rzmissing-format-attributez�Used when a PEP 3101 format string uses an attribute specifier ({0.length}), but the argument passed for formatting doesn't have that attribute.)z2Using invalid lookup key %r in format specifier %rzinvalid-format-indexz�Used when a PEP 3101 format string uses a lookup specifier ({a[1]}), but the argument passed for formatting doesn't contain or doesn't have that key as an attribute.)zKDuplicate string formatting argument %r, consider passing as named argumentz$duplicate-string-formatting-argumentzmUsed when we detect that a string formatting is repeating an argument instead of using named string arguments)ZE1300ZE1301ZE1302ZE1303ZW1300ZW1301ZE1304ZE1305ZE1306ZE1307ZE1310ZW1302ZW1303ZW1304ZW1305ZW1306ZW1307ZW1308z.strz.floatz.intcCsNg}x6|D].\}}|r(|�d�|��q
|�d�|��q
Wt|�d�|�S)z^ Given a list of format specifiers, returns
    the final access path (e.g. a.b.c[0][1]).
    z.{}z[{!r}]�)�append�format�str�join)�key�parts�path�is_attribute�	specifier�r�H/opt/alt/python37/lib/python3.7/site-packages/pylint/checkers/strings.py�get_access_path�srcCsT|dkrdSt|tj�rP|��}|tkr0|dkS|tkr@|dkS|tkrLdSdSdS)N�srT�cz	deEfFgGn%F)�
isinstance�astroid�Instance�pytype�BUILTINS_STR�BUILTINS_FLOAT�BUILTINS_INT)�arg_type�format_typerrr�arg_matches_format_type�sr'c@sVeZdZdZefZdZeZe	e�dd��Z
e	e�dd��Zdd�Zd	d
�Z
dd�Zd
S)�StringFormatCheckerz�Checks string formatting operations to ensure that the format string
    is valid and the arguments match the format string.
    �stringc
Cs`|jdkrdS|j}|j}t|tj�r2t|jt�s6dS|j}yt�	|�\}}}}Wnltj
k
r�}	z*||	j}
|jd||
t
|
�|	jfd�dSd}	~	XYn$tjk
r�|jd|d�dSX|r�|r�|jd|d��n�|�rZt|tj��r*t�}d}xV|jD]L\}
}t|
tj��rF|
j}t|t��r4|�|�n|jd||d�nd	}�qW|�s�x(|D] }||k�r\|jd
||d��q\Wx(|D] }||k�r�|jd||d��q�Wx�|jD]r\}}t|tj��s̐q�|�|jd�}t�|�}|dk	�r�|dtjfk�r�t||��s�|jd||��|fd��q�Wn,t|ttjf��r\t|�j}|jd
||d��nd}t|tj��r�t�|�}d}t|d��r�|j}t|�}n(t|ttjtjff��r�|g}d}nd}|dk	�r\||k�r�|jd|d�n||k�r�|jd|d�x`t ||�D]R\}}|�s�qt�|�}|dtjfk�rt||��s|jd||��|fd��qWdS)N�%zbad-format-character)�node�argsztruncated-format-string)r+zmixed-format-stringFzbad-format-string-keyTzmissing-format-string-keyzunused-format-string-keyzbad-string-format-typezformat-needs-mappingr�elts�ztoo-many-format-argsztoo-few-format-args)!�op�left�rightrrr�valuerr
Zparse_format_stringZUnsupportedFormatCharacter�index�add_message�ord�IncompleteFormatString�Dict�set�items�add�get�
safe_infer�Uninferabler'r!�OTHER_NODESZTuple�type�__name__�hasattrr-�lenZDictComp�zip)�selfr+r0r,�
format_stringZ
required_keysZrequired_num_argsZrequired_key_typesZrequired_arg_types�er�keysZunknown_keys�k�_r�argr&r%Z	type_nameZ	args_eltsZ	rhs_tuple�num_argsrrr�visit_binop�s�
















zStringFormatChecker.visit_binopcCs�t�|j�}t|tj�r�t|jtj�r�|jjdkr�|jdkr�|j	r�t�|j	d�}t|tj
�rjt|jt�sndSt
|j�t
t|j��kr�|jd||jj|jfd�n|jdkr�|�||�dS)N)r�unicode�bytes)�strip�lstrip�rstriprzbad-str-strip-call)r+r,r)r
r<�funcrrZBoundMethod�boundr �namer,rr2rrBr8r4�_check_new_format)rDr+rRrJrrr�
visit_callRs
zStringFormatChecker.visit_callcCsHtdd�|D��}x0|��D]$\}}|dkr.q|jd||fd�qWdS)Ncss |]}t|tj�r|jVqdS)N)rr�NamerT)�.0rJrrr�	<genexpr>iszAStringFormatChecker._detect_vacuous_formatting.<locals>.<genexpr>r.z$duplicate-string-formatting-argument)r+r,)rr9r4)rDr+�positional_arguments�counterrT�countrrr�_detect_vacuous_formattinggsz.StringFormatChecker._detect_vacuous_formattingcCs6t|jtj�r"t|jjtj�s"dS|js.|jr2dSyt|j	�
��}Wntjk
rZdSXt|tj�rtt|jt
�sxdSyt�|�}Wntjk
r�dSXyt�|j�\}}}Wn$tjk
r�|jd|d�dSX|j}|j}	dd�|D�}
|�r|�r|jd|d�dSd}|tdd	�|
D��7}|
�r�x0|
D](}|�r8||	k�r8|jd
||fd��q8Wx*|	D]"}||
k�rj|jd||fd��qjW|�p�|}|�s�|�r�td
d	�|
D��}
|	�s�|
�r�d}nd}|�r|�p�|}t|�|k�r�|jd|d�nt|�|k�r|jd|d�|�||�|�|||	�dS)z" Check the new string formatting. Nzbad-format-string)r+cSs"h|]}t|dt�r|d�qS)r)rr)rX�fieldrrr�	<setcomp>�sz8StringFormatChecker._check_new_format.<locals>.<setcomp>zformat-combined-specificationFcss|]}|dkrdVqdS)rr.Nr)rXr^rrrrY�sz8StringFormatChecker._check_new_format.<locals>.<genexpr>zmissing-format-argument-key)r+r,zunused-format-string-argumentcss|]}|dkrdVqdS)rTNr)rXr^rrrrY�sTztoo-many-format-argsztoo-few-format-args)rrRr�	Attribute�exprrZstarargs�kwargs�nextrS�infer�InferenceErrorr2rrZ	from_callr
Zparse_format_method_stringr6r4rZZkeyword_arguments�sum�anyrBr]�_check_new_format_specifiers)rDr+rRZstrnodeZ	call_site�fieldsrKZ
manual_posrZZnamed_argumentsZnamed_fieldsZ
check_argsr^�emptyrrrrUrsh





z%StringFormatChecker._check_new_formatcCsh�x`|D�]V\}}|dkrd}t|tj�rVyt�||�}Wqhtjk
rRwYqhXn||kr`q||}|tjdfkrxqyt|�	��}Wntj
k
r�wYnX|r|tjkr�q|jr�t|jtj�r�q|}g}	�x�|D�]�\}
}|tjkr�P|	�
|
|f�|
�rhy|�|�d}WnPtjk
�rdt|d��r@|���r@Pt||	�}|jd||f|d�PYnXn�d}
t|d��r�y|�t�|��}Wn>tjtjtjfk
�r�d	}
Yntj
k
�r�PYnX|tjk�r
Pn.y|�d
�PWntjk
�rd	}
YnX|
�r0t||	�}|jd||f|d�Pyt|�	��}Wq�tj
k
�rZPYq�Xq�WqWdS)zg
        Check attribute and index access in the format
        string ("{0.a}" and "{0[a]}").
        rrN�has_dynamic_getattrzmissing-format-attribute)r,r+F�getitemT�__getitem__zinvalid-format-index)r�numbers�Numberr
Zget_argument_from_callZNoSuchArgumentErrorrr=rcrdre�parent�	Argumentsr�getattrZ
NotFoundErrorrArkrr4rlrZAstroidIndexErrorZAstroidTypeErrorZAttributeInferenceError)rDr+ri�namedr�
specifiers�argnameZargumentZprevious�parsedrrrZ
warn_errorrrrrh�s�







z0StringFormatChecker._check_new_format_specifiersN)r@�
__module__�__qualname__�__doc__r�__implements__rT�MSGS�msgsrrLrVr]rUrhrrrrr(�szSr(cs�eZdZdZeeefZdZdddd�Z	ddd	d
dd�ffZ
d
ZdZ�fdd�Z
dd�Zdd�Zee	���dd��Zee	���dd��Zee	���dd��Zdd�Zdd�Zdd �Z�ZS)!�StringConstantCheckerzCheck string literalsr))zRAnomalous backslash in string: '%s'. String constant might be missing an r prefix.zanomalous-backslash-in-stringzBUsed when a backslash is in a literal string but not as an escape.)zaAnomalous Unicode escape in byte string: '%s'. String constant might be missing an r or u prefix.z"anomalous-unicode-escape-in-stringzSUsed when an escape like \u is encountered in a byte string where it has no effect.)z)Implicit string concatenation found in %szimplicit-str-concat-in-sequenceziString literals are implicitly concatenated in a literal iterable definition : maybe a comma is missing ?)ZW1401ZW1402ZW1403z check-str-concat-over-line-jumpsFZynz<y_or_n>z�This flag controls whether the implicit-str-concat-in-sequence should generate a warning on implicit string concatenation in sequences defined over several lines.)�defaultr?�metavar�helpzabfnrtvx

	\'"01234567ZuUNcstt|�j||�i|_dS)N)�superr}�__init__�
string_tokens)rDr,rb)�	__class__rrr�[szStringConstantChecker.__init__cCsd|jk|_dS)N�unicode_literals)Zfuture_imports�_unicode_literals)rD�modulerrr�process_module_sz$StringConstantChecker.process_modulecCs�d}x�t|�D]�\}\}}}}}|tjkr0|}q|tjkr|�||d�|d}	x2|	t|�kr�||	jtjtjtj	fkr�|	d7}	qTW|	t|�kr�||	nd}
|dkr�|dt|d|d��
|��f}t|�|
f|j|<qWdS)N�asciirr.)
�	enumerate�tokenize�ENCODING�STRING�process_string_tokenrBr?�NEWLINE�NL�COMMENT�encode�str_evalr�)rD�tokens�encoding�i�tok_type�token�startrI�line�j�
next_tokenrrr�process_tokensbs 


"z$StringConstantChecker.process_tokenscCs|�|d�dS)N�list)�check_for_concatenated_strings)rDr+rrr�
visit_list{sz StringConstantChecker.visit_listcCs|�|d�dS)Nr8)r�)rDr+rrr�	visit_setszStringConstantChecker.visit_setcCs|�|d�dS)N�tuple)r�)rDr+rrr�visit_tuple�sz!StringConstantChecker.visit_tuplecCs�x�|jD]�}t|t�r|��tkr|jdkr.q|j|jf|jkrBq|j|j|jf\}}||jkr|dk	r|j	t
jkr|jd|jks�|j
jr|jd|j|fd�qWdS)Nrzimplicit-str-concat-in-sequence)r�r,)r-rrr!�_AST_NODE_STR_TYPES�
col_offset�linenor�r2r?r�r�r��configZ check_str_concat_over_line_jumpsr4)rDZ
iterable_nodeZ
iterable_type�eltZmatching_tokenr�rrrr��s 
z4StringConstantChecker.check_for_concatenated_stringsc	Cs�d}d}x"t|�D]\}}|dkr|}PqW|dkr8dS|d|���}||d�}|dd�|dd�kr|d|kr�nn|dd�}n|dd�}d|kr�|�|||�dS)Nz'"r
���r.����r)r��lower�process_non_raw_string_token)	rDr��	start_rowZ
quote_charr3r�prefixZafter_prefix�string_bodyrrrr��s,z*StringConstantChecker.process_string_tokencCs�d}x�|�d|�}|dkrP||d}|||d�}||jkrtd|krLq�tsV|jr`d|kr`q�|jd||fd	�n||jkr�|jd
||fd	�|d7}qWdS)acheck for bad escapes in a non-raw string.

        prefix: lowercase string of eg 'ur' string prefix markers.
        string_body: the un-parsed body of the string, not including the quote
        marks.
        start_row: integer line number in the source.
        r�\r�r.r�u�bz"anomalous-unicode-escape-in-string)r�r,zanomalous-backslash-in-stringN)�find�UNICODE_ESCAPE_CHARACTERS�_PY3Kr�r4�ESCAPE_CHARACTERS)rDr�r�r�r�Z	next_char�matchrrrr��s(

z2StringConstantChecker.process_non_raw_string_token)r@rwrxryrrrrzrTr|�optionsr�r�r�r�r�rrGr�r�r�r�r�r��
__classcell__rr)r�rr}&s,
	
r}cCs |�t|��|�t|��dS)z.required method to auto register this checker N)Zregister_checkerr(r})Zlinterrrr�register�sr�cCsf|dd���dkr"|dd�}n|d��dkr>|dd�}|dd�dkrZ|dd	�S|dd
�S)a%
    Mostly replicate `ast.literal_eval(token)` manually to avoid any performance hit.
    This supports f-strings, contrary to `ast.literal_eval`.
    We have to support all string literal notations:
    https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
    rr)�frZrfN)r�r��fr.r
)z"""z'''r�r�)r�)r�rrrr��sr�),ry�builtins�sysr�rn�collectionsrrZastroid.argumentsrZastroid.node_classesrZpylint.interfacesrrrZpylint.checkersrr	r
Zpylint.checkers.utilsrr��version_infor�Z_PY27r{ZListZLambdaZFunctionDefZListCompZSetCompZGeneratorExpr>r@r"r#r$rr'r(r}r�r�rrrr�<module>sh



ZC