`c&^JddlZddlZddlZddlmZmZmZmZddlZddl m Z da edededediZ d d d d d d d d d d d d d d d d Z eeeeedZdZdZdZdZdZdZdZeZdZdZdZdZddddddddddddd ZdZGddeZGd d!eZ e Z!d"Z"Gd#d$e#Z$Gd%d&e$Z%Gd'd(e$Z&Gd)d*e'Z(Gd+d,e$Z)Gd-d.e$Z*Gd/d0e$Z+Gd1d2e+Z,Gd3d4e$Z-Gd5d6e+Z.Gd7d8e$Z/Gd9d:eZ0Gd;de0Z2e1e2d?Z3d@Z4GdAdBe5Z6GdCdDe6Z7GdEdFeZ8dJdGZ9dKdIZ:dS)LN)BOM_UTF8 BOM_UTF16 BOM_UTF16_BE BOM_UTF16_LE) __version__)utf_8N)utf16_beutf_16)utf16_ler )r r r r r r )r u16utf16zutf-16r utf_16_bezutf-16ber utf_16_lezutf-16ler u8utfutf8utf-8)r r r r Ncbt|dkS)Nr )BOM_LISTgetlower)encodings 4/usr/lib/python3/dist-packages/configobj/__init__.py match_utf8rDs# <<(( ) )W 44z'%s'z"%s"z%sz '"z"""%s"""z'''%s''')DEFAULT_INDENT_TYPEDEFAULT_INTERPOLATIONConfigObjError NestingError ParseErrorDuplicateErrorConfigspecError ConfigObj SimpleValInterpolationErrorInterpolationLoopErrorMissingInterpolationOptionRepeatSectionError ReloadError UnreprError UnknownTypeflatten_errorsget_extra_values configparserz TF) interpolation raise_errors list_values create_empty file_error configspec stringify indent_typerdefault_encodingunreprwrite_empty_valuesctddlad|z}t|}|dddS)Nrza=r)compilerparse getChildren)sps rgetObjrBs` qAqA ==??1  ) ) + +A . : : < ##D#.....rNrrGrrr(r(s):://///rr(ceZdZdZdS)r+z An error parsing in unrepr mode.NrrGrrr+r+s****rr+cNeZdZdZejdZdZdZdZ dZ dZ dS) InterpolationEnginez A helper class to help perform string interpolation. This class is an abstract base class; its descendants perform the actual work. %\(([^)]*)\)s%c||_dSrKsection)rOrs rrzInterpolationEngine.__init__*s  rcRj|vr|Sfd||ji}|S)Nc||jf|vrt|d|||jf< j|}|r |\}}}||}n ||||}|\} } d|d| ||| df}| t|z} j|| }||||jf=|S)axThe function that does the actual work. ``value``: the string we're trying to interpolate. ``section``: the section in which that string was found ``backtrail``: a dict to keep track of where we've been, to detect and prevent infinite recursion loops This is similar to a depth-first-search algorithm. rNr)rgr'_KEYCREsearch _parse_matchspanjoinlen)keyrWr backtrailmatchkvr@ replacementstartendnew_search_startrecursive_interpolaterOs rrz>InterpolationEngine.interpolate..recursive_interpolate4sW\"i//,S111-.IsGL) *L''..E E++E221a9"#KK#8"71a"K"KK"ZZ\\ svv U344[ IJJ#(3{+;+;#;  ++E3CDD! E&3 -.Lr)_cookier)rOrrWrs` @r interpolatezInterpolationEngine.interpolate/sT|u$$L( ( ( ( ( ( X&%c5$,CC rc|jjj}d|jj_|j} ||}|t |t snS|di|}|t |t sn|j|urn|j}||jj_|t|||fS)zHelper function to fetch values from owning section. Returns a 2-tuple: the value, and the section where it was found. FTNDEFAULT)rmainr1rrmSectionrvr()rOr save_interpcurrent_sectionvals r_fetchzInterpolationEngine._fetchds l'5 */ ', 5!%%c**Cz#w'?'?!%%i4488==Cz#w'?'?%88-4O 5"+6 ' ;,S11 1O##rct)aImplementation-dependent helper function. Will be passed a match object corresponding to the interpolation key we just found (e.g., "%(foo)s" or "$foo"). Should look up that key in the appropriate config file section (using the ``_fetch()`` helper function) and return a 3-tuple: (key, value, section) ``key`` is the name of the key we're looking for ``value`` is the value found for that key ``section`` is a reference to the section where it was found ``key`` and ``section`` should be None if no further interpolation should be performed on the resulting value (e.g., if we interpolated "$$" and returned "$"). )NotImplementedError)rOrs rrz InterpolationEngine._parse_matchs "###rN) rDrErFrrecompilerrrrrrrGrrrrsubj)**GG 222j$$$D$$$$$rrc<eZdZdZdZejdZdZdS)ConfigParserInterpolationzBehaves like ConfigParser.rrcf|d}||\}}|||fS)Nr)grouprrOrrrWrs rrz&ConfigParserInterpolation._parse_matchs3kk!nnS))wE7""rN) rDrErFrrrrrrrGrrrrs@$$Gbj)**G#####rrc\eZdZdZdZdZejdejej zZ dZ dS)TemplateInterpolationzBehaves like string.Template.$z \$(?: (?P\$) | # Two $ signs (?P[_a-z][_a-z0-9]*) | # $name format {(?P[^}]*)} # ${name} format ) c|dp|d}|||\}}|||fS|d d|jdfSd|dfS)Nnamedbracedescaped)rr _delimiterrs rrz"TemplateInterpolation._parse_matchskk'"";ekk(&;&; ?![[--NE7w& & ;;y ! ! -$. .U[[]]D((rN) rDrErFrrrrr IGNORECASEVERBOSErrrGrrrrsY''GJbj ]RZ ' ))G ) ) ) ) )rr)r/templatec|j|g|RSrK)__new__)clsargss r __newobj__rs 3;s "T " " ""rceZdZdZdZdZd%dZdZdZdZ d&d Z d Z d'd Z d Z efdZdZdZd'dZdZdZdZdZdZeZdZdZeZde_dZdZdZ d(dZdZ d Z!d!Z"d"Z#d#Z$d$Z%dS))ra A dictionary-like object that represents a section in a config file. It does string interpolation if the 'interpolation' attribute of the 'main' object is set to True. Interpolation is tried first from this object, then from the 'DEFAULT' section of this object, next from the parent and its 'DEFAULT' section, and so on until the main object is reached. A Section will behave like an ordered dictionary - following the order of the ``scalars`` and ``sections`` attributes. You can use this to change the order of members. Iteration follows the order: scalars, then sections. ct||d|j|ddS)Nrr)dictupdate__dict__rOstates r __setstate__zSection.__setstate__s: D%(### U1X&&&&&rcNt||jf}t|jf|fSrK)rrrrMrs r __reduce__zSection.__reduce__s&dT]+T^-u55rNc|i}t|||_||_||_||_||D] \}}|||< dS)z * parent is the section above * depth is the depth level of this section * main is the main ConfigObj * indict is a dictionary to initialise the section with N)rrrvrdepthrg _initialiseitems)rOrvrrindictrgentryrWs rrzSection.__init__s >F d     #LLNN  LE5DKK  rcg|_g|_i|_i|_d|_g|_i|_g|_d|_dS)NF) scalarssectionscommentsinline_commentsr6defaultsdefault_values extra_values_createdrs rrzSection._initialisesH   !   rc8 |j}n|#t$ro|jj}|dkrt}|}t |d}|d|j_|cYS||x}|_YnwxYw|||S)NTF) _interpolation_engineAttributeErrorrr1rrinterpolation_enginesrr)rOrrWenginergclass_s r _interpolatezSection._interpolates C/FF C C C9*Dt||,::<._check/s3!%)9::=#00e<<< Lrc&g|] }|SrGrG).0rrs r z'Section.__getitem__..3s!666vve}}666r) r __getitem__rr1rmrrrrS)rOrrnewrs`` @rrzSection.__getitem__(stS)) 9 " #s/00 3((c222#t$$ !!!!!!7666#666#::J rFc t|tjstd|z||jvrg|j|<d|j|<||jvr|j|t|tr<||vr|j |t |||dSt|tr_|s]||vr|j ||j dz}t ||t|||j||dS||vr|j ||jjs{t|tjrn`t|t"t$fr2|D].}t|tjst'd|z/nt'd|zt |||dS)a Correctly set a value. Making dictionary values Section instances. (We have to special case 'Section' instances - which are also dicts) Keys must be strings. Values need only be strings (or lists of strings) if ``main.stringify`` is set. ``unrepr`` must be set when setting a value to a dictionary, without creating a new sub-section. zThe key "%s" is not a string.rr)rrgzValue is not a string "%s".N)rmrr ValueErrorrrrremoverrappendr __setitem__rrrr7rSrarl)rOrrWr: new_depthrs rr zSection.__setitem__9s2#s/00 DA version of ``get`` that doesn't bypass string interpolation.KeyErrorrOrdefaults rrz Section.gets5 9    NNN s  c&|D] }||||<dS)zD A version of update that uses our ``__setitem__``. NrG)rOrrs rrzSection.updates, ( (E -DKK ( (rcX ||}||=n#t$r|tur|}YnwxYw|S)z 'D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised' )rMISSING)rOrrrs rpopz Section.popsV  s)C S    '!!CCC   s ''cp|j|jz}|std|d}||}||=||fS)zPops the first (key,val)z": 'popitem(): dictionary is empty'r)rrr)rOsequencerrs rpopitemzSection.popitemsJL4=0 A?@@ @qkCy ICxrct|g|_g|_i|_i|_d|_g|_g|_dS)z A version of clear that also affects scalars/sections Also clears comments and configspec. Leaves other attributes alone : depth/main/parent are not affected N) rclearrrrrr6rrrs rrz Section.clearsO 4   ! rcN ||S#t$r|||<||cYSwxYw)z:A version of setdefault that sets sequence if appropriate.rrs r setdefaultzSection.setdefaultsE 9    DI9    s  $$c tt|j|jzt|S)z8D.items() -> list of D's (key, value) pairs, as 2-tuples)rSziprrvaluesrs rrz Section.itemss3C 5T[[]]8K8KLLMMMrc |j|jzS)zD.keys() -> list of D's keysrrrs rkeysz Section.keyss t},-rc:fdjjzDS)z D.values() -> list of D's valuesc g|] }| SrGrG)rrrOs rrz"Section.values..sDDDcS DDDrr"rs`rr zSection.valuess&DDDDdlT]&BDDDDrc^tt|S)z=D.iteritems() -> an iterator over the (key, value) items of D)rZrSrrs r iteritemszSection.iteritemss D&&'''rc:t|j|jzS)z.D.iterkeys() -> an iterator over the keys of D)rZrrrs riterkeyszSection.iterkeyssT\DM1333rc^tt|S)z2D.itervalues() -> an iterator over the values of D)rZrSr rs r itervalueszSection.itervaluess D''(((rcrfdddfdjjzDzS)zx.__repr__() <==> repr(x)cl |S#t$rt|cYSwxYwrKr(rrrrOs r_getvalz!Section.__repr__.._getvalI 3Cy - 3 3 3''c22222 3  %33z{%s}, c dg|],}t|dt|-Sz: reprrrr0s rrz$Section.__repr__..sK#7#7#715S 4 ;M;M;M$N#7#7#7rrrrrOr0s`@r__repr__zSection.__repr__sk 3 3 3 3 3  #7#7#7#7 t}4#7#7#7888 8rzx.__str__() <==> str(x)ci}|D]}||}t|tr|}nIt|trt|}n$t|trt |}|||<|S)a0 Return a deepcopy of self as a dictionary. All members that are ``Section`` instances are recursively turned to ordinary dictionaries - by calling their ``dict`` method. >>> n = a.dict() >>> n == a 1 >>> n is a 0 )rmrrrSra)rOnewdictr this_entrys rrz Section.dicts ( (EeJ*g.. /'__.. J-- /!*-- J.. /":.. 'GENNrct|D]Z\}}||vrLt||tr1t|tr|||U|||<[dS)aQ A recursive update - useful for merging config files. >>> a = '''[section1] ... option1 = True ... [[subsection]] ... more_options = False ... # end of file'''.splitlines() >>> b = '''# File is user.ini ... [section1] ... option1 = False ... # end of file'''.splitlines() >>> c1 = ConfigObj(b) >>> c2 = ConfigObj(a) >>> c2.merge(c1) >>> c2 ConfigObj({'section1': {'option1': 'False', 'subsection': {'more_options': 'False'}}}) N)rSrrmrmerge)rOrrrs rr@z Section.merges&V\\^^,,  HCt 49d ; ; *3 5 5S $$$$S   rc||jvr|j}n#||jvr|j}ntd|z||}||}t||t|||||||||j |}|j |}|j |=|j |=||j |<||j |<dS)a Change a keyname to another, without changing position in sequence. Implemented so that transformations can be made on keys, as well as on values. (used by encode and decode) Also renames comments. zKey "%s" not found.N) rrrindexrr r rinsertrr)rOoldkeynewkeythe_listposrcomminline_comments rrenamezSection.rename,s T\ ! !|HH t} $ $}HH069:: :nnV$$6l v&&& vs+++V$$$}V$-f5 M& !   ( $ f'5V$$$rTc i}tt|jD]Q}|j|} |||fi|}|j|}|||<-#t$r|r|j|}d||<YNwxYwtt|jD]i}|j|}|r> |||fi|n%#t$r|r|j|}d||<YnwxYw|j|}||j|f||d|||<j|S)a Walk every member and call a function on the keyword and value. Return a dictionary of the return values If the function raises an exception, raise the errror unless ``raise_errors=False``, in which case set the return value to ``False``. Any unrecognised keyword arguments you pass to walk, will be pased on to the function you pass in. Note: if ``call_on_sections`` is ``True`` then - on encountering a subsection, *first* the function is called for the *whole* subsection, and then recurses into it's members. This means your function must be able to handle strings, dictionaries and lists. This allows you to change the key of subsections as well as for ordinary members. The return value when called on the whole subsection has to be discarded. See the encode and decode methods for examples, including functions. .. admonition:: caution You can use ``walk`` to transform the names of members of a section but you mustn't add or delete members. >>> config = '''[XXXXsection] ... XXXXkey = XXXXvalue'''.splitlines() >>> cfg = ConfigObj(config) >>> cfg ConfigObj({'XXXXsection': {'XXXXkey': 'XXXXvalue'}}) >>> def transform(section, key): ... val = section[key] ... newkey = key.replace('XXXX', 'CLIENT1') ... section.rename(key, newkey) ... if isinstance(val, (tuple, list, dict)): ... pass ... else: ... val = val.replace('XXXX', 'CLIENT1') ... section[newkey] = val >>> cfg.walk(transform, call_on_sections=True) {'CLIENT1section': {'CLIENT1key': None}} >>> cfg ConfigObj({'CLIENT1section': {'CLIENT1key': 'CLIENT1value'}}) F)r2call_on_sections)rangerr Exceptionrwalk) rOfunctionr2rLkeywargsoutr]rrs rrOz Section.walkJs^s4<(()) ' 'ALOE 'htU77h77 Q E  ' ' '' LOE!&CJJJ  's4=))**  AM!$E )+HT555H5555 +++#+ $ a 0%*E + a()e))!1 CJJ  s#AA32A3) B44CCc ||}|dkrdS|dkrdS t|tjst|jj|S#t$rtd|zwxYw)a_ Accepts a key as input. The corresponding value must be a string or the objects (``True`` or 1) or (``False`` or 0). We allow 0 and 1 to retain compatibility with Python 2.2. If the string is one of ``True``, ``On``, ``Yes``, or ``1`` it returns ``True``. If the string is one of ``False``, ``Off``, ``No``, or ``0`` it returns ``False``. ``as_bool`` is not case sensitive. Any other input will raise a ``ValueError``. >>> a = ConfigObj() >>> a['a'] = 'fish' >>> a.as_bool('a') Traceback (most recent call last): ValueError: Value "fish" is neither True nor False >>> a['b'] = 'True' >>> a.as_bool('b') 1 >>> a['b'] = 'off' >>> a.as_bool('b') 0 TFz$Value "%s" is neither True nor False)rmrrrr_boolsrr)rOrrs ras_boolzSection.as_bools83i $;;4 E\\5 O!#s'7889"**$9+CIIKK88 O O O !G#!MNNN Os A A&&Bc,t||S)ai A convenience method which coerces the specified value to an integer. If the value is an invalid literal for ``int``, a ``ValueError`` will be raised. >>> a = ConfigObj() >>> a['a'] = 'fish' >>> a.as_int('a') Traceback (most recent call last): ValueError: invalid literal for int() with base 10: 'fish' >>> a['b'] = '1' >>> a.as_int('b') 1 >>> a['b'] = '3.2' >>> a.as_int('b') Traceback (most recent call last): ValueError: invalid literal for int() with base 10: '3.2' )intr s ras_intzSection.as_ints(49~~rc,t||S)a> A convenience method which coerces the specified value to a float. If the value is an invalid literal for ``float``, a ``ValueError`` will be raised. >>> a = ConfigObj() >>> a['a'] = 'fish' >>> a.as_float('a') #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ValueError: invalid literal for float(): fish >>> a['b'] = '1' >>> a.as_float('b') 1.0 >>> a['b'] = '3.2' >>> a.as_float('b') #doctest: +ELLIPSIS 3.2... )rkr s ras_floatzSection.as_floats&T#Yrcn||}t|ttfrt|S|gS)aU A convenience method which fetches the specified value, guaranteeing that it is a list. >>> a = ConfigObj() >>> a['a'] = 1 >>> a.as_list('a') [1] >>> a['a'] = (1,) >>> a.as_list('a') [1] >>> a['a'] = [1] >>> a.as_list('a') [1] )rmrarS)rOrresults ras_listzSection.as_lists6 c fudm , , << xrc|j|}t|||||jvr|j||S)a Restore (and return) default value for the specified key. This method will only work for a ConfigObj that was created with a configspec and has been validated. If there is no default value for this key, ``KeyError`` is raised. )rrr rrrs rrestore_defaultzSection.restore_defaultsQ%c* sG,,, dm # # M  % % %rc|jD]}|||jD]}||dS)a' Recursively restore default values to all members that have them. This method will only work for a ConfigObj that was created with a configspec and has been validated. It doesn't delete or modify entries without default values. N)rr_rrestore_defaults)rOrrs rrazSection.restore_defaultssa& & &C   % % % %} - -G M * * , , , , - -rNNFrK)TF)&rDrErFrrrrrrrr r rrrrrrrrr#r r'r)__iter__r+r;__str__rr@rJrOrUrXrZr]r_rarGrrrrs?$'''666     4"...."8/8/8/8/v&&&((( '     $NNN ... EEE ((( 444H))) 888G/GO 8   6666<+/"RRRRj)O)O)OX.   ,,    -----rrc PeZdZdZejdejZejdejZejdejZ ejdejZ ejdejZ ejdZ ejdZ ejd Zejd Ze efe efd Zd d d d d d d d dZ d+dZdZd,dZdZdZdZdZdZdZdZdZdZdZd-dZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&d%Z'd&Z(d.d'Z) d/d(Z*d)Z+d*Z,dS)0r$z2An object to read, create, and write config files.a^ # line start (\s*) # indentation ( # keyword (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'"=].*?) # no quotes ) \s*=\s* # divider (.*) # value (including list values and comments) $ # line end a=^ (\s*) # 1: indentation ((?:\[\s*)+) # 2: section marker open ( # 3: section name open (?:"\s*\S.*?\s*")| # at least one non-space with double quotes (?:'\s*\S.*?\s*')| # at least one non-space with single quotes (?:[^'"\s].*?) # at least one non-space unquoted ) # section name close ((?:\s*\])+) # 4: section marker close \s*(\#.*)? # 5: optional comment $a^ (?: (?: ( (?: (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\#][^,\#]*?) # unquoted ) \s*,\s* # comma )* # match all list items ending in a comma (if any) ) ( (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\#\s][^,]*?)| # unquoted (?:(?> ?GG OOO MM?,  < < < ! I I//#$?%$GHHH0 $_%:%:%<%< = = 3 3 u''%*GEN ( M))%2GEN  +%*GM " !!!\* $.! 6:&&&&&rc t|tjr||_tj|r@t|d5}|pg}dddn #1swxYwYnC|j rtd|jz|j r=t|d5}| ddddn #1swxYwYg}nt|ttfrt|}nt|trZt|t r fd  ||n|D] }||||<|`|||nd|_dSt)|dt*t*ur|pg}nt/d|rJ||}|D]2}|r |dd vrd D] }||r ||_n!t7d |DsJt9|d |D}|||jrdd |jdjz}t?|jdkrd|z} tA| } n |jd} |j| _!|| _"| |`| d|_dS||dS)NrbzConfig file not found: "%s".wrc|jD] }||||<|jD]}i||<|||| dSrKr") in_section this_sectionrr set_sections rrz$ConfigObj._load..set_sectionsr!+!3@@.8.? U++#-#6PP02 W-# Jw$7g9NOOOOPPrreadz>infile must be a filename, file like object, or list of lines.)  ) rrc3JK|]}t|tjVdSrK)rmrrrrs r z"ConfigObj._load..s/JJ$:dC$455JJJJJJrc8g|]}|dS)r)rstriprs rrz#ConfigObj._load..s$;;;44;;v&&;;;rz at line %s.rrz2Parsing failed with several errors. First error %s)#rmrrfilenameospathisfileopen readlinesr5rr4writerSrarr$_errors_handle_configspecr6rtrrrl _handle_bomendswithnewlinesallr7_parserrrerrorsconfig) rOr{r6hcontentrrrinforerrorrs @rrzzConfigObj._loads fc. / /2 ^"DMw~~f%% &$''21kkmm1rG222222222222222 ">/C}}S))(+ JJ'JJJJJYYDQXMMYYY;;7;;; G <  4<?#>>D4<  1$$KdR&s++ Q "?h' ! < %$D  D!!!!!rcrfdddfdjjzDzS)Ncl |S#t$rt|cYSwxYwrKr.r/s rr0z#ConfigObj.__repr__.._getvalQr1r2zConfigObj({%s})r3c dg|],}t|dt|-Sr5r6r8s rrz&ConfigObj.__repr__..WsK;;;)-S 4 3E3E3EF;;;rr9r:s`@rr;zConfigObj.__repr__Psl 3 3 3 3 3 " ;;;; L4=8;;;<<< =rc|j;|jtvr|||jSt |t t fr |d}n|}t |tjr|||jS|j>t|j}|dkrzt t D]8\}\}}|s | |r|||cS9|||jSt|}| |s|||jS|t|d}t |t t fr||d<n|}d|_|||jSt t D]'\}\}}t |tjr| |s9||_|sd|_|t|d}t |t t fr||d<n|}t |tjr|dcSt |tjr*|ddcS||dcS|||cStjr+t |t&r||dSt |tjr(|ddS||dS)a1 Handle any BOM, and decode if necessary. If an encoding is specified, that *must* be used - but the BOM should still be removed (and the BOM attribute set). (If the encoding is wrongly specified, then a BOM for an alternative encoding won't be discovered or removed.) If an encoding is not specified, UTF8 or UTF16 BOM will be detected and removed. The BOM attribute will be set. UTF16 will be decoded to unicode. NOTE: This method must not be called with an empty ``infile``. Specifying the *wrong* encoding is likely to cause a ``UnicodeDecodeError``. ``infile`` must always be returned as a list of lines, but may be passed in as a single string. Nrr Tr)rrr_decodermrSrar text_typeBOMSr startswithBOM_SETrr binary_type splitlinesdecodePY2str)rOr{rencrrfinal_encodingnewlines rrzConfigObj._handle_bom[s.] & ] " "( 2 2<< 66 6 ftUm , , !9DDD dCM * * 7<< 66 6 = $ 4=..001Ch7;DJJLL7I7I>>3C3(N)! ((--> $||FH===== >||FDM:::#,C??3'' ;||FDM:::3s8899oG&4-00 !#q  DH<< 66 604DJJLL/A/A 6 6 +C+(NdCO44 6DOOC>$-00 0Nrct|tjr|dSt|tjr?|r(||dS|dS|rGt |D]7\}}t|tjr||||<8|S)z Decode infile to unicode. Using the specified encoding. if is a string, it also needs converting to a list. T)rmrrrrr enumerate)rOr{rr]rs rrzConfigObj._decodes fc. / / +$$T** * fco . . / /}}X..99$???((...  6$V,, 6 64dCO446!% H 5 5F1I rc|t|tjr!|jr||jS|S)z'Decode element to unicode if necessary.)rmrrr9r)rOrs r_decode_elementzConfigObj._decode_elements: dCO , , 1F ;;t455 5KrcXt|tjst|S|S)zh Used by ``stringify`` within validate, to turn non-string values into strings. )rmrrrrOrWs r_strzConfigObj._strs, %!122 u:: Lrcp |j}|jrd|_g}d}|}t|dz }d}d}||krN|rg}|dz }||} | } | r| drd}|| [|s ||_g}d}d}|j| } | u| \} } }}}| r|j | |_ | d}|| dkr| d t||||jkrK |||j}nq#t"$r!| d t||YOwxYw||jkr|j}n0||jdzkr|}n| d t||||}||vr| d t&||t)|||| }|||<||j|<||j|<|j| } | 2| d| t2||n| \} }}| r|j | |_ |dddvr |||||\}}}|jrfd} t|}n2#t6$rE}t9|t:krd}nd}| |t<||Yd}~d}~wwxYwn#t"$r!| dt2||Y3wxYw|jrbd} t|}n#t6$rB}t?|t:rd}nd}| |t<||Yd}~d}~wwxYw | |\}}n.#t"$r!| dt2||YwxYw||}||vr| dt&|| |!||d||j|<||j|<N||kN|j d|_ |s|js||_n |s||_"||_dS)zActually parse the config file.Frr#TN[]z Cannot compute the section depthzCannot compute nesting levelzSection too nestedzDuplicate section name)rgz=Invalid line ({0!r}) (matched as neither section nor keyword))rhrgrzUnknown name or type in valuez+Parse error from unrepr-ing multiline valuezParse error in multiline valuez!Parse error from unrepr-ing valuezParse error in valuezDuplicate keyword name)r:)#r3r:rstriprrr_sectionmarkerrgroupsr8count _handle_errorr r _match_depthrvr_unquoter"rrr_keywordformatr! _multilinerNtyper,r+rm _handle_valuer r)rOr{temp_list_values comment_list done_startrmaxline cur_index reset_commentrslinematindent sect_open sect_name sect_closecomment cur_depthrvrrWers rrzConfigObj._parses5+ ; %$D    f++/  '!! "! NI)$DJJLLE E,,S11  % ##D))) "'3$! !  M%++D11CFIjjllCIz7.t/7'-D$%OOC00  0 0 5 555&&'I'3VYHHH|111!!%!2!2<3<">">>D&!!!**+I+7LLL !,"444)0FF,"4q"888)FF&&';'3VYHHH MM)44 &&&&'?'5vyJJJ '"  $ $ $ %1y!4;&y1-9 *-%%d++C{""SZZ[_`` 3333 (+zz||$e.t/7'-D$!9..)48OO!69g5?5?1w  ; )&(G )(.u #,)))#'77k#9#9*ICC*WC $ 2 23 V$-!/!/!/ () ) '!!!**<& ;;;! !&{%"$ %$*5MMEE(%%%)![99J&E&I ..sK )+++$HHHH%%/3/A/A%/H/H,UGG*%%% .. 6 *FI???%H % mmC((,&&&&0& ;;;((eD(AAA4; ,S1-9 %c*Y'!!\   #!D  .D0 .#/D  .!-D +sf;E'FF1L;K(( L72:L22L7;'M&%M&3N O 7O  OO,,'PPc||jkr)||jurt|j}||jk)|j|kr|St)z Given a section and a depth level, walk back through the sections parents to see if the depth level matches a previous section. Return a reference to the right section, or raise a SyntaxError. )rrvr)rOsectrs rrzConfigObj._match_depths\dj  t{""!mm#;D dj  :  Kmmrc||}|dz }d||}||||}|jr||j|dS)z Handle an error according to the error settings. Either raise the error or store it. The error will have occured at ``cur_index`` rz{0} at line {1}.N)rr2rr)rOtext ErrorClassr{rrrrs rrzConfigObj._handle_errorsmi Q $++D)<< 7It44   K E"""""rcd|st|d|dkr|ddvr |dd}|S)z%Return an unquoted version of a valuerr)"'r)rrs rrzConfigObj._unquotesC   !Hb ! !aJ(>(>!B$KE rcf|rjr|dkrdS|rtt|ttfrX|sdSt |dkr |dddzSdfd|DSt|tjs)j rt|}ntd |z|sd Sj od |vod |v}|o d |vrd|vpd |v}|o| o d |vod|vod |v}|s| o| }|rej st}nkd |vrtd|z|dtvr|dtvr d|vrt}n+|}n|}|tkr d |vrj r|}||zS)a Return a safely quoted version of a value. Raise a ConfigObjError if the value cannot be safely quoted. If multiline is ``True`` (default) then use triple quotes if necessary. * Don't quote values that don't need it. * Recursively quote members of a list and return a comma joined list. * Multiline is ``False`` for lists. * Obey list syntax for empty and single member lists. If ``list_values=False`` then the value is only quoted if it contains a ``\n`` (is multiline) or '#'. If ``write_empty_values`` is set, and the value is an empty string, it won't be quoted. r,rrF multiliner3c>g|]}|dS)Fr)_quoterrrOs rrz$ConfigObj._quote..s9"""#kk#k??"""rzValue "%s" is not a string.""rrrr#Value "%s" cannot be safely quoted.r)r;rmrSrarrrrrr7rrlr3noquotr wspace_plus_get_single_quote_get_triple_quote)rOrWrno_lists_no_quotes need_triplehash_triple_quotecheck_for_singlequots` rrzConfigObj._quotesX&  0 Ub[[2  #ED%=99 # DsUq{{58u{==CC99"""" """## #%!122 G~ GE  = EFFF 4!%!11\d%6G\CW\L\]se|&G#,%\TUZ] %rk/rse|rRUY^R^rehlqeq.Ak/\K\G\  1# 5$%JU%RSSS8;..2Yk11%%--e44))%00D 6>>cUllt/?l))%00De|rc`d|vrd|vrtd|zd|vrt}nt}|S)Nrrr)rsquotdquotrOrWrs rrzConfigObj._get_single_quote%sA 5LLse|| !F!NOO O E\\DDD rc|ddkr+|ddkrtd|z|ddkrt}nt}|S)Nrhrrgr)findrtdquottsquotrs rrzConfigObj._get_triple_quote/sk JJu   # #%**U*;*;r*A*A !F!NOO O ::e   " "DDD rc"jr|dfSjs>j|}|t |Sj|}|t |\}}}}|dkr|t |g|fS| |r|sd}n|pd}|}|dkr||fSj |}fd|D}|||gz }||fS)z Given a value string, unquote, remove comment, handle lists. (including empty and single member lists) rNrc:g|]}|SrG)rrs rrz+ConfigObj._handle_value..ds%;;;3DMM#&&;;;r) rtr3 _nolistvaluerrr _valueexpr _listvalueexpfindall)rOrWrr3single empty_listrrFs` rrzConfigObj._handle_value9sX < 2;  #))%00C{!mm#::<< n""5)) ;-- 58ZZ\\2fj' 2  FN--   !=   /6 /4v.. "  G$ $%--k::;;;;(;;;    H'""rc|dd}|dd}|j|d}|j|d}||} | 8t| } | || S||dkrt ||kr8|dz }|dz }||} | |dkr|| z }nn||k8t || } | t | \}} ||z| |fS)z9Extract the value, where we are in a multiline situation.Nrrrrr) _triple_quoterrSrrrr) rOrWr{rrrnewvalue single_line multi_linerretvalrrs rrzConfigObj._multilinejsRRaRy9(.q1 '-a0 && ?#**,,''F MM) $ $ $M ]]4 B & &-- '!! NI  H)$Dyy"$$D '!!-- t$$ ;-- ::<<5 '955rct|tsX t|ddd}nC#t$r}td|zd}~wt$r}t d|zd}~wwxYw||_dS)zParse the configspec.T)r2r5rtzParsing configspec failed: %sNzReading configspec failed: %s)rmr$rr#rr6)rOr6rs rrzConfigObj._handle_configspecs*i00 C C&z4826/3555 " K K K&&E&IJJJ C C C=ABBB C%s + A+A A+A&&A+c|j}|d}t|tr|jD]}||vr |||_|jD]}|dkr ||vrZi||<d||_|rF|j|g|j|<|j|d|j|<t||tr||||_dS)z Called by validate. Handles setting the configspec on subsections including sections to be validated by __many__ __many__TrN) r6rrmrrrrrr)rOrcopyr6manyrs r_set_configspeczConfigObj._set_configspecs ' ~~j)) dD ! ! 5 ) 5 5 **04GEN-( > >E ""G##!#*.'_.8.A.E.EeR.P.PG$U+5?5O5S5STY[]5^5^G+E2'%.'22 >,6u,=) > >rc4|js)|||}nt|}||||d|d|||S)z.Write an individual line, for the write methodFrz = )r:rrr7r)rO indent_stringrr>rrs r _write_linezConfigObj._write_lines{ #&&t{{:'>'>??CCz""C,}#33DKKQVK4W4WXXX#||E222"s#33G<<< > >rc||d|z|||d|d|z||S)zWrite a section marker linerFrr)rrr)rOrrrrs r _write_markerzConfigObj._write_markersv,}#||C%K888#{{4+?+?+F+FRW{XXX#||C%K888#33G<<< > >rc||sdS|j}|ds||dz }||zS)zDeal with a comment.rrz # )r8rr)rOrrs r_handle_commentzConfigObj._handle_commentsM 2 !!#&& ) T\\%(( (E rc j t_g}d}d}|tj}d_}jD]\}|}|}|r||s||z}||]j|j z} |j |j zD];} | |j vr |j | D]]} | } | r| |s|| z} || | z^|| } |j| } t#| t$r[|| | j | | || || | | | =|urkjD]\}|}|}|r||s||z}||]|_|ur|Sj|jrfd|D}jrfj5t6jdkr*|s|dt<|d z|d <|Sjp t@j!}tE|d d#|j#d krtHj%d kr|d krd}|&|}|'|s||z }t#|tPj)r|}n#|*jpj+pd}jr%jtYjr t<|z}|||dSt[jd5}||ddddS#1swxYwYdS)a~ Write the current ConfigObj as a file tekNico: FIXME: use StringIO instead of real files >>> filename = a.filename >>> a.filename = 'test.ini' >>> a.write() >>> a.filename = filename >>> a == ConfigObj('test.ini', raise_errors=True) 1 >>> import os >>> os.remove('test.ini') Nrz# FrcDg|]}|jSrG)encoder)rlrOs rrz#ConfigObj.write../s'<<<1qxx ..<<rroutput output_bytesrs` rrzConfigObj.writes   #2D  \\#  ll4   ?(G!&D G, ! !++D11 $  &)A)A")E)E&:D 4    (7=8 o(88  E((( ' 0 7 9 9 #33L4G4G4I4IJJ 6 (?(?(C(C6#&#5L =<78888 J**7+B5+IJJG*g..  4--!$   4::j:99:::: 4++!  d??* ! !++D11 $  &)A)A")E)E&:D 4    !(D  $  J M !} =<<<<<<< +t}4dm113344??#JJrNNN!CF*AJ--2: GVT * * 67<3;N;N ''Gv,=,=Gg&&++C00w''  g F fco . . 2!LL!==*1)-)>*1)022L 8 3$-/Jt}4M4M/#l2L   MM, ' ' ' ' 'dmT** &a %%% & & & & & & & & & & & & & & & & & &s7QQ!Qc vjtdr ddlm}|_rfjj_jj_jj_jj_jj _ jj _ j fd}id}d}fdj D} fdj D} fd j D} j D]} | d vr| j vs | jvrVd} d}rO| j vrFj| gj| <j| d j| <n d } | }|| | || ||\}}d}d j vr d }ndj vrd}|"| D]} | }|| ||d ||\}}g} | D]+} d }sd | < d }d| z}|| <,| D]+} d }sd | < d }d| z}|| <,j D]} ur| dkr | j| | 0rFj| gj| <j| d j| <| }|| <|d krd }|dkrd }d }| _r jsd }|r&r$r"t/ }|rdS|rd SS)a; Test the ConfigObj against a configspec. It uses the ``validator`` object from *validate.py*. To run ``validate`` on the current ConfigObj, call: :: test = config.validate(validator) (Normally having previously passed in the configspec when the ConfigObj was created - you can dynamically assign a dictionary of checks to the ``configspec`` attribute of a section though). It returns ``True`` if everything passes, or a dictionary of pass/fails (True/False). If every member of a subsection passes, it will just have the value ``True``. (It also returns ``False`` if all members fail). In addition, it converts the values from strings to their native types if their checks pass (and ``stringify`` is set). If ``preserve_errors`` is ``True`` (``False`` is default) then instead of a marking a fail with a ``False``, it will preserve the actual exception object. This can contain info about the reason for failure. For example the ``VdtValueTooSmallError`` indicates that the value supplied was too small. If a value (or section) is missing it will still be marked as ``False``. You must have the validate module to use ``preserve_errors=True``. You can then use the ``flatten_errors`` function to turn your nested results dictionary into a flattened list of failures - useful for displaying meaningful error messages. NzNo configspec supplied.r)VdtMissingValuec j|d | j|<n#ttjf$rYnwxYw |||}d}d |< js|r[ jsGt|ttfr fd|D}n|r|d}n |}||ks|r| |< s%|r#| j vr j |n=#j$r0} rt| jrd |<n| |<d}d}Yd}~nd}~wwxYw||fS)N)missingFTc:g|]}|SrG)r)ritemrOs rrz>ConfigObj.validate..validate_entry..s#$G$G$GTYYt__$G$G$Grr)rrget_default_valuerrbaseErrorClasscheckr7rmrSrarrr_vdtMissingValue)rspecrr8ret_true ret_falser=rr6rrRpreserve_errorsrrO validators rvalidate_entryz*ConfigObj.validate..validate_entrys  " & &ud 3 3 3 090K0KJW\L]0^0^&u--ni.FG      3!(+07(**" !E > /W / >5%edE];;5$G$G$G$G$G$G$GEE$5$&EE$(IIe$4$4E  ).33E9I,I,I$++E2225+ ! ! !&&*Q8M*N*N&!&CJJ"#CJ %I  !6Y& &s)#AAA D E&EETcg|]}|v| SrGrG)rrr6s rrz&ConfigObj.validate..s#IIIQQj5H5Hq5H5H5Hrc&g|] }|jv |SrG)rrrrs rrz&ConfigObj.validate..s%UUUAW_@T@Ta@T@T@Trc&g|] }|jv |SrG)rrGs rrz&ConfigObj.validate..s&TTT1a7CS>S>SQ>S>S>Sr)r ___many___rFrrIz"Value %r was provided as a sectionz)Section %r was provided as a single valuer)rBrr)r6rconfigobj.validater6r>rrrrrr8rrrrrrrr<rvalidaterranyr )rOrCrBrrr6rDr@rA unvalidatedincorrect_sectionsincorrect_scalarsrr8rrrr=r6rRs````` @@rrKzConfigObj.validateSsH ?& !:;;; 8?>>>>>(7%G E*1*<*L'(/(:(H%#*#5#> %04 #*#5#> &-&8&D#'  Wd+++* '* '* '* '* '* '* '* '* '* '* 'Z IIII'/III UUUU)<UUUTTTT (:TTT' O OE222W_,,%7;K2K2KCE88#+//r::$U+#266ubAA+E2 en"0. 58I318(I#O#O Hii + + +j)DD Z/ / /l+D  $ J Jen&4nUD#u5=y'J'J#))K& ; ;EH" ;"E ! :UB&55c::E ' ; ;EH" ;"E ! AEI&55c::E % ! !E$5I#5#5u~(0""5))) [*4*=*A*A%*L*L '1;1K1O1OPUWY1Z1Z'.MM)_SWahinaoMppECJ~~ $!  *  7#3 I  . .S .   ---I  4  5 rcr||d|_d|_dS)z@Clear ConfigObj instance and restore to 'freshly created' state.N)rrr6ryrs rresetzConfigObj.reset" s8  $(!!!rcPt|jtjst |j}i}t D]}|dkr t ||||<|j}||d<|| || ||dS)z Reload a ConfigObj from file. This method raises a ``ReloadError`` if the ConfigObj doesn't have a filename attribute pointing to a file. r6N) rmrrrr*rxrtryrrrz)rOrcurrent_optionsrr6s rreloadzConfigObj.reload- s$-)9:: -- =$ : :E $$%,T5%9%9OE " ". (2 %  ))) 8Z(((((r)NNNNTFTFFTNNFFFrK)Trb)FFN)-rDrErFrrrrrrrr r_single_line_single_single_line_double_multi_line_single_multi_line_doublerrTrrzrr;rrrrrrrrrrrrrrrrrrrrrKrQrTrGrrr$r$/s6<<rz     H RZ !    N"  0 1I6BJ  M2:    L%"*%>??$"*%>??#$:;;#$:;;$%78#%78M55 u   FMQEIAEAF38 7'7'7'7't]0]0]0@""""@===r1r1r1j2   d,d,d,N&###&DDDDN.#.#.#b 6 6 6F%%%*>>>8 > > >>>>!!!p&p&p&p&d?DLLLL^))))))))rr$c eZdZdZdZddZdS)r%a A simple validator. Can be used to check that all members expected are present. To use it, provide a configspec with all your members in (the value given will be ignored). Pass an instance of ``SimpleVal`` to the ``validate`` method of your ``ConfigObj``. ``validate`` will return ``True`` if all members are present, or a dictionary with True/False meaning present/missing. (Whole missing sections will be replaced with ``False``) ct|_dSrK)rr<rs rrzSimpleVal.__init__S s,rFc2|r||S)z9A dummy check method, always returns the value unchanged.)r<)rOr=memberr8s rr=zSimpleVal.checkV s!  (%%'' ' rNrc)rDrErFrrr=rGrrr%r%G sA  ---rr%c|g}g}|dkrt|S|dkst|trE||ddd|f|r|t|St |D]\}}|dkr t||tr.||t|||||b||dd||f|r|t|S)a An example function that will turn a nested dictionary of results (as returned by ``ConfigObj.validate``) into a flat list. ``cfg`` is the ConfigObj instance being checked, ``res`` is the results dictionary returned by ``validate``. (This is a recursive function, so you shouldn't use the ``levels`` or ``results`` arguments - they are used by the function.) Returns a list of keys that failed. Each member of the list is a tuple:: ([list of sections...], key, result) If ``validate`` was called with ``preserve_errors=False`` (the default) then ``result`` will always be ``False``. *list of sections* is a flattened list of sections that the key was found in. If the section was missing (or a section was expected and a scalar provided - or vice-versa) then key will be ``None``. If the value (or section) was missing then ``result`` will be ``False``. If ``validate`` was called with ``preserve_errors=True`` and a value was present, but failed the check, then ``result`` will be the exception object returned. You can use this as a string that describes the failure. For example *The value "3" is of the wrong type*. NTF) sortedrmrNrrrSrrrr-)cfgreslevelsresultsrrs rr-r-] sA@~ d{{g e||z#y11|qqq 4-...   JJLLLg399;;''.. c $;;  cggcllD ) )  MM#    3s8S&' : : : qqq 3,---- '??rrGcg}|fd|jD|jD]8}||jvr-|t|||fz9|S)a Find all the values and sections not in the configspec from a validated ConfigObj. ``get_extra_values`` returns a list of tuples where each tuple represents either an extra section, or an extra value. The tuples contain two values, a tuple representing the section the value is in and the name of the extra values. For extra values in the top level section the first member will be an empty tuple. For values in the 'foo' section the first member will be ``('foo',)``. For members in the 'bar' subsection of the 'foo' section the first member will be ``('foo', 'bar')``. NOTE: If you call ``get_extra_values`` on a ConfigObj instance that hasn't been validated it will return an empty list. cg|]}|fSrGrG)rrg_prepends rrz$get_extra_values.. s???T4 ???r)r)rrr.)confrerRrgs ` rr.r. s" CJJ????T->???@@@ II t( ( ( JJ'T Hw4FGG H H H Jrrb)rG);rrr+codecsrrrrr_versionrr=rrrrrrrrrrobjectr__all__rrMAX_INTERPOL_DEPTHrxrBrNr,rI_builderr:rrr r!rr*r"r#r&r'r)r(r+rrrrrrrr$r%r-r.rGrrrms;  BBBBBBBBBBBB !!!!!!   o(( #          (    555     &(( *'(@@@     )   4444444444f444444n 799,,,,,[,,,> FFFFF'FFF^ n 77777777CCCCC/CCC/////!3///+++++.+++ x$x$x$x$x$&x$x$x$x##### 3###)))))/)))6.% ###b -b -b -b -b -db -b -b -JT)T)T)T)T)T)T)T)p(,9999x4HGr