MCPcopy Create free account
hub / github.com/MotrixLab/insactor / check_path_suffix

Function check_path_suffix

diffplanner/utils/path_utils.py:13–51  ·  view source on GitHub ↗

Check whether the suffix of the path is allowed. Args: path_str (str): Path to check. allowed_suffix (List[str], optional): What extension names are allowed. Offer a list like ['.jpg', ',jpeg']. When it's [], all will be received.

(path_str: str,
                      allowed_suffix: Union[str, List[str]] = '')

Source from the content-addressed store, hash-verified

11
12
13def check_path_suffix(path_str: str,
14 allowed_suffix: Union[str, List[str]] = '') -> bool:
15 """Check whether the suffix of the path is allowed.
16
17 Args:
18 path_str (str):
19 Path to check.
20 allowed_suffix (List[str], optional):
21 What extension names are allowed.
22 Offer a list like ['.jpg', ',jpeg'].
23 When it's [], all will be received.
24 Use [''] then directory is allowed.
25 Defaults to [].
26
27 Returns:
28 bool:
29 True: suffix test passed
30 False: suffix test failed
31 """
32 if isinstance(allowed_suffix, str):
33 allowed_suffix = [allowed_suffix]
34 pathinfo = Path(path_str)
35 suffix = pathinfo.suffix.lower()
36 if len(allowed_suffix) == 0:
37 return True
38 if pathinfo.is_dir():
39 if '' in allowed_suffix:
40 return True
41 else:
42 return False
43 else:
44 for index, tmp_suffix in enumerate(allowed_suffix):
45 if not tmp_suffix.startswith('.'):
46 tmp_suffix = '.' + tmp_suffix
47 allowed_suffix[index] = tmp_suffix.lower()
48 if suffix in allowed_suffix:
49 return True
50 else:
51 return False
52
53
54class Existence(Enum):

Callers 2

prepare_output_pathFunction · 0.85
check_input_pathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected