
'![c           @   s   d  Z  d d l 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 h Z d	 Z d
 Z d Z d Z e j d k r d Z n d Z d   Z d e	 f d     YZ d   Z d S(   s0   Checkers for various standard library functions.iN(   t   Instance(   t   IAstroidChecker(   t   BaseChecker(   t   utilst   opent   files   unittest.cases   threading.Threads	   copy.copys   os._Environi   i    t   _iot   __builtin__c   
      C   s  t  |  t j  s t St |   } d } t } t j rP | d 7} d | k } n  | t |  sx t |   t |  k r| t Sd | k } d | k } d | k } d | k } d | k } d | k r | s | s | r t j r t St } t j s t } q n  | r| rt S| | | t j r(| n d	 }	 |	 d
 k r?t S| p]| p]| p]| o]t j sdt St j sd |  k r|  j d d  }  d |  k rd |  }  qn  |  d	 d k St S(   Ns   rwatb+Ut   xt   rt   wt   at   tt   bt   Ui    i   t    (   R	   R
   R   R   (	   t
   isinstancet   sixt   string_typest   Falset   sett   PY3t   lent   Truet   replace(
   t   modet   modest   _modet   creatingt   readingt   writingt	   appendingt   textt   binaryt   total(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   _check_mode_str+   sF    	
(	!!	t   StdlibCheckerc           B   s  e  Z e f Z d  Z i d] d 6d d d i d^ d
 6f d 6d_ d 6d` d 6da d 6db d 6Z i d d d d d  d! d" g d# 6i d$ d% d& d' d( g dc 6d+ d, d- d. d/ d0 d1 d2 d3 g	 dd 6d) 6i d5 d6 g de 6d7 d8 d9 g df 6d; d< d0 d1 d2 d3 g dg 6d= d> d? d@ dA dB g dh 6dC dD dE dF dG g di 6dI g dj 6dJ dK dL dM dN dO dP g dk 6dQ g dl 6d 6Z dR   Z dS   Z e	 j
 d d d d d  dT    Z e	 j
 d  dU    Z e	 j
 d  dV    Z e	 j
 d  dW    Z e	 j
 d  dX    Z dY   Z dZ   Z d[   Z d\   Z RS(m   t   stdlibs"   "%s" is not a valid mode for open.s   bad-open-modes   Python supports: r, w, a[, x] modes with b, +, and U (only with r) options. See http://docs.python.org/2/library/functions.html#opent   W1501s)   Using datetime.time in a boolean context.s   boolean-datetimes   Using 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.i   i   t
   maxversiont   W1502s*   Redundant use of %s with constant value %rs   redundant-unittest-asserts   The 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.t   W1503s   Using deprecated method %s()s   deprecated-methods   The method is marked as deprecated and will be removed in a future version of Python. Consider looking for an alternative in the documentation.t   W1505s*   threading.Thread needs the target functions   bad-thread-instantiations   The 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. t   W1506s<   Using copy.copy(os.environ). Use os.environ.copy() instead. s   shallow-copy-environs   os.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. t   W1507s   cgi.parse_qss   cgi.parse_qsls   ctypes.c_buffers2   distutils.command.register.register.check_metadatas,   distutils.command.sdist.sdist.check_metadatas   tkinter.Misc.tk_menuBars    tkinter.Menu.tk_bindForTraversali    s   commands.getstatuss	   os.popen2s	   os.popen3s	   os.popen4s   macostools.touchedi   i   s#   unittest.case.TestCase.assertEqualss&   unittest.case.TestCase.assertNotEqualss)   unittest.case.TestCase.assertAlmostEqualss,   unittest.case.TestCase.assertNotAlmostEqualss   unittest.case.TestCase.assert_s)   xml.etree.ElementTree.Element.getchildrens)   xml.etree.ElementTree.Element.getiterators+   xml.etree.ElementTree.XMLParser.getiterators'   xml.etree.ElementTree.XMLParser.doctypei   s   inspect.getargspecs1   unittest.case.TestCase._deprecate.deprecated_funcs   base64.encodestrings   base64.decodestrings   ntpath.splitunci   s
   cgi.escapes#   configparser.RawConfigParser.readfps   inspect.getmoduleinfos   logging.warns   logging.Logger.warns   logging.LoggerAdapter.warns   nntplib._NNTPBase.xpaths   platform.popens   importlib.find_loaders   plistlib.readPlists   plistlib.writePlists   plistlib.readPlistFromBytess   plistlib.writePlistToBytesi   s   asyncio.tasks.asyncs   fractions.gcds   inspect.getargvaluess   inspect.formatargspecs   inspect.formatargvaluess   inspect.getcallargss   platform.linux_distributions   platform.dists4   importlib._bootstrap_external.FileLoader.load_modulec         C   s-   | j  r) | j r) |  j d d | n  d  S(   Ns   bad-thread-instantiationt   node(   t   kwargst   argst   add_message(   t   selfR-   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   _check_bad_thread_instantiation   s    c         C   sY   t  j | d d } x= | j   D]/ } | j   t k r" |  j d d | Pq" q" Wd  S(   Nt   positioni    s   shallow-copy-environR-   (   R   t   get_argument_from_callt   inferredt   qnamet
   OS_ENVIRONR0   (   R1   R-   t   argR5   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   _check_shallow_copy_environ   s
    c         C   s2  yx| j  j   D] } | t j k r. q n  | j   j t k rq t | j  d d  t	 k rq |  j
 |  qq n  | j   j t k r |  j | |  n  t | t j  r | j   t k r |  j |  n  t | t j  r| j   t k r|  j |  n  |  j | |  q WWn t j k
 r-d SXd S(   s   Visit a Call node.t   nameN(   t   funct   infert   astroidt   Uninferablet   rootR:   t   OPEN_MODULEt   getattrt   Nonet
   OPEN_FILESt   _check_open_modet   UNITTEST_CASEt   _check_redundant_assertR   t   ClassDefR6   t   THREADING_THREADR2   t   FunctionDeft	   COPY_COPYR9   t   _check_deprecated_methodt   InferenceError(   R1   R-   R5   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt
   visit_call   s     $$c         C   s&   | j  d k r" |  j | j  n  d  S(   Nt   not(   t   opt   _check_datetimet   operand(   R1   R-   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   visit_unaryop   s    c         C   s   |  j  | j  d  S(   N(   RP   t   test(   R1   R-   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   visit_if   s    c         C   s   |  j  | j  d  S(   N(   RP   RS   (   R1   R-   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   visit_ifexp   s    c         C   s%   x | j  D] } |  j |  q
 Wd  S(   N(   t   valuesRP   (   R1   R-   t   value(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   visit_boolop   s    c   	      C   s%  t  j d } t | j t j  r1 | j j } n( t | j t j  rU | j j } n d  St j	 t j
 t j f } t | |  s d  S| j   } | |  j d k r |  j d d | d | f n_ x\ |  j | j   D]G \ } } | t  j k r | | k r |  j d d | d | f Pq q Wd  S(   Ni    s   deprecated-methodR-   R/   (   t   syst   version_infoR   R;   R=   t	   Attributet   attrnamet   NameR:   t   BoundMethodt   UnboundMethodRI   R6   t
   deprecatedR0   t   items(	   R1   R-   R5   t   py_verst	   func_namet   acceptable_nodesR6   t
   since_verst	   func_list(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyRK      s(     
c         C   sv   t  | t j  rr | j rr t  | j d t j  rr | j d k rr |  j d d | j | j d j f d | n  d  S(   Ni    t
   assertTruet   assertFalses   redundant-unittest-assertR/   R-   (   Rg   Rh   (   R   R=   R^   R/   t   ConstR:   R0   RW   (   R1   R-   R<   (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyRF     s    "c         C   si   y t  | j    } Wn t j k
 r- d SXt | t  re | j   d k re |  j d d | n  d S(   sZ    Check that a datetime was infered.
        If so, emit boolean-datetime warning.
        Ns   datetime.times   boolean-datetimeR-   (   t   nextR<   R=   RL   R   R    R6   R0   (   R1   R-   t   infered(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyRP   #  s    c         C   s   y t  j | d d d d } Wn t  j k
 r6 d SX| r t  j |  } t | t j  r t | j  r |  j	 d d | d | j q n  d S(	   s>   Check that the mode argument of an open or file call is valid.R3   i   t   keywordR   Ns   bad-open-modeR-   R/   (
   R   R4   t   NoSuchArgumentErrort
   safe_inferR   R=   Ri   R#   RW   R0   (   R1   R-   t   mode_arg(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyRD   /  s    (   s"   "%s" is not a valid mode for open.s   bad-open-modes   Python supports: r, w, a[, x] modes with b, +, and U (only with r) options. See http://docs.python.org/2/library/functions.html#open(   i   i   (   s*   Redundant use of %s with constant value %rs   redundant-unittest-asserts   The 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.(   s   Using deprecated method %s()s   deprecated-methods   The method is marked as deprecated and will be removed in a future version of Python. Consider looking for an alternative in the documentation.(   s*   threading.Thread needs the target functions   bad-thread-instantiations   The 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. (   s<   Using copy.copy(os.environ). Use os.environ.copy() instead. s   shallow-copy-environs   os.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. (   i   i   i    (   i   i   i    (   i   i    i    (   i   i   i    (   i   i   i    (   i   i   i    (   i   i   i    (   i   i   i   (   i   i   i    (   i   i   i    (   t   __name__t
   __module__R   t   __implements__R:   t   msgsR`   R2   R9   R   t   check_messagesRM   RR   RT   RU   RX   RK   RF   RP   RD   (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyR$   U   s   	          








					c         C   s   |  j  t |    d S(   s.   required method to auto register this checker N(   t   register_checkerR$   (   t   linter(    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   register>  s    (   i   i    (   t   __doc__RY   R   R=   t   astroid.basesR    t   pylint.interfacesR   t   pylint.checkersR   R   RC   RE   RH   RJ   R7   RZ   R@   R#   R$   Rw   (    (    (    s5   lib/python2.7/site-packages/pylint/checkers/stdlib.pyt   <module>   s$   		*