PKc@s3ddlmZddlZddlZddlZddlmZmZmZm Z e a ide fe6ddfe6ddfe 6ddfe6Z idd6dd6dd 6dd 6dd6dd 6dd 6dd6dd 6dd6dd6dd6dd6dd6dd6Z ied6ed6ed6e d6ee 6ZdZdZdZdZdZdZdZeZdZyeWnek rdZnXddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.fZd/Zd0Zd1Zi ed26e d36ed46e d56e d66e d76ed86e d96e d:6e d;6e d<6e d=6Z!d>Z"d,e#fd?YZ$d@efdAYZ%e%Z&dBZ'de(fdCYZ)d e)fdDYZ*d!e)fdEYZ+d*e,fdFYZ-d"e)fdGYZ.d#e)fdHYZ/d&e)fdIYZ0d'e0fdJYZ1d)e)fdKYZ2d(e0fdLYZ3d+e)fdMYZ4dNefdOYZ5dPe5fdQYZ6dRe5fdSYZ7ie6d/6e7dT6Z8dUZ9dVe:fdWYZ;d$e;fdXYZ<d%efdYYZ=e e dZZ>fd[Z?dS(\i(t generatorsN(tBOM_UTF8t BOM_UTF16t BOM_UTF16_BEt BOM_UTF16_LEtutf_8tutf16_betutf_16tutf16_letu16tutf16sutf-16t utf_16_besutf-16bet utf_16_lesutf-16letu8tutftutf8sutf-8cCstj|jdkS(NR(tBOM_LISTtgettlower(tencoding((s-/usr/lib/python2.7/site-packages/configobj.pyt match_utf8Gss'%s's"%s"s%ss '"s"""%s"""s'''%s'''s4.7.2cCsx|D]}|rtSqWtS(N(tTruetFalse(titerabletentry((s-/usr/lib/python2.7/site-packages/configobj.pytany[s t __version__tDEFAULT_INDENT_TYPEtDEFAULT_INTERPOLATIONtConfigObjErrort NestingErrort ParseErrortDuplicateErrortConfigspecErrort ConfigObjt SimpleValtInterpolationErrortInterpolationLoopErrortMissingInterpolationOptiontRepeatSectionErrort ReloadErrort UnreprErrort UnknownTypetflatten_errorstget_extra_valuest configparsers i t interpolationt raise_errorst list_valuest create_emptyt file_errort configspect stringifyt indent_typeRtdefault_encodingtunreprtwrite_empty_valuescCsVtdkrddland|}tj|}|jdjdjdS(Nisa=ii(tcompilertNonetparset getChildren(tstp((s-/usr/lib/python2.7/site-packages/configobj.pytgetObjs   cBseZRS((t__name__t __module__(((s-/usr/lib/python2.7/site-packages/configobj.pyR*stBuildercBsbeZdZdZdZdZdZdZdZdZ dZ d Z RS( cCsGt|d|jjd}|dkr=t|jjn||S(Ntbuild_(tgetattrt __class__R@R:R*(tselftotm((s-/usr/lib/python2.7/site-packages/configobj.pytbuilds cCst|j|jS(N(tmapRIR<(RFRG((s-/usr/lib/python2.7/site-packages/configobj.pyt build_ListscCs|jS(N(tvalue(RFRG((s-/usr/lib/python2.7/site-packages/configobj.pyt build_ConstscCsIi}tt|j|j}x|D]}|j||\$) | # Two $ signs (?P[_a-z][_a-z0-9]*) | # $name format {(?P[^}]*)} # ${name} format ) cCs|jdp|jd}|dk rL|j|\}}|||fS|jddk rqd|jdfSd|jdfS(Ntnamedtbracedtescaped(RR:Rt _delimiter(RFR|RzRLRs((s-/usr/lib/python2.7/site-packages/configobj.pyRvs  ( R@RARmRRRRt IGNORECASEtVERBOSERtRv(((s-/usr/lib/python2.7/site-packages/configobj.pyRs ttemplatecGs|j||S(N(t__new__(tclstargs((s-/usr/lib/python2.7/site-packages/configobj.pyt __newobj__sRcBsReZdZdZdZd!d!dZdZdZdZ e dZ dZ d!d Z d Zed Zd Zd Zd!dZdZdZdZdZdZeZdZdZeZde_dZdZdZe e dZ!dZ"dZ#dZ$dZ%dZ&d Z'RS("s 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. cCs,tj||d|jj|ddS(Nii(tdicttupdatet__dict__(RFtstate((s-/usr/lib/python2.7/site-packages/configobj.pyt __setstate__scCs(t||jf}t|jf|fS(N(RRRRE(RFR((s-/usr/lib/python2.7/site-packages/configobj.pyt __reduce__scCs{|dkri}ntj|||_||_||_||_|jx$|jD]\}}|||t}n|j}tj|d}|dkrxt |j_|S||}|_nX|j ||S(N( t_interpolation_enginetAttributeErrorRR.RRRtinterpolation_enginesRR:RR(RFRzRLtengineRVtclass_((s-/usr/lib/python2.7/site-packages/configobj.pyt _interpolates        cstj}jjrt|tr=j|St|trfd}g|D]}||^qe}||kr|Sqn|S(s+Fetch the item and do string interpolation.cs#t|trj|S|S(N(R[t basestringR(R(RzRF(s-/usr/lib/python2.7/site-packages/configobj.pyt_check<s(Rt __getitem__RR.R[RRtlist(RFRzRRRtnew((RzRFs-/usr/lib/python2.7/site-packages/configobj.pyR5s   c Cst|ts"td|n||jkrNg|j|A version of ``get`` that doesn't bypass string interpolation.N(tKeyError(RFRztdefault((s-/usr/lib/python2.7/site-packages/configobj.pyRs  cCs#x|D]}|||| v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised' (RtMISSING(RFRzRR((s-/usr/lib/python2.7/site-packages/configobj.pytpops   cCsJ|j|j}|s%tdn|d}||}||=||fS(sPops the first (key,val)s": 'popitem(): dictionary is empty'i(RRR(RFtsequenceRzR((s-/usr/lib/python2.7/site-packages/configobj.pytpopitems  cCsPtj|g|_g|_i|_i|_d|_g|_g|_ dS(s 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( RtclearRRRRR:R3RR(RF((s-/usr/lib/python2.7/site-packages/configobj.pyRs       cCs3y ||SWn tk r.|||<||SXdS(s:A version of setdefault that sets sequence if appropriate.N(R(RFRzR((s-/usr/lib/python2.7/site-packages/configobj.pyt setdefaults    cCst|j|j|jS(s8D.items() -> list of D's (key, value) pairs, as 2-tuples(tzipRRtvalues(RF((s-/usr/lib/python2.7/site-packages/configobj.pytitemsscCs|j|jS(sD.keys() -> list of D's keys(RR(RF((s-/usr/lib/python2.7/site-packages/configobj.pytkeysscCs%g|j|jD]}||^qS(s D.values() -> list of D's values(RR(RFRz((s-/usr/lib/python2.7/site-packages/configobj.pyRscCst|jS(s=D.iteritems() -> an iterator over the (key, value) items of D(RNR(RF((s-/usr/lib/python2.7/site-packages/configobj.pyRscCst|j|jS(s.D.iterkeys() -> an iterator over the keys of D(RNRR(RF((s-/usr/lib/python2.7/site-packages/configobj.pytiterkeysscCst|jS(s2D.itervalues() -> an iterator over the values of D(RNR(RF((s-/usr/lib/python2.7/site-packages/configobj.pyt itervaluessc sYfd}ddjgjjD](}dt|t||f^q)S(sx.__repr__() <==> repr(x)cs1y |SWntk r,tj|SXdS(N(R&RR(Rz(RF(s-/usr/lib/python2.7/site-packages/configobj.pyt_getvals  s{%s}s, s%s: %s(RxRRtrepr(RFRRz((RFs-/usr/lib/python2.7/site-packages/configobj.pyt__repr__s sx.__str__() <==> str(x)cCsi}x||D]t}||}t|tr;|j}n<t|trYt|}nt|trwt|}n|||>> n = a.dict() >>> n == a 1 >>> n is a 0 (R[RRRRT(RFtnewdictRt this_entry((s-/usr/lib/python2.7/site-packages/configobj.pyRs   cCsmxf|jD]X\}}||kr[t||tr[t|tr[||j|q |||>> 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(RR[Rtmerge(RFRRzR((s-/usr/lib/python2.7/site-packages/configobj.pyRs cCs||jkr|j}n+||jkr6|j}ntd||j|}||}tj||tj||||j||j|||j |}|j |}|j |=|j |=||j |<||j |>> 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'}}) R/tcall_on_sections(trangeRyRt ExceptionRRtwalk( RFtfunctionR/RtkeywargstoutRQRR((s-/usr/lib/python2.7/site-packages/configobj.pyRWs:/        cCs||}|tkrtS|tkr*tSy3t|tsHtn|jj|jSWn!tk rtd|nXdS(s_ 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 s$Value "%s" is neither True nor FalseN( RRR[RRRt_boolsRR(RFRzR((s-/usr/lib/python2.7/site-packages/configobj.pytas_bools     cCst||S(si 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' (tint(RFRz((s-/usr/lib/python2.7/site-packages/configobj.pytas_intscCst||S(s 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') 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') 3.2000000000000002 (RY(RFRz((s-/usr/lib/python2.7/site-packages/configobj.pytas_floatscCs0||}t|ttfr)t|S|gS(sU 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] (R[RTR(RFRztresult((s-/usr/lib/python2.7/site-packages/configobj.pytas_lists  cCsF|j|}tj|||||jkrB|jj|n|S(s 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. (RRRRR(RFRzR((s-/usr/lib/python2.7/site-packages/configobj.pytrestore_defaults cCsGx|jD]}|j|q Wx|jD]}||jq+WdS(s' 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(RRRtrestore_defaults(RFRzRs((s-/usr/lib/python2.7/site-packages/configobj.pyR+s N((R@RARmRRR:RkRRRRRRRRRRRRRRRRRRt__iter__RRt__str__RRRRRRRRRRR(((s-/usr/lib/python2.7/site-packages/configobj.pyRsH      ;                T ,    cBsFeZdZejdejZejdejZejdejZejdejZ ejdejZ ejdZ ejdZ ejdZ ejd Zie e fd 6e efd 6Zied 6ed 6ed6ed6ed6ed6ed6ed6Zd/d/d/d/eeeeeed/d/eeedZdZd/dZdZdZdZdZdZdZdZdZdZd Z ed!Z!d"Z"d#Z#d$Z$d%Z%d&Z&d'Z'd(Z(d)Z)d*Z*d/d/d+Z+eed/d,Z,d-Z-d.Z.RS(0s2An object to read, create, and write config files.s^ # line start (\s*) # indentation ( # keyword (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'"=].*?) # no quotes ) \s*=\s* # divider (.*) # value (including list values and comments) $ # line end s=^ (\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 $s^ (?: (?: ( (?: (?: (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\#][^,\#]*?) # unquoted ) \s*,\s* # comma )* # match all list items ending in a comma (if any) ) ( (?:".*?")| # double quotes (?:'.*?')| # single quotes (?:[^'",\#\s][^,]*?)| # unquoted (?:(?infile must be a filename, file like object, or list of lines.is s s s at line %s.iis2Parsing failed with several errors. First error %s(s s s (s s s ("R[RtfilenametostpathtisfiletopenR tcloseR2RnR1twriteRRTRR"t_errorsR:t_handle_configspecR3RDRRZt _handle_bomtendswithtnewlinestrstript_parseRiRyRterrorstconfig( RFRR3thRRhRtinfoRpterror((R s-/usr/lib/python2.7/site-packages/configobj.pyRsl              %         cCs |dkrt}nd|_g|_|d|_|d|_|d|_|d|_|d|_|d|_ |d|_ |d|_ |d |_ t |_d|_|d |_|d |_g|_g|_d|_|jrt |_ntj|dS( NR/R.R0R1R2R4R5RR6R8R7(R:RR RR/R.R0R1R2R4R5RR6RtBOMRR8R7tinitial_commentt final_commentR3RRR(RFR((s-/usr/lib/python2.7/site-packages/configobj.pyR>s.                      c sYfd}ddjgjjD](}dt|t||f^q)S(Ncs1y |SWntk r,tj|SXdS(N(R&RR(Rz(RF(s-/usr/lib/python2.7/site-packages/configobj.pyR_s  sConfigObj({%s})s, s%s: %s(RxRRR(RFRRz((RFs-/usr/lib/python2.7/site-packages/configobj.pyR^s cCsI|jdk r7|jjtkr7|j||jSt|ttfrY|d}n|}|jdk rnt|jj}|dkrxKtj D]=\}\}}|sqn|j |r|j||SqW|j||jSt |}|j |s|j||jS|t |}t|ttfrL||d>> 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') R2s# RsRRgitmodeRtwin32s s twbN(.R5R:RR,R.RRR0R5R#RRRRRRtlstripRwRR[RRvtextendRRuR R RtencodeRRRRRRR tlinesepRDRxtsystplatformRxRRRR(RFtoutfileRsRtcstcsptint_valRht stripped_lineRtRt comment_lineRRLtlR(toutputR((s-/usr/lib/python2.7/site-packages/configobj.pyRs                 ('  '    c sdkrjdkr*tdnrLddlm}|_nrjj_jj_jj_jj _ jj _ jj _ qnjj fd}it }t }gjD]} | kr| ^q} gjD]} | jkr6| ^q6} gjD]} | jkra| ^qa} xjD]} | dkrqn| jks| jkr!t }d}r1| jkr1jj| gj| <jj| dj| s   "            8     |   g<