
    h+                    T   S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJrJrJrJrJr  \R"                  " \5      r/ SQr " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r\" SSS9 " S S5      5       r " S S\5      r\" 5       r " S S\5      rg)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                      \ rS rSrSrSrg)r   ,   z%Base exception for the config module. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       L/var/www/html/env/lib/python3.13/site-packages/fontTools/misc/configTools.pyr   r   ,   s    /r    r   c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   0   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                ,   > [         TU ]  SU S35        g )NConfig option z is already registered.)super__init__)selfname	__class__s     r!   r'   %ConfigAlreadyRegisteredError.__init__8   s    >$/FGHr    r   r   r   r   r   r   r'   r   __classcell__r*   s   @r!   r   r   0   s    I Ir    r   c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   <   z3Raised when a configuration value cannot be parsed.c                D   > [         TU ]  SU S[        U5       S35        g )Nr%   z : value cannot be parsed (given )r&   r'   reprr(   r)   valuer*   s      r!   r'    ConfigValueParsingError.__init__?   s'    TF"B4;-qQ	
r    r   r,   r.   s   @r!   r   r   <   s    =
 
r    r   c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   E   z6Raised when a configuration value cannot be validated.c                D   > [         TU ]  SU S[        U5       S35        g )Nr%   z: value is invalid (given r2   r3   r5   s      r!   r'   #ConfigValueValidationError.__init__H   s'    TF"<T%[MK	
r    r   r,   r.   s   @r!   r   r   E   s    @
 
r    r   c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   N   z.Raised when a configuration option is unknown.c                   > [        U[        5      (       a  SUR                   S[        U5       S3OSU S3n[        TU ]  SU S35        g )N'z' (id=z)>r%   z is unknown)
isinstancer   r)   idr&   r'   )r(   option_or_namer)   r*   s      r!   r'   !ConfigUnknownOptionError.__init__Q   s]     .&11 ##$F2n+=*>bA^$A& 	
 	>${;<r    r   r,   r.   s   @r!   r   r   N   s    8= =r    r   TF)frozeneqc                  ~    \ rS rSr% S\S'    S\S'    S\S'    S\S'    S	rS
\S'    \SS j5       r\SS j5       rSr	g	)r   [   strr)   helpr   defaultCallable[[str], Any]parseNOptional[Callable[[Any], bool]]validatec                t    [        U 5      R                  5       nUS;   a  gUS;   a  gUS;   a  g [        S5      e)N>   0nofalseF>   1yestrueT>   autononezinvalid optional bool: {v!r})rH   lower
ValueError)vss     r!   parse_optional_boolOption.parse_optional_boolh   sA    FLLN$$$$  788r    c                8    U S L =(       d    [        U [        5      $ N)r@   bool)rZ   s    r!   validate_optional_boolOption.validate_optional_bools   s    Dy/Jq$//r    r   )rZ   rH   returnzOptional[bool])rZ   r   rc   r`   )
r   r   r   r   __annotations__rN   staticmethodr\   ra   r   r   r    r!   r   r   [   sW    
IM
I$L(Q04H-4@9 9 0 0r    r   c                      \ rS rSr% SrS\S'   SSS jjr S           SS jjrSS jrSS	 jr	SS
 jr
SS jrSS jrSS jrSrg)r   x   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__optionsNc                j    0 U l         Ub)  UR                  5        H  nU R                  U5        M     g g r_   )rh   valuesregister_option)r(   otheroptions      r!   r'   Options.__init__   s2    ,,.$$V, ) r    c           	     :    U R                  [        XX4U5      5      $ )z!Create and register a new option.)rk   r   )r(   r)   rI   rJ   rL   rN   s         r!   registerOptions.register   s     ##F4wx$PQQr    c                n    UR                   nX R                  ;   a  [        U5      eXR                  U'   U$ )zRegister a new option.)r)   rh   r   )r(   rm   r)   s      r!   rk   Options.register_option   s1    {{>>!.t44%tr    c                P    U R                   R                  UR                  5      UL $ )z<Return True if the same option object is already registered.)rh   getr)   )r(   rm   s     r!   is_registeredOptions.is_registered   s     ~~!!&++.&88r    c                8    U R                   R                  U5      $ r_   )rh   __getitem__)r(   keys     r!   ry   Options.__getitem__   s    ~~))#..r    c                6    U R                   R                  5       $ r_   )rh   __iter__r(   s    r!   r}   Options.__iter__   s    ~~&&((r    c                6    U R                   R                  5       $ r_   )rh   __len__r~   s    r!   r   Options.__len__   s    ~~%%''r    c                    U R                   R                   S3SR                  S U R                  R	                  5        5       5      -   S-   $ )Nz({
 c              3  P   #    U  H  u  pS U< SUR                   < S3v   M     g7f)z    z: Option(default=z, ...),
N)rJ   ).0krZ   s      r!   	<genexpr>#Options.__repr__.<locals>.<genexpr>   s-      2DA qe,QYYMC2s   $&z}))r*   r   joinrh   itemsr~   s    r!   __repr__Options.__repr__   sQ    ~~&&'u-gg  NN002 
 	
r    )	__optionsr_   )rl   z	'Options'rc   Noner)   rH   rI   rH   rJ   r   rL   rK   rN   rM   rc   r   )rm   r   rc   r   )rm   r   rc   r`   )rz   rH   rc   r   )rc   zIterator[str]rc   intrc   rH   )r   r   r   r   r   rd   r'   rp   rk   rv   ry   r}   r   r   r   r   r    r!   r   r   x   s}     ! - 59	R	R 	R 		R
 $	R 2	R 
	R9/)(
r    r   c                     \ rS rSr% SrS\S'   \ S           SS jj5       rS\S'   0 S	S	4     SS
 jjrSS jr	  S       SS jjr
\4     SS jjrS rSS jrSS jrSS jrS S jrS!S jrS"S jrSrg)#r      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]optionsNc                8    U R                   R                  XX4US9$ )z3Register an available option in this config system.)rI   rJ   rL   rN   )r   rp   )clsr)   rI   rJ   rL   rN   s         r!   rk   AbstractConfig.register_option   s'     {{##WH $ 
 	
r    zDict[str, Any]_valuesFc                    0 U l         [        U[        5      (       a  UR                   OUnUR                  5        H  u  pVU R	                  XVX#5        M     g r_   )r   r@   r   r   set)r(   rj   parse_valuesskip_unknownvalues_dictr)   r6   s          r!   r'   AbstractConfig.__init__   sF     (26>(J(JfnnPV&,,.KDHHT,= /r    c                T   [        U[        5      (       a/  UnU R                  R                  U5      (       d  [	        U5      eU$ [        U[
        5      (       a  Un U R                  U   $ [        S[        U5      R                   SU< 35      e! [         a    [	        U5      ef = f)Nzexpected Option or str, found z: )
r@   r   r   rv   r   rH   KeyError	TypeErrortyper   )r(   rB   rm   r)   s       r!   _resolve_optionAbstractConfig._resolve_option   s    nf--#F<<--f55.v66M,,!D5||D)) 0'001N3EG   5.t445s   B B'c                    U R                  U5      nU(       a   UR                  U5      nUR                  b,  UR                  U5      (       d  [        UR                  U5      eX R                  UR                  '   g! [         a0  nU(       a#  [        R                  [	        U5      5         SnAge SnAff = f! [         a  n[        UR                  U5      UeSnAff = f)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)r   r   logdebugrH   rL   	Exceptionr   r)   rN   r   r   )r(   rB   r6   r   r   rm   es          r!   r   AbstractConfig.set   s    ,	)).9F IU+ ??&vu/E/E,V[[%@@$)V[[!# ( 			#a&!		  I-fkk5AqHIs4   A> B; >
B8%B32B33B8;
C!CC!c                    U R                  U5      nUR                  U R                  ;   a  U R                  UR                     $ U[        La  U$ UR                  $ )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.
)r   r)   r   _USE_GLOBAL_DEFAULTrJ   )r(   rB   rJ   rm   s       r!   ru   AbstractConfig.get)  sO    2 %%n5;;$,,&<<,,--N~~r    c                8    U R                  U R                  5      $ r_   )r*   r   r~   s    r!   copyAbstractConfig.copyI  s    ~~dll++r    c                $    U R                  U5      $ r_   )ru   )r(   rB   s     r!   ry   AbstractConfig.__getitem__L  s    xx''r    c                $    U R                  X5      $ r_   )r   )r(   rB   r6   s      r!   __setitem__AbstractConfig.__setitem__O  s    xx..r    c                T    U R                  U5      nU R                  UR                  	 g r_   )r   r   r)   )r(   rB   rm   s      r!   __delitem__AbstractConfig.__delitem__R  s"    %%n5LL%r    c                6    U R                   R                  5       $ r_   )r   r}   r~   s    r!   r}   AbstractConfig.__iter__V  s    ||$$&&r    c                ,    [        U R                  5      $ r_   )lenr   r~   s    r!   r   AbstractConfig.__len__Y  s    4<<  r    c                `    U R                   R                   S[        U R                  5       S3$ )N(r2   )r*   r   r4   r   r~   s    r!   r   AbstractConfig.__repr__\  s*    ..))*!D,>+?qAAr    )r   r_   r   )rj   z4Union[AbstractConfig, Dict[Union[Option, str], Any]]r   r`   r   r`   )rB   Union[Option, str]rc   r   )FF)rB   r   r6   r   r   r`   r   r`   )rB   r   rJ   r   rc   r   )rB   r   rc   r   )rB   r   r6   r   rc   r   )rB   r   rc   r   )rc   zIterable[str]r   r   )r   r   r   r   r   rd   classmethodrk   r'   r   r   r   ru   r   ry   r   r   r}   r   r   r   r   r    r!   r   r      s   0  59

 
 	

 $
 2
 

 
  HJ""		>D	> 	> 		>, #")**)* )* 	)*
 )*X BU0;>	@,(/&'!Br    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!   <module>r      s   	 #  !   !	0) 0	I; 	I
k 

 
	={ 	= $5!0 0 "088
g 8
v h gB^ gBr    