³ò
+e|Mc           @   s…  d  Z  d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z y d d k	 Z	 Wn e
 j
 o d d k Z	 n Xy d d k l Z Wn# e
 j
 o d d k l Z n Xd d k l Z d d k l Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d a e a e i d d ƒ a d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  Z e e e e e d „ Z d S(   s²  
Creates a session object in your WSGI environment.

Use like:

..code-block:: Python

    environ['paste.session.factory']()

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.

@@: This doesn't do any locking, and may cause problems when a single
session is accessed concurrently.  Also, it loads and saves the
session for each request, with no caching.  Also, sessions aren't
expired.
iÿÿÿÿ(   t   SimpleCookieN(   t   md5(   t   wsgilib(   t   requestt   SessionMiddlewarec           B   s   e  Z d d  „ Z d „  Z RS(   c         K   s   | |  _  | |  _ d  S(   N(   t   applicationt
   factory_kw(   t   selfR   t   global_confR   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   __init__/   s    	c            sƒ   t  | |  i  ‰ ˆ | d <g  ‰ d  ‡  ‡ ‡ f d † } |  i | | ƒ } ‡  ‡ ‡ f d †  } ‡ f d †  } t i | | | ƒ S(   Ns   paste.session.factoryc            sK   ˆ i  p |  | g ˆ (ˆ  |  | ƒ Sn | i ˆ i ƒ  ƒ ˆ  |  | | ƒ S(   N(   t   createdt   appendt   set_cookie_header(   t   statust   headerst   exc_info(   t   start_responset   session_factoryt   remember_headers(    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   session_start_response8   s
    
c             s`   ˆ i  oR ˆ oK ˆ \ }  } | i ˆ i ƒ  ƒ t d ƒ } ˆ  |  | | i | d  f ƒ n d  S(   NsL   You cannot get the session after content from the app_iter has been returned(   R
   R   R   t
   ValueErrort	   __class__t   None(   R   R   t   exc(   R   R   R   (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   start@   s    	c              s   ˆ  i  o ˆ  i ƒ  n d  S(   N(   t   usedt   close(    (   R   (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   I   s    
(   t   SessionFactoryR   R   R   R   t   add_start_close(   R   t   environR   R   t   app_iterR   R   (    (   R   R   R   s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   __call__3   s    
	N(   t   __name__t
   __module__R   R	   R   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   -   s   R   c           B   sS   e  Z d  d
 d d „ Z d „  Z d „  Z d „  Z d
 d „ Z d „  Z d	 „  Z	 RS(   t   _SID_i<   i   c         K   sS   t  |  _ t  |  _ | |  _ | |  _ d  |  _ | p t |  _ | |  _	 | |  _
 d  S(   N(   t   FalseR
   R   R   t   cookie_nameR   t   sessiont   FileSessiont   session_classt   session_class_kwt
   expiration(   R   R   R$   R'   t   session_expirationR(   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR	   R   s    						c         C   s  t  |  _ |  i d  j	 o |  i i ƒ  Sn t i |  i ƒ } d  } | i |  i	 ƒ oO | |  i	 i
 |  _ y" |  i |  i d t |  i } Wq¤ t j
 o q¤ Xn | d  j o: t  |  _ |  i ƒ  |  _ |  i |  i d t  |  i } n | i ƒ  | |  _ | i ƒ  S(   Nt   create(   t   TrueR   R%   R   t   dataR   t   get_cookiesR   t   has_keyR$   t   valuet   sidR'   R#   R(   t   KeyErrorR
   t   make_sidt   clean_up(   R   t   cookiesR%   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   a   s(    			
	c         C   sI   |  i  d  j	 o t Sn t i |  i ƒ } | i |  i ƒ o t Sn t S(   N(	   R%   R   R,   R   R.   R   R/   R$   R#   (   R   R5   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   has_sessionx   s    c         C   sM   d i  g  } t i t i ƒ  ƒ d  D] } | d | q$ ~ ƒ d |  i ƒ  S(   Nt    i   s   %02dt   -(   t   joint   timet	   localtimet	   unique_id(   R   t   _[1]t   x(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR3   €   s    c         C   sÞ   t  i  ƒ  t i ƒ  g } t t d ƒ o | i t i ƒ  ƒ n | d j	 o | i t | ƒ ƒ n t t	 | ƒ ƒ } y | i
 ƒ  SWnT t j
 oH g  } x+ | i ƒ  D] } | i d t | ƒ ƒ q§ Wd i | ƒ Sn Xd S(   s   
        Generates an opaque, identifier string that is practically
        guaranteed to be unique.  If an object is passed, then its
        id() is incorporated into the generation.  Relies on md5 and
        returns a 32 character long string.
        t   timess   %02xR7   N(   R:   t   randomt   hasattrt   osR   R?   R   t   idR   t   strt	   hexdigestt   AttributeErrort   digestt   ordR9   (   R   t
   for_objectt   rt   md5_hashRE   t   char(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR<   …   s     c         C   s   t  ƒ  } |  i | |  i <d | |  i d <t i t i ƒ  |  i d ƒ } t i d | ƒ | |  i d <t | ƒ i d d ƒ \ } } | | f S(   Nt   /t   pathi<   s   %a, %d-%b-%Y %H:%M:%S GMTt   expiress   : i   (	   R    R1   R$   R:   t   gmtimeR)   t   strftimeRD   t   split(   R   t   ct   gmt_expiration_timet   nameR0   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   œ   s    	 c         C   s%   |  i  d  j	 o |  i  i ƒ  n d  S(   N(   R%   R   R   (   R   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   §   s    NiÐ  (
   R    R!   R   R	   R   R6   R3   R<   R   R   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   O   s   				t   secondsi   i<   R&   c           B   sY   e  Z e e i ƒ  d d  d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   i@  c         C   sš   | o# t  | t ƒ o t | d ƒ } n | |  _ | p
 t ‚ n | |  _ | |  _ | p' t i i	 |  i
 ƒ  ƒ p
 t ‚ q„ n d  |  _ | |  _ d  S(   Ni   (   t
   isinstancet
   basestringt   intt   chmodR2   t   session_file_pathR1   RB   RN   t   existst   filenameR   t   _dataR)   (   R   R1   R+   R[   RZ   R)   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR	   ²   s    	
			c         C   s   t  i i |  i |  i ƒ S(   N(   RB   RN   R9   R[   R1   (   R   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR]   Æ   s    c         C   sy   |  i  d  j	 o |  i  Sn t i i |  i ƒ  ƒ o5 t |  i ƒ  d ƒ } t i | ƒ |  _  | i	 ƒ  n
 h  |  _  |  i  S(   Nt   rb(
   R^   R   RB   RN   R\   R]   t   opent   cPicklet   loadR   (   R   t   f(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR-   É   s    	c         C   s±   |  i  d  j	 o |  i ƒ  } t i i | ƒ } |  i  p | o t i | ƒ q© q­ t | d ƒ } t i	 |  i  | ƒ | i
 ƒ  | o! |  i o t i | |  i ƒ q­ n d  S(   Nt   wb(   R^   R   R]   RB   RN   R\   t   unlinkR`   Ra   t   dumpR   RZ   (   R   R]   R\   Rc   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR   Ô   s    

c         C   sŠ   z| t  i d |  i d ƒ } t  i  i ƒ  } xM t i |  i ƒ D]9 \ } } } x' | D] } |  i | d | d | ƒqT Wq> WWd  t a	 Xd  S(   NRV   i<   t   exp_timet   now(
   t   datetimet	   timedeltaR)   Rh   RB   t   walkR[   t   _clean_up_fileR#   t   cleaning_up(   R   Rg   Rh   t   roott   dirst   filesRc   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt	   _clean_upâ   s      %c         C   sö   | i  d ƒ } t | ƒ d j o d  Sn | d } yp t i t | d d !ƒ t | d d !ƒ t | d d !ƒ t | d d !ƒ t | d d !ƒ t | d d	 !ƒ ƒ } Wn t j
 o d  Sn X| | | j  o# t i t i i |  i	 | ƒ ƒ n d  S(
   NR8   i   i    i   i   i   i
   i   i   (
   RR   t   lenRi   RY   R   RB   t   removeRN   R9   R[   (   R   Rc   Rg   Rh   t   tt	   sess_time(    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyRl   ï   s     
	c         C   sŒ   t  i  i ƒ  } t o d  Sn t p t t | j  oQ t pF t a y) | a t i d |  i ƒ } | i	 ƒ  Wq„ t
 a ‚  q„ Xqˆ n d  S(   Nt   target(   Ri   Rh   Rm   t   last_cleanupt   cleanup_cycleR,   t	   threadingt   ThreadRq   R   R#   (   R   Rh   Rt   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR4     s    N(   R    R!   R#   t   tempfilet
   gettempdirR   R	   R]   R-   R   Rq   Rl   R4   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR&   °   s   					t
   _NoDefaultc           B   s   e  Z d  „  Z RS(   c         C   s   d S(   Ns   <dynamic default>(    (   R   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   __repr__  s    (   R    R!   R~   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyR}     s   c         C   sï   | t  j o | i d d ƒ } n t | ƒ } | t  j o | i d d ƒ } n t | ƒ } | t  j o | i d d ƒ } n | t  j o | i d d	 ƒ } n | t  j o | i d
 d ƒ } n t |  d | d | d | d | d | ƒS(   s  
    Adds a middleware that handles sessions for your applications.
    The session is a peristent dictionary.  To get this dictionary
    in your application, use ``environ['paste.session.factory']()``
    which returns this persistent dictionary.

    Configuration:

      session_expiration:
          The time each session lives, in minutes.  This controls
          the cookie expiration.  Default 12 hours.

      expiration:
          The time each session lives on disk.  Old sessions are
          culled from disk based on this.  Default 48 hours.

      cookie_name:
          The cookie name used to track the session.  Use different
          names to avoid session clashes.

      session_file_path:
          Sessions are put in this location, default /tmp.

      chmod:
          The octal chmod you want to apply to new sessions (e.g., 660
          to make the sessions group readable/writable)

    Each of these also takes from the global configuration.  cookie_name
    and chmod take from session_cookie_name and session_chmod
    R*   i<   i   R)   i0   t   session_cookie_nameR"   R[   s   /tmpt   session_chmodR$   RZ   iÐ  i@  N(   t	   NoDefaultt   getRY   R   R   (   t   appR   R*   R)   R$   R[   RZ   (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pyt   make_session_middleware  s     %i„  (   t   __doc__t   CookieR    R:   R@   RB   Ri   Ry   R{   Ra   t   ImportErrort   picklet   hashlibR   t   pasteR   R   t   objectR   R   R   Rw   R#   Rm   Rj   Rx   R&   R}   R   R„   (    (    (    s\   /afs/athena.mit.edu/user/x/a/xavid/Public/bazki/lib/Paste-1.7.5.1-py2.5.egg/paste/session.pys   <module>   s<   "]h	