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

hyperactive.memory.util   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 6

4 Functions

Rating   Name   Duplication   Size   Complexity  
A is_sha1() 0 8 3
A get_model_id() 0 2 1
A get_func_str() 0 2 1
A get_hash() 0 2 1
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