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

Function get_app_from_path

pywebio/platform/path_deploy.py:151–184  ·  view source on GitHub ↗

Get PyWebIO app :param str request_path: request path :param str base: dir base path, MUST a absolute path :param callable index: :return: ('error', http error code in int) / ('app', pywebio task function) / ('html', Html content in bytes)

(request_path, base, index, reload=False)

Source from the content-addressed store, hash-verified

149
150
151def get_app_from_path(request_path, base, index, reload=False):
152 """Get PyWebIO app
153
154 :param str request_path: request path
155 :param str base: dir base path, MUST a absolute path
156 :param callable index:
157 :return: ('error', http error code in int) / ('app', pywebio task function) / ('html', Html content in bytes)
158 """
159 path = valid_and_norm_path(base, request_path)
160 if path is None:
161 return 'error', 403
162
163 if os.path.isdir(path):
164 if not request_path.endswith('/'):
165 return 'error', 404
166
167 if os.path.isfile(os.path.join(path, 'index.py')):
168 path = os.path.join(path, 'index.py')
169 elif index:
170 content = index(path)
171 return 'html', content
172 else:
173 return 'error', 404
174 else:
175 path += '.py'
176
177 if not os.path.isfile(path):
178 return 'error', 404
179
180 module = _get_module(path, reload=reload)
181 if hasattr(module, 'main'):
182 return 'app', make_applications(module.main)
183
184 return 'error', 404
185
186
187def _path_deploy(base, port=0, host='', static_dir=None, max_payload_size=2 ** 20 * 200,

Callers 2

get_appMethod · 0.85
get_appFunction · 0.85

Calls 4

valid_and_norm_pathFunction · 0.85
indexFunction · 0.85
_get_moduleFunction · 0.85
make_applicationsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…