
    /h/                     R    S r SSKrSSKrSSKJr  S	S jr " S S5      rS
S jrS rg)z8
Authentication utilities to accompany `twitterclient`.
    N)Twythonc                 2    [        5       R                  XUS9$ )z)
Convenience function for authentication

creds_filesubdirverbose)Authenticate
load_credsr   s      I/var/www/auris/envauris/lib/python3.13/site-packages/nltk/twitter/util.pycredsfromfiler      s#     >$$g %      c                   2    \ rS rSrSrS rSS jrS	S jrSrg)
r	      z*
Methods for authenticating with Twitter.
c                     SU l         S U l        0 U l         [        R                  S   U l        U R
                  U l        g ! [         a    S U l        S U l         g f = f)Nzcredentials.txtTWITTER)r   creds_fullpathoauthosenvirontwitter_dircreds_subdirKeyError)selfs    r   __init__Authenticate.__init__!   s[    +"
	%!zz)4D $ 0 0D 	%#D $D	%s   )A AANc                    Ub  Xl         Uc  U R                  c  Sn[        U5      eOX l        [        R                  R                  [        R                  R                  U R                  U R                   5      5      U l        [        R                  R                  U R                  5      (       d  [        SU R                   35      e[        U R                  5       nU(       a  [        SU R                   35        U HJ  nSU;   d  M  UR                  SS5      u  pxUR                  5       U R                  UR                  5       '   ML     SSS5        U R                  US9  U R                  $ ! , (       d  f       N)= f)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
   Authenticate.load_creds-   s=   * !(O>  (?  !o% ) !' gg..GGLL**DOO<
 ww~~d1122-d.A.A-BCDD$%%&&1$2E2E1FGH$;"&**S!"4KD/4{{}DJJtzz|, 	 ' 	!!'!2zz '&s   )E2AE22
F c                 j  ^  Sn/ SQnSn/ SQn[        U 4S jU 5       5      (       a  SnO[        U 4S jU 5       5      (       a  SnU(       dE  U(       d>  ST R                   S3nU[        R                  " T R                  5      -  n[        U5      eU(       a  [        S	T R                   S
35        gg)z%Check validity of a credentials file.F)app_key
app_secretoauth_tokenoauth_token_secret)r1   r2   access_tokenc              3   @   >#    U  H  oTR                   ;   v   M     g 7fNr   .0kr   s     r   	<genexpr>4Authenticate._validate_creds_file.<locals>.<genexpr>i   s     41DJJ   Tc              3   @   >#    U  H  oTR                   ;   v   M     g 7fr7   r8   r9   s     r   r<   r=   k   s     6+Qdjj+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)   !Authenticate._validate_creds_filec   s    T?4444F6+666F&4T__4ERHC6>>$**--CS/!&t&7|DE r   )r   r   r   r   r   NNF)F)	__name__
__module____qualname____firstlineno____doc__r   r
   r)   __static_attributes__ r   r   r	   r	      s    
%4lFr   r	   c                 T   U cC  [         R                  R                  [        5      n[         R                  R	                  US5      n [        U S9nUS   nUS   n[        X4SS9nUR                  5       nSU S	3n[        U S
5       n[        XxS9  SSS5        g! , (       d  f       g= f)zW
For OAuth 2, retrieve an access token for an app and append it to a
credentials file.
Nzcredentials2.txt)r   r1   r2      )oauth_versionzaccess_token=r@   a)file)
r   r    dirname__file__r"   r   r   obtain_access_tokenr%   r&   )	r   r    rF   r1   r2   twitterr5   tokr+   s	            r   add_access_tokenr[   v   s    
 wwx(WW\\$(:;
j1FYG%Jg;G..0L,r
*C	j#	&c 
		s   
B
B'c                     [         R                  R                  U 5      (       a  U $ [         R                  R                  [         R                  R	                  SU 5      5      $ )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_pathra      s@     
ww}}S
ww!!"'',,sC"899r   rI   r7   )	rN   r   rB   twythonr   r   r	   r[   ra   rP   r   r   <module>rc      s3    
  WF WFt &
:r   