本文整理汇总了Python中oauth2client.client.Credentials.new_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.new_from_json方法的具体用法?Python Credentials.new_from_json怎么用?Python Credentials.new_from_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client.Credentials
的用法示例。
在下文中一共展示了Credentials.new_from_json方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_gcloud_oauth2_creds
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def get_gcloud_oauth2_creds():
gcfp = '~/.config/gcloud/credentials'
credfn = os.path.expanduser(gcfp)
if not os.path.exists(credfn):
credfn = os.path.expanduser('~/.config/gcloud/legacy_credentials')
if os.path.exists(credfn):
cdirs = os.listdir(credfn)
if cdirs:
credfn = "%s/%s/multistore.json" % (credfn, cdirs[0]) # just take the first one for now
if not os.path.exists(credfn):
msg = "[edx2bigquery] Authentication error! You have specified USE_GCLOUD_AUTH in the configuration, but do not have gcloud authentication available.\n"
msg += " Please authenticate using 'gcloud auth login' before running this."
msg += " Missing file %s" % credfn
print msg
raise Exception(msg)
gcloud_cred = json.loads(open(credfn).read())['data'][0]['credential']
credentials = Credentials.new_from_json(json.dumps(gcloud_cred))
return credentials
示例2: _from_base_type
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def _from_base_type(self, value):
"""Converts our stored JSON string back to the desired type.
Args:
value: A value from the datastore to be converted to the desired type.
Returns:
A deserialized Credentials (or subclass) object, else None if the
value can't be parsed.
"""
if not value:
return None
try:
# Uses the from_json method of the implied class of value
credentials = Credentials.new_from_json(value)
except ValueError:
credentials = None
return credentials
示例3: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from datastore.
Returns:
oauth2client.Credentials
"""
credentials = None
if self._cache:
json = self._cache.get(self._key_name)
if json:
credentials = Credentials.new_from_json(json)
if credentials is None:
entity = self._get_entity()
if entity is not None:
credentials = getattr(entity, self._property_name)
if self._cache:
self._cache.set(self._key_name, credentials.to_json())
if credentials and hasattr(credentials, 'set_store'):
credentials.set_store(self)
return credentials
示例4: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
示例5: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
Raises:
CredentialsFileSymbolicLinkError if the file is a symbolic link.
"""
credentials = None
self._validate_file()
try:
f = open(self._filename, 'rb')
content = f.read()
f.close()
except IOError:
return credentials
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
示例6: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
Raises:
CredentialsFileSymbolicLinkError if the file is a symbolic link.
"""
credentials = None
self._validate_file()
try:
f = open(self._filename, 'rb')
content = f.read()
f.close()
except IOError:
return credentials
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
示例7: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from datastore.
Returns:
oauth2client.Credentials
"""
credentials = None
if self._cache:
json = self._cache.get(self._key_name)
if json:
credentials = Credentials.new_from_json(json)
if credentials is None:
entity = self._get_entity()
if entity is not None:
credentials = getattr(entity, self._property_name)
if self._cache:
self._cache.set(self._key_name, credentials.to_json())
if credentials and hasattr(credentials, 'set_store'):
credentials.set_store(self)
return credentials
示例8: locked_get
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
示例9: _decode_credential_from_json
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def _decode_credential_from_json(self, cred_entry):
"""Load a credential from our JSON serialization.
Args:
cred_entry: A dict entry from the data member of our format
Returns:
(key, cred) where the key is the key tuple and the cred is the
OAuth2Credential object.
"""
raw_key = cred_entry['key']
key = _dict_to_tuple_key(raw_key)
credential = None
credential = Credentials.new_from_json(
json.dumps(cred_entry['credential']))
return (key, credential)
示例10: _from_base_type
# 需要导入模块: from oauth2client.client import Credentials [as 别名]
# 或者: from oauth2client.client.Credentials import new_from_json [as 别名]
def _from_base_type(self, value):
"""Converts our stored JSON string back to the desired type.
Args:
value: A value from the datastore to be converted to the
desired type.
Returns:
A deserialized Credentials (or subclass) object, else None if
the value can't be parsed.
"""
if not value:
return None
try:
# Uses the from_json method of the implied class of value
credentials = Credentials.new_from_json(value)
except ValueError:
credentials = None
return credentials