U
    ,]MT                     @   s  d 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	m
Z
 ddlmZmZ ddlZernde_ddlZd	d
dgZdjZdjZdjZG dd	 d	eZejej d Zdddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~ddddddddddddddddddddddddddddddddddddddddddddddddddddddddZefddZedZedZdd Z dddddddgZ!dddddddddddddgZ"de!e"fddфZ#G ddӄ deZ$dZ%ede% d e% d ejZ&G dd
 d
eZ'G dd de'Z(dS )af
  
http.cookies module ported to python-future from Py3.3

Here's a sample session to show how to use this module.
At the moment, this is the only documentation.

The Basics
----------

Importing is easy...

   >>> from http import cookies

Most of the time you start by creating a cookie.

   >>> C = cookies.SimpleCookie()

Once you've created your Cookie, you can add values just as if it were
a dictionary.

   >>> C = cookies.SimpleCookie()
   >>> C["fig"] = "newton"
   >>> C["sugar"] = "wafer"
   >>> C.output()
   'Set-Cookie: fig=newton\r\nSet-Cookie: sugar=wafer'

Notice that the printable representation of a Cookie is the
appropriate format for a Set-Cookie: header.  This is the
default behavior.  You can change the header and printed
attributes by using the .output() function

   >>> C = cookies.SimpleCookie()
   >>> C["rocky"] = "road"
   >>> C["rocky"]["path"] = "/cookie"
   >>> print(C.output(header="Cookie:"))
   Cookie: rocky=road; Path=/cookie
   >>> print(C.output(attrs=[], header="Cookie:"))
   Cookie: rocky=road

The load() method of a Cookie extracts cookies from a string.  In a
CGI script, you would use this method to extract the cookies from the
HTTP_COOKIE environment variable.

   >>> C = cookies.SimpleCookie()
   >>> C.load("chips=ahoy; vienna=finger")
   >>> C.output()
   'Set-Cookie: chips=ahoy\r\nSet-Cookie: vienna=finger'

The load() method is darn-tootin smart about identifying cookies
within a string.  Escaped quotation marks, nested semicolons, and other
such trickeries do not confuse it.

   >>> C = cookies.SimpleCookie()
   >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";')
   >>> print(C)
   Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;"

Each element of the Cookie also supports all of the RFC 2109
Cookie attributes.  Here's an example which sets the Path
attribute.

   >>> C = cookies.SimpleCookie()
   >>> C["oreo"] = "doublestuff"
   >>> C["oreo"]["path"] = "/"
   >>> print(C)
   Set-Cookie: oreo=doublestuff; Path=/

Each dictionary element has a 'value' attribute, which gives you
back the value associated with the key.

   >>> C = cookies.SimpleCookie()
   >>> C["twix"] = "none for you"
   >>> C["twix"].value
   'none for you'

The SimpleCookie expects that all values should be standard strings.
Just to be sure, SimpleCookie invokes the str() builtin to convert
the value to a string, when the values are set dictionary-style.

   >>> C = cookies.SimpleCookie()
   >>> C["number"] = 7
   >>> C["string"] = "seven"
   >>> C["number"].value
   '7'
   >>> C["string"].value
   'seven'
   >>> C.output()
   'Set-Cookie: number=7\r\nSet-Cookie: string=seven'

Finis.
    )unicode_literals)print_function)division)absolute_import)chrdictintstr)PY2as_native_strNCookieError
BaseCookieSimpleCookie z;  c                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   ?/usr/lib/python3/dist-packages/future/backports/http/cookies.pyr      s   z!#$%&'*+-.^_`|~:z\000z\001z\002z\003z\004z\005z\006z\007z\010z\011z\012z\013z\014z\015z\016z\017z\020z\021z\022z\023z\024z\025z\026z\027z\030z\031z\032z\033z\034z\035z\036z\037z\054z\073\"z\\z\177z\200z\201z\202z\203z\204z\205z\206z\207z\210z\211z\212z\213z\214z\215z\216z\217z\220z\221z\222z\223z\224z\225z\226z\227z\230z\231z\232z\233z\234z\235z\236z\237z\240z\241z\242z\243z\244z\245z\246z\247z\250z\251z\252z\253z\254z\255z\256z\257z\260z\261z\262z\263z\264z\265z\266z\267z\270z\271z\272z\273z\274z\275z\276z\277z\300z\301z\302z\303z\304z\305z\306z\307z\310z\311z\312z\313z\314z\315z\316z\317z\320z\321z\322z\323z\324z\325z\326z\327z\330z\331z\332z\333z\334z\335z\336z\337z\340z\341z\342z\343z\344z\345z\346z\347z\350z\351z\352z\353z\354z\355z\356z\357z\360z\361z\362z\363z\364z\365z\366z\367z\370z\371z\372z\373z\374z\375z\376z\377) 	
,;"\                                                                                                       ¡   ¢   £   ¤   ¥   ¦   §   ¨   ©   ª   «   ¬   ­   ®   ¯   °   ±   ²   ³   ´   µ   ¶   ·   ¸   ¹   º   »   ¼   ½   ¾   ¿   À   Á   Â   Ã   Ä   Å   Æ   Ç   È   É   Ê   Ë   Ì   Í   Î   Ï   Ð   Ñ   Ò   Ó   Ô   Õ   Ö   ×   Ø   Ù   Ú   Û   Ü   Ý   Þ   ß   à   á   â   ã   ä   å   æ   ç   è   é   ê   ë   ì   í   î   ï   ð   ñ   ò   ó   ô   õ   ö   ÷   ø   ù   ú   û   ü   ý   þ   ÿc                    s8   t  fdd| D r| S dtdd | D  d S dS )zQuote a string for use in a cookie header.

    If the string does not need to be double-quoted, then just return the
    string.  Otherwise, surround the string in doublequotes and quote
    (with a \) special characters.
    c                 3   s   | ]}| kV  qd S Nr   .0c
LegalCharsr   r   	<genexpr>   s     z_quote.<locals>.<genexpr>r9   c                 s   s   | ]}t ||V  qd S r   )_Translatorget)r   sr   r   r   r      s     N)all	_nulljoin)r	   r   r   r   r   _quote   s    r   z\\[0-3][0-7][0-7]z[\\].c                 C   sB  t | dk r| S | d dks(| d dkr,| S | dd } d}t | }g }d|  kr^|k r:n nt| |}t| |}|s|s|| |d   q:d }}|r|d}|r|d}|r|r||k r|| ||  || |d   |d }qH|| ||  |tt| |d |d  d |d }qHt|S )N   r   r9            )	len
_OctalPattsearch
_QuotePattappendstartr   r   r   )mystrinresZo_matchZq_matchjkr   r   r   _unquote   s6    


$
r   ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc              	   C   sR   ddl m}m } | }|||  \	}}}}	}
}}}}d|| ||| ||	|
|f S )Nr   )gmtimetimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r   r   )ZfutureZweekdaynameZ	monthnamer   r   ZnowZyearZmonthZdayZhhZmmZssZwdyzr   r   r   _getdate3  s    r   c                	   @   s   e Zd ZdZdddddddd	d
ZeddgZdd Zdd Zdd Z	e
fddZdddZeZe dd ZdddZdddZdS ) Morsela  A class to hold ONE (key, value) pair.

    In a cookie, each such pair may have several attributes, so this class is
    used to keep the attributes associated with the appropriate key,value pair.
    This class also includes a coded_value attribute, which is used to hold
    the network representation of the value.  This is most useful when Python
    objects are pickled for network transit.
    expiresPathCommentZDomainzMax-AgesecurehttponlyZVersion)r   pathZcommentZdomainmax-ager   r   versionc                 C   s0   d  | _  | _| _| jD ]}t| |d qd S )Nr   )keyvaluecoded_value	_reservedr   __setitem__)selfr   r   r   r   __init__^  s    
zMorsel.__init__c                 C   s0   |  }|| jkrtd| t| || d S )NzInvalid Attribute %s)lowerr   r   r   r   )r   KVr   r   r   r   f  s    
zMorsel.__setitem__c                 C   s   |  | jkS r   )r   r   )r   r   r   r   r   isReservedKeyl  s    zMorsel.isReservedKeyc                    sR   |  | jkrtd| t fdd|D r<td| || _|| _|| _d S )Nz!Attempt to set a reserved key: %sc                 3   s   | ]}| kV  qd S r   r   r   r   r   r   r   t  s     zMorsel.set.<locals>.<genexpr>zIllegal key value: %s)r   r   r   anyr   r   r   )r   r   valZ	coded_valr   r   r   r   seto  s    z
Morsel.setNSet-Cookie:c                 C   s   d||  |f S )Nz%s %s)OutputString)r   attrsheaderr   r   r   output|  s    zMorsel.outputc                 C   s>   t rt| jtrt| j}n| j}d| jjt| jt|f S )Nz<%s: %s=%s>)	r
   
isinstancer   unicoder	   	__class__r   r   reprr   r   r   r   r   __repr__  s     zMorsel.__repr__c                 C   s   d|  |dd S )Nz
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        r9   r   )r   replace)r   r   r   r   r   	js_output  s    zMorsel.js_outputc                 C   s  g }|j }|d| j| jf  |d kr,| j}t|  }|D ]\}}|dkrNq<||krXq<|dkrt|tr|d| j| t|f  q<|dkrt|tr|d| j| |f  q<|dkr|t	| j|  q<|dkr|t	| j|  q<|d| j| |f  q<t
|S )N%s=%sr   r   r   z%s=%dr   r   )r   r   r   r   sorteditemsr   r   r   r	   _semispacejoin)r   r   resultr   r  r   r   r   r   r   r     s*    zMorsel.OutputString)Nr   )N)N)r   r   r   __doc__r   r   _flagsr   r   r   _LegalCharsr   __str__r   r  r  r   r   r   r   r   r   ;  s*   



r   z.[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]z~
    (?x)                           # This is a verbose pattern
    (?P<key>                       # Start of group 'key'
    a  +?   # Any word of at least one letter
    )                              # End of group 'key'
    (                              # Optional group: there may not be a value.
    \s*=\s*                          # Equal Sign
    (?P<val>                         # Start of group 'val'
    "(?:[^\\"]|\\.)*"                  # Any doublequoted string
    |                                  # or
    \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT  # Special case for "expires" attr
    |                                  # or
    a,  *      # Any word or empty string
    )                                # End of group 'val'
    )?                             # End of optional value group
    \s*                            # Any number of spaces.
    (\s+|;|$)                      # Ending either at space, semicolon, or EOS.
    c                   @   st   e Zd ZdZdd Zdd ZdddZd	d
 Zdd ZdddZ	e	Z
e dd ZdddZdd ZefddZdS )r   z'A container class for a set of Morsels.c                 C   s   ||fS )a
  real_value, coded_value = value_decode(STRING)
        Called prior to setting a cookie's value from the network
        representation.  The VALUE is the value read from HTTP
        header.
        Override this function to modify the behavior of cookies.
        r   r   r   r   r   value_decode  s    zBaseCookie.value_decodec                 C   s   t |}||fS )zreal_value, coded_value = value_encode(VALUE)
        Called prior to setting a cookie's value from the dictionary
        representation.  The VALUE is the value being assigned.
        Override this function to modify the behavior of cookies.
        )r	   r   r   Zstrvalr   r   r   value_encode  s    zBaseCookie.value_encodeNc                 C   s   |r|  | d S r   )load)r   inputr   r   r   r     s    zBaseCookie.__init__c                 C   s.   |  |t }|||| t| || dS )z+Private method for setting a cookie's valueN)r   r   r   r   r   )r   r   Z
real_valuer   Mr   r   r   Z__set  s    zBaseCookie.__setc                 C   s    |  |\}}| ||| dS )zDictionary style assignment.N)r  _BaseCookie__set)r   r   r   rvalcvalr   r   r   r     s    zBaseCookie.__setitem__r   
c                 C   s:   g }t |  }|D ]\}}|||| q||S )z"Return a string suitable for HTTP.)r  r  r   r   join)r   r   r   sepr  r  r   r   r   r   r   r     s
    zBaseCookie.outputc                 C   sn   g }t |  }|D ]D\}}tr8t|jtr8t|j}n|j}|dt|t|f  qd| j	j
t|f S )Nr  z<%s: %s>)r  r  r
   r   r   r   r	   r   r   r   r   
_spacejoin)r   lr  r   r   r   r   r   r   r    s    zBaseCookie.__repr__c                 C   s6   g }t |  }|D ]\}}||| qt|S )z(Return a string suitable for JavaScript.)r  r  r   r  r   )r   r   r  r  r   r   r   r   r   r    s
    zBaseCookie.js_outputc                 C   s4   t |tr| | n| D ]\}}|| |< qdS )zLoad cookies from a string (presumably HTTP_COOKIE) or
        from a dictionary.  Loading cookies from a dictionary 'd'
        is equivalent to calling:
            map(Cookie.__setitem__, d.keys(), d.values())
        N)r   r	   _BaseCookie__parse_stringr  )r   Zrawdatar   r   r   r   r   r    s
    

zBaseCookie.loadc                 C   s   d}t |}d }d|  kr$|k rn n|||}|s:q|d|d }}|d}|d dkr||r|||dd  < q| tjkr|r|d kr| tjkrd||< qt|||< q|d k	r| 	|\}	}
| 
||	|
 | | }qd S )Nr   r   r   $r   T)r   r   groupendr   r   r   r
  r   r  r  )r   r   Zpattr   r   r  matchr   r   r  r  r   r   r   Z__parse_string&  s,    

zBaseCookie.__parse_string)N)Nr   r  )N)r   r   r   r	  r  r  r   r  r   r   r  r   r  r  r  _CookiePatternr  r   r   r   r   r     s   		



c                   @   s    e Zd ZdZdd Zdd ZdS )r   z
    SimpleCookie supports strings as cookie values.  When setting
    the value using the dictionary assignment notation, SimpleCookie
    calls the builtin str() to convert the value to a string.  Values
    received from HTTP are kept as strings.
    c                 C   s   t ||fS r   )r   r   r   r   r   r  Q  s    zSimpleCookie.value_decodec                 C   s   t |}|t|fS r   )r	   r   r  r   r   r   r  T  s    zSimpleCookie.value_encodeN)r   r   r   r	  r  r  r   r   r   r   r   J  s   ))r	  Z
__future__r   r   r   r   Zfuture.builtinsr   r   r   r	   Zfuture.utilsr
   r   reASCIIstring__all__r  r   r  r  	Exceptionr   Zascii_lettersZdigitsr  r   r   compiler   r   r   Z_weekdaynameZ
_monthnamer   r   Z_LegalCharsPattr   r   r   r   r   r   r   <module>'   s  [
                                                                                                             A

2           t