ó
ú2ec           @   s   d  Z  d d l m Z d d l m Z d d l Z e j j Z i  Z	 d e
 f d     YZ d e
 f d     YZ e e d	  Z d S(
   sĖ  
Creates a session object.

In your application, use::

    environ['paste.flup_session_service'].session

This will return a dictionary.  The contents of this dictionary will
be saved to disk when the request is completed.  The session will be
created when you first fetch the session dictionary, and a cookie will
be sent in that case.  There's current no way to use sessions without
cookies, and there's no way to delete a session except to clear its
data.
iĸĸĸĸ(   t   httpexceptions(   t   wsgilibNt	   NoDefaultc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyR      s   t   SessionMiddlewarec           B   sĪ   e  Z i e j d  d e d f g f d 6e j d  d e d f d d e d f g f d 6e j d  d e d f d d	 e d
 f g f d 6Z d e
 e
 d  Z d   Z RS(   t   session_timeoutt   timeouti<   t   memoryt   session_dirt   storeDirs   /tmp/sessionst   diskt   session_filet	   storeFiles   /tmp/session.shelvet   shelvec         K   s  | |  _  | t k r* | j d d  } n  | |  _ y  |  j |  j \ |  _ |  _ Wn< t k
 r t d |  j d j |  j j	    f   n Xi  } x? |  j D]4 \ } } }	 }
 |	 | j | |
   } | | | <qĒ W|  j |   |  _
 | t k r| j d d  } n  | |  _ d  S(   Nt   session_typeR   s0   The session_type %s is unknown (I know about %s)s   , t   session_cookiet   _SID_(   t   applicationR   t   getR   t   session_classest   store_classt
   store_argst   KeyErrort   joint   keyst   storet   cookie_name(   t   selft   appt   global_confR   R   t   store_configt   kwt   config_namet   kw_namet   coercert   defaultt   value(    (    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyt   __init__.   s&    		 #c            sŲ   t  j |  j | d |  j d |  j     | d <d     f d  } y |  j | |  } Wng t j k
 rē } | j p} i  j	   }   j
 |  t |  | _   j     n   j     n Xt j |   j  S(   Nt
   cookieNamet	   fieldNames   paste.flup_session_servicec            s     j  |   |  | |  S(   N(   t	   addCookie(   t   statust   headerst   exc_info(   t   servicet   start_response(    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyt   cookie_start_responseN   s    (   t   flup_sessiont   SessionServiceR   R   t   NoneR   R    t   HTTPExceptionR+   t   itemsR)   t   dictt   closeR   t	   add_close(   R   t   environR.   R/   t   app_itert   eR+   (    (   R-   R.   s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyt   __call__H   s"    


N(   R   R   R0   t   MemorySessionStoret   intt   DiskSessionStoret   strt   ShelveSessionStoreR   R2   R   R&   R;   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyR      s   	c      	   K   s   t  |  d | d | d | | S(   s   
    Wraps the application in a session-managing middleware.
    The session service can then be found in
    ``environ['paste.flup_session_service']``
    R   R   R   (   R   (   R   R   R   R   R   (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyt   make_session_middleware`   s    		(   t   __doc__t   pasteR    R   t   flup.middleware.sessiont   flupt
   middlewaret   sessionR0   t   store_cachet   objectR   R   RA   (    (    (    s<   /usr/local/lib/python2.7/dist-packages/paste/flup_session.pyt   <module>   s   B