§
    ±Û”a§(  ã                   ó:  — d Z 	 ddlmZ n# e$ r	 ddlmZ Y nw xY wddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZmZ ddlmZ ddlmZ eZg d	¢Zd
Z G d„ d¦  «        Z G d„ d¦  «        Z G d„ de	j        ¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )z.OAuth classes for use with lazr.restfulclient.é    )ÚConfigParser)ÚSafeConfigParserN)Úoauth1)Úparse_qsÚ	urlencode)ÚHttpAuthorizer)ÚCredentialsFileError)ÚAccessTokenÚConsumerÚOAuthAuthorizerÚSystemWideConsumerÚ1c                   ó   — e Zd ZdZdd„ZdS )r   z An OAuth consumer (application).Ú Nc                 ó0   — || _         || _        || _        dS )an  Initialize

        :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   r   r   s       úD/usr/lib/python3/dist-packages/lazr/restfulclient/authorize/oauth.pyÚ__init__zConsumer.__init__9   s    € ð ˆŒØˆŒØ 0ˆÔÐÐó    ©r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r   r   6   s.   € € € € € Ø*Ð*ð1ð 1ð 1ð 1ð 1ð 1r   r   c                   ó:   — e Zd ZdZdd„Zd„ ZeZed„ ¦   «         ZdS )r
   zAn OAuth access token.r   Nc                 ó0   — || _         || _        || _        d S ©N)r   r   Úcontext)r   r   r   r"   s       r   r   zAccessToken.__init__K   s   € ØˆŒØˆŒØˆŒˆˆr   c                 ó@   — t          d| j        fd| j        fg¦  «        S )NÚoauth_token_secretÚoauth_token)r   r   r   ©r   s    r   Ú	to_stringzAccessToken.to_stringP   s-   € Ýà% t¤{Ð3Ø ¤Ð)ðñ
ô 
ð 	
r   c                 ót   — t          |d¬¦  «        }|d         d         }|d         d         } | ||¦  «        S )NF)Úkeep_blank_valuesr%   r   r$   )r   )ÚclsÚsÚparamsr   r   s        r   Úfrom_stringzAccessToken.from_stringZ   sE   € å˜!¨uÐ5Ñ5Ô5ˆØ�]Ô# AÔ&ˆØÐ,Ô-¨aÔ0ˆØˆs�3˜ÑÔÐr   r   )	r   r   r   r   r   r'   Ú__str__Úclassmethodr-   r   r   r   r
   r
   H   s]   € € € € € Ø Ð ðð ð ð ð

ð 
ð 
ð €Gàð ð  ñ „[ð ð  ð  r   r
   c                   ó   — e Zd ZdZd„ ZeZdS )ÚTruthyStringz&A Unicode string which is always true.c                 ó   — dS )NTr   r&   s    r   Ú__bool__zTruthyString.__bool__e   s   € Øˆtr   N)r   r   r   r   r3   Ú__nonzero__r   r   r   r1   r1   b   s*   € € € € € Ø0Ð0ðð ð ð €K€K€Kr   r1   c                   ó>   ‡ — e Zd ZdZdZdˆ fd„	Zed„ ¦   «         Zˆ xZS )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).
    zSystem-wide: %s (%s)r   c                 óf   •— t          t          | ¦  «                             | j        ||¦  «         dS )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)r   r   r   Ú	__class__s      €r   r   zSystemWideConsumer.__init__u   s=   ø€ õ 	Õ  $Ñ'Ô'×0Ò0ØÔ˜vÐ'7ñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óÆ   — 	 ddl }|                     ¦   «         }n# t          $ r d}Y nw xY w|dk    rt          j        ¦   «         }| j        |t          j        ¦   «         fz  S )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.
        r   Nr   )ÚdistroÚnameÚ	ExceptionÚplatformÚsystemÚ
KEY_FORMATÚsocketÚgethostname)r   r;   Údistnames      r   r8   zSystemWideConsumer.consumer_key�   sx   € ð	ØˆMˆMˆMà—{’{‘}”}ˆHˆHøÝð 	ð 	ð 	ð ˆHˆHˆHð	øøøð �rŠ>ˆ>Ý”Ñ(Ô(ˆHØŒ (­FÔ,>Ñ,@Ô,@Ð!AÑAÐAs   ‚ ›*©*)r   )	r   r   r   r   r@   r   Úpropertyr8   Ú__classcell__)r9   s   @r   r   r   k   sp   ø€ € € € € ðð ð (€Jð

ð 

ð 

ð 

ð 

ð 

ð ðBð Bñ „XðBð Bð Bð Bð Br   r   c                   óh   — e Zd ZdZ	 	 	 	 	 dd„Zed„ ¦   «         Zd„ Zed„ ¦   «         Z	d	„ Z
d
„ Zd„ ZdS )r   zBA client that signs every outgoing request with OAuth credentials.Nr   ÚOAuthc                 ó`   — d | _         |�t          |||¦  «        | _         || _        || _        d S r!   )Úconsumerr   Úaccess_tokenÚoauth_realm)r   Úconsumer_nameÚconsumer_secretrJ   rK   r   s         r   r   zOAuthAuthorizer.__init__˜   sB   € ð ˆŒØÐ$Ý$Ø˜Ð0@ñô ˆDŒMð )ˆÔØ&ˆÔÐÐr   c                 óp   — i }| j         €|S | j         j        |d<   | j         j        �| j         j        |d<   |S )zoAny information necessary to identify this user agent.

        In this case, the OAuth consumer name.
        NÚoauth_consumerÚapplication)rI   r   r   )r   r,   s     r   Úuser_agent_paramsz!OAuthAuthorizer.user_agent_params¨   sE   € ð ˆØŒ=Ð ØˆMØ#'¤=Ô#4ˆÐÑ ØŒ=Ô)Ð5Ø$(¤MÔ$BˆF�=Ñ!Øˆr   c                 óò  — t          ¦   «         }t          |d|j        ¦  «        } ||¦  «         |                     t          ¦  «        st          dt          z  ¦  «        ‚|                     t          d¦  «        }|                     t          d¦  «        }t          ||¦  «        | _        |                     t          d¦  «        }|                     t          d¦  «        }t          ||¦  «        | _
        dS )ak  Load 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
        Ú	read_filezNo configuration for version %sr8   rM   rJ   Úaccess_secretN)r   ÚgetattrÚreadfpÚhas_sectionÚCREDENTIALS_FILE_VERSIONr	   Úgetr   rI   r
   rJ   )r   Úreadable_fileÚparserÚreaderr8   rM   rJ   rT   s           r   ÚloadzOAuthAuthorizer.load¶   sè   € õ "Ñ#Ô#ˆÝ˜ ¨f¬mÑ<Ô<ˆØˆˆ}ÑÔÐð ×!Ò!Õ":Ñ;Ô;ð 	Ý&Ø1Õ4LÑLñô ð ð —z’zÕ":¸NÑKÔKˆØ Ÿ*š*Ý$Ð&7ñ
ô 
ˆõ ! ¨Ñ?Ô?ˆŒØ—z’zÕ":¸NÑKÔKˆØŸ
š
Õ#;¸_ÑMÔMˆÝ'¨°mÑDÔDˆÔÐÐr   c                 óŒ   —  | ¦   «         }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)Úopenr]   Úclose)r*   ÚpathÚcredentialsÚcredentials_files       r   Úload_from_pathzOAuthAuthorizer.load_from_pathÓ   sJ   € ð �c‘e”eˆÝ  c™?œ?ÐØ×ÒÐ)Ñ*Ô*Ð*Ø×ÒÑ Ô Ð ØÐr   c                 ó  — | j         €t          d¦  «        ‚| j        €t          d¦  «        ‚t          ¦   «         }|                     t
          ¦  «         |                     t
          d| j         j        ¦  «         |                     t
          d| j         j        ¦  «         |                     t
          d| j        j        ¦  «         |                     t
          d| j        j        ¦  «         | 	                    |¦  «         dS )aH  Write 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
        NzNo consumerzNo access tokenr8   rM   rJ   rT   )
rI   r	   rJ   r   Úadd_sectionrX   Úsetr   r   Úwrite)r   Úwritable_filer[   s      r   ÚsavezOAuthAuthorizer.saveæ   sõ   € ð Œ=Ð Ý& }Ñ5Ô5Ð5ØÔÐ$Ý&Ð'8Ñ9Ô9Ð9å!Ñ#Ô#ˆØ×ÒÕ3Ñ4Ô4Ð4Ø�
Š
Õ+¨^¸T¼]Ô=NÑOÔOÐOØ�
Š
Ý$Ð&7¸¼Ô9Mñ	
ô 	
ð 	
ð 	�
Š
Ý$ n°dÔ6GÔ6Kñ	
ô 	
ð 	
ð 	�
Š
Ý$ o°tÔ7HÔ7Oñ	
ô 	
ð 	
ð 	�Š�]Ñ#Ô#Ð#Ð#Ð#r   c                 ó   — t          j        t          j        |t           j        t           j        z  t           j        z  t          j        t          j        z  ¦  «        d¦  «        }|  	                    |¦  «         | 
                    ¦   «          dS )aT  Convenience 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Úfdopenr`   ÚO_CREATÚO_TRUNCÚO_WRONLYÚstatÚS_IREADÚS_IWRITErk   ra   )r   rb   rd   s      r   Úsave_to_pathzOAuthAuthorizer.save_to_path  sy   € õ œ9ÝŒGØÝ”�bœjÑ(­2¬;Ñ6Ý”¥¤Ñ-ñô ð
 ñ
ô 
Ðð 	�	Š	Ð"Ñ#Ô#Ð#Ø×ÒÑ Ô Ð Ð Ð r   c                 óÔ  — t          j        | j        j        | j        j        t          | j        j        pd¦  «        | j        j        t           j        | j        ¬¦  «        }t          |j	        ¦  «        |_	        | 
                    |¦  «        \  }}}|                     ¦   «         D ]@\  }}	t          j        r*|                     d¦  «        }|	                     d¦  «        }	|	||<   ŒAdS )z&Sign a request with OAuth credentials.r   )Úclient_secretÚresource_owner_keyÚresource_owner_secretÚsignature_methodÚrealmzUTF-8N)r   ÚClientrI   r   r   r1   rJ   ÚSIGNATURE_PLAINTEXTrK   ry   ÚsignÚitemsÚsixÚPY2Úencode)
r   Úabsolute_uriÚmethodÚbodyÚheadersÚclientÚ_Úsigned_headersr   Úvalues
             r   ÚauthorizeRequestz OAuthAuthorizer.authorizeRequest  sâ   € å”ØŒMÔØœ-Ô.Ý+¨DÔ,=Ô,AÐ,GÀRÑHÔHØ"&Ô"3Ô":Ý#Ô7ØÔ"ð
ñ 
ô 
ˆõ %1°Ô1JÑ$KÔ$KˆÔ!Ø%Ÿ{š{¨<Ñ8Ô8Ñˆˆ>˜1Ø(×.Ò.Ñ0Ô0ð 	!ð 	!‰JˆC�õ Œwð .Ø—j’j Ñ)Ô)�ØŸš WÑ-Ô-�Ø ˆG�C‰LˆLð	!ð 	!r   )Nr   NrG   N)r   r   r   r   r   rD   rQ   r]   r/   re   rk   rv   rŒ   r   r   r   r   r   •   s´   € € € € € ØLÐLð ØØØØð'ð 'ð 'ð 'ð  ðð ñ „XððEð Eð Eð: ðð ñ „[ðð$$ð $ð $ð8!ð !ð !ð*!ð !ð !ð !ð !r   r   )r   Úconfigparserr   r   ÚImportErrorrn   r>   rA   rs   r�   Úoauthlibr   Úsix.moves.urllib.parser   r   Úlazr.restfulclient.authorizer   Úlazr.restfulclient.errorsr	   ÚtypeÚ__metaclass__Ú__all__rX   r   r
   Ú	text_typer1   r   r   r   r   r   ú<module>r—      sâ  ðð& 5Ð 4ð.à=Ð=Ð=Ð=Ð=Ð=Ð=øØð .ð .ð .Ø-Ð-Ð-Ð-Ð-Ð-Ð-Ð-ð.øøøð 
€	€	€	Ø €€€Ø €€€Ø €€€à 
€
€
€
Ø Ð Ð Ð Ð Ð Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6Ð 6à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø :Ð :Ð :Ð :Ð :Ð :à€ðð ð €ð Ð ð
1ð 1ð 1ð 1ð 1ñ 1ô 1ð 1ð$ ð  ð  ð  ð  ñ  ô  ð  ð4ð ð ð ð �3”=ñ ô ð ð'Bð 'Bð 'Bð 'Bð 'B˜ñ 'Bô 'Bð 'BðTX!ð X!ð X!ð X!ð X!�nñ X!ô X!ð X!ð X!ð X!s   „ ‹˜