B
    \                 @   sj   d Z ddlZddlZddlmZ dgfddZe \ZZdd Zdd
dZ	dd Z
dddZdddZdS )u   Support for wildcard pattern matching in object inspection.

Authors
-------
- Jörgen Stenarson <jorgen.stenarson@bostream.nu>
- Thomas Kluyver
    N)dir2lambdac             C   sd   dd t tD }i i  }}x>|D ]6}|dd  }tt|}|||< || kr"|||< q"W ||fS )zzReturn dictionaries mapping lower case typename (e.g. 'tuple') to type
    objects from the types package, and vice versa.c             S   s   g | ]}| d r|qS )ZType)endswith).0tname r   5lib/python3.7/site-packages/IPython/utils/wildcard.py
<listcomp>   s    z-create_typestr2type_dicts.<locals>.<listcomp>N)dirtypeslowergetattr)Zdont_include_in_type2typestrZtypenamelisttypestr2typetype2typestrr   nameobjr   r   r   create_typestr2type_dicts   s    


r   c             C   s<   |dkrdS t |t kr|}nt|d}|r8t| |S dS )a  is_type(obj, typestr_or_type) verifies if obj is of a certain type. It
    can take strings or actual python types for the second argument, i.e.
    'tuple'<->TupleType. 'all' matches all types.

    TODO: Should be extended for choosing more than one type.allTF)typer   get
isinstance)r   Ztypestr_or_typeZ	test_typer   r   r   is_type&   s    
r   Fc             C   s   |p|  dp|  d S )zCReturn true for strings starting with single _ if show_all is true.___)
startswith)strshow_allr   r   r   show_hidden6   s    r   c          	   C   sB   i }x8t | D ],}yt| |||< W q tk
r8   Y qX qW |S )zwProduce a dictionary of an object's attributes. Builds on dir2 by
    checking that a getattr() call actually succeeds.)r   r   AttributeError)r   nskeyr   r   r   dict_dir:   s    
r"   *r   Tc                sX   | dd dd}|r,t|d tj nt|d  t fdd|  D S )z<Filter a namespace dictionary by name pattern and item type.r#   z.*?.$c             3   s8   | ]0\}}  |rt|rt|r||fV  qd S )N)matchr   r   )r   r!   r   )regr   type_patternr   r   	<genexpr>U   s    
zfilter_ns.<locals>.<genexpr>)replacerecompileIdictitems)r    name_patternr)   ignore_caser   patternr   )r(   r   r)   r   	filter_nsK   s
    r4   c          	   C   s   | d}t|dkr,t| |d |||dS t| |d d||d}i }x^| D ]R\}}	tt|	|d|dd ||d}
x$|
 D ]\}}||d||f < qW qPW |S dS )	zbReturn dictionary of all objects in a namespace dictionary that match
    type_pattern and filter.r%      r   )r1   r)   r2   r   r   N)r2   r   z%s.%s)splitlenr4   r0   list_namespacer"   join)	namespacer)   filterr2   r   Zpattern_listZfilteredZresultsr   r   r    Z
inner_nameZ	inner_objr   r   r   r8   Y   s     






r8   )F)r#   r   TT)FF)__doc__r,   r   ZIPython.utils.dir2r   r   r   r   r   r   r"   r4   r8   r   r   r   r   <module>   s   	

 
