o
    b                     @   s0  d Z ddlmZmZ ddlmZ ddlZddlZddlZddl	m
Z
 ddlZddlmZ ddlmZmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ edZdd Zdd Zdd Zh dZddhZ h dZ!h dZ"dd Z#dd Z$edddgZ%G dd  d ej&Z'G d!d" d"ej(Z)d#d$ Z*dS )%z<Check Python 2 code for Python 2/3 source-compatible issues.    )absolute_importprint_function)
namedtupleN)	FrozenSet)bases)checkers
interfaces)node_ignores_exceptionfind_try_except_wrapper_node)INFERENCE_FAILURE	INFERENCE)WarningScope)utilsz^0+$c                 C   sD   t | rdS td| r zt| d W dS  ty   Y dS w d S )NFz0\d+   T)_ZEROmatchreint
ValueError)literal r   V/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/python3.py_is_old_octal0   s   
r   c                 C   s&   t | tjrdS t | tjod| jv S )NTdict)
isinstanceastroidDictInstance	basenames)valuer   r   r   _inferred_value_is_dict<   s   r    c                 C   s   t | dd dv S )Nname)__builtin__builtins)getattrnoder   r   r   _is_builtinB   s   r'   >   allanymaxminsetsumr   iterlisttuplefiltersortedreversed	enumerate	frozensetOrderedDictjoinfrom_iterable>   builtins.set.updatebuiltins.dict.updatebuiltins.list.extend>   keysitemsvaluesc                 C   sf  | j }t|tjrdS t|tjr|j| krdS nt|tjrjt|jtjr=|j	|jj
d }t|r<|jj
tv r<dS nt|jtjrL|jjtv rLdS t|j}|ri| tv r\dS | }|ri|j
dkridS n?t|tjrt|jd tjtjfrt|jd jdkrdS n t|tjrt|jdkr|jd d dkrdS t|tjrdS t|tjrdS dS )z{Check if the node is being used as an iterator.

    Definition is taken from lib2to3.fixer_util.in_special_context().
    Tr   	itertools   inF)parentr   r   ForZComprehensionr.   CallfuncNamelookupr!   r'   _ACCEPTS_ITERATOR	AttributeattrnameATTRIBUTES_ACCEPTS_ITERATORr   
safe_inferqname _BUILTIN_METHOD_ACCEPTS_ITERATORrootAssigntargetsListTupleleneltsCompareops	YieldFromStarred)r&   rB   Zparent_scopeinferredrO   r   r   r   _in_iterating_contexta   sT   

r[   c                 C   s    | j }t|tjtjtjtjfS )zAChecks if an import node is in the context of a conditional.
    )rB   r   r   Z	TryExceptExceptHandlerIfIfExp)r&   rB   r   r   r   _is_conditional_import   s   r_   Branchr&   is_py2_onlyc                
       s  e Zd ZejZdZdZi ddddddd	d
ddgifddddddgifddddej	dgdfddddddifddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3i d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOddPgifdQdRdSdTddUgifdVdWdXdYdZd[i d\d]d^d_d`dadbdcdddedfdgdhdidjdkddlgifdmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddi ddddddddddddddddddddddddddddddddZ
eg dZeg dZeg dZdedgideg dideg dieg ddeg didedhideh didedhidZdej  krcdk rin ne Zn	edd dD Z fddZd fdd	Zdd Zdd Zdd ZddÄ Zddń ZddǄ ZddɄ Zedʡdd̄ Zed͡ddτ Zddф Z edҡddԄ Z!dddׄZ"ddل Z#ddۄ Z$edܡddބ Z%edߡdd Z&dd Z'e(dd Z)e(dd Z*e(dd Z+e(dd Z,dd Z-dd Z.edNdd Z/dd Z0dd Z1edddd Z2ed	d͡dd Z3eddd Z4edSddd Z5d d Z6  Z7S (  Python3CheckerFpython3ZE1601)zprint statement usedprint-statementzGUsed when a print statement is used (`print` is a function in Python 3)ZE1602)zParameter unpacking specifiedparameter-unpackingzTUsed when parameter unpacking is specified for a function(Python 3 doesn't allow it)ZE1603z=Implicit unpacking of exceptions is not supported in Python 3unpacking-in-exceptzwPython3 will not allow implicit unpacking of exceptions in except clauses. See http://www.python.org/dev/peps/pep-3110/	old_names)ZW0712rf   ZE1604z=Use raise ErrorClass(args) instead of raise ErrorClass, args.old-raise-syntaxzZUsed when the alternate raise syntax 'raise foo, bar' is used instead of 'raise foo(bar)'.)ZW0121rh   ZE1605zUse of the `` operatorbacktickzYUsed when the deprecated "``" (backtick) operator is used instead  of the str() function.)ZW0333ri   )scoperg   ZE1609z%Import * only allowed at module levelimport-star-module-levelzNUsed when the import star syntax is used somewhere else than the module level.
maxversion   r   ZW1601)zapply built-in referencedzapply-builtinzKUsed when the apply built-in function is referenced (missing from Python 3)ZW1602)zbasestring built-in referencedzbasestring-builtinzPUsed when the basestring built-in function is referenced (missing from Python 3)ZW1603)zbuffer built-in referencedzbuffer-builtinzLUsed when the buffer built-in function is referenced (missing from Python 3)ZW1604)zcmp built-in referencedzcmp-builtinzIUsed when the cmp built-in function is referenced (missing from Python 3)ZW1605)zcoerce built-in referencedzcoerce-builtinzLUsed when the coerce built-in function is referenced (missing from Python 3)ZW1606)zexecfile built-in referencedzexecfile-builtinzNUsed when the execfile built-in function is referenced (missing from Python 3)ZW1607)zfile built-in referencedzfile-builtinzJUsed when the file built-in function is referenced (missing from Python 3)ZW1608)zlong built-in referencedzlong-builtinzJUsed when the long built-in function is referenced (missing from Python 3)ZW1609)zraw_input built-in referencedzraw_input-builtinzOUsed when the raw_input built-in function is referenced (missing from Python 3)ZW1610)zreduce built-in referencedzreduce-builtinzLUsed when the reduce built-in function is referenced (missing from Python 3)ZW1611)z!StandardError built-in referencedzstandarderror-builtinzSUsed when the StandardError built-in function is referenced (missing from Python 3)ZW1612)zunicode built-in referencedzunicode-builtinzMUsed when the unicode built-in function is referenced (missing from Python 3)ZW1613)zxrange built-in referencedzxrange-builtinzLUsed when the xrange built-in function is referenced (missing from Python 3)ZW1614)z__coerce__ method definedzcoerce-methodzIUsed when a __coerce__ method is defined (method is not used by Python 3)ZW1615)z__delslice__ method definedzdelslice-methodzKUsed when a __delslice__ method is defined (method is not used by Python 3)ZW1616)z__getslice__ method definedzgetslice-methodzKUsed when a __getslice__ method is defined (method is not used by Python 3)ZW1617)z__setslice__ method definedzsetslice-methodzKUsed when a __setslice__ method is defined (method is not used by Python 3)ZW1618)z7import missing `from __future__ import absolute_import`no-absolute-importztUsed when an import is not accompanied by ``from __future__ import absolute_import`` (default behaviour in Python 3)ZW1619)z!division w/o __future__ statementold-divisionzUsed for non-floor division w/o a float literal or ``from __future__ import division`` (Python 3 returns a float for int division unconditionally)ZW1620)zCalling a dict.iter*() methoddict-iter-methodz]Used for calls to dict.iterkeys(), itervalues() or iteritems() (Python 3 lacks these methods)ZW1621)zCalling a dict.view*() methoddict-view-methodz]Used for calls to dict.viewkeys(), viewvalues() or viewitems() (Python 3 lacks these methods)ZW1622)z#Called a next() method on an objectnext-method-calledzZUsed when an object's next() method is called (Python 3 uses the next() built-in function)ZW1623)z.Assigning to a class's __metaclass__ attributemetaclass-assignmentzUsed when a metaclass is specified by assigning to __metaclass__ (Python 3 specifies the metaclass as a class statement argument)ZW1624z-Indexing exceptions will not work on Python 3indexing-exceptionzSIndexing exceptions will not work on Python 3. Use `exception.args[index]` instead.)ZW0713ru   ZW1625zRaising a string exceptionraising-stringzGUsed when a string exception is raised. This will not work on Python 3.)ZW0701rv   ZW1626)zreload built-in referencedzreload-builtinzUsed when the reload built-in function is referenced (missing from Python 3). You can use instead imp.reload or importlib.reload.ZW1627)z__oct__ method definedz
oct-methodzGUsed when an __oct__ method is defined (method is not used by Python 3)ZW1628)z__hex__ method definedz
hex-methodzFUsed when a __hex__ method is defined (method is not used by Python 3)ZW1629)z__nonzero__ method definedznonzero-methodzJUsed when a __nonzero__ method is defined (method is not used by Python 3)ZW1630)z__cmp__ method definedz
cmp-methodzFUsed when a __cmp__ method is defined (method is not used by Python 3)ZW1632)zinput built-in referencedzinput-builtinzYUsed when the input built-in is referenced (backwards-incompatible semantics in Python 3)ZW1633)zround built-in referencedzround-builtinzYUsed when the round built-in is referenced (backwards-incompatible semantics in Python 3)ZW1634)zintern built-in referencedzintern-builtinzMUsed when the intern built-in is referenced (Moved to sys.intern in Python 3)ZW1635)zunichr built-in referencedzunichr-builtinzAUsed when the unichr built-in is referenced (Use chr in Python 3)ZW1636z*map built-in referenced when not iteratingzmap-builtin-not-iteratingzeUsed when the map built-in is referenced in a non-iterating context (returns an iterator in Python 3))ZW1631zimplicit-map-evaluationZW1637)z*zip built-in referenced when not iteratingzzip-builtin-not-iteratingzeUsed when the zip built-in is referenced in a non-iterating context (returns an iterator in Python 3)ZW1638)z,range built-in referenced when not iteratingzrange-builtin-not-iteratingzgUsed when the range built-in is referenced in a non-iterating context (returns an iterator in Python 3)ZW1639)z-filter built-in referenced when not iteratingzfilter-builtin-not-iteratingzhUsed when the filter built-in is referenced in a non-iterating context (returns an iterator in Python 3)ZW1640)z-Using the cmp argument for list.sort / sortedusing-cmp-argumentzUsing the cmp argument for list.sort or the sorted builtin should be avoided, since it was removed in Python 3. Using either `key` or `functools.cmp_to_key` should be preferred.ZW1641)z6Implementing __eq__ without also implementing __hash__eq-without-hashzUsed when a class implements __eq__ but not __hash__.  In Python 2, objects get object.__hash__ as the default implementation, in Python 3 objects get None as their default __hash__ implementation if they also implement __eq__.ZW1642)z__div__ method definedz
div-methodzUsed when a __div__ method is defined.  Using `__truediv__` and setting__div__ = __truediv__ should be preferred.(method is not used by Python 3)ZW1643)z__idiv__ method definedzidiv-methodzUsed when an __idiv__ method is defined.  Using `__itruediv__` and setting__idiv__ = __itruediv__ should be preferred.(method is not used by Python 3)ZW1644)z__rdiv__ method definedzrdiv-methodzUsed when a __rdiv__ method is defined.  Using `__rtruediv__` and setting__rdiv__ = __rtruediv__ should be preferred.(method is not used by Python 3)ZW1645)z%Exception.message removed in Python 3exception-message-attributezYUsed when the message attribute is accessed on an Exception.  Use str(exception) instead.ZW1646)z$non-text encoding used in str.decodeinvalid-str-codeczqUsed when using str.encode or str.decode with a non-text encoding.  Use codecs module to handle arbitrary codecs.ZW1647)zsys.maxint removed in Python 3sys-max-intz9Used when accessing sys.maxint.  Use sys.maxsize instead.ZW1648)zModule moved in Python 3bad-python3-importz?Used when importing a module that no longer exists in Python 3.ZW1649)z4Accessing a deprecated function on the string moduledeprecated-string-functionzKUsed when accessing a string function that has been deprecated in Python 3.ZW1650)z:Using str.translate with deprecated deletechars parametersdeprecated-str-translate-callzwUsed when using the deprecated deletechars parameters from str.translate.  Use re.sub to remove the desired characters ZW1651)z7Accessing a deprecated function on the itertools moduledeprecated-itertools-functionzNUsed when accessing a function on itertools that has been removed in Python 3.ZW1652)z1Accessing a deprecated fields on the types moduledeprecated-types-fieldzGUsed when accessing a field on types that has been removed in Python 3.ZW1653)znext method definednext-method-definedzyUsed when a next method is defined that would be an iterator in Python 2 but is treated as a normal function in Python 3.ZW1654)z(dict.items referenced when not iteratingzdict-items-not-iteratingz_Used when dict.items is referenced in a non-iterating context (returns an iterator in Python 3)ZW1655)z'dict.keys referenced when not iteratingzdict-keys-not-iteratingz^Used when dict.keys is referenced in a non-iterating context (returns an iterator in Python 3)ZW1656)z)dict.values referenced when not iteratingzdict-values-not-iteratingz`Used when dict.values is referenced in a non-iterating context (returns an iterator in Python 3)ZW1657)z4Accessing a removed attribute on the operator moduledeprecated-operator-functionzQUsed when accessing a field on operator module that has been removed in Python 3.ZW1658)z2Accessing a removed attribute on the urllib moduledeprecated-urllib-functionzXUsed when accessing a field on urllib module that has been removed or moved in Python 3.ZW1659)z(Accessing a removed xreadlines attributexreadlines-attributezTUsed when accessing the xreadlines() function on a file stream, removed in Python 3.ZW1660)z/Accessing a removed attribute on the sys moduledeprecated-sys-functionzLUsed when accessing a field on sys module that has been removed in Python 3.ZW1661)z=Using an exception object that was bound by an except handlerexception-escapezEmitted when using an exception, that was bound in an except handler, outside of the except handler. On Python 3 these exceptions will be deleted once they get out of the except handler.ZW1662)z6Using a variable that was bound inside a comprehensioncomprehension-escapezEmitted when using a variable, that was bound in a comprehension handler, outside of the comprehension itself. On Python 3 these variables will be deleted outside of the comprehension.)apply
basestringbuffercmpZcoerceZexecfilefileinputinternlong	raw_inputreduceroundStandardErrorunichrunicodexrangereload)Z
__coerce__Z__delslice__Z__getslice__Z__setslice__Z__oct__Z__hex____nonzero__Z__cmp__Z__div__Z__idiv__Z__rdiv__)base64_codecbase64base_64	bz2_codecbz2	hex_codechexquopri_codecquopriquotedprintablequoted_printableuu_codecuu
zlib_codeczlibziprot13rot_13sysZmaxintr?   )izipifilterimapizip_longestifilterfalsetypes)EllipsisTypeZ
XRangeTypeZComplexTypeZ
StringTypeZTypeTypeZLongTypeZUnicodeTypeZ	ClassTypeZ
BufferTypeZStringTypesNotImplementedTypeNoneTypeZInstanceTypeZ	FloatTypeZ	SliceTypeZUnboundMethodTypeZ
ObjectTypeZIntTypeZ	TupleTypeZListTypeDictTypeFileTypeZDictionaryTypeZBooleanTypeZDictProxyType)]anydbmBaseHTTPServerr"   CGIHTTPServerConfigParsercopy_regcPickle	cStringIOCookie	cookielibdbhashdumbdbmZdumbdbDialogDocXMLRPCServer
FileDialogZFixTkgdbmhtmlentitydefs
HTMLParserhttplib
markupbaseQueuereprrobotparserScrolledTextSimpleDialogSimpleHTTPServerSimpleXMLRPCServerStringIOdummy_threadSocketServerztest.test_supportTkinterTixTkconstantstkColorChoosertkCommonDialogTkdndtkFileDialogtkFonttkMessageBoxtkSimpleDialogUserList
UserStringwhichdb_winreg	xmlrpclibZaudiodevZBastionZbsddb185Zbsddb3ZCanvasZcfmfileclcommandscompilerZdircachedl	exceptionZfpformatZhtmllibZihooksZimageopZimputilZlinuxaudiodevmd5ZmhlibZ	mimetoolsZ
MimeWriterZmimifyZ	multifilemutexnewZpopen2Z	posixfileZpureZrexecZrfc822ZsetsshaZsgmllibZsreZ	stringoldZsunaudiosvztest.testallthreadZtimingZtoaiffuserurllib2urlparsestring)$	maketransatofatoiZatol
capitalize
expandtabsfindrfindindexrindexcountlowerletterssplitrsplitZsplitfieldsr7   Z
joinfieldslstriprstripstripswapcase	translateupperljustrjustcenterzfillreplaceZ	lowercaser   Z	uppercaseZ
atol_errorZ
atof_errorZ
atoi_errorZindex_erroroperatordivurllib>'   basejoinalways_safegetproxies_macosx_sysconfproxy_bypass_macosx_sysconfmainquoteunwrapaddbaseaddinfounquoteurlopenftpcachesplittag	ftperrors	noheaders	splitattr	splithost	splitport	splittype	splituser	urlencode
addinfourl
ftpwrapper
getproxies
quote_plus
reporthook
splitnport
splitquery
splitvalue
urlcleanupsplitpasswdurlretrieveaddclosehookpathname2urlproxy_bypassunquote_plusurl2pathnamegetproxies_environmentproxy_bypass_environmentZ	exc_clear)r{   r   r   r|   r}   r   r   r   )rn      )rn   r5  r5  c                 C   s   g | ]	}t | qS r   )r   Zextract_node	repr_tree.0xr   r   r   
<listcomp>x  s    zPython3Checker.<listcomp>)zsys.version_info[0] == 2zsys.version_info[0] < 3zsys.version_info == (2, 7)zsys.version_info <= (2, 7)zsys.version_info < (3, 0)c                    s4   d| _ d| _t | _g | _tt| j|i | d S )NF)_future_division_future_absolute_importr,   _modules_warned_about_branch_stacksuperrb   __init__)selfargskwargs	__class__r   r   r@    s
   zPython3Checker.__init__c                    s<   |s| j r| j d jstt| j|g|R i | d S d S )N)r>  ra   r?  rb   add_message)rA  Zmsg_idalways_warnrB  rC  rD  r   r   rG    s   
"zPython3Checker.add_messagec                 C   sf   t |jtjr t |jjtjr |jjjdkr|jjdkrdS dS t |jtjr1|j	 | j
v r1dS dS )NsixPY2TF)r   testr   rI   exprrF   r!   rJ   rV   r6  _python_2_testsrA  r&   r   r   r   _is_py2_test  s   
zPython3Checker._is_py2_testc                 C      | j t|| | d S Nr>  appendr`   rO  rN  r   r   r   visit_if     zPython3Checker.visit_ifc                 C      | j  j|ks
J d S rQ  r>  popr&   rN  r   r   r   leave_if     zPython3Checker.leave_ifc                 C   rP  rQ  rR  rN  r   r   r   visit_ifexp  rU  zPython3Checker.visit_ifexpc                 C   rV  rQ  rW  rN  r   r   r   leave_ifexp  rZ  zPython3Checker.leave_ifexpc                 C   s   d| _ d| _dS )z*Clear checker state after previous module.FN)r;  r<  rN  r   r   r   visit_module  s   
zPython3Checker.visit_modulec                 C   s   |  rI|j| jv r%|j}|jdr|jdd }| j|d |d d S |jdkrKd}t|tjd gr8d	}t	|j
j
|krM| jd
|d d S d S d S d S )N__   z-methodr%   nextr@   z.staticmethodr   r   )Z	is_methodr!   _unused_magic_methods
startswithrG  r   Zdecorated_withr   BUILTINSrT   rB  )rA  r&   method_nameZfailing_arg_countr   r   r   visit_functiondef  s   
	z Python3Checker.visit_functiondefre   c                 C   s*   |j D ]}t|tjr| jd|d qd S )Nre   r%   )rB  r   r   rS   rG  rA  r&   argr   r   r   visit_arguments  s
   
zPython3Checker.visit_argumentsr   c                    s   dd j D  j }|jtjtjd}t fdd|jtjtjdD }|r-d S t	 }t
|}|D ]&}|j vsN|jjksN|j|v sN| krOq6||j | jd|d q6d S )Nc                 S   s"   h | ]}t |jtjr|jjqS r   )r   targetr   
AssignNamer!   )r8  	generatorr   r   r   	<setcomp>  s    z0Python3Checker.visit_listcomp.<locals>.<setcomp>Z
skip_klassc                 3   s*    | ]}|j  v r|jjkr|V  qd S rQ  r!   linenor8  Zassign_namenamesr&   r   r   	<genexpr>  s    

z0Python3Checker.visit_listcomp.<locals>.<genexpr>r   r%   )
generatorsrB   rj   nodes_of_classr   rF   FunctionDefr)   rk  r,   r/   r!   rp  addrG  )rA  r&   rj   scope_namesZhas_redefined_assign_nameZemitted_for_names
scope_namer   rr  r   visit_listcomp  s6   


zPython3Checker.visit_listcompc                 C   sh   | |j\}}t|sdS |j| jvrdS t|s"tt|tjr$dS |j	 d }| j
||d dS )z+Detect when a "bad" built-in is referenced.Nz-builtinr%   )rG   r!   r'   _bad_builtinsr	   r   r
   r   r\   r   rG  )rA  r&   
found_node_messager   r   r   
visit_name  s   

zPython3Checker.visit_namerd   c                 C   s   | j d|dd d S )Nrd   T)r&   rH  rG  rN  r   r   r   visit_print  s   zPython3Checker.visit_printTc                 C   st   | j  D ]2\}}||v r7|| jvr7t|tr'|r&| j| | j||d q|r7|| |r7| j||d qd S )Nr%   )_bad_python3_module_mapr=   r=  r   r5   rx  rG  intersection)rA  r&   module
attributesreport_on_modulesr  Z
module_mapr   r   r   _warn_if_deprecated  s   
z"Python3Checker._warn_if_deprecatedc                 C   s   |j dkr|jD ]\}}|dkrd| _q|dkrd| _qn(| js0| jdr0| jd|d d| _t|sE|jsE| 	||j dd |jD  |jd	 d	 d
kre| jdrgt
| tjsi| jd|d d S d S d S d S )N
__future__divisionTr   ro   r%   c                 S   s   h | ]}|d  qS )r   r   r7  r   r   r   rm    s    z2Python3Checker.visit_importfrom.<locals>.<setcomp>r   *rk   )modnamers  r;  r<  linteris_message_enabledrG  r_   levelr  r   rj   r   ModulerA  r&   r!   r~  r   r   r   visit_importfrom  s*   
zPython3Checker.visit_importfromc                 C   sT   | j s| jdr| jd|d d| _ t|s&|jD ]\}}| ||d  qd S d S )Nro   r%   T)r<  r  r  rG  r_   rs  r  r  r   r   r   visit_import  s   zPython3Checker.visit_importrt   c                 C   s`   d|j v r| jd|d t|j dd | D }d|v r,d|vr.| jd|d d S d S d S )	N__metaclass__rt   r%   c                 s   s    | ]}|j V  qd S rQ  )r!   r7  r   r   r   rt  (  s    z0Python3Checker.visit_classdef.<locals>.<genexpr>__eq____hash__rx   )localsrG  r,   unionZ	mymethods)rA  r&   Zlocals_and_methodsr   r   r   visit_classdef$  s   
zPython3Checker.visit_classdefrp   c                 C   sZ   | j s)|jdkr+|j|jfD ]}t|tjrt|jtr d S q| j	d|d d S d S d S )N/rp   r%   )
r;  opleftrightr   r   Constr   floatrG  rg  r   r   r   visit_binop,  s   zPython3Checker.visit_binopc                 C   s   g }t |jtjr0|jjdkr0t|jj}|sd S dt	j
}t |tjs,| |kr/|j}n&t |jtjrV|jjdkrVt|j}|sGd S dt	j
}| |krV|j}|pYg D ]}|jdkrk| jd|d  d S qZd S )Nsortz{}.listr2   z	{}.sortedr   rw   r%   )r   rE   r   rI   rJ   r   rL   rL  formatr   rd  rR   rM   keywordsrF   r!   rh  rG  )rA  r&   rC  rZ   Zbuiltins_listZbuiltins_sortedkwargr   r   r   _check_cmp_argument5  s,   
z"Python3Checker._check_cmp_argumentc                 C   s$   t | tjrt | jtS t | tjS rQ  )r   r   r  r   strrF   r%   r   r   r   _is_constant_string_or_nameO  s   z*Python3Checker._is_constant_string_or_namec                 C   s   t | tjo
| jd u S rQ  )r   r   r  r   r%   r   r   r   _is_noneU  s   zPython3Checker._is_nonec                 C   s    t | j|kot| jo| j S rQ  )rT   rB  r(   r  )r&   Znumber_of_argsr   r   r   _has_only_n_positional_argsY  s    z*Python3Checker._has_only_n_positional_argsc                 C   sH   | rt nt}| D ]}|tju rt}qt|tjrt|jts! d S q|S rQ  )r   r   r   Uninferabler   r  r   r  )inferred_types
confidenceZinferred_typer   r   r   _could_be_string]  s   


zPython3Checker._could_be_stringc           
      C   s  |  | t|jtjrt }zE|jj D ]<}|tju rq|	| t|tj
r6| j||j|jjhdd t|rR|jjtv rRt|sRd|jj}| j||d qW n
 tjy^   Y nw |jr| |}|r|jjdv rt|jdkr|jd r|jd }| || |jjdkr| |d	r| |jd r| |jd r| jd
||d d S |jrd S |jjdkr| jd|d d S |jjdv r| jd|d d S |jjdv r| jd|d d S d S t|jtjr8|j|jjd }t|r:|jjdv rt|sd|jj}| j||d |jjdkr<|jr>|j}|p#g D ]}	|	jdkr6| |	j |  d S q$d S d S d S d S d S )NFr  zdict-{}-not-iteratingr%   )encodedecoder@   r   r  r_  r~   )r&   r  ra  rs   )iterkeys
itervalues	iteritemsrq   )viewkeys
viewvalues	viewitemsrr   )r1   mapranger   z{}-builtin-not-iteratingopenencoding)!r  r   rE   r   rI   r,   rL  inferr  rx  r  r  r!   rJ   r    DICT_METHODSr[   r  rG  InferenceErrorrB  r  rT   _validate_encodingr  r  r  r  rF   rG   r'   rh  r   )
rA  r&   r  Zinferred_receivercheckerZis_str_confidenceZ	first_argr}  rC  r  r   r   r   
visit_callj  s   










zPython3Checker.visit_callc                 C   s6   t |tjr|j}|| jv r| jd|d d S d S d S )Nrz   r%   )r   r   r  r   _invalid_encodingsrG  )rA  r  r&   r   r   r   r   r    s   
z!Python3Checker._validate_encodingc                 C   sT   z|j  D ]}t|tjsqt|r| jd|d qW dS  tjy)   Y dS w )z Look for indexing exceptions. ru   r%   N)	r   r  r   r   r   r   inherit_from_std_exrG  r  )rA  r&   rZ   r   r   r   visit_subscript  s   
zPython3Checker.visit_subscriptc                 C   s"   t | tjr| | d S d S rQ  )r   Zassign_typer   	AugAssignvisit_attributerN  r   r   r   visit_assignattr  s   zPython3Checker.visit_assignattrc                 C   s   |  | d S rQ  )r  rN  r   r   r   visit_delattr  s   zPython3Checker.visit_delattrry   r   c                 C   s   |j dkr| jd|d dS d}z:|j D ]1}t|tjr5t|r5|j |kr5||j	v r.q| jd|d t|tj
rG| j||j|j hdd qW dS  tjyU   Y dS w )	zLook for removed attributesZ
xreadlinesr   r%   Nr  ry   Fr  )rJ   rG  rL  r  r   r   r   r   r  Zinstance_attrsr  r  r!   r  )rA  r&   Zexception_messagerZ   r   r   r   r    s,   


zPython3Checker.visit_attributec                    s   dd  t jtjtjfr| jdd dS jsdS j }|jtj	tj
d}t|} fdd|D }fd	d
|jtjtj
dD }|D ]tfdd|D rYqJ| jdd qJdS )z@Visit an except handler block and check for exception unpacking.c                 S   sX   |   }| }|r!||kr!t|tjs!|j}|r!||kr!t|tjrt|tjo+|j| kS rQ  )rj   r   r   r\   rB   type)r&   rj   currentr   r   r   _is_used_in_except_block  s    

zDPython3Checker.visit_excepthandler.<locals>._is_used_in_except_blockrf   r%   Nrn  c                    s2   g | ]}|j j j kr|jjkr |s|qS r   ro  )r8  rz  )r  r&   r   r   r:  
  s    
z6Python3Checker.visit_excepthandler.<locals>.<listcomp>c                    s    h | ]}|j  j j kr|jqS r   ro  rq  r%   r   r   rm    s    z5Python3Checker.visit_excepthandler.<locals>.<setcomp>c                 3   s,    | ]}j |  k o j k n  V  qd S rQ  )rp  r8  elem)leaked_namer&   r   r   rt    s
    
z5Python3Checker.visit_excepthandler.<locals>.<genexpr>r   )r   r!   r   rS   rR   rG  rB   rj   rv  rF   rw  r/   rk  r)   )rA  r&   rj   ry  Zpotential_leaked_namesZreassignments_for_same_namer   )r  r  r&   r   visit_excepthandler  s0   

z"Python3Checker.visit_excepthandlerc                 C   s   | j d|d d S )Nri   r%   r  rN  r   r   r   
visit_repr   s   zPython3Checker.visit_reprc                 C   s^   |j du rdS |j }| ||rdS z	tt|}W n tjy&   Y dS w | || dS )z[Visit a raise statement and check for raising
        strings or old-raise-syntax.
        N)exc_check_raise_valuera  r   Zunpack_inferr  rA  r&   rL  r   r   r   r   visit_raise$  s   
zPython3Checker.visit_raisec                 C   s2   t |tjr|j}t |tr| jd|d dS d S )Nrv   r%   T)r   r   r  r   r  rG  r  r   r   r   r  6  s   
z!Python3Checker._check_raise_value)F)T)8__name__
__module____qualname__r   ZIAstroidChecker__implements__enabledr!   r   ZNODEmsgsr5   r|  rb  r  r  r   version_inforM  r@  rG  rO  rT  rY  r[  r\  r]  rf  r   Zcheck_messagesri  r{  r  r  r  r  r  r  r  r  staticmethodr  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__r   r   rD  r   rb      sJ   	&-39?EKQW]ciou{           "  (  .  4  :  A  H  O  U  Z  `  f  l  r  x  }                       &    -    4    ;    A    G    L    Q    V    \    a    f    l    r    x    ~                                   )b*-  c

 

	





S




/


rb   c                   @   sd   e Zd ZejZdZdZdddddifdd	d
ddgdfdddddifdddddifdZdd Z	dS )Python3TokenCheckerrc   FzUse of long suffixlong-suffixz~Used when "l" or "L" is used to mark a long integer. This will not work in Python 3, since `int` and `long` types have merged.rl   rm   zUse of the <> operatorold-ne-operatorz\Used when the deprecated "<>" operator is used instead of "!=". This is removed in Python 3.)ZW0331r  )rl   rg   zUse of old octal literalold-octal-literalzrUsed when encountering the old octal syntax, removed in Python 3. To use the new syntax, prepend 0o on the number.z-Non-ascii bytes literals not supported in 3.xnon-ascii-bytes-literalzdUsed when non-ascii bytes literals are found in a program. They are no longer supported in Python 3.)ZE1606ZE1607ZE1608ZE1610c                 C   s   t |D ]]\}\}}}}}|tjkr0| dr#| jd|d d nt|r0| jd|d d || d dkrE| jd|| d	 d d |tjkra|d
rat	dd |D ra| jd|d d qd S )Nlr  r   )liner  r@   z<>r  r_  bc                 s   s     | ]}t |d kr|V  qdS )   N)ordr  r   r   r   rt  p  s    z5Python3TokenChecker.process_tokens.<locals>.<genexpr>r  )
r4   tokenizeNUMBERr   endswithrG  r   STRINGrc  r)   )rA  tokensidxtok_typetokenstartr~  r   r   r   process_tokense  s   
z"Python3TokenChecker.process_tokensN)
r  r  r  r   ZITokenCheckerr  r!   r  r  r  r   r   r   r   r  ?  s4    	
	!r  c                 C   s    |  t|  |  t|  d S rQ  )Zregister_checkerrb   r  )r  r   r   r   registert  s   r  )+__doc__r  r   r   collectionsr   r   r   r  typingr   r   r   Zpylintr   r   Zpylint.checkers.utilsr	   r
   Zpylint.interfacesr   r   Zpylint.utilsr   Zpylint.checkersr   compiler   r   r    r'   rH   rK   rN   r  r[   r_   r`   ZBaseCheckerrb   ZBaseTokenCheckerr  r  r   r   r   r   <module>   sJ   
9	         "5