當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。