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)
| 149 | |
| 150 | |
| 151 | def 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 | |
| 187 | def _path_deploy(base, port=0, host='', static_dir=None, max_payload_size=2 ** 20 * 200, |
no test coverage detected
searching dependent graphs…