def wsgi_app(environ, start_response, enable_static=False): if environ['REQUEST_METHOD'] == 'OPTIONS': # This is to hanle the preflight request for CORS. # See https://developer.mozilla.org/en/http_access_control response = Response() response.status = "200 OK" else: params = extract_params(environ) log('------') path = environ['PATH_INFO'].split(environ['HTTP_HOST'])[-1] if BASE_PATH: path = path.split(BASE_PATH)[1] log(path) try: if '/pico/' in path: path = path.replace('/pico/', '/') try: response = handle_api_v1(path, params, environ) except APIError: try: response = handle_pico_js(path, params) except APIError: try: response = handle_api_v2(path, params, environ) except APIError: response = not_found_error(path) elif enable_static: try: response = static_file_handler(path) except OSError, e: response = not_found_error(path) else:
def wsgi_app(environ, start_response, enable_static=False): if environ['REQUEST_METHOD'] == 'OPTIONS': # This is to hanle the preflight request for CORS. # See https://developer.mozilla.org/en/http_access_control response = Response() response.status = "200 OK" else: params = extract_params(environ) log('------') path = environ['PATH_INFO'].split(environ['HTTP_HOST'])[-1] if BASE_PATH: path = path.split(BASE_PATH)[1] log(path) try: if '/pico/' in path: path = path.replace('/pico/', '/') try: response = handle_api_v1(path, params, environ) except APIError: try: response = handle_pico_js(path, params) except APIError: try: response = handle_api_v2(path, params, environ) except APIError: response = not_found_error(path) elif enable_static: try: response = static_file_handler(path) except OSError, e: response = not_found_error(path) else:
def generate_exception_report(e, path, params): response = Response() full_tb = traceback.extract_tb(sys.exc_info()[2]) tb_str = '' for tb in full_tb: tb_str += "File '%s', line %s, in %s; " % (tb[0], tb[1], tb[2]) report = {} report['exception'] = str(e) report['traceback'] = tb_str report['url'] = path.replace('/pico/', '/') report['params'] = dict([(k, _value_summary(params[k])) for k in params]) log(json.dumps(report, indent=1)) response.content = report response.status = '500 ' + str(e) return response
def generate_exception_report(e, path, params): response = Response() full_tb = traceback.extract_tb(sys.exc_info()[2]) tb_str = '' for tb in full_tb: tb_str += "File '%s', line %s, in %s; " % (tb[0], tb[1], tb[2]) report = {} report['exception'] = str(e) report['traceback'] = tb_str report['url'] = path.replace('/pico/', '/') report['params'] = dict([(k, _value_summary(params[k])) for k in params]) log(json.dumps(report, indent=1)) response.content = report response.status = '500 ' + str(e) return response
def wsgi_app(self, environ, start_response, enable_static=False): if environ['REQUEST_METHOD'] == 'OPTIONS': # This is to hanle the preflight request for CORS. # See https://developer.mozilla.org/en/http_access_control response = Response() response.status = "200 OK" else: params = self.extract_params(environ) self.log('------') path = environ['PATH_INFO'].split(environ['HTTP_HOST'])[-1] if BASE_PATH: path = path.split(BASE_PATH)[1] self.log(path) path = path.replace('/pico/', '/') try: response = self.handle_api_v2(path, params, environ) except PicoError, e: response = e.response except False, e: response = self.generate_exception_report(e, path, params)
def not_found_error(path): response = Response() response.status = '404 NOT FOUND' response.content = '404 File not found' response.type = 'plaintext' return response
def not_found_error(path): response = Response() response.status = '404 NOT FOUND' response.content = '404 File not found' response.type = 'plaintext' return response