本文整理汇总了Python中client.Credentials.new_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python Credentials.new_from_json方法的具体用法?Python Credentials.new_from_json怎么用?Python Credentials.new_from_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类client.Credentials
的用法示例。
在下文中一共展示了Credentials.new_from_json方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: locked_get
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from 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
示例2: locked_get
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
try:
f = open(self._filename, 'r')
content = f.read()
f.close()
except IOError:
return credentials
# First try reading as JSON, and if that fails fall back to pickle.
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
# TODO(jcgregorio) On a future release remove this path to finally remove
# all pickle support.
try:
credentials = pickle.loads(content)
credentials.set_store(self)
except:
pass
return credentials
示例3: make_value_from_datastore
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from client.Credentials import new_from_json [as 别名]
def make_value_from_datastore(self, value):
if value is None:
return None
if len(value) == 0:
return None
try:
credentials = Credentials.new_from_json(value)
except ValueError:
credentials = None
return credentials
示例4: make_value_from_datastore
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from client.Credentials import new_from_json [as 别名]
def make_value_from_datastore(self, value):
logging.info("make: Got type " + str(type(value)))
if value is None:
return None
if len(value) == 0:
return None
try:
credentials = Credentials.new_from_json(value)
except ValueError:
credentials = None
return credentials
示例5: locked_get
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from 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
示例6: _decode_credential_from_json
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from 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']
client_id = raw_key['clientId']
user_agent = raw_key['userAgent']
scope = raw_key['scope']
key = (client_id, user_agent, scope)
credential = None
credential = Credentials.new_from_json(simplejson.dumps(cred_entry['credential']))
return (key, credential)
示例7: locked_get
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from datastore.
Returns:
oauth2client.Credentials
"""
if self._cache:
json = self._cache.get(self._key_name)
if json:
return Credentials.new_from_json(json)
entity = self._model.get_or_insert(self._key_name)
credential = getattr(entity, self._property_name)
if credential and hasattr(credential, 'set_store'):
credential.set_store(self)
if self._cache:
self._cache.set(self._key_name, credentials.to_json())
return credential
示例8: locked_get
# 需要导入模块: from client import Credentials [as 别名]
# 或者: from client.Credentials import new_from_json [as 别名]
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
try:
f = open(self._filename, 'r')
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