Completed
Push — master ( 2b17b1...77ef8d )
by Simon
03:52
created

hyperactive.memory.util.is_sha1()   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import inspect
6
import hashlib
7
8
9
def get_func_str(func):
10
    return inspect.getsource(func)
11
12
13
def get_hash(object):
14
    return hashlib.sha1(object).hexdigest()
15
16
17
def get_model_id(model):
18
    return str(get_hash(get_func_str(model).encode("utf-8")))
19
20
21
def is_sha1(maybe_sha):
22
    if len(maybe_sha) != 40:
23
        return False
24
    try:
25
        sha_int = int(maybe_sha, 16)
26
    except ValueError:
27
        return False
28
    return True
29