#NEWLINE# def load_creds( self , creds_file = None , subdir = None , verbose = False ) : #NEWLINE# #INDENT# "\n        Read OAuth credentials from a text file.\n\n        ::\n           File format for OAuth 1\n           =======================\n           app_key=YOUR_APP_KEY\n           app_secret=YOUR_APP_SECRET\n           oauth_token=OAUTH_TOKEN\n           oauth_token_secret=OAUTH_TOKEN_SECRET\n\n\n        ::\n           File format for OAuth 2\n           =======================\n\n           app_key=YOUR_APP_KEY\n           app_secret=YOUR_APP_SECRET\n           access_token=ACCESS_TOKEN\n\n        :param str file_name: File containing credentials. ``None`` (default) reads        data from `TWITTER/'credentials.txt'`\n        " #NEWLINE# if ( creds_file is not None ) : #NEWLINE# #INDENT# self . creds_file = creds_file #NEWLINE# #UNINDENT# if ( subdir is None ) : #NEWLINE# #INDENT# if ( self . creds_subdir is None ) : #NEWLINE# #INDENT# msg = ( "Supply a value to the 'subdir' parameter or" + ' set the TWITTER environment variable.' ) #NEWLINE# raise ValueError ( msg ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . creds_subdir = subdir #NEWLINE# #UNINDENT# self . creds_fullpath = os . path . normpath ( os . path . join ( self . creds_subdir , self . creds_file ) ) #NEWLINE# if ( not os . path . isfile ( self . creds_fullpath ) ) : #NEWLINE# #INDENT# raise OSError ( 'Cannot find file {}' . format ( subdir . creds_fullpath ) ) #NEWLINE# #UNINDENT# with open ( self . creds_fullpath ) as infile : #NEWLINE# #INDENT# if verbose : #NEWLINE# #INDENT# print ( 'Reading credentials file {}' . format ( self . creds_fullpath ) ) #NEWLINE# #UNINDENT# for line in infile : #NEWLINE# #INDENT# if ( '=' in line ) : #NEWLINE# #INDENT# ( name , value ) = line . split ( '=' , 1 ) #NEWLINE# self . oauth [ name . strip ( ) ] = value . strip ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . _validate_creds_file ( verbose = verbose ) #NEWLINE# return self . oauth