From d5f0001950c49fc4dce9f4decb9878daa1b51e90 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 5 Oct 2016 14:16:20 -0500 Subject: [PATCH] small cleanups --- lbrynet/core/utils.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/utils.py b/lbrynet/core/utils.py index 85af1a7c4..46f39f7dc 100644 --- a/lbrynet/core/utils.py +++ b/lbrynet/core/utils.py @@ -18,13 +18,15 @@ blobhash_length = get_lbry_hash_obj().digest_size * 2 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(): return datetime.datetime.now() + def utcnow(): return datetime.datetime.utcnow() + def isonow(): """Return utc now in isoformat with timezone""" return utcnow().isoformat() + 'Z' @@ -42,6 +44,10 @@ def generate_id(num=None): return h.digest() +def is_valid_hashcharacter(char): + return char in "0123456789abcdef" + + def is_valid_blobhash(blobhash): """ @param blobhash: string, the blobhash to check @@ -50,10 +56,7 @@ def is_valid_blobhash(blobhash): """ if len(blobhash) != blobhash_length: return False - for l in blobhash: - if l not in "0123456789abcdef": - return False - return True + return all(is_valid_hashcharacter(l) for l in blobhash) def version_is_greater_than(a, b):