ó
¿ÁåKc           @   sO   d  e  f d „  ƒ  YZ d e  f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d S(   t   ConfigNamespacec           B   sq   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z RS(   s  Abstract class representing the interface of Config objects.

    A ConfigNamespace is a collection of names mapped to values, where
    the values may be nested namespaces.  Values can be accessed via
    container notation - obj[key] - or via dotted notation - obj.key.
    Both these access methods are equivalent.

    To minimize name conflicts between namespace keys and class members,
    the number of class members should be minimized, and the names of
    all class members should start with an underscore.

    Subclasses must implement the methods for container-like access,
    and this class will automatically provide dotted access.

    c         C   s
   t  | ƒ S(   N(   t   NotImplementedError(   t   selft   key(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   _getitem   s    c         C   s   t  | | ƒ ‚ d  S(   N(   R   (   R   R   t   value(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __setitem__   s    c         C   s   t  | ƒ ‚ d  S(   N(   R   (   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __delitem__   s    c         C   s   t  ƒ  S(   N(   R   (   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __iter__   s    c         C   s   t  | ƒ ‚ d  S(   N(   R   (   R   t   name(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   _new_namespace    s    c         C   s*   y |  j  | ƒ Wn t k
 r% t SXt S(   N(   R   t   KeyErrort   Falset   True(   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __contains__#   s
    c         C   s3   y |  j  | ƒ SWn t k
 r. t | |  ƒ SXd  S(   N(   R   R   t	   Undefined(   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __getitem__6   s    c         C   sZ   y |  j  | ƒ SWnB t k
 rU | j d ƒ rH | j d ƒ rH t ‚ n  t | |  ƒ SXd  S(   Nt   __(   R   R   t
   startswitht   endswitht   AttributeErrorR   (   R   R	   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __getattr__<   s    	c         C   sO   y' t  j |  | ƒ t  j |  | | ƒ Wn! t k
 rJ |  j | | ƒ n Xd  S(   N(   t   objectt   __getattribute__t   __setattr__R   R   (   R   R	   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   D   s
    c         C   sI   y$ t  j |  | ƒ t  j |  | ƒ Wn t k
 rD |  j | ƒ n Xd  S(   N(   R   R   t   __delattr__R   R   (   R   R	   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   K   s
    c         C   s   |  j  j | ƒ d  S(   N(   t   __dict__t   update(   R   t   state(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __setstate__V   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R
   R   R   R   R   R   R   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR       s   										R   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s  Helper class used to hold undefined names until assignment.

    This class helps create any undefined subsections when an
    assignment is made to a nested value.  For example, if the
    statement is "cfg.a.b.c = 42", but "cfg.a.b" does not exist yet.
    c         C   s*   t  j |  d | ƒ t  j |  d | ƒ d  S(   NR	   t	   namespace(   R   R   (   R   R	   R!   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   __init__a   s    c         C   s#   |  j  j |  j ƒ } | | | <d  S(   N(   R!   R
   R	   (   R   R	   R   t   obj(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   e   s    c         C   s#   |  j  j |  j ƒ } | | | <d  S(   N(   R!   R
   R	   (   R   R	   R   R#   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   i   s    (   R   R   R    R"   R   R   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   Y   s   		t   BasicConfigc           B   s_   e  Z d  Z d
 Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d d „ Z
 d „  Z d	 „  Z RS(   s‹  Represents a hierarchical collection of named values.

    Values are added using dotted notation:

    >>> n = BasicConfig()
    >>> n.x = 7
    >>> n.name.first = 'paramjit'
    >>> n.name.last = 'oberoi'

    ...and accessed the same way, or with [...]:

    >>> n.x
    7
    >>> n.name.first
    'paramjit'
    >>> n.name.last
    'oberoi'
    >>> n['x']
    7
    >>> n['name']['first']
    'paramjit'

    Iterating over the namespace object returns the keys:

    >>> l = list(n)
    >>> l.sort()
    >>> l
    ['name', 'x']

    Values can be deleted using 'del' and printed using 'print'.

    >>> n.aaa = 42
    >>> del n.x
    >>> print n
    aaa = 42
    name.first = paramjit
    name.last = oberoi

    Nested namepsaces are also namespaces:

    >>> isinstance(n.name, ConfigNamespace)
    True
    >>> print n.name
    first = paramjit
    last = oberoi
    >>> sorted(list(n.name))
    ['first', 'last']

    Finally, values can be read from a file as follows:

    >>> from StringIO import StringIO
    >>> sio = StringIO('''
    ... # comment
    ... ui.height = 100
    ... ui.width = 150
    ... complexity = medium
    ... have_python
    ... data.secret.password = goodness=gracious me
    ... ''')
    >>> n = BasicConfig()
    >>> n._readfp(sio)
    >>> print n
    complexity = medium
    data.secret.password = goodness=gracious me
    have_python
    ui.height = 100
    ui.width = 150
    c         C   s   i  |  _  d  S(   N(   t   _data(   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR"   ¹   s    c         C   s   |  j  | S(   N(   R%   (   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   ¼   s    c         C   s   | |  j  | <d  S(   N(   R%   (   R   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   ¿   s    c         C   s   |  j  | =d  S(   N(   R%   (   R   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   Â   s    c         C   s   t  |  j ƒ S(   N(   t   iterR%   (   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR   Å   s    t    c         C   s¿   g  } |  j  j ƒ  } | j ƒ  x | D]ˆ } |  j  | } t | t ƒ rn | j | j d d | | f ƒ ƒ q& | d  k r” | j d | | f ƒ q& | j d | | | f ƒ q& Wd j | ƒ S(   Nt   prefixs   %s%s.s   %s%ss	   %s%s = %ss   
(	   R%   t   keyst   sortt
   isinstanceR    t   appendt   __str__t   Nonet   join(   R   R(   t   linesR)   R	   R   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR-   È   s    
&c         C   s   t  ƒ  } | |  j | <| S(   N(   R$   R%   (   R   R	   R#   (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR
   ×   s    	c   	      C   s)  x"t  r$| j ƒ  } | s Pn  | j ƒ  } | s7 q n  | d d k rM q n  | j d d ƒ } t | ƒ d k r€ | } d  } n  | d j ƒ  } | d j ƒ  } | j d ƒ } |  } x[ | d  D]O } | | k r | | } t | t ƒ st d | ƒ ‚ qqÀ | j	 | ƒ } qÀ W| | | d <q Wd  S(   Ni    t   #t   =i   t   .iÿÿÿÿs   value-namespace conflict(
   R   t   readlinet   stript   splitt   lenR.   R+   R    t	   TypeErrorR
   (	   R   t   fpt   linet   dataR	   R   t   name_componentst   nst   n(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   _readfpÜ   s0    	  	
N(   R   R   R    R.   R%   R"   R   R   R   R   R-   R
   R?   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR$   p   s   D						c         C   sŽ   x‡ | D] } | | } t  | t ƒ r| | |  k r] |  | } t  | t ƒ sl t d ƒ ‚ ql n |  j | ƒ } t | | ƒ q | |  | <q Wd S(   s¿  Imports values from source into target.

    Recursively walks the <source> ConfigNamespace and inserts values
    into the <target> ConfigNamespace.  For example:

    >>> n = BasicConfig()
    >>> n.playlist.expand_playlist = True
    >>> n.ui.display_clock = True
    >>> n.ui.display_qlength = True
    >>> n.ui.width = 150
    >>> print n
    playlist.expand_playlist = True
    ui.display_clock = True
    ui.display_qlength = True
    ui.width = 150

    >>> from iniparse import ini
    >>> i = ini.INIConfig()
    >>> update_config(i, n)
    >>> print i
    [playlist]
    expand_playlist = True
    <BLANKLINE>
    [ui]
    display_clock = True
    display_qlength = True
    width = 150

    s   value-namespace conflictN(   R+   R    R8   R
   t   update_config(   t   targett   sourceR	   R   t   myns(    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyR@   ú   s    

N(   R   R    R   R$   R@   (    (    (    s3   /usr/lib/python2.7/site-packages/iniparse/config.pyt   <module>   s   XŠ