ó
&9_[c           @   sA   d  Z  d d l Z d d l m Z d „  Z d „  Z d „  Z d S(   s:   A fancy version of Python's builtin :func:`dir` function.
iÿÿÿÿNi   (   t   string_typesc         C   s$   y t  |  | ƒ t SWn t SXd S(   sf   In recent versions of Python, hasattr() only catches AttributeError.
    This catches all errors.
    N(   t   getattrt   Truet   False(   t   objt   attr(    (    s1   lib/python2.7/site-packages/IPython/utils/dir2.pyt   safe_hasattr   s
    c         C   se   y t  t |  ƒ ƒ } Wn t k
 r2 t  ƒ  } n Xg  | D] } t | t ƒ r: | ^ q: } t | ƒ S(   sv  dir2(obj) -> list of strings

    Extended version of the Python builtin dir(), which does a few extra
    checks.

    This version is guaranteed to return only a list of true strings, whereas
    dir() returns anything that objects inject into themselves, even if they
    are later not really valid for attribute access (many extension libraries
    have such bugs).
    (   t   sett   dirt	   Exceptiont
   isinstanceR    t   sorted(   R   t   wordst   w(    (    s1   lib/python2.7/site-packages/IPython/utils/dir2.pyt   dir2   s    (c         C   s   t  j |  ƒ r d Sy t |  d d ƒ } Wn t k
 r= d SX| d k	 rN d Sy t |  | d ƒ } Wn t k
 rx d SXt | ƒ r‰ | Sd S(   s1  Like getattr, but with a few extra sanity checks:

    - If obj is a class, ignore its methods
    - Check if obj is a proxy that claims to have all attributes
    - Catch attribute access failing with any exception
    - Check that the attribute is a callable object

    Returns the method or None.
    t(   _ipython_canary_method_should_not_exist_N(   t   inspectt   isclasst   NoneR   R	   t   callable(   R   t   namet   canaryt   m(    (    s1   lib/python2.7/site-packages/IPython/utils/dir2.pyt   get_real_method3   s    
(   t   __doc__R   t	   py3compatR    R   R   R   (    (    (    s1   lib/python2.7/site-packages/IPython/utils/dir2.pyt   <module>   s
   		