ó
žµäKc           @   sÖ   d  Z  d d l Z d d l m Z m Z m Z m Z m Z m Z m	 Z	 m
 Z
 d d l m Z m Z m Z m Z d d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d S(   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(   t   DuplicateSectionErrort   NoSectionErrort   NoOptionErrort   InterpolationMissingOptionErrort   InterpolationDepthErrort   InterpolationSyntaxErrort   DEFAULTSECTt   MAX_INTERPOLATION_DEPTH(   t   Errort   InterpolationErrort   MissingSectionHeaderErrort   ParsingErrort   RawConfigParserc           B   sý   e  Z d e d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d d „ Z d d	 „ Z d
 „  Z d „  Z d „  Z i e d 6e d 6e d 6e d 6e d 6e d 6e d 6e d 6Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s:   | t  k r t d ƒ ‚ n  t j d | d |  ƒ |  _ d  S(   Ns   Custom dict types not supportedt   defaultst   optionxformsource(   t   dictt
   ValueErrort   init	   INIConfigt   data(   t   selfR   t	   dict_type(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   __init__   s    c         C   s
   | j  ƒ  S(   N(   t   lower(   R   t	   optionstr(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   optionxform#   s    c         C   s=   i  } |  j  j } x$ | j D] } | j | ƒ | | <q W| S(   N(   R   t	   _defaultst   _optionst   _compat_get(   R   t   dt   secobjt   name(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR   &   s
    c         C   s   t  |  j ƒ S(   s3   Return a list of section names, excluding [DEFAULT](   t   listR   (   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   sections-   s    c         C   sT   | j  ƒ  d k r" t d | ‚ n  |  j | ƒ r@ t | ƒ ‚ n |  j j | ƒ d S(   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.
        t   defaults   Invalid section name: %sN(   R   R   t   has_sectionR    R   t   _new_namespace(   R   t   section(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   add_section1   s
    	c         C   s   | |  j  k S(   s~   Indicate whether the named section is present in the configuration.

        The DEFAULT section is not acknowledged.
        (   R   (   R   R%   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR#   B   s    c         C   s0   | |  j  k r  t |  j  | ƒ St | ƒ ‚ d S(   s9   Return a list of option names for the given section name.N(   R   R    R   (   R   R%   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   optionsI   s    c         C   s„   g  } t  | t ƒ r! | g } n  x\ | D]T } y t | ƒ } Wn t k
 rT q( n X| j | ƒ |  j j | ƒ | 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
   basestringt   opent   IOErrort   appendR   t   _readfpt   close(   R   t	   filenamest
   files_readt   filenamet   fp(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   readP   s    
c         C   s   |  j  j | ƒ d S(   s  Like 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(   R   R-   (   R   R2   R1   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   readfpg   s    c         C   s|   |  j  | ƒ s t | ƒ ‚ n  | d  k	 rC | | k rC | | } n  |  j | } | | k ri | j | ƒ St | | ƒ ‚ d  S(   N(   R#   R   t   NoneR   R   R   (   R   R%   t   optiont   varst   valuet   sec(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   getq   s    c         C   s`   | |  j  k rP g  } x4 |  j  | D]% } | j | |  j | | ƒ f ƒ q# W| St | ƒ ‚ d  S(   N(   R   R,   R:   R   (   R   R%   t   anst   opt(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   items}   s    #c         C   s   t  |  j | | ƒ ƒ S(   N(   t   intR:   (   R   R%   R6   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   getint†   s    c         C   s   t  |  j | | ƒ ƒ S(   N(   t   floatR:   (   R   R%   R6   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   getfloat‰   s    t   1t   yest   truet   ont   0t   not   falset   offc         C   sH   |  j  | | ƒ } | j ƒ  |  j k r7 t d | ‚ n  |  j | j ƒ  S(   Ns   Not a boolean: %s(   R:   R   t   _boolean_statesR   (   R   R%   R6   t   v(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt
   getboolean   s    c         C   s5   | |  j  k r |  j  | } n t | ƒ ‚ | | k S(   s=   Check for the existence of a given option in a given section.(   R   R   (   R   R%   R6   R9   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt
   has_option•   s    c         C   s3   | |  j  k r# | |  j  | | <n t | ƒ ‚ d S(   s   Set an option.N(   R   R   (   R   R%   R6   R8   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   set   s    c         C   s   | j  t |  j ƒ ƒ d S(   s?   Write an .ini-format representation of the configuration state.N(   t   writet   strR   (   R   R2   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyRO   ¤   s    c         C   sJ   | |  j  k r |  j  | } n t | ƒ ‚ | | k rB | | =d Sd Sd S(   s   Remove an option.i   i    N(   R   R   (   R   R%   R6   R9   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   remove_option¨   s    c         C   s!   |  j  | ƒ s t S|  j | =t S(   s   Remove a file section.(   R#   t   FalseR   t   True(   R   R%   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   remove_section´   s    
N(   t   __name__t
   __module__R5   R   R   R   R   R!   R&   R#   R'   R3   R4   R:   R=   R?   RA   RS   RR   RJ   RL   RM   RN   RO   RQ   RT   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR      s*   							
									t
   ConfigDictc           B   s    e  Z d  Z d „  Z d „  Z RS(   s*   Present a dict interface to a ini section.c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   cfgR%   R7   (   R   RX   R%   R7   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR   ¿   s    		c         C   sM   y# t  j |  j |  j | |  j ƒ SWn# t t f k
 rH t | ƒ ‚ n Xd  S(   N(   R   R:   RX   R%   R7   R   R   t   KeyError(   R   t   key(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   __getitem__Ä   s    #(   RU   RV   t   __doc__R   R[   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyRW   ¼   s   	t   ConfigParserc           B   s/   e  Z e d d  „ Z d „  Z e d d „ Z RS(   c         C   sˆ   | t  k r+ |  j | ƒ r+ t | ƒ ‚ n  |  j | ƒ } t j |  | | | ƒ } | r\ | St |  | | ƒ } |  j | | | | ƒ Sd S(   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(   R   R#   R   R   R   R:   RW   t   _interpolate(   R   R%   R6   t   rawR7   R8   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR:   Í   s    c         C   s¡   | } t  } xd | rr | d 8} d | k rn y | | } Wqo t k
 rj } t | | | | j d ƒ ‚ qo Xq Pq W| j d ƒ d k r t | | | ƒ ‚ n  | S(   Ni   s   %(i    iÿÿÿÿ(   R   RY   R   t   argst   findR   (   R   R%   R6   t   rawvalR7   R8   t   deptht   e(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR^   ä   s    	
 c      	   C   s&  | t  k r+ |  j | ƒ r+ t | ƒ ‚ n  | d k rM t |  j | ƒ } nM g  } x1 |  j | D]" } | | k ra | j | ƒ qa qa W| j | j ƒ  ƒ d | k r¶ | j	 d ƒ n  t
 |  | | ƒ } | rï g  | D] } | | | f ^ qÕ Sg  | D]( } | |  j | | | | | ƒ f ^ qö Sd S(   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.
        RU   N(   R   R#   R   R5   R    R   R,   t   extendt   keyst   removeRW   R^   (   R   R%   R_   R7   R'   t   xR   R6   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR=   ö   s"    N(   RU   RV   RR   R5   R:   R^   R=   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR]   Ë   s   	t   SafeConfigParserc           B   sS   e  Z e j d  ƒ Z e j d ƒ Z d „  Z d „  Z e j d  ƒ j Z	 d „  Z
 RS(   s   %\(([^)]+)\)ss   %[^%]|%$c         C   s„   t  | t ƒ s t d ƒ ‚ n  |  j j d | ƒ } |  j j | ƒ } | rj t d | | j ƒ  f ƒ ‚ n  t	 j
 |  | | | ƒ d  S(   Ns   option values must be stringst    s1   invalid interpolation syntax in %r at position %d(   R(   R)   t	   TypeErrort   _interpvar_ret   subt   _badpercent_ret   searchR   t   startR]   RN   (   R   R%   R6   R8   t	   tmp_valuet   m(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyRN     s    c         C   s/   g  } |  j  | | | | | d ƒ d j | ƒ S(   Ni   Rj   (   t   _interpolate_somet   join(   R   R%   R6   Rb   R7   t   L(    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyR^   +  s    c         C   s¬  | t  k r! t | | | ƒ ‚ n  x„| r§| j d ƒ } | d k  rV | j | ƒ d  S| d k r€ | j | |  ƒ | | } n  | d d !} | d k r³ | j d ƒ | d } q$ | d k rˆ|  j | ƒ }	 |	 d  k ró t | | d | ƒ ‚ n  |	 j d ƒ }
 | |	 j ƒ  } y | |
 } Wn& t	 k
 rHt
 | | | |
 ƒ ‚ n Xd | k rx|  j | | | | | | d ƒ q¤| j | ƒ q$ t | | d t | ƒ ƒ ‚ q$ Wd  S(   Nt   %i    i   i   t   (s'   bad interpolation variable reference %rs+   '%' must be followed by '%' or '(', found: (   R   R   Ra   R,   t   _interpvar_matchR5   R   t   groupt   endRY   R   Rs   t   repr(   R   R6   t   accumt   restR%   t   mapRc   t   pt   cRr   t   varRK   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyRs   3  sB    		(   RU   RV   t   ret   compileRl   Rn   RN   R^   t   matchRx   Rs   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyRi     s   		(   R\   R‚   R]   R    R   R   R   R   R   R   R   R   R	   R
   R   R   t   objectR   RW   Ri   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/compat.pyt   <module>   s   :	"ŸN