o
    Zh                     @   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   M/var/www/html/lang_env/lib/python3.10/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   


