L i+ZdZddlmZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZmZej"eZgdZGddeZGd d eZGd d eZGd deZGddeZeddGddZGdde ZeZGdde Zy)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) AnyCallableClassVarDictIterableMappingMutableMappingOptionalSetUnion)AbstractConfigConfigAlreadyRegisteredError ConfigErrorConfigUnknownOptionErrorConfigValueParsingErrorConfigValueValidationErrorOptionOptionsceZdZdZy)rz%Base exception for the config module.N)__name__ __module__ __qualname____doc__`/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/misc/configTools.pyrr,s/rrc"eZdZdZfdZxZS)rzRaised 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|d|dy)NConfig option z is already registered.)super__init__)selfname __class__s rr#z%ConfigAlreadyRegisteredError.__init__8s >$/FGHrrrrrr# __classcell__r&s@rrr0sIIrrc"eZdZdZfdZxZS)rz3Raised when a configuration value cannot be parsed.cDt|d|dt|dy)Nr!z : value cannot be parsed (given )r"r#reprr$r%valuer&s rr#z ConfigValueParsingError.__init__?s' TF"B4;-q Q rr'r)s@rrr<s=  rrc"eZdZdZfdZxZS)rz6Raised when a configuration value cannot be validated.cDt|d|dt|dy)Nr!z: value is invalid (given r,r-r/s rr#z#ConfigValueValidationError.__init__Hs' TF"r!z is unknown) isinstancerr%idr"r#)r$option_or_namer%r&s rr#z!ConfigUnknownOptionError.__init__QsZ.&1##$F2n+=*>b A^$A& >${;0nofalseF>1yestrueT>autononezinvalid optional bool: {v!r})r<lower ValueError)vss rparse_optional_boolzOption.parse_optional_boolhsA FLLN $ $ $ $  788rc.|duxst|tSN)r6bool)rNs rvalidate_optional_boolzOption.validate_optional_boolssDy/Jq$//r)rNr<returnzOptional[bool])rNrrUrS)rrr__annotations__rB staticmethodrPrTrrrrr[sW IM I$ L( Q04H-4@9900rrcxeZdZUdZded<d ddZ d ddZddZddZdd Z dd Z dd Z dd Z y)rzRegistry of available options for a given config system. Define new options using the :meth:`register()` method. Access existing options using the Mapping interface. zDict[str, Option]_Options__optionsNcdi|_|'|jD]}|j|yyrR)rYvaluesregister_option)r$otheroptions rr#zOptions.__init__s7  ,,. -$$V, - rc >|jt|||||S)z!Create and register a new option.)r\r)r$r%r=r>r@rBs rregisterzOptions.registers"##F4wx$PQQrcn|j}||jvr t|||j|<|S)zRegister a new option.)r%rYr)r$r^r%s rr\zOptions.register_options5{{ 4>> !.t4 4%t rcP|jj|j|uS)z).0krNs r z#Options.__repr__..s0Aqqe,QYYMCs "z}))r&rjoinrYitemsrjs r__repr__zOptions.__repr__sQ~~&&'u -gg NN002     rrR)r]z 'Options'rUNone r%r<r=r<r>rr@r?rBrArUr)r^rrUr)r^rrUrS)rgr<rUr)rUz Iterator[str]rUintrUr<) rrrrrVr#r`r\rdrfrirlrurrrrrxs}! -59 R R R R $ R 2 R  R9/)( rrceZdZUdZded<e d ddZded<iddf dd Zdd Z d dd Z e f dd Z d Z ddZ ddZddZddZddZd dZy)!ra 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}) zClassVar[Options]optionsNcB|jj|||||S)z3Register an available option in this config system.)r=r>r@rB)r|r`)clsr%r=r>r@rBs rr\zAbstractConfig.register_options+{{## tWEH$  rzDict[str, Any]_valuesFci|_t|tr |jn|}|jD]\}}|j ||||yrR)rr6rrtset)r$r[ parse_values skip_unknown values_dictr%r0s rr#zAbstractConfig.__init__sN  (26>(JfnnPV &,,. >KD% HHT5, = >rc2t|tr*|}|jj|s t ||St|t r|} |j|Stdt|jd|#t $r t |wxYw)Nzexpected Option or str, found z: ) r6rr|rdrr<KeyError TypeErrortyper)r$r8r^r%s r_resolve_optionzAbstractConfig._resolve_options nf -#F<<--f5.v66M  ,!D 5||D))0'001N3EG  5.t44 5s BBc |j|}|r |j |}|j'|j|st|j|||j|j<y#t$r+}|r#tjt |Yd}~yd}~wwxYw#t $r}t|j||d}~wwxYw)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) rrlogdebugr<r@ Exceptionrr%rBrr)r$r8r0rrr^es rrzAbstractConfig.sets, )).9F  I U+ ?? &vu/E,V[[%@ @$) V[[!#(  #a&!    I-fkk5AqH Is4A4B+4 B(= B#"B##B(+ C4C  Cc|j|}|j|jvr|j|jS|tur|S|jS)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. )rr%r_USE_GLOBAL_DEFAULTr>)r$r8r>r^s rrczAbstractConfig.get)sO2%%n5 ;;$,, &<< , , - -N~~rc8|j|jSrR)r&rrjs rcopyzAbstractConfig.copyIs~~dll++rc$|j|SrR)rc)r$r8s rrfzAbstractConfig.__getitem__Lsxx''rc&|j||SrR)r)r$r8r0s r __setitem__zAbstractConfig.__setitem__Osxx..rcT|j|}|j|j=yrR)rrr%)r$r8r^s r __delitem__zAbstractConfig.__delitem__Rs"%%n5 LL %rc6|jjSrR)rrirjs rrizAbstractConfig.__iter__Vs||$$&&rc,t|jSrR)lenrrjs rrlzAbstractConfig.__len__Ys4<<  rc`|jjdt|jdS)N(r,)r&rr.rrjs rruzAbstractConfig.__repr__\s*..))*!D,>+?qAArrRrw)r[z4Union[AbstractConfig, Dict[Union[Option, str], Any]]rrSrrS)r8Union[Option, str]rUr)FF)r8rr0rrrSrrS)r8rr>rrUr)r8rrUr)r8rr0rrUrv)r8rrUrv)rUz Iterable[str]rxrz)rrrrrV classmethodr\r#rrrrcrrfrrrirlrurrrrrs059        $  2       HJ"" >D > > >,#" )**)*)* )*  )*XBU0;> @,(/&'!Brr) r __future__rlogging dataclassesrtypingrrrrr r r r r r getLoggerrr__all__rrrrrrrrobjectrrrrrrs #!   g! 0)0 I; I k    ={ = $5!00"088 g8 vhgB^gBr