本文整理匯總了Python中openid.store.nonce.SKEW屬性的典型用法代碼示例。如果您正苦於以下問題:Python nonce.SKEW屬性的具體用法?Python nonce.SKEW怎麽用?Python nonce.SKEW使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類openid.store.nonce
的用法示例。
在下文中一共展示了nonce.SKEW屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def useNonce(self, server_url, timestamp, salt):
"""
This method returns Falase if a nonce has been used before or its
timestamp is not current.
"""
db = self.database
if abs(timestamp - time.time()) > nonce.SKEW:
return False
query = (db.oid_nonces.server_url == server_url) & (db.oid_nonces.itimestamp == timestamp) & (db.oid_nonces.salt == salt)
if db(query).count() > 0:
return False
else:
db.oid_nonces.insert(server_url=server_url,
itimestamp=timestamp,
salt=salt)
return True
示例2: txn_useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def txn_useNonce(self, server_url, timestamp, salt):
"""Return whether this nonce is present, and if it is, then
remove it from the set.
str -> bool"""
if abs(timestamp - time.time()) > nonce.SKEW:
return False
try:
self.db_add_nonce(server_url, timestamp, salt)
except self.exceptions.IntegrityError:
# The key uniqueness check failed
return False
else:
# The nonce was successfully added
return True
示例3: useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def useNonce(self, server_url, timestamp, salt):
"""Called when using a nonce.
This method should return C{True} if the nonce has not been
used before, and store it for a while to make sure nobody
tries to use the same value again. If the nonce has already
been used or the timestamp is not current, return C{False}.
You may use L{openid.store.nonce.SKEW} for your timestamp window.
"""
if is_nonce_old(timestamp):
return False
try:
mist_nonces = MistNonce.objects(server_url=server_url, salt=salt,
timestamp=timestamp)
except me.DoesNotExist:
mist_nonces = []
if len(mist_nonces) == 0:
print "Timestamp = %s" % timestamp
MistNonce(server_url=server_url, salt=salt, timestamp=timestamp).save()
return True
return False
示例4: cleanupNonces
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def cleanupNonces(self):
"""
Remove expired nonce entries from DB and return the number
of entries deleted.
"""
db = self.database
query = (db.oid_nonces.itimestamp < time.time() - nonce.SKEW)
return db(query).delete()
示例5: txn_cleanupNonces
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def txn_cleanupNonces(self):
self.db_clean_nonce(int(time.time()) - nonce.SKEW)
return self.cur.rowcount
示例6: useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def useNonce(self, server_url, timestamp, salt):
"""Return whether this nonce is valid.
str -> bool
"""
if abs(timestamp - time.time()) > nonce.SKEW:
return False
if server_url:
proto, rest = server_url.split('://', 1)
else:
# Create empty proto / rest values for empty server_url,
# which is part of a consumer-generated nonce.
proto, rest = '', ''
domain = _filenameEscape(rest.split('/', 1)[0])
url_hash = _safe64(server_url)
salt_hash = _safe64(salt)
filename = '%08x-%s-%s-%s-%s' % (timestamp, proto, domain,
url_hash, salt_hash)
filename = os.path.join(self.nonce_dir, filename)
try:
fd = os.open(filename, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0200)
except OSError, why:
if why.errno == EEXIST:
return False
else:
raise
else:
os.close(fd)
return True
示例7: cleanupNonces
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def cleanupNonces(self):
nonces = os.listdir(self.nonce_dir)
now = time.time()
removed = 0
# Check all nonces for expiry
for nonce_fname in nonces:
timestamp = nonce_fname.split('-', 1)[0]
timestamp = int(timestamp, 16)
if abs(timestamp - now) > nonce.SKEW:
filename = os.path.join(self.nonce_dir, nonce_fname)
_removeIfPresent(filename)
removed += 1
return removed
示例8: useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def useNonce(self, server_url, timestamp, salt):
if abs(timestamp - time.time()) > nonce.SKEW:
return False
anonce = (str(server_url), int(timestamp), str(salt))
if anonce in self.nonces:
return False
else:
self.nonces[anonce] = None
return True
示例9: is_nonce_old
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def is_nonce_old(timestamp, lifespan=None):
if not lifespan:
lifespan = nonce.SKEW
return abs(time.time() - timestamp) > lifespan
示例10: useNonce
# 需要導入模塊: from openid.store import nonce [as 別名]
# 或者: from openid.store.nonce import SKEW [as 別名]
def useNonce(self, server_url, timestamp, salt):
"""Generate one use number and return *if* it was created"""
if abs(timestamp - time.time()) > SKEW:
return False
return self.nonce.use(server_url, timestamp, salt)