%PDF- %PDF-
| Direktori : /snap/core18/current/usr/lib/python3.6/http/__pycache__/ |
| Current File : //snap/core18/current/usr/lib/python3.6/http/__pycache__/cookies.cpython-36.pyc |
3
���iW �
@ s� d Z ddlZddlZdddgZdjZdjZdjZd d
� ZG dd� de �Z
ejej d Z
e
d
Zdd� eed��eeee�� D �Zejed�ded�di� ejdeje
� �jZejd�Zdd� Zdd� Zejd�Zejd�Zdd� Zdd d!d"d#d$d%gZdd&d'd(d)d*d+d,d-d.d/d0d1g
Z dee fd2d3�Z!G d4d5� d5e"�Z#d6Z$e$d7 Z%ejd8e$ d9 e% d: ej&ej'B �Z(G d;d� de"�Z)G d<d� de)�Z*dS )=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=;";')
>>> print(C)
Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=;"
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 C s$ dd l }d| }|j|tdd� d S )Nr zvThe .%s setter is deprecated. The attribute will be read-only in future releases. Please use the set() method instead.� )�
stacklevel)�warnings�warn�DeprecationWarning)�setterr �msg� r �"/usr/lib/python3.6/http/cookies.py�_warn_deprecated_setter� s r c @ s e Zd ZdS )r N)�__name__�
__module__�__qualname__r r r r r � s z!#$%&'*+-.^_`|~:z
()/<=>?@[]{}c C s i | ]}d | |�qS )z\%03or )�.0�nr r r �
<dictcomp>� s r � �"z\"�\z\\z[%s]+z[\x00-\x1F\x7F]c G s t dd� | D ��S )zhDetects control characters within a value.
Supports any type, as header values can be any type.
c s s | ]}t jt|��V qd S )N)�_control_character_re�search�str)r �vr r r � <genexpr>� s z)_has_control_character.<locals>.<genexpr>)�any)�valr r r �_has_control_character� s r! c C s* | dkst | �r| S d| jt� d S dS )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.
Nr )�
_is_legal_key� translate�_Translator)r r r r �_quote� s r% z\\[0-3][0-7][0-7]z[\\].c C sT | d kst | �dk r| S | d dks0| d dkr4| S | dd� } d}t | �}g }x�d| kod|k n �rJtj| |�}tj| |�}| r�| r�|j| |d � � P d }}|r�|jd�}|r�|jd�}|o�| s�||k �r
|j| ||� � |j| |d � |d }qR|j| ||� � |jtt| |d |d � d��� |d }qRW t|�S )
N� r r � � � ���r* r* ) �len�
_OctalPattr �
_QuotePatt�append�start�chr�int� _nulljoin)r �ir ZresZo_matchZq_match�j�kr r r �_unquote� s6
$r6 ZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecc C sR ddl m}m } |� }||| �\ }}}} }
}}}
}d|| ||| || |
|f S )Nr )�gmtime�timez#%s, %02d %3s %4d %02d:%02d:%02d GMT)r8 r7 )ZfutureZweekdaynameZ monthnamer7 r8 ZnowZyearZmonthZdayZhhZmmZssZwd�y�zr r r �_getdate s
r; c @ s e Zd ZdZdddddddd d
�ZddhZd
d� Zedd� �Zej dd� �Zedd� �Z
e
j dd� �Z
edd� �Zej dd� �Zdd� Zd4dd�Z
dd� ZejZdd � Zd!d"� Zd#d$� Zefd%d&�Zd'd(� Zd)d*� Zd5d,d-�ZeZd.d/� Zd6d0d1�Zd7d2d3�ZdS )8�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.
�expiresZPath�CommentZDomainzMax-AgeZSecureZHttpOnlyZVersion)r= �path�commentZdomainzmax-age�secure�httponly�versionrA rB c C s4 d | _ | _| _x| jD ]}tj| |d� qW d S )Nr )�_key�_value�_coded_value� _reserved�dict�__setitem__)�self�keyr r r �__init__/ s zMorsel.__init__c C s | j S )N)rD )rJ r r r rK 7 s z
Morsel.keyc C s t d� || _d S )NrK )r rD )rJ rK r r r rK ; s c C s | j S )N)rE )rJ r r r �value@ s zMorsel.valuec C s t d� || _d S )NrM )r rE )rJ rM r r r rM D s c C s | j S )N)rF )rJ r r r �coded_valueI s zMorsel.coded_valuec C s t d� || _d S )NrN )r rF )rJ rN r r r rN M s c C sP |j � }|| jkr td|f ��t||�r>td|�d|����tj| ||� d S )NzInvalid attribute %rz.Control characters are not allowed in cookies r )�lowerrG r r! rH rI )rJ �K�Vr r r rI R s
zMorsel.__setitem__Nc C sH |j � }|| jkr td|f ��t||�r:td||f ��tj| ||�S )NzInvalid attribute %rz3Control characters are not allowed in cookies %r %r)rO rG r r! rH �
setdefault)rJ rK r r r r rR Z s
zMorsel.setdefaultc C s>