本文整理汇总了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)