Ë
    !í�eù'  ã                   ó  — d Z 	 ddlm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«      Z G d„ de«      Z G d„ de«      Zy# e$ r	 ddlmZ Y Œuw xY w)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y)r   z An OAuth consumer (application).Nc                 ó.   — || _         || _        || _        y)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__8   s   € ð ˆŒØˆŒØ 0ˆÕó    ©Ú N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   © r   r   r   r   5   s
   „ Ù*ô1r   r   c                   ó2   — e Zd ZdZdd„Zd„ ZeZed„ «       Zy)r
   zAn OAuth access token.Nc                 ó.   — || _         || _        || _        y ©N)r   r   Úcontext)r   r   r   r"   s       r   r   zAccessToken.__init__J   s   € ØˆŒØˆŒØˆ�r   c                 óL   — 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_stringO   s,   € Üà% t§{¡{Ð3Ø §¡Ð)ðó
ð 	
r   c                 óN   — t        |d¬«      }|d   d   }|d   d   } | ||«      S )NF)Úkeep_blank_valuesr%   r   r$   )r   )ÚclsÚsÚparamsr   r   s        r   Úfrom_stringzAccessToken.from_stringY   s:   € ä˜!¨uÔ5ˆØ�]Ñ# AÑ&ˆØÐ,Ñ-¨aÑ0ˆÙ�3˜ÓÐr   r   )	r   r   r   r   r   r'   Ú__str__Úclassmethodr-   r   r   r   r
   r
   G   s(   „ Ù óò

ð €Gàñ ó ñ r   r
   c                   ó   — e Zd ZdZd„ ZeZy)ÚTruthyStringz&A Unicode string which is always true.c                  ó   — y)NTr   r&   s    r   Ú__bool__zTruthyString.__bool__d   s   € Ør   N)r   r   r   r   r3   Ú__nonzero__r   r   r   r1   r1   a   s   „ Ù0òð �Kr   r1   c                   ó8   ‡ — 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)c                 óD   •— t         t        | �  | j                  ||«       y)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__t   s#   ø€ ô 	Ô  $Ñ0Ø×Ñ˜vÐ'7õ	
r   c                 óÆ   — 	 ddl }|j                  «       }|dk(  rt        j                  «       }| j
                  |t        j                  «       fz  S # t        $ r d}Y ŒIw xY w)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€   s_   € ð	Ûà—{‘{“}ˆHð
 �rŠ>Ü—‘Ó(ˆHØ�‰ (¬F×,>Ñ,>Ó,@Ð!AÑAÐAøô ò 	ð ŠHð	ús   ‚A ÁA ÁA )r   )	r   r   r   r   r@   r   Úpropertyr8   Ú__classcell__)r9   s   @r   r   r   j   s*   ø„ ñð (€Jõ

ð ñBó ôBr   r   c                   óZ   — e Zd ZdZ	 	 	 	 	 d
d„Zed„ «       Zd„ Zed„ «       Z	d„ Z
d„ Zd	„ Zy)r   zBA client that signs every outgoing request with OAuth credentials.Nc                 óV   — d | _         |�t        |||«      | _         || _        || _        y r!   )Úconsumerr   Úaccess_tokenÚoauth_realm)r   Úconsumer_nameÚconsumer_secretrI   rJ   r   s         r   r   zOAuthAuthorizer.__init__—   s7   € ð ˆŒØÐ$Ü$Ø˜Ð0@óˆDŒMð )ˆÔØ&ˆÕr   c                 ó¶   — 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.
        Úoauth_consumerÚapplication)rH   r   r   )r   r,   s     r   Úuser_agent_paramsz!OAuthAuthorizer.user_agent_params§   sV   € ð ˆØ�=‰=Ð ØˆMØ#'§=¡=×#4Ñ#4ˆÐÑ Ø�=‰=×)Ñ)Ð5Ø$(§M¡M×$BÑ$BˆF�=Ñ!Øˆr   c                 ó´  — t        «       }t        |d«      r|j                  }n|j                  } ||«       |j	                  t
        «      st        dt
        z  «      ‚|j                  t
        d«      }|j                  t
        d«      }t        ||«      | _	        |j                  t
        d«      }|j                  t
        d«      }t        ||«      | _        y)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   rL   rI   Úaccess_secretN)r   ÚhasattrrR   ÚreadfpÚhas_sectionÚCREDENTIALS_FILE_VERSIONr	   Úgetr   rH   r
   rI   )r   Úreadable_fileÚparserÚreaderr8   rL   rI   rS   s           r   ÚloadzOAuthAuthorizer.loadµ   sÁ   € ô "Ó#ˆÜ�6˜;Ô'Ø×%Ñ%‰Fà—]‘]ˆFÙˆ}Ôð ×!Ñ!Ô":Ô;Ü&Ø1Ô4LÑLóð ð —z‘zÔ":¸NÓKˆØ Ÿ*™*Ü$Ð&7ó
ˆô ! ¨Ó?ˆŒØ—z‘zÔ":¸NÓKˆØŸ
™
Ô#;¸_ÓMˆÜ'¨°mÓDˆÕr   c                 ón   —  | «       }t        |d«      }|j                  |«       |j                  «        |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Õ   s8   € ñ “eˆÜ  c›?ÐØ×ÑÐ)Ô*Ø×ÑÔ ØÐr   c                 ó  — | j                   €t        d«      ‚| j                  €t        d«      ‚t        «       }|j	                  t
        «       |j                  t
        d| j                   j                  «       |j                  t
        d| j                   j                  «       |j                  t
        d| j                  j                  «       |j                  t
        d| j                  j                  «       |j                  |«       y)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   rL   rI   rS   )
rH   r	   rI   r   Úadd_sectionrW   Úsetr   r   Úwrite)r   Úwritable_filerZ   s      r   ÚsavezOAuthAuthorizer.saveè   sÑ   € ð �=‰=Ð Ü& }Ó5Ð5Ø×ÑÐ$Ü&Ð'8Ó9Ð9ä!Ó#ˆØ×ÑÔ3Ô4Ø�
‰
Ô+¨^¸T¿]¹]×=NÑ=NÔOØ�
‰
Ü$Ð&7¸¿¹×9MÑ9Mô	
ð 	�
‰
Ü$ n°d×6GÑ6G×6KÑ6Kô	
ð 	�
‰
Ü$ o°t×7HÑ7H×7OÑ7Oô	
ð 	�‰�]Õ#r   c                 ó:  — t        j                  t        j                  |t         j                  t         j                  z  t         j
                  z  t        j                  t        j                  z  «      d«      }| j                  |«       |j                  «        y)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_IWRITErj   r`   )r   ra   rc   s      r   Úsave_to_pathzOAuthAuthorizer.save_to_path  sk   € ô Ÿ9™9Ü�G‰GØÜ—‘œbŸj™jÑ(¬2¯;©;Ñ6Ü—‘¤§¡Ñ-óð
 ó
Ðð 	�	‰	Ð"Ô#Ø×ÑÕ r   c                 ó¼  — t        j                  | j                  j                  | j                  j                  t        | j                  j                  xs d«      | j                  j                  t         j                  | j                  ¬«      }t        |j                  «      |_	        |j                  |«      \  }}}|j                  «       D ]
  \  }}	|	||<   Œ y)z&Sign a request with OAuth credentials.r   )Úclient_secretÚresource_owner_keyÚresource_owner_secretÚsignature_methodÚrealmN)r   ÚClientrH   r   r   r1   rI   ÚSIGNATURE_PLAINTEXTrJ   rx   ÚsignÚitems)
r   Úabsolute_uriÚmethodÚbodyÚheadersÚclientÚ_Úsigned_headersr   Úvalues
             r   ÚauthorizeRequestz OAuthAuthorizer.authorizeRequest  s³   € ä—‘Ø�M‰M×ÑØŸ-™-×.Ñ.Ü+¨D×,=Ñ,=×,AÑ,AÒ,GÀRÓHØ"&×"3Ñ"3×":Ñ":Ü#×7Ñ7Ø×"Ñ"ô
ˆô %1°×1JÑ1JÓ$KˆÔ!Ø%Ÿ{™{¨<Ó8Ñˆˆ>˜1Ø(×.Ñ.Ó0ò 	!‰JˆC�Ø ˆG�CŠLñ	!r   )Nr   NÚOAuthN)r   r   r   r   r   rD   rP   r\   r/   rd   rj   ru   rˆ   r   r   r   r   r   ”   sY   „ ÙLð ØØØØó'ð  ñó ðòEð@ ñó ðò$$ò8!ó*!r   r   )r   Úconfigparserr   r   ÚImportErrorrm   r>   rA   rr   Úoauthlibr   Úurllib.parser   r   Úlazr.restfulclient.authorizer   Úlazr.restfulclient.errorsr	   ÚtypeÚ__metaclass__Ú__all__rW   r   r
   Ústrr1   r   r   r   r   r   ú<module>r”      s’   ðñ& 5ð.å=ó 
Û Û Û å ß ,å 7Ý :à€ò€ð Ð ÷
1ñ 1÷$ ñ  ô4�3ô ô'B˜ô 'BôTV!�nõ V!øðw ò .ß-ð.ús   „A2 Á2B Á?B 