Skip to content

Commit

Permalink
Format auth.py
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash committed Apr 28, 2020
1 parent 46abc18 commit 71484eb
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions gspread/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

DEFAULT_SCOPES = [
'https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'
'https://www.googleapis.com/auth/drive',
]

READONLY_SCOPES = [
'https://www.googleapis.com/auth/spreadsheets.readonly',
'https://www.googleapis.com/auth/drive.readonly'
'https://www.googleapis.com/auth/drive.readonly',
]


Expand All @@ -37,38 +37,29 @@ def get_config_dir(config_dir_name='gspread', os_is_windows=os.name == 'nt'):
"""
if os_is_windows:
return os.path.join(
os.environ["APPDATA"],
config_dir_name
)
return os.path.join(os.environ["APPDATA"], config_dir_name)
else:
return os.path.join(
os.path.expanduser('~'),
'.config',
config_dir_name
os.path.expanduser('~'), '.config', config_dir_name
)


DEFAULT_CONFIG_DIR = get_config_dir()

DEFAULT_CREDENTIALS_FILENAME = os.path.join(
DEFAULT_CONFIG_DIR,
'credentials.json'
DEFAULT_CONFIG_DIR, 'credentials.json'
)
DEFAULT_AUTHORIZED_USER_FILENAME = os.path.join(
DEFAULT_CONFIG_DIR,
'authorized_user.json'
DEFAULT_CONFIG_DIR, 'authorized_user.json'
)
DEFAULT_SERVICE_ACCOUNT_FILENAME = os.path.join(
DEFAULT_CONFIG_DIR,
'service_account.json'
DEFAULT_CONFIG_DIR, 'service_account.json'
)


def _create_installed_app_flow(scopes):
return InstalledAppFlow.from_client_secrets_file(
DEFAULT_CREDENTIALS_FILENAME,
scopes
DEFAULT_CREDENTIALS_FILENAME, scopes
)


Expand All @@ -90,9 +81,7 @@ def load_credentials(filename=DEFAULT_AUTHORIZED_USER_FILENAME):


def store_credentials(
creds,
filename=DEFAULT_AUTHORIZED_USER_FILENAME,
strip='token'
creds, filename=DEFAULT_AUTHORIZED_USER_FILENAME, strip='token'
):
with open(filename, 'w') as f:
f.write(creds.to_json(strip))
Expand All @@ -110,11 +99,9 @@ def oauth(scopes=DEFAULT_SCOPES, flow=local_server_flow):


def service_account(
filename=DEFAULT_SERVICE_ACCOUNT_FILENAME,
scopes=DEFAULT_SCOPES
filename=DEFAULT_SERVICE_ACCOUNT_FILENAME, scopes=DEFAULT_SCOPES
):
creds = ServiceAccountCredentials.from_service_account_file(
filename,
scopes=scopes
filename, scopes=scopes
)
return Client(auth=creds)

0 comments on commit 71484eb

Please sign in to comment.