3
‡ŒðiMT  ã            ¦   @   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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ždŸd d¡d¢d£d¤d¥d¦d§d¨d©dªd«d¬d­d®d¯d°d±d²d³d´dµd¶œ¥Zefd·d¸„Zejd¹ƒZejdºƒZd»d¼„ Z d½d¾d¿dÀdÁdÂdÃgZ!ddÄdÅdÆdÇdÈdÉdÊdËdÌdÍdÎdÏgZ"de!e"fdÐdÑ„Z#G dÒdÓ„ dÓeƒZ$dÔZ%ejdÕe% dÖ e% d× ejƒZ&G dØd
„ d
eƒZ'G dÙd„ 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   ú?/tmp/pip-build-6m2fasei/future/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\073z\"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 )zãQuote 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>r8   c             s   s   | ]}t j||ƒV  qd S )N)Ú_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   sL  t | ƒdk r| S | d dks(| d dkr,| S | dd… } d}t | ƒ}g }xúd|  ko\|k n  �rBtj| |ƒ}tj| |ƒ}| rœ| rœ|j| |d … ƒ P d	 }}|r²|jdƒ}|rÀ|jdƒ}|oÐ| sÔ||k �r|j| ||… ƒ |j| |d  ƒ |d }qJ|j| ||… ƒ |jtt| |d |d … dƒƒƒ |d }qJW t|ƒS )
Né   r   r8   é   é   é   éÿÿÿÿrÉ   rÉ   )	ÚlenÚ
_OctalPattÚsearchÚ
_QuotePattÚappendÚstartr   r   rÃ   )ÚmystrÚiÚnÚresÚo_matchÚq_matchÚjÚkr   r   r   Ú_unquoteû   s6    


$rØ   ÚMonÚTueÚWedÚThuÚFriÚSatÚSunÚJanÚFebÚMarÚAprÚMayÚJunÚJulÚAugÚSepÚOctÚNovÚDecc          	   C   sR   ddl m}m } |ƒ }|||  ƒ\	}}}}	}
}}}}d|| ||| ||	|
|f S )Nr   )ÚgmtimeÚtimez#%s, %02d %3s %4d %02d:%02d:%02d GMT)rí   rì   )ÚfutureÚweekdaynameÚ	monthnamerì   rí   ÚnowÚyearÚmonthÚdayÚhhÚmmÚssÚ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ÚCommentÚDomainzMax-AgeÚsecureÚhttponlyÚVersion)rý   ÚpathÚcommentÚdomainzmax-ager  r  Úversionc             C   s4   d  | _  | _| _x| jD ]}tj| |dƒ qW d S )Nr   )ÚkeyÚvalueÚcoded_valueÚ	_reservedr   Ú__setitem__)Úselfr  r   r   r   Ú__init__^  s    zMorsel.__init__c             C   s0   |j ƒ }|| jkrtd| ƒ‚tj| ||ƒ 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 ƒ | jkS )N)r  r  )r  r  r   r   r   ÚisReservedKeyl  s    zMorsel.isReservedKeyc                sR   |j ƒ | 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 )Nr   )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  ÚvalÚ	coded_valr½   r   )r½   r   Úseto  s    z
Morsel.setNúSet-Cookie:c             C   s   d|| j |ƒ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| j |ƒjddƒ S )Nz—
        <script type="text/javascript">
        <!-- begin hiding
        document.cookie = "%s";
        // end hiding -->
        </script>
        r8   z\")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| jƒ ƒ}xÊ|D ]Â\}}|dkrPq>||krZq>|dkrˆt|tƒrˆ|d| j| t|ƒf ƒ q>|dkr²t|tƒr²|d| j| |f ƒ q>|dkrÎ|t	| j| ƒƒ q>|dkrê|t	| j| ƒƒ q>|d| j| |f ƒ q>W t
|ƒS )Nz%s=%sr   rý   zmax-agez%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   r   Úvalue_decodeÙ  s    zBaseCookie.value_decodec             C   s   t |ƒ}||fS )zýreal_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  Ústrvalr   r   r   Úvalue_encodeâ  s    zBaseCookie.value_encodeNc             C   s   |r| j |ƒ d S )N)Úload)r  Úinputr   r   r   r  ë  s    zBaseCookie.__init__c             C   s.   | j |tƒ ƒ}|j|||ƒ tj| ||ƒ dS )z+Private method for setting a cookie's valueN)rÀ   rü   r  r   r  )r  r  Ú
real_valuer
  ÚMr   r   r   Ú__setï  s    zBaseCookie.__setc             C   s    | j |ƒ\}}| j|||ƒ dS )zDictionary style assignment.N)r-  Ú_BaseCookie__set)r  r  r	  ÚrvalÚcvalr   r   r   r  õ  s    zBaseCookie.__setitem__úSet-Cookie:ú
c             C   s>   g }t | jƒ ƒ}x"|D ]\}}|j|j||ƒƒ qW |j|ƒ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   sr   g }t | jƒ ƒ}xL|D ]D\}}tr:t|jtƒr:t|jƒ}n|j}|jdt|ƒt|ƒf ƒ qW d| j	j
t|ƒf S )Nz%s=%sz<%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   s:   g }t | jƒ ƒ}x |D ]\}}|j|j|ƒƒ qW 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   s8   t |tƒr| j|ƒ nx|jƒ D ]\}}|| |< q W dS )zÝLoad 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  Úrawdatar  r	  r   r   r   r.    s
    
zBaseCookie.loadc             C   sò   d}t |ƒ}d }xÜd|  ko$|k n  rì|j||ƒ}|s<P |jdƒ|jdƒ }}|jdƒ}|d dkr~|rê|||dd … < q|jƒ tjkr¾|rê|d kr°|jƒ tjkr¼d||< qêt|ƒ||< q|d k	r| j	|ƒ\}	}
| j
||	|
ƒ | | }qW d S )Nr   r  r  ú$rÆ   T)rÊ   rÌ   ÚgroupÚendr  rü   r  r(  rØ   r+  r3  )r  rÐ   ÚpattrÑ   rÒ   r1  Úmatchr  r	  r4  r5  r   r   r   Ú__parse_string&  s,    

zBaseCookie.__parse_string)N)Nr6  r7  )N)r   r   r   r'  r+  r-  r  r3  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 )N)rØ   )r  r  r   r   r   r+  Q  s    zSimpleCookie.value_decodec             C   s   t |ƒ}|t|ƒfS )N)r	   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'  Ú
__future__r   r   r   r   Zfuture.builtinsr   r   r   r	   Zfuture.utilsr
   r   ÚreÚASCIIÚstringÚ__all__r8  rÃ   r%  r:  Ú	Exceptionr   Úascii_lettersÚdigitsr)  r¿   rÄ   ÚcompilerË   rÍ   rØ   Ú_weekdaynameÚ
_monthnamerû   rü   Z_LegalCharsPattrD  r   r   r   r   r   r   Ú<module>�   s²   


2 t