forked from zmh-program/blob-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
31 lines (19 loc) · 776 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from hashlib import sha256, md5
from typing import List
def sha2_file(filename) -> str:
"""Returns hash of file."""
with open(filename, "rb") as buffer:
return sha256(buffer.read()).hexdigest()
def md5_file(filename) -> str:
"""Returns hash of file."""
with open(filename, "rb") as buffer:
return md5(buffer.read()).hexdigest()
def sha2_encode(string) -> str:
"""Returns hash of string."""
return sha256(string.encode("utf-8")).hexdigest()
def md5_encode(string) -> str:
"""Returns hash of string."""
return md5(string.encode("utf-8")).hexdigest()
def contains(value: str, items: List[str]) -> bool:
"""Returns True if value is in items or contains it."""
return any(item in value for item in items if item)