B
    u9a                 @   s  d dl mZ d dlmZmZ d dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZdddddd	d
ddddddddddddddgZdZdZG dd deZG dd deZG dd deZG dd deZG d d deZG d!d deZG d"d
 d
eZG d#d deZG d$d	 d	eZG d%d deZG d&d deZe ZG d'd dZG d(d deZ G d)d deZ!G d*d deZ"G d+d deZ#G d,d de#Z$G d-d de$Z%G d.d deZ&G d/d deZ'dS )0    )MutableMapping)OrderedDictChainMapNNoSectionErrorDuplicateOptionErrorDuplicateSectionErrorNoOptionErrorInterpolationErrorInterpolationDepthErrorInterpolationMissingOptionErrorInterpolationSyntaxErrorParsingErrorMissingSectionHeaderErrorConfigParserSafeConfigParserRawConfigParserInterpolationBasicInterpolationExtendedInterpolationLegacyInterpolationSectionProxyConverterMappingDEFAULTSECTMAX_INTERPOLATION_DEPTHZDEFAULT
   c               @   s"   e Zd ZdddZdd ZeZdS )Error c             C   s   || _ t| | d S )N)message	Exception__init__)selfmsg r"   "/usr/lib/python3.7/configparser.pyr      s    zError.__init__c             C   s   | j S )N)r   )r    r"   r"   r#   __repr__   s    zError.__repr__N)r   )__name__
__module____qualname__r   r$   __str__r"   r"   r"   r#   r      s   
r   c               @   s   e Zd Zdd ZdS )r   c             C   s$   t | d|f  || _|f| _d S )NzNo section: %r)r   r   sectionargs)r    r)   r"   r"   r#   r      s    zNoSectionError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r      s   c               @   s   e Zd ZdddZdS )r   Nc             C   s   t |dg}|d k	rRdt |g}|d k	r8|d| |d || |}n|dd t| d| || _|| _	|| _
|||f| _d S )Nz already existszWhile reading from z [line {0:2d}]z
: section r   zSection r   )reprappendformatextendinsertr   r   joinr)   sourcelinenor*   )r    r)   r1   r2   r!   r   r"   r"   r#   r      s    

zDuplicateSectionError.__init__)NN)r%   r&   r'   r   r"   r"   r"   r#   r      s   c               @   s   e Zd ZdddZdS )r   Nc             C   s   t |dt |dg}|d k	rZdt |g}|d k	r@|d| |d || |}n|dd t| d| || _|| _	|| _
|| _||||f| _d S )	Nz in section z already existszWhile reading from z [line {0:2d}]z	: option r   zOption r   )r+   r,   r-   r.   r/   r   r   r0   r)   optionr1   r2   r*   )r    r)   r3   r1   r2   r!   r   r"   r"   r#   r      s     

zDuplicateOptionError.__init__)NN)r%   r&   r'   r   r"   r"   r"   r#   r      s   c               @   s   e Zd Zdd ZdS )r   c             C   s.   t | d||f  || _|| _||f| _d S )NzNo option %r in section: %r)r   r   r3   r)   r*   )r    r3   r)   r"   r"   r#   r      s
    zNoOptionError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r      s   c               @   s   e Zd Zdd ZdS )r	   c             C   s(   t | | || _|| _|||f| _d S )N)r   r   r3   r)   r*   )r    r3   r)   r!   r"   r"   r#   r      s    zInterpolationError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r	      s   c               @   s   e Zd Zdd ZdS )r   c             C   s8   d ||||}t| ||| || _||||f| _d S )NzBad value substitution: option {!r} in section {!r} contains an interpolation key {!r} which is not a valid option name. Raw value: {!r})r-   r	   r   	referencer*   )r    r3   r)   rawvalr4   r!   r"   r"   r#   r   
  s
    z(InterpolationMissingOptionError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r     s   c               @   s   e Zd ZdS )r   N)r%   r&   r'   r"   r"   r"   r#   r     s   c               @   s   e Zd Zdd ZdS )r
   c             C   s0   d ||t|}t| ||| |||f| _d S )NzRecursion limit exceeded in value substitution: option {!r} in section {!r} contains an interpolation key which cannot be substituted in {} steps. Raw value: {!r})r-   r   r	   r   r*   )r    r3   r)   r5   r!   r"   r"   r#   r     s
    z InterpolationDepthError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r
     s   c               @   s8   e Zd Zd	ddZedd Zejdd Zdd ZdS )
r   Nc             C   sT   |r|rt dn|s$|s$t dn|r,|}t| d|  || _g | _|f| _d S )Nz:Cannot specify both `filename' and `source'. Use `source'.z%Required argument `source' not given.z"Source contains parsing errors: %r)
ValueErrorr   r   r1   errorsr*   )r    r1   filenamer"   r"   r#   r   +  s    

zParsingError.__init__c             C   s   t jdtdd | jS )NzSThe 'filename' attribute will be removed in future versions.  Use 'source' instead.   )
stacklevel)warningswarnDeprecationWarningr1   )r    r"   r"   r#   r8   :  s    
zParsingError.filenamec             C   s   t jdtdd || _d S )NzSThe 'filename' attribute will be removed in future versions.  Use 'source' instead.r9   )r:   )r;   r<   r=   r1   )r    valuer"   r"   r#   r8   D  s    
c             C   s*   | j ||f |  jd||f 7  _d S )Nz
	[line %2d]: %s)r7   r,   r   )r    r2   liner"   r"   r#   r,   N  s    zParsingError.append)NN)r%   r&   r'   r   propertyr8   setterr,   r"   r"   r"   r#   r   (  s   


c               @   s   e Zd Zdd ZdS )r   c             C   s8   t | d|||f  || _|| _|| _|||f| _d S )Nz7File contains no section headers.
file: %r, line: %d
%r)r   r   r1   r2   r?   r*   )r    r8   r2   r?   r"   r"   r#   r   V  s    z"MissingSectionHeaderError.__init__N)r%   r&   r'   r   r"   r"   r"   r#   r   S  s   c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
r   c             C   s   |S )Nr"   )r    parserr)   r3   r>   defaultsr"   r"   r#   
before_getj  s    zInterpolation.before_getc             C   s   |S )Nr"   )r    rB   r)   r3   r>   r"   r"   r#   
before_setm  s    zInterpolation.before_setc             C   s   |S )Nr"   )r    rB   r)   r3   r>   r"   r"   r#   before_readp  s    zInterpolation.before_readc             C   s   |S )Nr"   )r    rB   r)   r3   r>   r"   r"   r#   before_writes  s    zInterpolation.before_writeN)r%   r&   r'   rD   rE   rF   rG   r"   r"   r"   r#   r   g  s   c               @   s.   e Zd ZedZdd Zdd Zdd ZdS )	r   z%\(([^)]+)\)sc          	   C   s$   g }|  ||||||d d|S )N   r   )_interpolate_somer0   )r    rB   r)   r3   r>   rC   Lr"   r"   r#   rD     s    zBasicInterpolation.before_getc             C   s<   | dd}| jd|}d|kr8td||df |S )Nz%%r   %z1invalid interpolation syntax in %r at position %d)replace_KEYCREsubr6   find)r    rB   r)   r3   r>   	tmp_valuer"   r"   r#   rE     s    zBasicInterpolation.before_setc          
   C   sp  |j ||d|d}|tkr&t|||xB|rj|d}	|	dk rP|| d S |	dkrv||d |	  ||	d  }|dd }
|
dkr|d |dd  }q*|
dkrV| j|}|d krt||d| ||	d}||
 d  }y|| }W n& tk
r"   t||||d Y nX d|krJ| |||||||d  n
|| q*t||d	|f q*W d S )
NT)rawfallbackrK   r   rH   r9   (z'bad interpolation variable reference %rz/'%%' must be followed by '%%' or '(', found: %r)getr   r
   rO   r,   rM   matchr   optionxformgroupendKeyErrorr   rI   )r    rB   r3   accumrestr)   mapdepthr5   pcmvarvr"   r"   r#   rI     sF    






z$BasicInterpolation._interpolate_someN)	r%   r&   r'   recompilerM   rD   rE   rI   r"   r"   r"   r#   r   w  s   
c               @   s.   e Zd ZedZdd Zdd Zdd ZdS )	r   z\$\{([^}]+)\}c          	   C   s$   g }|  ||||||d d|S )NrH   r   )rI   r0   )r    rB   r)   r3   r>   rC   rJ   r"   r"   r#   rD     s    z ExtendedInterpolation.before_getc             C   s<   | dd}| jd|}d|kr8td||df |S )Nz$$r   $z1invalid interpolation syntax in %r at position %d)rL   rM   rN   r6   rO   )r    rB   r)   r3   r>   rP   r"   r"   r#   rE     s    z ExtendedInterpolation.before_setc             C   s  |j ||d|d}|tkr&t|||x|r|d}	|	dk rP|| d S |	dkrv||d |	  ||	d  }|dd }
|
dkr|d |dd  }q*|
dkr| j|}|d krt||d| |d	d	}||
 d  }|}|}yrt|dkr ||d }|| }nHt|dkrV|d }||d }|j ||dd
}nt||d|f W n2 tttfk
r   t|||d	|d Y nX d|kr| |||||t|j|dd
|d  n
|| q*t||d|f q*W d S )NT)rQ   rR   re   r   rH   r9   {z'bad interpolation variable reference %r:)rQ   zMore than one ':' found: %rz-'$' must be followed by '$' or '{', found: %r)rT   r   r
   rO   r,   rM   rU   r   rW   splitrX   lenrV   rY   r   r   r   r0   rI   dictitems)r    rB   r3   rZ   r[   r)   r\   r]   r5   r^   r_   r`   pathZsectoptrb   r"   r"   r#   rI     s^    







z'ExtendedInterpolation._interpolate_someN)	r%   r&   r'   rc   rd   rM   rD   rE   rI   r"   r"   r"   r#   r     s   
c               @   s2   e Zd ZedZdd Zdd Zedd Z	dS )	r   z%\(([^)]*)\)s|.c       
   
   C   s   |}t }x|r|d8 }|rd|krtj| j|d}| j||}y|| }W q tk
r }	 zt||||	jd d W d d }	~	X Y qX q
P q
W |rd|krt	||||S )NrH   z%()rB   r   )
r   	functoolspartial_interpolation_replacerM   rN   rY   r   r*   r
   )
r    rB   r)   r3   r>   varsr5   r]   rL   er"   r"   r#   rD     s"    (zLegacyInterpolation.before_getc             C   s   |S )Nr"   )r    rB   r)   r3   r>   r"   r"   r#   rE   #  s    zLegacyInterpolation.before_setc             C   s,   |  d}|d kr|   S d|| S d S )NrH   z%%(%s)s)rW   rV   )rU   rB   sr"   r"   r#   rp   &  s    
z*LegacyInterpolation._interpolation_replaceN)
r%   r&   r'   rc   rd   rM   rD   rE   staticmethodrp   r"   r"   r"   r#   r   	  s   
c            
       s2  e Zd ZdZdZdZe Ze	eej
Ze	ejddej
Ze	ejddej
Ze	dZddddddddd	Zd
edfddd
ddeeedddZdd Zdd Zdd Zdd Zdd ZdcddZddddZdedd Zdfd"d#Zdgd$d%Zdd
ed&d'd(Zd)d* Z dd
ed&d+d,Z!dd
ed&d-d.Z"dd
ed&d/d0Z#dd
ed&d1d2Z$edd
f fd3d4	Z%d5d6 Z&d7d8 Z'd9d: Z(dhd;d<Z)did=d>Z*d?d@ Z+dAdB Z,dCdD Z-dEdF Z.dGdH Z/dIdJ Z0dKdL Z1dMdN Z2dOdP Z3dQdR Z4dSdT Z5dUdV Z6dWdX Z7dYdZ Z8d[d\ Z9d]d]d]d^d_d`Z:e;dadb Z<  Z=S )jr   z
        \[                                 # [
        (?P<header>[^]]+)                  # very permissive!
        \]                                 # ]
        a  
        (?P<option>.*?)                    # very permissive!
        \s*(?P<vi>{delim})\s*              # any number of space/tab,
                                           # followed by any of the
                                           # allowed delimiters,
                                           # followed by any space/tab
        (?P<value>.*)$                     # everything up to eol
        a  
        (?P<option>.*?)                    # very permissive!
        \s*(?:                             # any number of space/tab,
        (?P<vi>{delim})\s*                 # optionally followed by
                                           # any of the allowed
                                           # delimiters, followed by any
                                           # space/tab
        (?P<value>.*))?$                   # everything up to eol
        z=|:)delimz\STF)1ZyestrueZon0noZfalseZoffN)=rg   )#;)
delimiterscomment_prefixesinline_comment_prefixesstrictempty_lines_in_valuesdefault_sectioninterpolation
convertersc            C   s<  || _ |   | _|   | _t| | _|   | _t| |	| j|	< t|| _|dkrd|rZ| j	n| j
| _nNddd |D }|rt| jj|dtj| _nt| jj|dtj| _t|pd| _t|pd| _|| _|| _|| _|	| _|
| _| jtkr| j| _| jd krt | _|tk	r(| j| |r8| | d S )N)rz   rg   |c             s   s   | ]}t |V  qd S )N)rc   escape).0dr"   r"   r#   	<genexpr>i  s    z+RawConfigParser.__init__.<locals>.<genexpr>)ru   r"   )_dict	_sections	_defaultsr   _converters_proxiesr   tuple_delimiters	OPTCRE_NVOPTCRE_optcrer0   rc   rd   _OPT_NV_TMPLr-   VERBOSE	_OPT_TMPL_comment_prefixes_inline_comment_prefixes_strict_allow_no_value_empty_lines_in_valuesr   _interpolation_UNSET_DEFAULT_INTERPOLATIONr   update_read_defaults)r    rC   Z	dict_typeZallow_no_valuer}   r~   r   r   r   r   r   r   r   r"   r"   r#   r   X  s<    







zRawConfigParser.__init__c             C   s   | j S )N)r   )r    r"   r"   r#   rC     s    zRawConfigParser.defaultsc             C   s   t | j S )N)listr   keys)r    r"   r"   r#   sections  s    zRawConfigParser.sectionsc             C   sJ   || j krtd| || jkr(t||  | j|< t| || j|< d S )NzInvalid section name: %r)r   r6   r   r   r   r   r   )r    r)   r"   r"   r#   add_section  s    

zRawConfigParser.add_sectionc             C   s
   || j kS )N)r   )r    r)   r"   r"   r#   has_section  s    zRawConfigParser.has_sectionc             C   sJ   y| j |  }W n tk
r0   t|d Y nX || j t| S )N)r   copyrY   r   r   r   r   r   )r    r)   Zoptsr"   r"   r#   options  s    zRawConfigParser.optionsc          
   C   s   t |tttjfr|g}g }xl|D ]d}y(t||d}| || W d Q R X W n tk
rd   w"Y nX t |tjr|t|}|	| q"W |S )N)encoding)

isinstancestrbytesosPathLikeopen_readOSErrorfspathr,   )r    	filenamesr   Zread_okr8   fpr"   r"   r#   read  s    

zRawConfigParser.readc             C   s<   |d kr,y
|j }W n tk
r*   d}Y nX | || d S )Nz<???>)nameAttributeErrorr   )r    fr1   r"   r"   r#   	read_file  s    

zRawConfigParser.read_file<string>c             C   s   t |}| || d S )N)ioStringIOr   )r    stringr1   Zsfiler"   r"   r#   read_string  s    
zRawConfigParser.read_string<dict>c          
   C   s   t  }x| D ]\}}t|}y| | W n( ttfk
rV   | jrR||krR Y nX || xl| D ]`\}}| t|}|d k	rt|}| jr||f|krt	||||||f |  ||| qlW qW d S )N)
setrk   r   r   r   r6   r   addrV   r   )r    Z
dictionaryr1   elements_addedr)   r   keyr>   r"   r"   r#   	read_dict  s"    
zRawConfigParser.read_dictc             C   s"   t jdtdd | j||d d S )NzRThis method will be removed in future versions.  Use 'parser.read_file()' instead.r9   )r:   )r1   )r;   r<   r=   r   )r    r   r8   r"   r"   r#   readfp  s    
zRawConfigParser.readfp)rQ   rq   rR   c            C   s   y|  ||}W n$ tk
r4   |tkr, n|S Y nX | |}y|| }W n, tk
rx   |tkrpt||n|S Y nX |s|d kr|S | j| ||||S d S )N)_unify_valuesr   r   rV   rY   r   r   rD   )r    r)   r3   rQ   rq   rR   r   r>   r"   r"   r#   rT     s"    


zRawConfigParser.getc             K   s   || j ||f|S )N)rT   )r    r)   convr3   kwargsr"   r"   r#   _get!  s    zRawConfigParser._getc         	   K   sD   y| j |||f||d|S  ttfk
r>   |tkr: |S X d S )N)rQ   rq   )r   r   r   r   )r    r)   r3   r   rQ   rq   rR   r   r"   r"   r#   	_get_conv$  s    zRawConfigParser._get_convc            K   s   | j ||tf|||d|S )N)rQ   rq   rR   )r   int)r    r)   r3   rQ   rq   rR   r   r"   r"   r#   getint/  s    zRawConfigParser.getintc            K   s   | j ||tf|||d|S )N)rQ   rq   rR   )r   float)r    r)   r3   rQ   rq   rR   r   r"   r"   r#   getfloat4  s    zRawConfigParser.getfloatc            K   s    | j ||| jf|||d|S )N)rQ   rq   rR   )r   _convert_to_boolean)r    r)   r3   rQ   rq   rR   r   r"   r"   r#   
getboolean9  s    zRawConfigParser.getbooleanc                s   t krt  S j  y j  W n& tk
rV   jkrRt	Y nX |rx"| D ]\}}| 
|< qfW  fdd|r fddfdd  D S )Nc                s   j |  |   S )N)r   rD   )r3   )r   r)   r    r"   r#   <lambda>U  s   z'RawConfigParser.items.<locals>.<lambda>c                s    |  S )Nr"   )r3   )r   r"   r#   r   X      c                s   g | ]}| |fqS r"   r"   )r   r3   )value_getterr"   r#   
<listcomp>Y  s    z)RawConfigParser.items.<locals>.<listcomp>)r   superrk   r   r   r   r   rY   r   r   rV   r   )r    r)   rQ   rq   r   r>   )	__class__)r   r)   r    r   r#   rk   >  s    


zRawConfigParser.itemsc             C   s.   x$|   D ]}| | }| |= ||fS W td S )N)r   rY   )r    r   r>   r"   r"   r#   popitem[  s
    
zRawConfigParser.popitemc             C   s   |  S )N)lower)r    Z	optionstrr"   r"   r#   rV   h  s    zRawConfigParser.optionxformc             C   sV   |r|| j kr"| |}|| jkS || jkr0dS | |}|| j| kpP|| jkS d S )NF)r   rV   r   r   )r    r)   r3   r"   r"   r#   
has_optionk  s    



zRawConfigParser.has_optionc             C   sl   |r| j | |||}|r$|| jkr,| j}n.y| j| }W n tk
rX   t|d Y nX ||| |< d S )N)r   rE   r   r   r   rY   r   rV   )r    r)   r3   r>   sectdictr"   r"   r#   r   y  s    zRawConfigParser.setc             C   sl   |rd | jd }n
| jd }| jr>| || j| j | x(| jD ]}| ||| j|  | qFW d S )Nz {} r   )r-   r   r   _write_sectionr   rk   r   )r    r   Zspace_around_delimitersr   r)   r"   r"   r#   write  s    

zRawConfigParser.writec             C   s|   | d| x\|D ]T\}}| j| |||}|d k	s>| jsT|t|dd }nd}| d|| qW | d d S )Nz[{}]

z
	r   z{}{}
)r   r-   r   rG   r   r   rL   )r    r   Zsection_nameZsection_itemsZ	delimiterr   r>   r"   r"   r#   r     s    zRawConfigParser._write_sectionc             C   sd   |r|| j kr| j}n.y| j| }W n tk
rB   t|d Y nX | |}||k}|r`||= |S )N)r   r   r   rY   r   rV   )r    r)   r3   r   existedr"   r"   r#   remove_option  s    
zRawConfigParser.remove_optionc             C   s"   || j k}|r| j |= | j|= |S )N)r   r   )r    r)   r   r"   r"   r#   remove_section  s
    
zRawConfigParser.remove_sectionc             C   s&   || j kr| |st|| j| S )N)r   r   rY   r   )r    r   r"   r"   r#   __getitem__  s    zRawConfigParser.__getitem__c             C   s@   || j kr| j  n|| jkr.| j|   | ||i d S )N)r   r   clearr   r   )r    r   r>   r"   r"   r#   __setitem__  s
    

zRawConfigParser.__setitem__c             C   s2   || j krtd| |s$t|| | d S )Nz"Cannot remove the default section.)r   r6   r   rY   r   )r    r   r"   r"   r#   __delitem__  s
    

zRawConfigParser.__delitem__c             C   s   || j kp| |S )N)r   r   )r    r   r"   r"   r#   __contains__  s    zRawConfigParser.__contains__c             C   s   t | jd S )NrH   )ri   r   )r    r"   r"   r#   __len__  s    zRawConfigParser.__len__c             C   s   t | jf| j S )N)	itertoolschainr   r   r   )r    r"   r"   r#   __iter__  s    zRawConfigParser.__iter__c             C   s0  t  }d }d }d }d}d}d }	xt|ddD ]\}}
tj}dd | jD }x||tjkr|ri }x`| D ]T\}}|
||d }|dkrql|||< |dks|dkrl|
|d   rlt||}qlW |}qPW x"| j	D ]}|

 |rd}P qW |tjkrd }|
d | 
 }|s\| jrT|d krZ|d k	rZ|rZ|| d k	rZ|| d q.tj}q.| j|
}|rv| nd}|d k	r|r||kr|| | q.|}| j|}|rJ|d}|| jkr| jr||krt|||| j| }|| n@|| jkr| j}n,|  }|| j|< t| || j|< || d }q.|d krbt|||
q.| j|}|r|d	d
d\}}}|s| |	|||
}	|  |! }| jr||f|krt"|||||||f |d k	r|
 }|g||< nd ||< q.| |	|||
}	q.W | #  |	r,|	d S )Nr   rH   )startc             S   s   i | ]
}d |qS )r"   )r   r^   r"   r"   r#   
<dictcomp>  s    z)RawConfigParser._read.<locals>.<dictcomp>r   r   headerr3   vir>   )$r   	enumeratesysmaxsizer   rk   rO   isspaceminr   strip
startswithr   r,   NONSPACECREsearchr   SECTCRErU   rW   r   r   r   r   r   r   r   r   r   r   r   _handle_errorrV   rstripr   _join_multiline_values)r    r   fpnamer   ZcursectZsectnameZoptnamer2   Zindent_levelrr   r?   Zcomment_startZinline_prefixesZnext_prefixesprefixindexr>   Zfirst_nonspaceZcur_indent_levelmor   Zoptvalr"   r"   r#   r     s     










zRawConfigParser._readc             C   sz   | j | jf}t|f| j }xT|D ]L\}}xB| D ]6\}}t|trXd|	 }| j
| |||||< q8W q&W d S )Nr   )r   r   r   r   r   rk   r   r   r0   r   r   rF   )r    rC   Zall_sectionsr)   r   r   valr"   r"   r#   r   X  s    
z&RawConfigParser._join_multiline_valuesc             C   s*   x$|  D ]\}}|| j| |< q
W d S )N)rk   r   rV   )r    rC   r   r>   r"   r"   r#   r   d  s    zRawConfigParser._read_defaultsc             C   s    |st |}||t| |S )N)r   r,   r+   )r    excr   r2   r?   r"   r"   r#   r   j  s    zRawConfigParser._handle_errorc             C   s   i }y| j | }W n( tk
r:   || jkr6t|d Y nX i }|rxx2| D ]&\}}|d k	rft|}||| |< qNW t||| jS )N)	r   rY   r   r   rk   r   rV   	_ChainMapr   )r    r)   rq   ZsectiondictZvardictr   r>   r"   r"   r#   r   p  s    
zRawConfigParser._unify_valuesc             C   s(   |  | jkrtd| | j|   S )NzNot a boolean: %s)r   BOOLEAN_STATESr6   )r    r>   r"   r"   r#   r     s    z#RawConfigParser._convert_to_booleanr   )r)   r3   r>   c            C   sD   t |tstdt |ts$td| jr.|r@t |ts@tdd S )Nzsection names must be stringszoption keys must be stringszoption values must be strings)r   r   	TypeErrorr   )r    r)   r3   r>   r"   r"   r#   _validate_value_types  s    



z%RawConfigParser._validate_value_typesc             C   s   | j S )N)r   )r    r"   r"   r#   r     s    zRawConfigParser.converters)N)N)r   )r   )N)N)T)>r%   r&   r'   Z
_SECT_TMPLr   r   r   r   rc   rd   r   r   r-   r   r   r   r  _default_dictr   r   r   rC   r   r   r   r   r   r   r   r   r   rT   r   r   r   r   r   rk   r   rV   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r@   r   __classcell__r"   r"   )r   r#   r   /  sv   	
#	




	%


zc                   s8   e Zd Ze Zd fdd	Z fddZdd Z  ZS )	r   Nc                s"   | j ||d t ||| d S )N)r3   r>   )r  r   r   )r    r)   r3   r>   )r   r"   r#   r     s    zConfigParser.setc                s   | j |d t | d S )N)r)   )r  r   r   )r    r)   )r   r"   r#   r     s    zConfigParser.add_sectionc             C   s0   z"| j }t | _ | | j|i W d || _ X d S )N)r   r   r   r   )r    rC   Zhold_interpolationr"   r"   r#   r     s
    zConfigParser._read_defaults)N)	r%   r&   r'   r   r   r   r   r   r  r"   r"   )r   r#   r     s   c                   s   e Zd Z fddZ  ZS )r   c                s"   t  j|| tjdtdd d S )NzThe SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead.r9   )r:   )r   r   r;   r<   r=   )r    r*   r   )r   r"   r#   r     s    zSafeConfigParser.__init__)r%   r&   r'   r   r  r"   r"   )r   r#   r     s   c               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zedd Zedd ZdddddddZdS )r   c             C   sJ   || _ || _x8|jD ].}d| }tj| jt||d}t| || qW d S )NrT   )_impl)_parser_namer   rn   ro   rT   getattrsetattr)r    rB   r   r   r   getterr"   r"   r#   r     s    zSectionProxy.__init__c             C   s   d | jS )Nz<Section: {}>)r-   r	  )r    r"   r"   r#   r$     s    zSectionProxy.__repr__c             C   s(   | j | j|st|| j | j|S )N)r  r   r	  rY   rT   )r    r   r"   r"   r#   r     s    zSectionProxy.__getitem__c             C   s"   | j j||d | j | j||S )N)r3   r>   )r  r  r   r	  )r    r   r>   r"   r"   r#   r     s    zSectionProxy.__setitem__c             C   s,   | j | j|r | j | j|s(t|d S )N)r  r   r	  r   rY   )r    r   r"   r"   r#   r     s    zSectionProxy.__delitem__c             C   s   | j | j|S )N)r  r   r	  )r    r   r"   r"   r#   r     s    zSectionProxy.__contains__c             C   s   t |  S )N)ri   _options)r    r"   r"   r#   r     s    zSectionProxy.__len__c             C   s   |    S )N)r  r   )r    r"   r"   r#   r     s    zSectionProxy.__iter__c             C   s*   | j | jjkr| j| j S | j S d S )N)r	  r  r   r   rC   )r    r"   r"   r#   r    s    zSectionProxy._optionsc             C   s   | j S )N)r  )r    r"   r"   r#   rB     s    zSectionProxy.parserc             C   s   | j S )N)r	  )r    r"   r"   r#   r     s    zSectionProxy.nameNF)rQ   rq   r  c            K   s(   |s| j j}|| j|f|||d|S )N)rQ   rq   rR   )r  rT   r	  )r    r3   rR   rQ   rq   r  r   r"   r"   r#   rT     s    
zSectionProxy.get)N)r%   r&   r'   r   r$   r   r   r   r   r   r   r  r@   rB   r   rT   r"   r"   r"   r#   r     s   	c               @   sF   e Zd ZedZdd Zdd Zdd Zdd	 Z	d
d Z
dd ZdS )r   z^get(?P<name>.+)$c             C   sV   || _ i | _xDt| j D ]6}| j|}|rtt| j |s>qd | j|d< qW d S )Nr   )r  _datadir	GETTERCRErU   callabler
  rW   )r    rB   r  r`   r"   r"   r#   r   "  s    zConverterMapping.__init__c             C   s
   | j | S )N)r  )r    r   r"   r"   r#   r   +  s    zConverterMapping.__getitem__c          	   C   s   yd| }W n( t k
r4   td|t|Y nX |dkrFtd|| j|< tj| jj|d}||_	t
| j|| x.| j D ] }tj|j|d}t
||| qW d S )NrT   zIncompatible key: {} (type: {})z)Incompatible key: cannot use "" as a name)r   )r  )r  r6   r-   typer  rn   ro   r  r   Z	converterr  valuesrT   )r    r   r>   kfuncproxyr  r"   r"   r#   r   .  s    
zConverterMapping.__setitem__c          	   C   s   yd|p
d  }W n t k
r,   t|Y nX | j|= xDt| jf| j D ]*}yt|| W qN tk
rv   wNY qNX qNW d S )NrT   )	r  rY   r  r   r   r  r  delattrr   )r    r   r  instr"   r"   r#   r   >  s    zConverterMapping.__delitem__c             C   s
   t | jS )N)iterr  )r    r"   r"   r#   r   L  s    zConverterMapping.__iter__c             C   s
   t | jS )N)ri   r  )r    r"   r"   r#   r   O  s    zConverterMapping.__len__N)r%   r&   r'   rc   rd   r  r   r   r   r   r   r   r"   r"   r"   r#   r     s   
	)(Zcollections.abcr   collectionsr   r  r   r  rn   r   r   r   rc   r   r;   __all__r   r   r   r   r   r   r   r   r	   r   r   r
   r   r   objectr   r   r   r   r   r   r   r   r   r   r"   r"   r"   r#   <module>   sV   	
+HJ&    z F