fc@s\dZddlmZddlmZmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddddd d d d d dddddgZdZdZGdddeZGdddeZGdddeZGdddeZGdddeZGdd d eZGdddeZGdd d eZGdd d eZGd d d eZGd!d d eZeZGd"d#d#ZGd$d%d%eZ Gd&d'd'eZ!Gd(d)d)eZ"Gd*ddeZ#Gd+dde#Z$Gd,dde$Z%Gd-d.d.eZ&dS(/uConfiguration file parser. A configuration file consists of sections, lead by a "[section]" header, and followed by "name: value" entries, with continuations and such in the style of RFC 822. Intrinsic defaults can be specified by passing them into the ConfigParser constructor as a dictionary. class: ConfigParser -- responsible for parsing a list of configuration files, and managing the parsed database. methods: __init__(defaults=None, dict_type=_default_dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True): Create the parser. When `defaults' is given, it is initialized into the dictionary or intrinsic defaults. The keys must be strings, the values must be appropriate for %()s string interpolation. When `dict_type' is given, it will be used to create the dictionary objects for the list of sections, for the options within a section, and for the default values. When `delimiters' is given, it will be used as the set of substrings that divide keys from values. When `comment_prefixes' is given, it will be used as the set of substrings that prefix comments in empty lines. Comments can be indented. When `inline_comment_prefixes' is given, it will be used as the set of substrings that prefix comments in non-empty lines. When `strict` is True, the parser won't allow for any section or option duplicates while reading from a single source (file, string or dictionary). Default is True. When `empty_lines_in_values' is False (default: True), each empty line marks the end of an option. Otherwise, internal empty lines of a multiline option are kept as part of the value. When `allow_no_value' is True (default: False), options without values are accepted; the value presented for these is None. sections() Return all the configuration section names, sans DEFAULT. has_section(section) Return whether the given section exists. has_option(section, option) Return whether the given option exists in the given section. options(section) Return list of configuration options for the named section. read(filenames, encoding=None) Read and parse the list of named configuration files, given by name. A single filename is also allowed. Non-existing files are ignored. Return list of successfully read files. read_file(f, filename=None) Read and parse one configuration file, given as a file object. The filename defaults to f.name; it is only used in error messages (if f has no `name' attribute, the string `' is used). read_string(string) Read configuration from a given string. read_dict(dictionary) Read configuration from a dictionary. Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order. Values are automatically converted to strings. get(section, option, raw=False, vars=None, fallback=_UNSET) Return a string value for the named option. All % interpolations are expanded in the return values, based on the defaults passed into the constructor and the DEFAULT section. Additional substitutions may be provided using the `vars' argument, which must be a dictionary whose contents override any pre-existing defaults. If `option' is a key in `vars', the value from `vars' is used. getint(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to an integer. getfloat(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a float. getboolean(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a boolean (currently case insensitively defined as 0, false, no, off for False, and 1, true, yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) If section is given, return a list of tuples with (name, value) for each option in the section. Otherwise, return a list of tuples with (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. remove_option(section, option) Remove the given option from the given section. set(section, option, value) Set the given option. write(fp, space_around_delimiters=True) Write the configuration state in .ini format. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces. i(uMutableMapping(u OrderedDictuChainMapNuNoSectionErroruDuplicateOptionErroruDuplicateSectionErroru NoOptionErroruInterpolationErroruInterpolationDepthErroruInterpolationSyntaxErroru ParsingErroruMissingSectionHeaderErroru ConfigParseruSafeConfigParseruRawConfigParseru DEFAULTSECTuMAX_INTERPOLATION_DEPTHuDEFAULTi cBs;|EeZdZdZdddZddZeZdS(uErroru'Base class for ConfigParser exceptions.ucCs||_tj||dS(N(umessageu Exceptionu__init__(uselfumsg((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s uError.__init__cCs|jS(N(umessage(uself((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__repr__suError.__repr__N(u__name__u __module__u __qualname__u__doc__u__init__u__repr__u__str__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuErrors uErrorcBs&|EeZdZdZddZdS(uNoSectionErroru2Raised when no section matches a requested option.cCs0tj|d|f||_|f|_dS(NuNo section: %r(uErroru__init__usectionuargs(uselfusection((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s uNoSectionError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuNoSectionErrorscBs,|EeZdZdZddddZdS(uDuplicateSectionErroruRaised when a section is repeated in an input source. Possible repetitions that raise this exception are: multiple creation using the API or in strict parsers when a section is found more than once in a single input file, string or dictionary. cCst|dg}|dk rxdt|g}|dk rU|jdj|n|jd|j||}n|jddtj|dj|||_ ||_ ||_ |||f|_ dS(Nu already existsuWhile reading from u [line {0:2d}]u : section iuSection u( urepruNoneuappenduformatuextenduinsertuErroru__init__ujoinusectionusourceulinenouargs(uselfusectionusourceulinenoumsgumessage((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s        uDuplicateSectionError.__init__N(u__name__u __module__u __qualname__u__doc__uNoneu__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuDuplicateSectionErrorscBs,|EeZdZdZddddZdS(uDuplicateOptionErroruRaised by strict parsers when an option is repeated in an input source. Current implementation raises this exception only when an option is found more than once in a single file, string or dictionary. cCst|dt|dg}|dk rdt|g}|dk ra|jdj|n|jd|j||}n|jddtj|dj|||_ ||_ ||_ ||_ ||||f|_ dS( Nu in section u already existsuWhile reading from u [line {0:2d}]u : option iuOption u(urepruNoneuappenduformatuextenduinsertuErroru__init__ujoinusectionuoptionusourceulinenouargs(uselfusectionuoptionusourceulinenoumsgumessage((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s           uDuplicateOptionError.__init__N(u__name__u __module__u __qualname__u__doc__uNoneu__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuDuplicateOptionErrorscBs&|EeZdZdZddZdS(u NoOptionErroru!A requested option was not found.cCs?tj|d||f||_||_||f|_dS(NuNo option %r in section: %r(uErroru__init__uoptionusectionuargs(uselfuoptionusection((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s    uNoOptionError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyu NoOptionErrorscBs&|EeZdZdZddZdS(uInterpolationErroru0Base class for interpolation-related exceptions.cCs8tj||||_||_|||f|_dS(N(uErroru__init__uoptionusectionuargs(uselfuoptionusectionumsg((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s  uInterpolationError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuInterpolationErrorscBs&|EeZdZdZddZdS(uInterpolationMissingOptionErroruAA string substitution required a setting which was not available.cCsNd||||f}tj||||||_||||f|_dS(NuNBad value substitution: section: [%s] option : %s key : %s rawval : %s (uInterpolationErroru__init__u referenceuargs(uselfuoptionusectionurawvalu referenceumsg((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s  u(InterpolationMissingOptionError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuInterpolationMissingOptionErrorsuInterpolationMissingOptionErrorcBs|EeZdZdZdS(uInterpolationSyntaxErroruRaised when the source text contains invalid syntax. Current implementation raises this exception when the source text into which substitutions are made does not conform to the required syntax. N(u__name__u __module__u __qualname__u__doc__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuInterpolationSyntaxErrorscBs&|EeZdZdZddZdS(uInterpolationDepthErroru0Raised when substitutions are nested too deeply.cCs?d|||f}tj|||||||f|_dS(NuSValue interpolation too deeply recursive: section: [%s] option : %s rawval : %s (uInterpolationErroru__init__uargs(uselfuoptionusectionurawvalumsg((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__ su InterpolationDepthError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuInterpolationDepthErrorscBs_|EeZdZdZd d ddZeddZejddZddZ d S( u ParsingErroru>Raised when a configuration file does not follow legal syntax.cCs}|r|rtdn,| r8| r8tdn|rG|}ntj|d|||_g|_|f|_dS(Nu:Cannot specify both `filename' and `source'. Use `source'.u%Required argument `source' not given.u"Source contains parsing errors: %r(u ValueErroruErroru__init__usourceuerrorsuargs(uselfusourceufilename((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__s    uParsingError.__init__cCstjdtdd|jS(uDeprecated, use `source'.uSThe 'filename' attribute will be removed in future versions. Use 'source' instead.u stackleveli(uwarningsuwarnuDeprecationWarningusource(uself((u1/opt/alt/python33/lib64/python3.3/configparser.pyufilename&s uParsingError.filenamecCs#tjdtdd||_dS(uDeprecated, user `source'.uSThe 'filename' attribute will be removed in future versions. Use 'source' instead.u stackleveliN(uwarningsuwarnuDeprecationWarningusource(uselfuvalue((u1/opt/alt/python33/lib64/python3.3/configparser.pyufilename0s cCs3|jj||f|jd||f7_dS(Nu [line %2d]: %s(uerrorsuappendumessage(uselfulinenouline((u1/opt/alt/python33/lib64/python3.3/configparser.pyuappend:suParsingError.appendN( u__name__u __module__u __qualname__u__doc__uNoneu__init__upropertyufilenameusetteruappend(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyu ParsingErrors   cBs&|EeZdZdZddZdS(uMissingSectionHeaderErroru@Raised when a key-value pair is found before any section header.cCsNtj|d|||f||_||_||_|||f|_dS(Nu7File contains no section headers. file: %r, line: %d %r(uErroru__init__usourceulinenoulineuargs(uselfufilenameulinenouline((u1/opt/alt/python33/lib64/python3.3/configparser.pyu__init__Bs   u"MissingSectionHeaderError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuMissingSectionHeaderError?scBsJ|EeZdZdZddZddZddZdd Zd S( u InterpolationuBDummy interpolation that passes the value through with no changes.cCs|S(N((uselfuparserusectionuoptionuvalueudefaults((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_getVsuInterpolation.before_getcCs|S(N((uselfuparserusectionuoptionuvalue((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_setYsuInterpolation.before_setcCs|S(N((uselfuparserusectionuoptionuvalue((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_read\suInterpolation.before_readcCs|S(N((uselfuparserusectionuoptionuvalue((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_write_suInterpolation.before_writeN(u__name__u __module__u __qualname__u__doc__u before_getu before_setu before_readu before_write(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyu InterpolationSs    u InterpolationcBsM|EeZdZdZejdZddZddZddZ d S( uBasicInterpolationu!Interpolation as implemented in the classic ConfigParser. The option values can contain format strings which refer to other values in the same section, or values in the special default section. For example: something: %(dir)s/whatever would resolve the "%(dir)s" to the value of dir. All reference expansions are done late, on demand. If a user needs to use a bare % in a configuration file, she can escape it by writing %%. Other % usage is considered a user error and raises `InterpolationSyntaxError'.u %\(([^)]+)\)scCs2g}|j||||||ddj|S(Niu(u_interpolate_someujoin(uselfuparserusectionuoptionuvalueudefaultsuL((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_gettsuBasicInterpolation.before_getcCsY|jdd}|jjd|}d|krUtd||jdfn|S(Nu%%uu%u1invalid interpolation syntax in %r at position %d(ureplaceu_KEYCREusubu ValueErrorufind(uselfuparserusectionuoptionuvalueu tmp_value((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_setys  uBasicInterpolation.before_setc Cs|tkr!t|||nx|r|jd}|dkrV|j|dS|dkr|j|d|||d}n|dd} | dkr|jd|dd}q$| dkr|jj|} | dkr t||d|n|j| j d} || j d}y|| } Wn't k rpt |||| YnXd| kr|j |||| |||dq|j| q$t||d|fq$WdS(Nu%iiiu(u'bad interpolation variable reference %ru/'%%' must be followed by '%%' or '(', found: %r(uMAX_INTERPOLATION_DEPTHuInterpolationDepthErrorufinduappendu_KEYCREumatchuNoneuInterpolationSyntaxErroru optionxformugroupuenduKeyErroruInterpolationMissingOptionErroru_interpolate_some( uselfuparseruoptionuaccumurestusectionumapudepthupucumuvaruv((u1/opt/alt/python33/lib64/python3.3/configparser.pyu_interpolate_somesD            u$BasicInterpolation._interpolate_someN( u__name__u __module__u __qualname__u__doc__ureucompileu_KEYCREu before_getu before_setu_interpolate_some(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuBasicInterpolationcs    uBasicInterpolationcBsM|EeZdZdZejdZddZddZddZ d S( uExtendedInterpolationuyAdvanced variant of interpolation, supports the syntax used by `zc.buildout'. Enables interpolation between sections.u \$\{([^}]+)\}cCs2g}|j||||||ddj|S(Niu(u_interpolate_someujoin(uselfuparserusectionuoptionuvalueudefaultsuL((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_getsu ExtendedInterpolation.before_getcCsY|jdd}|jjd|}d|krUtd||jdfn|S(Nu$$uu$u1invalid interpolation syntax in %r at position %d(ureplaceu_KEYCREusubu ValueErrorufind(uselfuparserusectionuoptionuvalueu tmp_value((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_sets  u ExtendedInterpolation.before_setcCs|tkr!t|||nxj|r|jd}|dkrV|j|dS|dkr|j|d|||d}n|dd} | dkr|jd|dd}q$| dkrq|jj|} | dkr t||d|n| jdj d} || j d}|} |} yt | dkrz|j | d} || }nct | dkr| d} |j | d} |j | | dd }nt||d |fWn9tttfk rt|||dj| YnXd|kra|j|| ||| t|j| dd |dq|j|q$t||d |fq$WdS( Nu$iiiu{u'bad interpolation variable reference %ru:urawuMore than one ':' found: %ru-'$' must be followed by '$' or '{', found: %rT(uMAX_INTERPOLATION_DEPTHuInterpolationDepthErrorufinduappendu_KEYCREumatchuNoneuInterpolationSyntaxErrorugroupusplituendulenu optionxformugetuTrueuKeyErroruNoSectionErroru NoOptionErroruInterpolationMissingOptionErrorujoinu_interpolate_someudictuitems(uselfuparseruoptionuaccumurestusectionumapudepthupucumupathusectuoptuv((u1/opt/alt/python33/lib64/python3.3/configparser.pyu_interpolate_somes\              u'ExtendedInterpolation._interpolate_someN( u__name__u __module__u __qualname__u__doc__ureucompileu_KEYCREu before_getu before_setu_interpolate_some(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuExtendedInterpolations   uExtendedInterpolationcBsS|EeZdZdZejdZddZddZe ddZ d S( uLegacyInterpolationu{Deprecated interpolation used in old versions of ConfigParser. Use BasicInterpolation or ExtendedInterpolation instead.u%\(([^)]*)\)s|.c Cs|}t}x|r|d8}|rd|krtj|jd|}|jj||}y||}Wqtk r} z!t|||| jdWYdd} ~ XqXqPqW|rd|krt |||n|S(Niu%(uparseri( uMAX_INTERPOLATION_DEPTHu functoolsupartialu_interpolation_replaceu_KEYCREusubuKeyErroruInterpolationMissingOptionErroruargsuInterpolationDepthError( uselfuparserusectionuoptionuvalueuvarsurawvaludepthureplaceue((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_gets"   /uLegacyInterpolation.before_getcCs|S(N((uselfuparserusectionuoptionuvalue((u1/opt/alt/python33/lib64/python3.3/configparser.pyu before_set suLegacyInterpolation.before_setcCs:|jd}|dkr%|jSd|j|SdS(Niu%%(%s)s(ugroupuNoneu optionxform(umatchuparserus((u1/opt/alt/python33/lib64/python3.3/configparser.pyu_interpolation_replaces  u*LegacyInterpolation._interpolation_replaceN( u__name__u __module__u __qualname__u__doc__ureucompileu_KEYCREu before_getu before_setu staticmethodu_interpolation_replace(u __locals__((u1/opt/alt/python33/lib64/python3.3/configparser.pyuLegacyInterpolations   uLegacyInterpolationcsF|EeZdZdZdZdZdZeZe j ee j Z e j ej dde j Ze j ej dde j Ze j dZidnd6dnd 6dnd 6dnd 6dod 6dod 6dod6dod6ZddpddqddrddnddndededredoddZddZdd Zd!d"Zd#d$Zd%d&Zdrd'd(Zdrd)d*Zd+d,d-Z d.d/d0Z!drd1d2Z"d3dod4drd5ed6d7Z#d8d9Z$d3dod4drd5ed:d;Z%d3dod4drd5ed<d=Z&d3dod4drd5ed>d?Z'edodrfd@dAZ(dBdCZ)dDdEZ*dFdGZ+drdHdIZ,dndJdKZ-dLdMZ.dNdOZ/dPdQZ0dRdSZ1dTdUZ2dVdWZ3dXdYZ4dZd[Z5d\d]Z6d^d_Z7d`daZ8dbdcZ9dddeZ:dfdgZ;dhdidjdidkdidldmZ<S(suRawConfigParseru,ConfigParser that does not do interpolation.u \[ # [ (?P
[^]]+) # very permissive! \] # ] u (?P