ó
i4Vdc           @  s  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z d  d l m Z d  d l m Z m Z m Z d  d	 l m Z m Z d  d
 l m Z e j e j Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   datetimet	   timedelta(   t   settings(   t   SuspiciousSession(   t   SuspiciousOperation(   t   timezone(   t   constant_time_comparet   get_random_stringt   salted_hmac(   t   force_bytest
   force_text(   t   import_stringt   CreateErrorc           B  s   e  Z d  Z RS(   u‡   
    Used internally as a consistent exception type to catch from save (see the
    docstring for SessionBase.save() for details).
    (   t   __name__t
   __module__t   __doc__(    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR      s   t   SessionBasec           B  sÜ  e  Z d  Z d Z d Z e ƒ  Z d- d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d- d „ Z e 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% e# ƒ Z& e% e# e$ ƒ Z' e( d  „ Z) e% e) ƒ Z* d! „  Z+ d" „  Z, d# „  Z- d$ „  Z. d% „  Z/ d& „  Z0 d' „  Z1 d( „  Z2 e( d) „ Z3 d- d* „ Z4 d+ „  Z5 e6 d, „  ƒ Z7 RS(.   u-   
    Base class for all Session classes.
    u
   testcookieu   workedc         C  s1   | |  _  t |  _ t |  _ t t j ƒ |  _ d  S(   N(   t   _session_keyt   Falset   accessedt   modifiedR   R   t   SESSION_SERIALIZERt
   serializer(   t   selft   session_key(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   __init__(   s    			c         C  s   | |  j  k S(   N(   t   _session(   R   t   key(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   __contains__.   s    c         C  s   |  j  | S(   N(   R   (   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   __getitem__1   s    c         C  s   | |  j  | <t |  _ d  S(   N(   R   t   TrueR   (   R   R   t   value(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   __setitem__4   s    c         C  s   |  j  | =t |  _ d  S(   N(   R   R   R   (   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   __delitem__8   s    
c         C  s   |  j  j | | ƒ S(   N(   R   t   get(   R   R   t   default(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR#   <   s    c         C  sL   |  j  p | |  j k |  _  | |  j k r0 d n | f } |  j j | | Œ S(   N(    (   R   R   t   _SessionBase__not_givent   pop(   R   R   R$   t   args(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR&   ?   s    c         C  s8   | |  j  k r |  j  | St |  _ | |  j  | <| Sd  S(   N(   R   R   R   (   R   R   R    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt
   setdefaultD   s
    	c         C  s   |  j  |  |  j <d  S(   N(   t   TEST_COOKIE_VALUEt   TEST_COOKIE_NAME(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   set_test_cookieL   s    c         C  s   |  j  |  j ƒ |  j k S(   N(   R#   R*   R)   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   test_cookie_workedO   s    c         C  s   |  |  j  =d  S(   N(   R*   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   delete_test_cookieR   s    c         C  s#   d |  j  j } t | | ƒ j ƒ  S(   Nu   django.contrib.sessions(   t	   __class__R   R	   t	   hexdigest(   R   R    t   key_salt(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _hashU   s    c         C  sH   |  j  ƒ  j | ƒ } |  j | ƒ } t j | j ƒ  d | ƒ j d ƒ S(   uH   Returns the given session dictionary serialized and encoded as a string.t   :u   ascii(   R   t   dumpsR1   t   base64t	   b64encodet   encodet   decode(   R   t   session_dictt
   serializedt   hash(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR6   Y   s    c         C  sÐ   t  j t | ƒ ƒ } yb | j d d ƒ \ } } |  j | ƒ } t | j ƒ  | ƒ sc t d ƒ ‚ n |  j ƒ  j	 | ƒ SWnR t
 k
 rË } t | t ƒ rÇ t j d | j j ƒ } | j t | ƒ ƒ n  i  SXd  S(   NR2   i   u   Session data corruptedu   django.security.%s(   R4   t	   b64decodeR
   t   splitR1   R   R7   R   R   t   loadst	   Exceptiont
   isinstanceR   t   loggingt	   getLoggerR.   R   t   warningR   (   R   t   session_datat   encoded_dataR:   R9   t   expected_hasht   et   logger(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR7   _   s    	c         C  s   |  j  j | ƒ t |  _ d  S(   N(   R   t   updateR   R   (   R   t   dict_(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRH   r   s    c         C  s   | |  j  k S(   N(   R   (   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   has_keyv   s    c         C  s   |  j  j ƒ  S(   N(   R   t   keys(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRK   y   s    c         C  s   |  j  j ƒ  S(   N(   R   t   values(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRL   |   s    c         C  s   |  j  j ƒ  S(   N(   R   t   items(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRM      s    c         C  s   |  j  j ƒ  S(   N(   R   t   iterkeys(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRN   ‚   s    c         C  s   |  j  j ƒ  S(   N(   R   t
   itervalues(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRO   …   s    c         C  s   |  j  j ƒ  S(   N(   R   t	   iteritems(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRP   ˆ   s    c         C  s   i  |  _  t |  _ t |  _ d  S(   N(   t   _session_cacheR   R   R   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   clear‹   s    		c         C  s5   y t  |  j ƒ o |  j SWn t k
 r0 t SXd S(   uB   Returns True when there is no session_key and the session is emptyN(   t   boolR   RQ   t   AttributeErrorR   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   is_empty“   s    c         C  s3   x, t  r. t d t ƒ } |  j | ƒ s Pq q W| S(   u*   Returns session key that isn't being used.i    (   R   R   t   VALID_KEY_CHARSt   exists(   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _get_new_session_keyš   s
    	c         C  s(   |  j  d  k r! |  j ƒ  |  _  n  |  j  S(   N(   R   t   NoneRX   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _get_or_create_session_key¢   s    c         C  s   | o t  | ƒ d k S(   u”   
        Key must be truthy and at least 8 characters long. 8 characters is an
        arbitrary lower bound for some minimal key security.
        i   (   t   len(   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _validate_session_key§   s    c         C  s   |  j  S(   N(   t   _SessionBase__session_key(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _get_session_key®   s    c         C  s(   |  j  | ƒ r | |  _ n	 d |  _ d S(   uV   
        Validate session key on assignment. Invalid values will set to None.
        N(   R\   R]   RY   (   R   R    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _set_session_key±   s    c         C  s_   t  |  _ y |  j SWnA t k
 rW |  j d k s9 | rE i  |  _ qX |  j ƒ  |  _ n X|  j S(   u    
        Lazily loads session from storage (unless "no_load" is True, when only
        an empty dict is stored) and stores it in the current instance.
        N(   R   R   RQ   RT   R   RY   t   load(   R   t   no_load(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   _get_session½   s    	c         K  s›   y | d } Wn t  k
 r- t j ƒ  } n Xy | d } Wn  t  k
 r^ |  j d ƒ } n X| sl t j St | t ƒ s | S| | } | j d | j	 S(   uÕ   Get the number of seconds until the session expires.

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        u   modificationu   expiryu   _session_expiryi€Q (
   t   KeyErrorR   t   nowR#   R   t   SESSION_COOKIE_AGER?   R   t   dayst   seconds(   R   t   kwargst   modificationt   expiryt   delta(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   get_expiry_ageÎ   s    
c         K  s•   y | d } Wn t  k
 r- t j ƒ  } n Xy | d } Wn  t  k
 r^ |  j d ƒ } n Xt | t ƒ rr | S| s„ t j } n  | t d | ƒ S(   uÔ   Get session the expiry date (as a datetime object).

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        u   modificationu   expiryu   _session_expiryRg   (	   Rc   R   Rd   R#   R?   R   R   Re   R   (   R   Rh   Ri   Rj   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   get_expiry_dateç   s    c         C  s_   | d k r/ y |  d =Wn t k
 r* n Xd St | t ƒ rQ t j ƒ  | } n  | |  d <d S(   u+  
        Sets a custom expiration for the session. ``value`` can be an integer,
        a Python ``datetime`` or ``timedelta`` object or ``None``.

        If ``value`` is an integer, the session will expire after that many
        seconds of inactivity. If set to ``0`` then the session will expire on
        browser close.

        If ``value`` is a ``datetime`` or ``timedelta`` object, the session
        will expire at that specific future time.

        If ``value`` is ``None``, the session uses the global session expiry
        policy.
        u   _session_expiryN(   RY   Rc   R?   R   R   Rd   (   R   R    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt
   set_expiryý   s    c         C  s/   |  j  d ƒ d k r t j S|  j  d ƒ d k S(   u  
        Returns ``True`` if the session is set to expire when the browser
        closes, and ``False`` if there's an expiry date. Use
        ``get_expiry_date()`` or ``get_expiry_age()`` to find the actual expiry
        date/age, if there is one.
        u   _session_expiryi    N(   R#   RY   R   t   SESSION_EXPIRE_AT_BROWSER_CLOSE(   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   get_expire_at_browser_close  s    c         C  s!   |  j  ƒ  |  j ƒ  d |  _ d S(   ue   
        Removes the current session data from the database and regenerates the
        key.
        N(   RR   t   deleteRY   R   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   flush"  s    

c         C  s6   |  j  } |  j } |  j ƒ  | |  _  |  j | ƒ d S(   uV   
        Creates a new session key, while retaining the current session data.
        N(   RQ   R   t   createRq   (   R   t   dataR   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt	   cycle_key+  s
    		
	c         C  s   t  d ƒ ‚ d S(   uG   
        Returns True if the given session_key already exists.
        u9   subclasses of SessionBase must provide an exists() methodN(   t   NotImplementedError(   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRW   7  s    c         C  s   t  d ƒ ‚ d S(   uÆ   
        Creates a new session instance. Guaranteed to create a new object with
        a unique key and will have saved the result once (with empty data)
        before the method returns.
        u8   subclasses of SessionBase must provide a create() methodN(   Rv   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRs   =  s    c         C  s   t  d ƒ ‚ d S(   uå   
        Saves the session data. If 'must_create' is True, a new session object
        is created (otherwise a CreateError exception is raised). Otherwise,
        save() can update an existing object with the same key.
        u6   subclasses of SessionBase must provide a save() methodN(   Rv   (   R   t   must_create(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   saveE  s    c         C  s   t  d ƒ ‚ d S(   u}   
        Deletes the session data under this key. If the key is None, the
        current session key value is used.
        u8   subclasses of SessionBase must provide a delete() methodN(   Rv   (   R   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyRq   M  s    c         C  s   t  d ƒ ‚ d S(   uB   
        Loads the session data and returns a dictionary.
        u6   subclasses of SessionBase must provide a load() methodN(   Rv   (   R   (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR`   T  s    c         C  s   t  d ƒ ‚ d S(   u  
        Remove expired sessions from the session store.

        If this operation isn't possible on a given backend, it should raise
        NotImplementedError. If it isn't necessary, because the backend has
        a built-in expiration mechanism, it should be a no-op.
        u.   This backend does not support clear_expired().N(   Rv   (   t   cls(    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   clear_expiredZ  s    	N(8   R   R   R   R*   R)   t   objectR%   RY   R   R   R   R!   R"   R#   R&   R(   R+   R,   R-   R1   R6   R7   RH   RJ   RK   RL   RM   RN   RO   RP   RR   RU   RX   RZ   R\   R^   R_   t   propertyR   R   R   Rb   R   Rl   Rm   Rn   Rp   Rr   Ru   RW   Rs   Rx   Rq   R`   t   classmethodRz   (    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyR      sb   																																						(   t
   __future__R    R4   R@   t   stringR   R   t   django.confR   t"   django.contrib.sessions.exceptionsR   t   django.core.exceptionsR   t   django.utilsR   t   django.utils.cryptoR   R   R	   t   django.utils.encodingR
   R   t   django.utils.module_loadingR   t   ascii_lowercaset   digitsRV   R>   R   R{   R   (    (    (    ss   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.pyt   <module>   s   