o
    g3j                     @   s  U d Z ddlZddlmZ ddlmZmZmZ ddlZddlm	Z	 ddl
mZmZmZ ddlmZ ddlmZ d	Zd
ZdZdZdZdZdZdZdZddh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 i d!d"d#d"d$d"d%d"d&d"d'd"d(d"d)d*d+d,d-d.d/d0d1d2d3d0d4d0d5d0d6d0d7d0d8d9d9d:d:d;d;d<d=d>id?Zd@hh dAdBZh dCh dDh dEdFh dGh dHh dIh dJh dKdLhh dMdNdOhh dPh dQh dRh dSdTdUZ ee!dV< dWhdXdYhh dZd[d\d]hid^Z"d_d` Z#G dadb dbeeZ$dcdd Z%dS )ez0Checkers for various standard library functions.    N)Iterable)AnyDictSet)nodes)BaseCheckerDeprecatedMixinutils)IAstroidChecker)PyLinter)openfile)r   	read_text
write_textzunittest.casezthreading.Threadz	copy.copyzos._Environ)z	os.getenvzsubprocess.Popenzsubprocess.run_iopathlib)zbuiltins.breakpointzsys.breakpointhookzpdb.set_traceztkinter.tixfpectloptparseimp	formatterasynchatasyncoremacpath>   binhexparsersymbollib2to3)r   r   r         r   r      r   r      r   r      r   r      r   r   	   r   ))Nx)intboolfloatzasyncio.tasks.sleep))Nloopz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_shell))r"   r/   zgettext.translation))r$   codesetzgettext.install))r    r0   zfunctools.partialmethod)Nfunczweakref.finalize)r1   )Nobjzprofile.Profile.runcallzcProfile.Profile.runcallzbdb.Bdb.runcallztrace.Trace.runfunczcurses.wrapper))Nfunction))Nfn))Ncallback))Nc)Ntypeid)z!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))   random)r   r      r   r)   zasyncio.coroutine>   abc.abstractpropertyabc.abstractclassmethodabc.abstractstaticmethod)r;   r   r   r   >   cgi.parse_qscgi.parse_qslctypes.c_buffertkinter.Misc.tk_menuBar tkinter.Menu.tk_bindForTraversal,distutils.command.sdist.sdist.check_metadata2distutils.command.register.register.check_metadata>   	os.popen2	os.popen3	os.popen4commands.getstatusmacostools.touched>	   unittest.case.TestCase.assert_#unittest.case.TestCase.assertEquals&unittest.case.TestCase.assertNotEquals)unittest.case.TestCase.assertAlmostEquals,unittest.case.TestCase.assertNotAlmostEquals'xml.etree.ElementTree.XMLParser.doctype)xml.etree.ElementTree.Element.getchildren)xml.etree.ElementTree.Element.getiterator+xml.etree.ElementTree.XMLParser.getiterator))r    r&   r   )r    r(   r   >   inspect.getargspecfailIfassert_
failUnlessfailIfEqualassertEqualsassertNotEqualsfailUnlessEqualfailUnlessRaisesfailIfAlmostEqualassertAlmostEqualsassertRaisesRegexpassertRegexpMatchesassertNotAlmostEqualsfailUnlessAlmostEqualassertNotRegexpMatches>   ntpath.splituncos.path.splituncbase64.decodestringbase64.encodestringos.stat_float_times>   
cgi.escape#configparser.RawConfigParser.readfprR   rS   rT   rU   >   
time.clocklogging.warnplatform.popenlogging.Logger.warninspect.getmoduleinfonntplib._NNTPBase.xpathsqlite3.OptimizedUnicodelogging.LoggerAdapter.warn>   plistlib.readPlistplistlib.writePlistimportlib.find_loaderplistlib.writePlistToBytesplistlib.readPlistFromByteszasyncio.tasks.async>   fractions.gcdplatform.distinspect.getcallargsinspect.formatargspecplatform.linux_distributionz4importlib._bootstrap_external.FileLoader.load_modulez_ssl.RAND_pseudo_bytes>   aifc.openfpwave.openfpsunau.openfplocale.formatssl.wrap_socketssl.match_hostnameasyncio.Task.all_taskasyncio.Task.current_tasksys.get_coroutine_wrappersys.set_coroutine_wrapperthreading.Thread.isAlive>   gettext.lgettextgettext.ldgettextgettext.lngettextgettext.ldngettextgettext.bind_textdomain_codeset'gettext.NullTranslations.output_charset+gettext.NullTranslations.set_output_charsetr   >   binascii.a2b_hqxbinascii.b2a_hqxbinascii.rlecode_hqxbinascii.rledecode_hqx>   cgi.logpathlib.Path.link_tothreading.Event.isSetthreading.activeCountthreading.currentThreadthreading.Thread.getNamethreading.Thread.setNamethreading.Thread.isDaemonthreading.Thread.setDaemon_sqlite3.enable_shared_cachethreading.Condition.notifyAll!zipimport.zipimporter.find_loader!zipimport.zipimporter.find_module!zipimport.zipimporter.load_module))r   r   r   )r   r9   r   r   r@   r!   )r   r"   r"   r#   r%   r'   r;   r)   )r   
   r   )r   r    r   DEPRECATED_METHODSFinderImpImporter	ImpLoader>   r   SizedMappingCallableHashabler   IteratorKeysViewSequence	Awaitable	Container	Coroutine	Generator	ItemsView
ByteString
Collection
MutableSet
Reversible
ValuesViewMappingViewAsyncIterableAsyncIteratorAsyncGeneratorMutableMappingMutableSequence)zimportlib.abcpkgutilcollectionssmtpdMailmanProxy)r@   r)   c           
      C   s   t | tsdS t| }d}d|v }|t| st| t|kr!dS d|v }d|v }d|v }d|v }d|v }d	|v rC|s?|s?|rAdS d
}|rI|rIdS || | | }	|	dkrWdS |sa|sa|sa|sadS d
S )NFzrwatb+Uxr+   rwatbUTr9   )
isinstancestrsetlen)
modemodes_modecreatingreadingwriting	appendingtextbinarytotal r   T/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/checkers/stdlib.py_check_mode_str5  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ddZ	dTdefddZdd Z	dd Z
dd Zd ejd!dfd"d#Zed$d%d&d'd(d)d*d+d,d-d.d/d0d ejd!dfd1d2Zedd ejd!dfd3d4Zedd ejd!dfd5d6Zedd ejd!dfd7d8Zedd ejd!dfd9d:Zd;d< Zd=d> Zd?d@ Zd ejdAed!dfdBdCZdDdE ZdFdG Z dHdI Z!dJdK Z"dLefdMdNZ#dOefdPdQZ$d!e%fdRdSZ&dS )UStdlibChecker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.
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.)z4Using open without explicitly specifying an encodingunspecified-encodingzIt is better to specify an encoding when opening documents. Using the system default implicitly can create problems on other operating systems. See https://www.python.org/dev/peps/pep-0597/)zLLeaving functions creating breakpoints in production code is not recommendedforgotten-debug-statementzCalls to breakpoint(), sys.breakpointhook() and pdb.set_trace() should be removed from code that is not actively being debugged.)W1501W1502W1503W1505W1506W1507E1507W1508W1509W1510W1511W1512W1513W1514W1515Nlinterc                 C   s  t | | t | _| jtd  ttjd   D ]\}}|tjkr*| j| qi | _	t
 D ]\}}|tjkrA| j	| q2i | _t D ]\}}|tjkrX| j| qIt | _t D ]\}}|tjkrp| j| qat | _t D ]\}}|tjkr| j| qyd S )Nr   )r   __init__r   _deprecated_methodsupdater   sysversion_infoitems_deprecated_attributesDEPRECATED_ARGUMENTS_deprecated_classesDEPRECATED_CLASSES_deprecated_modulesDEPRECATED_MODULES_deprecated_decoratorsDEPRECATED_DECORATORS)selfr   
since_vers	func_list
class_listmod_listdecorator_listr   r   r   r     s8   




zStdlibChecker.__init__c                 C   s8   |j s|jst|jdkr| jd|d d S d S d S d S )Nr9   r   node)kwargskeywordsr   argsadd_messager	  r  r   r   r   _check_bad_thread_instantiation  s   z-StdlibChecker._check_bad_thread_instantiationc                 C   s2   |j r|j D ]}|jdkr| jd|d qd S d S )N
preexec_fnr   r  )r  argr  )r	  r  keywordr   r   r   _check_for_preexec_fn_in_popen  s   

z,StdlibChecker._check_for_preexec_fn_in_popenc                 C   s2   dd |j pdD }d|vr| jd|d d S d S )Nc                 S   s   h | ]}|j qS r   )r  .0r  r   r   r   	<setcomp>  s    z;StdlibChecker._check_for_check_kw_in_run.<locals>.<setcomp>r   checkr   r  )r  r  )r	  r  r  r   r   r   _check_for_check_kw_in_run  s   z(StdlibChecker._check_for_check_kw_in_runr  returnc                 C   s`   t j|dd}z| }W n tjy   Y d S w |D ]}| tkr-| jd|d  d S qd S )Nr   )positionr   r  )r	   get_argument_from_callinferredastroidInferenceErrorqname
OS_ENVIRONr  )r	  r  r  inferred_argsr#  r   r   r   _check_shallow_copy_environ  s   z)StdlibChecker._check_shallow_copy_environr   r   r   r   r   r   r   r   r   r   r   r   r   c                 C   sr  |  | t|jD ]}|tju rq| jtv rPt	|jt
jr,|jjtv r,| | t	|jt
jr9|jjtv sFt	|jt
jrO|jjtv rO| || j n`| jtkr^| || nRt	|t
jr|| tkrp| | n@| tkr{| | n4t	|t
jr| }|tkr| | n |tv r| || n|tkr|  | n|t!v r| j"d|d | #|| qdS )zVisit a Call node.r   r  N)$check_deprecated_class_in_callr	   	infer_allr2   r$  UninferablerootnameOPEN_MODULEr   r   NameOPEN_FILES_MODE_check_open_modeOPEN_FILES_ENCODING	Attributeattrname_check_open_encodedUNITTEST_CASE_check_redundant_assertClassDefr&  THREADING_THREADr  SUBPROCESS_POPENr  FunctionDef	COPY_COPYr)  ENV_GETTERS_check_env_functionSUBPROCESS_RUNr  DEBUG_BREAKPOINTSr  check_deprecated_method)r	  r  r#  r.  r   r   r   
visit_call  sJ   



zStdlibChecker.visit_callc                 C   s   |j dkr| |j d S d S )Nnot)op_check_datetimeoperandr  r   r   r   visit_unaryop*  s   
zStdlibChecker.visit_unaryopc                 C      |  |j d S NrF  testr  r   r   r   visit_if/     zStdlibChecker.visit_ifc                 C   rI  rJ  rK  r  r   r   r   visit_ifexp3  rN  zStdlibChecker.visit_ifexpc                 C   s   |j D ]}| | qd S rJ  )valuesrF  )r	  r  valuer   r   r   visit_boolop7  s   
zStdlibChecker.visit_boolopc                 C   s`   t |tjr(|jr*t |jd tjr,|jdv r.| jd|j|jd jf|d d S d S d S d S d S )Nr   )
assertTrueassertFalser   )r  r  )	r   r$  BoundMethodr  r   Constr.  r  rQ  )r	  r  inferr   r   r   r8  <  s   


z%StdlibChecker._check_redundant_assertc                 C   sZ   zt | }W n tjy   Y dS w t|tjr)| dkr+| jd|d dS dS dS )zZCheck that a datetime was inferred.
        If so, emit boolean-datetime warning.
        Nzdatetime.timer   r  )nextrW  r$  r%  r   Instancer&  r  )r	  r  r#  r   r   r   rF  I  s   
zStdlibChecker._check_datetimec                 C   sr   z
t j|ddd}W n t jy   Y dS w |r3t |}t|tjr5t|js7| j	d||jd dS dS dS dS )z>Check that the mode argument of an open or file call is valid.r9   r   r!  r  Nr   r  r  )
r	   r"  NoSuchArgumentError
safe_inferr   r   rV  r   rQ  r  )r	  r  mode_argr   r   r   r2  W  s   
zStdlibChecker._check_open_modeopen_modulec                 C   s   d}z|dkrt j|ddd}n|dkrt j|ddd}W n
 t jy'   Y nw |r/t |}|r6d|jvrod}z
t j|dd	d}W n t jyS   | jd
|d Y nw |rqt |}t|tjrs|jdu ru| jd
|d dS dS dS dS dS )z9Check that the encoded argument of an open call is valid.Nr   r9   r   rZ  r   r   r   encodingr   r  )	r	   r"  r\  r]  rQ  r  r   r   rV  )r	  r  r_  r^  encoding_argr   r   r   r6  d  s@   


	z!StdlibChecker._check_open_encodedc                 C   s   d}d}|j rdd |j D }nd }|jr|jd }n|r&||v r&|| }nd }|r7| j|dt||dd t|jd	krD|jd
 }n|rO||v rO|| }nd }|rb| j||dt|dd d S d S )Nkeydefaultc                 S   s   i | ]}|j |jqS r   )r  rQ  r  r   r   r   
<dictcomp>  s    z5StdlibChecker._check_env_function.<locals>.<dictcomp>r   r   F)r  messagecall_argrW  
allow_noner    r9   r   T)r  rW  re  rf  rg  )r  r  _check_invalid_envvar_valuer	   r]  r   )r	  r  rW  env_name_kwargenv_value_kwargr  env_name_arg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r8d}|jd u r| }nt|jts&d}|r6| j||||	 fd d S d S | j||||	 fd d S )NFTr[  )
r$  r,  r&  r   r   rV  rQ  r   r  pytype)r	  r  rW  re  rf  rg  r.  emitr   r   r   rh    s   
z)StdlibChecker._check_invalid_envvar_valuec                 C      | j S )z*Callback returning the deprecated modules.)r  r	  r   r   r   deprecated_modules  s   z StdlibChecker.deprecated_modulesc                 C   ro  rJ  )r   rp  r   r   r   deprecated_methods     z StdlibChecker.deprecated_methodsmethodc                 C      | j |dS Nr   )r  get)r	  rt  r   r   r   deprecated_arguments     z"StdlibChecker.deprecated_argumentsmodulec                 C   ru  rv  )r  rw  )r	  rz  r   r   r   deprecated_classes  ry  z StdlibChecker.deprecated_classesc                 C   ro  rJ  )r  rp  r   r   r   deprecated_decorators  rs  z#StdlibChecker.deprecated_decoratorsrJ  )'__name__
__module____qualname__r
   __implements__r.  msgsr   r   r  r  r  r   Callr)  r	   check_messagesrC  UnaryOprH  IfrM  IfExprO  BoolOprR  r8  rF  r2  r   r6  r?  rh  rq  rr  rx  r{  r   r|  r   r   r   r   r   S  s    	
k
& 'r   c                 C   s   |  t|  dS )z-required method to auto register this checkerN)register_checkerr   )r   r   r   r   register  s   r  )&__doc__r   collections.abcr   typingr   r   r   r$  r   pylint.checkersr   r   r	   pylint.interfacesr
   pylint.lintr   r1  r3  r7  r:  r=  r'  r>  r;  r@  r/  rA  r  r  r  r   __annotations__r  r   r   r  r   r   r   r   <module>   s   %	
'


 %-  {