ó
ú2ec           @   s   d  Z  d d l m Z m Z d d d g Z d e f d „  ƒ  YZ e ƒ  Z e ƒ  Z d e f d „  ƒ  YZ	 d „  Z
 e	 j  Z d	 S(
   s*   Paste Configuration Middleware and Objectsiÿÿÿÿ(   t   RegistryManagert   StackedObjectProxyt   DispatchingConfigt   CONFIGt   ConfigMiddlewarec           B   s`   e  Z d  Z d d „ Z d „  Z d	 d „ Z d „  Z d	 d „ Z d „  Z	 d „  Z
 e
 Z Z RS(
   s  
    This is a configuration object that can be used globally,
    imported, have references held onto.  The configuration may differ
    by thread (or may not).

    Specific configurations are registered (and deregistered) either
    for the process or for threads.
    R   c         C   s*   t  t |  ƒ j d | ƒ g  |  j d <d  S(   Nt   namet   _process_configs(   t   superR   t   __init__t   __dict__(   t   selfR   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR      s    c         C   s   |  j  | ƒ d S(   sŸ  
        Make ``conf`` the active configuration for this thread.
        Thread-local configuration always overrides process-wide
        configuration.

        This should be used like::

            conf = make_conf()
            dispatching_config.push_thread_config(conf)
            try:
                ... do stuff ...
            finally:
                dispatching_config.pop_thread_config(conf)
        N(   t   _push_object(   R
   t   conf(    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   push_thread_config   s    c         C   s   |  j  | ƒ d S(   s¹   
        Remove a thread-local configuration.  If ``conf`` is given,
        it is checked against the popped configuration and an error
        is emitted if they don't match.
        N(   t   _pop_object(   R
   R   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   pop_thread_config+   s    c         C   s   |  j  j | ƒ d S(   sg   
        Like push_thread_config, but applies the configuration to
        the entire process.
        N(   R   t   append(   R
   R   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   push_process_config3   s    c         C   s   |  j  |  j | ƒ d  S(   N(   t	   _pop_fromR   (   R
   R   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   pop_process_config:   s    c         C   sA   | j  ƒ  } | d  k	 r= | | k	 r= t d | | f ƒ ‚ n  d  S(   NsB   The config popped (%s) is not the same as the config expected (%s)(   t   popt   Nonet   AssertionError(   R
   t   lstR   t   popped(    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR   =   s
    c         C   sO   y t  t |  ƒ j ƒ  SWn1 t k
 rJ |  j r; |  j d St d ƒ ‚ n Xd  S(   Niÿÿÿÿs?   No configuration has been registered for this process or thread(   R   R   t   _current_objt	   TypeErrorR   t   AttributeError(   R
   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR   E   s    	N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   t   currentt   current_conf(    (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR   	   s   					c           B   s   e  Z d  Z e d d „ Z RS(   s  
    A WSGI middleware that adds a ``paste.config`` key (by default)
    to the request environment, as well as registering the
    configuration temporarily (for the length of the request) with
    ``paste.config.CONFIG`` (or any other ``DispatchingConfig``
    object).
    s   paste.configc            s5   ‡  ‡ ‡ ‡ f d †  } t  |  j |  ƒ j | ƒ d S(   sv   
        This delegates all requests to `application`, adding a *copy*
        of the configuration `config`.
        c            s~   |  j  ˆ t ƒ } ˆ j ƒ  } |  ˆ <|  d j ˆ | ƒ z ˆ  |  | ƒ } Wd  | t k ro |  j ˆ d  ƒ n
 | |  ˆ <X| S(   Ns   paste.registry(   t   gett	   no_configt   copyt   registerR   R   (   t   environt   start_responset   popped_configt   current_configt   app_iter(   t   applicationt   configt   dispatching_configt   environ_key(    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   register_configb   s    N(   R   t	   __class__R   (   R
   R*   R+   R,   R-   R.   (    (   R*   R+   R,   R-   s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR   \   s    (   R   R   R   R   R   (    (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyR   S   s   c         K   s&   | j  ƒ  } | j | ƒ t |  | ƒ S(   N(   R#   t   updateR   (   t   appt   global_conft
   local_confR   (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   make_config_filters   s    N(   R   t   paste.registryR    R   t   __all__R   R   t   objectR"   R   R4   t   make_config_middleware(    (    (    s6   /usr/local/lib/python2.7/dist-packages/paste/config.pyt   <module>   s   G		 	