MINI MINI MANI MO

Path : /lib/python2.7/site-packages/iniparse/
File Upload :
Current File : //lib/python2.7/site-packages/iniparse/compat.pyc

ó
žµäKc@sÖdZddlZddlmZmZmZmZmZmZm	Z	m
Z
ddlmZmZm
Z
mZddlZdefd„ƒYZdefd„ƒYZd	efd
„ƒYZdefd„ƒYZdS(
s(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
iÿÿÿÿN(tDuplicateSectionErrortNoSectionErrort
NoOptionErrortInterpolationMissingOptionErrortInterpolationDepthErrortInterpolationSyntaxErrortDEFAULTSECTtMAX_INTERPOLATION_DEPTH(tErrortInterpolationErrortMissingSectionHeaderErrortParsingErrortRawConfigParsercBsýeZded„Zd„Zd„Zd„Zd„Zd„Z	d„Z
d„Zdd„Zdd	„Z
d
„Zd„Zd„Zied
6ed6ed6ed6ed6ed6ed6ed6Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs:|tkrtdƒ‚ntjd|d|ƒ|_dS(NsCustom dict types not supportedtdefaultstoptionxformsource(tdictt
ValueErrortinit	INIConfigtdata(tselfR
t	dict_type((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt__init__scCs
|jƒS(N(tlower(Rt	optionstr((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytoptionxform#scCs=i}|jj}x$|jD]}|j|ƒ||<qW|S(N(Rt	_defaultst_optionst_compat_get(Rtdtsecobjtname((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR
&s
cCs
t|jƒS(s3Return a list of section names, excluding [DEFAULT](tlistR(R((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytsections-scCsT|jƒdkr"td|‚n|j|ƒr@t|ƒ‚n|jj|ƒdS(séCreate 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.
        tdefaultsInvalid section name: %sN(RRthas_sectionRRt_new_namespace(Rtsection((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytadd_section1s
	cCs
||jkS(s~Indicate whether the named section is present in the configuration.

        The DEFAULT section is not acknowledged.
        (R(RR%((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR#BscCs0||jkr t|j|ƒSt|ƒ‚dS(s9Return a list of option names for the given section name.N(RR R(RR%((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytoptionsIscCs„g}t|tƒr!|g}nx\|D]T}yt|ƒ}Wntk
rTq(nX|j|ƒ|jj|ƒ|jƒq(W|S(s£Read 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.
        (t
isinstancet
basestringtopentIOErrortappendRt_readfptclose(Rt	filenamest
files_readtfilenametfp((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytreadPs



cCs|jj|ƒdS(sLike 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-(RR2R1((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytreadfpgscCs||j|ƒst|ƒ‚n|dk	rC||krC||}n|j|}||kri|j|ƒSt||ƒ‚dS(N(R#RtNoneRRR(RR%toptiontvarstvaluetsec((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytgetqs


cCs`||jkrPg}x4|j|D]%}|j||j||ƒfƒq#W|St|ƒ‚dS(N(RR,R:R(RR%tanstopt((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytitems}s#cCst|j||ƒƒS(N(tintR:(RR%R6((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytgetint†scCst|j||ƒƒS(N(tfloatR:(RR%R6((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytgetfloat‰st1tyesttruetont0tnotfalsetoffcCsH|j||ƒ}|jƒ|jkr7td|‚n|j|jƒS(NsNot a boolean: %s(R:Rt_boolean_statesR(RR%R6tv((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt
getbooleanscCs5||jkr|j|}nt|ƒ‚||kS(s=Check for the existence of a given option in a given section.(RR(RR%R6R9((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt
has_option•scCs3||jkr#||j||<nt|ƒ‚dS(sSet an option.N(RR(RR%R6R8((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytsetscCs|jt|jƒƒdS(s?Write an .ini-format representation of the configuration state.N(twritetstrR(RR2((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRO¤scCsJ||jkr|j|}nt|ƒ‚||krB||=dSdSdS(sRemove an option.iiN(RR(RR%R6R9((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt
remove_option¨scCs!|j|ƒstS|j|=tS(sRemove a file section.(R#tFalseRtTrue(RR%((s3/usr/lib/python2.7/site-packages/iniparse/compat.pytremove_section´s
N(t__name__t
__module__R5RRRR
R!R&R#R'R3R4R:R=R?RARSRRRJRLRMRNRORQRT(((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRs*							
									t
ConfigDictcBs eZdZd„Zd„ZRS(s*Present a dict interface to a ini section.cCs||_||_||_dS(N(tcfgR%R7(RRXR%R7((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR¿s		cCsMy#tj|j|j||jƒSWn#ttfk
rHt|ƒ‚nXdS(N(RR:RXR%R7RRtKeyError(Rtkey((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt__getitem__Äs#(RURVt__doc__RR[(((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRW¼s	tConfigParsercBs/eZedd„Zd„Zedd„ZRS(cCsˆ|tkr+|j|ƒr+t|ƒ‚n|j|ƒ}tj||||ƒ}|r\|St|||ƒ}|j||||ƒSdS(s®Get 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(RR#RRRR:RWt_interpolate(RR%R6trawR7R8R((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR:ÍscCs¡|}t}xd|rr|d8}d|krny||}Wqotk
rj}t||||jdƒ‚qoXqPqW|jdƒdkrt|||ƒ‚n|S(Nis%(iiÿÿÿÿ(RRYRtargstfindR(RR%R6trawvalR7R8tdepthte((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR^äs	
 c	Cs&|tkr+|j|ƒr+t|ƒ‚n|dkrMt|j|ƒ}nMg}x1|j|D]"}||kra|j|ƒqaqaW|j|jƒƒd|kr¶|j	dƒnt
|||ƒ}|rïg|D]}|||f^qÕSg|D](}||j|||||ƒf^qöSdS(sØReturn 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.
        RUN(RR#RR5R RR,textendtkeystremoveRWR^(RR%R_R7R'txRR6((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR=ös"N(RURVRRR5R:R^R=(((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR]Ës	tSafeConfigParsercBsSeZejdƒZejdƒZd„Zd„ZejdƒjZ	d„Z
RS(s
%\(([^)]+)\)ss%[^%]|%$cCs„t|tƒstdƒ‚n|jjd|ƒ}|jj|ƒ}|rjtd||jƒfƒ‚nt	j
||||ƒdS(Nsoption values must be stringsts1invalid interpolation syntax in %r at position %d(R(R)t	TypeErrort
_interpvar_retsubt_badpercent_retsearchRtstartR]RN(RR%R6R8t	tmp_valuetm((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRNscCs/g}|j|||||dƒdj|ƒS(NiRj(t_interpolate_sometjoin(RR%R6RbR7tL((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyR^+scCs¬|tkr!t|||ƒ‚nx„|r§|jdƒ}|dkrV|j|ƒdS|dkr€|j|| ƒ||}n|dd!}|dkr³|jdƒ|d}q$|dkrˆ|j|ƒ}	|	dkrót||d|ƒ‚n|	jdƒ}
||	jƒ}y||
}Wn&t	k
rHt
||||
ƒ‚nXd|krx|j||||||dƒq¤|j|ƒq$t||dt|ƒƒ‚q$WdS(Nt%iiit(s'bad interpolation variable reference %rs+'%' must be followed by '%' or '(', found: (
RRRaR,t_interpvar_matchR5RtgrouptendRYRRstrepr(RR6taccumtrestR%tmapRctptcRrtvarRK((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRs3sB	




	
(RURVtretcompileRlRnRNR^tmatchRxRs(((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyRis		(R\R‚R]RRRRRRRRRR	R
RRtobjectRRWRi(((s3/usr/lib/python2.7/site-packages/iniparse/compat.pyt<module>s:	"ŸN

OHA YOOOO