a
    lc                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZmZmZmZmZ dd
lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 d3 Z4d3 Z5e6eds<dge_7dZ8ej9:ddZ;e;< dv rbdZ=n e;< dv rvdZ=ne>de; ej?oej?@dZAdd ZBG dd deCZDG d d! d!ejEZFG d"d# d#eZGeGjHZIeGjJZKd)d$d%ZLd&d' ZMeNd(kr eGO  dS )*z,A base class for a configurable application.    N)OrderedDictdefaultdict)suppress)deepcopy)
dictConfig)dedent)ConfigurableSingletonConfigurable)ArgumentErrorConfigConfigFileNotFoundJSONFileConfigLoaderKVArgParseConfigLoaderPyFileConfigLoader)
BoolDictEnumInstanceList
TraitErrorUnicodedefaultobserveobserve_compat)nested_update)indentwrap_paragraphs   cast_unicode)import_itemz
The options below are convenience aliases to configurable class-options,
as listed in the "Equivalent to" description-line of the aliases.
To see all configurable class-options for some <cmd>, use:
    <cmd> --help-all
z
The command-line option below sets the respective configurable class-parameter:
    --Class.parameter=value
This line is evaluated in Python, so simple expressions are allowed.
For instance, to set `C.a=[0,1,2]`, you may type this:
    --C.a='range(3)'
argv zp
Subcommands are launched as `{app} cmd [args]`. For information on using
subcommand 'cmd', do: `{app} cmd -h`.
-TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR>   1trueT>   falser"   0FzUnsupported value for environment variable: 'TRAITLETS_APPLICATION_RAISE_CONFIG_FILE_ERROR' is set to '%s' which is none of  {'0', '1', 'false', 'true', ''}.zpythonw.exec                    s   t   fdd}|S )a  Method decorator for catching invalid config (Trait/ArgumentErrors) during init.

    On a TraitError (generally caused by bad config), this will print the trait's
    message, and exit the app.

    For use on init methods, to prevent invoking excepthook on invalid input.
    c              
      sn   z | g|R i |W S  t tfyh } z4| jd| | jd| j | d W Y d }~n
d }~0 0 d S )Nz0Bad config encountered during initialization: %szConfig at the time: %s   )r   r
   logfataldebugconfigexit)appargskwargsemethod X/var/www/html/django/DPS/env/lib/python3.9/site-packages/traitlets/config/application.pyinnerk   s    z!catch_config_error.<locals>.inner)	functoolswraps)r3   r6   r4   r2   r5   catch_config_errorb   s    	r9   c                   @   s   e Zd ZdS )ApplicationErrorN)__name__
__module____qualname__r4   r4   r4   r5   r:   w   s   r:   c                       s*   e Zd ZdZejZdZ fddZ  Z	S )LevelFormattera  Formatter with additional `highlevel` record

    This field is empty if log level is less than highlevel_limit,
    otherwise it is formatted with self.highlevel_format.

    Useful for adding 'WARNING' to warning messages,
    without adding 'INFO' to info, etc.
    z %(levelname)s |c                    s.   |j | jkr| j|j |_nd|_t |S )Nr"   )levelnohighlevel_limithighlevel_format__dict__Z	highlevelsuperformat)selfrecord	__class__r4   r5   rD      s    zLevelFormatter.format)
r;   r<   r=   __doc__loggingWARNr@   rA   rD   __classcell__r4   r4   rG   r5   r>   {   s   	r>   c                       s  e Zd ZU dZedZejeef e	d< edZ
ejeef e	d< eeZejeef e	d< eeZejeef e	d< eeZejeef e	d< eZeZe Zejeef e	d	< g Zejejej  e	d
< dddZedZejeef e	d< e Zejeje ef e	d< eeZejeef e	d< edej ddj!ddZ"ejee#ef e	d< e$Z%edddj!ddZ&ejeef e	d< edddj!ddZ'ejeef e	d< dd  Z(e)dddd!d"d# Z*e)d$d%d&d'd( Z+d)d* Z,e-d$d+d, Z.e/d-dj!ddZ0d.d/iZ1ej/eejf e	d0< d dej2iid1fd d2diid3fd d4diid5fd6Z3ej/eejf e	d7< e/ Z4ejej/eej5eef f e/f e	d8< e6d9dd:Z7ee Z8ejeje ef e	d;< e6e9d<i d=dZ:e Z;ed>dj!ddZ<ejeef e	d2< ed?dj!ddZ=ejeef e	d4< e)d4d@dA Z>e)d2dBdC Z?dDdE Z@e)dFeA fdGdHZBeCddIdJZDdKdL ZEdMdN ZFdOdP ZGdQdR ZHdSdT ZIdUdV ZJdWdX ZKdYdZ ZLd[d\ ZMd]d^ ZNd_d` ZOddbdcZPddddeZQdfdg ZRdhdi ZSdjdk ZTdldm ZUdndo ZVdpdq ZWeCddrdsZXdtdu ZYdvdw ZZeCddxdyZ[e\ddzd{Z]e^d|d} Z_eCdd~dZ`dddZadddZbdd ZcdddZddd Zee\dddZf  ZgS )Applicationz8A singleton application with full configuration support.ZapplicationnamezThis is an application.descriptionoption_descriptionkeyvalue_descriptionsubcommand_descriptionexamplesclassesNc                 c   sV   |du r| j }t }|D ]8}t| D ]&}t|tr(||vr(|| |V  q(qdS )a  Iterate through configurable classes, including configurable parents

        :param classes:
            The list of classes to iterate; if not set, uses :attr:`classes`.

        Children should always be after parents, and each class should only be
        yielded once.
        N)rT   setreversedmro
issubclassr   add)rE   rT   seencparentr4   r4   r5   _classes_inc_parents   s    	
z Application._classes_inc_parentsz0.0versionr!   raise_config_file_errors)r   
         (   2   DEBUGINFOrK   ERRORCRITICALz#Set the log level by value or name.)default_valuehelpTr,   	log_levelz%Y-%m-%d %H:%M:%Sz:The date format used by logging formatters for %(asctime)s)rj   log_datefmtz#[%(name)s]%(highlevel)s %(message)szThe Logging format template
log_formatc                 C   sl   ddddt | jddid| jj d| jj | j| jdi| jjddgd	id
d}t	rh|d= |d= |S )a  Return the base logging configuration.

        The default is to log to stderr using a StreamHandler, if no default
        handler already exists.

        The log handler level starts at logging.WARN, but this can be adjusted
        by setting the ``log_level`` attribute.

        The ``logging_config`` trait is merged into this allowing for finer
        control of logging.

        r(   consolezlogging.StreamHandlerzext://sys.stderr)class	formatterlevelstream.)rp   rD   datefmtre   )rr   handlersF)r^   rv   
formattersloggersdisable_existing_loggersrv   rx   )
rJ   getLevelNamerl   _log_formatter_clsr<   r;   rn   rm   rH   
IS_PYTHONWrE   r,   r4   r4   r5   get_default_logging_config   s6    
	
z&Application.get_default_logging_configlogging_configc                 C   s(   | j }t|trtt|| _ |   d S N)rl   
isinstancestrgetattrrJ   _configure_logging)rE   changerl   r4   r4   r5   _observe_logging_change  s    
z#Application._observe_logging_changer)   r   )typec                 C   s   |    d S r   )r   rE   r   r4   r4   r5   _observe_logging_default  s    z$Application._observe_logging_defaultc                 C   s*   |   }t|| jpi  t| d| _d S )NT)r~   r   r   r   _logging_configuredr}   r4   r4   r5   r     s    zApplication._configure_loggingc                 C   s<   t | jj}d|_|}|r8|jr&|S |js0q8q|j}q|S )z#Start logging for this application.F)rJ   	getLoggerrH   r;   	propagaterv   r\   )rE   r)   _logr4   r4   r5   _log_default   s    zApplication._log_defaulta   
            Configure additional log handlers.

            The default stderr logs handler is configured by the
            log_level, log_datefmt and log_format settings.

            This configuration can be used to configure additional handlers
            (e.g. to output the log to a file) or for finer control over the
            default handlers.

            If provided this should be a logging configuration dictionary, for
            more information see:
            https://docs.python.org/3/library/logging.config.html#logging-config-dictschema

            This dictionary is merged with the base logging configuration which
            defines the following:

            * A logging formatter intended for interactive use called
              ``console``.
            * A logging handler that writes to stderr called
              ``console`` which uses the formatter ``console``.
            * A logger with the name of this application set to ``DEBUG``
              level.

            This example adds a new handler that writes to a file:

            .. code-block:: python

               c.Application.logging_config = {
                   'handlers': {
                       'file': {
                           'class': 'logging.FileHandler',
                           'level': 'DEBUG',
                           'filename': '<path/to/file>',
                       }
                   },
                   'loggers': {
                       '<application-name>': {
                           'level': 'DEBUG',
                           # NOTE: if you don't list the default "console"
                           # handler here then it will be disabled
                           'handlers': ['console', 'file'],
                       },
                   }
               }

        z	log-levelzApplication.log_levelaliasesz5Set log-level to debug, for the most verbose logging.show_configz<Show the application's configuration (human-readable format)show_config_jsonz2Show the application's configuration (json format))r+   zshow-configzshow-config-jsonflagssubcommandsz(traitlets.config.application.Application)
allow_none
extra_argsr4   zThe subset of our configuration that came from the command-line

        We re-load this configuration after loading config files,
        to ensure that it maintains highest priority.
        zAInstead of starting the Application, dump configuration to stdoutzKInstead of starting the Application, dump configuration to stdout (as JSON)c                 C   s   |j | _d S r   )newr   r   r4   r4   r5   _show_config_json_changed  s    z%Application._show_config_json_changedc                 C   s   |j r| j| _| j| _d S r   )r   startZ_save_startstart_show_configr   r4   r4   r5   _show_config_changed  s    z Application._show_config_changedc                 K   sR   t j| fi | | j}|| jvrN| j|ju r>|g| j | _n| jd| j d S )Nr   )r	   __init__rH   rT   insert)rE   r0   clsr4   r4   r5   r     s    
zApplication.__init__r,   c                    s    t  | | jd|j d S )NzConfig changed: %r)rC   _config_changedr)   r+   r   r   rG   r4   r5   r     s    zApplication._config_changedc                 C   s   |  | dS )zMDo the basic steps to configure me.

        Override in subclasses.
        N)parse_command_line)rE   r!   r4   r4   r5   
initialize  s    zApplication.initializec                 C   s   | j dur| j  S dS )zAStart the app mainloop.

        Override in subclasses.
        N)subappr   rE   r4   r4   r5   r     s    
zApplication.startc           
   
   C   s  | j  }| j D ]0}|j|v r||j }|dd |dd q| jrrtj|t	j
ddtd t	j
d dS | jrtd | jD ]}td	|  qt  t|D ]Z}|| }|sqt| td
dd}t|D ]*}|| }	td|tj|	fi | qqdS )z,start function used when show_config is Truer   Nr   r(   T)r   	sort_keysr   
zLoaded config files:z     )r   compactz
  .{} = {})r,   copyrH   rW   r;   popr   jsondumpsysstdoutreprwrite_loaded_config_filesprintsorteddictrD   pprintpformat)
rE   r,   r   Z
cls_configf	classnameZclass_configZpformat_kwargs	traitnamevaluer4   r4   r5   r     s:    



zApplication.start_show_configc                 C   s   t d|   dS )z"Print the alias parts of the help.r   N)r   joinemit_alias_helpr   r4   r4   r5   print_alias_help  s    zApplication.print_alias_helpc                 c   sV  | j s
dS i }| jD ]$}| dd D ]}|||j< q(q| j  D ]
\}}zt|trd|\}}nd}|ddd \}}|d | }|| }|jdd| }	|j	|	|d
 }t|ts|f}t|td}d	d
d |D }|d d| ||d< |E dH  td| V  W qD tyN }
 z| jd||
  W Y d}
~
qDd}
~
0 0 qDdS )z+Yield the lines for alias part of the help.Nrt   Trk   )Zhelptextkey, c                 s   s&   | ]}t |d krdnd| V  qdS r(   z--%sz-%sNlen.0mr4   r4   r5   	<genexpr>      z.Application.emit_alias_help.<locals>.<genexpr>r   --zEquivalent to: [--%s]z7Failed collecting help-message for alias %r, due to: %s)r   rT   rW   r;   itemsr   tuplesplitZclass_traitsZclass_get_trait_help
splitlinesr   r   r   replacer   	Exceptionr)   error)rE   	classdictr   r[   aliaslongnamefhelpr   r   traitexr4   r4   r5   r     s4    




zApplication.emit_alias_helpc                 C   s   t d|   dS )z Print the flag part of the help.r   N)r   r   emit_flag_helpr   r4   r4   r5   print_flag_help!  s    zApplication.print_flag_helpc                 c   s   | j s
dS | j  D ]\}\}}zzt|ts2|f}t|td}ddd |D }|V  tt|	 V  ddd | D }d| }tt|V  W q t
y } z| jd	||  W Y d}~qd}~0 0 qdS )
z.Yield the lines for the flag part of the help.Nr   r   c                 s   s&   | ]}t |d krdnd| V  qdS r   r   r   r4   r4   r5   r   /  r   z-Application.emit_flag_help.<locals>.<genexpr> c                 s   s:   | ]2\}}|  D ] \}}d | d| d| V  qqdS )r   rt   =N)r   )r   ZclnameZ
props_dictpropvalr4   r4   r5   r   2  s   zEquivalent to: [%s]z6Failed collecting help-message for flag %r, due to: %s)r   r   r   r   r   r   r   r   r   stripr   r)   r   )rE   r   cfgr   Zcfg_listZcfg_txtr   r4   r4   r5   r   %  s$    

zApplication.emit_flag_helpc                 C   s   t d|   dS )z#Print the options part of the help.r   N)r   r   emit_options_helpr   r4   r4   r5   print_options=  s    zApplication.print_optionsc                 c   sj   | j s| jsdS d}|V  dt| V  t| jD ]}|V  dV  q2|  E dH  |  E dH  dV  dS )z1Yield the lines for the options part of the help.NOptionsr   r"   )r   r   r   r   rP   r   r   )rE   headerpr4   r4   r5   r   A  s    zApplication.emit_options_helpc                 C   s   t d|   dS )z&Print the subcommand part of the help.r   N)r   r   emit_subcommands_helpr   r4   r4   r5   print_subcommandsP  s    zApplication.print_subcommandsc                 c   s   | j s
dS d}|V  dt| V  t| jj| jdD ]}|V  dV  q6| j  D ](\}\}}|V  |rRtt|	 V  qRdV  dS )z4Yield the lines for the subcommand part of the help.NZSubcommandsr   )r.   r"   )
r   r   r   rR   rD   rN   r   r   r   r   )rE   r   r   subc_rj   r4   r4   r5   r   T  s    z!Application.emit_subcommands_helpc                 c   s   |sdV  dV  dS )zzYield the very bottom lines of the help message.

        If classes=False (the default), print `--help-all` msg.
        z5To see all available configurables, use `--help-all`.r"   Nr4   rE   rT   r4   r4   r5   emit_help_epiloguee  s    zApplication.emit_help_epilogueFc                 C   s   t d| j|d dS )zPrint the help for each Configurable class in self.classes.

        If classes=False (the default), only flags and aliases are printed.
        r   rT   N)r   r   	emit_helpr   r4   r4   r5   
print_helpn  s    zApplication.print_helpc                 c   s   |   E dH  |  E dH  |  E dH  |r||  }|rbdV  dV  t| jD ]}|V  dV  qP|D ]}| V  dV  qf|  E dH  | |E dH  dS )zYield the help-lines for each Configurable class in self.classes.

        If classes=False (the default), only flags and aliases are printed.
        NzClass optionsz=============r"   )	emit_descriptionr   r   _classes_with_config_traitsr   rQ   Zclass_get_helpemit_examplesr   )rE   rT   Zhelp_classesr   r   r4   r4   r5   r   u  s     
zApplication.emit_helpc                 C   s   d dd |  D S )zwGenerate rST format documentation for the config options this application

        Returns a multiline string.
        r   c                 s   s   | ]}|  V  qd S r   )Zclass_config_rst_doc)r   r[   r4   r4   r5   r     r   z6Application.document_config_options.<locals>.<genexpr>)r   r]   r   r4   r4   r5   document_config_options  s    z#Application.document_config_optionsc                 C   s   t d|   dS )z"Print the application description.r   N)r   r   r   r   r4   r4   r5   print_description  s    zApplication.print_descriptionc                 c   s*   t | jp| jpdD ]}|V  dV  qdS )z-Yield lines with the application description.r"   N)r   rO   rI   )rE   r   r4   r4   r5   r     s    zApplication.emit_descriptionc                 C   s   t d|   dS )z1Print usage and examples (see `emit_examples()`).r   N)r   r   r   r   r4   r4   r5   print_examples  s    zApplication.print_examplesc                 c   s6   | j r2dV  dV  dV  tt| j  V  dV  dS )zYield lines with the usage and examples.

        This usage string goes at the end of the command line help string
        and should contain examples of the application's usage.
        ZExamplesz--------r"   N)rS   r   r   r   r   r4   r4   r5   r     s    zApplication.emit_examplesc                 C   s   t | j dS )zPrint the version string.N)r   r^   r   r4   r4   r5   print_version  s    zApplication.print_versionc                 C   s   | j |}|dusJ |\}}t|tr2t|}t|tr`t|tr`| j	  |j
| d| _n t|rt|| | _ntd| | j| dS )z"Initialize a subcommand with argv.N)r\   z%Invalid mappings for subcommand '%s'!)r   getr   r   r    r   rX   rM   rH   Zclear_instanceinstancer   callableAssertionErrorr   )rE   r   r!   r   r   r   r4   r4   r5   initialize_subcommand  s    

z!Application.initialize_subcommandc                 C   sf  t t}| jD ]0}|j}| dd D ]}||j | q(qi }| j D ]r\}}t|t	rh|\}}|
dd\}}	|| }
t|
dkr|
d }t|t	s|f}|D ]}d||	g||< qqNi }| j D ]\}\}}i }| D ]H\}}|| }
t|
dkr|
d }||v r(|| | q|||< qt|t	sD|f}|D ]}||f||< qHq||fS )a  Flatten flags and aliases for loaders, so cl-args override as expected.

        This prevents issues such as an alias pointing to InteractiveShell,
        but a config file setting the same trait in TerminalInteraciveShell
        getting inappropriate priority over the command-line arg.
        Also, loaders expect ``(key: longname)`` and not ````key: (longname, help)`` items.

        Only aliases with exactly one descendent in the class list
        will be promoted.

        r(   r   rt   r   )r   listrT   r;   rW   appendr   r   r   r   r   r   r   r   update)rE   Zmro_treer   clsnamer\   r   r   r   r   r   childrenalr   r   Zflagdictrj   ZnewflagZsubdictkr4   r4   r5   flatten_flags  s@    




zApplication.flatten_flagsc                 C   s   t ||||| jdS )N)rT   r)   )r   r)   )rE   r!   r   r   rT   r4   r4   r5   _create_loader  s    zApplication._create_loaderc                    s  t |trJ |du r$tjdd n|}dd |D | _|rZ|d dkrZ|dd dg }| jrt|dkr|d |dd  }}td|r|| jv r| ||S z|d|	d	  W n t
y   | Y n0 t fd
ddD r| d v  | d d v sd v r(|   | d |  \}}t|  }| j||||d}zt| | _W n tyz    Y n0 | | j |j| _dS )z!Parse the command line arguments.Nr(   c                 S   s   g | ]}t |qS r4   r   )r   argr4   r4   r5   
<listcomp>  r   z2Application.parse_command_line.<locals>.<listcomp>r   rj   -hz^\w(\-?\w)*$r   c                 3   s   | ]}| v V  qd S r   r4   )r   xZinterpreted_argvr4   r5   r   &  r   z1Application.parse_command_line.<locals>.<genexpr>)r  
--help-allz--helpr  z	--versionz-Vr   )r   r   r   r!   r   r   rematchr   index
ValueErroranyr   r-   r   r   r   r   r  r   load_config
cli_config
SystemExitupdate_configr   )rE   r!   r   Zsubargvr   r   rT   loaderr4   r  r5   r     s8    


zApplication.parse_command_linec                 c   sR  t |ts|g}t|D ]2}| j|d ||d}|rL|d||pHt  | j|d ||d}g }g }	||fD ]}
d}z|
 }W nF t	y   Y nH t
y   |
jp|}|r |r|jd|dd Y n0 |r|d	|
j |rpt|	|D ]:\}}||}|r|r|d
||
jtj|dd q||
jfV  || |	|
j qpqdS )zeLoad config files (py,json) by filename and path.

        yield each config object in turn.
        z.py)pathr)   zLooking for %s in %sz.jsonNz&Exception while loading config file %sT)exc_infozLoaded config file: %szMCollisions detected in {0} and {1} config files. {1} has higher priority: {2}r   )r   )r   r   rV   python_config_loader_classr+   osgetcwdjson_config_loader_classr  r   r   Zfull_filenamer   zip
collisionswarningrD   r   dumpsr   )r   Zbasefilenamer  r)   r_   currentZpyloaderZ
jsonloaderZloaded	filenamesr  r,   filenameZearlier_configr  r4   r4   r5   _load_config_files<  sJ    



zApplication._load_config_filesc                 C   s   | j dd S )z$Currently loaded configuration filesN)r   r   r4   r4   r5   loaded_config_fileso  s    zApplication.loaded_config_filesc                 C   sp   t j|\}}t }| j||| j| jdD ](\}}|| || jvr,| j	| q,|| j
 | | dS )z'Load config files by filename and path.)r  r)   r_   N)r  r  splitextr   r  r)   r_   merger   r   r  r  )rE   r  r  extZ
new_configr,   fnamer4   r4   r5   load_config_filet  s    
zApplication.load_config_filec                 #   s   |du r| j }tdd | |D   fdd  }tfdd  D   |kr2q`q2  D ]\}}|rh|V  qhdS )a  
        Yields only classes with configurable traits, and their subclasses.

        :param classes:
            The list of classes to iterate; if not set, uses :attr:`classes`.

        Thus, produced sample config-file will contain all classes
        on which a trait-value may be overridden:

        - either on the class owning the trait,
        - or on its subclasses, even if those subclasses do not define
          any traits themselves.
        Nc                 s   s"   | ]}|t |jd dfV  qdS )Trk   N)boolZclass_own_traits)r   r   r4   r4   r5   r     s   z:Application._classes_with_config_traits.<locals>.<genexpr>c                    s   t  fdd| jD S )Nc                 3   s   | ]}| v o | V  qd S r   r4   )r   bcls_to_configr4   r5   r     r   zZApplication._classes_with_config_traits.<locals>.is_any_parent_included.<locals>.<genexpr>)r  	__bases__)r   r(  r4   r5   is_any_parent_included  s    zGApplication._classes_with_config_traits.<locals>.is_any_parent_includedc                 3   s"   | ]\}}||p |fV  qd S r   r4   )r   r   inc_yes)r+  r4   r5   r     s   )rT   r   r]   r   r   )rE   rT   Zto_incl_origclr,  r4   )r)  r+  r5   r     s    z'Application._classes_with_config_traitsc                 C   sn   d| j  g}|d |d |d |du r8| jn|}t| |}|D ]}||| qNd|S )z/generate default config file from Configurablesz# Configuration file for %s.r"   zc = get_config()  # noqaNr   )rN   r   rT   r   r   Zclass_config_sectionr   )rE   rT   linesZconfig_classesr   r4   r4   r5   generate_config_file  s    


z Application.generate_config_filec              	   C   sT   t | ddrP| jjD ]4}tt |  W d    q1 s>0    Y  qd| _d S )Nr   F)r   r)   rv   r   r   closer   )rE   handlerr4   r4   r5   close_handlers  s
    
(zApplication.close_handlersr   c                 C   s(   | j d| j  |   t| d S )NzExiting application: %s)r)   r+   rN   r2  r   r-   )rE   Zexit_statusr4   r4   r5   r-     s    zApplication.exitc                 C   s   |    d S r   )r2  r   r4   r4   r5   __del__  s    zApplication.__del__c                 K   s&   | j f i |}|| |  dS )zLaunch a global instance of this Application

        If a global instance already exists, this reinitializes and starts it
        N)r   r   r   )r   r!   r0   r.   r4   r4   r5   launch_instance  s    
zApplication.launch_instance)N)N)F)F)N)N)NNF)N)N)N)r   )N)hr;   r<   r=   rI   r   rN   tUnionr   __annotations__rO   rP   rQ   rR   r   r  r   r  rS   rT   r   TypeAnyr]   r^   r!   r   r#   r_   r&  r   rJ   rK   tagrl   intr>   r{   rm   rn   r~   r   r   r   r   r   r   r   r   r   re   r   r   Tupler   r   r   r   r  r   r   r   r   r   r   r   r   r9   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   classmethodr  propertyr   r%  r   r/  r2  r-   r3  r4  rL   r4   r4   rG   r5   rM      s  

3



05	

 ,"

&%	

;02

(


rM   c                 C   sV   |p
d| }|pd| }| d\}}||dii}||dii}| ||fd|  ||fiS )a  Helper for building basic --trait, --no-trait flags.

    Parameters
    ----------
    name : str
        The name of the flag.
    configurable : str
        The 'Class.trait' string of the trait to be set/unset with the flag
    set_help : unicode
        help string for --name flag
    unset_help : unicode
        help string for --no-name flag

    Returns
    -------
    cfg : dict
        A dict with two keys: 'name', and 'no-name', for setting and unsetting
        the trait, respectively.
    zset %s=Truezset %s=Falsert   TFzno-)r   )rN   ZconfigurableZset_helpZ
unset_helpr   r   setterZunsetterr4   r4   r5   boolean_flag  s    r@  c                   C   s   t  rt  jS t S dS )z|Get the config object for the global Application instance, if there is one

    otherwise return an empty config object
    N)rM   Zinitializedr   r,   r   r4   r4   r4   r5   
get_config   s    
rA  __main__)r"   r"   )PrI   r7   r   rJ   r  r   r  r   typingr5  collectionsr   r   
contextlibr   r   r   logging.configr   textwrapr   Ztraitlets.config.configurabler   r	   Ztraitlets.config.loaderr
   r   r   r   r   r   Ztraitlets.traitletsr   r   r   r   r   r   r   r   r   r   Ztraitlets.utils.nested_updater   Ztraitlets.utils.textr   r   utilsr   Zutils.importstringr    r   rP   rQ   hasattrr!   rR   environr   Z_envvarlowerr#   r  
executableendswithr|   r9   r   r:   	Formatterr>   rM   r   Zdefault_aliasesr   Zdefault_flagsr@  rA  r;   r4  r4   r4   r4   r5   <module>   sh    0
      S

