Total Complexity | 6 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Changes | 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 |