Ë
    çÍ:j/  ã                   óN   — d Z ddlZddlZddlmZ d	d„Z G d„ d«      Zd
d„Zd„ Zy)z8
Authentication utilities to accompany `twitterclient`.
é    N)ÚTwythonc                 ó:   — t        «       j                  | ||¬«      S )z1
    Convenience function for authentication
    ©Ú
creds_fileÚsubdirÚverbose)ÚAuthenticateÚ
load_credsr   s      úf/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/twitter/util.pyÚcredsfromfiler      s%   € ô ‹>×$Ñ$Ø f°gð %ó ð ó    c                   ó&   — e Zd ZdZd„ Zdd„Zdd„Zy)r	   z2
    Methods for authenticating with Twitter.
    c                 ó¼   — d| _         d | _        i | _        	 t        j                  d   | _        | j
                  | _        y # t        $ r d | _        d | _        Y y w xY w)Nzcredentials.txtÚTWITTER)r   Úcreds_fullpathÚoauthÚosÚenvironÚtwitter_dirÚcreds_subdirÚKeyError)Úselfs    r   Ú__init__zAuthenticate.__init__!   s[   € Ø+ˆŒØ"ˆÔàˆŒ
ð	%Ü!Ÿz™z¨)Ñ4ˆDÔØ $× 0Ñ 0ˆDÕøÜò 	%Ø#ˆDÔØ $ˆDÖð	%ús   —)A ÁAÁANc                 óä  — |�|| _         |€| j                  €d}t        |«      ‚|| _        t        j                  j                  t        j                  j                  | j                  | j                   «      «      | _        t        j                  j                  | j                  «      st        d| j                  › �«      ‚t        | j                  «      5 }|rt        d| j                  › �«       |D ]G  }d|v sŒ|j                  dd«      \  }}|j                  «       | j                  |j                  «       <   ŒI 	 ddd«       | j                  |¬«       | j                  S # 1 sw Y   Œ'xY w)a  
        Read OAuth credentials from a text file.

        File format for OAuth 1::

           app_key=YOUR_APP_KEY
           app_secret=YOUR_APP_SECRET
           oauth_token=OAUTH_TOKEN
           oauth_token_secret=OAUTH_TOKEN_SECRET


        File format for OAuth 2::

           app_key=YOUR_APP_KEY
           app_secret=YOUR_APP_SECRET
           access_token=ACCESS_TOKEN

        :param str file_name: File containing credentials. ``None`` (default) reads
            data from `TWITTER/'credentials.txt'`
        NzQSupply a value to the 'subdir' parameter or set the TWITTER environment variable.zCannot find file zReading credentials file ú=é   )r   )r   r   Ú
ValueErrorr   ÚpathÚnormpathÚjoinr   ÚisfileÚOSErrorÚopenÚprintÚsplitÚstripr   Ú_validate_creds_file)	r   r   r   r   ÚmsgÚinfileÚlineÚnameÚvalues	            r   r
   zAuthenticate.load_creds-   sE  € ð* Ð!Ø(ˆDŒOàˆ>Ø× Ñ Ð(ð?ð ô ! “oÐ%à &ˆDÔä Ÿg™g×.Ñ.Ü�G‰G�L‰L˜×*Ñ*¨D¯O©OÓ<ó
ˆÔô �w‰w�~‰~˜d×1Ñ1Ô2ÜÐ-¨d×.AÑ.AÐ-BÐCÓDÐDä�$×%Ñ%Ó&ð 	=¨&ÙÜÐ1°$×2EÑ2EÐ1FÐGÔHàò =�Ø˜$’;Ø"&§*¡*¨S°!Ó"4‘K�D˜%Ø/4¯{©{«}�D—J‘J˜tŸz™z›|Ò,ñ=÷		=ð 	×!Ñ!¨'Ð!Ô2à�z‰zÐ÷	=ð 	=ús   Ã$E&Ã=AE&Å&E/c                 ó2  ‡ — d}g d¢}d}g d¢}t        ˆ fd„|D «       «      rd}nt        ˆ fd„|D «       «      rd}|s?|s=d‰ j                  › d�}|t        j                  ‰ j                  «      z  }t        |«      ‚|rt        d	‰ j                  › d
�«       yy)z%Check validity of a credentials file.F)Úapp_keyÚ
app_secretÚoauth_tokenÚoauth_token_secret)r.   r/   Úaccess_tokenc              3   ó:   •K  — | ]  }|‰j                   v –— Œ y ­w©N©r   ©Ú.0Úkr   s     €r   ú	<genexpr>z4Authenticate._validate_creds_file.<locals>.<genexpr>i   s   øè ø€ Ò4 1ˆq�D—J‘JŒÑ4ùó   ƒTc              3   ó:   •K  — | ]  }|‰j                   v –— Œ y ­wr4   r5   r6   s     €r   r9   z4Authenticate._validate_creds_file.<locals>.<genexpr>k   s   øè ø€ Ò6 Q��d—j‘j”Ñ6ùr:   z Missing or incorrect entries in ú
zCredentials file "z" looks goodN)Úallr   ÚpprintÚpformatr   r   r$   )r   r   Úoauth1Úoauth1_keysÚoauth2Úoauth2_keysr(   s   `      r   r'   z!Authenticate._validate_creds_filec   s•   ø€ àˆÚTˆØˆÚ?ˆÜÓ4¨Ô4Ô4Ø‰FÜÓ6¨+Ô6Ô6ØˆFá™&Ø4°T·_±_Ð4EÀRÐHˆCØ”6—>‘> $§*¡*Ó-Ñ-ˆCÜ˜S“/Ð!ÙÜÐ& t§¡Ð&7°|ÐDÕEð r   ©NNF)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   r'   © r   r   r	   r	      s   „ ñò
%ó4ôlFr   r	   c                 ó^  — | €Ct         j                  j                  t        «      }t         j                  j	                  |d«      } t        | ¬«      }|d   }|d   }t        ||d¬«      }|j                  «       }d|› d	�}t        | d
«      5 }t        ||¬«       ddd«       y# 1 sw Y   yxY w)zc
    For OAuth 2, retrieve an access token for an app and append it to a
    credentials file.
    Nzcredentials2.txt)r   r.   r/   é   )Úoauth_versionzaccess_token=r<   Úa)Úfile)
r   r   ÚdirnameÚ__file__r    r   r   Úobtain_access_tokenr#   r$   )	r   r   rB   r.   r/   Útwitterr2   Útokr)   s	            r   Úadd_access_tokenrT   v   s¤   € ð
 ÐÜ�w‰w�‰œxÓ(ˆÜ—W‘W—\‘\ $Ð(:Ó;ˆ
Ü jÔ1€FØ�YÑ€GØ˜Ñ%€Jä�g˜z¸Ô;€GØ×.Ñ.Ó0€LØ˜,˜ rÐ
*€CÜ	ˆj˜#Ó	ð   &Üˆc˜Õ÷ ÷  ñ  ús   ÂB#Â#B,c                 ó¾   — t         j                  j                  | «      r| S t         j                  j                  t         j                  j	                  d| «      «      S )zÃ
    If the path is not absolute, guess that it is a subdirectory of the
    user's home directory.

    :param str pth: The pathname of the directory where files of tweets should be written
    ú~)r   r   ÚisabsÚ
expanduserr    )Úpths    r   Ú
guess_pathrZ   ‰   s=   € ô 
‡w�w‡}�}�SÔØˆ
ä�w‰w×!Ñ!¤"§'¡'§,¡,¨s°CÓ"8Ó9Ð9r   rD   r4   )	rH   r   r>   Útwythonr   r   r	   rT   rZ   rI   r   r   ú<module>r\      s3   ðñó 
Û å ó÷WFñ WFót ó&
:r   