HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipapython/__pycache__/cookie.cpython-39.opt-1.pyc
a

}�fXa�@sNddlZddlZddlZddlmZddlmZddlm	Z	Gdd�d�Z
dS)�N)�timegm)�urlparse)�datetime_from_utctimestampc@s@eZdZdZGdd�de�ZGdd�de�Ze�d�Z	e�dej
�Zdd	d
ddd
d�Ze
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eZdZdS)zCookie.ExpiredN��__name__�
__module__�__qualname__�r
r
�4/usr/lib/python3.9/site-packages/ipapython/cookie.py�Expired|src@seZdZdS)zCookie.URLMismatchNrr
r
r
r�URLMismatchsr
z;\s*z@^\s*([a-zA-Z0-9\!\#\$\%\&\'\*\+\-\.\^\_\`\|\~]+)\s*=\s*(.*?)\s*$�domain�path�max_age�expires�secure�httponly)rrzmax-agerrrcCs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.
        )rZutctimetuple)�cls�dtr
r
r�datetime_to_time�szCookie.datetime_to_timeNcCs:|��}|dur$|��dkr$td��tjj|�|�dd�S)zO
        Given a datetime object in UTC generate RFC 1123 date string.
        Ngztimezone is not UTCT)Zusegmt)�	utcoffsetZ
total_seconds�
ValueError�email�utilsZ
formatdater)rrrr
r
r�datetime_to_string�s	zCookie.datetime_to_stringc
CsR|��}ztj�|�}Wn4tyL}ztd||f��WYd}~n
d}~00|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)�striprrZparsedate_to_datetime�	Exceptionr)r�sr�er
r
r�parse_datetime�s&zCookie.parse_datetimecCsB|��}|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Cs6g}tj�|�}d}|D]�}tj�|�}|r||�d�}|�d�}	|	rv|	ddkrv|	ddkrj|	dd�}	ntd|	��d}
n|}d}	d	}
|��tjv}|dur�|
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"�r�"���zunterminated quote in '%s'TFzunknown cookie token '%s')r�field_re�split�
kv_pair_re�search�grouprr#�attrs�	normalize�append�_Cookie__set_attr)r�
cookie_string�request_url�cookies�fields�cookieZfield�match�key�valueZkv_pairZis_attributer
r
r�parse�sB







zCookie.parsecCsJd}|�|�}|D]}|j|kr|}q|dur4||_|durF|�|�|S)a$
        A cookie string may contain multiple cookies, parse the cookie
        string and return the last cookie in the string matching the
        cookie name or None if not found.

        This is basically a utility wrapper around the parse() class
        method which iterates over what parse() returns looking for
        the specific cookie.

        When cookie_name appears more than once the last instance is
        returned rather than the first because the ordering sequence
        makes the last instance the current value.
        N)r=r;�	timestampr2)rr5�cookie_namer6r>Z
target_cookier7r9r
r
r�get_named_cookie_from_stringAs


z#Cookie.get_named_cookie_from_stringc

Cs:||_||_||_||_||_||_||_||_|	|_dS)N)	r;r<rrrrrrr>)
�selfr;r<rrrrrrr>r
r
r�__init__`szCookie.__init__cCs|jS)a�
        The UTC moment at which cookie was received for purposes of
        computing the expiration given a Max-Age offset. The
        expiration will be timestamp + max_age. The timestamp value
        will aways be a datetime object.

        By default the timestamp will be the moment the Cookie object
        is created as this often corresponds to the moment the cookie
        is received (the intent of the Max-Age attribute). But becuase
        it's sometimes desirable to force a specific moment for
        purposes of computing the expiration from the Max-Age the
        Cookie timestamp can be updated.

        Setting a value of None causes the timestamp to be set to the
        current UTC time (now). You may also assign with a numeric
        UNIX timestamp (seconds since the epoch UTC) or a formatted time
        sting, in all cases the value will be converted to a datetime
        object.
        )�
_timestamp�rAr
r
rr>lszCookie.timestampcCsn|durd|_nZt|tj�r$||_nFt|ttf�rBt|dd�|_n(t|t�rZt�|�|_nt	d|j
j��dS)Nr"�Zunits�Dvalue must be datetime, int, long, float, basestring or None, not %s)rC�
isinstance�datetime�int�floatr�strrr �	TypeError�	__class__r�rAr<r
r
rr>�s
�cCs|jS)aH
        The expiration timestamp (in UTC) as a datetime object for the
        cookie, or None if not set.

        You may assign a value of None, a datetime object, a numeric
        UNIX timestamp (seconds since the epoch UTC) or formatted time
        string (the latter two will be converted to a datetime object.
        )�_expiresrDr
r
rr�s
zCookie.expirescCs�|durd|_nxt|tj�rB||_|jjdur�|jjtjjd�nFt|ttf�r`t	|dd�|_n(t|t
�rxt�|�|_nt
d|jj��dS)N)�tzinfor"rErF)rOrGrHrP�replace�timezone�utcrIrJrrKrr rLrMrrNr
r
rr�s
�cCs|jS)zq
        The lifetime duration of the cookie. Computed as an offset
        from the cookie's timestamp.
        )�_max_agerDr
r
rr�szCookie.max_agecCsB|durd|_n.zt|�|_Wnty<td|��Yn0dS)Nz-Max-Age value '%s' not convertable to integer)rTrIrrrNr
r
rr�scCs6tj�|��d�}|dur&td|��t|||�dS)z?
        Sets one of the predefined cookie attributes.
        Nzunknown cookie attribute '%s')rr1�getr#r�setattr)rA�namer<Z	attr_namer
r
rZ
__set_attr�szCookie.__set_attrcCs�g}|�d|j|jf�|jdur4|�d|j�|jdurN|�d|j�|jdurh|�d|j�|jdur�|�dt�|j��|j	r�|�d�|j
r�|�d�d�|�S)	Nz%s=%sz	Domain=%szPath=%sz
Max-Age=%sz
Expires=%sZSecureZHttpOnlyz; )r3r;r<rrrrrrrr�join)rA�
componentsr
r
r�__str__�s





zCookie.__str__cCs2|jdur|jtj|jd�S|jdur.|jSdS)a/
        Return the effective expiration of the cookie as a datetime
        object or None if no expiration is defined. Expiration may be
        defined either by the "Expires" timestamp attribute or the
        "Max-Age" duration attribute. If both are set "Max-Age" takes
        precedence. If neither is set the cookie has no expiration and
        None will be returned.

        "Max-Age" specifies the number of seconds in the future from when the
        cookie is received until it expires. Effectively it means
        adding "Max-Age" seconds to a timestamp to arrive at an
        expiration. By default the timestamp used to mark the arrival
        of the cookie is set to the moment the cookie object is
        created. However sometimes it is desirable to adjust the
        received timestamp to something other than the moment of
        object creation, therefore you can explicitly set the arrival
        timestamp used in the "Max-Age" calculation.

        "Expires" specifies an explicit timestamp.

        If "Max-Age" is set a datetime object is returned which is the
        sum of the arrival timestamp and "Max-Age".

        If "Expires" is set a datetime object is returned matching the
        timestamp specified as the "Expires" value.

        If neither is set None is returned.
        N)Zseconds)rr>rHZ	timedeltarrDr
r
r�get_expiration�s


zCookie.get_expirationcCs|��|_d|_|jS)a
        An expiration may be specified either with an explicit
        timestamp in the "Expires" attribute or via an offset
        specified witht the "Max-Age" attribute. The "Max-Age"
        attribute has precedence over "Expires" if both are
        specified.

        This method normalizes the expiration of the cookie such that
        only a "Expires" attribute remains after consideration of the
        "Max-Age" attribute. This is useful when storing the cookie
        for future reference.
        N)r[rrrDr
r
r�normalize_expirations
zCookie.normalize_expirationcCsBt|�\}}}}}}|jdur(|��|_|jdur>|�|�|_dS)z�
        If cookie domain and path attributes are not specified then
        they assume defaults from the request url the cookie was
        received from.
        N)rrr#rr()rA�urlZ_schemerrZ_paramsZ_queryZ	_fragmentr
r
r�set_defaults_from_urls



zCookie.set_defaults_from_urlcCs|�|�|��dS)z�
        Missing cookie attributes will receive default values derived
        from the request URL. The expiration value is normalized.
        N)r^r\)rAr]r
r
rr2)s
zCookie.normalizecCsd|j|jfS)z�
        Return a string with just the key and value (no attributes).
        This is appropriate for including in a HTTP Cookie header.
        z%s=%s;)r;r<rDr
r
r�http_cookie2szCookie.http_cookiec
sdd�}�fdd�}�j}t|�\}}}}}	}
���}|durptjjtjjd�}||krpt�d|��	|�f��||�j
�s�t�d|�j
|f��||�j�s�t�d	|�j|f��|�
�}�jr�|d
vr�t�d||f���jr�|dvr�t�d
||f��dS)a�
        Tests to see if a cookie should be returned when a request is
        sent to a specific URL.

        * The request url's host must match the cookie's doman
          otherwise raises Cookie.URLMismatch.

        * The path in the request url must contain the cookie's path
          otherwise raises Cookie.URLMismatch.

        * If the cookie defines an expiration date then the current
          time must be less or equal to the cookie's expiration
          timestamp. Will raise Cookie.Expired if a defined expiration
          is not valid.

        If the test fails Cookie.Expired or Cookie.URLMismatch will be raised,
        otherwise True is returned.

        cSsrddlm}z||�Wnty,YdS0|dur:dS|��}|��}||krVdS|�|�rn|�d�rndSdS)z~
            Compute domain component and perform test per
            RFC 6265, Section 5.1.3. "Domain Matching"
            r)�validate_domain_nameFNT�.)Zipalib.utilr`rr#�endswithr$)�
url_domainZ
cookie_domainr`r
r
r�domain_validNs	

z+Cookie.http_return_ok.<locals>.domain_validcsh|durdS|��}��|�}||kr*dS|rd|�|�rd|�d�rFdS|t|�d�}|�d�rddSdS)z�
            Compute path component and perform test per
            RFC 6265, Section 5.1.4. "Paths and Path-Match"
            NTr!F)r#r(r$rb�len)r'Zcookie_pathZrequest_path�tailrDr
r�
path_validms


z)Cookie.http_return_ok.<locals>.path_validN)Ztzz!cookie named '%s'; expired at %s'zBcookie named '%s'; it's domain '%s' does not match URL domain '%s'zDcookie named '%s'; it's path '%s' does not contain the URL path '%s')�http�httpszDcookie named '%s'; is restricted to HTTP but it's URL scheme is '%s')rizPcookie named '%s'; is restricted to secure transport but it's URL scheme is '%s'T)r;rr[rH�nowrRrSrrrrr
rr#rr)
rAr]rdrgr?Z
url_schemercr'Z_url_paramsZ
_url_queryZ
_url_fragmentZcookie_expirationrjr
rDr�http_return_ok9sH���
�
���zCookie.http_return_ok)N)N)NN)NNNNNNN)"rrr	�__doc__rrr
�re�compiler,�
IGNORECASEr.r1�classmethodrrr r(r=r@rB�propertyr>�setterrrr4rZr[r\r^r2r_rkr
r
r
rrDs`7
�


!\��







		&	r)rmrHZemail.utilsrZcalendarr�urllib.parserZipapython.ipautilrrr
r
r
r�<module>s+