
lYc           @   s  d  Z  d Z d Z d Z d Z d d l m Z m Z d d l m	 Z	 d d l
 Z
 d d l Z d d l Z d d l Z d d l 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 d 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' d" Z( d# Z) e j* d$ k r:d% Z+ n e j, d& k rRd' Z+ n d% Z+ y d d l- Z. e/ Z0 Wn e1 Z0 n Xy d d( l2 m3 Z3 Wn* e4 k
 rd) e j5 f d*     YZ3 n Xe j6 e7  Z8 e8 j9 re8 j: e3    n  d+ e; f d,     YZ< d- e; f d.     YZ= d/   Z> e? a@ d0 eA f d1     YZB d2 eB f d3     YZC d4 eB f d5     YZD d6   ZE d7   ZF d8 e; f d9     YZG d: eG f d;     YZH d< eH f d=     YZI d> eG f d?     YZJ d@ e; f dA     YZK dB e; f dC     YZL dD e; f dE     YZM dF   ZN dG   ZO dH e; f dI     YZP dJ eQ f dK     YZR dL   ZS dM   ZT d d lU ZV dN e; f dO     YZW e7 dP k reW dQ  ZX eX jY dR  n  d S(S   s  
This is a configuration module for Python.

This module should work under Python versions >= 2.2, and cannot be used with
earlier versions since it uses new-style classes.

Development and testing has only been carried out (so far) on Python 2.3.4 and
Python 2.4.2. See the test module (test_config.py) included in the
U{distribution<http://www.red-dove.com/python_config.html|_blank>} (follow the
download link).

A simple example - with the example configuration file::

    messages:
    [
      {
        stream : `sys.stderr`
        message: 'Welcome'
        name: 'Harry'
      }
      {
        stream : `sys.stdout`
        message: 'Welkom'
        name: 'Ruud'
      }
      {
        stream : $messages[0].stream
        message: 'Bienvenue'
        name: Yves
      }
    ]

a program to read the configuration would be::

    from config import Config

    f = file('simple.cfg')
    cfg = Config(f)
    for m in cfg.messages:
        s = '%s, %s' % (m.message, m.name)
        try:
            print >> m.stream, s
        except IOError, e:
            print e

which, when run, would yield the console output::

    Welcome, Harry
    Welkom, Ruud
    Bienvenue, Yves

See U{this tutorial<http://www.red-dove.com/python_config.html|_blank>} for more
information.

@version: 0.3.9

@author: Vinay Sajip

@copyright: Copyright (C) 2004-2010 Vinay Sajip. All Rights Reserved.


@var streamOpener: The default stream opener. This is a factory function which
takes a string (e.g. filename) and returns a stream suitable for reading. If
unable to open the stream, an IOError exception should be thrown.

The default value of this variable is L{defaultStreamOpener}. For an example
of how it's used, see test_config.py (search for streamOpener).
s&   Vinay Sajip <vinay_sajip@red-dove.com>t   alphas   0.3.9s   11 May 2010i(   t
   StringTypet   UnicodeType(   t   OrderedDictNt   at   9t   "t    t   {t   }t   [s   a[t   ]t   (s   ((t   )t   .t   ,t   :t   @t   +t   -t   *t   /t   %t   `t   $t   Truet   Falset   Nonet5   ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_t   win32s   
t   macs   (   t   NullHandlerR   c           B   s   e  Z d    Z RS(   c         C   s   d  S(   N(    (   t   selft   record(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   emit   s    (   t   __name__t
   __module__R"   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR      s   t   ConfigInputStreamc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s   
    An input stream which can read either ANSI files with default encoding
    or Unicode files with BOMs.

    Handles UTF-8, UTF-16LE, UTF-16BE. Could handle UTF-32 if Python had
    built-in support.
    c         C   s%  d } | j d  } d } t rT | t j k r9 d } qT | t j k rT d } qT n  | d k r | d  t j k r d } d } q | d  t j k r d } d } q | d  t j k r d } d	 } q d
 } n  | d
 k r | j	 |  n  | rt j
 |  } | |  } n  | |  _ | |  _ d S(   s   
        Initialize an instance.

        @param stream: The underlying stream to be read. Should be seekable.
        @type stream: A stream (file-like object).
        i   is   utf-32les   utf-32bei   s   utf-8i   s   utf-16les   utf-16bei    N(   R   t   readt	   has_utf32t   codecst   BOM_UTF32_LEt   BOM_UTF32_BEt   BOM_UTF8t   BOM_UTF16_LEt   BOM_UTF16_BEt   seekt	   getreadert   streamt   encoding(   R    R0   R1   t	   signaturet   usedt   reader(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __init__   s4    						c         C   sm   | d k s |  j  d  k r0 |  j j |  } n9 d } x0 | d k rh | |  j j d  7} | d 8} q9 W| S(   Ni    u    i   (   R1   R   R0   R&   (   R    t   sizet   rv(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR&      s    c         C   s   |  j  j   d  S(   N(   R0   t   close(   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR8      s    c         C   sd   |  j  d  k r d } n d } x? t r_ |  j j d  } | rL | | 7} n  | d k r! Pq! q! W| S(   NR   u    i   s   
(   R1   R   R   R0   R&   (   R    t   linet   c(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   readline   s    		(   R#   R$   t   __doc__R5   R&   R8   R;   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR%      s
   	#	
	t   ConfigOutputStreamc           B   s5   e  Z d  Z d d  Z d   Z d   Z d   Z RS(   s   
    An output stream which can write either ANSI files with default encoding
    or Unicode files with BOMs.

    Handles UTF-8, UTF-16LE, UTF-16BE. Could handle UTF-32 if Python had
    built-in support.
    c         C   s   | d k	 r! t |  j   } n  | |  _ | d k rI | j t j  n| | d k rh | j t j  n] | d k r | j t j  n> | d k r | j t j	  n | d k r | j t j
  n  | d k	 r t j |  } | |  } n  | |  _ d S(   s   
        Initialize an instance.

        @param stream: The underlying stream to be written.
        @type stream: A stream (file-like object).
        @param encoding: The desired encoding.
        @type encoding: str
        s   utf-8s   utf-16bes   utf-16les   utf-32bes   utf-32leN(   R   t   strt   lowerR1   t   writeR(   R+   R-   R,   R*   R)   t	   getwriterR0   (   R    R0   R1   t   writer(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5      s"    		c         C   s   |  j  j |  d  S(   N(   R0   R@   (   R    t   data(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR@     s    c         C   s   |  j  j   d  S(   N(   R0   t   flush(   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRD     s    c         C   s   |  j  j   d  S(   N(   R0   R8   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR8   	  s    N(   R#   R$   R<   R   R5   R@   RD   R8   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR=      s
   		c         C   s   t  t |  d   S(   s  
    This function returns a read-only stream, given its name. The name passed
    in should correspond to an existing stream, otherwise an exception will be
    raised.

    This is the default value of L{streamOpener}; assign your own callable to
    streamOpener to return streams based on names. For example, you could use
    urllib2.urlopen().

    @param name: The name of a stream, most commonly a file name.
    @type name: str
    @return: A stream with the specified name.
    @rtype: A read-only stream (file-like object)
    t   rb(   R%   t   file(   t   name(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   defaultStreamOpener  s    t   ConfigErrorc           B   s   e  Z d  Z RS(   sE   
    This is the base class of exceptions raised by this module.
    (   R#   R$   R<   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRI     s   t   ConfigFormatErrorc           B   s   e  Z d  Z RS(   sa   
    This is the base class of exceptions raised due to syntax errors in
    configurations.
    (   R#   R$   R<   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRJ   %  s   t   ConfigResolutionErrorc           B   s   e  Z d  Z RS(   sc   
    This is the base class of exceptions raised due to semantic errors in
    configurations.
    (   R#   R$   R<   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRK   ,  s   c         C   s8   t  |   t  d  k r t S|  j d d  }  |  j   S(   s%  
    See if a passed-in value is an identifier. If the value passed in is not a
    string, False is returned. An identifier consists of alphanumerics or
    underscore characters.

    Examples::

        isWord('a word') ->False
        isWord('award') -> True
        isWord(9) -> False
        isWord('a_b_c_') ->True

    @note: isWord('9abc') will return True - not exactly correct, but adequate
    for the way it's used here.

    @param s: The name to be tested
    @type s: any
    @return: True if a word, else False
    @rtype: bool
    R   t   _(   t   typeR   t   replacet   isalnum(   t   s(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   isWord3  s    c         C   s>   |  s | } n+ | d d k r, |  | } n |  d | } | S(   s  
    Make a path from a prefix and suffix.

    Examples::

        makePath('', 'suffix') -> 'suffix'
        makePath('prefix', 'suffix') -> 'prefix.suffix'
        makePath('prefix', '[1]') -> 'prefix[1]'

    @param prefix:  The prefix to use. If it evaluates as false, the suffix
                    is returned.
    @type prefix:   str
    @param suffix:  The suffix to use. It is either an identifier or an
                    index in brackets.
    @type suffix:   str
    @return:        The path concatenation of prefix and suffix, with a
                    dot if the suffix is not a bracketed index.
    @rtype:         str

    i    R
   R   (    (   t   prefixt   suffixR7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   makePathM  s    	t	   Containerc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   
    This internal class is the base class for mappings and sequences.

    @ivar path: A string which describes how to get
    to this instance from the root of the hierarchy.

    Example::

        a.list.of[1].or['more'].elements
    c         C   s   t  j |  d |  d S(   s   
        Initialize an instance.

        @param parent: The parent of this instance in the hierarchy.
        @type parent: A L{Container} instance.
        t   parentN(   t   objectt   __setattr__(   R    RV   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5   v  s    c         C   s   t  j |  d |  d S(   s   
        Set the path for this instance.
        @param path: The path - a string which describes how to get
        to this instance from the root of the hierarchy.
        @type path: str
        t   pathN(   RW   RX   (   R    RY   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   setPath  s    c         C   sF   t  | t  r! | j |   } n! t  | t  rB | j |   } n  | S(   s  
        Evaluate items which are instances of L{Reference} or L{Expression}.

        L{Reference} instances are evaluated using L{Reference.resolve},
        and L{Expression} instances are evaluated using
        L{Expression.evaluate}.

        @param item: The item to be evaluated.
        @type item: any
        @return: If the item is an instance of L{Reference} or L{Expression},
        the evaluated value is returned, otherwise the item is returned
        unchanged.
        (   t
   isinstancet	   Referencet   resolvet
   Expressiont   evaluate(   R    t   item(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR_     s
    c         C   s
   t   d S(   s  
        Write this instance to a stream at the specified indentation level.

        Should be redefined in subclasses.

        @param stream: The stream to write to
        @type stream: A writable stream (file-like object)
        @param indent: The indentation level
        @type indent: int
        @param container: The container of this instance
        @type container: L{Container}
        @raise NotImplementedError: If a subclass does not override this
        N(   t   NotImplementedError(   R    R0   t   indentt	   container(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   writeToStream  s    c         C   s   t  |  t  r d } n
 | d } t  | t  s@ t  | t  r] | j d | | t f  n; t |  t k r~ t |  } n  | j d | | t f  d  S(   Nt    s     s   %s%r%ss   %s%s%s(	   R[   t   MappingR\   R^   R@   t   NEWLINERM   R   t   repr(   R    t   valueR0   Rb   t   indstr(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt
   writeValue  s    	
(   R#   R$   R<   R5   RZ   R_   Rd   Rk   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRU   k  s   
						Rf   c           B   s   e  Z d  Z d d  Z d   Z d   Z e Z d   Z d   Z	 d   Z
 e d  Z d   Z e Z d	   Z d d
  Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z RS(   sN   
    This internal class implements key-value mappings in configurations.
    c         C   s`   t  j |  |  t j |  d d  t j |  d i   t j |  d g   t j |  d i   d S(   s   
        Initialize an instance.

        @param parent: The parent of this instance in the hierarchy.
        @type parent: A L{Container} instance.
        RY   R   RC   t   ordert   commentsN(   RU   R5   RW   RX   (   R    RV   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s
    c         C   sp   t  j |  d  } | | k r- t |   n  t  j |  d  } t  j |  d  } | | =| j |  | | =d S(   s    
        Remove an item
        RC   Rl   Rm   N(   RW   t   __getattribute__t   AttributeErrort   remove(   R    t   keyRC   Rl   Rm   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __delitem__  s    c         C   sD   t  j |  d  } | | k r- t |   n  | | } |  j |  S(   NRC   (   RW   Rn   Ro   R_   (   R    Rq   RC   R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __getitem__  s
    
c         C   s   | d k r i  S| d k r  g  St  j |  d  } | j |  } | rY t | |  } n- t  j |  |  } | d  k r t |   n  | S(   Nt   __dict__t   __methods__t   __members__RC   (   Ru   Rv   (   RW   Rn   t   has_keyt   getattrR   Ro   (   R    RG   RC   t   useDataR7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRn     s    c         c   s0   x# |  j    D] } | |  | f Vq Wt  d  S(   N(   t   keyst   StopIteration(   R    Rq   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt	   iteritems  s    c         C   s   t  j |  d  } | | k S(   NRl   (   RW   Rn   (   R    R`   Rl   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __contains__  s    c         C   s   t  j |  d  } t  j |  d  } t  j |  d  } | | | <| | k r\ | j |  n | su t d |   n  | | | <d S(   s  
        Add a key-value mapping with a comment.

        @param key: The key for the mapping.
        @type key: str
        @param value: The value for the mapping.
        @type value: any
        @param comment: The comment for the key (can be None).
        @type comment: str
        @param setting: If True, ignore clashes. This is set
        to true when called from L{__setattr__}.
        @raise ConfigFormatError: If an existing key is seen
        again and setting is False.
        RC   Rl   Rm   s   repeated key: %sN(   RW   Rn   t   appendRJ   (   R    Rq   Ri   t   commentt   settingRC   Rl   Rm   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt
   addMapping  s    
c         C   s   |  j  | | d  t  d  S(   N(   R   R   R   (   R    RG   Ri   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRX     s    c         C   s   t  j |  d  S(   sC   
        Return the keys in a similar way to a dictionary.
        Rl   (   RW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRz     s    c         C   s   | |  k r |  | S| S(   s:   
        Allows a dictionary-style get operation.
        (    (   R    Rq   t   default(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   get"  s    c         C   s   t  t j |  d   S(   NRC   (   R>   RW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __str__*  s    c         C   s   t  t j |  d   S(   NRC   (   Rh   RW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __repr__-  s    c         C   s   t  t j |  d   S(   NRl   (   t   lenRW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __len__0  s    c         C   s
   |  j    S(   N(   t   iterkeys(   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   __iter__3  s    c         C   s   t  j |  d  } | j   S(   NRl   (   RW   Rn   R   (   R    Rl   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   6  s    c         C   s   | d } t  |   d k r0 | j d t  na t | t  rO | j t  n  | j d | t f  |  j | | d  | j d | t f  d S(   s  
        Write this instance to a stream at the specified indentation level.

        Should be redefined in subclasses.

        @param stream: The stream to write to
        @type stream: A writable stream (file-like object)
        @param indent: The indentation level
        @type indent: int
        @param container: The container of this instance
        @type container: L{Container}
        s     i    s    { }%ss   %s{%si   s   %s}%sN(   R   R@   Rg   R[   Rf   t   save(   R    R0   Rb   Rc   Rj   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRd   :  s    
i    c         C   s   | d } t  j |  d  } t  j |  d  } d } x | D] } |  j | } t |  rc | }	 n t |  }	 | r | j d | | f  n  | j d | | |	 f  | | }
 t |
 t  r |
 j | | |   q; |  j	 |
 | |  q; Wd S(   s  
        Save this configuration to the specified stream.
        @param stream: A stream to which the configuration is written.
        @type stream: A write-only stream (file-like object).
        @param indent: The indentation level for the output.
        @type indent: int
        s     Rl   RC   i    s   %s#%ss   %s%-*s :N(
   RW   Rn   Rm   RQ   Rh   R@   R[   RU   Rd   Rk   (   R    R0   Rb   Rj   Rl   RC   t   maxlenRq   R   t   skeyRi   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   Q  s     
	
N(   R#   R$   R<   R   R5   Rr   Rs   t   __getattr__Rn   R|   R}   R   R   RX   t   __setitem__Rz   R   R   R   R   R   R   Rd   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRf     s(   													t   Configc           B   si   e  Z d  Z d e f d     YZ d
 d
 d  Z d   Z d
 d  Z d
 d  Z	 d d  Z
 d	   Z RS(   s   
    This class represents a configuration, and is the only one which clients
    need to interface to, under normal circumstances.
    t	   Namespacec           B   s    e  Z d  Z d   Z d   Z RS(   s|   
        This internal class is used for implementing default namespaces.

        An instance acts as a namespace.
        c         C   s   t  |  _  t |  _ d  S(   N(   t   syst   os(   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5   x  s    	c         C   s   d d j  |  j j    S(   Ns   <Namespace('%s')>R   (   t   joinRt   Rz   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   |  s    (   R#   R$   R<   R5   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   r  s   	c         C   s   t  j |  |  t j |  d t |    t j |  d t j   g  t j |  d t    | d k	 r t	 | t
  s t	 | t  r t d k r t a n  t |  } n  t j |  d  } | |  n  d S(   s8  
        Initializes an instance.

        @param streamOrFile: If specified, causes this instance to be loaded
        from the stream (by calling L{load}). If a string is provided, it is
        passed to L{streamOpener} to open a stream. Otherwise, the passed
        value is assumed to be a stream and used as is.
        @type streamOrFile: A readable stream (file-like object) or a name.
        @param parent: If specified, this becomes the parent of this instance
        in the configuration hierarchy.
        @type parent: a L{Container} instance.
        R4   t
   namespacest	   resolvingt   loadN(   Rf   R5   RW   RX   t   ConfigReaderR   R   t   setR   R[   R   R   t   streamOpenerRH   Rn   (   R    t   streamOrFileRV   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    	c         C   s-   t  j |  d  } | j |  | j   d S(   s  
        Load the configuration from the specified stream. Multiple streams can
        be used to populate the same instance, as long as there are no
        clashing keys. The stream is closed.
        @param stream: A stream from which the configuration is read.
        @type stream: A read-only stream (file-like object).
        @raise ConfigError: if keys in the loaded configuration clash with
        existing keys.
        @raise ConfigFormatError: if there is a syntax error in the stream.
        R4   N(   RW   Rn   R   R8   (   R    R0   R4   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c         C   sF   t  j |  d  } | d k r. | j |  n t | d | |  d S(   s  
        Add a namespace to this configuration which can be used to evaluate
        (resolve) dotted-identifier expressions.
        @param ns: The namespace to be added.
        @type ns: A module or other namespace suitable for passing as an
        argument to vars().
        @param name: A name for the namespace, which, if specified, provides
        an additional level of indirection.
        @type name: str
        R   i    N(   RW   Rn   R   R~   t   setattr(   R    t   nsRG   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   addNamespace  s    c         C   sC   t  j |  d  } | d k r. | j |  n t | d |  d S(   s   
        Remove a namespace added with L{addNamespace}.
        @param ns: The namespace to be removed.
        @param name: The name which was specified when L{addNamespace} was
        called.
        @type name: str
        R   i    N(   RW   Rn   R   Rp   t   delattr(   R    R   RG   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   removeNamespace  s    i    c         C   s0   t  j |  | |  | d k r, | j   n  d S(   s  
        Save this configuration to the specified stream. The stream is
        closed if this is the top-level configuration in the hierarchy.
        L{Mapping.save} is called to do all the work.
        @param stream: A stream to which the configuration is written.
        @type stream: A write-only stream (file-like object).
        @param indent: The indentation level for the output.
        @type indent: int
        i    N(   Rf   R   R8   (   R    R0   Rb   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    
c         C   sD   d | } y t  |  SWn% t k
 r? } t t |    n Xd S(   s  
        Obtain a value in the configuration via its path.
        @param path: The path of the required value
        @type path: str
        @return the value at the specified path.
        @rtype: any
        @raise ConfigError: If the path is invalid
        s   self.N(   t   evalt	   ExceptionRI   R>   (   R    RY   RP   t   e(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt	   getByPath  s
    	
N(   R#   R$   R<   RW   R   R   R5   R   R   R   R   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   l  s   	t   Sequencec           B   sx   e  Z d  Z d e f d     YZ d d  Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   sU   
    This internal class implements a value which is a sequence of other values.
    t   SeqIterc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sX   
        This internal class implements an iterator for a L{Sequence} instance.
        c         C   s1   | |  _  t t j | d   |  _ d |  _ d  S(   NRC   i    (   t   seqR   RW   Rn   t   limitt   index(   R    R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    	c         C   s   |  S(   N(    (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c         C   s>   |  j  |  j k r t  n  |  j |  j  } |  j  d 7_  | S(   Ni   (   R   R   R{   R   (   R    R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   next  s
    	(   R#   R$   R<   R5   R   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s   		c         C   s:   t  j |  |  t j |  d g   t j |  d g   d S(   s   
        Initialize an instance.

        @param parent: The parent of this instance in the hierarchy.
        @type parent: A L{Container} instance.
        RC   Rm   N(   RU   R5   RW   RX   (   R    RV   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    c         C   sB   t  j |  d  } t  j |  d  } | j |  | j |  d S(   s   
        Add an item to the sequence.

        @param item: The item to add.
        @type item: any
        @param comment: A comment for the item.
        @type comment: str
        RC   Rm   N(   RW   Rn   R~   (   R    R`   R   RC   Rm   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR~     s    	c         C   s   t  j |  d  } y | | } Wn< t t t f k
 r^ t d | t  j |  d  f   n Xt | t  s |  j |  } n3 g  } x$ | D] } | j	 |  j |   q W| } | S(   NRC   s   %r is not a valid index for %rRY   (
   RW   Rn   t
   IndexErrort   KeyErrort	   TypeErrorRK   R[   t   listR_   R~   (   R    R   RC   R7   t   resultR   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRs     s    &c         C   s   t  j |   S(   N(   R   R   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   %  s    c         C   s   t  t j |  d   S(   NRC   (   Rh   RW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   (  s    c         C   s   t  |   S(   N(   R>   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   +  s    c         C   s   t  t j |  d   S(   NRC   (   R   RW   Rn   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   .  s    c         C   s   | d } t  |   d k r0 | j d t  na t | t  rO | j t  n  | j d | t f  |  j | | d  | j d | t f  d S(   s  
        Write this instance to a stream at the specified indentation level.

        Should be redefined in subclasses.

        @param stream: The stream to write to
        @type stream: A writable stream (file-like object)
        @param indent: The indentation level
        @type indent: int
        @param container: The container of this instance
        @type container: L{Container}
        s     i    s    [ ]%ss   %s[%si   s   %s]%sN(   R   R@   Rg   R[   Rf   R   (   R    R0   Rb   Rc   Rj   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyRd   1  s    
c   	      C   s   | d k r t  d   n  t j |  d  } t j |  d  } | d } x t d t |   D]r } | | } | | } | r | j d | | f  n  t | t  r | j | | |   q_ |  j	 | | |  q_ Wd S(   s  
        Save this instance to the specified stream.
        @param stream: A stream to which the configuration is written.
        @type stream: A write-only stream (file-like object).
        @param indent: The indentation level for the output, > 0
        @type indent: int
        i    s,   sequence cannot be saved as a top-level itemRC   Rm   s     s   %s#%sN(
   RI   RW   Rn   t   xrangeR   R@   R[   RU   Rd   Rk   (	   R    R0   Rb   RC   Rm   Rj   t   iRi   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   H  s    


N(   R#   R$   R<   RW   R   R   R5   R~   Rs   R   R   R   R   Rd   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s   							R\   c           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sW   
    This internal class implements a value which is a reference to another value.
    c         C   s"   | |  _  | |  _ | g |  _ d S(   sK  
        Initialize an instance.

        @param config: The configuration which contains this reference.
        @type config: A L{Config} instance.
        @param type: The type of reference.
        @type type: BACKTICK or DOLLAR
        @param ident: The identifier which starts the reference.
        @type ident: str
        N(   t   configRM   t   elements(   R    R   RM   t   ident(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5   c  s    		c         C   s   |  j  j | | f  d S(   s   
        Add an element to the reference.

        @param type: The type of reference.
        @type type: BACKTICK or DOLLAR
        @param ident: The identifier which continues the reference.
        @type ident: str
        N(   R   R~   (   R    RM   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt
   addElementr  s    	c         C   s9   x2 | d k	 r4 t | t  r4 t j | d  } q W| S(   s  
        Find the closest enclosing configuration to the specified container.

        @param container: The container to start from.
        @type container: L{Container}
        @return: The closest enclosing configuration, or None.
        @rtype: L{Config}
        RV   N(   R   R[   R   RW   Rn   (   R    Rc   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt
   findConfig}  s    	c         C   s3  d } t j | d  } |  j |  } x| d k	 r	|  j t k r t j | d  } t } t |   d d !} x{ | D]s } yP y t | t	 |   } Wn) t
 k
 r t | i  t	 |   } n Xt } PWqw t j d | |  qw Xqw W| rPqn |  j d }	 |	 | j k r:| j j |	  t d |	   n  | j j |	  |	 }
 yK | |
 } x) |  j d D] } | d }
 | |
 } qkW| j j |	  PWn= t k
 r  n* t j d |
 t j   d  d } n X| j j |	  |  j t j | d	   } q* W| d k r/t d
 |  | f   n  | S(   s  
        Resolve this instance in the context of a container.

        @param container: The container to resolve from.
        @type container: L{Container}
        @return: The resolved value.
        @rtype: any
        @raise ConfigResolutionError: If resolution fails.
        RY   R   i   is   unable to resolve %r in %ri    s   Circular reference: %rs   Unable to resolve %r: %sRV   s-   unable to evaluate %r in the configuration %sN(   R   RW   Rn   R   RM   t   BACKTICKR   R>   R   t   varsR   R   t   loggert   debugR   R   Rp   RK   t   addR   t   exc_infot   discard(   R    Rc   R7   RY   t   currentR   t   foundRP   R   t   firstkeyRq   R`   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR]     sZ    


c         C   s}   |  j  d } xF |  j  d D]7 \ } } | t k rD | d | 7} q | d | 7} q W|  j t k rq t | t St | Sd  S(   Ni    i   s   .%ss   [%r](   R   t   DOTRM   R   t   DOLLAR(   R    RP   t   ttt   tv(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c         C   s
   |  j    S(   N(   R   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    (	   R#   R$   R<   R5   R   R   R]   R   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR\   _  s   				9	R^   c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s_   
    This internal class implements a value which is obtained by evaluating an expression.
    c         C   s   | |  _  | |  _ | |  _ d S(   s  
        Initialize an instance.

        @param op: the operation expressed in the expression.
        @type op: PLUS, MINUS, STAR, SLASH, MOD
        @param lhs: the left-hand-side operand of the expression.
        @type lhs: any Expression or primary value.
        @param rhs: the right-hand-side operand of the expression.
        @type rhs: any Expression or primary value.
        N(   t   opt   lhst   rhs(   R    R   R   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    		c         C   s   d |  j  |  j |  j f S(   Ns   %r %s %r(   R   R   R   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c         C   s
   |  j    S(   N(   R   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c         C   s  |  j  } t | t  r* | j |  } n! t | t  rK | j |  } n  |  j } t | t  ru | j |  } n! t | t  r | j |  } n  |  j } | t k r | | } nU | t	 k r | | } n< | t
 k r | | } n# | t k r| | } n
 | | } | S(   s  
        Evaluate this instance in the context of a container.

        @param container: The container to evaluate in from.
        @type container: L{Container}
        @return: The evaluated value.
        @rtype: any
        @raise ConfigResolutionError: If evaluation fails.
        @raise ZeroDivideError: If division by zero occurs.
        @raise TypeError: If the operation is invalid, e.g.
        subtracting one string from another.
        (   R   R[   R\   R]   R^   R_   R   R   t   PLUSt   MINUSt   STARt   SLASH(   R    Rc   R   R   R   R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR_     s*    			
(   R#   R$   R<   R5   R   R   R_   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR^     s
   			R   c           B   s   e  Z d  Z d   Z d   Z d   Z d   Z e Z d   Z d d d  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(   sE   
    This internal class implements a parser for configurations.
    c         C   s   d  |  _ | |  _ d |  _ d |  _ d  |  _ d  |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ d t |  _ |  j |  j |  _ g  |  _ g  |  _ d  |  _ d  S(   Ni    t   #s    	
s   '"s   :-+*/%,.{}[]()@`$t
   0123456789s   %s(   R   t   filenameR   t   linenot   colnot   lastct
   last_tokent   commentcharst
   whitespacet   quotest   punctt   digitst	   WORDCHARSt	   wordcharst
   identcharst   pbcharst   pbtokensR   (   R    R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s     													c         C   s   d |  j  |  j |  j f S(   s   
        Return the current location (filename, line, column) in the stream
        as a string.

        Used when printing error messages,

        @return: A string representing a location in the stream being read.
        @rtype: str
        s	   %s(%d,%d)(   R   R   R   (   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   location&  s    
c         C   sg   |  j  r |  j  j   } nH |  j j d  } |  j d 7_ | d k rc |  j d 7_ d |  _ n  | S(   s   
        Get the next char from the stream. Update line and column numbers
        appropriately.

        @return: The next character from the stream.
        @rtype: str
        i   s   
(   R   t   popR0   R&   R   R   (   R    R:   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   getChar2  s    	c         C   s   d t  |   S(   Ns   <ConfigReader at 0x%08x>(   t   id(   R    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   D  s    c      	   C   s  |  j  r |  j  j   S|  j } d |  _ d } t } xct r|  j   } | sS Pn0 | d k r | j   |  _ |  j	 d 7_	 q7 n  | |  j
 k r| } | } t } t } t } |  j   } | | k r |  j   }	 |	 | k r t } | | 7} | | 7} q0|  j j |	  |  j j |  n |  j j |  x t r|  j   } | sOPn  | | 7} | | k r| r| st |  d k r| j | d   r| d d k rPqn  | d k r| } q3t } q3W| st d |  j   | | f   n  Pn  | |  j k r| |  _ q7 q7 | |  j k r| } | } |  j d	 k sU|  j |  j k r| d
 k rjt } q| d k rt } qn  Pq7 | |  j k r| } t } t }
 xt r|  j   } | sPn  | |  j k r| | 7} q| d k r| j d  d k  r|
 r| | 7} q| d k rK| j d  d k  rK|
 rK| | 7} q| d k r| j d  d k  r| j d  d k  r| | 7} t }
 q| r| |  j k r|  j j |  n  PqWPq7 | |  j k rz| } t } |  j   } x/ | r| |  j k r| | 7} |  j   } qW| r7|  j j |  n  | d k rLt } n* | d k rat } n | d k rvt  } n  Pq7 t d |  j   | f   q7 W| r| d |  _ n	 d |  _ | |  _! | | f S(   sd  
        Get a token from the stream. String values are returned in a form
        where you need to eval() the returned value to get the actual
        string. The return value is (token_type, token_value).

        Multiline string tokenizing is thanks to David Janes (BlogMatrix)

        @return: The next token.
        @rtype: A token tuple.
        R   R   i   i   i   is   \s&   %s: Unterminated quoted string: %r, %rR   R
   R   R   i    R   t   eER   t   ER   R   R   s   %s: Unexpected character: %riN("   R   R   R0   R   R   t   EOFR   R   R;   R   R   t   STRINGR   R   R~   R   t   endswithRJ   R   R   R   R   R   t   LBRACK2t   LPAREN2R   t   NUMBERt   findR   t   WORDt   TRUEt   FALSEt   NONER   (   R    R0   t   tokenR   R:   t   quotet   escapedt	   multilinet   c1t   c2t   in_exponent(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   getTokenI  s    				
	
<

"	!		('!
	
			 		c         C   s   | d k	 rO | d k r' t d   n  |  j j t t j | d  |   n  |  j |  |  j   |  _	 |  j
 |  j  |  j	 d t k r t d |  j   |  j	 d f   n  d S(   s  
        Load the configuration from the specified stream.

        @param stream: A stream from which to load the configuration.
        @type stream: A stream (file-like object).
        @param parent: The parent of the configuration (to which this reader
        belongs) in the hierarchy. Specified when the configuration is
        included in another one.
        @type parent: A L{Container} instance.
        @param suffix: The suffix of this configuration in the parent
        configuration. Should be specified whenever the parent is not None.
        @raise ConfigError: If parent is specified but suffix is not.
        @raise ConfigFormatError: If there are syntax errors in the stream.
        s5   internal error: load called with parent but no suffixRY   i    s   %s: expecting EOF, found %ri   N(   R   RI   R   RZ   RT   RW   Rn   t	   setStreamR   R   t   parseMappingBodyR   RJ   R   (   R    R0   RV   RS   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    (c         C   sI   | |  _  t | d  r$ | j } n d } | |  _ d |  _ d |  _ d S(   s   
        Set the stream to the specified value, and prepare to read from it.

        @param stream: A stream from which to load the configuration.
        @type stream: A stream (file-like object).
        RG   t   ?i   N(   R0   t   hasattrRG   R   R   R   (   R    R0   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    			c         C   sX   |  j  d | k r< t d |  j   | |  j  d f   n  |  j  } |  j   |  _  | S(   s  
        Ensure that the current token type matches the specified value, and
        advance to the next token.

        @param t: The token type to match.
        @type t: A valid token type.
        @return: The token which was last read from the stream before this
        function is called.
        @rtype: a token tuple - see L{getToken}.
        @raise ConfigFormatError: If the token does not match what's expected.
        i    s   %s: expecting %s, found %ri   (   R   RJ   R   R   (   R    t   tR7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   match  s
    )	c         C   s1   x* |  j  d t t g k r, |  j |  q Wd S(   s   
        Parse the internals of a mapping, and add entries to the provided
        L{Mapping}.

        @param parent: The mapping to add entries to.
        @type parent: A L{Mapping} instance.
        i    N(   R   R   R   t   parseKeyValuePair(   R    RV   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    c   
      C   s  |  j  } |  j \ } } | t k r3 | } | } nG | t k rX t |  } d | } n" d } t | |  j   | f   |  j   |  _ |  j d t k r |  j   |  _ |  j	 | |  } n t
 } y | j | | |  Wn9 t k
 r}	 t d |  j   |	 |  j d f   n X|  j d } | t t t t t g k rmd } t | |  j   |  j d f   n  | t k r|  j   |  _ n  d S(   s   
        Parse a key-value pair, and add it to the provided L{Mapping}.

        @param parent: The mapping to add entries to.
        @type parent: A L{Mapping} instance.
        @raise ConfigFormatError: if a syntax error is found.
        s   [%s]s&   %s: expecting word or string, found %ri    s
   %s: %s, %ri   s>   %s: expecting one of EOF, WORD, STRING,RCURLY, COMMA, found %rN(   R   R   R   R   R   RJ   R   R   t   COLONt
   parseValueR   R   R   R   t   RCURLYt   COMMA(
   R    RV   R   R   R   Rq   RS   t   msgRi   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s4    		&c         C   s   |  j  d } | t t t t t t t t t	 t
 g
 k rF |  j   } nk | t k rg |  j | |  } nJ | t t g k r |  j | |  } n# t d |  j   |  j  d f   | S(   sO  
        Parse a value.

        @param parent: The container to which the value will be added.
        @type parent: A L{Container} instance.
        @param suffix: The suffix for the value.
        @type suffix: str
        @return: The value
        @rtype: any
        @raise ConfigFormatError: if a syntax error is found.
        i    s   %s: unexpected input: %ri   (   R   R   R   R   t   LPARENR   R   R   R   R   R   t   parseScalart   LBRACKt   parseSequencet   LCURLYt   ATt   parseMappingRJ   R   (   R    RV   RS   R   R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   ,  s    c         C   s  t  |  } | j t t j | d  |   |  j t  |  j } |  j d } x | t	 t
 t t t t t t t t t t g k rd t |  } |  j | |  } | j | |  |  j d } |  j } | t k rT |  j t  |  j d } |  j } qT qT qT W|  j t  | S(   s  
        Parse a sequence.

        @param parent: The container to which the sequence will be added.
        @type parent: A L{Container} instance.
        @param suffix: The suffix for the value.
        @type suffix: str
        @return: a L{Sequence} instance representing the sequence.
        @rtype: L{Sequence}
        @raise ConfigFormatError: if a syntax error is found.
        RY   i    s   [%d](   R   RZ   RT   RW   Rn   R   R  R   R   R   R   R   R  R  R   R   R   R   R   R   R   R   R~   R   t   RBRACK(   R    RV   RS   R7   R   R   Ri   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR  E  s&    "			
c         C   s   |  j  d t k rk |  j t  t |  } | j t t j | d  |   |  j |  |  j t	  n7 |  j t
  |  j t  \ } } t t |  |  } | S(   s  
        Parse a mapping.

        @param parent: The container to which the mapping will be added.
        @type parent: A L{Container} instance.
        @param suffix: The suffix for the value.
        @type suffix: str
        @return: a L{Mapping} instance representing the mapping.
        @rtype: L{Mapping}
        @raise ConfigFormatError: if a syntax error is found.
        i    RY   (   R   R  R   Rf   RZ   RT   RW   Rn   R   R   R  R   R   R   (   R    RV   RS   R7   R   t   fn(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR  e  s    c         C   sn   |  j    } |  j d } xN | t t g k ri |  j |  |  j    } t | | |  } |  j d } q W| S(   s   
        Parse a scalar - a terminal value such as a string or number, or
        an L{Expression} or L{Reference}.

        @return: the parsed scalar
        @rtype: any scalar
        @raise ConfigFormatError: if a syntax error is found.
        i    (   t	   parseTermR   R   R   R   R^   (   R    R   R   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR  ~  s    	c         C   sq   |  j    } |  j d } xQ | t t t g k rl |  j |  |  j    } t | | |  } |  j d } q W| S(   s   
        Parse a term in an additive expression (a + b, a - b)

        @return: the parsed term
        @rtype: any scalar
        @raise ConfigFormatError: if a syntax error is found.
        i    (   t   parseFactorR   R   R   t   MODR   R^   (   R    R   R   R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR
    s    c         C   sK  |  j  d } | t t t t t t g k rc |  j  d } | t k rS t |  } n  |  j |  n | t	 k r |  j t	  |  j
   } |  j t  n | t k r |  j t  |  j t  } n | t k r |  j t  |  j t  } |  j t  nL | t k r$|  j t  |  j
   } n# t d |  j   |  j  d f   | S(   s   
        Parse a factor in an multiplicative expression (a * b, a / b, a % b)

        @return: the parsed factor
        @rtype: any scalar
        @raise ConfigFormatError: if a syntax error is found.
        i    i   s   %s: unexpected input: %r(   R   R   R   R   R   R   R   R   R   R  R  t   RPARENR   t   parseReferenceR   R   RJ   R   (   R    R   R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR    s.    c         C   sY   |  j  t  } t |  j | | d  } x* |  j d t t g k rT |  j |  q+ W| S(   s   
        Parse a reference.

        @return: the parsed reference
        @rtype: L{Reference}
        @raise ConfigFormatError: if a syntax error is found.
        i   i    (   R   R   R\   R   R   R   R   t   parseSuffix(   R    RM   t   wordR7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR    s
    c         C   s   |  j  d } | t k rL |  j t  |  j t  } | j t | d  n |  j t  |  j  \ } } | t t g k r t d |  j	   | f   n  |  j
   |  _  t |  } |  j t  | j t |  d S(   s   
        Parse a reference suffix.

        @param ref: The reference of which this suffix is a part.
        @type ref: L{Reference}.
        @raise ConfigFormatError: if a syntax error is found.
        i    i   s'   %s: expected number or string, found %rN(   R   R   R   R   R   R   R   R   RJ   R   R   R   R  R  (   R    t   refR   R  R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR    s    N(   R#   R$   R<   R5   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  R
  R  R  R  (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s(   					v				'		 				!	c         C   sl   |  | } | | } t  | t  r; t  | t  r; d } n- t  | t  rb t  | t  rb d } n d } | S(   s  
    A default resolver for merge conflicts. Returns a string
    indicating what action to take to resolve the conflict.

    @param map1: The map being merged into.
    @type map1: L{Mapping}.
    @param map2: The map being used as the merge operand.
    @type map2: L{Mapping}.
    @param key: The key in map2 (which also exists in map1).
    @type key: str
    @return: One of "merge", "append", "mismatch" or "overwrite"
             indicating what action should be taken. This should
             be appropriate to the objects being merged - e.g.
             there is no point returning "merge" if the two objects
             are instances of L{Sequence}.
    @rtype: str
    t   mergeR~   t   mismatch(   R[   Rf   R   (   t   map1t   map2Rq   t   obj1t   obj2R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   defaultMergeResolve  s    

		c         C   s+   t  |  | |  } | d k r' d } n  | S(   s  
    An overwriting resolver for merge conflicts. Calls L{defaultMergeResolve},
    but where a "mismatch" is detected, returns "overwrite" instead.

    @param map1: The map being merged into.
    @type map1: L{Mapping}.
    @param map2: The map being used as the merge operand.
    @type map2: L{Mapping}.
    @param key: The key in map2 (which also exists in map1).
    @type key: str
    R  t	   overwrite(   R  (   R  R  Rq   R7   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   overwriteMergeResolve  s    	t   ConfigMergerc           B   s>   e  Z d  Z e d  Z d   Z d   Z d   Z d   Z RS(   sE  
    This class is used for merging two configurations. If a key exists in the
    merge operand but not the merge target, then the entry is copied from the
    merge operand to the merge target. If a key exists in both configurations,
    then a resolver (a callable) is called to decide how to handle the
    conflict.
    c         C   s   | |  _  d S(   s  
        Initialise an instance.

        @param resolver:
        @type resolver: A callable which takes the argument list
        (map1, map2, key) where map1 is the mapping being merged into,
        map2 is the merge operand and key is the clashing key. The callable
        should return a string indicating how the conflict should be resolved.
        For possible return values, see L{defaultMergeResolve}. The default
        value preserves the old behaviour
        N(   t   resolver(   R    R  (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    c         C   s   |  j  | |  d S(   sF  
        Merge two configurations. The second configuration is unchanged,
        and the first is changed to reflect the results of the merge.

        @param merged: The configuration to merge into.
        @type merged: L{Config}.
        @param mergee: The configuration to merge.
        @type mergee: L{Config}.
        N(   t   mergeMapping(   R    t   mergedt   mergee(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR  +  s    
c   	      C   s   | j    } x | j    D] } | | k r< | | | | <q | | } | | } |  j | | |  } | d k r |  j | |  q | d k r |  j | |  q | d k r | | | <q | d k r |  j | |  q d } t | |   q Wd S(   s4  
        Merge two mappings recursively. The second mapping is unchanged,
        and the first is changed to reflect the results of the merge.

        @param map1: The mapping to merge into.
        @type map1: L{Mapping}.
        @param map2: The mapping to merge.
        @type map2: L{Mapping}.
        R  R~   R  R  s/   unable to merge: don't know how to implement %rN(   Rz   R  R  t   mergeSequencet   handleMismatcht
   ValueError(	   R    R  R  Rz   Rq   R  R  t   decisionR   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR  7  s"    


c         C   s   t  j | d  } t  j | d  } x | D] } | j |  q+ Wt  j | d  } t  j | d  } x | D] } | j |  qm Wd S(   sD  
        Merge two sequences. The second sequence is unchanged,
        and the first is changed to have the elements of the second
        appended to it.

        @param seq1: The sequence to merge into.
        @type seq1: L{Sequence}.
        @param seq2: The sequence to merge.
        @type seq2: L{Sequence}.
        RC   Rm   N(   RW   Rn   R~   (   R    t   seq1t   seq2t   data1t   data2t   objt   comment1t   comment2(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   U  s    c         C   s   t  d | | f   d S(   s   
        Handle a mismatch between two objects.

        @param obj1: The object to merge into.
        @type obj1: any
        @param obj2: The object to merge.
        @type obj2: any
        s   unable to merge %r with %rN(   RI   (   R    R  R  (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR!  i  s    	(	   R#   R$   R<   R  R5   R  R  R   R!  (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR    s   			t
   ConfigListc           B   s   e  Z d  Z d   Z RS(   s   
    This class implements an ordered list of configurations and allows you
    to try getting the configuration from each entry in turn, returning
    the first successfully obtained value.
    c         C   sh   t  } d } x< |  D]4 } y | j |  } t } PWq t k
 rF q Xq W| sd t d |   n  | S(   s  
        Obtain a value from the first configuration in the list which defines
        it.

        @param path: The path of the value to retrieve.
        @type path: str
        @return: The value from the earliest configuration in the list which
        defines it.
        @rtype: any
        @raise ConfigError: If no configuration in the list has an entry with
        the specified path.
        s   unable to resolve %rN(   R   R   R   R   RI   (   R    RY   R   R7   t   entry(    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR   {  s    (   R#   R$   R<   R   (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR+  t  s   c            s     f d       |   S(   Nc            s   t  |  t t t f  r: g  |  D] }   |  ^ q }  n t  |  t  r t |   }  xh |  j   D] }   |  |  |  | <qb Wn= t  |  t  r x+ |  j   D] }   |  |  |  | <q Wn  |  S(   N(   R[   R   t   tupleR   Rf   t   dictRz   (   R(  R   t   k(   t   walker(    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR0    s    "(    (   t   d(    (   R0  s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   mappingToDict  s    c            s     f d       |   S(   Nc            s   t  |  t t t f  r: g  |  D] }   |  ^ q }  n t  |  t  r t |   }  xt |  j   D] }   |  |  |  | <qb WnI t  |  t  r t |   }  x+ |  j   D] }   |  |  |  | <q Wn  |  S(   N(   R[   R   R-  R   Rf   R   Rz   R.  (   R(  R   R/  (   R0  (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR0    s    "(    (   R1  (    (   R0  s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   mappingToOrderedDict  s    t
   ConfigJsonc           B   s/   e  Z d    Z d   Z e d  Z d   Z RS(   c         C   s   | |  _  d  S(   N(   t	   _filename(   R    R   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR5     s    c         C   s5   t  |  j d  } | j   } | j   t j |  S(   Nt   r(   t   openR5  R&   R8   t   jsont   loads(   R    t   fRC   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    
c         C   sS   yB t  |  j d  } t j | | d | d d } | j   t SWn
   n Xd  S(   Nt   wt	   sort_keysRb   i   (   R7  R5  R8  t   dumpR8   R   (   R    RC   t   sortR:  (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR     s    
c         C   sW   y8 | } t  t | d   } t |  } |  j |  Wn t k
 rR } | GHn Xd  S(   NR6  (   R   RF   R2  R   R   (   R    t   config_filenamet   fconft   cfgR   (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   configToJson  s    (   R#   R$   R5   R   R   R   RB  (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyR4    s   		
t   __main__s   /home/marco/Desktop/pcored.confs7   /home/marco/Desktop/p3dev/pcored/etc/pcored/pcored.conf(Z   R<   t
   __author__t
   __status__t   __version__t   __date__t   typesR   R   t   collectionsR   R(   t   loggingR   R   t   pprintR   R   R   R   R  R   R  R   R  R  R   R  R   R   R   R  R   R   R   R   R  R   R   R   R   R   R   t   platformRg   RG   t   encodings.utf_32t	   encodingsR   R'   R   t   logging.handlersR   t   ImportErrort   Handlert	   getLoggerR#   R   t   handlerst
   addHandlerRW   R%   R=   RH   R   R   R   RI   RJ   RK   RQ   RT   RU   Rf   R   R   R\   R^   R   R  R  R  R   R+  R2  R3  t
   simplejsonR8  R4  RA  RB  (    (    (    s=   /var/www/c4bv.valis/psync-server-c4/p3py_sub/paytor/config.pyt   <module>T   s   		


E.			Pyzs= 		`!		$