
'![c        =   @   s  d  Z  d d l Z d d l Z y d d l m Z Wn! e k
 rU d d l m Z n Xy d d l m Z Wn! e k
 r d d l m Z n Xd d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z m Z d d l Z d d l m Z d d l m Z e j Z e j e j e j e j f Z e	 j d d	 k Z e sad
 Z n d Z e d  Z d Z  e j! rd n d Z" d Z# d Z$ d Z% d Z& d Z' i d d 6d d 6d ds 6d dx 6d d	 6d d 6Z) d|   e) j*   D Z+ e e+  Z, d} e- f d~     YZ. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 e j5 j6   Z d Z7 d   Z8 d   Z9 d   Z: d   Z; d   Z< d   Z= d   Z> d   Z? d   Z@ d e- f d     YZA d e- f d     YZB d   ZC d   ZD d   ZE d   ZF d d d  ZG d   ZH d   ZI d   ZJ d   ZK d   ZL e d d  d d   ZM d   ZN d   ZO d   ZP d   ZQ d   ZR d   ZS d   ZT d   ZU d   ZV d   ZW d   ZX d   ZY d   ZZ d   Z[ d   Z\ d   Z] d   Z^ d   Z_ d   Z` d   Za d   Zb d   Zc d   Zd d   Ze e d d  d d   Zf d d  Zg d   Zh d   Zi d   Zj d   Zk d   Zl d   Zm d S(   s7   some functions that may be useful for various checkers
iN(   t   singledispatch(   t	   lru_cache(   t   mapt   builtins(   t   bases(   t   scoped_nodesi    i   t
   exceptionsR   s   abc.abstractpropertys   abc.abstractmethods   abc.abstractclassmethods   abc.abstractstaticmethodt   __iter__t   nextt   __next__t   __getitem__t   __setitem__t   __delitem__t   __contains__t   keyst   __new__t   __init__t   __call__t   __del__t   __repr__t   __str__t	   __bytes__t   __hash__t   __bool__t   __dir__t   __len__t   __length_hint__t   __reversed__t   __neg__t   __pos__t   __abs__t
   __invert__t   __complex__t   __int__t	   __float__t	   __index__t	   __enter__t
   __aenter__t   __getnewargs_ex__t   __getnewargs__t   __getstate__t
   __reduce__t   __copy__t   __unicode__t   __nonzero__t	   __await__t	   __aiter__t	   __anext__t
   __fspath__t
   __format__t   __lt__t   __le__t   __eq__t   __ne__t   __gt__t   __ge__t   __getattr__t   __getattribute__t   __delattr__t
   __delete__t   __instancecheck__t   __subclasscheck__t   __missing__t   __add__t   __sub__t   __mul__t   __truediv__t   __floordiv__t   __mod__t
   __divmod__t
   __lshift__t
   __rshift__t   __and__t   __xor__t   __or__t   __radd__t   __rsub__t   __rmul__t   __rtruediv__t   __rmod__t   __rdivmod__t   __rpow__t   __rlshift__t   __rrshift__t   __rand__t   __rxor__t   __ror__t   __iadd__t   __isub__t   __imul__t   __itruediv__t   __ifloordiv__t   __imod__t   __ilshift__t   __irshift__t   __iand__t   __ixor__t   __ior__t   __ipow__t   __setstate__t   __reduce_ex__t   __deepcopy__t   __cmp__t
   __matmul__t   __rmatmul__t   __div__i   t   __setattr__t   __get__t   __set__t   __set_name__i   t   __exit__t	   __aexit__t	   __round__c         C   s,   i  |  ]" \ } } | D] } | |  q q S(    (    (   t   .0t   paramst   methodst   name(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys
   <dictcomp>v   s   		t   NoSuchArgumentErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyRu   }   s   c         C   sH   |  } x) | r1 t  | j t j  r1 | j } q	 W| oG | | j j k S(   s=   Returns true if node is inside the name of an except handler.(   t
   isinstancet   parentt   astroidt   ExceptHandlerRt   (   t   nodet   current(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_inside_except   s    c         c   sW   t  |  t j t j f  rN x5 |  j D]" } x t |  D] } | Vq8 Wq% Wn |  Vd S(   s9   Recursively returns all atoms in nested lists and tuples.N(   Rx   Rz   t   Tuplet   Listt   eltst   get_all_elements(   R|   t   childt   e(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR      s
    c         C   s   t  |  t j  r5 t |  j d |  j j   f f f St  |  t j  r |  j } t	 |  rl t | d f f S|  j
 |  d } | r t  | d j   t j t j t j f  r t | d | d j f f Sn  t d f S(   s   Checks if an assignment node in an except handler clobbers an existing
    variable.

    Returns (True, args for W0623) if assignment clobbers an existing variable,
    (False, None) otherwise.
    s	   object %rR   i   i    s   outer scope (line %s)N(   Rx   Rz   t
   AssignAttrt   Truet   attrnamet   exprt	   as_stringt
   AssignNameRt   t
   is_builtint   lookupt   assign_typet   Assignt	   AugAssignR{   t
   fromlinenot   Falset   None(   R|   Rt   t   stmts(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   clobber_in_except   s    #	c         C   s5   t  |  d d  d k r1 |  j   j t k r1 t St S(   sH   return True if the node is referencing the "super" builtin function
    Rt   t   superN(   t   getattrR   t   rootRt   t   BUILTINS_NAMER   R   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_super   s    c         C   s2   x+ |  j    D] } t | t j  r) t St SWd S(   sA   return true if the function does nothing but raising an exceptionN(   t   get_childrenRx   Rz   t   RaiseR   R   (   R|   t
   child_node(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_error   s    c         C   s+   x$ |  D] } t  | t j  r t Sq Wt S(   s:   return true if the given statement node raise an exception(   Rx   Rz   R   R   R   (   t   bodyR|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt
   is_raising   s    t   __builtins__c         C   s   |  o |  j    j t k S(   sH   Returns True if the given node is an object from the __builtin__ module.(   R   Rt   R   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_builtin_object   s    c         C   s   |  t  k p |  t k S(   sM   return true if <name> could be considered as a builtin defined by python
    (   R   t   SPECIAL_BUILTINS(   Rt   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR      s    c   
      C   s  |  j  } |  j } x| rt | t  r] x| j t j  D] } | j  | k r= t Sq= Wnt | t j  r x| j	 j t j  D] } | j  | k r t Sq WnSt | t j
  rx>| j D]J \ } } | j |   r Pn  | r t | t j  r | j  | k r t Sq Wn t | t j t j f  r| j j |  r| j j |   ry  | j j |  | j } w Wqt j k
 rqXn  t St | d d  | k rt SPnI t | t j  rt | j  t j  r| j  } | j  | k rt Sqn  | j } q W|  j   } | j   } | j } x | r| j | k rx- | j t j  D] } | j  | k rQt SqQWxW | j t j t j f  D]: } | g  | j D] }	 |	 d p|	 d ^ qk rt SqW| j   } q)Wt S(   s   return True if the variable node is defined by a parent node (list,
    set, dict, or generator comprehension, lambda) or in a previous sibling
    node on the same line (statement_defining ; statement_using)
    Rt   i   i    N(   Rt   Ry   Rx   t   COMP_NODE_TYPESt   nodes_of_classRz   R   R   t   Fort   targett   Witht   itemst	   parent_oft   Lambdat   FunctionDeft   argst   is_argumentt   default_valuet	   NoDefaultR   R   R{   t	   statementt   previous_siblingR   t
   ImportFromt   Importt   namesR   (
   t   var_nodet   varnamet   _nodet   ass_nodeR   t   idst   stmtt   linenot   imp_nodeRt   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_defined_before   sd    					
	"0c         C   si   |  j    } t | t j  re xD | j j D]3 } x* | j t j  D] } | |  k rD t SqD Wq+ Wn  t	 S(   sX   return true if the given Name node is used in function default argument's
    value
    (
   t   scopeRx   Rz   R   R   t   defaultsR   t   NameR   R   (   R|   Ry   t   default_nodet   default_name_node(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_func_default  s    c         C   sm   |  j  } x] | d k	 rh t | t j  r. t S| j sX t | t j t j	 t j
 f  r\ Pn  | j  } q Wt S(   s5   return true if the name is used in function decoratorN(   Ry   R   Rx   Rz   t
   DecoratorsR   t   is_statementR   R   t   ComprehensionScopet   ListCompR   (   R|   Ry   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_func_decorator  s    		c         C   sS   y |  j  } Wn t k
 r! t SXx* | D]" } | | j t j  k r) t Sq) Wt S(   si   return True if `frame` is a astroid.Class node with `node` in the
    subtree of its bases attribute
    (   R   t   AttributeErrorR   R   Rz   R   R   (   t   frameR|   R   t   base(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_ancestor_name!  s    c         C   s;   x4 |  r6 t  |  t j t j t j f  r6 |  j }  q W|  S(   sL   return the higher parent which is not an AssignName, Tuple or List node
    (   Rx   Rz   R   R   R   Ry   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   assign_parent.  s
    c         C   sA   x: |  j    D], } | | k r t | | t j  r t Sq Wt S(   s=   return True if <name> is a method overridden from an ancestor(   t	   ancestorsRx   Rz   R   R   R   (   t
   class_nodeRt   t   ancestor(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   overrides_a_method8  s    "c             s     f d   } | S(   s@   decorator to store messages that are handled by a checker methodc            s     |  _  |  S(   N(   t   checks_msgs(   t   func(   t   messages(    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   store_messagesB  s    	(    (   R   R   (    (   R   s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   check_messages?  s    t   IncompleteFormatStringc           B   s   e  Z d  Z RS(   s:   A format string ended in the middle of a format specifier.(   Rv   Rw   t   __doc__(    (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR   G  s   t   UnsupportedFormatCharacterc           B   s   e  Z d  Z d   Z RS(   sX   A format character in a format string is not one of the supported
    format characters.c         C   s   t  j |  |  | |  _ d  S(   N(   t	   ExceptionR   t   index(   t   selfR   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR   N  s    (   Rv   Rw   R   R   (    (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR   K  s   c            s  t    } d }   f d   } d } xX| t    k  r~  | } | d k rq| |  \ } } d } | d k rd } | |  \ } } | } xT | d k r | d k r | d 7} n | d k r | d 8} n  | |  \ } } q W| d }	   | |	 !} n  x" | d k r&| |  \ } } qW| d k rR| d 7} | |  \ } } n( x% | t j k ry| |  \ } } qUW| d	 k r| |  \ } } | d k r| d 7} | |  \ } } qx( | t j k r| |  \ } } qWn  | d
 k r| |  \ } } n  t rd }
 n d }
 | |
 k r?t |   n  | rU| j |  qq| d k rq| d 7} qqn  | d 7} q' W| | f S(   s'  Parses a format string, returning a tuple of (keys, num_args), where keys
    is the set of mapping keys in the format string, and num_args is the number
    of arguments required by the format string.  Raises
    IncompleteFormatString or UnsupportedFormatCharacter if a
    parse error occurs.i    c            s3   |  d 7}  |  t     k r% t  n  |    |  f S(   Ni   (   t   lenR   (   t   i(   t   format_string(    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt	   next_charZ  s    
	t   %t   (i   t   )s   #0- +t   *t   .t   hlLs   diouxXeEfFgGcrs%as   diouxXeEfFgGcrs%N(   t   setR   R   t   stringt   digitst   PY3KR   t   add(   R   R   t   num_argsR   R   t   chart   keyt   deptht	   key_startt   key_endt   flags(    (   R   s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   parse_format_stringR  s`    	



	c         C   s9   |  d d k o8 |  d k o8 |  j  d  o7 |  j d  S(   sk   return True if attribute name is protected (start with _ and some other
    details), False otherwise.
    i    t   _t   __(   t
   startswitht   endswith(   R   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_attr_protected  s    c         C   s]   |  j    } xJ | d k	 rX t | t j  rX | j d k rF d } q | j j    } q W| S(   sh   return klass node for a method node (or a staticmethod or a
    classmethod), return null otherwise
    N(   R   R   Rx   Rz   t   ClassDefRy   (   R|   t   klass(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   node_frame_class  s    "	c         C   s   t  j d  } | j |   S(   sq   Check that attribute name is private (at least two leading underscores,
    at most one trailing underscore)
    s   ^_{2,}.*[^_]+_?$(   t   ret   compilet   match(   R   t   regex(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_attr_private  s    c         C   s   | d k r' | d k r' t d   n  | d k	 rY y |  j | SWqY t k
 rU qY Xn  | r |  j r x* |  j D] } | j | k rr | j Sqr Wn  t  d S(   s
  Returns the specified argument from a function call.

    :param astroid.Call call_node: Node representing a function call to check.
    :param int position: position of the argument.
    :param str keyword: the keyword of the argument.

    :returns: The node representing the argument, None if the argument is not found.
    :rtype: astroid.Name
    :raises ValueError: if both position and keyword are None.
    :raises NoSuchArgumentError: if no argument at the provided position or with
    the provided keyword.
    s2   Must specify at least one of: position or keyword.N(   R   t
   ValueErrorR   t
   IndexErrort   keywordst   argt   valueRu   (   t	   call_nodet   positiont   keywordR  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   get_argument_from_call  s    c         C   s[   |  j  d k r( |  j   j  t k r( t St |  d  s; t St d   |  j d t  D  S(   sV   
    Return true if the given class node is subclass of
    exceptions.Exception.
    R   t   BaseExceptionR   c         s   s   |  ] } t  |  Vq d  S(   N(   t   inherit_from_std_ex(   Rq   Ry   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <genexpr>  s   t   recurs(   R   R
  (   Rt   R   t   EXCEPTIONS_MODULER   t   hasattrR   t   anyR   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR    s    	c            sT   d     t  | t  s$ | f } n    f d   | D } |  j sG t S|  j |  S(   sr  
    Check if the given exception handler catches
    the given error_type.

    The *handler* parameter is a node, representing an ExceptHandler node.
    The *error_type* can be an exception, such as AttributeError,
    the name of an exception, or it can be a tuple of errors.
    The function will return True if the handler catches any of the
    given errors.
    c         S   s   t  |  t j  s |  j S|  S(   N(   Rx   t   sixt   string_typesRv   (   t   error(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   stringify_error  s    c            s   h  |  ] }   |   q S(    (    (   Rq   R  (   R  (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <setcomp>  s   	 (   Rx   t   tuplet   typeR   t   catch(   t   handlert
   error_typet   expected_errors(    (   R  s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   error_of_type  s    		c         C   sk   |  j  s t SxW |  j  j D]I } t | t j  s8 q n  y t |  rK t SWq t j k
 rb q Xq Wt S(   sA    Detect if the given function node is decorated with a property. (	   t
   decoratorsR   t   nodesRx   Rz   R   t   _is_property_decoratorR   t   InferenceError(   R|   t	   decorator(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   decorated_with_property  s    	c         C   s   x |  j    D] } t | t j  r | j   j t k rM | j d k rM t Sx? | j   D]. } | j d k rZ | j   j t k rZ t SqZ Wq q Wd  S(   Nt   property(
   t   inferRx   Rz   R   R   Rt   R   R   R   R   (   R  t   inferedR   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR    s    $$c            st   |  j  r |  j  j n g  } xR | D]J } y* t   f d   | j   D  rQ t SWq" t j k
 rk q" q" Xq" Wt S(   sM   Determine if the `func` node has a decorator with the qualified name `qname`.c         3   s-   |  ]# } | d  k	 o$ | j     k Vq d  S(   N(   R   t   qname(   Rq   R   (   t   qnames(    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <genexpr>  s    (   R  R  R  R"  R   Rz   R  R   (   R   R%  R  t   decorator_node(    (   R%  s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   decorated_with  s    "t   maxsizei   c         C   so  | d k r$ t j t d t } n  i  } y t |  j    } Wn& t k
 rT i  St j	 k
 rh i  SXx | D] } x | j
   D] } | } t | t j  r	t |  } | s | j | k r | | j =q q n  t | t j  s	| j | k r| | j =qq	n  t | t j  r | |  } | r=| | | j <qc| rc| j | k rc| | j =qcq q Wqp W| S(   s  
    Get the unimplemented abstract methods for the given *node*.

    A method can be considered abstract if the callback *is_abstract_cb*
    returns a ``True`` value. The check defaults to verifying that
    a method is decorated with abstract methods.
    The function will work only for new-style classes. For old-style
    classes, it will simply return an empty dictionary.
    For the rest of them, it will return a dictionary of abstract method
    names and their inferred objects.
    R%  N(   R   t	   functoolst   partialR'  t   ABC_METHODSt   reversedt   mrot   NotImplementedErrorRz   t   ResolveErrort   valuesRx   R   t
   safe_inferRt   R   (   R|   t   is_abstract_cbt   visitedR-  R   t   objR#  t   abstract(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   unimplemented_abstract_methods  s:    	c         C   sd   |  } t  j t  j f } x& | r@ t | j |  r@ | j } q W| r` t | j |  r` | j Sd S(   sD   Return the ExceptHandler or the TryExcept node in which the node is.N(   Rz   R{   t	   TryExceptRx   Ry   R   (   R|   R}   t   ignores(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _import_node_contextX  s    c         C   s   t  |   } | s t St | t j  rC | j j } | j j } n( t j	 j
 d   | j D  } | j } t d   | D  } t | t  } | p | S(   s8   Check if the given node is from a fallback import block.c         s   s   |  ] } | j  Vq d  S(   N(   R   (   Rq   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <genexpr>o  s    c         s   s*   |  ]  } t  | t j t j f  Vq d  S(   N(   Rx   Rz   R   R   (   Rq   t   import_node(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <genexpr>r  s   (   R9  R   Rx   Rz   R{   Ry   R   t   handlerst	   itertoolst   chaint   from_iterableR  t"   _except_handlers_ignores_exceptiont   ImportError(   R|   t   contextt
   other_bodyR;  t   has_fallback_importst   ignores_import_error(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_from_fallback_blockd  s    			c         C   s+   t  j t d | f } t t | |    S(   NR  (   R)  R*  R  R  R   (   R;  t	   exceptionR   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR?  x  s    c            s9   t  |   } t | t j  r5   f d   | j D Sd S(   sM  Return the collections of handlers handling the exception in arguments.

    Args:
        node (astroid.Raise): the node raising the exception.
        exception (builtin.Exception or str): exception or name of the exception.

    Returns:
        generator: the collection of handlers that are handling the exception or None.

    c         3   s$   |  ] } t  |    r | Vq d  S(   N(   R  (   Rq   t   _handler(   RF  (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pys	   <genexpr>  s    N(   R9  Rx   Rz   R7  R;  R   (   R|   RF  RA  (    (   RF  s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   get_exception_handlers}  s    c         C   s   t  |   } t | t j  S(   s  Check if the node is directly under a Try/Except statement.
    (but not under an ExceptHandler!)

    Args:
        node (astroid.Raise): the node raising the exception.

    Returns:
        bool: True if the node is inside a try/except statement, False otherwise.
    (   R9  Rx   Rz   R7  (   R|   RA  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_node_inside_try_except  s    
c         C   s#   t  |  |  } | s t St |  S(   sF   Check if the node is in a TryExcept which handles the given exception.(   RH  R   R  (   R|   RF  t   managing_handlers(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   node_ignores_exception  s    c         C   sI   xB |  j    D]4 } | j j   |  k r | j d t  rA t Sq q Wt S(   sV   return true if the given class node should be considered as an abstract
    class
    t   pass_is_abstract(   Rs   Ry   R   t   is_abstractR   R   (   R|   t   method(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   class_is_abstract  s
    c         C   sj   y |  j  |  } Wn t j k
 r* t SX| d } t | t j  rf t | j j t j  rf t Sn  t	 S(   Ni    (
   R   Rz   t   NotFoundErrorR   Rx   R   Ry   R  t   ConstR   (   R  t   attrt
   attributest   first(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_protocol_method  s    
c         C   s+   t  j t  j t  j t  j f } t |  |  S(   N(   Rz   R   t   SetCompt   DictCompt   GeneratorExpRx   (   R|   t   comprehensions(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_comprehension  s
    c         C   s   t  |  t  o t  |  t  S(   N(   RU  t   GETITEM_METHODt   KEYS_METHOD(   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_mapping_protocol  s    c         C   s   t  |  t  S(   N(   RU  t   CONTAINS_METHOD(   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt"   _supports_membership_test_protocol  s    c         C   s   t  |  t  p t  |  t  S(   N(   RU  t   ITER_METHODR[  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_iteration_protocol  s    c         C   s   t  |  t  S(   N(   RU  R[  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_getitem_protocol  s    c         C   s   t  |  t  S(   N(   RU  t   SETITEM_METHOD(   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_setitem_protocol  s    c         C   s   t  |  t  S(   N(   RU  t   DELITEM_METHOD(   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_delitem_protocol  s    c         C   sX   |  j    } | j d  } | j d  } | j d  pE | j d  } | pW | pW | S(   Nt   mixinR5  R   (   t   lowerR   R   (   Rt   t   lnamet   is_mixinRM  t   is_base(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _is_abstract_class_name  s
    c         C   ss   xl |  d  k	 rn t |  t j  rb t |   r1 t St |  d d   } | d  k	 rb t |  rb t Sn  |  j }  q Wt	 S(   NRt   (
   R   Rx   Rz   R   RO  R   R   Rl  Ry   R   (   R|   Rt   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_inside_abstract_class  s    c         C   s   t  |  t j  rP t |   s" t S|  j   } | d  k	 rP | |  rM t SqP n  t  |  t j  r t |   sr t S|  j   r t S| |   r t Sn  t  |  t	 j
  r t  |  j t j  r t |  j  r |  j }  | |   St S(   N(   Rx   Rz   R   t   has_known_basesR   t	   metaclassR   t   BaseInstancet   has_dynamic_getattrt   _basest   Proxyt   _proxiedR   (   R  t   protocol_callbackt   meta(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   _supports_protocol  s(    
	
c         C   s   t  |  t  S(   N(   Rw  Ra  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_iterable  s    c         C   s   t  |  t  S(   N(   Rw  R]  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt
   is_mapping  s    c         C   s   t  |  t  } | p t |   S(   N(   Rw  R_  Rx  (   R  t	   supported(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   supports_membership_test  s    c         C   s   t  |  t  S(   N(   Rw  Rb  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   supports_getitem   s    c         C   s   t  |  t  S(   N(   Rw  Rd  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   supports_setitem$  s    c         C   s   t  |  t  S(   N(   Rw  Rf  (   R  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   supports_delitem(  s    c         C   sy   y" |  j  d |  } t |  } Wn t j k
 r9 d SXy t |  d SWn& t j k
 rc d St k
 rt | SXd S(   s   Return the inferred value for the given node.

    Return None if inference failed or if there is some ambiguity (more than
    one node has been inferred).
    RA  N(   R"  R   Rz   R  R   t   StopIteration(   R|   RA  t   inferitR  (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR1  -  s    
c         C   s   y |  j  SWn t k
 r n Xxb |  j D]W } t | d | } t | t j  ss | |  k ss t | d | r) t |  _  t Sq) Wt	 |  _  t	 S(   s=   Return true if all base classes of a class could be inferred.RA  (
   t   _all_bases_knownR   R   R1  Rx   Rz   R   Rn  R   R   (   R   RA  R   t   result(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyRn  B  s    		c         C   sL   |  d  k pK t |  t j  r- |  j d  k pK t |  t j  oK |  j d k S(   NR   (   R   Rx   Rz   RQ  R  R   Rt   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_noneT  s    !c         C   s   t    } y_ xX |  j   D]J } | t j k s t |  r@ q n  | j |  t |  d k r d Sq WWn t j k
 r d SX| r | j	   Sd S(   s   Return the inferred type for `node`

    If there is more than one possible type, or if inferred type is YES or None,
    return None
    i   N(
   R   R"  Rz   t   UninferableR  R   R   R   R  t   pop(   R|   t   typest   var_type(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt	   node_type[  s    	c         C   s   d } t  |  t j  s t S|  j r1 |  j j n g  } x | D] } t  | t j  s\ q> n  | j } t  | t j  s> | j	 d k r q> n  y t
 | j j    } Wn t j k
 r q> n Xt  | t j  r> t | |  Sq> Wt S(   s>   Check if the given function node is a singledispatch function.s   functools.singledispatchs   singledispatch.singledispatcht   register(   s   functools.singledispatchs   singledispatch.singledispatch(   Rx   Rz   R   R   R  R  t   CallR   t	   AttributeR   R   R   R"  R  R'  (   R|   t   singledispatch_qnamesR  R  R   t   func_def(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt(   is_registered_in_singledispatch_functionp  s$     	"c         C   s   t  |  d t  r# t |  j d  St  |  d t  rF t |  j d  St  |  d t  ri t |  j d  St  |  d t  r t |  j d  S|  j S(   s   
    Get the last lineno of the given node. For a simple statement this will just be node.lineno,
    but for a node that has child statements (e.g. a method) this will be the lineno of the last
    child statement recursively.
    t	   finalbodyit   orelseR;  R   (   R   R   t   get_node_last_linenoR  R  R;  R   R   (   R|   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyR    s    c         C   s3   |  } x& | j  r. | j  } t |  r	 t Sq	 Wt S(   s3   Return True if the given node is in a comprehension(   Ry   RZ  R   R   (   R|   t   curnode(    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   in_comprehension  s    	c         C   s   x |  j  D] } y | j   } Wn t j k
 r9 q
 n XxN | D]F } t | t j  s_ qA n  | j d k rA | j   j d k rA t SqA Wq
 Wt	 S(   s   Check if a class definition defines an Enum class.

    :param node: The class node to check.
    :type node: astroid.ClassDef

    :returns: True if the given node represents an Enum class. False otherwise.
    :rtype: bool
    t   Enumt   enum(
   R   t   inferredRz   R  Rx   R   Rt   R   R   R   (   R|   R   t   inferred_basesR   (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   is_enum_class  s    	$(   s   abc.abstractpropertys   abc.abstractmethods   abc.abstractclassmethods   abc.abstractstaticmethod(   R   R   R   (&   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R    R!   R"   R   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R/   R0   (<   R1   R2   R3   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R
   R>   R   R   R?   R@   RA   RB   RC   RD   RE   RF   RG   RH   RI   RJ   RK   RL   RM   RN   RO   RP   RQ   RR   RS   RT   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   (   Rj   Rk   Rl   R   Rm   (   Rn   Ro   (   Rp   (   i    i   (   R   (n   R   t   collectionsR)  R    R@  R   t   backports.functools_lru_cacheR<  R   t   sysR   t   warningsR  t	   six.movesR   R   Rz   R   Rr  R   Rv   R   R   RV  RW  RX  R   t   version_infoR   R  R   R+  R`  t   PY2t   NEXT_METHODR[  Rc  Re  R^  R\  R   t   _SPECIAL_METHODS_PARAMSR   t   SPECIAL_METHODS_PARAMSt	   PYMETHODSR   Ru   R~   R   R   R   R   R   t   __dict__t   copyR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R	  R  R  R   R  R'  R6  R9  RE  R?  RH  RI  RK  RO  RU  RZ  R]  R_  Ra  Rb  Rd  Rf  Rl  Rm  Rw  Rx  Ry  R{  R|  R}  R~  R1  Rn  R  R  R  R  R  R  (    (    (    s4   lib/python2.7/site-packages/pylint/checkers/utils.pyt   <module>   s  			                   
			
							<				
			F								:																											 		