o
    ®Ÿ?eà  ã                   @   sN   d Z ddlZddlZddlZddlmZ ddlmZ ejZ	G dd„ de
ƒZdS )zGConfigurations for TensorFlow Debugger (TFDBG) command-line interfaces.é    N)Údebugger_cli_common)Úgfilec                   @   s`   e Zd ZdZdZddgZddd„Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zddd„Zdd„ ZdS )Ú	CLIConfigz?Client-facing configurations for TFDBG command-line interfaces.z.tfdbg_config)Zgraph_recursion_depthé   )Z
mouse_modeTNc                 C   s^   |p|   ¡ | _t | j¡| _t | j¡r&|  ¡ }| 	¡ D ]	\}}|| j|< q|  
¡  i | _d S ©N)Ú_default_config_file_pathÚ_config_file_pathÚcollectionsÚOrderedDictÚ_DEFAULT_CONFIGÚ_configr   ZExistsÚ_load_from_fileÚitemsÚ_save_to_fileÚ_set_callbacks)ÚselfZconfig_file_pathÚconfigÚkeyÚvalue© r   úg/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/debug/cli/cli_config.pyÚ__init__$   s   ÿ
zCLIConfig.__init__c                 C   s    || j vrtd| ƒ‚| j | S )Nú %s is not a valid property name.)r   ÚKeyError)r   Úproperty_namer   r   r   Úget0   s   

zCLIConfig.getc                 C   sÚ   || j vrtd| ƒ‚| j | }t|tƒr7t|tƒr2| ¡ dv r#d}qS| ¡ dv r,d}qStd| ƒ‚t|ƒ}nt|tƒrAt|ƒ}nt|tƒrKt|ƒ}ntdt	|ƒ ƒ‚|| j |< |  
¡  || jv rk| j| | j ƒ dS dS )	aÔ  Set the value of a property.

    Supports limitd property value types: `bool`, `int` and `str`.

    Args:
      property_name: Name of the property.
      property_val: Value of the property. If the property has `bool` type and
        this argument has `str` type, the `str` value will be parsed as a `bool`

    Raises:
      ValueError: if a `str` property_value fails to be parsed as a `bool`.
      KeyError: if `property_name` is an invalid property name.
    r   )Ú1ÚtrueÚtÚyesÚyÚonT)Ú0ÚfalseÚfÚnoÚnÚoffFz&Invalid string value for bool type: %szUnsupported property type: %sN)r   r   Ú
isinstanceÚboolÚstrÚlowerÚ
ValueErrorÚintÚ	TypeErrorÚtyper   r   )r   r   Zproperty_valZorig_valr   r   r   Úset5   s.   



ÿ






ÿzCLIConfig.setc                 C   s4   || j vrtd| ƒ‚t|ƒstdƒ‚|| j|< dS )aØ  Set a set-callback for given property.

    Args:
      property_name: Name of the property.
      callback: The callback as a `callable` of signature:
          def cbk(config):
        where config is the config after it is set to the new value.
        The callback is invoked each time the set() method is called with the
        matching property_name.

    Raises:
      KeyError: If property_name does not exist.
      TypeError: If `callback` is not callable.
    r   z-The callback object provided is not callable.N)r   r   Úcallabler.   r   )r   r   Úcallbackr   r   r   Úset_callback_   s
   
zCLIConfig.set_callbackc                 C   s   t j t j d¡| j¡S )Nú~)ÚosÚpathÚjoinÚ
expanduserÚ_CONFIG_FILE_NAME)r   r   r   r   r   t   s   z#CLIConfig._default_config_file_pathc                 C   s\   z#t  | jd¡}t | j|¡ W d   ƒ W d S 1 sw   Y  W d S  ty-   Y d S w )NÚw)r   ÚOpenr   ÚjsonÚdumpr   ÚIOError)r   Úconfig_filer   r   r   r   w   s   &ÿÿzCLIConfig._save_to_filec                 C   s„   t ddƒt dƒg}| j ¡ D ].\}}||krdnd}t dƒ}|t |d|gƒ7 }|t dƒ7 }|t t|ƒ|d7 }| |¡ qt |¡S )	zœGet a text summary of the config.

    Args:
      highlight: A property name to highlight in the output.

    Returns:
      A `RichTextLines` output.
    zCommand-line configuration:ÚboldÚ Nz  Ú	underlinez: )Z	font_attr)ÚRLr   r   r*   Úappendr   Z#rich_text_lines_from_rich_line_list)r   Ú	highlightÚlinesÚnameÚvalZhighlight_attrÚliner   r   r   Ú	summarize~   s   	
zCLIConfig.summarizec              	   C   sˆ   z5t  | jd¡#}t |¡}t ¡ }t| ¡ ƒD ]}|| ||< q|W  d   ƒ W S 1 s.w   Y  W d S  t	t
fyC   tƒ  Y S w )NÚr)r   r;   r   r<   Úloadr	   r
   ÚsortedÚkeysr>   r,   Údict)r   r?   Zconfig_dictr   r   r   r   r   r   ‘   s   
(û
ýzCLIConfig._load_from_filer   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   r   r   r   r0   r3   r   r   rJ   r   r   r   r   r   r      s    þ
*
r   )rS   r	   r<   r5   Ztensorflow.python.debug.clir   Ztensorflow.python.platformr   ZRichLinerC   Úobjectr   r   r   r   r   Ú<module>   s   