a
    =a]                     @   s  d Z ddlZddlmZ ddlZddlmZmZmZ ddl	m
Z
 ddhZdZd	Zd
ZdZdhZdZdZdZddhdhdhdhddhdhh ddZddddddddddddddd d!d d d d d d"d#d#d$d$d%d%d&d'd(id)Zd*hh d+d,Zh d-h d.h d/d0h d1h d2h d3h d4h d5d6hh d7d8d9hh d:h d;h d<h d=d>d?Zd@hdAdBhh dCdDdEdFhidGZdHdI ZG dJdK dKeeZdLdM ZdS )Nz0Checkers for various standard library functions.    N)Iterable)BaseCheckerDeprecatedMixinutils)IAstroidCheckeropenfilezunittest.casezthreading.Threadz	copy.copyzos._Environz	os.getenvzsubprocess.Popenzsubprocess.run_ioztkinter.tixZfpectlZoptparseimpZ	formatterZasynchatZasyncoreZmacpath>   Zlib2to3ZbinhexparserZsymbol)r   r   r         r   r      r   r      r   r      r   r      r   r   	   r   ))Nx)intboolfloat))Nloop))r   r   ))r   codeset))r   r   )Nfunc)r    )Nobj))NZfunction))Nfn))Ncallback))Nc)NZtypeid)zasyncio.tasks.sleepzasyncio.tasks.gatherzasyncio.tasks.shieldzasyncio.tasks.wait_forzasyncio.tasks.waitzasyncio.tasks.as_completedz)asyncio.subprocess.create_subprocess_execz*asyncio.subprocess.create_subprocess_shellzgettext.translationzgettext.installzfunctools.partialmethodzweakref.finalizezprofile.Profile.runcallzcProfile.Profile.runcallzbdb.Bdb.runcallztrace.Trace.runfunczcurses.wrapperz!unittest.case.TestCase.addCleanupz3concurrent.futures.thread.ThreadPoolExecutor.submitz5concurrent.futures.process.ProcessPoolExecutor.submitz"contextlib._BaseExitStack.callbackz-contextlib.AsyncExitStack.push_async_callbackz&multiprocessing.managers.Server.createz2multiprocessing.managers.SharedMemoryServer.createzrandom.Random.shuffle))   Zrandom)r   r      r   r   zasyncio.coroutine>   zabc.abstractstaticmethodzabc.abstractpropertyzabc.abstractclassmethod)r'   r   r   r   >   zcgi.parse_qsztkinter.Misc.tk_menuBarzcgi.parse_qslz,distutils.command.sdist.sdist.check_metadataz2distutils.command.register.register.check_metadataz tkinter.Menu.tk_bindForTraversalzctypes.c_buffer>   z	os.popen2z	os.popen3zcommands.getstatuszmacostools.touchedz	os.popen4>	   z#unittest.case.TestCase.assertEqualsz)unittest.case.TestCase.assertAlmostEqualsz&unittest.case.TestCase.assertNotEqualsz,unittest.case.TestCase.assertNotAlmostEquals)xml.etree.ElementTree.Element.getiterator'xml.etree.ElementTree.XMLParser.doctype+xml.etree.ElementTree.XMLParser.getiteratorzunittest.case.TestCase.assert_)xml.etree.ElementTree.Element.getchildren))r   r   r   )r   r   r   >   ZfailIfAlmostEqualZassert_Z
failUnlessZfailIfZassertNotEqualsZassertAlmostEqualsZassertEqualszinspect.getargspecZfailUnlessAlmostEqualZassertRaisesRegexpZassertNotAlmostEqualsZfailIfEqualZfailUnlessEqualZassertNotRegexpMatchesZassertRegexpMatchesZfailUnlessRaises>   zntpath.splitunczbase64.encodestringzos.stat_float_timeszbase64.decodestringzos.path.splitunc>   z#configparser.RawConfigParser.readfpz
cgi.escaper+   r*   r,   r-   >   zplatform.popenzinspect.getmoduleinfozlogging.Logger.warnznntplib._NNTPBase.xpathzlogging.warnzsqlite3.OptimizedUnicodezlogging.LoggerAdapter.warnz
time.clock>   zimportlib.find_loaderzplistlib.writePlistzplistlib.readPlistFromByteszplistlib.writePlistToByteszplistlib.readPlistzasyncio.tasks.async>   zplatform.linux_distributionzinspect.formatargspeczfractions.gcdzplatform.distzinspect.getcallargsz4importlib._bootstrap_external.FileLoader.load_modulez_ssl.RAND_pseudo_bytes>   zssl.wrap_socketzlocale.formatzsys.get_coroutine_wrapperzwave.openfpthreading.Thread.isAlivezsunau.openfpzasyncio.Task.all_taskzasyncio.Task.current_taskzsys.set_coroutine_wrapperzaifc.openfpzssl.match_hostname>   zgettext.lngettextzgettext.lgettextr.   zgettext.bind_textdomain_codesetz'gettext.NullTranslations.output_charsetzgettext.ldngettextzgettext.ldgettextz+gettext.NullTranslations.set_output_charset>   zbinascii.a2b_hqxzbinascii.rlecode_hqxzbinascii.rledecode_hqxzbinascii.b2a_hqx>   zthreading.Condition.notifyAllzthreading.activeCountz_sqlite3.enable_shared_cachezcgi.logzpathlib.Path.link_toz!zipimport.zipimporter.find_loaderzthreading.Event.isSetzthreading.Thread.setDaemonzthreading.Thread.setNamezthreading.Thread.getNamezthreading.currentThreadzthreading.Thread.isDaemonz!zipimport.zipimporter.load_modulez!zipimport.zipimporter.find_module))r   r   r   )r   r&   r   r   r)   r   )r   r   r   r   r   r   r'   r   )r   
   r   )r   r   r   FinderImpImporter	ImpLoader>   AsyncIterator
CollectionMappingViewMapping
ReversibleSet
ValuesView
ByteStringAsyncIterableMutableMappingCallable	CoroutineSequenceAsyncGeneratorMutableSequencer   KeysView	Container
MutableSet	Awaitable	GeneratorSizedIteratorHashable	ItemsView)zimportlib.abcpkgutilcollectionsZsmtpdZMailmanProxy)r)   r   c           
      C   s   t | tsdS t| }d}d|v }|t| s>t| t|krBdS d|v }d|v }d|v }d|v }d|v }d	|v r|s~|s~|rdS d
}|r|rdS || | | }	|	dkrdS |s|s|s|sdS d
S )NFzrwatb+Uxr   rwatbUTr&   )
isinstancestrsetlen)
modeZmodes_modeZcreatingZreadingZwritingZ	appendingtextZbinarytotal r[   5lib/python3.9/site-packages/pylint/checkers/stdlib.py_check_mode_str/  s0    
r]   c                   @   s<  e Zd ZefZdZddddddifdd	d
dddddddddZdKddZdd Zdd Z	dd Z
dd Zedd d!d"d#d$d%d&d'd(d)d*d+ Zedd,d- Zedd.d/ Zedd0d1 Zedd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZedBdCdDZedEdFdGZedHdIdJZdS )LStdlibCheckerZstdlib)z""%s" is not a valid mode for open.bad-open-modezPython supports: r, w, a[, x] modes with b, +, and U (only with r) options. See https://docs.python.org/2/library/functions.html#openz)Using datetime.time in a boolean context.boolean-datetimezUsing datetime.time in a boolean context can hide subtle bugs when the time they represent matches midnight UTC. This behaviour was fixed in Python 3.5. See https://bugs.python.org/issue13936 for reference.Z
maxversion)r   r   )z*Redundant use of %s with constant value %rredundant-unittest-assertzThe first argument of assertTrue and assertFalse is a condition. If a constant is passed as parameter, that condition will be always true. In this case a warning should be emitted.)zUsing deprecated method %s()deprecated-methodzThe method is marked as deprecated and will be removed in a future version of Python. Consider looking for an alternative in the documentation.)z*threading.Thread needs the target functionbad-thread-instantiationzThe warning is emitted when a threading.Thread class is instantiated without the target function being passed. By default, the first parameter is the group param, not the target param. )z<Using copy.copy(os.environ). Use os.environ.copy() instead. shallow-copy-environzos.environ is not a dict object but proxy object, so shallow copy has still effects on original object. See https://bugs.python.org/issue15373 for reference. )z$%s does not support %s type argumentinvalid-envvar-valuezxEnv manipulation functions support only string type arguments. See https://docs.python.org/3/library/os.html#os.getenv. )z,%s default type is %s. Expected str or None.invalid-envvar-defaultzEnv manipulation functions return None or str values. Supplying anything different as a default may cause bugs. See https://docs.python.org/3/library/os.html#os.getenv. )zGUsing preexec_fn keyword which may be unsafe in the presence of threadssubprocess-popen-preexec-fna+  The preexec_fn parameter is not safe to use in the presence of threads in your application. The child process could deadlock before exec is called. If you must use it, keep it trivial! Minimize the number of libraries you call into.https://docs.python.org/3/library/subprocess.html#popen-constructor)zGUsing subprocess.run without explicitly set `check` is not recommended.subprocess-run-checkzThe check parameter should always be used with explicitly set `check` keyword to make clear what the error-handling behavior is.https://docs.python.org/3/library/subprocess.html#subprocess.run)z+Using deprecated argument %s of method %s()deprecated-argumentzGThe argument is marked as deprecated and will be removed in the future.)z&Using deprecated class %s of module %sdeprecated-classzDThe class is marked as deprecated and will be removed in the future.)zUsing deprecated decorator %s()zdeprecated-decoratorzHThe decorator is marked as deprecated and will be removed in the future.)ZW1501ZW1502ZW1503ZW1505ZW1506ZW1507ZE1507ZW1508ZW1509ZW1510ZW1511ZW1512ZW1513Nc                 C   s  t | | t | _| jtd  ttjd   D ]\}}|tjkr6| j| q6t	 | _
t D ]\}}|tjkrf| j
| qft	 | _t D ]\}}|tjkr| j| qt | _t D ]\}}|tjkr| j| qt | _t D ]\}}|tjkr| j| qd S )Nr   )r   __init__rU   _deprecated_methodsupdateDEPRECATED_METHODSsysversion_infoitemsdict_deprecated_attributesDEPRECATED_ARGUMENTS_deprecated_classesDEPRECATED_CLASSES_deprecated_modulesDEPRECATED_MODULES_deprecated_decoratorsDEPRECATED_DECORATORS)selflinterZ
since_versZ	func_listZ
class_listZmod_listdecorator_listr[   r[   r\   rk     s,    




zStdlibChecker.__init__c                 C   s,   |j s(|js(t|jdkr(| jd|d d S )Nr&   rc   node)kwargskeywordsrV   argsadd_messager{   r   r[   r[   r\   _check_bad_thread_instantiation  s    z-StdlibChecker._check_bad_thread_instantiationc                 C   s.   |j r*|j D ]}|jdkr| jd|d qd S )NZ
preexec_fnrg   r~   )r   argr   )r{   r   keywordr[   r[   r\   _check_for_preexec_fn_in_popen  s    

z,StdlibChecker._check_for_preexec_fn_in_popenc                 C   s.   dd |j pdD }d|vr*| jd|d d S )Nc                 S   s   h | ]
}|j qS r[   )r   .0r   r[   r[   r\   	<setcomp>      z;StdlibChecker._check_for_check_kw_in_run.<locals>.<setcomp>r[   Zcheckrh   r~   )r   r   )r{   r   r   r[   r[   r\   _check_for_check_kw_in_run  s    z(StdlibChecker._check_for_check_kw_in_runc                 C   s>   t j|dd}| D ]"}| tkr| jd|d  q:qd S )Nr   )positionrd   r~   )r   get_argument_from_callinferredqname
OS_ENVIRONr   )r{   r   r   r   r[   r[   r\   _check_shallow_copy_environ  s
    z)StdlibChecker._check_shallow_copy_environr_   ra   rb   ri   rc   rd   re   rf   rg   rh   rj   c                 C   s*  z
|  | |j D ]}|tju r(q| jtkrTt|jddt	v r| 
| n| jtkrp| || nt|tjr| tkr| | q| tkr| | nPt|tjr| }|tkr| | n(|tv r| || n|tkr| | | || qW n tjy$   Y dS 0 dS )zVisit a Call node.nameN)Zcheck_deprecated_class_in_callr!   inferastroidUninferablerootr   OPEN_MODULEgetattr
OPEN_FILES_check_open_modeUNITTEST_CASE_check_redundant_assertrS   ZClassDefr   THREADING_THREADr   SUBPROCESS_POPENr   ZFunctionDef	COPY_COPYr   ENV_GETTERS_check_env_functionSUBPROCESS_RUNr   Zcheck_deprecated_methodInferenceError)r{   r   r   r   r[   r[   r\   
visit_call  s4    


zStdlibChecker.visit_callc                 C   s   |j dkr| |j d S )Nnot)op_check_datetimeoperandr   r[   r[   r\   visit_unaryop  s    
zStdlibChecker.visit_unaryopc                 C   s   |  |j d S Nr   testr   r[   r[   r\   visit_if  s    zStdlibChecker.visit_ifc                 C   s   |  |j d S r   r   r   r[   r[   r\   visit_ifexp  s    zStdlibChecker.visit_ifexpc                 C   s   |j D ]}| | qd S r   )valuesr   )r{   r   valuer[   r[   r\   visit_boolop  s    
zStdlibChecker.visit_boolopc                 C   sP   t |tjrL|jrLt |jd tjrL|jdv rL| jd|j|jd jf|d d S )Nr   )Z
assertTrueZassertFalsera   )r   r   )rS   r   ZBoundMethodr   Constr   r   r   )r{   r   r   r[   r[   r\   r     s    
z%StdlibChecker._check_redundant_assertc                 C   sR   zt | }W n tjy&   Y dS 0 t|tjrN| dkrN| jd|d dS )zZCheck that a datetime was inferred.
        If so, emit boolean-datetime warning.
        Nzdatetime.timer`   r~   )nextr   r   r   rS   ZInstancer   r   )r{   r   r   r[   r[   r\   r   %  s    

zStdlibChecker._check_datetimec                 C   sf   zt j|ddd}W n t jy*   Y dS 0 |rbt |}t|tjrbt|jsb| j	d||jd dS )z>Check that the mode argument of an open or file call is valid.r&   rW   )r   r   Nr_   r   r   )
r   r   ZNoSuchArgumentError
safe_inferrS   r   r   r]   r   r   )r{   r   Zmode_argr[   r[   r\   r   3  s    
zStdlibChecker._check_open_modec                 C   s   d}d}|j r dd |j D }nd }|jr6|jd }n|rL||v rL|| }nd }|rn| j|dt||dd t|jd	kr|jd
 }n|r||v r|| }nd }|r| j||dt|dd d S )Nkeydefaultc                 S   s   i | ]}|j |jqS r[   )r   r   r   r[   r[   r\   
<dictcomp>D  r   z5StdlibChecker._check_env_function.<locals>.<dictcomp>r   re   F)r   messagecall_argr   
allow_noner   r&   rf   T)r   r   r   r   r   )r   r   _check_invalid_envvar_valuer   r   rV   )r{   r   r   Zenv_name_kwargZenv_value_kwargr   Zenv_name_argZenv_value_argr[   r[   r\   r   @  s>    

z!StdlibChecker._check_env_functionc                 C   s   |t jd fv rd S | }t|t jrjd}|jd u r<| }nt|jtsLd}|r| j|||| fd n| j|||| fd d S )NFTr   )	r   r   r   rS   r   r   rT   r   Zpytype)r{   r   r   r   r   r   r   emitr[   r[   r\   r   g  s    
z)StdlibChecker._check_invalid_envvar_valuec                 C   s   | j S )z*Callback returning the deprecated modules.)rw   r{   r[   r[   r\   deprecated_modulesw  s    z StdlibChecker.deprecated_modulesc                 C   s   | j S r   )rl   r   r[   r[   r\   deprecated_methods{  s    z StdlibChecker.deprecated_methods)methodc                 C   s   | j |dS Nr[   )rs   get)r{   r   r[   r[   r\   deprecated_arguments~  s    z"StdlibChecker.deprecated_arguments)modulec                 C   s   | j |dS r   )ru   r   )r{   r   r[   r[   r\   deprecated_classes  s    z StdlibChecker.deprecated_classes)returnc                 C   s   | j S r   )ry   r   r[   r[   r\   deprecated_decorators  s    z#StdlibChecker.deprecated_decorators)N)__name__
__module____qualname__r   Z__implements__r   Zmsgsrk   r   r   r   r   r   Zcheck_messagesr   r   r   r   r   r   r   r   r   r   r   r   rT   r   r   r   r   r[   r[   r[   r\   r^   M  sr   	
]





'r^   c                 C   s   |  t|  dS )z-required method to auto register this checkerN)Zregister_checkerr^   )r|   r[   r[   r\   register  s    r   )__doc__ro   collections.abcr   r   Zpylint.checkersr   r   r   Zpylint.interfacesr   r   r   r   r   r   r   r   r   r   rx   rt   rz   rn   rv   r]   r^   r   r[   r[   r[   r\   <module>%   s   '


 %-  =