<s> '''<STR_LIT>''' <EOL> """<STR_LIT>""" <EOL> import json <EOL> import base64 <EOL> import requests <EOL> import copy <EOL> import getpass <EOL> import urllib <EOL> import httplib2 <EOL> import csv <EOL> from rauth import OAuth2Service <EOL> __copyright__ = "<STR_LIT>" <EOL> __status__ = "<STR_LIT>" <EOL> class CredentialsInvalidError ( Exception ) : <EOL> pass <EOL> class Credentials ( object ) : <EOL> def __init__ ( self , identifier ) : <EOL> self . type = "<STR_LIT:password>" <EOL> self . identifier = identifier <EOL> self . server_data = { } <EOL> self . username = None <EOL> self . password = None <EOL> def read ( self , user_creds ) : <EOL> self . username = user_creds . get ( "<STR_LIT:username>" ) <EOL> self . password = user_creds . get ( "<STR_LIT:password>" ) <EOL> if self . password : <EOL> self . password = self . decrypt ( self . password ) <EOL> def _populate_user_creds ( self , user_creds ) : <EOL> user_creds = { } <EOL> user_creds [ "<STR_LIT:type>" ] = self . type <EOL> if self . username is not None : <EOL> user_creds [ "<STR_LIT:username>" ] = self . username <EOL> if self . password is not None : <EOL> user_creds [ "<STR_LIT:password>" ] = self . encrypt ( self . password ) <EOL> return user_creds <EOL> def new_credentials ( self ) : <EOL> print "<STR_LIT>" , self . identifier , "<STR_LIT:]>" <EOL> username = raw_input ( '<STR_LIT>' ) <EOL> password = getpass . getpass ( '<STR_LIT>' ) <EOL> self . username = username <EOL> self . password = password <EOL> def authorizationHeaderValue ( self ) : <EOL> b64creds = base64 . b64encode ( "<STR_LIT>" % ( self . username , self . password ) ) <EOL> return "<STR_LIT>" % ( b64creds ) <EOL> def write ( self ) : <EOL> self . credential_manager . write_back_credentials ( self ) <EOL> def valid ( self ) : <EOL> return True <EOL> class OAuthCredentials ( Credentials ) : <EOL> def __init__ ( self , identifier ) : <EOL> super ( OAuthCredentials , self ) . __init__ ( identifier ) <EOL> self . type = "<STR_LIT>" <EOL> self . token_data = { } <EOL> def read ( self , user_creds ) : <EOL> super ( OAuthCredentials , self ) . read ( user_creds ) <EOL> self . token_data = user_creds . get ( "<STR_LIT>" , { } ) <EOL> if self . token_data . get ( "<STR_LIT>" ) is not None : <EOL> self . token_data [ "<STR_LIT>" ] = self . decrypt ( self . token_data [ "<STR_LIT>" ] ) <EOL> self . server_data = user_creds . get ( "<STR_LIT>" , { } ) <EOL> if self . server_data is not None : <EOL> self . server_data = user_creds . get ( "<STR_LIT>" , { } ) <EOL> if self . server_data . get ( "<STR_LIT>" ) is not None : <EOL> self . server_data [ "<STR_LIT>" ] = self . decrypt ( self . server_data [ "<STR_LIT>" ] ) <EOL> def _populate_user_creds ( self , user_creds ) : <EOL> user_creds = super ( OAuthCredentials , self ) . _populate_user_creds ( user_creds ) <EOL> if self . token_data and self . token_data . get ( "<STR_LIT>" ) is not None : <EOL> user_creds [ "<STR_LIT>" ] = copy . deepcopy ( self . token_data ) <EOL> user_creds [ "<STR_LIT>" ] [ "<STR_LIT>" ] = self . encrypt ( self . token_data [ "<STR_LIT>" ] ) <EOL> if self . server_data is not None : <EOL> user_creds [ "<STR_LIT>" ] = copy . deepcopy ( self . server_data ) <EOL> if self . server_data . get ( "<STR_LIT>" ) is not None : <EOL> user_creds [ "<STR_LIT>" ] [ "<STR_LIT>" ] = self . encrypt ( self . server_data [ "<STR_LIT>" ] ) <EOL> return user_creds <EOL> def authorizationHeaderValue ( self ) : <EOL> if self . token_data is None or self . token_data . get ( "<STR_LIT>" ) is None : <EOL> self . refreshToken ( ) <EOL> return "<STR_LIT>" % ( self . token_data . get ( "<STR_LIT>" ) ) <EOL> def refreshToken ( self ) : <EOL> raise NotImplementedError </s>
