当前位置: 首页>>代码示例>>Python>>正文


Python client.responses方法代码示例

本文整理汇总了Python中http.client.responses方法的典型用法代码示例。如果您正苦于以下问题:Python client.responses方法的具体用法?Python client.responses怎么用?Python client.responses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.client的用法示例。


在下文中一共展示了client.responses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_headers

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def write_headers(
        self,
        start_line: Union["RequestStartLine", "ResponseStartLine"],
        headers: HTTPHeaders,
        chunk: bytes = None,
    ) -> "Future[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.

        The ``version`` field of ``start_line`` is ignored.

        Returns a future for flow control.

        .. versionchanged:: 6.0

           The ``callback`` argument was removed.
        """
        raise NotImplementedError() 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:httputil.py

示例2: write_headers

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
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.

        .. deprecated:: 5.1

           The ``callback`` argument is deprecated and will be removed
           in Tornado 6.0.
        """
        raise NotImplementedError() 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:httputil.py

示例3: _request

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def _request(self, method: str, url: str, params=None, auth=None, data=None):
        if params:
            logger.info('[%s] %s?%s', method.upper(), url, urlencode(params))
        else:
            logger.info('[%s] %s', method.upper(), url)
        if data:
            logger.debug(data)
        response = self.session.request(
            method=method,
            url=url,
            params=params,
            data=data,
            auth=auth,
            headers=self.headers,
            timeout=self.timeout,
            verify=self.verify_cert,
        )
        logger.info('[RESPONSE] %s (%s)', http_responses[response.status_code], response.status_code)
        if response.text:
            if method == 'get':
                logger.debug('\n%s', json.dumps(response.json(), sort_keys=True, indent=4))
            else:
                logger.debug(response.text)
        return response 
开发者ID:kaisero,项目名称:fireREST,代码行数:26,代码来源:__init__.py

示例4: test_handle_build_err

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_handle_build_err(self):
        # Special-cased above for testing.
        self.res.request = FakeHttpRequest('POST')
        settings.DEBUG = False
        self.addCleanup(setattr, settings, 'DEBUG', True)

        resp = self.res.handle('detail')
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 500)
        self.assertEqual(resp.reason_phrase.title(), responses[500])
        self.assertEqual(json.loads(resp.content.decode('utf-8')), {
            'error': {
                'code': 'random-crazy',
                'message': 'This is a random & crazy exception.',
            }
        }) 
开发者ID:toastdriven,项目名称:restless,代码行数:18,代码来源:test_dj.py

示例5: __init__

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def __init__(self, method, url, headers, status_code,
                 response_headers=None, content=None):
        self.method = method
        self.url = url
        self.request_headers = FoldCaseDict()
        for header in headers:
            self.request_headers[header] = headers[header]
        self.status = status_code
        self.headers = response_headers
        self.data = content
        if content is None:
            self.reason = httplib.responses[status_code]

    # noinspection PyUnusedLocal 
开发者ID:minio,项目名称:minio-py,代码行数:16,代码来源:minio_mocks.py

示例6: test_all

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_httplib.py

示例7: test_responses

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_responses(self):
        self.assertEqual(client.responses[client.NOT_FOUND], "Not Found") 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:4,代码来源:test_httplib.py

示例8: detect_broken_links

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def detect_broken_links(self, process_pool):
        """ Go through all the `web_links` and the `relative_links` and report
        which are broken (i.e. do not resolve to HTTP200OK or a file on disk).
        """
        result = process_pool.map(self.validate_url, self.web_links)
        for response, url in result:
            if not response == 200:
                yield url + ' Status: ' + (responses[response] if response is int else "Exception")

        for file in self.relative_links:
            if not os.path.exists(file):
                yield file 
开发者ID:HEInventions,项目名称:docnado,代码行数:14,代码来源:docnado.py

示例9: log_request

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def log_request(action):
    '''
    decorator that adds additional debug logging for api requests
    '''

    def inner_function(f):
        @wraps(f)
        def wrapper(*args, **kwargs):
            logger = args[0].logger
            request = args[1]
            request_id = str(uuid4())[:8]
            try:
                data = args[3]
            except IndexError:
                data = None
            logger.debug('[%s] [%s] %s', request_id, action, request)
            if data:
                logger.debug('[%s] [Data] %s', request_id, data)
            result = f(*args)
            status_code = result.status_code
            status_code_name = http_responses[status_code]
            logger.debug('[%s] [Response] %s (%s)', request_id, status_code_name, status_code)
            if status_code >= 299:
                logger.debug('[%s] [Message] %s', request_id, result.content)
            return result

        return wrapper

    return inner_function 
开发者ID:kaisero,项目名称:fireREST,代码行数:31,代码来源:decorators.py

示例10: test_all

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
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.startswith("_") or 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) 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:15,代码来源:test_httplib.py

示例11: test_handle_not_implemented

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_handle_not_implemented(self):
        self.res.request = FakeHttpRequest('TRACE')

        resp = self.res.handle('list')
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 501)
        self.assertEqual(resp.reason_phrase.title(), responses[501])

        resp_json = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(
            resp_json['error'], "Unsupported method 'TRACE' for list endpoint.")
        self.assertIn('traceback', resp_json) 
开发者ID:toastdriven,项目名称:restless,代码行数:14,代码来源:test_dj.py

示例12: test_handle_not_authenticated

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_handle_not_authenticated(self):
        # Special-cased above for testing.
        self.res.request = FakeHttpRequest('DELETE')

        # First with DEBUG on
        resp = self.res.handle('list')
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 401)
        self.assertEqual(resp.reason_phrase.title(), responses[401])

        resp_json = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(resp_json['error'], 'Unauthorized.')
        self.assertIn('traceback', resp_json)

        # Now with DEBUG off.
        settings.DEBUG = False
        self.addCleanup(setattr, settings, 'DEBUG', True)
        resp = self.res.handle('list')
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 401)
        resp_json = json.loads(resp.content.decode('utf-8'))
        self.assertEqual(resp_json, {
            'error': 'Unauthorized.',
        })
        self.assertNotIn('traceback', resp_json)

        # Last, with bubble_exceptions.
        class Bubbly(DjTestResource):
            def bubble_exceptions(self):
                return True

        with self.assertRaises(Unauthorized):
            bubb = Bubbly()
            bubb.request = FakeHttpRequest('DELETE')
            bubb.handle('list') 
开发者ID:toastdriven,项目名称:restless,代码行数:37,代码来源:test_dj.py

示例13: test_object_does_not_exist

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_object_does_not_exist(self):
        # Make sure we get a proper Not Found exception rather than a
        # generic 500, when code raises a ObjectDoesNotExist exception.
        self.res.request = FakeHttpRequest('GET')
        settings.DEBUG = False
        self.addCleanup(setattr, settings, 'DEBUG', True)

        resp = self.res.handle('detail', 1001)
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 404)
        self.assertEqual(resp.reason_phrase.title(), responses[404])
        self.assertEqual(json.loads(resp.content.decode('utf-8')), {
            'error': 'Model with pk 1001 not found.'
        }) 
开发者ID:toastdriven,项目名称:restless,代码行数:16,代码来源:test_dj.py

示例14: test_http404_exception_handling

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
def test_http404_exception_handling(self):
        # Make sure we get a proper Not Found exception rather than a
        # generic 500, when code raises a Http404 exception.
        res = DjTestResourceHttp404Handling()
        res.request = FakeHttpRequest('GET')
        settings.DEBUG = False
        self.addCleanup(setattr, settings, 'DEBUG', True)

        resp = res.handle('detail', 1001)
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 404)
        self.assertEqual(resp.reason_phrase.title(), responses[404])
        self.assertEqual(json.loads(resp.content.decode('utf-8')), {
            'error': 'Model with pk 1001 not found.'
        }) 
开发者ID:toastdriven,项目名称:restless,代码行数:17,代码来源:test_dj.py

示例15: message

# 需要导入模块: from http import client [as 别名]
# 或者: from http.client import responses [as 别名]
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 
开发者ID:neon-jungle,项目名称:wagtail-linkchecker,代码行数:15,代码来源:scanner.py


注:本文中的http.client.responses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。