HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/lazr/restfulclient/authorize/__pycache__/oauth.cpython-38.pyc
U

�"�[|&�@s�dZzddlmZWn ek
r4ddlmZYnXddlZddlZddlZddlZddl	m
Z
ddlZddlm
Z
ddlmZeZdd	d
dgZdZGd
d	�d	�ZGdd�d�ZGdd�dej�ZGdd�de�ZGdd
�d
e
�ZdS)z.OAuth classes for use with lazr.restfulclient.�)�ConfigParser)�SafeConfigParserN)�oauth1)�HttpAuthorizer)�CredentialsFileError�AccessToken�Consumer�OAuthAuthorizer�SystemWideConsumer�1c@seZdZdZddd�ZdS)rz An OAuth consumer (application).�NcCs||_||_||_dS)anInitialize

        :param key: The OAuth consumer key
        :param secret: The OAuth consumer secret. Don't use this. It's
            a misfeature, and lazr.restful doesn't expect it.
        :param application_name: An application name, if different
            from the consumer key. If present, this will be used in
            the User-Agent header.
        N)�key�secret�application_name)�selfr
rr�r�D/usr/lib/python3/dist-packages/lazr/restfulclient/authorize/oauth.py�__init__7s
zConsumer.__init__)rN��__name__�
__module__�__qualname__�__doc__rrrrrr4sc@seZdZdZddd�ZdS)rzAn OAuth access token.rNcCs||_||_||_dS�N)r
r�context)rr
rrrrrrIszAccessToken.__init__)rNrrrrrrFsc@seZdZdZdd�ZeZdS)�TruthyStringz&A Unicode string which is always true.cCsdS)NTr)rrrr�__bool__RszTruthyString.__bool__N)rrrrrZ__nonzero__rrrrrOsrcs2eZdZdZdZd�fdd�	Zedd��Z�ZS)	r
z�A consumer associated with the logged-in user rather than an app.

    This can be used to share a single OAuth token among multiple
    desktop applications. The OAuth consumer key will be derived from
    system information (platform and hostname).
    zSystem-wide: %s (%s)rcstt|��|j||�dS)a	Constructor.

        :param application_name: An application name. This will be
            used in the User-Agent header.
        :param secret: The OAuth consumer secret. Don't use this. It's
            a misfeature, and lazr.restful doesn't expect it.
        N)�superr
r�consumer_key)rrr��	__class__rrras

�zSystemWideConsumer.__init__cCsPzddl}|��}Wntk
r,d}YnX|dkr>t��}|j|t��fS)z�The system-wide OAuth consumer key for this computer.

        This key identifies the platform and the computer's
        hostname. It does not identify the active user.
        rNr)�distro�name�	Exception�platform�system�
KEY_FORMAT�socketZgethostname)rr!Zdistnamerrrrls
zSystemWideConsumer.consumer_key)r)	rrrrr&r�propertyr�
__classcell__rrrrr
Xs
c@sReZdZdZddd�Zedd��Zd	d
�Zedd��Z	d
d�Z
dd�Zdd�ZdS)r	zBA client that signs every outgoing request with OAuth credentials.Nr�OAuthcCs,d|_|dk	rt|||�|_||_||_dSr)�consumerr�access_token�oauth_realm)rZ
consumer_name�consumer_secretr,r-rrrrr�s�zOAuthAuthorizer.__init__cCs:i}|jdkr|S|jj|d<|jjdk	r6|jj|d<|S)zoAny information necessary to identify this user agent.

        In this case, the OAuth consumer name.
        NZoauth_consumerZapplication)r+r
r)rZparamsrrr�user_agent_params�s
z!OAuthAuthorizer.user_agent_paramscCs~t�}t|d|j�}||�|�t�s2tdt��|�td�}|�td�}t||�|_|�td�}|�td�}t	||�|_
dS)akLoad credentials from a file-like object.

        This overrides the consumer and access token given in the constructor
        and replaces them with the values read from the file.

        :param readable_file: A file-like object to read the credentials from
        :type readable_file: Any object supporting the file-like `read()`
            method
        Z	read_filezNo configuration for version %srr.r,�
access_secretN)r�getattrZreadfpZhas_section�CREDENTIALS_FILE_VERSIONr�getrr+rr,)rZ
readable_file�parser�readerrr.r,r0rrr�load�s2
�����zOAuthAuthorizer.loadcCs&|�}t|d�}|�|�|��|S)a�Convenience method for loading credentials from a file.

        Open the file, create the Credentials and load from the file,
        and finally close the file and return the newly created
        Credentials instance.

        :param path: In which file the credential file should be saved.
        :type path: string
        :return: The loaded Credentials instance.
        :rtype: `Credentials`
        �r)�openr6�close)�cls�pathZcredentials�credentials_filerrr�load_from_path�s



zOAuthAuthorizer.load_from_pathcCs�|jdkrtd��|jdkr$td��t�}|�t�|�td|jj�|�td|jj�|�td|jj�|�td|jj�|�	|�dS)aHWrite the credentials to the file-like object.

        :param writable_file: A file-like object to write the credentials to
        :type writable_file: Any object supporting the file-like `write()`
            method
        :raise CredentialsFileError: when there is either no consumer or no
            access token
        NzNo consumerzNo access tokenrr.r,r0)
r+rr,rZadd_sectionr2�setr
r�write)rZ
writable_filer4rrr�save�s.	


����zOAuthAuthorizer.savecCsBt�t�|tjtjBtjBtjtjB�d�}|�	|�|�
�dS)aTConvenience method for saving credentials to a file.

        Create the file, call self.save(), and close the
        file. Existing files are overwritten. The resulting file will
        be readable and writable only by the user.

        :param path: In which file the credential file should be saved.
        :type path: string
        �wN)�os�fdopenr8�O_CREAT�O_TRUNC�O_WRONLY�stat�S_IREAD�S_IWRITEr@r9)rr;r<rrr�save_to_path�s

��
zOAuthAuthorizer.save_to_pathc
Cs�tj|jj|jjt|jjpd�|jjtj|jd�}t|j	�|_	|�
|�\}}}|��D]*\}}	tj
rx|�d�}|	�d�}	|	||<qVdS)z&Sign a request with OAuth credentials.r)Z
client_secret�resource_owner_keyZresource_owner_secretZsignature_methodZrealmzUTF-8N)rZClientr+r
rrr,ZSIGNATURE_PLAINTEXTr-rKZsign�items�sixZPY2�encode)
rZabsolute_uri�methodZbodyZheadersZclient�_Zsigned_headersr
�valuerrr�authorizeRequest�s�

z OAuthAuthorizer.authorizeRequest)NrNr*N)
rrrrrr(r/r6�classmethodr=r@rJrRrrrrr	s�




)r�configparserrr�ImportErrorrBr$rGr'ZoauthlibrrMZlazr.restfulclient.authorizerZlazr.restfulclient.errorsr�typeZ
__metaclass__�__all__r2rrZ	text_typerr
r	rrrr�<module>s0�		'