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


Python util.status_reasons方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def __init__(self, code=500, title="", explanation=""):
        self.code = code
        # There is a strict rule about constructing status line for HTTP:
        # '...Status-Line, consisting of the protocol version followed by a
        # numeric status code and its associated textual phrase, with each
        # element separated by SP characters'
        # (http://www.faqs.org/rfcs/rfc2616.html)
        # 'code' and 'title' can not be empty because they correspond
        # to numeric status code and its associated text
        if title:
            self.title = title
        else:
            try:
                self.title = status_reasons[self.code]
            except KeyError:
                generic_code = self.code // 100
                self.title = status_generic_reasons[generic_code]
        self.explanation = explanation
        super(ConvertedException, self).__init__() 
開發者ID:cloudbase,項目名稱:vdi-broker,代碼行數:21,代碼來源:exception.py

示例2: wrap_pecan_controller_exception

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def wrap_pecan_controller_exception(func):
    """This decorator wraps pecan controllers to handle exceptions."""
    def _func_server_error(log_correlation_id, status_code):
        pecan.response.status = status_code
        return {
            'faultcode': 'Server',
            'status_code': status_code,
            'title': woutil.status_reasons[status_code],
            'description': six.text_type(OBFUSCATED_MSG % log_correlation_id),
        }

    def _func_client_error(excp, status_code):
        pecan.response.status = status_code
        return {
            'faultcode': 'Client',
            'faultstring': convert_excp_to_err_code(excp.__class__.__name__),
            'status_code': status_code,
            'title': six.text_type(excp),
            'description': six.text_type(excp),
        }

    return wrap_controller_exception(func,
                                     _func_server_error,
                                     _func_client_error) 
開發者ID:openstack,項目名稱:zun,代碼行數:26,代碼來源:exception.py

示例3: _status__set

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def _status__set(self, value):
        if isinstance(value, int):
            self.status_code = value
            return
        if PY3: # pragma: no cover
            if isinstance(value, bytes):
                value = value.decode('ascii')
        elif isinstance(value, text_type):
            value = value.encode('ascii')
        if not isinstance(value, str):
            raise TypeError(
                "You must set status to a string or integer (not %s)"
                % type(value))
        if ' ' not in value:
             try:
                value += ' ' + status_reasons[int(value)]
             except KeyError:
                value += ' ' + status_generic_reasons[int(value) // 100]
        self._status = value 
開發者ID:yuxiaokui,項目名稱:Intranet-Penetration,代碼行數:21,代碼來源:response.py

示例4: __init__

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def __init__(self, code, title="", explanation=""):
        self.code = code
        # There is a strict rule about constructing status line for HTTP:
        # '...Status-Line, consisting of the protocol version followed by a
        # numeric status code and its associated textual phrase, with each
        # element separated by SP characters'
        # (http://www.faqs.org/rfcs/rfc2616.html)
        # 'code' and 'title' can not be empty because they correspond
        # to numeric status code and its associated text
        if title:
            self.title = title
        else:
            try:
                self.title = woutil.status_reasons[self.code]
            except KeyError:
                msg = "Improper or unknown HTTP status code used: %d"
                LOG.error(msg, code)
                self.title = woutil.status_generic_reasons[self.code // 100]
        self.explanation = explanation
        super(ConvertedException, self).__init__() 
開發者ID:openstack,項目名稱:masakari,代碼行數:22,代碼來源:exception.py

示例5: __init__

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def __init__(self, code, title="", explanation=""):
        self.code = code
        # There is a strict rule about constructing status line for HTTP:
        # '...Status-Line, consisting of the protocol version followed by a
        # numeric status code and its associated textual phrase, with each
        # element separated by SP characters'
        # (http://www.faqs.org/rfcs/rfc2616.html)
        # 'code' and 'title' can not be empty because they correspond
        # to numeric status code and its associated text
        if title:
            self.title = title
        else:
            try:
                self.title = woutil.status_reasons[self.code]
            except KeyError:
                msg = _LE("Improper or unknown HTTP status code used: %d")
                LOG.error(msg, code)
                self.title = woutil.status_generic_reasons[self.code // 100]
        self.explanation = explanation
        super(ConvertedException, self).__init__() 
開發者ID:BU-NU-CLOUD-SP16,項目名稱:Trusted-Platform-Module-nova,代碼行數:22,代碼來源:exception.py

示例6: _status_code__set

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def _status_code__set(self, code):
        try:
            self._status = '%d %s' % (code, status_reasons[code])
        except KeyError:
            self._status = '%d %s' % (code, status_generic_reasons[code // 100]) 
開發者ID:yuxiaokui,項目名稱:Intranet-Penetration,代碼行數:7,代碼來源:response.py

示例7: test_instantiate_without_title_known_code

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def test_instantiate_without_title_known_code(self):
        exc = exception.ConvertedException(int(http.INTERNAL_SERVER_ERROR))
        self.assertEqual(exc.title, status_reasons[http.INTERNAL_SERVER_ERROR]) 
開發者ID:openstack,項目名稱:masakari,代碼行數:5,代碼來源:test_exception.py

示例8: test_instantiate_without_title_known_code

# 需要導入模塊: from webob import util [as 別名]
# 或者: from webob.util import status_reasons [as 別名]
def test_instantiate_without_title_known_code(self):
        exc = exception.ConvertedException(500)
        self.assertEqual(exc.title, status_reasons[500]) 
開發者ID:BU-NU-CLOUD-SP16,項目名稱:Trusted-Platform-Module-nova,代碼行數:5,代碼來源:test_exception.py


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