D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
lib
/
python3.9
/
site-packages
/
ipapython
/
__pycache__
/
Filename :
cookie.cpython-39.opt-1.pyc
back
Copy
a }�fXa � @ sN d dl Z d dlZd dlZd dlmZ d dlmZ d dlm Z G dd� d�Z dS )� N)�timegm)�urlparse)�datetime_from_utctimestampc @ s@ e Zd ZdZG dd� de�ZG dd� de�Ze�d�Z e�dej �Zdd d ddd d�Ze dd� �Ze d7dd��Ze dd� �Ze dd� �Ze d8dd��Ze d9dd��Zd:dd�Zedd� �Zejd d� �Zed!d"� �Zejd#d"� �Zed$d%� �Zejd&d%� �Zd'd(� Zd)d*� Zd+d,� Zd-d.� Zd/d0� Zd1d2� Zd3d4� Z d5d6� Z!dS );�Cookiea� A Cookie object has the following attributes: key The name of the cookie value The value of the cookie A Cookie also supports these predefined optional attributes. If an optional attribute is not set on the cookie it's value is None. domain Restrict cookie usage to this domain path Restrict cookie usage to this path or below expires Cookie is invalid after this UTC timestamp max_age Cookie is invalid this many seconds in the future. Has precedence over the expires attribute. secure Cookie should only be returned on secure (i.e. SSL/TLS) connections. httponly Cookie is intended only for HTTP communication, it can never be utilized in any other context (e.g. browser Javascript). See the documentation of get_expiration() for an explanation of how the expires and max-age attributes interact as well as the role of the timestamp attribute. Expiration values are stored as datetime objects for easy manipulation and comparision. There are two ways to instantiate a Cookie object. Either directly via the constructor or by calling the class function parse() which returns a list of Cookie objects found in a string. To create a cookie to sent to a client: Example: cookie = Cookie('session', session_id, domain=my_domain, path=mypath, httponly=True, secure=True, expires=expiration) headers.append(('Set-Cookie', str(cookie))) To receive cookies from a request: Example: cookies = Cookie.parse(response.getheader('Set-Cookie'), request_url) c @ s e Zd ZdS )zCookie.ExpiredN��__name__� __module__�__qualname__� r r �4/usr/lib/python3.9/site-packages/ipapython/cookie.py�Expired| s r c @ s e Zd ZdS )zCookie.URLMismatchNr r r r r �URLMismatch s r z;\s*z@^\s*([a-zA-Z0-9\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~]+)\s*=\s*(.*?)\s*$�domain�path�max_age�expires�secure�httponly)r r zmax-ager r r c C s t |�� �S )ag Timestamps (timestamp & expires) are stored as datetime objects in UTC. It's non-obvious how to convert a naive UTC datetime into a unix time value (seconds since the epoch UTC). That functionality is oddly missing from the datetime and time modules. This utility provides that missing functionality. )r Zutctimetuple)�cls�dtr r r �datetime_to_time� s zCookie.datetime_to_timeNc C s: |� � }|dur$|�� dkr$td��tjj| �|�dd�S )zO Given a datetime object in UTC generate RFC 1123 date string. Ng ztimezone is not UTCT)Zusegmt)� utcoffsetZ total_seconds� ValueError�email�utilsZ formatdater )r r r r r r �datetime_to_string� s zCookie.datetime_to_stringc C sR |� � }ztj�|�}W n4 tyL } ztd||f ��W Y d}~n d}~0 0 |S )z_ Parse a RFC 822, RFC 1123 date string, return a datetime naive object in UTC. z)unable to parse expires datetime '%s': %sN)�stripr r Zparsedate_to_datetime� Exceptionr )r �sr �er r r �parse_datetime� s &zCookie.parse_datetimec C sB |� � }|sdS |�d�sdS |�d�dkr0dS |d|�d�� S )a+ Given a URL path, possibly empty, return a path consisting only of directory components. The URL path must end with a trailing slash for the last path element to be considered a directory. Also the URL path must begin with a slash. Empty input returns '/'. Examples: '' -> '/' '/' -> '/' 'foo' -> '/' 'foo/' -> '/' '/foo -> '/' '/foo/' -> '/foo' '/foo/bar' -> '/foo' '/foo/bar/' -> '/foo/bar' �/� N)�lower� startswith�count�rindex)r �url_pathr r r �normalize_url_path� s zCookie.normalize_url_pathc C s6 g }t j�|�}d}|D ]�}t j�|�}|r||�d�}|�d�} | rv| d dkrv| d dkrj| dd� } ntd| ��d} n|}d} d } |�� t jv }|du r�| r�|s�t || �}q|r�| r�|s�|dur�|� |� |� |� t || �}q|r�|r�|�|| � q|rtd | ��q|�r2|du�r(|� |� |� |� |S )z� Given a string containing one or more cookies (the HTTP_COOKIES environment variable typically contains multiple cookies) parse the string and return a list of Cookie objects found in the string. Nr"