Move random_hex function to voussoirkit/passwordy.
This commit is contained in:
parent
9b8159c453
commit
11b846a3e0
4 changed files with 6 additions and 9 deletions
|
@ -379,12 +379,6 @@ def parse_unit_string(s):
|
||||||
else:
|
else:
|
||||||
return bytestring.parsebytes(s)
|
return bytestring.parsebytes(s)
|
||||||
|
|
||||||
def random_hex(length=12):
|
|
||||||
randbytes = os.urandom(math.ceil(length / 2))
|
|
||||||
token = ''.join('{:02x}'.format(x) for x in randbytes)
|
|
||||||
token = token[:length]
|
|
||||||
return token
|
|
||||||
|
|
||||||
def read_filebytes(filepath, range_min=0, range_max=None, chunk_size=bytestring.MIBIBYTE):
|
def read_filebytes(filepath, range_min=0, range_max=None, chunk_size=bytestring.MIBIBYTE):
|
||||||
'''
|
'''
|
||||||
Yield chunks of bytes from the file between the endpoints.
|
Yield chunks of bytes from the file between the endpoints.
|
||||||
|
|
|
@ -11,6 +11,7 @@ import types
|
||||||
from voussoirkit import cacheclass
|
from voussoirkit import cacheclass
|
||||||
from voussoirkit import configlayers
|
from voussoirkit import configlayers
|
||||||
from voussoirkit import expressionmatch
|
from voussoirkit import expressionmatch
|
||||||
|
from voussoirkit import passwordy
|
||||||
from voussoirkit import pathclass
|
from voussoirkit import pathclass
|
||||||
from voussoirkit import ratelimiter
|
from voussoirkit import ratelimiter
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
@ -1077,7 +1078,7 @@ class PDBSQLMixin:
|
||||||
self.on_commit_queue.clear()
|
self.on_commit_queue.clear()
|
||||||
|
|
||||||
def savepoint(self, message=None):
|
def savepoint(self, message=None):
|
||||||
savepoint_id = helpers.random_hex(length=16)
|
savepoint_id = passwordy.random_hex(length=16)
|
||||||
if message:
|
if message:
|
||||||
self.log.log(5, 'Savepoint %s for %s.', savepoint_id, message)
|
self.log.log(5, 'Savepoint %s for %s.', savepoint_id, message)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,6 +3,7 @@ import functools
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from voussoirkit import cacheclass
|
from voussoirkit import cacheclass
|
||||||
|
from voussoirkit import passwordy
|
||||||
|
|
||||||
import etiquette
|
import etiquette
|
||||||
|
|
||||||
|
@ -48,7 +49,7 @@ def cached_endpoint(max_age):
|
||||||
value = value.response
|
value = value.response
|
||||||
if value != state['stored_value']:
|
if value != state['stored_value']:
|
||||||
state['stored_value'] = value
|
state['stored_value'] = value
|
||||||
state['stored_etag'] = etiquette.helpers.random_hex(20)
|
state['stored_etag'] = passwordy.random_hex(20)
|
||||||
state['headers']['ETag'] = state['stored_etag']
|
state['headers']['ETag'] = state['stored_etag']
|
||||||
state['last_run'] = time.time()
|
state['last_run'] = time.time()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -4,6 +4,7 @@ import werkzeug.wrappers
|
||||||
import werkzeug.datastructures
|
import werkzeug.datastructures
|
||||||
|
|
||||||
from voussoirkit import cacheclass
|
from voussoirkit import cacheclass
|
||||||
|
from voussoirkit import passwordy
|
||||||
|
|
||||||
import etiquette
|
import etiquette
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ REQUEST_TYPES = (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalP
|
||||||
RESPONSE_TYPES = (flask.Response, werkzeug.wrappers.Response)
|
RESPONSE_TYPES = (flask.Response, werkzeug.wrappers.Response)
|
||||||
|
|
||||||
def _generate_token(length=32):
|
def _generate_token(length=32):
|
||||||
return etiquette.helpers.random_hex(length=length)
|
return passwordy.random_hex(length=length)
|
||||||
|
|
||||||
def _normalize_token(token):
|
def _normalize_token(token):
|
||||||
if isinstance(token, REQUEST_TYPES):
|
if isinstance(token, REQUEST_TYPES):
|
||||||
|
|
Loading…
Reference in a new issue