o
    b@                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddl	mZ dd	hZd
ZdZdZdZdhZdZejdkrAdZndZdd ZG dd de
Zdd ZdS )z0Checkers for various standard library functions.    N)Instance)Const)IAstroidChecker)BaseChecker)utilsopenfilezunittest.casezthreading.Threadz	copy.copyzos._Environz	os.getenvzsubprocess.Popen)   r   _io__builtin__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+UxxrwatbUT   )
isinstancestrsetlen)
modemodes_modeZcreatingreadingwritingZ	appendingtextbinarytotal r    U/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/checkers/stdlib.py_check_mode_str0   s0   
r"   c                   @   s6  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	Zh dh dh ddh dh dh dh dh ddhh ddhddZdd Zd d! Z	d"d# Z
ed$d%d&d'd(d)d*d+d,d- Zedd.d/ Zedd0d1 Zedd2d3 Zedd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBS )C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 http://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 http://bugs.python.org/issue13936 for reference.Z
maxversion)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)	ZW1501ZW1502ZW1503ZW1505ZW1506ZW1507ZE1507ZW1508ZW1509>   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   )rD      r   >   failIfassert_
failUnlessfailIfEqualassertEqualsassertNotEqualsfailUnlessEqualfailUnlessRaisesfailIfAlmostEqualassertAlmostEqualsassertRaisesRegexpassertRegexpMatchesassertNotAlmostEqualsfailUnlessAlmostEqualassertNotRegexpMatchesinspect.getargspec>   ntpath.splituncbase64.decodestringbase64.encodestring>   
cgi.escape#configparser.RawConfigParser.readfpr@   rA   rB   rC   >   logging.warnplatform.popenlogging.Logger.warninspect.getmoduleinfonntplib._NNTPBase.xpathlogging.LoggerAdapter.warn>   plistlib.readPlistplistlib.writePlistimportlib.find_loaderplistlib.writePlistToBytesplistlib.readPlistFromByteszasyncio.tasks.async>   fractions.gcdplatform.distinspect.getcallargsinspect.getargvaluesinspect.formatargspecinspect.formatargvaluesplatform.linux_distributionz4importlib._bootstrap_external.FileLoader.load_module))r	   r   r   )r	   r   r   )r	   rD   r   )r	   r	   r   )r	      r   )r	   rn   rn   )r	   r'   r   )r	   rE   r   )r   rD   r	   c                 C   s8   |j s|jst|jdkr| jd|d d S d S d S d S )Nr   r*   node)kwargskeywordsr   argsadd_messageselfrp   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.   ro   )rr   argrt   )rv   rp   keywordr    r    r!   _check_for_preexec_fn_in_Popen   s   

z,StdlibChecker._check_for_preexec_fn_in_Popenc                 C   s@   t j|dd}| D ]}| tkr| jd|d  d S qd S )Nr   )positionr+   ro   )r   get_argument_from_callinferredqname
OS_ENVIRONrt   )rv   rp   ry   r~   r    r    r!   _check_shallow_copy_environ   s   z)StdlibChecker._check_shallow_copy_environr%   r(   r)   r*   r+   r,   r-   r.   c                 C   s  zw|j  D ]n}|tju rq| jtkr$t|j ddtv r#| 	| nJ| jt
kr2| || n<t|tjrP| tkrD| | n*| tkrO| | nt|tjrn| }|tkrd| | n
|tv rn| || | || qW dS  tjy   Y dS w )zVisit a Call node.nameN)funcinferastroidUninferablerootr   OPEN_MODULEgetattr
OPEN_FILES_check_open_modeUNITTEST_CASE_check_redundant_assertr   ClassDefr   THREADING_THREADrw   SUBPROCESS_POPENr{   FunctionDef	COPY_COPYr   ENV_GETTERS_check_env_function_check_deprecated_methodInferenceError)rv   rp   r~   r   r    r    r!   
visit_call  s6   


zStdlibChecker.visit_callc                 C   s   |j dkr| |j d S d S )Nnot)op_check_datetimeoperandru   r    r    r!   visit_unaryop)  s   
zStdlibChecker.visit_unaryopc                 C      |  |j d S Nr   testru   r    r    r!   visit_if.     zStdlibChecker.visit_ifc                 C   r   r   r   ru   r    r    r!   visit_ifexp2  r   zStdlibChecker.visit_ifexpc                 C   s   |j D ]}| | qd S r   )valuesr   )rv   rp   valuer    r    r!   visit_boolop6  s   
zStdlibChecker.visit_boolopc                    s   t jd }t|jtjr|jj}nt|jtjr|jj}nd S tj	tj
tjf}t||s.d S | }tfdd||fD rJjd||fd d S j|  D ]"\} |t jkrst fdd||fD rsjd||fd  d S qQd S )Nr   c                 3   s    | ]
}| j d  v V  qdS )r   N)
deprecated.0r   )rv   r    r!   	<genexpr>P  s    z9StdlibChecker._check_deprecated_method.<locals>.<genexpr>r)   rp   rs   c                 3   s    | ]}| v V  qd S r   r    r   )	func_listr    r!   r   T  s    
)sysversion_infor   r   r   	AttributeattrnameNamer   BoundMethodZUnboundMethodr   r   anyrt   r   items)rv   rp   r~   Zpy_vers	func_nameZacceptable_nodesr   Z
since_versr    )r   rv   r!   r   ;  s.   



z&StdlibChecker._check_deprecated_methodc                 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   )
assertTrueZassertFalser(   )rs   rp   )r   r   r   rs   r   r   rt   r   )rv   rp   r   r    r    r!   r   Z  s   

z%StdlibChecker._check_redundant_assertc                 C   sX   zt | }W n tjy   Y dS w t|tr(| dkr*| jd|d dS dS dS )zZ Check that a datetime was infered.
        If so, emit boolean-datetime warning.
        Nzdatetime.timer&   ro   )nextr   r   r   r   r   r   rt   )rv   rp   Zinferedr    r    r!   r   g  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.r   r   )r|   rz   Nr%   r   )
r   r}   ZNoSuchArgumentError
safe_inferr   r   r   r"   r   rt   )rv   rp   Zmode_argr    r    r!   r   r  s   
zStdlibChecker._check_open_modec                 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    )ry   r   )r   rz   r    r    r!   
<dictcomp>  s    z5StdlibChecker._check_env_function.<locals>.<dictcomp>r   r,   F)rp   messagecall_argr   
allow_nonerD   r   r-   T)rp   r   r   r   r   )rr   rs   _check_invalid_envvar_valuer   r   r   )rv   rp   r   Zenv_name_kwargZenv_value_kwargrq   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r7d}|jd u r| }nt|jts%d}|r5| j|||| fd d S d S | j|||| fd d S )NFTr   )	r   r   r   r   r   r   r   rt   Zpytype)rv   rp   r   r   r   r   r   emitr    r    r!   r     s   

z)StdlibChecker._check_invalid_envvar_valueN)__name__
__module____qualname__r   Z__implements__r   Zmsgsr   rw   r{   r   r   Zcheck_messagesr   r   r   r   r   r   r   r   r   r   r   r    r    r    r!   r#   N   sv    	H
	[





'r#   c                 C   s   |  t|  dS )z.required method to auto register this checker N)Zregister_checkerr#   )Zlinterr    r    r!   register  s   r   )__doc__r   r   Zastroid.basesr   Zastroid.node_classesr   Zpylint.interfacesr   Zpylint.checkersr   r   r   r   r   r   r   r   r   r   r   r"   r#   r   r    r    r    r!   <module>   s.   
  k