def get(self): endpoints = [] replace_map = ( ("(?P<status_code>\d{3})", "{status_code: int}", str(choice(list(responses.keys())))), ("(?P<name>.+)", "{name: str}", "test_name"), ("(?P<value>.+)", "{value: str}", "test_value"), ("(?P<num>\d{1,2})", "{redirects_num: int}", '4'), ("(?P<username>.+)", "{username: str}", "test_username"), ("(?P<password>.+)", "{password: str}", "test_password"), ("(?P<qop>.+)", "{quality of protection: auth | auth-int}", "auth"), ("(?P<version>.+)", "{version: float}", "1.0"), ("(?P<consumer_key>.+)", "{consumer_key: str}", random_string(15)), ("(?P<consumer_secret>.+)", "{consumer_secret: str}", random_string(15)), ("(?P<pin>.+)", "{pin: str}", random_string(10)), ("(?P<verifier>.+)", "{pin: str}", random_string(10)), ("(?P<token_key>.+)", "{token_key: str}", random_string(10)), ("(?P<token_secret>.+)", "{token_secret: str}", random_string(10)), ("(?P<tmp_token_key>.+)", "{tmp_token_key: str}", random_string(10)), ("(?P<tmp_token_secret>.+)", "{tmp_token_secret: str}", random_string(10)), # ("(?<consumer_secret>.+)", "{consumer_secret: str}", random_string(15)), ) for point in self.application.dirty_handlers: default_url = point[0] api_format = point[0] for r in replace_map: default_url = default_url.replace(r[0], r[2]) api_format = api_format.replace(r[0], r[1]) description = point[2] if len(point) >= 3 else point[1].__doc__.strip() endpoint = {"default_url": default_url, "api_format": api_format, "description": description} endpoints.append(endpoint) responses_groups = ( (100, 200, "1xx Informational", []), (200, 300, "2xx Success", []), (300, 400, "3xx Redirection", []), (400, 500, "4xx Client Error", []), (500, 600, "5xx Server Error", [])) groups = [] for i, group in enumerate(responses_groups): groups.append([group[0], group[1], group[2], [(k, v, get_status_extdescription(k)) for k, v in responses.items() if group[0] <= k < group[1]]]) self.render("index.html", endpoints=endpoints, groups=groups)
def get(self, status_code): status_code = int(status_code) if status_code not in responses.keys(): raise HTTPError(404) self.set_status(status_code) if status_code in STATUSES_WITHOUT_BODY: self.finish() elif status_code in STATUSES_WITH_LOCATION: self.set_header("Location", self.request.host) elif status_code in STATUSES_WITH_AUHT: self.set_header("WWW-Authenticate", 'Basic realm="Fake Realm"') elif status_code in STATUSES_WITH_PROXY_AUTH: self.set_header("Proxy-Authenticate", 'Basic realm="Fake Realm"') else: self.json_response({"tagline": str(choice(taglines)), "code": status_code, "description": responses.get(status_code)})