eaiovnaovbqoebvqoeavibavo 3 C]o/@sdZddlZddlmZmZmZmZmZmZm Z m Z ddlm Z m Z m Z mZddlZddlmZGdddeZGd d d eZGd d d eZGd ddeZdS)a(Compatibility interfaces for ConfigParser Interfaces of ConfigParser, RawConfigParser and SafeConfigParser should be completely identical to the Python standard library versions. Tested with the unit tests included with Python-2.3.4 The underlying INIConfig object can be accessed as cfg.data N)DuplicateSectionErrorNoSectionError NoOptionErrorInterpolationMissingOptionErrorInterpolationDepthErrorInterpolationSyntaxError DEFAULTSECTMAX_INTERPOLATION_DEPTH)ErrorInterpolationErrorMissingSectionHeaderError ParsingError)inic @seZdZdefddZddZddZdd Zd d Zd d Z ddZ ddZ d+ddZ d,ddZ ddZddZddZdddddddddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*ZdS)-RawConfigParserNcCs$|tkrtdtj||d|_dS)NzCustom dict types not supported)defaultsZoptionxformsource)dict ValueErrorrZ INIConfigdata)selfrZ dict_typer/usr/lib/python3.6/compat.py__init__ szRawConfigParser.__init__cCs|jS)N)lower)rZ optionstrrrr optionxform%szRawConfigParser.optionxformcCs.i}|jj}x|jD]}|j|||<qW|S)N)rZ _defaultsZ_options _compat_get)rdZsecobjnamerrrr(s  zRawConfigParser.defaultscCs t|jS)z3Return a list of section names, excluding [DEFAULT])listr)rrrrsections/szRawConfigParser.sectionscCs<|jdkrtd||j|r,t|n |jj|dS)zCreate a new section in the configuration. Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT or any of its case-insensitive variants. defaultzInvalid section name: %sN)rr has_sectionrrZ_new_namespace)rsectionrrr add_section3s    zRawConfigParser.add_sectioncCs ||jkS)z~Indicate whether the named section is present in the configuration. The DEFAULT section is not acknowledged. )r)rr"rrrr!DszRawConfigParser.has_sectioncCs$||jkrt|j|St|dS)z9Return a list of option names for the given section name.N)rrr)rr"rrroptionsKs zRawConfigParser.optionsc Csjg}t|tjr|g}xN|D]F}y t|}Wntk rBwYnX|j||jj||jqW|S)aRead and parse a filename or a list of filenames. Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user's home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given. ) isinstancesix string_typesopenIOErrorappendr_readfpclose)r filenamesZ files_readfilenamefprrrreadRs       zRawConfigParser.readcCs|jj|dS)aLike read() but the argument must be a file-like object. The `fp' argument must have a `readline' method. Optional second argument is the `filename', which if not given, is taken from fp.name. If fp has no `name' attribute, `' is used. N)rr+)rr/r.rrrreadfpiszRawConfigParser.readfpcCsT|j|st||dk r*||kr*||}|j|}||krF|j|St||dS)N)r!rrrr)rr"optionvarsvaluesecrrrgetss   zRawConfigParser.getcCsH||jkr|St|||}|j||||SdS)aGet an option value for a given section. All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw' is true. Additional substitutions may be provided using the `vars' argument, which must be a dictionary whose contents overrides any pre-existing defaults. The section DEFAULT is special. N)r r!rrrr6rN _interpolate)rr"r2rawr3r4rrrrr6s   zConfigParser.getcCs|}t}x`|rh|d8}d|krdy ||}Wqftk r`}zt||||jdWYdd}~XqfXq Pq W|jddkrt||||S)Nrz%(r)r rPrargsfindr)rr"r2rawvalr3r4deptherrrrUs & zConfigParser._interpolatecstkrj rt|dkr4tj}n8g}x$jD]}||krD|j|qDW|j|jd|kr~|jdt ||rfdd|DSfdd|DSdS)aReturn a list of tuples with (name, value) for each option in the section. All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw' is true. Additional substitutions may be provided using the `vars' argument, which must be a dictionary whose contents overrides any pre-existing defaults. The section DEFAULT is special. NrKcsg|]}||fqSrr).0r2)rrr sz&ConfigParser.items..cs$g|]}|j||fqSr)rU)r]r2)rr"rrrr^s) r r!rrrr*extendkeysremoverN)rr"rVr3r$xr)rr"rrr8s"    zConfigParser.items)FN)FN)rKrLrMr6rUr8rrrrrTs rTc@sDeZdZejdZejdZddZddZejdj Z ddZ d S) SafeConfigParserz %\(([^)]+)\)sz%[^%]|%$cCsZt|tjstd|jjd|}|jj|}|rFtd||j ft j ||||dS)Nzoption values must be stringsz1invalid interpolation syntax in %r at position %d) r%r&r' TypeError _interpvar_resub_badpercent_researchrstartrTrF)rr"r2r4Z tmp_valuemrrrrFs  zSafeConfigParser.setcCs"g}|j|||||ddj|S)Nrrd)_interpolate_somejoin)rr"r2rZr3LrrrrU-szSafeConfigParser._interpolatec CsT|tkrt|||x8|rN|jd}|dkr>|j|dS|dkrd|j|d|||d}|dd}|dkr|jd|dd}q|dkr8|j|} | dkrt||d|| jd} || jd}y || } Wn$tk rt |||| YnXd| kr,|j ||| |||dn |j| qt||dt |qWdS)N%rr(z'bad interpolation variable reference %rz+'%' must be followed by '%' or '(', found: ) r rrYr*_interpvar_matchrgroupendrPrrlrepr) rr2Zaccumrestr"mapr[pcrkvarrCrrrrl5sB               z"SafeConfigParser._interpolate_someN) rKrLrMrecompilerfrhrFrUmatchrrrlrrrrrcs    rc)rSr{Z configparserrrrrrrr r r r r rr&rdrobjectrrNrTrcrrrr s(   N