https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/web/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/web/__pycache__/session.cpython-310.pyc
o

�k�`-b�@s�ddlZddlmZmZmZmZddlmZmZm	Z	m
Z
mZddlm
Z
mZmZmZmZddlmZmZmZmZmZmZddlmZddlmZddlmZmZd	Z d
Z!dZ"Gdd
�d
e#�Z$Gdd�de$�Z%Gdd�de%�Z&Gdd�de�Z'ddd�Z(dS)�N)�AdminCommandError�IAdminCommandProvider�console_date_format�get_console_locale)�	Component�ExtensionPoint�	TracError�TracValueError�
implements)�as_bool�as_float�as_int�hex_entropy�lazy)�get_datetime_format_hint�format_date�
parse_date�time_now�to_datetime�to_timestamp)�print_table)�_)�IRequestHandler�is_valid_default_handler�Qi�v�trac_sessioncsTeZdZ�fdd�Z�fdd�Zddd�Zddd	�Zdd
d�Zd�fdd
�	Z�Z	S)�SessionDictcs(t�j|i|��d|_d|_d|_dS)NFr)�super�__init__�
authenticated�
last_visit�sid)�self�args�kwargs��	__class__��2/usr/lib/python3/dist-packages/trac/web/session.pyr/s
zSessionDict.__init__cst��|t|��dS�N)r�__setitem__�str)r"�key�valuer%r'r(r*5szSessionDict.__setitem__NcCs||vr|St|||�S)a�Return the value as a boolean. Return `default` if
        if an exception is raised while converting the value to a
        boolean.

        :param key: the name of the session attribute
        :keyword default: the value to return if the parameter is not
                          specified or an exception occurs converting
                          the value to a boolean.

        :since: 1.2
        )r)r"r,�defaultr'r'r(r8szSessionDict.as_boolcC�||vr|St|||||�S)aReturn the value as an integer. Return `default` if
        if an exception is raised while converting the value to an
        integer.

        :param key: the name of the session attribute
        :keyword default: the value to return if the parameter does
                          not exist or an exception occurs converting
                          the value to an integer.
        :keyword min: lower bound to which the value is limited
        :keyword max: upper bound to which the value is limited

        :since: 1.2
        )r
�r"r,r.�min�maxr'r'r(r
H�zSessionDict.as_intcCr/)aReturn the value as a float. Return `default` if
        if an exception is raised while converting the value to a
        float.

        :param key: the name of the session attribute
        :keyword default: the value to return if the parameter does
                          not exist or an exception occurs converting
                          the value to a float.
        :keyword min: lower bound to which the value is limited
        :keyword max: upper bound to which the value is limited

        :since: 1.3.6
        )rr0r'r'r(rZr3zSessionDict.as_floatcsBt|�}|durt|�}||kr|�|d�dSt��||�dS)z`Set a variable in the session, or remove it if it's equal to the
        default value.
        N)r+�poprr*)r"r,r-r.r%r'r(�setlszSessionDict.setr))NNN)
�__name__�
__module__�__qualname__rr*rr
rr5�
__classcell__r'r'r%r(r-s


rcs.eZdZ�fdd�Zddd�Zdd�Z�ZS)	�DetachedSessioncs6t���||_d|_i|_|r|j|dd�dSdS)NT�r)rr�env�_new�_old�get_session)r"r<r!r%r'r(r{s
�zDetachedSession.__init__Fc	Cs�|jj�d|�|jj�M}||_||_|��|d|t|�f�D]\}d|_t|p*d�|_	|�
|d|t|�f��|��|_nd|_	d|_i|_Wd�dSWd�dS1s\wYdS)NzRetrieving session for ID %rz~
                    SELECT last_visit FROM session
                    WHERE sid=%s AND authenticated=%s
                    Frz�
                    SELECT name, value FROM session_attribute
                    WHERE sid=%s and authenticated=%s
                    T)
r<�log�debug�db_queryr!r�clear�intr=r �update�copyr>)r"r!r�dbr r'r'r(r?�s*


�
�
�"�zDetachedSession.get_sessionc	s�t�j��tt��}t����}�s�js|sdSd}�jj��}�j}|rX|�_	d�_z|d�j
�j	�f�Wn �jjjyW�jj
�d�j
�|��YWd�dSw�rw|sr�j�d���d�ksr�j�d���d�krw�j���j�kr�|s��s�|d�j
f�|d�j
�f�t�����_z|�d��fd	d
�|D��Wn �jjjy��jj
�d�j
�|��YWd�dSwd}Wd�n1s�wY|�rO|�j	tk�rQ|�_	�jj}|d
kr�||dnd}�jj�+}�jj
�d�j
�|d�j	�j
�f�|�r�jj
�d�|d|f�Wd�n	1�s)wY|�rS�jj�}|d|f�Wd�dS1�sHwYdSdSdSdS)NFz{INSERT INTO session (sid, last_visit, authenticated)
                          VALUES (%s,%s,%s)
                          zSession %s already exists�name�email�4DELETE FROM session WHERE sid=%s AND authenticated=0zlDELETE FROM session_attribute
                      WHERE sid=%s AND authenticated=%s
                      z�
                        INSERT INTO session_attribute
                          (sid,authenticated,name,value)
                        VALUES (%s,%s,%s,%s)
                        csg|]\}}�j�||f�qSr'�r!)�.0�k�v�rr"r'r(�
<listcomp>�s�z(DetachedSession.save.<locals>.<listcomp>z)Attributes for session %s already updatedTrrzRefreshing session %szoUPDATE session SET last_visit=%s
                      WHERE sid=%s AND authenticated=%s
                      zPurging old, expired, sessions.aDELETE FROM session_attribute
                          WHERE authenticated=0 AND sid IN (
                              SELECT sid FROM session
                              WHERE authenticated=0 AND last_visit < %s
                          )
                          z�
                        DELETE FROM session
                        WHERE authenticated=0 AND last_visit < %s
                        )rDrr�list�itemsr>r<�db_transactionr=r r!�db_exc�IntegrityErrorr@�warning�rollback�get�invalidate_known_users_cache�dict�executemany�UPDATE_INTERVAL�anonymous_session_lifetime�inforA)r"�nowrR�
session_savedrG�new�lifetime�mintimer'rOr(�save�s�


���

����
��.��8
����
�$��zDetachedSession.save�F)r6r7r8rr?rdr9r'r'r%r(r:ys
r:csTeZdZdZ�fdd�Zefdd�Ze�d�Z	d�fdd	�	Z
d
d�Zdd
�Z�Z
S)�Sessionz/Basic session handling and per-session storage.cs�t��|d�||_|js*t|jvrtd�|_|��dS|jtj	}|�
|�dSt|jvr:|jtj	}|�|�|j
|jdd�dS)N�Tr;)
rr�req�is_authenticated�
COOKIE_KEY�incookierr!�bake_cookier-r?�promote_session�authname)r"r<rhr!r%r'r(rs



zSession.__init__cCsp|jsJd��|j|jjt<|jjpd|jjtd<||jjtd<|jjr.d|jjtd<d|jjtd<dS)NzSession ID not set�/�path�expiresT�secure�httponly)r!rh�	outcookierj�	base_pathr<�secure_cookies)r"rqr'r'r(rlszSession.bake_cookiez[_A-Za-z0-9]+\ZFcsxd}|s|j�|�sttd���|jr||jkrd}t��||�|jr.t�|jt	kr.d}|s8|r:|�
�dSdSdS)NF� Session ID must be alphanumeric.T)�
_valid_sid_re�matchr	rr!rr?r rr\rl)r"r!r�refresh_cookier%r'r(r?"s�zSession.get_sessioncCs�|jjrJd��|sJd��||jkrdS|j�|�s$ttd�td���|jj�3}|d|f�r:t	td|d�td���|jj
�d|j|�|d	||jf�|d
||jf�Wd�n1s^wY||_|��dS)Nz)Cannot change ID of authenticated sessionzSession ID cannot be emptyrwzError renaming sessionz$SELECT sid FROM session WHERE sid=%szFSession '%(id)s' already exists. Please choose a different session ID.)�idzChanging session ID %s to %sz:UPDATE session SET sid=%s WHERE sid=%s AND authenticated=0ziUPDATE session_attribute SET sid=%s
                  WHERE sid=%s and authenticated=0
                  )
rhrir!rxryr	rr<rSrr@rArl)r"�new_sidrGr'r'r(�
change_sid2s:
�
�
������
zSession.change_sidc	Cs6|jjsJd��|jj�z}dd�|d||jjf�D�}t|�dkr.|d|f�|d|f�nQt|�dkrV|d	sU|jj�d
||jj�|d|jj|f�|d|jj|f�n)z|d
|jjtt	��f�Wn|jj
jy~|jj�d|jj�|�
�YnwWd�n1s�wYd|_||_|�d	�dS)z�Promotes an anonymous session to an authenticated session, if there
        is no preexisting session data for that user name.
        z(Cannot promote session of anonymous usercSsg|]\}|�qSr'r')rLrr'r'r(rPSsz+Session.promote_session.<locals>.<listcomp>z8SELECT authenticated FROM session WHERE sid=%s OR sid=%s�rJzkDELETE FROM session_attribute
                      WHERE sid=%s AND authenticated=0
                      �rzCPromoting anonymous session %s to authenticated session for user %sz�UPDATE session SET sid=%s, authenticated=1
                          WHERE sid=%s AND authenticated=0
                          zvUPDATE session_attribute SET sid=%s, authenticated=1
                          WHERE sid=%s
                          z|INSERT INTO session (sid, last_visit, authenticated)
                          VALUES (%s, %s, 1)
                          z+Authenticated session for %s already existsNF)rhrir<rSrn�lenr@rArDrrTrUrVrWr=r!rl)r"r!rG�authenticated_flagsr'r'r(rmKsT
�

���
�
�
���
����&zSession.promote_sessionre)r6r7r8�__doc__r�	PURGE_AGErl�re�compilerxr?r}rmr9r'r'r%r(rfs
	rfc@s�eZdZdZee�ee�Zdd�Z	e
dd��Zdd�Zdd	�Z
d
d�Zdd
�Zdd�Zdd�Zdd�Zddd�Zdd�Zdd�Zdd�ZdS)�SessionAdminz2trac-admin command provider for session managementccs��tt|j��td�d�}ddd|j|jfVdddd|jfVd	d
d|j|jfVdd
d|j|j	fVddd|d|j
fVdS)N�iso8601)�datetimer�zsession listz[sid[:0|1]] [...]a�List the name and email for the given sids

               Specifying the sid 'anonymous' lists all unauthenticated
               sessions, and 'authenticated' all authenticated sessions.
               '*' lists all sessions, and is the default if no sids are
               given.

               An sid suffix ':0' operates on an unauthenticated session with
               the given sid, and a suffix ':1' on an authenticated session
               (the default).zsession addz<sid[:0|1]> [name] [email]a3Create a session for the given sid

               Populates the name and email attributes for the given session.
               Adding a suffix ':0' to the sid makes the session
               unauthenticated, and a suffix ':1' makes it authenticated (the
               default if no suffix is specified).zsession setz0<name|email|default_handler> <sid[:0|1]> <value>z�Set the name or email attribute of the given sid

               An sid suffix ':0' operates on an unauthenticated session with
               the given sid, and a suffix ':1' on an authenticated session
               (the default).zsession deletez<sid[:0|1]> [...]a2Delete the session of the specified sid

               An sid suffix ':0' operates on an unauthenticated session with
               the given sid, and a suffix ':1' on an authenticated session
               (the default). Specifying the sid 'anonymous' will delete all
               anonymous sessions.z
session purgez<age>z�Purge anonymous sessions older than given age or date

               Age may be specified as a relative time like "90 days ago", or
               as a date in the "%(datetime)s" or "%(iso8601)s" (ISO 8601)
               format.)rrr<�_complete_list�_do_list�_do_add�
_complete_set�_do_set�_complete_delete�
_do_delete�	_do_purge)r"�hintsr'r'r(�get_admin_commands�s4��
�
�	�	�	�
�zSessionAdmin.get_admin_commandscCstdd�|jD��S)Ncss �|]}t|�r|jjVqdSr))rr&r6)rL�handlerr'r'r(�	<genexpr>�s
��z7SessionAdmin._valid_default_handlers.<locals>.<genexpr>)�sorted�request_handlers�r"r'r'r(�_valid_default_handlers�s�z$SessionAdmin._valid_default_handlerscCs<|�d�r
|dd�dfS|�d�r|dd�dfS|dfS)Nz:0���rz:1r)�endswith)r"r!r'r'r(�
_split_sid�s


zSessionAdmin._split_sidcCs|j�d�}dd�|D�S)Nz&SELECT sid, authenticated FROM sessioncSsg|]
\}}d||f�qS)z%s:%dr')rLr!�authr'r'r(rP�sz*SessionAdmin._get_sids.<locals>.<listcomp>)r<rB)r"�rowsr'r'r(�	_get_sids�szSessionAdmin._get_sidsc#s��d|vpd|v}d|vpd|v}�fdd�|D�}�j�d�}|D]$\}}}}}	}
|r.|r8|r2|s8||f|vrF||tt|�t�||	|
fVq"dS)N�	anonymous�*rcsh|]}|dvr��|��qS))r�rr�)r�)rLr!r�r'r(�	<setcomp>�s
�z)SessionAdmin._get_list.<locals>.<setcomp>a�
            SELECT DISTINCT s.sid, s.authenticated, s.last_visit,
                            n.value, e.value, h.value
            FROM session AS s
              LEFT JOIN session_attribute AS n
                ON (n.sid=s.sid AND n.authenticated=s.authenticated
                    AND n.name='name')
              LEFT JOIN session_attribute AS e
                ON (e.sid=s.sid AND e.authenticated=s.authenticated
                    AND e.name='email')
              LEFT JOIN session_attribute AS h
                ON (h.sid=s.sid AND h.authenticated=s.authenticated
                    AND h.name='default_handler')
            ORDER BY s.sid, s.authenticated
            )r<rBrrr)r"�sids�all_anon�all_authr�r!rr rHrIr�r'r�r(�	_get_list�s$�
�����zSessionAdmin._get_listcCs |��gd�}t|�t|�S)N)r�r�r�r�r5�r"r#�all_sidsr'r'r(r��szSessionAdmin._complete_listcCs,t|�dkr
ddgSt|�dkr|��SdS)NrrHrIr~)r�r�)r"r#r'r'r(r��s
�zSessionAdmin._complete_setcCs|��dg}t|�t|�S)Nr�r�r�r'r'r(r��szSessionAdmin._complete_deletecGsF|sdg}td�td�td�td�td�td�f}t|�|�|�dS)Nr��SID�Authz
Last Visit�Name�EmailzDefault Handler)rrr�)r"r��headersr'r'r(r��s�zSessionAdmin._do_listNc	Cs�|�|�\}}|jj�9}z
|d||tt��f�Wnty(ttd|d���w|r3|d|||f�|r=|d|||f�Wd�n1sGwY|j��dS)Nz'INSERT INTO session VALUES (%s, %s, %s)z Session '%(sid)s' already existsrKz6INSERT INTO session_attribute VALUES (%s,%s,'name',%s)z7INSERT INTO session_attribute VALUES (%s,%s,'email',%s))	r�r<rSrDr�	ExceptionrrrY)r"r!rHrIrrGr'r'r(r��s,
�������
zSessionAdmin._do_addcCs�|dvrttd|d���|dkr|r||jvrttd|d���|�|�\}}|jj�*}|d||f�s:ttd|d	���|d
|||f�|rM|d||||f�Wd�n1sWwY|j��dS)N)rHrI�default_handlerzInvalid attribute '%(attr)s')�attrr�z!Invalid default_handler '%(val)s')�valzRSELECT sid FROM session
                         WHERE sid=%s AND authenticated=%szSession '%(sid)s' not foundrKz}
                DELETE FROM session_attribute
                WHERE sid=%s AND authenticated=%s AND name=%s
                z5INSERT INTO session_attribute VALUES (%s, %s, %s, %s))rrr�r�r<rSrY)r"r�r!r�rrGr'r'r(r�s6��
���
���
zSessionAdmin._do_setcGs�|jj�/}|D]$}|�|�\}}|dkr|d�|d�q|d||f�|d||f�qWd�n1s6wY|j��dS)Nr�z)DELETE FROM session WHERE authenticated=0z3DELETE FROM session_attribute WHERE authenticated=0z
                        DELETE FROM session
                        WHERE sid=%s AND authenticated=%s
                        z�
                        DELETE FROM session_attribute
                        WHERE sid=%s AND authenticated=%s
                        )r<rSr�rY)r"r�rGr!rr'r'r(r�'s

����zSessionAdmin._do_deletecCs^t|dt|j�d�}|jj�}t|�}|d|f�|d�Wd�dS1s(wYdS)Nr�)�hint�localezm
                DELETE FROM session
                WHERE authenticated=0 AND last_visit<%s
                a+
                DELETE FROM session_attribute
                WHERE authenticated=0
                      AND NOT EXISTS (SELECT * FROM session AS s
                                      WHERE s.sid=session_attribute.sid
                                      AND s.authenticated=0)
                )rrr<rSr)r"�age�whenrG�tsr'r'r(r�9s�
�
"�zSessionAdmin._do_purge)NN)r6r7r8r�r
rrrr�r�rr�r�r�r�r�r�r�r�r�r�r�r�r'r'r'r(r�~s$5

r�cCs.|�d||rdnd|f�D]}|dS|S)Nzw
            SELECT value FROM session_attribute
            WHERE sid=%s AND authenticated=%s AND name=%s
            rr)rB)r<r!rrHr.�rowr'r'r(�get_session_attributeKs
�r�r)))r��trac.admin.apirrrr�	trac.corerrrr	r
�	trac.utilrrr
rr�trac.util.datefmtrrrrrr�trac.util.textr�trac.util.translationr�trac.web.apirrr\r�rjrZrr:rfr�r�r'r'r'r(�<module>s$ 	LzN

https://t.me/RX1948 - 2025