mņ ›KX;c@s/dZdkZdkZdkZdkZdkZdkZdkZdkZ dk l Z dk Z dZ deifd„ƒYZeidƒZeied„Zdfd „ƒYZd efd „ƒYZd efd „ƒYZdefd„ƒYZdefd„ƒYZeieieed„Zeieieed„Zdefd„ƒYZeZeZ defd„ƒYZ!e!Z"e!Z#defd„ƒYZ$de!fd„ƒYZ%defd„ƒYZ&defd„ƒYZ'd efd!„ƒYZ(d"efd#„ƒYZ)d$e'fd%„ƒYZ*d&e&fd'„ƒYZ+d(e'fd)„ƒYZ,d*e&fd+„ƒYZ-d,e*fd-„ƒYZ.d.efd/„ƒYZ/d0e/fd1„ƒYZ0d2e0fd3„ƒYZ1d4efd5„ƒYZ2d6efd7„ƒYZ3d8efd9„ƒYZ4d:efd;„ƒYZ5d<efd=„ƒYZ6d>efd?„ƒYZ7d@efdA„ƒYZ8dBefdC„ƒYZ9dDe i fdE„ƒYZ:dFe:fdG„ƒYZ;eidHƒZ<eidIƒZ=dJfdK„ƒYZ>e?dLjoQdMe:fdN„ƒYZ@dOZAdkBZBeBiCeAƒZDe>e@ƒZEeEiFeDƒndS(Psė ConfigFile -- Interface to simple template based configuration files. The format of these files is as follows: globalvar = 2 [ABC] a = 1 b = abc.html c = text with spaces [DEF] a = 2 b = a + 3 c = a string Entries in square brackets indicate new subsections. Global variables may be set prior to starting any subsection. Emtpy lines and lines starting with '#' (comments) are ignored. Indentation is not necessary; lines can start at any column. Entries may span multiple lines by using '' continuations at the line ends, e.g. [Continuation] a = first line second line The lines are stripped of any white space before removing the trailing '' and concatenating them. Comment lines are removed as well. To parse these files, a template in form of a class including subclasses (identifying the subsections) must be given to the reader. This template defines which sections and attributes are known. All others are rejected. A sample template for the above looks like this: from mx.Misc.ConfigFile import * class Template(ConfigNamespace): global = IntegerEntry() class ABC(ConfigSection): a = IntegerEntry('0') b = StringEntry('default.html') c = StringEntry() class DEF(ConfigSection): a = IntegerEntry('0') b = EvalEntry('0') c = StringEntry('default value') The main class representing the global namespace of the ini file must have ConfigNamespace as baseclass. It may contain any number of ConfigSection subclasses each defining parsed attributes. The ini file may only contain entries defined in this template. In case an unkown section is found, the main class is looked up for a ConfigSection subclass with name 'DefaultSection'. This section object is then taken as template for a new section of the given name. The same feature is available for attributes in sections. In case a given attribute is not found in the templates, the section's 'DefaultAttribute' attribute is deepcopied and the used as attribute template. Needs mxTools to be installed. XXX Add support for long strings (including embedded control characters and spanning multiple lines) Copyright (c) 2000, Marc-Andre Lemburg; All Rights Reserved. See the documentation for further information on copyrights, or contact the author. All Rights Reserved. N(sfreezeitErrorcBstZRS(N(t__name__t __module__(((t=/data/zmath/lib/python2.4/site-packages/mx/Misc/ConfigFile.pyRYss"(?:\$([a-zA-Z0-9._]+)|\${([^}]*)})cCs|xu|i|ƒ} | pPn| iƒ}||dp|ddƒ}|d}|i |dƒ} | djo<|i |dƒ} | djotii |dƒ} q­nxH|dD]<}yt| |ƒ} Wqøtj otd|‚qøXqøW| iƒ\} } t| tƒo=| } | i tjo| i| i||ƒn| i } n|| t| ƒ|| }qW|S(sś Expands all variables of the form $var or ${var} using the dictionaries locals,globals,os.environ in that order as database. Default value is the empty string, just like for shell environment variables. iit.tsattribute "%s" undefinedN(t shell_vartsearchttexttmtgroupstgtsplittvarpathtvarnametlocalstgettNonetvaluetglobalstostenvirontattrtgetattrtAttributeErrorRtspantltrt isinstancetEntrytentrytNotGiventparsetdefaulttstr(RRRR RR RR RR RRRR((Rt expand_vars`s8       !RcBsbtZdZeZdZeeefZ ed„Z d„Z e i ed„Zd„Zd„ZRS(sŁ Converts the value to another datatype depending on the .converters attribute. Each of those functions is applied to the value. The first one to not raise an exception succeeds. RcCs|tj o ||_ndS(N(R!Rtself(R$R!((Rt__init__Ÿs cCs†|it|ƒ||ƒ}xB|iD]1}y||ƒ}PWq%t i ƒd}q%Xq%W|‚d}|i |||ƒ|_}|S(s¬ Parse text according to the namespace dictionaries locals and globals. Sets self.value and returns the parsed value as well. iN(R$t pre_processR"RRRt converterst converterRtsystexc_infotlastexcRt post_process(R$RRRR+R(R((RR ¤s  cCs|||ƒ||ƒS(sˆ Preprocess the text value. Default behaviour is to strip the text and then apply variable expansion. N(R#tstripRRR(R$RRRR-R#((RR&ŗs cCs|S(sŠ Postprocess the value after conversion has been applied. The default behaviour is to leave it as it is. N(R(R$RRR((RR,ĘscCs7|itjo|i|ihhƒnt|iƒS(sŽ Return a stringified version of self.value. The default value is parsed in case no value has yet been set. N(R$RRR R!R"(R$((Rt__str__Ļs(RRt__doc__RRR!tinttfloatR"R'R%R tstringR-R#R&R,R.(((RR‹s    t IntegerEntrycBstZdZefZRS(s' Converts the value to an integer. (RRR/R0R'(((RR3Żs t FloatEntrycBstZdZefZRS(s$ Converts the value to a float. (RRR/R1R'(((RR4ćs t NumericEntrycBstZdZeefZRS(s8 Converts the value to a number (integer or float). (RRR/R0R1R'(((RR5és t StringEntrycBstZdZefZRS(s% Converts the value to a string. (RRR/R"R'(((RR6ļs cCs||||dƒƒS(Nt,(tmapR-R R(RR-R R8ttuple((Rt comma_listõscCs||||ƒƒS(N(R8R-R R(RR-R R8R9((Rt spaced_listūst TupleEntrycBs tZdZefZd„ZRS(sŪ Converts the value to a tuple of strings. value must be a string with entries separated by ','. Entries are split at each occurance of ',' and then stripped of surrounding spaces. cCs t|ƒS(N(R9R(R$RRR((RR, s(RRR/R:R'R,(((RR<s  t ListEntrycBstZdZefZRS(sŚ Converts the value to a list of strings. value must be a string with entries separated by ','. Entries are split at each occurance of ',' and then stripped of surrounding spaces. (RRR/R:R'(((RR=s tSpacedTupleEntrycBstZdZefZRS(sŲ Converts the value to a tuple of strings. value must be a string with entries separated by whitespace. Entries are split at each occurance of whitespace; surrounding spaces is removed. (RRR/R;R'(((RR>#s tSpacedListEntrycBstZdZefZRS(s× Converts the value to a list of strings. value must be a string with entries separated by whitespace. Entries are split at each occurance of whitespace; surrounding spaces is removed. (RRR/R;R'(((RR?.s t FileEntrycBstZdZefZRS(s! Entry field for an OS file. (RRR/R"R'(((RR@9s t PathEntrycBs tZdZefZd„ZRS(sV Entry field for an OS path. Paths will always end with os.sep if given. cCs0|o%|dtijo|ti}n|S(Ni’’’’(RRtsep(R$RRR((RR,Gs(RRR/R"R'R,(((RRA?s  tAbsoluteFileEntrycBs tZdZefZd„ZRS(sm Entry field for an absolute OS pathname. The pathname will always start with os.sep if given. cCs0|o%|dtijoti|}n|S(Ni(RRRB(R$RRR((RR,Vs(RRR/R"R'R,(((RRCMs  tAbsolutePathEntrycBs tZdZefZd„ZRS(sq Entry field for an absolute OS path. The pathname will always start and end with os.sep if given. cCsY|oN|dtijoti|}n|dtijo|ti}qUn|S(Nii’’’’(RRRB(R$RRR((RR,es (RRR/R"R'R,(((RRD\s  tRelativePathEntrycBs#tZdZed„Zd„ZRS(sŌ Entry field for relative paths. The path stored is the result of joining the given parameter with a basepath. basepath is subject to variable expansion at parsing time. cCs||_ti||ƒdS(N(tbasepathR$RAR%R!(R$RFR!((RR%ws cCs"tiit|i||ƒ|ƒS(N( RtpathtjoinR#R$RFRRR(R$RRR((RR,|s(RRR/RR%R,(((RREns  tRelativeFileEntrycBs#tZdZed„Zd„ZRS(sį Entry field for relative pathnames to files. The path stored is the result of joining the given parameter with a basepath. basepath is subject to variable expansion at parsing time. cCs||_ti||ƒdS(N(RFR$RAR%R!(R$RFR!((RR%‰s cCs"tiit|i||ƒ|ƒS(N( RRGRHR#R$RFRRR(R$RRR((RR,Žs(RRR/RR%R,(((RRI€s  tExistingPathEntrycBstZdZd„ZRS(sl Checks value to point to an existing OS path. Raises an exception if the path does not exist. cCsT|o%|dtijo|ti}ntii|ƒptd|‚n|S(Ni’’’’snon existing path "%s"(RRRBRGtexistsR(R$RRR((RR,˜s (RRR/R,(((RRJ’s tExistingFileEntrycBstZdZd„ZRS(si Checks value to point to an existing file. Raises an exception if the file does not exist. cCs1| ptii|ƒ otd|‚n|S(Nsnon existing file "%s"(RRRGRKR(R$RRR((RR,¦s(RRR/R,(((RRL s tExistingRelativePathEntrycBstZdZd„ZRS(sŹ Entry field for relative paths. The path stored is the result of joining the given parameter with a basepath. Raises an exception if the path does not exist. cCsLtiit|i||ƒ|ƒ}tii |ƒpt d|‚n|S(Nsnon existing path "%s"( RRGRHR#R$RFRRRRKR(R$RRR((RR,µs$(RRR/R,(((RRM¬s tURLEntrycBstZdZd„ZRS(s Entry field for URLs. The field takes a default value as argument. Needs mxHTMLTools to be installed. cCsdkl}|i|ƒS(N(s HTMLTools(tmxt HTMLToolstURLR(R$RRRRP((RR,Ås (RRR/R,(((RRN¼s tRelativeURLEntrycBs&tZdZded„Zd„ZRS(sĢ Entry field for relative URLs. A base URL can be set which is then urljoined with the value given. The field also takes a default value. Needs mxHTMLTools to be installed. RcCs||_ti||ƒdS(N(tbaseurlR$R6R%R!(R$RSR!((RR%Ōs cCs,dkl}|it|i||ƒ|ƒS(N(s HTMLTools( RORPturljoinR#R$RSRRR(R$RRRRP((RR,Łs (RRR/RR%R,(((RRRŹs tAbsoluteURLEntrycBstZdZd„ZRS(sŗ Entry field for absolute URLs. A base URL can be set which is then urljoined with the value given. The field also takes a default value as second argument. cCs7ti||||ƒ}|iptd|‚n|S(Nsneed an absolute URL: "%s"( RRR,R$RRRturltabsoluteR(R$RRRRV((RR,ēs (RRR/R,(((RRUßs t DateEntrycBstZdZd„ZRS(s› Date entry field. The value is stored using a DateTime instance. A time part is ignored. Needs mxDateTime to be installed. cCsdkl}||ƒS(N(sDateFromString(tmx.DateTime.ParsertDateFromStringR(R$RRRRZ((RR,ųs (RRR/R,(((RRXīs t DateTimeEntrycBstZdZd„ZRS(s€ Date/time entry field. The value is stored using a DateTime instance. Needs mxDateTime to be installed. cCsdkl}||ƒS(N(sDateTimeFromString(RYtDateTimeFromStringR(R$RRRR\((RR,s (RRR/R,(((RR[żs t TimeEntrycBstZdZd„ZRS(s  Time entry field. The value is stored using a DateTimeDelta instance. A date part is ignored. Needs mxDateTime to be installed. cCsdkl}||ƒS(N(sTimeFromString(RYtTimeFromStringR(R$RRRR^((RR,s (RRR/R,(((RR] s tDateTimeDeltaEntrycBstZdZd„ZRS(s‹ Date/time delta entry field. The value is stored using a DateTimeDelta instance. Needs mxDateTime to be installed. cCsdkl}||ƒS(N(sDateTimeDeltaFromString(RYtDateTimeDeltaFromStringR(R$RRRR`((RR,#s (RRR/R,(((RR_s tRelativeDateTimeEntrycBstZdZd„ZRS(s‘ Relative date/time entry field. The value is stored using a RelativeDateTime instance. Needs mxDateTime to be installed. cCsdkl}||ƒS(N(sRelativeDateTimeFromString(RYtRelativeDateTimeFromStringR(R$RRRRb((RR,1s (RRR/R,(((RRa(s t EvalEntrycBstZdZed„ZRS(s  Allows simple calculations to be done using the current locals (the symbols defined in the class where the entry is located) and globals. cCs||||ƒ|_|iS(N(tevalRRRR$R(R$RRRRd((RR =s(RRR/RdR (((RRc6s t SafeEvalEntrycBstZdZed„ZRS(sÅ Allows simple calculations to be done using the current locals (the symbols defined in the class where the entry is located) and globals. Builtins are not available. cCs||||ƒ|_|iS(N(trevalRRRR$R(R$RRRRf((RR Ms(RRR/RfR (((RReDs t DictEntrycBstZdZd„ZRS(s± Allows the construction of a Python dictionary. The entries value is taken as list of key: value pairs which are evaluated in the current locals (the symbols defined in the class where the entry is located) and globals. Parsing is left to the Python interpreter. The needed curly brackets {} are added by the parsing method. Sample: dict = 'a': (1,2,3), 'b': (3,4,5) cCs$td|d||ƒ|_|iS(Nt{t}(RdRRRR$R(R$RRR((RR ds(RRR/R (((RRgTs tConfigNamespacecBsŒtZdZdZeeieiei ei fei ei ei eieifeieid„Zd„Zd„Zd„Zd„ZRS(Nc Cs|i}t|ƒ|i} | i|iƒxģ| iƒD]Ž\}}|d djo | |=nt |ƒ} | |jo2|djo!t |tƒo|ƒ| |R?R@RARCRDRERIRJRLRMRNRRRURXR[R]R_RaRcReRgRjRyR¦R©R–RRÆRt cStringIOtStringIOtftcfR­(;R<RĘRARÆR?RR;RĮRÉRnRøRUR@RXRÅRµRCRMRgRŸRLR½RIR–R6R4R=R:R¦RJR2RaR3R5RR)RERcR©RRR}R[RNRŒRjR]RyReRČR>RRRÄR#R_R¾RDRRO((Rt?Nsn?   +R    tĄ  )