o
    Ďi                     @   sZ   d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 e
dZeG dd deZdS )	z9Implementation of configuration-related magic functions.
    N)
UsageError)Magicsmagics_class
line_magic)errorz
^\w+\.\w+$c                       s(   e Zd Z fddZedd Z  ZS )ConfigMagicsc                    s   t t| | g | _d S N)superr   __init__configurables)selfshell	__class__ V/home/jeff/fluffinator/venv/lib/python3.10/site-packages/IPython/core/magics/config.pyr
      s   
zConfigMagics.__init__c                 C   s  ddl m} ttdd | jjD dd d}dd |D }| }|s4td	 |D ]}td
| q*dS ||v rY||| }|j	}|
|}	ttdtjd|	}	t|	 dS t|ro|d\}}
t||| |
S d|vrd}| }|D ]}|| kr|d|  } nq{t|| | }td| | jjt  |D ]}z|| W q ty } z
t| W Y d}~qd}~ww dS )a  configure IPython

            %config Class[.trait=value]

        This magic exposes most of the IPython config system. Any
        Configurable class should be able to be configured with the simple
        line::

            %config Class.trait=value

        Where `value` will be resolved in the user's namespace, if it is an
        expression or variable name.

        Examples
        --------

        To see what classes are available for config, pass no arguments::

            In [1]: %config
            Available objects for config:
                AliasManager
                DisplayFormatter
                HistoryManager
                IPCompleter
                LoggingMagics
                MagicsManager
                OSMagics
                PrefilterManager
                ScriptMagics
                TerminalInteractiveShell

        To view what is configurable on a given class, just pass the class
        name::

            In [2]: %config LoggingMagics
            LoggingMagics(Magics) options
            ---------------------------
            LoggingMagics.quiet=<Bool>
                Suppress output of log state when logging is enabled
                Current: False

        but the real use is in setting values::

            In [3]: %config LoggingMagics.quiet = True

        and these values are read from the user_ns if they are variables::

            In [4]: feeling_quiet=False

            In [5]: %config LoggingMagics.quiet = feeling_quiet

        r   )Configc                 S   s   g | ]}|j jd dr|qS )T)config)r   class_traits.0cr   r   r   
<listcomp>]   s    
z'ConfigMagics.config.<locals>.<listcomp>c                 S   s   | j jS r   r   __name__)xr   r   r   <lambda>_   s    z%ConfigMagics.config.<locals>.<lambda>)keyc                 S   s   g | ]}|j jqS r   r   r   r   r   r   r   `   s    zAvailable objects for config:z   Nz^-- .=z>Invalid config statement: %r, should be `Class.trait = value`.z!
Did you mean %s (note the case)?zcfg.)traitlets.config.loaderr   sortedsetr   r   stripprintindexr   class_get_helpresubcompile	MULTILINEregmatchsplitgetattrlowerr   execuser_nslocalsupdate_config	Exceptionr   )r   sr   r   
classnameslinenamer   clshelpattrmsgll	classnamecfgconfigurableer   r   r   r   #   sP   6

zConfigMagics.config)r   
__module____qualname__r
   r   r   __classcell__r   r   r   r   r      s    r   )__doc__r(   IPython.core.errorr   IPython.core.magicr   r   r   loggingr   r*   r,   r   r   r   r   r   <module>   s    
