forked from LBRYCommunity/lbry-sdk
small cleanups
This commit is contained in:
parent
4a07b56e8a
commit
d5f0001950
1 changed files with 8 additions and 5 deletions
|
@ -18,13 +18,15 @@ blobhash_length = get_lbry_hash_obj().digest_size * 2
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# defining this here allows for easier overriding in testing
|
# defining these time functions here allows for easier overriding in testing
|
||||||
def now():
|
def now():
|
||||||
return datetime.datetime.now()
|
return datetime.datetime.now()
|
||||||
|
|
||||||
|
|
||||||
def utcnow():
|
def utcnow():
|
||||||
return datetime.datetime.utcnow()
|
return datetime.datetime.utcnow()
|
||||||
|
|
||||||
|
|
||||||
def isonow():
|
def isonow():
|
||||||
"""Return utc now in isoformat with timezone"""
|
"""Return utc now in isoformat with timezone"""
|
||||||
return utcnow().isoformat() + 'Z'
|
return utcnow().isoformat() + 'Z'
|
||||||
|
@ -42,6 +44,10 @@ def generate_id(num=None):
|
||||||
return h.digest()
|
return h.digest()
|
||||||
|
|
||||||
|
|
||||||
|
def is_valid_hashcharacter(char):
|
||||||
|
return char in "0123456789abcdef"
|
||||||
|
|
||||||
|
|
||||||
def is_valid_blobhash(blobhash):
|
def is_valid_blobhash(blobhash):
|
||||||
"""
|
"""
|
||||||
@param blobhash: string, the blobhash to check
|
@param blobhash: string, the blobhash to check
|
||||||
|
@ -50,10 +56,7 @@ def is_valid_blobhash(blobhash):
|
||||||
"""
|
"""
|
||||||
if len(blobhash) != blobhash_length:
|
if len(blobhash) != blobhash_length:
|
||||||
return False
|
return False
|
||||||
for l in blobhash:
|
return all(is_valid_hashcharacter(l) for l in blobhash)
|
||||||
if l not in "0123456789abcdef":
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def version_is_greater_than(a, b):
|
def version_is_greater_than(a, b):
|
||||||
|
|
Loading…
Add table
Reference in a new issue