o
    û›h  ã                   @   sn   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   s`   dd„ t tƒD ƒ}i i }}|D ]}|dd…  ¡ }tt|ƒ}|||< || vr+|||< q||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 )ÚType)Úendswith)Ú.0Útname© r   úLc:\Users\shubh\Videos\agent\nova\Lib\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¡}|rt| |ƒ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   s:   i }t | ƒD ]}z	t| |ƒ||< W q ty   Y 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   s:   � | ]\}}ˆ   |¡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	   Ú	filter_nsK   s
   r6   c              	   C   s¢   |  d¡}t|ƒdkrt| |d |||d�S t| |d d||d�}i }| ¡ D ]'\}}	tt|	ƒ|d |dd… ¡||d�}
|
 ¡ D ]\}}||d||f < qAq'|S )	zbReturn dictionary of all objects in a namespace dictionary that match
    type_pattern and filter.r&   é   r   )r3   r+   r4   r   r   N)r4   r   z%s.%s)ÚsplitÚlenr6   r2   Úlist_namespacer#   Újoin)Ú	namespacer+   Úfilterr4   r   Zpattern_listÚfilteredÚresultsr   r   r!   Z
inner_nameZ	inner_objr   r   r	   r:   Y   s(   

þ
þ
þÿr:   )F)r$   r   TT)FF)Ú__doc__r.   r   ZIPython.utils.dir2r   r   r   r   r   r   r#   r6   r:   r   r   r   r	   Ú<module>   s   


ÿ