o
    h+                     @  s   d Z ddlmZ ddlZddl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 eeZg dZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZedddG dd dZG dd deZe ZG dd deZdS )a`  
Code of the config system; not related to fontTools or fonts in particular.

The options that are specific to fontTools are in :mod:`fontTools.config`.

To create your own config system, you need to create an instance of
:class:`Options`, and a subclass of :class:`AbstractConfig` with its
``options`` class variable set to your instance of Options.

    )annotationsN)	dataclass)
AnyCallableClassVarDictIterableMappingMutableMappingOptionalSetUnion)AbstractConfigConfigAlreadyRegisteredErrorConfigErrorConfigUnknownOptionErrorConfigValueParsingErrorConfigValueValidationErrorOptionOptionsc                   @  s   e Zd ZdZdS )r   z%Base exception for the config module.N)__name__
__module____qualname____doc__ r   r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fontTools/misc/configTools.pyr   ,   s    r   c                          e Zd ZdZ fddZ  ZS )r   zRaised when a module tries to register a configuration option that
    already exists.

    Should not be raised too much really, only when developing new fontTools
    modules.
    c                   s   t  d| d d S )NConfig option z is already registered.)super__init__)selfname	__class__r   r   r   8   s   z%ConfigAlreadyRegisteredError.__init__r   r   r   r   r   __classcell__r   r   r"   r   r   0   s    r   c                      r   )r   z3Raised when a configuration value cannot be parsed.c                   "   t  d| dt| d d S )Nr   z : value cannot be parsed (given )r   r   reprr    r!   valuer"   r   r   r   ?      z ConfigValueParsingError.__init__r$   r   r   r"   r   r   <       r   c                      r   )r   z6Raised when a configuration value cannot be validated.c                   r&   )Nr   z: value is invalid (given r'   r(   r*   r"   r   r   r   H   r,   z#ConfigValueValidationError.__init__r$   r   r   r"   r   r   E   r-   r   c                      r   )r   z.Raised when a configuration option is unknown.c                   sF   t |trd|j dt| dnd| d}t d| d d S )N'z' (id=z)>r   z is unknown)
isinstancer   r!   idr   r   )r    option_or_namer!   r"   r   r   r   Q   s
   
z!ConfigUnknownOptionError.__init__r$   r   r   r"   r   r   N   r-   r   TF)frozeneqc                   @  s`   e Zd ZU ded< 	 ded< 	 ded< 	 ded< 	 dZd	ed
< 	 edddZedddZdS )r   strr!   helpr   defaultCallable[[str], Any]parseNOptional[Callable[[Any], bool]]validatevreturnOptional[bool]c                 C  s8   t |  }|dv rdS |dv rdS |dv rd S td)N>   0nofalseF>   1yestrueT>   autononezinvalid optional bool: {v!r})r4   lower
ValueError)r;   sr   r   r   parse_optional_boolh   s   zOption.parse_optional_boolboolc                 C  s   | d u pt | tS N)r/   rJ   )r;   r   r   r   validate_optional_bools      zOption.validate_optional_bool)r;   r4   r<   r=   )r;   r   r<   rJ   )r   r   r   __annotations__r:   staticmethodrI   rL   r   r   r   r   r   [   s   
 
r   c                   @  sp   e Zd ZU dZded< d(d)d	d
Z	d(d*ddZd+ddZd,ddZd-ddZ	d.d!d"Z
d/d$d%Zd0d&d'ZdS )1r   zRegistry of available options for a given config system.

    Define new options using the :meth:`register()` method.

    Access existing options using the Mapping interface.
    zDict[str, Option]_Options__optionsNother	'Options'r<   Nonec                 C  s.   i | _ |d ur| D ]	}| | qd S d S rK   )rP   valuesregister_option)r    rQ   optionr   r   r   r      s   zOptions.__init__r!   r4   r5   r6   r   r8   r7   r:   r9   r   c                 C  s   |  t|||||S )z!Create and register a new option.)rU   r   )r    r!   r5   r6   r8   r:   r   r   r   register   s   	zOptions.registerrV   c                 C  s&   |j }|| jv rt||| j|< |S )zRegister a new option.)r!   rP   r   )r    rV   r!   r   r   r   rU      s
   

zOptions.register_optionrJ   c                 C  s   | j |j|u S )z<Return True if the same option object is already registered.)rP   getr!   )r    rV   r   r   r   is_registered   rM   zOptions.is_registeredkeyc                 C  s   | j |S rK   )rP   __getitem__)r    rZ   r   r   r   r[         zOptions.__getitem__Iterator[str]c                 C  
   | j  S rK   )rP   __iter__r    r   r   r   r_         
zOptions.__iter__intc                 C  r^   rK   )rP   __len__r`   r   r   r   rc      ra   zOptions.__len__c                 C  s,   | j j dddd | j D  d S )Nz({
 c                 s  s(    | ]\}}d |d|j dV  qdS )z    z: Option(default=z, ...),
N)r6   ).0kr;   r   r   r   	<genexpr>   s
    
z#Options.__repr__.<locals>.<genexpr>z}))r#   r   joinrP   itemsr`   r   r   r   __repr__   s   
zOptions.__repr__rK   )rQ   rR   r<   rS   r!   r4   r5   r4   r6   r   r8   r7   r:   r9   r<   r   )rV   r   r<   r   )rV   r   r<   rJ   )rZ   r4   r<   r   )r<   r]   r<   rb   r<   r4   )r   r   r   r   rN   r   rW   rU   rY   r[   r_   rc   rj   r   r   r   r   r   x   s   
 




r   c                   @  s   e Zd ZU dZded< e	d6d7ddZded< i ddfd8ddZd9ddZ		d:d;d!d"Z	e
fd<d#d$Zd%d& Zd=d'd(Zd>d*d+Zd?d,d-Zd@d/d0ZdAd2d3ZdBd4d5ZdS )Cr   a  
    Create a set of config values, optionally pre-filled with values from
    the given dictionary or pre-existing config object.

    The class implements the MutableMapping protocol keyed by option name (`str`).
    For convenience its methods accept either Option or str as the key parameter.

    .. seealso:: :meth:`set()`

    This config class is abstract because it needs its ``options`` class
    var to be set to an instance of :class:`Options` before it can be
    instanciated and used.

    .. code:: python

        class MyConfig(AbstractConfig):
            options = Options()

        MyConfig.register_option( "test:option_name", "This is an option", 0, int, lambda v: isinstance(v, int))

        cfg = MyConfig({"test:option_name": 10})

    zClassVar[Options]optionsNr!   r4   r5   r6   r   r8   r7   r:   r9   r<   r   c                 C  s   | j j|||||dS )z3Register an available option in this config system.)r5   r6   r8   r:   )rn   rW   )clsr!   r5   r6   r8   r:   r   r   r   rU      s   

zAbstractConfig.register_optionzDict[str, Any]_valuesFrT   4Union[AbstractConfig, Dict[Union[Option, str], Any]]parse_valuesrJ   skip_unknownc                 C  s@   i | _ t|tr|j n|}| D ]\}}| |||| qd S rK   )rp   r/   r   ri   set)r    rT   rr   rs   values_dictr!   r+   r   r   r   r      s
   zAbstractConfig.__init__r1   Union[Option, str]c                 C  sr   t |tr|}| j|st||S t |tr,|}z| j| W S  ty+   t|w tdt|j	 d|)Nzexpected Option or str, found z: )
r/   r   rn   rY   r   r4   KeyError	TypeErrortyper   )r    r1   rV   r!   r   r   r   _resolve_option   s&   

zAbstractConfig._resolve_optionr+   c              
   C  s   z|  |}W n ty$ } z|rtt| W Y d}~dS  d}~ww |rBz||}W n tyA } zt|j||d}~ww |j	durR|	|sRt
|j||| j|j< dS )a_  Set the value of an option.

        Args:
            * `option_or_name`: an `Option` object or its name (`str`).
            * `value`: the value to be assigned to given option.
            * `parse_values`: parse the configuration value from a string into
                its proper type, as per its `Option` object. The default
                behavior is to raise `ConfigValueValidationError` when the value
                is not of the right type. Useful when reading options from a
                file type that doesn't support as many types as Python.
            * `skip_unknown`: skip unknown configuration options. The default
                behaviour is to raise `ConfigUnknownOptionError`. Useful when
                reading options from a configuration file that has extra entries
                (e.g. for a later version of fontTools)
        N)rz   r   logdebugr4   r8   	Exceptionr   r!   r:   r   rp   )r    r1   r+   rr   rs   rV   er   r   r   rt      s&   zAbstractConfig.setc                 C  s4   |  |}|j| jv r| j|j S |tur|S |jS )a  
        Get the value of an option. The value which is returned is the first
        provided among:

        1. a user-provided value in the options's ``self._values`` dict
        2. a caller-provided default value to this method call
        3. the global default for the option provided in ``fontTools.config``

        This is to provide the ability to migrate progressively from config
        options passed as arguments to fontTools APIs to config options read
        from the current TTFont, e.g.

        .. code:: python

            def fontToolsAPI(font, some_option):
                value = font.cfg.get("someLib.module:SOME_OPTION", some_option)
                # use value

        That way, the function will work the same for users of the API that
        still pass the option to the function call, but will favour the new
        config mechanism if the given font specifies a value for that option.
        )rz   r!   rp   _USE_GLOBAL_DEFAULTr6   )r    r1   r6   rV   r   r   r   rX   )  s   
zAbstractConfig.getc                 C  s   |  | jS rK   )r#   rp   r`   r   r   r   copyI  r\   zAbstractConfig.copyc                 C  s
   |  |S rK   )rX   )r    r1   r   r   r   r[   L  ra   zAbstractConfig.__getitem__rS   c                 C  s   |  ||S rK   )rt   )r    r1   r+   r   r   r   __setitem__O  r\   zAbstractConfig.__setitem__c                 C  s   |  |}| j|j= d S rK   )rz   rp   r!   )r    r1   rV   r   r   r   __delitem__R  s   
zAbstractConfig.__delitem__Iterable[str]c                 C  r^   rK   )rp   r_   r`   r   r   r   r_   V  ra   zAbstractConfig.__iter__rb   c                 C  s
   t | jS rK   )lenrp   r`   r   r   r   rc   Y  ra   zAbstractConfig.__len__c                 C  s   | j j dt| j dS )N(r'   )r#   r   r)   rp   r`   r   r   r   rj   \  s   zAbstractConfig.__repr__rK   rk   )rT   rq   rr   rJ   rs   rJ   )r1   rv   r<   r   )FF)r1   rv   r+   r   rr   rJ   rs   rJ   )r1   rv   r6   r   r<   r   )r1   rv   r<   r   )r1   rv   r+   r   r<   rS   )r1   rv   r<   rS   )r<   r   rl   rm   )r   r   r   r   rN   classmethodrU   r   rz   rt   r   rX   r   r[   r   r   r_   rc   rj   r   r   r   r   r      s0   
 
, 




r   ) r   
__future__r   loggingdataclassesr   typingr   r   r   r   r   r	   r
   r   r   r   	getLoggerr   r{   __all__r}   r   r   r   r   r   r   r   objectr   r   r   r   r   r   <module>   s"    0
		
;