ó
Xé?_c           @   sµ  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 m
 Z
 m Z m Z d d l m Z d d l m Z d d l m Z d d l m Z e ƒ  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z e e _ d „  Z e e _ d e _ d e e d d e e d e e e d „ Z  e e d d e e e d „ Z! d „  Z" d S(   sT  Session implementation for CherryPy.

You need to edit your config file to use sessions. Here's an example::

    [/]
    tools.sessions.on = True
    tools.sessions.storage_type = "file"
    tools.sessions.storage_path = "/home/site/sessions"
    tools.sessions.timeout = 60

This sets the session to be stored in files in the directory
/home/site/sessions, and the session timeout to 60 minutes. If you omit
``storage_type`` the sessions will be saved in RAM.
``tools.sessions.on`` is the only required line for working sessions,
the rest are optional.

By default, the session ID is passed in a cookie, so the client's browser must
have cookies enabled for your site.

To set data for the current session, use
``cherrypy.session['fieldname'] = 'fieldvalue'``;
to get data use ``cherrypy.session.get('fieldname')``.

================
Locking sessions
================

By default, the ``'locking'`` mode of sessions is ``'implicit'``, which means
the session is locked early and unlocked late. Be mindful of this default mode
for any requests that take a long time to process (streaming responses,
expensive calculations, database lookups, API calls, etc), as other concurrent
requests that also utilize sessions will hang until the session is unlocked.

If you want to control when the session data is locked and unlocked,
set ``tools.sessions.locking = 'explicit'``. Then call
``cherrypy.session.acquire_lock()`` and ``cherrypy.session.release_lock()``.
Regardless of which mode you use, the session is guaranteed to be unlocked when
the request is complete.

=================
Expiring Sessions
=================

You can force a session to expire with :func:`cherrypy.lib.sessions.expire`.
Simply call that function at the point you want the session to expire, and it
will cause the session cookie to expire client-side.

===========================
Session Fixation Protection
===========================

If CherryPy receives, via a request cookie, a session id that it does not
recognize, it will reject that id and create a new one to return in the
response cookie. This `helps prevent session fixation attacks
<http://en.wikipedia.org/wiki/Session_fixation#Regenerate_SID_on_each_request>`_.
However, CherryPy "recognizes" a session id by looking up the saved session
data for that id. Therefore, if you never save any session data,
**you will get a new session id for every request**.

================
Sharing Sessions
================

If you run multiple instances of CherryPy (for example via mod_python behind
Apache prefork), you most likely cannot use the RAM session backend, since each
instance of CherryPy will have its own memory space. Use a different backend
instead, and verify that all instances are pointing at the same file or db
location. Alternately, you might try a load balancer which makes sessions
"sticky". Google is your friend, there.

================
Expiration Dates
================

The response cookie will possess an expiration date to inform the client at
which point to stop sending the cookie back in requests. If the server time
and client time differ, expect sessions to be unreliable. **Make sure the
system time of your server is accurate**.

CherryPy defaults to a 60-minute session timeout, which also applies to the
cookie which is sent to the client. Unfortunately, some versions of Safari
("4 public beta" on Windows XP at least) appear to have a bug in their parsing
of the GMT expiration date--they appear to interpret the date as one hour in
the past. Sixty minutes minus one hour is pretty close to zero, so you may
experience this bug as a new session id for every request, unless the requests
are less than one second apart. To fix, try increasing the session.timeout.

On the other extreme, some users report Firefox sending cookies after their
expiration date, although this was on a system with an inaccurate system time.
Maybe FF doesn't trust system time.
iÿÿÿÿN(   t	   copyitemst   picklet   random20t
   unicodestr(   t   httputil(   t   lockfile(   t   locking(   t   is_iteratort   Sessionc           B   s[  e  Z d  Z d Z d Z d „  Z d „  Z e e e d d ƒZ	 d Z
 e Z e Z d Z d Z d Z e Z e Z e Z 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 e d „ Z  d „  Z! e" i  d ƒ rd „  Z# n  d d „ Z$ d „  Z% d d „ Z& d „  Z' d „  Z( d „  Z) d „  Z* RS(   s6   A CherryPy dict-like Session object (one per request).c         C   s   |  j  S(   N(   t   _id(   t   self(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   _get_idv   s    c         C   s+   | |  _  x |  j D] } | | ƒ q Wd  S(   N(   R	   t   id_observers(   R
   t   valuet   o(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   _set_idy   s    	t   docs   The current session ID.i<   i   c         K   sþ   g  |  _  i  |  _ x* | j ƒ  D] \ } } t |  | | ƒ q W| |  _ t |  _ | d  k r† |  j ry t	 j
 d d ƒ n  |  j ƒ  nt | |  _ |  j ƒ  r¾ |  j rú t	 j
 d | d ƒ qú n< |  j rÞ t	 j
 d | d ƒ n  d  |  _ t |  _ |  j ƒ  d  S(   Ns   No id given; making a new ones   TOOLS.SESSIONSs   Set id to %s.s1   Expired or malicious session %r; making a new one(   R   t   _datat   itemst   setattrt
   originalidt   Falset   missingt   Nonet   debugt   cherrypyt   logt   _regeneratet   idt   _existst   True(   R
   R   t   kwargst   kt   v(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __init__¢   s(    											c         C   s   t  j  j ƒ  S(   s³   Generate the session specific concept of 'now'.

        Other session providers can override this to use alternative,
        possibly timezone aware, versions of 'now'.
        (   t   datetimet   now(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR$   ¾   s    c         C   s   t  |  _ |  j ƒ  d S(   s,   Replace the current session (with a new id).N(   R   t   regeneratedR   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt
   regenerateÆ   s    	c         C   s  |  j  d  k	 r? |  j r2 t j d |  j  d ƒ n  |  j ƒ  n  |  j } | rw |  j ƒ  |  j rw t j d d ƒ qw n  d  |  _  x: |  j  d  k r¼ |  j ƒ  |  _  |  j	 ƒ  rƒ d  |  _  qƒ qƒ W|  j rà t j d |  j  d ƒ n  | r|  j
 ƒ  |  j rt j d d ƒ qn  d  S(   Ns5   Deleting the existing session %r before regeneration.s   TOOLS.SESSIONSs   Old lock released.s   Set id to generated %s.s   Regenerated lock acquired.(   R   R   R   R   R   t   deletet   lockedt   release_lockt   generate_idR   t   acquire_lock(   R
   t   old_session_was_locked(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   Ë   s0    	
	
			

	c         C   s   d S(   s   Clean up expired sessions.N(    (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   clean_upé   s    c         C   s   t  ƒ  S(   s   Return a new session id.(   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR*   í   s    c         C   sÌ   z’ |  j  rn t j d |  j d ƒ } |  j ƒ  | } |  j r^ t j d |  j | f d ƒ n  |  j	 | ƒ n# |  j r‘ t j d |  j d ƒ n  Wd |  j
 rÇ |  j ƒ  |  j rÇ t j d d ƒ qÇ n  Xd S(   s   Save session data.t   secondsi<   s    Saving session %r with expiry %ss   TOOLS.SESSIONSs0   Skipping save of session %r (no session loaded).Ns   Lock released after save.(   t   loadedR#   t	   timedeltat   timeoutR$   R   R   R   R   t   _saveR(   R)   (   R
   t   tt   expiration_time(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   saveñ   s"    			
		
	c         C   s   |  j  ƒ  } | d
 k s. | d |  j ƒ  k  r] |  j rQ t j d |  j d ƒ n  i  |  _ n0 |  j r€ t j d |  j d ƒ n  | d |  _ t |  _	 |  j
 } |  j r| j rt j j j t j |  j |  j d d d ƒ} | j ƒ  | | _ | j ƒ  |  j rt j d	 d ƒ qn  d
 S(   s4   Copy stored session data into this session instance.i   s"   Expired session %r, flushing data.s   TOOLS.SESSIONSs   Data loaded for session %r.i    i<   t   names   Session cleanups   Started cleanup thread.N(   t   _loadR   R$   R   R   R   R   R   R   R/   t	   __class__t
   clean_freqt   clean_threadt   processt   pluginst   Monitort   engineR-   t	   subscribet   start(   R
   t   datat   clsR3   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   load
  s*    "	
	
			
	
	c         C   s1   |  j  ƒ  |  j r- t j d |  j d ƒ n  d S(   s   Delete stored session data.s   Deleted session %s.s   TOOLS.SESSIONSN(   t   _deleteR   R   R   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR'   )  s    
	c         C   s!   |  j  s |  j ƒ  n  |  j | S(   N(   R/   RC   R   (   R
   t   key(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __getitem__2  s    	c         C   s'   |  j  s |  j ƒ  n  | |  j | <d  S(   N(   R/   RC   R   (   R
   RE   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __setitem__7  s    	c         C   s$   |  j  s |  j ƒ  n  |  j | =d  S(   N(   R/   RC   R   (   R
   RE   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __delitem__<  s    	c         C   sI   |  j  s |  j ƒ  n  | t k r2 |  j j | ƒ S|  j j | | ƒ Sd S(   s¦   Remove the specified key and return the corresponding value.
        If key is not found, default is returned if given,
        otherwise KeyError is raised.
        N(   R/   RC   R   R   t   pop(   R
   RE   t   default(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRI   A  s
    	c         C   s#   |  j  s |  j ƒ  n  | |  j k S(   N(   R/   RC   R   (   R
   RE   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __contains__M  s    	t   has_keyc         C   s#   |  j  s |  j ƒ  n  | |  j k S(   s2   D.has_key(k) -> True if D has a key k, else False.(   R/   RC   R   (   R
   RE   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRL   S  s    	c         C   s)   |  j  s |  j ƒ  n  |  j j | | ƒ S(   s<   D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.(   R/   RC   R   t   get(   R
   RE   RJ   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRM   Y  s    	c         C   s*   |  j  s |  j ƒ  n  |  j j | ƒ d S(   s?   D.update(E) -> None.  Update D from E: for k in E: D[k] = E[k].N(   R/   RC   R   t   update(   R
   t   d(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRN   _  s    	c         C   s)   |  j  s |  j ƒ  n  |  j j | | ƒ S(   sA   D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D.(   R/   RC   R   t
   setdefault(   R
   RE   RJ   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRP   e  s    	c         C   s'   |  j  s |  j ƒ  n  |  j j ƒ  d S(   s,   D.clear() -> None.  Remove all items from D.N(   R/   RC   R   t   clear(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRQ   k  s    	c         C   s#   |  j  s |  j ƒ  n  |  j j ƒ  S(   s   D.keys() -> list of D's keys.(   R/   RC   R   t   keys(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRR   q  s    	c         C   s#   |  j  s |  j ƒ  n  |  j j ƒ  S(   s9   D.items() -> list of D's (key, value) pairs, as 2-tuples.(   R/   RC   R   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   w  s    	c         C   s#   |  j  s |  j ƒ  n  |  j j ƒ  S(   s!   D.values() -> list of D's values.(   R/   RC   R   t   values(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRS   }  s    	N(+   t   __name__t
   __module__t   __doc__R   R	   R   R   R   t   propertyR   R1   R   R(   R/   R:   R9   R   R   R%   R   R"   R$   R&   R   R-   R*   R5   RC   R'   RF   RG   RH   RI   RK   t   hasattrRL   RM   RN   RP   RQ   RR   R   RS   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   m   sL   																			t
   RamSessionc           B   s\   e  Z i  Z i  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   c         C   s  |  j  ƒ  } x¤ t |  j ƒ D]“ \ } \ } } | | k r y |  j | =Wn t k
 r[ n Xy< |  j | j d t ƒ r— |  j j | ƒ } | j ƒ  n  Wq¯ t k
 r« q¯ Xq q Wx^ t	 |  j ƒ D]M } | |  j k rÃ |  j | j d t ƒ rÃ |  j j | ƒ } | j ƒ  qÃ qÃ Wd S(   s   Clean up expired sessions.t   blockingN(
   R$   R    t   cachet   KeyErrort   lockst   acquireR   RI   t   releaset   list(   R
   R$   R	   RA   R4   t   lock(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR-   Š  s"    "(c         C   s   |  j  |  j k S(   N(   R   R[   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   ¡  s    c         C   s   |  j  j |  j ƒ S(   N(   R[   RM   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR7   ¤  s    c         C   s   |  j  | f |  j |  j <d  S(   N(   R   R[   R   (   R
   R4   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR2   §  s    c         C   s   |  j  j |  j d  ƒ d  S(   N(   R[   RI   R   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRD   ª  s    c         C   s/   t  |  _ |  j j |  j t j ƒ  ƒ j ƒ  d S(   s?   Acquire an exclusive lock on the currently-loaded session data.N(   R   R(   R]   RP   R   t	   threadingt   RLockR^   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR+   ­  s    	c         C   s!   |  j  |  j j ƒ  t |  _ d S(   s6   Release the lock on the currently-loaded session data.N(   R]   R   R_   R   R(   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR)   ²  s    c         C   s   t  |  j ƒ S(   s%   Return the number of active sessions.(   t   lenR[   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __len__·  s    (   RT   RU   R[   R]   R-   R   R7   R2   RD   R+   R)   Re   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRY   „  s   							t   FileSessionc           B   sž   e  Z d  Z d Z d Z e j Z d d „ Z	 d „  Z
 e e
 ƒ Z
 d „  Z d „  Z d d „ Z d „  Z d	 „  Z d d
 „ Z d d „ Z d „  Z d „  Z RS(   sÆ  Implementation of the File backend for sessions

    storage_path
        The folder where session data will be saved. Each session
        will be saved as pickle.dump(data, expiration_time) in its own file;
        the filename will be self.SESSION_PREFIX + self.id.

    lock_timeout
        A timedelta or numeric seconds indicating how long
        to block acquiring a lock. If None (default), acquiring a lock
        will block indefinitely.
    s   session-s   .lockc         K   s§   t  j j | d ƒ | d <| j d d  ƒ t j |  d | | t |  j t	 t
 f ƒ rs t j d |  j ƒ |  _ n  t |  j t j t d  ƒ f ƒ s£ t d ƒ ‚ n  d  S(   Nt   storage_patht   lock_timeoutR   R.   s=   Lock timeout must be numeric seconds or a timedelta instance.(   t   ost   patht   abspathRP   R   R   R"   t
   isinstanceRh   t   intt   floatR#   R0   t   typet
   ValueError(   R
   R   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR"   Ï  s    !c         K   sK   t  j j | d ƒ | d <x* | j ƒ  D] \ } } t |  | | ƒ q' Wd S(   sÏ   Set up the storage system for file-based sessions.

        This should only be called once per process; this will be done
        automatically when using sessions.init (as the built-in Tool does).
        Rg   N(   Ri   Rj   Rk   R   R   (   RB   R   R    R!   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   setupÝ  s    c         C   sY   t  j j |  j |  j |  j ƒ } t  j j | ƒ j |  j ƒ sU t j	 d d ƒ ‚ n  | S(   Ni  s   Invalid session id in cookie.(
   Ri   Rj   t   joinRg   t   SESSION_PREFIXR   Rk   t
   startswithR   t	   HTTPError(   R
   t   f(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   _get_file_pathê  s    "c         C   s   |  j  ƒ  } t j j | ƒ S(   N(   Rw   Ri   Rj   t   exists(   R
   Rj   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   ð  s    c         C   s±   |  j  s t d ƒ ‚ | d  k r0 |  j ƒ  } n  y2 t | d ƒ } z t j | ƒ SWd  | j ƒ  XWnH t t	 f k
 r¬ t
 j ƒ  d } |  j r¨ t j d | d ƒ n  d  SXd  S(   NsJ   The session load without being locked.  Check your tools' priority levels.t   rbi   s$   Error loading the session pickle: %ss   TOOLS.SESSIONS(   R(   t   AssertionErrorR   Rw   t   openR   RC   t   closet   IOErrort   EOFErrort   syst   exc_infoR   R   R   (   R
   Rj   Rv   t   e(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR7   ô  s    		c         C   s_   |  j  s t d ƒ ‚ t |  j ƒ  d ƒ } z# t j |  j | f | |  j ƒ Wd  | j ƒ  Xd  S(   NsO   The session was saved without being locked.  Check your tools' priority levels.t   wb(	   R(   Rz   R{   Rw   R   t   dumpR   t   pickle_protocolR|   (   R
   R4   Rv   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR2     s
    #c         C   sD   |  j  s t d ƒ ‚ y t j |  j ƒ  ƒ Wn t k
 r? n Xd  S(   NsN   The session deletion without being locked.  Check your tools' priority levels.(   R(   Rz   Ri   t   unlinkRw   t   OSError(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRD     s
    c         C   s·   | d k r |  j ƒ  } n  | |  j 7} t j |  j |  j ƒ } xK | j ƒ  s y t j	 | ƒ |  _
 Wn! t j k
 rˆ t j d ƒ qC XPqC Wt |  _ |  j r³ t j d d ƒ n  d S(   s?   Acquire an exclusive lock on the currently-loaded session data.gš™™™™™¹?s   Lock acquired.s   TOOLS.SESSIONSN(   R   Rw   t   LOCK_SUFFIXR   t   LockCheckerR   Rh   t   expiredR   t   LockFileRa   t	   LockErrort   timet   sleepR   R(   R   R   R   (   R
   Rj   t   checker(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR+     s    		c         C   s'   |  j  j ƒ  |  j  j ƒ  t |  _ d S(   s6   Release the lock on the currently-loaded session data.N(   Ra   R_   t   removeR   R(   (   R
   Rj   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR)   (  s    c         C   sñ   |  j  ƒ  } xÞ t j |  j ƒ D]Ê } | j |  j ƒ r | j |  j ƒ r t j j	 |  j | ƒ } |  j
 | ƒ |  j r‹ t j d d ƒ n  zJ |  j | ƒ } | d k	 rÔ | \ } } | | k  rÔ t j | ƒ qÔ n  Wd |  j | ƒ Xq q Wd S(   s   Clean up expired sessions.s   Cleanup lock acquired.s   TOOLS.SESSIONSN(   R$   Ri   t   listdirRg   Rt   Rs   t   endswithR‡   Rj   Rr   R+   R   R   R   R7   R   R…   R)   (   R
   R$   t   fnameRj   t   contentsRA   R4   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR-   .  s    	c         C   sN   t  g  t j |  j ƒ D]1 } | j |  j ƒ r | j |  j ƒ r | ^ q ƒ S(   s%   Return the number of active sessions.(   Rd   Ri   R   Rg   Rt   Rs   R‘   R‡   (   R
   R’   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRe   K  s    N(   RT   RU   RV   Rs   R‡   R   t   HIGHEST_PROTOCOLR„   R   R"   Rq   t   classmethodRw   R   R7   R2   RD   R+   R)   R-   Re   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRf   ¼  s    								t   PostgresqlSessionc           B   s€   e  Z d  Z e j Z d d „ Z d „  Z e	 e ƒ Z d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z RS(   s*   Implementation of the PostgreSQL backend for sessions. It assumes
        a table like this::

            create table session (
                id varchar(40),
                data text,
                expiration_time timestamp
            )

    You must provide your own get_db function.
    c         K   s)   t  j |  | |  |  j j ƒ  |  _ d  S(   N(   R   R"   t   dbt   cursor(   R
   R   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR"   b  s    c         K   s@   x* | j  ƒ  D] \ } } t |  | | ƒ q Wt j ƒ  t _ d S(   sÓ   Set up the storage system for Postgres-based sessions.

        This should only be called once per process; this will be done
        automatically when using sessions.init (as the built-in Tool does).
        N(   R   R   R
   t   get_dbR—   (   RB   R   R    R!   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRq   f  s    c         C   s*   |  j  r |  j  j ƒ  n  |  j j ƒ  d  S(   N(   R˜   R|   R—   t   commit(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   __del__r  s    	c         C   s2   |  j  j d |  j f ƒ |  j  j ƒ  } t | ƒ S(   Ns5   select data, expiration_time from session where id=%s(   R˜   t   executeR   t   fetchallt   bool(   R
   t   rows(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   w  s    c         C   s[   |  j  j d |  j f ƒ |  j  j ƒ  } | s2 d  S| d \ } } t j | ƒ } | | f S(   Ns5   select data, expiration_time from session where id=%si    (   R˜   Rœ   R   R   R   R   t   loads(   R
   RŸ   t   pickled_dataR4   RA   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR7   ~  s    c         C   s;   t  j |  j |  j ƒ } |  j j d | | |  j f ƒ d  S(   Ns@   update session set data = %s, expiration_time = %s where id = %s(   R   t   dumpsR   R„   R˜   Rœ   R   (   R
   R4   R¡   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR2   Š  s    c         C   s   |  j  j d |  j f ƒ d  S(   Ns   delete from session where id=%s(   R˜   Rœ   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRD     s    c         C   sB   t  |  _ |  j j d |  j f ƒ |  j r> t j d d ƒ n  d S(   s?   Acquire an exclusive lock on the currently-loaded session data.s-   select id from session where id=%s for updates   Lock acquired.s   TOOLS.SESSIONSN(   R   R(   R˜   Rœ   R   R   R   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR+   “  s
    		c         C   s   |  j  j ƒ  t |  _ d S(   s6   Release the lock on the currently-loaded session data.N(   R˜   R|   R   R(   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR)   œ  s    c         C   s    |  j  j d |  j ƒ  f ƒ d S(   s   Clean up expired sessions.s.   delete from session where expiration_time < %sN(   R˜   Rœ   R$   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR-   £  s    N(   RT   RU   RV   R   R”   R„   R   R"   Rq   R•   R›   R   R7   R2   RD   R+   R)   R-   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR–   R  s   		
								t   MemcachedSessionc           B   sž   e  Z e j ƒ  Z i  Z d  g Z d „  Z e e ƒ Z d „  Z	 d „  Z
 e e	 e
 d d ƒZ d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   s   127.0.0.1:11211c         K   sR   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd d l } | j |  j ƒ |  _ d S(   sÔ   Set up the storage system for memcached-based sessions.

        This should only be called once per process; this will be done
        automatically when using sessions.init (as the built-in Tool does).
        iÿÿÿÿN(   R   R   t   memcachet   Clientt   serversR[   (   RB   R   R    R!   R¤   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRq   ´  s    c         C   s   |  j  S(   N(   R	   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   Á  s    c         C   sL   t  | t ƒ r! | j d ƒ } n  | |  _ x |  j D] } | | ƒ q4 Wd  S(   Ns   utf-8(   Rl   R   t   encodeR	   R   (   R
   R   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   Ä  s
    	R   s   The current session ID.c         C   s?   |  j  j ƒ  z t |  j j |  j ƒ ƒ SWd  |  j  j ƒ  Xd  S(   N(   t   mc_lockR^   Rž   R[   RM   R   R_   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR   Ï  s    c         C   s9   |  j  j ƒ  z |  j j |  j ƒ SWd  |  j  j ƒ  Xd  S(   N(   R¨   R^   R[   RM   R   R_   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR7   Ö  s    c         C   s{   t  t j | j ƒ  ƒ ƒ } |  j j ƒ  z> |  j j |  j |  j	 | f | ƒ se t
 d |  j ƒ ‚ n  Wd  |  j j ƒ  Xd  S(   Ns   Session data for id %r not set.(   Rm   RŒ   t   mktimet	   timetupleR¨   R^   R[   t   setR   R   Rz   R_   (   R
   R4   t   td(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR2   Ý  s    $c         C   s   |  j  j |  j ƒ d  S(   N(   R[   R'   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRD   è  s    c         C   sK   t  |  _ |  j j |  j t j ƒ  ƒ j ƒ  |  j rG t	 j
 d d ƒ n  d S(   s?   Acquire an exclusive lock on the currently-loaded session data.s   Lock acquired.s   TOOLS.SESSIONSN(   R   R(   R]   RP   R   Rb   Rc   R^   R   R   R   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR+   ë  s    	"	c         C   s!   |  j  |  j j ƒ  t |  _ d S(   s6   Release the lock on the currently-loaded session data.N(   R]   R   R_   R   R(   (   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR)   ò  s    c         C   s
   t  ‚ d S(   s%   Return the number of active sessions.N(   t   NotImplementedError(   R
   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRe   ÷  s    (   RT   RU   Rb   Rc   R¨   R]   R¦   Rq   R•   R   R   RW   R   R   R7   R2   RD   R+   R)   Re   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR£   ©  s   											c          C   sœ   t  t j d ƒ s d St j j }  t j j } t  |  d ƒ rA d St |  _ | j ro |  j j	 d t j
 j ƒ n) t | j ƒ r‹ | j ƒ  n  t j
 j ƒ  d S(   s   Save any changed session data.t   sessionNt   _sessionsavedt   on_end_request(   RX   R   t   servingt   requestt   responseR   R¯   t   streamt   hookst   attachR®   R5   R   t   bodyt   collapse_body(   R²   R³   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR5   þ  s    		c          C   sT   t  t j d d ƒ }  t  |  d t ƒ rP |  j ƒ  |  j rP t j d d ƒ qP n  d S(   s*   Close the session object for this request.R®   R(   s   Lock released on close.s   TOOLS.SESSIONSN(   t   getattrR   R±   R   R   R)   R   R   (   t   sess(    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyR|     s
    
	iZ   t   ramt
   session_idi<   i   c            s~  t  j j } t | d ƒ r d St | _ d } ˆ  | j k rm | j ˆ  j } |
 rm t  j	 d | d ƒ qm n  |  j
 ƒ  d } t ƒ  | } t t  d ƒ s» t | d ƒ r» | j |   q» n  | | d <| | d	 <| | |  t  j _ } |
 | _ ‡  f d
 †  } | j j | ƒ t t  d ƒ s4t  j d ƒ t  _ n  | rC| } n d } t d | d | d ˆ  d | d | d | d |	 ƒ d S(   s3  Initialize session object (using cookies).

    storage_type
        One of 'ram', 'file', 'postgresql', 'memcached'. This will be
        used to look up the corresponding class in cherrypy.lib.sessions
        globals. For example, 'file' will use the FileSession class.

    path
        The 'path' value to stick in the response cookie metadata.

    path_header
        If 'path' is None (the default), then the response
        cookie 'path' will be pulled from request.headers[path_header].

    name
        The name of the cookie.

    timeout
        The expiration timeout (in minutes) for the stored session data.
        If 'persistent' is True (the default), this is also the timeout
        for the cookie.

    domain
        The cookie domain.

    secure
        If False (the default) the cookie 'secure' value will not
        be set. If True, the cookie 'secure' value will be set (to 1).

    clean_freq (minutes)
        The poll rate for expired session cleanup.

    persistent
        If True (the default), the 'timeout' argument will be used
        to expire the cookie. If False, the cookie will not have an expiry,
        and the cookie will be a "session cookie" which expires when the
        browser is closed.

    httponly
        If False (the default) the cookie 'httponly' value will not be set.
        If True, the cookie 'httponly' value will be set (to 1).

    Any additional kwargs will be bound to the new Session instance,
    and may be specific to the storage type. See the subclass of Session
    you're using for more information.
    t   _session_init_flagNs#   ID obtained from request.cookie: %rs   TOOLS.SESSIONSR   R®   Rq   R1   R9   c            s   |  t  j j j ˆ  <d S(   s4   Update the cookie every time the session id changes.N(   R   R±   R³   t   cookie(   R   (   R6   (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   update_cookiet  s    Rj   t   path_headerR6   t   domaint   securet   httponly(   R   R±   R²   RX   R   R½   R   R¾   R   R   t   titlet   globalsRq   R®   R   R   t   appendt   _ThreadLocalProxyt   set_response_cookie(   t   storage_typeRj   RÀ   R6   R1   RÁ   RÂ   R9   t
   persistentRÃ   R   R   R²   R   t   storage_classRº   R¿   t   cookie_timeout(    (   R6   s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   init$  s:    2	

		c   	      C   só   t  j j j } t  j j j | | <|  pC t  j j j j | ƒ pC d | | d <| r‚ t	 j	 ƒ  | d } t
 j | ƒ | | d <n  | d
 k	 rŸ | | | d <n  | r¶ d | | d <n  | rï | | j d ƒ sÞ t d	 ƒ ‚ n  d | | d <n  d
 S(   sj  Set a response cookie for the client.

    path
        the 'path' value to stick in the response cookie metadata.

    path_header
        if 'path' is None (the default), then the response
        cookie 'path' will be pulled from request.headers[path_header].

    name
        the name of the cookie.

    timeout
        the expiration timeout for the cookie. If 0 or other boolean
        False, no 'expires' param will be set, and the cookie will be a
        "session cookie" which expires when the browser is closed.

    domain
        the cookie domain.

    secure
        if False (the default) the cookie 'secure' value will not
        be set. If True, the cookie 'secure' value will be set (to 1).

    httponly
        If False (the default) the cookie 'httponly' value will not be set.
        If True, the cookie 'httponly' value will be set (to 1).

    t   /Rj   i<   t   expiresRÁ   i   RÂ   RÃ   s+   The httponly cookie token is not supported.N(   R   R±   R³   R¾   R®   R   R²   t   headersRM   RŒ   R   t   HTTPDateR   t   isReservedKeyRp   (	   Rj   RÀ   R6   R1   RÁ   RÂ   RÃ   R¾   R   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyRÈ   ˆ  s      c          C   sU   t  j j j j d d ƒ }  d
 } t j ƒ  | } t j | ƒ t  j j j	 |  d <d S(   s"   Expire the current session cookie.s   tools.sessions.nameR¼   i<   i   im  RÏ   Ni  i€Q i€3á(
   R   R±   R²   t   configRM   RŒ   R   RÑ   R³   R¾   (   R6   t   one_yearR   (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   expireÂ  s
    (#   RV   R   R#   Ri   RŒ   Rb   t   typesR   t   cherrypy._cpcompatR    R   R   R   t   cherrypy.libR   R   R   R   t   objectR   R   RY   Rf   R–   R£   R5   R   t   failsafeR|   t   priorityR   R   RÍ   RÈ   RÕ   (    (    (    s|   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/sessions.pyt   <module>[   s<   "	ÿ 8–WU					b	9