B
    Çä˜\¸  ã               @   s0   d Z ddlZddlZdd„ Zdd„ Zdd„ ZdS )	z:A fancy version of Python's builtin :func:`dir` function.
é    Nc             C   s   yt | |ƒ dS    dS dS )zfIn recent versions of Python, hasattr() only catches AttributeError.
    This catches all errors.
    TFN)Úgetattr)ÚobjÚattr© r   ú1lib/python3.7/site-packages/IPython/utils/dir2.pyÚsafe_hasattr   s
    
r   c             C   s^   yt t| ƒƒ}W n tk
r*   t ƒ }Y nX t| dƒrH|t t| jƒƒO }dd„ |D ƒ}t|ƒS )av  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).
    Ú	__class__c             S   s   g | ]}t |tƒr|‘qS r   )Ú
isinstanceÚstr)Ú.0Úwr   r   r   ú
<listcomp>2   s    zdir2.<locals>.<listcomp>)ÚsetÚdirÚ	Exceptionr   r   Úsorted)r   Zwordsr   r   r   Údir2   s    
r   c             C   s‚   yt | ddƒ}W n tk
r$   dS X |dk	r2dS yt | |dƒ}W n tk
rV   dS X t | ¡rrt|tjƒsrdS t|ƒr~|S dS )aE  Like getattr, but with a few extra sanity checks:

    - If obj is a class, ignore everything except class 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.
    Z(_ipython_canary_method_should_not_exist_N)r   r   ÚinspectZisclassr	   ÚtypesÚ
MethodTypeÚcallable)r   ÚnameZcanaryÚmr   r   r   Úget_real_method6   s    
r   )Ú__doc__r   r   r   r   r   r   r   r   r   Ú<module>   s
   