__init__(self,
env='
' ,
ckeysep=' - ' ,
strictkey=False,
dkeytf=None,
dkeyitf=None,
pkeytf=None,
pkeyitf=None,
pvaltf=None,
ksyntf=None,
envtf=None)
(Constructor)
|
|
Constructor of syntagma derivators.
The default resolution of derivation key conflicts, as described in
module documentation, can be changed to strict resolution through
strictkey parameter. If strictkey is
True , all key syntagmas must be unique.
Parameter env is used to specify the environment from
which the derivations are taken. In case no non-default environments have
been used in derivations, env is simply empty string.
Otherwise, it can be:
-
a string specifying a non-default environment
-
a tuple specifying an environment fallback chain
-
a tuple of tuples, specifying more than one environment chain
(Lists can also be used instead of tuples.)
If several environment fallback chains are given, when a property is
requrested they are tried in the order of specification, and the first
yielded property is returned. It is also possible to combine properties
from different environment chains in a custom way, by supplying a
property value transformation function (pvaltf
parameter).
Compound keys, for single-key lookups, are built by joining the
derivation and property keys with a separator. This separator can be
chosen through ckeysep parameter. The separator string can
be contained inside a derivation key, but it must not be found inside any
property key (the compound key is split from the back).
A myriad of transformation functions can be applied by
derivator object to imported derivations, through *tf
parameters. They are as follows (stating only default inputs, see below
for more possibilities):
-
dkeytf : applied to derivation key supplied on lookups
(e.g. in get or get2
methods). Takes the derivation key as parameter, returns either the
derivation key or a tuple of the derivation key and another object.
-
dkeyitf : applied to all derivation keys on import. Same
default input-output as dkey .
-
pkeytf : like dkeytf , only working
analogously on property key instead of derivation key.
-
pkeyitf : like dkeyitf , only working
analogously on property key instead of derivation key.
-
pvaltf : applied to tagged segments of property values.
The input to this function is a list of lists by each environment
fallback chain; list for one environemnt chain consists of 2-tuples,
each tuple having a list of tags as the first element, and a text
segment as the second element. For example, if there is only one
environment chain (e.g. evn="" or
env=("someenv", "") , and the
property value is derived to be foo ~tag bar in this
environment, then the argument to the function will be [[([''],
"foo "), (['tag'], " bar")]] . If an
environemnt chain yielded no property value, its element will be
None instead of list of 2-tuples. The return value is
the final property value string. Note that simplification will not be
applied to this value afterwards, so if desired, simplify() should be manually called inside the
function.
-
ksyntf : quite similar to pvaltf , only
applied to tagged segments of key syntagmas. The difference is that
there are no multiple environments for key syntagmas, so the input
value is just one list of tagged text segments (what would be the
first element of input list to pvaltf ).
-
envtf : applied to environment fallback chain on lookups.
Takes original environment chain as argument, returns new environment
chain (in one of the forms acceptable as env parameter).
Transformation functions can take more input arguments than the
default described above, on demand. If transformation function is
supplied directly, e.g. pvaltf=somefunc , it is sent default
inputs. Extra inputs are requested by supplying instead a tuple, where
the first element is the transformation function, and the following
elements are predefined keywords of available extra inputs, e.g.
pvalf=(somefunc, "dkey", "pkrest") .
Available extra inputs by transformation function are:
-
dkeytf : "self" the derivation
object.
-
pkeytf : "self" ,
"dkey" the derivation key (original or that
returned by dkeytf ), "dkrest" the
second object returned by dkeytf .
-
pvaltf : "self" ,
"dkey" , "pkey" the
property key (original or that returned by pkeytf ),
"env" the tuple of environment chains,
"dkrest" , "pkrest" the
second object returned by pkeytf .
-
ksyntf : "self" ,
"dkey" , "dkrest" .
-
envtf : "self" ,
"dkey" , "dkrest" .
- Parameters:
env (string, (string*), ((string*)*)) - environment for derivations
ckeysep (string) - derivation-property key separator in compound keys
strictkey - whether all key syntagmas must be unique to avoid conflicts
dkeytf - transformation function for lookup derivation keys
dkeyitf - transformation function for imported derivation keys
pkeytf - transformation function for lookup property keys
pkeyitf - transformation function for imported property keys
pvaltf - transformation fucntion for property values
ksyntf - transformation fucntion for key syntagamas
- Overrides:
object.__init__
|