Completed
Push — master ( 77ef8d...d45822 )
by Simon
02:00
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
"""
22
def is_sha1(maybe_sha):
23
    if len(maybe_sha) != 40:
24
        return False
25
    try:
26
        sha_int = int(maybe_sha, 16)
27
    except ValueError:
28
        return False
29
    return True
30
"""
31