當前位置: 首頁>>代碼示例>>Python>>正文


Python httputil.responses方法代碼示例

本文整理匯總了Python中tornado.httputil.responses方法的典型用法代碼示例。如果您正苦於以下問題:Python httputil.responses方法的具體用法?Python httputil.responses怎麽用?Python httputil.responses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.httputil的用法示例。


在下文中一共展示了httputil.responses方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_status

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def set_status(self, status_code, reason=None):
        """設置響應的狀態碼.

        :arg int status_code: 響應狀態碼. 如果 ``reason`` 是 ``None``,
            它必須存在於 `httplib.responses <http.client.responses>`.
        :arg string reason: 用人類可讀的原因短語來描述狀態碼.
            如果是 ``None``, 它會由來自
            `httplib.responses <http.client.responses>` 的reason填滿.
        """
        self._status_code = status_code
        if reason is not None:
            self._reason = escape.native_str(reason)
        else:
            try:
                self._reason = httputil.responses[status_code]
            except KeyError:
                raise ValueError("unknown status code %d", status_code) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:19,代碼來源:web.py

示例2: _handle_request_exception

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def _handle_request_exception(self, e):
        if isinstance(e, Finish):
            # Not an error; just finish the request without logging.
            if not self._finished:
                self.finish(*e.args)
            return
        try:
            self.log_exception(*sys.exc_info())
        except Exception:
            # An error here should still get a best-effort send_error()
            # to avoid leaking the connection.
            app_log.error("Error in exception logger", exc_info=True)
        if self._finished:
            # Extra errors after the request has been finished should
            # be logged, but there is no reason to continue to try and
            # send a response.
            return
        if isinstance(e, HTTPError):
            if e.status_code not in httputil.responses and not e.reason:
                gen_log.error("Bad HTTP status code: %d", e.status_code)
                self.send_error(500, exc_info=sys.exc_info())
            else:
                self.send_error(e.status_code, exc_info=sys.exc_info())
        else:
            self.send_error(500, exc_info=sys.exc_info()) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:27,代碼來源:web.py

示例3: set_status

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def set_status(self, status_code: int, reason: str = None) -> None:
        """Sets the status code for our response.

        :arg int status_code: Response status code.
        :arg str reason: Human-readable reason phrase describing the status
            code. If ``None``, it will be filled in from
            `http.client.responses` or "Unknown".

        .. versionchanged:: 5.0

           No longer validates that the response code is in
           `http.client.responses`.
        """
        self._status_code = status_code
        if reason is not None:
            self._reason = escape.native_str(reason)
        else:
            self._reason = httputil.responses.get(status_code, "Unknown") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:20,代碼來源:web.py

示例4: _clear_headers_for_304

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def _clear_headers_for_304(self) -> None:
        # 304 responses should not contain entity headers (defined in
        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1)
        # not explicitly allowed by
        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
        headers = [
            "Allow",
            "Content-Encoding",
            "Content-Language",
            "Content-Length",
            "Content-MD5",
            "Content-Range",
            "Content-Type",
            "Last-Modified",
        ]
        for h in headers:
            self.clear_header(h) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:19,代碼來源:web.py

示例5: clear

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def clear(self):
        """Resets all headers and content for this response."""
        self._headers = httputil.HTTPHeaders({
            "Server": "TornadoServer/%s" % tornado.version,
            "Content-Type": "text/html; charset=UTF-8",
            "Date": httputil.format_timestamp(time.time()),
        })
        self.set_default_headers()
        if (not self.request.supports_http_1_1() and
            getattr(self.request, 'connection', None) and
                not self.request.connection.no_keep_alive):
            conn_header = self.request.headers.get("Connection")
            if conn_header and (conn_header.lower() == "keep-alive"):
                self.set_header("Connection", "Keep-Alive")
        self._write_buffer = []
        self._status_code = 200
        self._reason = httputil.responses[200] 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:19,代碼來源:web.py

示例6: set_status

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def set_status(self, status_code, reason=None):
        """Sets the status code for our response.

        :arg int status_code: Response status code. If ``reason`` is ``None``,
            it must be present in `httplib.responses <http.client.responses>`.
        :arg string reason: Human-readable reason phrase describing the status
            code. If ``None``, it will be filled in from
            `httplib.responses <http.client.responses>`.
        """
        self._status_code = status_code
        if reason is not None:
            self._reason = escape.native_str(reason)
        else:
            try:
                self._reason = httputil.responses[status_code]
            except KeyError:
                raise ValueError("unknown status code %d", status_code) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:19,代碼來源:web.py

示例7: set_status

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def set_status(self, status_code, reason=None):
        """Sets the status code for our response.

        :arg int status_code: Response status code.
        :arg str reason: Human-readable reason phrase describing the status
            code. If ``None``, it will be filled in from
            `http.client.responses` or "Unknown".

        .. versionchanged:: 5.0

           No longer validates that the response code is in
           `http.client.responses`.
        """
        self._status_code = status_code
        if reason is not None:
            self._reason = escape.native_str(reason)
        else:
            self._reason = httputil.responses.get(status_code, "Unknown") 
開發者ID:tp4a,項目名稱:teleport,代碼行數:20,代碼來源:web.py

示例8: clear

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def clear(self):
        """重置這個響應的所有頭部和內容."""
        self._headers = httputil.HTTPHeaders({
            "Server": "TornadoServer/%s" % tornado.version,
            "Content-Type": "text/html; charset=UTF-8",
            "Date": httputil.format_timestamp(time.time()),
        })
        self.set_default_headers()
        self._write_buffer = []
        self._status_code = 200
        self._reason = httputil.responses[200] 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:13,代碼來源:web.py

示例9: _clear_headers_for_304

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def _clear_headers_for_304(self):
        # 304 responses should not contain entity headers (defined in
        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1)
        # not explicitly allowed by
        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
        headers = ["Allow", "Content-Encoding", "Content-Language",
                   "Content-Length", "Content-MD5", "Content-Range",
                   "Content-Type", "Last-Modified"]
        for h in headers:
            self.clear_header(h) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:12,代碼來源:web.py

示例10: __str__

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def __str__(self):
        message = "HTTP %d: %s" % (
            self.status_code,
            self.reason or httputil.responses.get(self.status_code, 'Unknown'))
        if self.log_message:
            return message + " (" + (self.log_message % self.args) + ")"
        else:
            return message 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:10,代碼來源:web.py

示例11: clear

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def clear(self) -> None:
        """Resets all headers and content for this response."""
        self._headers = httputil.HTTPHeaders(
            {
                "Server": "TornadoServer/%s" % tornado.version,
                "Content-Type": "text/html; charset=UTF-8",
                "Date": httputil.format_timestamp(time.time()),
            }
        )
        self.set_default_headers()
        self._write_buffer = []  # type: List[bytes]
        self._status_code = 200
        self._reason = httputil.responses[200] 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:15,代碼來源:web.py

示例12: __str__

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def __str__(self) -> str:
        message = "HTTP %d: %s" % (
            self.status_code,
            self.reason or httputil.responses.get(self.status_code, "Unknown"),
        )
        if self.log_message:
            return message + " (" + (self.log_message % self.args) + ")"
        else:
            return message 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:11,代碼來源:web.py

示例13: _handle_request_exception

# 需要導入模塊: from tornado import httputil [as 別名]
# 或者: from tornado.httputil import responses [as 別名]
def _handle_request_exception(self, e):
        self.log_exception(*sys.exc_info())
        if self._finished:
            # Extra errors after the request has been finished should
            # be logged, but there is no reason to continue to try and
            # send a response.
            return
        if isinstance(e, HTTPError):
            if e.status_code not in httputil.responses and not e.reason:
                gen_log.error("Bad HTTP status code: %d", e.status_code)
                self.send_error(500, exc_info=sys.exc_info())
            else:
                self.send_error(e.status_code, exc_info=sys.exc_info())
        else:
            self.send_error(500, exc_info=sys.exc_info()) 
開發者ID:viewfinderco,項目名稱:viewfinder,代碼行數:17,代碼來源:web.py


注:本文中的tornado.httputil.responses方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。