B
    `O                 @   sT  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 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mZmZmZ d dlmZ ddddd	d
dgZe ZdZG dd deZG dd deZdd Zdd Zdd fddZdd Z dd Z!dd Z"G dd deZ#d Z$d!Z%d"e&e% Z'd#Z(d$e' Z)d%Z*d&e' Z+d'e$e(e+f Z,e)e* e, Z-e.ee-d(Z/e.ed)d(Z0ere1nd*d Z2ed+d, e3d-D Z4e45d.d, e6e47 D  erd/ne8d/Z9erd0ne8d0Z:d1d2 Z;d3d4 Z<d5Z=e	j>e	j? e= Z@ee@ZAe	j>e	j? d6 ZBeeBZCe@d7 ZDed8d, e3d-D ZEeE5eFeDeD esned9d, eEG D ZEeEjHZId:ZJd;ZKdZLd<d= ZMd>d? ZNd@dA ZOdBdC ZPePZQePZRdDePdEdFeNdEdGeQdEdHeRdEdIZSeTeSZUeVeSZWeW5dJdKdLdMg dVdPdZXG dQd	 d	eZYG dRd
 d
eZZG dSd deZ[e Z\G dTd deZ]G dUd de]Z^dS )W    N)datedatetime	timedelta)MutableMappingPY2	text_typebytes_text_native_string_types)strings_differCookieCookieProfileSignedCookieProfileSignedSerializerJSONSerializerBase64Serializermake_cookieTc               @   s   e Zd ZdZdd Zedd Zdd Zdd	 Zd
d Z	dd Z
d)ddZdd Zdd Zdd Zdd Zerdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZdS )*RequestCookieszwebob._parsed_cookiesc             C   s
   || _ d S )N)_environ)selfenviron r   U/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/webob/cookies.py__init__*   s    zRequestCookies.__init__c                sh   | j }|dd}|| ji d f\}}||kr4|S dd  t fddt|D }||f|| j< |S )NHTTP_COOKIE c             S   s
   |  dS )Nutf8)decode)br   r   r   <lambda>4       z'RequestCookies._cache.<locals>.<lambda>c             3   s"   | ]\}} | |fV  qd S )Nr   ).0kv)dr   r   	<genexpr>5   s    z(RequestCookies._cache.<locals>.<genexpr>)r   get
_cache_keydictparse_cookie)r   envheadercacheZcache_headerr   )r%   r   _cache-   s    zRequestCookies._cachec             C   s*  | j d}|d k	}|pd}ts*|d}t|d}|d krBd }ntt|d}|d | }t|}d}	x|D ]l}
|
 \}}|
	d}||krpd	}	|d kr|d | 
d
||d   }n|d | | ||d   }P qpW |d k	r|r|d| 7 }n|}|rt|d| j d< n|r&d| j d< |	S )Nr   r   zlatin-1asciizutf-8   =F   Ts    ;s   ; )r   r'   r   encoder   _value_quote
_rx_cookiefinditerspangrouprstripr
   )r   namevaluer,   Z
had_headerZ
bytes_namereplacementZ	bytes_valmatchesfoundmatchstartendZ
match_namer   r   r   _mutate_header9   s<    




 
zRequestCookies._mutate_headerc             C   sh   t |tst|dt |ts(t|d}yt|d}W n tk
rR   tdY nX t|sdtd|S )Nzcookie name must be a stringzutf-8r/   z&cookie name must be encodable to asciiz/cookie name must be valid according to RFC 6265)
isinstancer   	TypeErrorr   r	   r   UnicodeEncodeError_valid_cookie_name)r   r9   Zbytes_cookie_namer   r   r   rE   _   s    



z!RequestCookies._valid_cookie_namec             C   sf   |  |}t|tst|dt|tsVyt|d}W n tk
rT   t|dY nX | || d S )Nzcookie value must be a stringzutf-8z,cookie value must be utf-8 binary or unicode)rE   rB   r   
ValueErrorr   r	   UnicodeDecodeErrorrA   )r   r9   r:   r   r   r   __setitem__l   s    



zRequestCookies.__setitem__c             C   s
   | j | S )N)r.   )r   r9   r   r   r   __getitem__x   s    zRequestCookies.__getitem__Nc             C   s   | j ||S )N)r.   r'   )r   r9   defaultr   r   r   r'   {   s    zRequestCookies.getc             C   s&   |  |}| |d }|s"t|d S )N)rE   rA   KeyError)r   r9   r=   r   r   r   __delitem__~   s    
zRequestCookies.__delitem__c             C   s
   | j  S )N)r.   keys)r   r   r   r   rM      s    zRequestCookies.keysc             C   s
   | j  S )N)r.   values)r   r   r   r   rN      s    zRequestCookies.valuesc             C   s
   | j  S )N)r.   items)r   r   r   r   rO      s    zRequestCookies.itemsc             C   s
   | j  S )N)r.   iterkeys)r   r   r   r   rP      s    zRequestCookies.iterkeysc             C   s
   | j  S )N)r.   
itervalues)r   r   r   r   rQ      s    zRequestCookies.itervaluesc             C   s
   | j  S )N)r.   	iteritems)r   r   r   r   rR      s    zRequestCookies.iteritemsc             C   s
   || j kS )N)r.   )r   r9   r   r   r   __contains__   s    zRequestCookies.__contains__c             C   s
   | j  S )N)r.   __iter__)r   r   r   r   rT      s    zRequestCookies.__iter__c             C   s
   t | jS )N)lenr.   )r   r   r   r   __len__   s    zRequestCookies.__len__c             C   s   d| j d< d S )Nr   r   )r   )r   r   r   r   clear   s    zRequestCookies.clearc             C   s   d| j f S )Nz+<RequestCookies (dict-like) with values %r>)r.   )r   r   r   r   __repr__   s    zRequestCookies.__repr__)N)__name__
__module____qualname__r(   r   propertyr.   rA   rE   rH   rI   r'   rL   rM   rN   rO   r   rP   rQ   rR   rS   rT   rV   rW   rX   r   r   r   r   r   &   s*   &
r   c               @   sH   e Zd ZdddZdd Zdd ZeZdd	d
Zdd ZeZ	dd Z
dS )r   Nc             C   s   |r|  | d S )N)load)r   inputr   r   r   r      s    zCookie.__init__c             C   s@   i }x6t |D ]*\}}| tkr,|||< q| ||}qW d S )N)_parse_cookielower_c_keysadd)r   datamorselkeyvalr   r   r   r]      s
    
zCookie.loadc             C   s>   t |ts|dd}t|s"i S t||}t| || |S )Nr/   replace)rB   bytesr2   rE   Morselr)   rH   )r   re   rf   rr   r   r   rb      s    

z
Cookie.addTc                s   d  fdd|  D S )Nz; c             3   s   | ]}|  V  qd S )N)	serialize)r"   m)fullr   r   r&      s    z#Cookie.serialize.<locals>.<genexpr>)joinrN   )r   rm   r   )rm   r   rk      s    zCookie.serializec             C   s   dd t |  D S )Nc             S   s   g | ]\}}|qS r   r   )r"   _rl   r   r   r   
<listcomp>   s    z!Cookie.values.<locals>.<listcomp>)sortedrO   )r   r   r   r   rN      s    zCookie.valuesc             C   s    d| j jdtt|  f S )Nz
<%s: [%s]>z, )	__class__rY   rn   mapreprrN   )r   r   r   r   rX      s    zCookie.__repr__)N)T)rY   rZ   r[   r   r]   rb   rH   rk   rN   __str__rX   r   r   r   r   r      s   

c             c   s8   t s| d} x$t| D ]\}}|t|fV  qW d S )Nzlatin-1)r   r2   r4   findall_unquote)rc   re   rf   r   r   r   r_      s    
r_   c             C   s   dd t | D S )zA
    Parse cookies ignoring anything except names and values
    c             s   s"   | ]\}}t |r||fV  qd S )N)rE   )r"   r#   r$   r   r   r   r&      s    zparse_cookie.<locals>.<genexpr>)r_   )rc   r   r   r   r*      s    r*   c             C   s   | S )Nr   )r$   r   r   r   r       r!   r    c                s     fdd}t  fdd|S )Nc                s   ||  < d S )Nr   )r   r$   )re   rk   r   r   fset   s    zcookie_property.<locals>.fsetc                s   |   S )Nr   )r   )re   r   r   r       r!   z!cookie_property.<locals>.<lambda>)r\   )re   rk   rx   r   )re   rk   r   cookie_property   s    ry   c             C   sB   t | tr(t| j| jd d d  } nt | tr:t| } t| S )N   <   )rB   r   strsecondsdaysintr   )r$   r   r   r   serialize_max_age   s
    

r   c             C   s   | d krd S t | tr| S t | tr.| dS t | trBt| d} t | trXt |  } t | ttfrn| 	 } t
d| }t|t| d  t| d  f dS )Nr/   )r}   z%%s, %d-%%s-%Y %H:%M:%S GMT   r1   )rB   rh   r   r2   r   r   r   utcnowr   	timetupletimestrftimer   weekdaysmonths)r$   rj   r   r   r   serialize_cookie_date   s    





r   c             C   s$   t | } tr |  dkr td| S )N)s   stricts   laxs   nonez+SameSite must be 'strict', 'lax', or 'none')r   SAMESITE_VALIDATIONr`   rF   )r$   r   r   r   serialize_samesite   s
    r   c               @   s   e Zd ZdZdd ZedZedZedZede	Z
edeZed	eZed
eZedeZdd ZdddZeZdd ZdS )ri   )r9   r:   c             C   s@   t |dd| _t |dd| _t| js*t| ttd  d S )Nr/   )encoding)	r   r9   r:   rE   AssertionErrorupdater)   fromkeysra   )r   r9   r:   r   r   r   r     s    zMorsel.__init__s   paths   domains   comments   expiress   max-ages   httponlys   secures   samesitec             C   s(   t | d}|tkr$t| || d S )Nr/   )r   r`   ra   r)   rH   )r   r#   r$   r   r   r   rH     s    zMorsel.__setitem__Tc       
      C   s   g }|j }|| jd t| j  |rxDtD ]<}| | }|r,t| }|d }|d }||d ||  q,W | d }	|	r|d|	  | jr|d | jr|d | jr| js| j	 dkrt
d	|d
| j  td|dS )Nr0   r9   quoters   expiress   expires=s   secures   HttpOnlys   nonez]Incompatible cookie attributes: when the samesite equals 'none', then the secure must be Trues	   SameSite=s   ; r/   )appendr9   r3   r:   
_c_valkeys
_c_renamessecurehttponlysamesiter`   rF   r
   rn   )
r   rm   resultrb   r#   r$   infor9   r   expiresr   r   r   rk     s0    
zMorsel.serializec             C   s   d| j jt| jt| jf S )Nz<%s: %s=%r>)rr   rY   r
   r9   r:   )r   r   r   r   rX   4  s    zMorsel.__repr__N)T)rY   rZ   r[   	__slots__r   ry   pathdomaincommentr   r   r   max_ageboolr   r   r   r   rH   rk   ru   rX   r   r   r   r   ri      s   





ri   z"(?:\\"|.)*?"z~!@#$%^&*()_+=-`.?|:/(){}<>'z[\w\d%s]z$\w{3},\s[\w\d-]{9,11}\s[\d:]{8}\sGMTz(%s+?)z\s*=\s*z(?:%s|\\(?:[0-3][0-7][0-7]|.))*z
(%s|%s|%s)r/   z\\([0-3][0-7][0-7]|.)c             C   s
   t | gS )N)rh   )ir   r   r   r    M  r!   c             c   s"   | ]}t d | t|fV  qdS )z%03oN)r   _bchr)r"   r   r   r   r   r&   N  s   r&      c             c   s   | ]}||fV  qd S )Nr   )r"   r$   r   r   r   r&   Q  s    $"c             C   s<   | r0| d | d   kr t kr0n n| dd } tt| S )Nr   r1   )_b_quote_mark_rx_unquotesub_ch_unquote)r$   r   r   r   rw   V  s    $rw   c             C   s   t | d S )Nr1   )_ch_unquote_mapr7   )rl   r   r   r   r   \  s    r   z!#$%&'()*+-./:<=>?@[]^_`{|}~z!#$%&'*+-.^_`|~ c             c   s   | ]}t |d | fV  qdS )z\%03oN)chr)r"   r   r   r   r   r&     s    c             c   s$   | ]\}}t |t|d fV  qdS )r/   N)ordr   )r"   r#   r$   r   r   r   r&     s    )MonTueWedThuFriSatSun)NJanFebMarAprMayJunJulAugSepOctNovDecc             C   s"   t r||ntj| |dd d S )N   )
stacklevel)_should_raisewarningswarn)textZ
warn_classZto_raiseZraise_reasonr   r   r   __warn_or_raise  s    
r   c             C   s@   |  d t}|r<td|f ttd ddtt|  d S | S )NzqCookie value contains invalid bytes: (%r). Future versions will raise ValueError upon encountering invalid bytes.z"Invalid characters in cookie value   "r!   )	translate_allowed_cookie_bytesr   RuntimeWarningrF   rn   rs   _escape_char)r$   Z	leftoversr   r   r   r3     s    
r3   c             C   s0   t | to.| d tp,| d tkp,|  tk S )Nr   )rB   rh   r   _valid_token_bytes_b_dollar_signr`   ra   )re   r   r   r   rE     s    
rE   c             C   s   d tt| S )Nr!   )rn   rs   r   )r$   r   r   r   _path_quote  s    r   s   Path)r9   r   s   Comments   Domains   Max-Age)s   paths   comments   domains   max-ages   expiress   secures   httponlys   samesite/Fc	             C   s   |dkrd}d}d}	ndt |tr>|jd d d |j }|}	n<|dk	rvyt|}W n tk
rn   tdY nX |}	nd}	t| |}
|dk	rt||
_|dk	rt||
_	|rd|
_
|rd|
_|dk	r||
_|	dk	r|	|
_|dk	rt||
_|dk	r||
_|
 S )	a  
    Generate a cookie value.

    ``name``
      The name of the cookie.

    ``value``
      The ``value`` of the cookie. If it is ``None``, it will generate a cookie
      value with an expiration date in the past.

    ``max_age``
      The maximum age of the cookie used for sessioning (in seconds).
      Default: ``None`` (browser scope).

    ``path``
      The path used for the session cookie. Default: ``/``.

    ``domain``
      The domain used for the session cookie. Default: ``None`` (no domain).

    ``secure``
      The 'secure' flag of the session cookie. Default: ``False``.

    ``httponly``
      Hide the cookie from JavaScript by setting the 'HttpOnly' flag of the
      session cookie. Default: ``False``.

    ``comment``
      Set a comment on the cookie. Default: ``None``

    ``samesite``
      The 'SameSite' attribute of the cookie, can be either ``"strict"``,
      ``"lax"``, ``"none"``, or ``None``. By default, WebOb will validate the
      value to ensure it conforms to the allowable options in the various draft
      RFC's that exist.

      To disable this check and send headers that are experimental or introduced
      in a future RFC, set the module flag ``SAMESITE_VALIDATION`` to a
      false value like:

      .. code::

          import webob.cookies
          webob.cookies.SAMESITE_VALIDATION = False

          ck = webob.cookies.make_cookie(cookie_name, value, samesite='future')

      .. danger::

          This feature has known compatibility issues with various user agents,
          and is not yet an accepted RFC. It is therefore considered
          experimental and subject to change.

          For more information please see :ref:`Experimental: SameSite Cookies
          <samesiteexp>`
    Nr!   r   zWed, 31-Dec-97 23:59:59 GMTr{   rz   zAmax_age should be an integer. Amount of seconds until expiration.T)rB   r   r~   r}   r   rF   ri   r   r   r   r   r   r   r   r   r   rk   )r9   r:   r   r   r   r   r   r   r   r   rd   r   r   r   r     s@    <




c               @   s    e Zd ZdZdd Zdd ZdS )r   z9 A serializer which uses `json.dumps`` and ``json.loads``c             C   s   t t|ddS )Nzutf-8)r   )r   jsondumps)r   	appstructr   r   r   r   /  s    zJSONSerializer.dumpsc             C   s   t t|ddS )Nzutf-8)r   )r   loadsr	   )r   bstructr   r   r   r   2  s    zJSONSerializer.loadsN)rY   rZ   r[   __doc__r   r   r   r   r   r   r   -  s   c               @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   z5 A serializer which uses base64 to encode/decode dataNc             C   s   |d krt  }|| _d S )N)r   
serializer)r   r   r   r   r   r   :  s    zBase64Serializer.__init__c             C   s   | j |}t|S )ze
        Given an ``appstruct``, serialize and sign the data.

        Returns a bytestring.
        )r   r   base64urlsafe_b64encode)r   r   cstructr   r   r   r   @  s    zBase64Serializer.dumpsc          
   C   sT   yt t|}W n4 tjtfk
rF } ztd| W dd}~X Y nX | j|S )z
        Given a ``bstruct`` (a bytestring), verify the signature and then
        deserialize and return the deserialized value.

        A ``ValueError`` will be raised if the signature fails to validate.
        zBadly formed base64 data: %sN)	r   urlsafe_b64decoder   binasciiErrorrC   rF   r   r   )r   r   r   er   r   r   r   I  s
    zBase64Serializer.loads)N)rY   rZ   r[   r   r   r   r   r   r   r   r   r   7  s   
	c               @   s*   e Zd ZdZd
ddZdd Zdd	 ZdS )r   a+  
    A helper to cryptographically sign arbitrary content using HMAC.

    The serializer accepts arbitrary functions for performing the actual
    serialization and deserialization.

    ``secret``
      A string which is used to sign the cookie. The secret should be at
      least as long as the block size of the selected hash algorithm. For
      ``sha512`` this would mean a 512 bit (64 character) secret.

    ``salt``
      A namespace to avoid collisions between different uses of a shared
      secret.

    ``hashalg``
      The HMAC digest algorithm to use for signing. The algorithm must be
      supported by the :mod:`hashlib` library. Default: ``'sha512'``.

    ``serializer``
      An object with two methods: `loads`` and ``dumps``.  The ``loads`` method
      should accept bytes and return a Python object.  The ``dumps`` method
      should accept a Python object and return bytes.  A ``ValueError`` should
      be raised for malformed inputs.  Default: ``None`, which will use a
      derivation of :func:`json.dumps` and ``json.loads``.

    sha512Nc                s   | _ | _| _yt|pdt|  _W n. tk
rZ   t|pDddt|d  _Y nX d fdd	 _  j _|d krt }| _	d S )Nr   zutf-8r!   c                s   t  j| S )N)hashlibnewhashalg)string)r   r   r   r      r!   z+SignedSerializer.__init__.<locals>.<lambda>)r!   )
saltsecretr   r   salted_secretrD   	digestmoddigest_sizer   r   )r   r   r   r   r   r   )r   r   r   t  s     zSignedSerializer.__init__c             C   s6   | j |}t| j|| j }t|| 	dS )ze
        Given an ``appstruct``, serialize and sign the data.

        Returns a bytestring.
        r0   )
r   r   hmacr   r   r   digestr   r   r8   )r   r   r   sigr   r   r   r     s    zSignedSerializer.dumpsc          
   C   s   y(dt | d  }tt|| }W n4 tjtfk
r\ } ztd| W dd}~X Y nX || jd }|d| j }t	
| jt|| j }t||rtd| j|S )z
        Given a ``bstruct`` (a bytestring), verify the signature and then
        deserialize and return the deserialized value.

        A ``ValueError`` will be raised if the signature fails to validate.
        r0      zBadly formed base64 data: %sNzInvalid signature)rU   r   r   r   r   r   rC   rF   r   r   r   r   r   r   r   r   r   )r   r   Z
b64paddingZfstructr   r   Zexpected_sigr   r   r   r   r     s    
zSignedSerializer.loads)r   N)rY   rZ   r[   r   r   r   r   r   r   r   r   r   W  s
    

c               @   sf   e Zd ZdZdddZdd Zd	d
 Zdd ZeeeeeefddZ	eeeeeefddZ
dd ZdS )r   aA  
    A helper class that helps bring some sanity to the insanity that is cookie
    handling.

    The helper is capable of generating multiple cookies if necessary to
    support subdomains and parent domains.

    ``cookie_name``
      The name of the cookie used for sessioning. Default: ``'session'``.

    ``max_age``
      The maximum age of the cookie used for sessioning (in seconds).
      Default: ``None`` (browser scope).

    ``secure``
      The 'secure' flag of the session cookie. Default: ``False``.

    ``httponly``
      Hide the cookie from Javascript by setting the 'HttpOnly' flag of the
      session cookie. Default: ``False``.

    ``samesite``
      The 'SameSite' attribute of the cookie, can be either ``b"strict"``,
      ``b"lax"``, ``b"none"``, or ``None``.

      For more information please see the ``samesite`` documentation in
      :meth:`webob.cookies.make_cookie`

    ``path``
      The path used for the session cookie. Default: ``'/'``.

    ``domains``
      The domain(s) used for the session cookie. Default: ``None`` (no domain).
      Can be passed an iterable containing multiple domains, this will set
      multiple cookies one for each domain.

    ``serializer``
      An object with two methods: ``loads`` and ``dumps``.  The ``loads`` method
      should accept a bytestring and return a Python object.  The ``dumps``
      method should accept a Python object and return bytes.  A ``ValueError``
      should be raised for malformed inputs.  Default: ``None``, which will use
      a derivation of :func:`json.dumps` and :func:`json.loads`.

    FNr   c	       	      C   sH   || _ || _|| _|| _|| _|| _|| _|d kr8t }|| _d | _	d S )N)
cookie_namer   r   r   r   r   domainsr   r   request)	r   r   r   r   r   r   r   r   r   r   r   r   r     s    
zCookieProfile.__init__c             C   s
   |  |S )z8 Bind a request to a copy of this instance and return it)bind)r   r   r   r   r   __call__  s    zCookieProfile.__call__c          	   C   s0   t | j| j| j| j| j| j| j| j}||_	|S )z8 Bind a request to a copy of this instance and return it)
r   r   r   r   r   r   r   r   r   r   )r   r   selfishr   r   r   r     s    zCookieProfile.bindc             C   sP   | j std| j j| j}|dk	rLy| jt|S  tk
rJ   dS X dS )a   Looks for a cookie by name in the currently bound request, and
        returns its value.  If the cookie profile is not bound to a request,
        this method will raise a :exc:`ValueError`.

        Looks for the cookie in the cookies jar, and if it can find it it will
        attempt to deserialize it.  Returns ``None`` if there is no cookie or
        if the value in the cookie cannot be successfully deserialized.
        z"No request bound to cookie profileN)r   rF   cookiesr'   r   r   r   r   )r   cookier   r   r   	get_value  s    
zCookieProfile.get_valuec	       
   	   C   s(   | j |||||||d}	|j|	 |S )z Set the cookies on a response.)r   r   r   r   r   r   )get_headersZ
headerlistextend)
r   responser:   r   r   r   r   r   r   r   r   r   r   set_cookies"  s    zCookieProfile.set_cookiesc       	   	   C   s6   |dkrd}d}n| j |}| j|||||||dS )z Retrieve raw headers for setting cookies.

        Returns a list of headers that should be set for the cookies to
        be correctly tracked.
        Nr   )r   r   r   r   r   r   )r   r   _get_cookies)	r   r:   r   r   r   r   r   r   r   r   r   r   r   2  s    zCookieProfile.get_headersc             C   s   |t kr| j}|t kr| j}|t kr*| j}|t kr8| j}|t krF| j}|t krT| j}|dk	rxt|dkrxtdt| g }|st	| j
||||||d}	|d|	f n6x4|D ],}
t	| j
|||
||||d}	|d|	f qW |S )a  Internal function

        This returns a list of cookies that are valid HTTP Headers.

        :environ: The request environment
        :value: The value to store in the cookie
        :domains: The domains, overrides any set in the CookieProfile
        :max_age: The max_age, overrides any set in the CookieProfile
        :path: The path, overrides any set in the CookieProfile
        :secure: Set this cookie to secure, overrides any set in CookieProfile
        :httponly: Set this cookie to HttpOnly, overrides any set in CookieProfile
        :samesite: Set this cookie to be for only the same site, overrides any
                   set in CookieProfile.

        Ni  z,Cookie value is too long to store (%s bytes))r   r   r   r   r   z
Set-Cookie)r   r   r   r   r   r   )_defaultr   r   r   r   r   r   rU   rF   r   r   r   )r   r:   r   r   r   r   r   r   r   Zcookievaluer   r   r   r   r   J  sN    
zCookieProfile._get_cookies)FNNNr   NN)rY   rZ   r[   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s$   ,      
c               @   s"   e Zd ZdZd
ddZdd	 ZdS )r   aK  
    A helper for generating cookies that are signed to prevent tampering.

    By default this will create a single cookie, given a value it will
    serialize it, then use HMAC to cryptographically sign the data. Finally
    the result is base64-encoded for transport. This way a remote user can
    not tamper with the value without uncovering the secret/salt used.

    ``secret``
      A string which is used to sign the cookie. The secret should be at
      least as long as the block size of the selected hash algorithm. For
      ``sha512`` this would mean a 512 bit (64 character) secret.

    ``salt``
      A namespace to avoid collisions between different uses of a shared
      secret.

    ``hashalg``
      The HMAC digest algorithm to use for signing. The algorithm must be
      supported by the :mod:`hashlib` library. Default: ``'sha512'``.

    ``cookie_name``
      The name of the cookie used for sessioning. Default: ``'session'``.

    ``max_age``
      The maximum age of the cookie used for sessioning (in seconds).
      Default: ``None`` (browser scope).

    ``secure``
      The 'secure' flag of the session cookie. Default: ``False``.

    ``httponly``
      Hide the cookie from Javascript by setting the 'HttpOnly' flag of the
      session cookie. Default: ``False``.

    ``samesite``
      The 'SameSite' attribute of the cookie, can be either ``b"strict"``,
      ``b"lax"``, ``b"none"``, or ``None``.

    ``path``
      The path used for the session cookie. Default: ``'/'``.

    ``domains``
      The domain(s) used for the session cookie. Default: ``None`` (no domain).
      Can be passed an iterable containing multiple domains, this will set
      multiple cookies one for each domain.

    ``serializer``
      An object with two methods: `loads`` and ``dumps``.  The ``loads`` method
      should accept bytes and return a Python object.  The ``dumps`` method
      should accept a Python object and return bytes.  A ``ValueError`` should
      be raised for malformed inputs.  Default: ``None`, which will use a
      derivation of :func:`json.dumps` and ``json.loads``.
    FNr   r   c             C   sJ   || _ || _|
| _|| _t|||
| jd}tj| |||||||	|d	 d S )N)r   )r   r   r   r   r   r   r   )r   r   r   original_serializerr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   Zsigned_serializerr   r   r   r     s&    
zSignedCookieProfile.__init__c             C   s<   t | j| j| j| j| j| j| j| j| j	| j
| j}||_|S )z8 Bind a request to a copy of this instance and return it)r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r     s    zSignedCookieProfile.bind)FNFNr   Nr   N)rY   rZ   r[   r   r   r   r   r   r   r   r     s   6       
)Nr   NFFNN)_r   r   r   r   r   r   r   r   rer   r   r   Zwebob.compatr   r   r   r   r	   r
   r   Z
webob.utilr   __all__objectZ_markerr   r   r)   r   r_   r*   ry   r   r   r   ri   Z
_re_quotedZ_legal_special_charsescapeZ_re_legal_charZ_re_expires_valZ_re_cookie_str_keyZ_re_cookie_str_equalZ_re_unquoted_valZ_re_cookie_str_valZ_re_cookie_strcompiler4   r   r   r   ranger   r   listrN   r   r   r   rw   r   Z_allowed_special_charsascii_lettersdigitsZ_allowed_cookie_charsr   Z_valid_token_charsr   Z_escape_noop_charsZ_escape_mapziprO   rI   r   r   r   r   r   r3   rE   r   Z_domain_quoteZ_max_age_quoter   rq   r   setra   r   r   r   r   r   r   r   r   r   r   r   <module>   s   $

 $
@
 
f
 Y d