Python http.client 模块,responses() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用http.client.responses()

项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
def test_responses(self):
        self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
def test_responses(self):
        self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
项目:sphinx-swagger    作者:dave-shawley    | 项目源码 | 文件源码
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
项目:sphinx-swagger    作者:dave-shawley    | 项目源码 | 文件源码
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()
项目:sphinx-swagger    作者:dave-shawley    | 项目源码 | 文件源码
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
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_responses(self):
        self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
项目:aweasome_learning    作者:Knight-ZXW    | 项目源码 | 文件源码
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()
项目:zenchmarks    作者:squeaky-pl    | 项目源码 | 文件源码
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()
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_responses(self):
        self.assertEqual(client.responses[client.NOT_FOUND], "Not Found")
项目:browser_vuln_check    作者:lcatro    | 项目源码 | 文件源码
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()
项目:TornadoWeb    作者:VxCoder    | 项目源码 | 文件源码
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()
项目:wagtail-linkchecker    作者:takeflight    | 项目源码 | 文件源码
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
项目:ProgrameFacil    作者:Gpzim98    | 项目源码 | 文件源码
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()
项目:ProgrameFacil    作者:Gpzim98    | 项目源码 | 文件源码
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()