)Ej<-dZddlmZddlZddlmZddlmZmZm Z m Z m Z m Z m Z mZmZmZejeZgdZGddeZGd d eZGd d eZGd deZGddeZeddGddZGdde ZeZGdde ZdS)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 ConfigErrorConfigUnknownOptionErrorConfigValueParsingErrorConfigValueValidationErrorOptionOptionsceZdZdZdS)rz%Base exception for the config module.N)__name__ __module__ __qualname____doc__LC:\PYTHON\MyICR_Suite\python\Lib\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. cRtd|ddS)NConfig option z is already registered.)super__init__)selfname __class__s rr#z%ConfigAlreadyRegisteredError.__init__8s- G$GGGHHHHHrrrrrr# __classcell__r&s@rrr0sKIIIIIIIIIrrc"eZdZdZfdZxZS)rz3Raised when a configuration value cannot be parsed.crtd|dt|ddS)Nr!z : value cannot be parsed (given )r"r#reprr$r%valuer&s rr#z ConfigValueParsingError.__init__?sE  QT Q Q4;; Q Q Q     rr'r)s@rrr<s>==         rrc"eZdZdZfdZxZS)rz6Raised when a configuration value cannot be validated.crtd|dt|ddS)Nr!z: value is invalid (given r,r-r/s rr#z#ConfigValueValidationError.__init__HsE  KT K KT%[[ K K K     rr'r)s@rrrEs>@@         rrc"eZdZdZfdZxZS)rz.Raised when a configuration option is unknown.ct|trd|jdt|dnd|d}t d|ddS)N'z' (id=z)>r!z is unknown) isinstancerr%idr"r#)r$option_or_namer%r&s rr#z!ConfigUnknownOptionError.__init__Qsz.&11 ' A# A A2n+=+= A A A A&^&&& ;$;;;<<<<88=========rrTF)frozeneqceZdZUded< ded< ded< ded< dZd ed < eddZeddZdS)rstrr%helprdefaultCallable[[str], Any]parseNOptional[Callable[[Any], bool]]validatevreturnOptional[bool]ct|}|dvrdS|dvrdS|dvrdStd)N>0nofalseF>1yestrueT>autononezinvalid optional bool: {v!r})r<lower ValueError)rCss rparse_optional_boolzOption.parse_optional_boolhsW FFLLNN $ $ $5 $ $ $4  47888rboolc4|dupt|tSN)r6rS)rCs rvalidate_optional_boolzOption.validate_optional_boolssDy/Jq$///r)rCr<rDrE)rCrrDrS)rrr__annotations__rB staticmethodrRrVrrrrr[s IIIM III$LLL(Q04H4444@999\9000\000rrcdeZdZUdZded<d d!d Z d d"dZd#dZd$dZd%dZ d&dZ d'dZ d(dZ dS))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__optionsNother 'Options'rDNonecti|_|,|D]}||dSdSrU)rZvaluesregister_option)r$r[options rr#zOptions.__init__sO  ,,.. - -$$V,,,,   - -rr%r<r=r>rr@r?rBrArc N|t|||||S)z!Create and register a new option.)r`r)r$r%r=r>r@rBs rregisterzOptions.registers(##F4wx$P$PQQQrracX|j}||jvrt|||j|<|S)zRegister a new option.)r%rZr)r$rar%s rr`zOptions.register_options5{ 4> ! !.t44 4%t rrScD|j|j|uS)z).0krCs r z#Options.__repr__..sPAqDqCCQYCCCrz}))r&rjoinrZitemsrns r__repr__zOptions.__repr__sb~& - - -gg N0022     rrU)r[r\rDr] r%r<r=r<r>rr@r?rBrArDr)rarrDr)rarrDrS)rhr<rDr)rDrkrDrorDr<) rrrrrWr#rcr`rgrjrmrqrzrrrrrxs!   -----59 R R R R R9999////))))((((      rrceZdZUdZded<e d*d+dZded<iddfd,dZd-dZ d.d/dZ e fd0dZ d Z d1d!Z d2d#Zd3d$Zd4d&Zd5d(Zd6d)ZdS)7ra 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]optionsNr%r<r=r>rr@r?rBrArDrc@|j|||||S)z3Register an available option in this config system.)r=r>r@rB)rrc)clsr%r=r>r@rBs rr`zAbstractConfig.register_options.{## tWEH$   rzDict[str, Any]_valuesFr_GUnion[AbstractConfig, Dict[Union[Option, str], Any], Mapping[str, Any]] parse_valuesrS skip_unknownci|_t|tr|jn|}|D]\}}|||||dSrU)rr6rryset)r$r_rr values_dictr%r0s rr#zAbstractConfig.__init__sj (26>(J(JVfnnPV &,,.. > >KD% HHT5, = = = = > >rr8Union[Option, str]cXt|tr-|}|j|st ||St|t r-|} |j|S#t $rt |wxYwtdt|j d|)Nzexpected Option or str, found z: ) r6rrrgrr<KeyError TypeErrortyper)r$r8rar%s r_resolve_optionzAbstractConfig._resolve_options nf - - #F<--f55 7.v666M  , , !D 5|D)) 5 5 5.t444 5G''0GG4BGG s  A((Br0c ||}nB#t$r5}|r-tt |Yd}~dSd}~wwxYw|r? ||}n(#t $r}t|j||d}~wwxYw|j *| |st|j|||j |j<dS)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$r8r0rrraes rrzAbstractConfig.sets, )).99FF'     #a&&!!!     I I U++ I I I-fk5AAqH I ? &vu/E/E &,V[%@@ @$) V[!!!s2 A)AAAA33 B=BBc||}|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>ras rrfzAbstractConfig.get+sN2%%n55 ;$, & &< , , - - -N~rc6||jSrU)r&rrns rcopyzAbstractConfig.copyKs~~dl+++rc,||SrU)rf)r$r8s rrjzAbstractConfig.__getitem__Nsxx'''rr]c.|||SrU)r)r$r8r0s r __setitem__zAbstractConfig.__setitem__Qsxx...rcJ||}|j|j=dSrU)rrr%)r$r8ras r __delitem__zAbstractConfig.__delitem__Ts'%%n55 L % % %r Iterable[str]c4|jSrU)rrmrns rrmzAbstractConfig.__iter__Xs|$$&&&rroc*t|jSrU)lenrrns rrqzAbstractConfig.__len__[s4<   rcJ|jjdt|jdS)N(r,)r&rr.rrns rrzzAbstractConfig.__repr__^s(.)AAD,>,>AAAArrUr{)r_rrrSrrS)r8rrDr)FF)r8rr0rrrSrrS)r8rr>rrDr)r8rrDr)r8rr0rrDr])r8rrDr])rDrr|r})rrrrrW classmethodr`r#rrrrfrrjrrrmrqrzrrrrrsl059     [   "" > > > > >,#" )*)*)*)*)*XBU@,,,((((////&&&&''''!!!!BBBBBBrr) r __future__rlogging dataclassesrtypingrrrrr r r r r r getLoggerrr__all__rrrrrrrrobjectrrrrrrsz  #"""""!!!!!!                        g!!   00000)000 I I I I I; I I I     k            = = = = ={ = = = $5!!!0000000"!088 8 8 8 8 g8 8 8 vfhhiBiBiBiBiB^iBiBiBiBiBr