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

hyperactive.memory.util.get_model_id()   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 1
dl 0
loc 2
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