JL i/NdZddlZddlZddlmZd dZGddZd dZdZy) z8 Authentication utilities to accompany `twitterclient`. N)Twythonc:tj|||S)z1 Convenience function for authentication  creds_filesubdirverbose) Authenticate load_credsrs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/twitter/util.py credsfromfiler s% > $ $fg % c&eZdZdZdZddZddZy)r z2 Methods for authenticating with Twitter. cd|_d|_i|_ tjd|_|j |_y#t$rd|_d|_YywxYw)Nzcredentials.txtTWITTER)rcreds_fullpathoauthosenviron twitter_dir creds_subdirKeyError)selfs r __init__zAuthenticate.__init__!s[+"  %!zz)4D  $ 0 0D  %#D  $D  %s)AAANc|||_||jd}t|||_tjj tjj |j|j|_tjj|jstd|jt|j5}|rtd|j|D]G}d|vs|jdd\}}|j|j|j<I ddd|j||jS#1swY'xYw)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.zCannot find file zReading credentials file =)r)rr ValueErrorrpathnormpathjoinrisfileOSErroropenprintsplitstripr_validate_creds_file) rrrrmsginfilelinenamevalues r r zAuthenticate.load_creds-sE*  !(DO >  (?!o% &D  gg.. GGLL**DOO < ww~~d112-d.A.A-BCD D $%% & =&1$2E2E1FGH =$;"&**S!"4KD%/4{{}DJJtzz|, =  = !!'!2zz = =s$E&=AE&&E/c2d}gd}d}gd}tfd|Drd}ntfd|Drd}|s?|s=djd}|tjjz }t ||rt d jd y y ) z%Check validity of a credentials file.F)app_key app_secret oauth_tokenoauth_token_secret)r.r/ access_tokenc3:K|]}|jvywNr.0krs r z4Authenticate._validate_creds_file..is41qDJJ4Tc3:K|]}|jvywr4r5r6s r r9z4Authenticate._validate_creds_file..ks6Qdjj6r:z Missing or incorrect entries in  zCredentials file "z " looks goodN)allrpprintpformatrrr$)rroauth1 oauth1_keysoauth2 oauth2_keysr(s` r r'z!Authenticate._validate_creds_filecsT ? 4 4 4F 6+6 6F&4T__4ERHC 6>>$**- -CS/ !  &t&7|D Er NNF)F)__name__ __module__ __qualname____doc__rr r'r r r r s %4lFr r c^|Ctjjt}tjj |d}t |}|d}|d}t ||d}|j}d|d }t|d 5}t|| dddy#1swYyxYw) zc For OAuth 2, retrieve an access token for an app and append it to a credentials file. Nzcredentials2.txt)rr.r/) oauth_versionz access_token=r<a)file) rrdirname__file__r r robtain_access_tokenr#r$) rrrBr.r/twitterr2tokr)s r add_access_tokenrTvs wwx(WW\\$(:; j 1FYG %Jgz;G..0L ,r *C j#  & c   s B##B,ctjj|r|Stjjtjj 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 ~)rrisabs expanduserr )pths r guess_pathrZs= ww}}S ww!!"'',,sC"899r rDr4) rHrr>twythonrr r rTrZrIr r r\s3 WFWFt & :r