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: //proc/self/root/usr/lib/python3/dist-packages/launchpadlib/__pycache__/credentials.cpython-38.pyc
U

�v�^Hx�@s�ddlmZeZdddddddgZzdd	lmZWn ek
rRdd	lmZYnXdd
l	Z	dd
l
Z
ddlmZdd
lZddl
mZdd
lZzdd
lmZWn ek
r�dd
lmZYnXzddlmZWn ek
r�ddlmZYnXdd
lZddlmZmZzdd
lZWnek
�r2dd
lZYnXddlmZeek�rPeZ neZ ddl!m"Z"ddl#m$Z%m&Z&m'Z'm(Z(ddl)m*Z*dZ+dZ,dZ-dZ.dZ/e0e1e2fZ3dd�Z4dd�Z5Gdd�de'�Z6Gdd�de%�Z$Gdd�de%�Z7Gd d�de8�Z9Gd!d"�d"e9�Z:Gd#d$�d$e9�Z;Gd%d&�d&e9�Z<Gd'd�de8�Z=Gd(d)�d)e=�Z>Gd*d�de>�Z?Gd+d,�d,e@�ZAGd-d.�d.eA�ZBGd/d0�d0eA�ZCGd1d2�d2eC�ZDGd3d4�d4eC�ZEGd5d6�d6eE�ZFGd7d8�d8eA�ZGGd9d:�d:eA�ZHGd;d<�d<eA�ZIGd=d>�d>eA�ZJd
S)?�)�print_function�AccessToken�AnonymousAccessToken� AuthorizeRequestTokenWithBrowser�CredentialStore�RequestTokenAuthorizationEngine�Consumer�Credentials)�StringION)�select)�stdin)�	urlencode)�urljoin)�	b64decode�	b64encode)�parse_qs)�	HTTPError)rr�OAuthAuthorizer�SystemWideConsumer)�urisz+request-tokenz
+access-tokenz+authorize-token�i�cCsttj�dd��S)z�Whether the user has disabled SSL certificate connection.

    Some testing servers have broken certificates.  Rather than raising an
    error, we allow an environment variable,
    ``LP_DISABLE_SSL_CERTIFICATE_VALIDATION`` to disable the check.
    Z%LP_DISABLE_SSL_CERTIFICATE_VALIDATIONF)�bool�os�environ�get�rr�:/usr/lib/python3/dist-packages/launchpadlib/credentials.py�$_ssl_certificate_validation_disabledYs
�rcCsDt�}tj|d�j|d|t|�d�\}}|jdkr<t||��||fS)z�POST to ``url`` with ``headers`` and a body of urlencoded ``params``.

    Wraps it up to make sure we avoid the SSL certificate validation if our
    environment tells us to.  Also, raises an error on non-200 statuses.
    )Z"disable_ssl_certificate_validationZPOST)�method�headersZbody��)r�httplib2ZHttpZrequestr
�statusr)�urlr�paramsZ
cert_disabled�response�contentrrr�
_http_postgs��


r'c@sXeZdZdZdZdZdZdZdZdd�Z	e
d	d
��Zdej
efdd�Zej
fd
d�ZdS)r	z�Standard credentials storage and usage class.

    :ivar consumer: The consumer (application)
    :type consumer: `Consumer`
    :ivar access_token: Access information on behalf of the user
    :type access_token: `AccessToken`
    NZuri�dictz<BR>�
cCs0t�}|�|�|��}t|t�r,|�d�}|S)zeTurn this object into a string.

        This should probably be moved into OAuthAuthorizer.
        �utf-8)r
�save�getvalue�
isinstance�unicode_type�encode)�selfZsio�
serializedrrr�	serialize�s


zCredentials.serializecCs,|�}t|t�s|�d�}|�t|��|S)z}Create a `Credentials` object from a serialized string.

        This should probably be moved into OAuthAuthorizer.
        r*)r-r.�decode�loadr
)�cls�value�credentialsrrr�from_string�s


zCredentials.from_stringc	Cs�|jdk	std��|jdks$td��t�|�}t|jjddd�}|t}d|i}||jkrbd|d	<t	|||�\}}t
|t�r�|�d
�}||jkr�t
�|�}|dk	r�||d<t�|�|_|St�|�|_d|t|jjf}|dk	r�||j_|d
|7}|SdS)a�Request an OAuth token to Launchpad.

        Also store the token in self._request_token.

        This method must not be called on an object with no consumer
        specified or if an access token has already been obtained.

        :param context: The context of this token, that is, its scope of
            validity within Launchpad.
        :param web_root: The URL of the website on which the token
            should be requested.
        :token_format: How the token should be
            presented. URI_TOKEN_FORMAT means just return the URL to
            the page that authorizes the token.  DICT_TOKEN_FORMAT
            means return a dictionary describing the token
            and the site's authentication policy.

        :return: If token_format is URI_TOKEN_FORMAT, the URL for the
            user to authorize the `AccessToken` provided by
            Launchpad. If token_format is DICT_TOKEN_FORMAT, a dict of
            information about the new access token.
        NzConsumer not specified.zAccess token already obtained.�	PLAINTEXT�&)�oauth_consumer_key�oauth_signature_method�oauth_signature�Refererzapplication/jsonZAcceptr*�
lp.contextz%s%s?oauth_token=%sz&lp.context=%s)�consumer�AssertionError�access_tokenr�lookup_web_rootr(�key�request_token_page�DICT_TOKEN_FORMATr'r-�bytesr3�json�loadsr�from_params�_request_tokenr8�authorize_token_page�context)	r0rM�web_root�token_formatr$r#rr%r&rrr�get_request_token�s:
�




�zCredentials.get_request_tokencCsl|jdk	std��t�|�}t|jjd|jjd|jjd�}|t}d|i}t	|||�\}}t
�|�|_dS)adExchange the previously obtained request token for an access token.

        This method must not be called unless get_request_token() has been
        called and completed successfully.

        The access token will be stored as self.access_token.

        :param web_root: The base URL of the website that granted the
            request token.
        Nz5get_request_token() doesn't seem to have been called.r9z&%s)r;r<�oauth_tokenr=r>)
rKrArrCr(r@rD�secret�access_token_pager'rr8rB)r0rNr$r#rr%r&rrr�'exchange_request_token_for_access_token�s�

�z3Credentials.exchange_request_token_for_access_token)�__name__�
__module__�__qualname__�__doc__rKZURI_TOKEN_FORMATrFZITEM_SEPARATOR�NEWLINEr2�classmethodr8rZSTAGING_WEB_ROOTrPrTrrrrr	vs
�
6�c@s(eZdZdZedd��Zedd��ZdS)rzAn OAuth access token.cCs&|d}|d}|�d�}||||�S)z:Create and return a new `AccessToken` from the given dict.rQ�oauth_token_secretr?)r)r5r$rDrRrMrrrrJ�s
zAccessToken.from_paramscCs�t|t�s|�d�}t|dd�}|d}t|�dks<td��|d}|d}t|�dks`td	��|d}|�d
�}|dk	r�t|�dks�td��|d}||||�S)
z<Create and return a new `AccessToken` from the given string.r*F)Zkeep_blank_valuesrQrz/Query string must have exactly one oauth_token.rr[z*Query string must have exactly one secret.r?Nz*Query string must have exactly one context)r-r.r3r�lenrAr)r5Zquery_stringr$rDrRrMrrrr8�s$

�
�zAccessToken.from_stringN)rUrVrWrXrZrJr8rrrrr�s

cs eZdZdZ�fdd�Z�ZS)rzoAn OAuth access token that doesn't authenticate anybody.

    This token can be used for anonymous access.
    cstt|��dd�dS)N�)�superr�__init__�r0��	__class__rrr_szAnonymousAccessToken.__init__)rUrVrWrXr_�
__classcell__rrrarrsc@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)rz�Store OAuth credentials locally.

    This is a generic superclass. To implement a specific way of
    storing credentials locally you'll need to subclass this class,
    and implement `do_save` and `do_load`.
    NcCs
||_dS)aConstructor.

        :param credential_save_failed: A callback to be invoked if the
            save to local storage fails. You should never invoke this
            callback yourself! Instead, you should raise an exception
            from do_save().
        N)�credential_save_failed�r0rdrrrr_szCredentialStore.__init__c
Csbz|�||�WnLtk
r&�Yn8tk
r\}z|jdkrD|�|��W5d}~XYnX|S)z�Save the credentials and invoke the callback on failure.

        Do not override this method when subclassing. Override
        do_save() instead.
        N)�do_save�EXPLOSIVE_ERRORS�	Exceptionrd)r0r7�unique_consumer_id�errrr+'s
zCredentialStore.savecCs
t��dS)z�Store newly-authorized credentials locally for later use.

        :param credentials: A Credentials object to save.
        :param unique_consumer_id: A string uniquely identifying an
            OAuth consumer on a Launchpad instance.
        N��NotImplementedError)r0r7rirrrrf7szCredentialStore.do_savecCs
|�|�S)a0Retrieve credentials from a local store.

        This method is the inverse of `save`.

        There's no special behavior in this method--it just calls
        `do_load`. There _is_ special behavior in `save`, and this
        way, developers can remember to implement `do_save` and
        `do_load`, not `do_save` and `load`.

        :param unique_key: A string uniquely identifying an OAuth consumer
            on a Launchpad instance.

        :return: A `Credentials` object if one is found in the local
            store, and None otherise.
        )�do_load�r0�
unique_keyrrrr4@szCredentialStore.loadcCs
t��dS)a@Retrieve credentials from a local store.

        This method is the inverse of `do_save`.

        :param unique_key: A string uniquely identifying an OAuth consumer
            on a Launchpad instance.

        :return: A `Credentials` object if one is found in the local
            store, and None otherise.
        NrkrnrrrrmRszCredentialStore.do_load)N)	rUrVrWrXr_r+rfr4rmrrrrrs

	csBeZdZdZdZd
�fdd�	Zedd��Zd	d
�Zdd�Z	�Z
S)�KeyringCredentialStorez�Store credentials in the GNOME keyring or KDE wallet.

    This is a good solution for desktop applications and interactive
    scripts. It doesn't work for non-interactive scripts, or for
    integrating third-party websites into Launchpad.
    s<B64>NFcs(tt|��|�d|_|r$t|�|_dS�N)r^rpr_�	_fallback�MemoryCredentialStore)r0rdZfallbackrarrr_jszKeyringCredentialStore.__init__cCsJdt�krddladt�krFzddlmaWntk
rDtaYnXdS)aGEnsure the keyring module is imported (postponing side effects).

        The keyring module initializes the environment-dependent backend at
        import time (nasty).  We want to avoid that initialization because it
        may do things like prompt the user to unlock their password store
        (e.g., KWallet).
        �keyringrN�NoKeyringError)ru)�globalsrtZkeyring.errorsru�ImportError�RuntimeErrorrrrr�_ensure_keyring_importedps	

z/KeyringCredentialStore._ensure_keyring_importedc
Cs�|��|��}|jt|�}zt�d||�d��WnPtk
r�}z2ttkr^dt	|�kr^�|j
rt|j
�||�n�W5d}~XYnXdS)z2Store newly-authorized credentials in the keyring.�launchpadlibr*�$No recommended backend was availableN)ryr2�	B64MARKERrrtZset_passwordr3rurx�strrrr+)r0r7ror1rjrrrrf�s"�
�zKeyringCredentialStore.do_savec
Cs�|��zt�d|�}WnTtk
rl}z6ttkr@dt|�kr@�|jrZ|j�|�WY�S�W5d}~XYnX|dk	r�t|t	�r�|�
d�}|�|j�r�zt
|t|j�d��}Wntk
r�YdSXzt�|�}|WSYdSXdS)z&Retrieve credentials from the keyring.rzr{N�utf8)ryrtZget_passwordrurxr}rrr4r-r.r/�
startswithr|rr\�	TypeErrorr	r8)r0roZcredential_stringrjr7rrrrm�s<�
�

�
zKeyringCredentialStore.do_load)NF)rUrVrWrXr|r_�staticmethodryrfrmrcrrrarrp`s
rpcs2eZdZdZd	�fdd�	Zdd�Zdd�Z�ZS)
�UnencryptedFileCredentialStorez�Store credentials unencrypted in a file on disk.

    This is a good solution for scripts that need to run without any
    user interaction.
    Ncstt|��|�||_dSrq)r^r�r_�filename)r0r�rdrarrr_�s
�z'UnencryptedFileCredentialStore.__init__cCs|�|j�dS)zSave the credentials to disk.N)Zsave_to_pathr��r0r7rorrrrf�sz&UnencryptedFileCredentialStore.do_savecCs4tj�|j�r0t�|j�tjdks0t�|j�SdS)zLoad the credentials from disk.rN)r�path�existsr��stat�ST_SIZEr	Zload_from_pathrnrrrrm�s
�z&UnencryptedFileCredentialStore.do_load)N�rUrVrWrXr_rfrmrcrrrarr��sr�cs2eZdZdZd	�fdd�	Zdd�Zdd�Z�ZS)
rsz�CredentialStore that stores keys only in memory.

    This can be used to provide a CredentialStore instance without
    actually saving any key to persistent storage.
    Ncstt|��|�i|_dSrq)r^rsr_�_credentialsrerarrr_�szMemoryCredentialStore.__init__cCs||j|<dS)z!Store the credentials in our dictN)r�r�rrrrf�szMemoryCredentialStore.do_savecCs|j�|�S)z&Retrieve the credentials from our dict)r�rrnrrrrm�szMemoryCredentialStore.do_load)Nr�rrrarrs�srsc@sJeZdZdZdZddd�Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�ZdS)ra/The superclass of all request token authorizers.

    This base class does not implement request token authorization,
    since that varies depending on how you want the end-user to
    authorize a request token. You'll need to subclass this class and
    implement `make_end_user_authorize_token`.
    ZUNAUTHORIZEDNcCs�t�|�|_t�|�|_|dkr0|dkr0td��|dk	rP|dk	rPtd||f��|dkrhdg}t|�}nt|�}|}||_||_	|p�g|_
dS)aDBase class initialization.

        :param service_root: The root of the Launchpad instance being
            used.

        :param application_name: The name of the application that
            wants to use launchpadlib. This is used in conjunction
            with a desktop-wide integration.

            If you specify this argument, your values for
            consumer_name and allow_access_levels are ignored.

        :param consumer_name: The OAuth consumer name, for an
            application that wants its own point of integration into
            Launchpad. In almost all cases, you want to specify
            application_name instead and do a desktop-wide
            integration. The exception is when you're integrating a
            third-party website into Launchpad.

        :param allow_access_levels: A list of the Launchpad access
            levels to present to the user. ('READ_PUBLIC' and so on.)
            Your value for this argument will be ignored during a
            desktop-wide integration.
        :type allow_access_levels: A list of strings.
        Nz:You must provide either application_name or consumer_name.zZYou must provide only one of application_name and consumer_name. (You provided %r and %r.)ZDESKTOP_INTEGRATION)rZlookup_service_root�service_rootZweb_root_for_service_rootrN�
ValueErrorrrr@�application_name�allow_access_levels)r0r�r��
consumer_namer�r@rrrr_�s,����
z(RequestTokenAuthorizationEngine.__init__cCs|jjd|jS)z7Return a string identifying this consumer on this host.�@)r@rDr�r`rrrri.sz2RequestTokenAuthorizationEngine.unique_consumer_idcCs>dt|f}d}t|j�dkr2|||�|j�7}t|j|�S)z�Return the authorization URL for a request token.

        This is the URL the end-user must visit to authorize the
        token. How exactly does this happen? That depends on the
        subclass implementation.
        z%s?oauth_token=%sz&allow_permission=r)rLr\r��joinrrN)r0�
request_tokenZpageZallow_permissionrrr�authorization_url3s
��z1RequestTokenAuthorizationEngine.authorization_urlcCs6|�|�}|�||�|jdkr$dS|�||j�|S)adAuthorize a token and associate it with the given credentials.

        If the credential store runs into a problem storing the
        credential locally, the `credential_save_failed` callback will
        be invoked. The callback will not be invoked if there's a
        problem authorizing the credentials.

        :param credentials: A `Credentials` object. If the end-user
            authorizes these credentials, this object will have its
            .access_token property set.

        :param credential_store: A `CredentialStore` object. If the
            end-user authorizes the credentials, they will be
            persisted locally using this object.

        :return: If the credentials are successfully authorized, the
            return value is the `Credentials` object originally passed
            in. Otherwise the return value is None.
        N)rP�make_end_user_authorize_tokenrBr+ri)r0r7Zcredential_storeZrequest_token_stringrrr�__call__Bs

z(RequestTokenAuthorizationEngine.__call__cCs|j|jtjd�}|dS)z\Get a new request token from the server.

        :param return: The request token.
        )rNrOrQ)rPrNr	rF)r0r7Zauthorization_jsonrrrrP`s
�z1RequestTokenAuthorizationEngine.get_request_tokencCs
t��dS)a5Authorize the given request token using the given credentials.

        Your subclass must implement this method: it has no default
        implementation.

        Because an access token may expire or be revoked in the middle
        of a session, this method may be called at arbitrary points in
        a launchpadlib session, or even multiple times during a single
        session (with a different request token each time).

        In most cases, however, this method will be called at the
        beginning of a launchpadlib session, or not at all.
        Nrk)r0r7r�rrrr�jsz=RequestTokenAuthorizationEngine.make_end_user_authorize_token)NNN)rUrVrWrXZUNAUTHORIZED_ACCESS_LEVELr_�propertyrir�r�rPr�rrrrr�s�
9

c@s@eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�AuthorizeRequestTokenWithURLz�Authorize using a URL.

    This authorizer simply shows the URL for the user to open for
    authorization, and waits until the server responds.
    z�Please open this authorization page:
 (%s)
in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.z.Press Enter after authorizing in your browser.cCst|�dS)z�Display a message.

        By default, prints the message to standard output. The message
        does not require any user interaction--it's solely
        informative.
        N)�print)r0�messagerrr�output�sz#AuthorizeRequestTokenWithURL.outputcCs|�|j|�dS)�Notify the end-user of the URL.N)r��WAITING_FOR_USER)r0r�rrr�!notify_end_user_authorization_url�sz>AuthorizeRequestTokenWithURL.notify_end_user_authorization_urlc
Cs|z|�|j�Wn`tk
rp}zB|jjdkr:t|j��n&|jjdkrVtd�t|�t|j��W5d}~XYnX|j	dk	S)z Check if the end-user authorizedi�i�z#Unexpected response from Launchpad:N)
rTrNrr%r"�EndUserDeclinedAuthorizationr&r��EndUserNoAuthorizationrB)r0r7rjrrr�check_end_user_authorization�s�z9AuthorizeRequestTokenWithURL.check_end_user_authorizationcCs"|�|j�t��|�|�dS)�"Wait for the end-user to authorizeN)r��WAITING_FOR_LAUNCHPADr�readliner�)r0r7rrr�wait_for_end_user_authorization�sz<AuthorizeRequestTokenWithURL.wait_for_end_user_authorizationcCs"|�|�}|�|�|�|�dS)z2Have the end-user authorize the token using a URL.N)r�r�r�)r0r7r�r�rrrr��s

z:AuthorizeRequestTokenWithURL.make_end_user_authorize_tokenN)rUrVrWrXr�r�r�r�r�r�r�rrrrr�{s��	r�csJeZdZdZdZdZdZdZdZd�fdd	�	Z	�fd
d�Z
dd
�Z�ZS)raSAuthorize using a URL that pops-up automatically in a browser.

    This authorizer simply opens up the end-user's web browser to a
    Launchpad URL and lets the end-user authorize the request token
    themselves.

    This is the same as its superclass, except this class also
    performs the browser automatic opening of the URL.
    z�The authorization page:
 (%s)
should be opening in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.z/Press Enter to continue or wait (%d) seconds...�)zwww-browserZlinksZlinks2ZlynxZelinkszelinks-liteZnetrikZw3mz5Waiting to hear from Launchpad about your decision...Ncstt|��||d|�dS)aoConstructor.

        :param service_root: See `RequestTokenAuthorizationEngine`.
        :param application_name: See `RequestTokenAuthorizationEngine`.
        :param consumer_name: The value of this argument is
            ignored. If we have the capability to open the end-user's
            web browser, we must be running on the end-user's computer,
            so we should do a full desktop integration.
        :param credential_save_failed: See `RequestTokenAuthorizationEngine`.
        :param allow_access_levels: The value of this argument is
            ignored, for the same reason as consumer_name.
        N)r^rr_)r0r�r�r�rdr�rarrr_�s
�z)AuthorizeRequestTokenWithBrowser.__init__cs�tt|��|�z"t��}t|dd�}||jk}Wntjk
rPd}d}YnX|r�|�|j	|j
�ttggg|j
�\}}}|r�t�
�|dk	r�t�|�dS)r��basenameNF)r^rr��
webbrowserr�getattr�TERMINAL_BROWSERS�Errorr��TIMEOUT_MESSAGE�TIMEOUTrrr��open)r0r�Zbrowser_objZbrowserZconsole_browserZrlist�_rarrr��s&��
zBAuthorizeRequestTokenWithBrowser.notify_end_user_authorization_urlcCsr|�|j�t��}|jdkrnt�t�z|�|�r8WqnWntk
rNYnXt��|tkrt	dt��qdS)r�NzTimed out after %d seconds.)
r�r��timerB�sleep�access_token_poll_timer�r��access_token_poll_timeout�TokenAuthorizationTimedOut)r0r7Z
start_timerrrr��s


�z@AuthorizeRequestTokenWithBrowser.wait_for_end_user_authorization)NNN)
rUrVrWrXr�r�r�r�r�r_r�r�rcrrrarr�s���c@seZdZdS)�TokenAuthorizationExceptionN�rUrVrWrrrrr�sr�c@seZdZdS)�RequestTokenAlreadyAuthorizedNr�rrrrr�sr�c@seZdZdZdS)�EndUserAuthorizationFailedz?Superclass exception for all failures of end-user authorizationN�rUrVrWrXrrrrr�sr�c@seZdZdZdS)r�zEnd-user declined authorizationNr�rrrrr�sr�c@seZdZdZdS)r�z*End-user did not perform any authorizationNr�rrrrr�sr�c@seZdZdZdS)r�z<End-user did not perform any authorization in timeout periodNr�rrrrr�"sr�c@seZdZdS)�ClientErrorNr�rrrrr�'sr�c@seZdZdS)�ServerErrorNr�rrrrr�+sr�c@seZdZdS)�NoLaunchpadAccountNr�rrrrr�/sr�c@seZdZdS)�TooManyAuthenticationFailuresNr�rrrrr�3sr�)KZ
__future__r�typeZ
__metaclass__�__all__�	cStringIOr
rw�ior!rrr��sysrr�Zurllib.parser
ZurllibrZurlparser��base64rrrHZ
simplejsonZsix.moves.urllib.parserrGr}Zunicoder.Zlazr.restfulclient.errorsrZ"lazr.restfulclient.authorize.oauthrZ_AccessTokenrrrrzrrErSrLr�r��MemoryError�KeyboardInterrupt�
SystemExitrgrr'r	r�objectrrpr�rsrr�rrhr�r�r�r�r�r�r�r�r�r�rrrr�<module>s��


v 	K_<T