MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / valid_and_norm_path

Function valid_and_norm_path

pywebio/platform/path_deploy.py:53–70  ·  view source on GitHub ↗

Join the sub-path to base path. This function always ensure the result path is a subpath of base path. :param str base: MUST a absolute path :param str subpath: sub-path under the `base` path :return: normalized result path. None returned if the sub path is not valid

(base, subpath)

Source from the content-addressed store, hash-verified

51
52
53def valid_and_norm_path(base, subpath):
54 """Join the sub-path to base path. This function always ensure the result path is a subpath of base path.
55
56 :param str base: MUST a absolute path
57 :param str subpath: sub-path under the `base` path
58 :return: normalized result path. None returned if the sub path is not valid
59 """
60 subpath = subpath.lstrip('/')
61 full_path = os.path.normpath(os.path.join(base, subpath))
62 if not full_path.startswith(base):
63 return None
64
65 parts = subpath.split('/')
66 for i in parts:
67 if not filename_ok(i):
68 return None
69
70 return full_path
71
72
73_cached_modules = {}

Callers 1

get_app_from_pathFunction · 0.85

Calls 1

filename_okFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…