我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用http.client.responses()。
def test_responses(self): self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
def __init__(self): self.method = None self.uri_template = None self.summary = '' self.description = '' self.parameters = [] self.responses = {} self.default_response_schema = None self.response_headers = None
def add_response_codes(self, status_dict): for code, info in status_dict.items(): swagger_rsp = self.responses.setdefault(code, {}) if not info['reason']: try: code = int(code) info['reason'] = http_client.responses[code] except (KeyError, TypeError, ValueError): info['reason'] = 'Unknown' tokens = info['description'].split(maxsplit=2) if tokens: tokens[0] = tokens[0].title() swagger_rsp['description'] = '{}\n\n{}'.format( info['reason'], ' '.join(tokens)).strip()
def generate_swagger(self): swagger = {'summary': self.summary, 'description': self.description} if self.parameters: swagger['parameters'] = self.parameters if self.responses: swagger['responses'] = self.responses else: # swagger requires at least one response swagger['responses'] = {'default': {'description': ''}} # Figure out where to put the response schema and response # header details. This is probably going to change in the # future since it is `hinky' at best. default_code = 'default' status_codes = sorted(int(code) for code in swagger['responses'] if code.isdigit()) for code in status_codes: if 200 <= code < 400: default_code = str(code) break if default_code in swagger['responses']: if self.default_response_schema: swagger['responses'][default_code]['schema'] = \ self.default_response_schema if self.response_headers: swagger['responses'][default_code]['headers'] = \ self.response_headers return swagger
def test_all(self): # Documented objects defined in the module should be in __all__ expected = {"responses"} # White-list documented dict() object # HTTPMessage, parse_headers(), and the HTTP status code constants are # intentionally omitted for simplicity blacklist = {"HTTPMessage", "parse_headers"} for name in dir(client): if name in blacklist: continue module_object = getattr(client, name) if getattr(module_object, "__module__", None) == "http.client": expected.add(name) self.assertCountEqual(client.__all__, expected)
def write_headers(self, start_line, headers, chunk=None, callback=None): """Write an HTTP header block. :arg start_line: a `.RequestStartLine` or `.ResponseStartLine`. :arg headers: a `.HTTPHeaders` instance. :arg chunk: the first (optional) chunk of data. This is an optimization so that small responses can be written in the same call as their headers. :arg callback: a callback to be run when the write is complete. The ``version`` field of ``start_line`` is ignored. Returns a `.Future` if no callback is given. """ raise NotImplementedError()
def message(self): if self.error: return self.error elif self.status_code in range(100, 300): message = "Success" elif self.status_code in range(500, 600) and self.url.startswith(self.site.root_url): message = str(self.status_code) + ': ' + _('Internal server error, please notify the site administrator.') else: try: message = str(self.status_code) + ': ' + client.responses[self.status_code] + '.' except KeyError: message = str(self.status_code) + ': ' + _('Unknown error.') return message