
\[\{Q                 @   s  d  Z  d d l Z d d l Z d d d g Z d j Z d j Z d j Z Gd	 d   d e  Z	 e j
 e j d
 Z i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6dC dD 6dE dF 6dG dH 6dI dJ 6dK dL 6dM dN 6dO dP 6dQ dR 6dS dT 6dU dV 6dW dX 6dY dZ 6d[ d\ 6d] d^ 6d_ d` 6da db 6dc dd 6de df 6dg dh 6di dj 6dk dl 6dm dn 6do dp 6dq dr 6ds dt 6du dv 6dw dx 6dy dz 6d{ d| 6d} d~ 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6dd6dd6dd6dd6d	d
6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d'd(6d)d*6d+d,6d-d.6d/d06d1d26d3d46d5d66d7d86d9d:6d;d<6d=d>6d?d@6dAdB6dCdD6dEdF6dGdH6dIdJ6dKdL6dMdN6dOdP6dQdR6dSdT6Z e dUdV Z e j dW Z e j dX Z dYdZ  Z d[d\d]d^d_d`dag Z d dbdcdddedfdgdhdidjdkdldmg Z d e e dndo Z Gdpdq  dqe  Z drZ e j dse dte due j  Z Gdvd   d e  Z Gdwd   d e  Z d S(x  a.
  
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.
    NCookieError
BaseCookieSimpleCookie z;  c               @   s   e  Z d  Z d S)r   N)__name__
__module____qualname__ r
   r
   "/usr/lib/python3.4/http/cookies.pyr      s   z!#$%&'*+-.^_`|~:z\000 z\001z\002z\003z\004z\005z\006z\007z\010z\011	z\012
z\013z\014z\015z\016z\017z\020z\021z\022z\023z\024z\025z\026z\027z\030z\031z\032z\033z\034z\035z\036z\037z\054,z\073;z\""z\\\z\177z\200   z\201   z\202   z\203   z\204   z\205   z\206   z\207   z\210   z\211   z\212   z\213   z\214   z\215   z\216   z\217   z\220   z\221   z\222   z\223   z\224   z\225   z\226   z\227   z\230   z\231   z\232   z\233   z\234   z\235   z\236   z\237   z\240    z\241   ¡z\242   ¢z\243   £z\244   ¤z\245   ¥z\246   ¦z\247   §z\250   ¨z\251   ©z\252   ªz\253   «z\254   ¬z\255   ­z\256   ®z\257   ¯z\260   °z\261   ±z\262   ²z\263   ³z\264   ´z\265   µz\266   ¶z\267   ·z\270   ¸z\271   ¹z\272   ºz\273   »z\274   ¼z\275   ½z\276   ¾z\277   ¿z\300   Àz\301   Áz\302   Âz\303   Ãz\304   Äz\305   Åz\306   Æz\307   Çz\310   Èz\311   Éz\312   Êz\313   Ëz\314   Ìz\315   Íz\316   Îz\317   Ïz\320   Ðz\321   Ñz\322   Òz\323   Óz\324   Ôz\325   Õz\326   Öz\327   ×z\330   Øz\331   Ùz\332   Úz\333   Ûz\334   Üz\335   Ýz\336   Þz\337   ßz\340   àz\341   áz\342   âz\343   ãz\344   äz\345   åz\346   æz\347   çz\350   èz\351   éz\352   êz\353   ëz\354   ìz\355   íz\356   îz\357   ïz\360   ðz\361   ñz\362   òz\363   óz\364   ôz\365   õz\366   öz\367   ÷z\370   øz\371   ùz\372   úz\373   ûz\374   üz\375   ýz\376   þz\377   ÿc                sF   t    f d d   |  D  r# |  Sd t d d   |  D  d Sd 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>r.   c             s   s!   |  ] } t  j | |  Vq d  S)N)_Translatorget)r   sr
   r
   r   r      s    N)all	_nulljoin)strr   r
   )r   r   _quote   s    r   z\\[0-3][0-7][0-7]z[\\].c             C   s  t  |   d k  r |  S|  d d k s6 |  d d k r: |  S|  d d  }  d } t  |   } g  } xHd | k o| | k  n rt j |  |  } t j |  |  } | r | r | j |  | d    Pn  d	 } } | r | j d  } n  | r| j d  } n  | rZ| s!| | k  rZ| j |  | |   | j |  | d  | d } qe | j |  | |   | j t t |  | d | d  d    | d } qe Wt |  S)
N   r   r.            r   r   )	len
_OctalPattsearch
_QuotePattappendstartchrintr   )r   inZ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   so   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   _getdate)  s
    	+r   c               @   s   e  Z d  Z d Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6Z d d h Z d d   Z d d   Z d d   Z e	 d d  Z
 d d d d  Z e Z 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.
    expiresZPathpathCommentZcommentZDomainZdomainzMax-Agezmax-agesecurehttponlyZVersionversionc             C   sB   d  |  _  |  _ |  _ x$ |  j D] } t j |  | d  q! Wd  S)Nr   )keyvaluecoded_value	_reserveddict__setitem__)selfr   r
   r
   r   __init__T  s    zMorsel.__init__c             C   sE   | j    } | |  j k r. t d |   n  t j |  | |  d  S)NzInvalid Attribute %s)lowerr   r   r   r   )r   KVr
   r
   r   r   \  s    zMorsel.__setitem__c             C   s   | j    |  j k S)N)r   r   )r   r   r
   r
   r   isReservedKeyb  s    zMorsel.isReservedKeyc                sy   | j    |  j k r( t d |   n  t   f d d   | D  rZ t d |   n  | |  _ | |  _ | |  _ d  S)Nz!Attempt to set a reserved key: %sc             3   s   |  ] } |   k Vq d  S)Nr
   )r   r   )r   r
   r   r   j  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   sete  s    		z
Morsel.setNzSet-Cookie:c             C   s   d | |  j  |  f S)Nz%s %s)OutputString)r   attrsheaderr
   r
   r   outputr  s    zMorsel.outputc             C   s#   d |  j  j |  j t |  j  f S)Nz<%s: %s=%s>)	__class__r   r   reprr   )r   r
   r
   r   __repr__w  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>
        r.   z\")r   replace)r   r   r
   r
   r   	js_output{  s    zMorsel.js_outputc             C   sw  g  } | j  } | d |  j |  j f  | d  k rA |  j } n  t |  j    } x| D]\ } } | d k rx qZ n  | | k r qZ n  | d k r t | t  r | d |  j | t |  f  qZ | d k rt | t  r| d |  j | | f  qZ | d k r(| t	 |  j |   qZ | d k rN| t	 |  j |   qZ | d |  j | | f  qZ Wt
 |  S)Nz%s=%sr   r   zmax-agez%s=%dr   r   )r   r   r   r   sorteditems
isinstancer   r   r   _semispacejoin)r   r   resultr   r   r   r   r
   r
   r   r     s*    	$zMorsel.OutputString)r   r   r	   __doc__r   _flagsr   r   r   _LegalCharsr   r   __str__r   r   r   r
   r
   r
   r   r   1  s(   

r   z.[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]z
    (?x)                           # This is a verbose pattern
    \s*                            # Optional whitespace at start of cookie
    (?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               @   s   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 d d  Z	 e	 Z
 d d   Z d d d  Z d d   Z e 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)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   strvalr
   r
   r   value_encode  s    zBaseCookie.value_encodeNc             C   s   | r |  j  |  n  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   Z
real_valuer   Mr
   r
   r   Z__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__zSet-Cookie:z
c             C   sU   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   si   g  } t  |  j    } x4 | D], \ } } | j d | t | j  f  q Wd |  j j t |  f S)Nz%s=%sz<%s: %s>)r   r   r   r   r   r   r   
_spacejoin)r   lr   r   r   r
   r
   r   r     s
    $zBaseCookie.__repr__c             C   sO   g  } t  |  j    } x* | D]" \ } } | j | j |   q Wt |  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   sJ   t  | t  r |  j |  n' x$ | j   D] \ } } | |  | <q, Wd 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  } x=d | k o2 | k  n rW| j | |  } | sS Pn  | j d  | j d  } } | j d  } | d d k r | rT| | | d d   <qTq | j   t j k r| rT| d  k r | j   t j k rd | | <qqt |  | | <qTq | d  k	 r |  j	 |  \ }	 }
 |  j
 | |	 |
  |  | } q q Wd  S)Nr   r   r   $r   T)r   matchgroupendr   r   r   r   r   r   r  )r   r   Zpattr   r   r   r
  r   r   r  r  r
   r
   r   Z__parse_string  s,    zBaseCookie.__parse_string)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)N)r   )r   r   r
   r
   r   r   =  s    zSimpleCookie.value_decodec             C   s   t  |  } | t |  f S)N)r   r   )r   r   r   r
   r
   r   r   @  s    zSimpleCookie.value_encodeN)r   r   r	   r   r   r   r
   r
   r
   r   r   6  s   )r   restring__all__r  r   r   r  	Exceptionr   Zascii_lettersZdigitsr   r   r   compiler   r   r   Z_weekdaynameZ
_monthnamer   r   r   Z_LegalCharsPattASCIIr  r   r   r
   r
   r
   r   <module>   s   			2~n