9
9
10
10
if TYPE_CHECKING :
11
11
from typing import Literal
12
+ from os import PathLike
12
13
13
14
14
15
class HashError (e3 .error .E3Error ):
15
16
pass
16
17
17
18
18
19
def __compute_hash (
19
- path : str , kind : Literal ["md5" ] | Literal ["sha1" ] | Literal ["sha256" ]
20
+ path : PathLike [str ] | str ,
21
+ kind : Literal ["md5" ] | Literal ["sha1" ] | Literal ["sha256" ],
20
22
) -> str :
21
23
if not os .path .isfile (path ):
22
24
raise HashError (kind , f"cannot find { path } " )
@@ -31,7 +33,7 @@ def __compute_hash(
31
33
return result .hexdigest ()
32
34
33
35
34
- def md5 (path : str ) -> str :
36
+ def md5 (path : PathLike [ str ] | str ) -> str :
35
37
"""Compute md5 hexadecimal digest of a file.
36
38
37
39
:param path: path to a file
@@ -42,7 +44,7 @@ def md5(path: str) -> str:
42
44
return __compute_hash (path , "md5" )
43
45
44
46
45
- def sha1 (path : str ) -> str :
47
+ def sha1 (path : PathLike [ str ] | str ) -> str :
46
48
"""Compute sha1 hexadecimal digest of a file.
47
49
48
50
:param str path: path to a file
@@ -53,7 +55,7 @@ def sha1(path: str) -> str:
53
55
return __compute_hash (path , "sha1" )
54
56
55
57
56
- def sha256 (path : str ) -> str :
58
+ def sha256 (path : PathLike [ str ] | str ) -> str :
57
59
"""Compute sha256 hexadecimal digest of a file.
58
60
59
61
:param str path: path to a file
0 commit comments