本文整理匯總了Python中openid.association.Association方法的典型用法代碼示例。如果您正苦於以下問題:Python association.Association方法的具體用法?Python association.Association怎麽用?Python association.Association使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openid.association
的用法示例。
在下文中一共展示了association.Association方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def getAssociation(self, server_url, handle=None):
"""
Return the association for server_url and handle. If handle is
not None return the latests associations for that server_url.
Return None if no association can be found.
"""
db = self.database
query = (db.oid_associations.server_url == server_url)
if handle:
query &= (db.oid_associations.handle == handle)
rows = db(query).select(orderby=db.oid_associations.issued)
keep_assoc, _ = self._removeExpiredAssocations(rows)
if len(keep_assoc) == 0:
return None
else:
assoc = keep_assoc.pop(
) # pop the last one as it should be the latest one
return Association(assoc['handle'],
assoc['secret'],
assoc['issued'],
assoc['lifetime'],
assoc['assoc_type'])
示例2: storeAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def storeAssociation(self, server_url, association):
"""
This method will store a MistAssociation object into mongodb after
creating a MistAssociation with the same values as the Association
provided.
Secret will be encoded because it constantly produced errors with
encoding.
"""
mist_association = MistAssociation()
mist_association.assoc_type = association.assoc_type
mist_association.handle = association.handle.encode('hex')
mist_association.secret = association.secret.encode('hex')
mist_association.lifetime = association.lifetime
mist_association.issued = association.issued
mist_association.server_url = server_url
mist_association.save()
示例3: txn_storeAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def txn_storeAssociation(self, server_url, association):
"""Set the association for the server URL.
Association -> NoneType
"""
a = association
self.db_set_assoc(
server_url,
a.handle,
self.blobEncode(a.secret),
a.issued,
a.lifetime,
a.assoc_type)
示例4: txn_getAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def txn_getAssociation(self, server_url, handle=None):
"""Get the most recent association that has been set for this
server URL and handle.
str -> NoneType or Association
"""
if handle is not None:
self.db_get_assoc(server_url, handle)
else:
self.db_get_assocs(server_url)
rows = self.cur.fetchall()
if len(rows) == 0:
return None
else:
associations = []
for values in rows:
assoc = Association(*values)
assoc.secret = self.blobDecode(assoc.secret)
if assoc.getExpiresIn() == 0:
self.txn_removeAssociation(server_url, assoc.handle)
else:
associations.append((assoc.issued, assoc))
if associations:
associations.sort()
return associations[-1][1]
else:
return None
示例5: getAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def getAssociation(self, server_url, handle=None):
stored_assocs = OpenIDStore.objects.filter(
server_url=server_url
)
if handle:
stored_assocs = stored_assocs.filter(handle=handle)
stored_assocs.order_by('-issued')
if stored_assocs.count() == 0:
return None
return_val = None
for stored_assoc in stored_assocs:
assoc = OIDAssociation(
stored_assoc.handle,
base64.decodestring(stored_assoc.secret.encode('utf-8')),
stored_assoc.issued, stored_assoc.lifetime,
stored_assoc.assoc_type
)
# See:
# necaris/[email protected]
if hasattr(assoc, 'getExpiresIn'):
expires_in = assoc.getExpiresIn()
else:
expires_in = assoc.expiresIn
if expires_in == 0:
stored_assoc.delete()
else:
if return_val is None:
return_val = assoc
return return_val
示例6: getAssociation
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def getAssociation(self, server_url, handle=None):
"""
Gets a server url and the handle and finds a matching association that
has not expired. Expired associations are deleted. The association
returned is the one with the most recent issuing timestamp.
"""
query = {'server_url': server_url}
if handle:
query.update({'handle': handle.encode('hex')})
try:
mist_associations = MistAssociation.objects(**query)
except me.DoesNotExist:
mist_associations = []
filtered_mist_assocs = []
for assoc in mist_associations:
if assoc.is_expired():
assoc.delete()
else:
filtered_mist_assocs.append(assoc)
filtered_mist_assocs = sorted(filtered_mist_assocs,
key=lambda assoc: assoc.issued,
reverse=True)
if len(filtered_mist_assocs) > 0:
mist_assoc = filtered_mist_assocs[0]
association = Association(handle=mist_assoc.handle.decode('hex'),
secret=mist_assoc.secret.decode('hex'),
issued=mist_assoc.issued,
lifetime=mist_assoc.lifetime,
assoc_type=mist_assoc.assoc_type)
return association
return None
示例7: openid_association
# 需要導入模塊: from openid import association [as 別名]
# 或者: from openid.association import Association [as 別名]
def openid_association(cls, assoc):
secret = assoc.secret
if not isinstance(secret, six.binary_type):
secret = secret.encode()
return OpenIdAssociation(assoc.handle, base64.decodestring(secret),
assoc.issued, assoc.lifetime,
assoc.assoc_type)