Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
if self.__class__.gc is None:
self.__class__.setUpClass()
self.assertTrue(isinstance(self.gc, gspread.client.Client))
def setUpClass(cls):
try:
cls.config = ConfigParser.RawConfigParser()
cls.gc = gspread.client.Client(auth={})
except IOError as e:
msg = "Can't find %s for reading test configuration. "
raise Exception(msg % e.filename)
from gspread.models import Spreadsheet
from gspread.utils import finditem
from past.builtins import basestring
from gspread_pandas.conf import default_scope, get_creds
from gspread_pandas.util import (
add_paths,
convert_credentials,
folders_to_create,
remove_keys_from_list,
)
__all__ = ["Client"]
class Client(ClientV4):
"""
The gspread_pandas :class:`Client` extends :class:`Client `
and authenticates using credentials stored in ``gspread_pandas`` config.
This class also adds a few convenience methods to explore the user's google drive
for spreadsheets.
Parameters
----------
user : str
optional, string indicating the key to a users credentials,
which will be stored in a file (by default they will be stored in
``~/.config/gspread_pandas/creds/`` but can be modified with
``creds_dir`` property in config). If using a Service Account, this
will be ignored. (default "default")
config : dict
def request(*args, **kwargs):
try:
return ClientV4.request(client, *args, **kwargs)
except APIError as e:
error = str(e)
# Only retry on 100s quota breaches
if "RESOURCE_EXHAUSTED" in error and "100s" in error:
sleep(retry_delay)
return request(*args, **kwargs)
else:
error = e
if "error" in locals():
raise error
def authorize(credentials, client_class=Client):
"""Login to Google API using OAuth2 credentials.
This is a shortcut function which
instantiates :class:`gspread.client.Client`
and performs login right away.
:returns: :class:`gspread.Client` instance.
"""
client = client_class(auth=credentials)
client.login()
return client