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


Python exc.HTTPError方法代碼示例

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


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

示例1: handle_exceptions

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def handle_exceptions(operation_name=u._('System')):
    """Decorator handling generic exceptions from REST methods."""

    def exceptions_decorator(fn):

        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError:
                LOG.exception(u._LE('Webob error seen'))
                raise  # Already converted to Webob exception, just reraise
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)

        return handler

    return exceptions_decorator 
開發者ID:cloud-security-research,項目名稱:sgx-kms,代碼行數:25,代碼來源:__init__.py

示例2: translate

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def translate(translatable, locale):
    """Translate the object to the given locale.

    If the object is an exception its translatable elements are translated
    in place, if the object is a translatable string it is translated and
    returned. Otherwise, the object is returned as-is.

    :param translatable: the object to be translated
    :param locale: the locale to translate to
    :returns: the translated object, or the object as-is if it
              was not translated
    """
    localize = oslo_i18n.translate
    if isinstance(translatable, exceptions.TackerException):
        translatable.msg = localize(translatable.msg, locale)
    elif isinstance(translatable, exc.HTTPError):
        translatable.detail = localize(translatable.detail, locale)
    elif isinstance(translatable, Exception):
        translatable.message = localize(translatable, locale)
    else:
        return localize(translatable, locale)
    return translatable 
開發者ID:openstack,項目名稱:tacker,代碼行數:24,代碼來源:api_common.py

示例3: handle_exceptions

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def handle_exceptions(operation_name=u._('System')):
    """Decorator handling generic exceptions from REST methods."""

    def exceptions_decorator(fn):

        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError:
                LOG.exception('Webob error seen')
                raise  # Already converted to Webob exception, just reraise
            # In case PolicyNotAuthorized, we do not want to expose payload by
            # logging exception, so just LOG.error
            except policy.PolicyNotAuthorized as pna:
                status, message = api.generate_safe_exception_message(
                    operation_name, pna)
                LOG.error(message)
                pecan.abort(status, message)
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)

        return handler

    return exceptions_decorator 
開發者ID:openstack,項目名稱:barbican,代碼行數:32,代碼來源:__init__.py

示例4: translate_exception

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def translate_exception(ex, locale):
    """Translate all translatable elements of the given exception."""
    if isinstance(ex, exception.SenlinException):
        ex.message = oslo_i18n.translate(ex.message, locale)
    else:
        ex.message = oslo_i18n.translate(str(ex), locale)

    if isinstance(ex, exc.HTTPError):
        ex.explanation = oslo_i18n.translate(ex.explanation, locale)
        ex.detail = oslo_i18n.translate(getattr(ex, 'detail', ''), locale)
    return ex 
開發者ID:openstack,項目名稱:senlin,代碼行數:13,代碼來源:wsgi.py

示例5: nav_data

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def nav_data(self, admin_options=False, navbar_entries=None):
        """
        Return data about project nav entries

        :param bool admin_options: include admin options?
        :param navbar_entries: for performance, include this if you already have grouped_navbar_entries data
        :return:
        """
        from allura.ext.admin.admin_main import ProjectAdminRestController

        grouping_threshold = self.get_tool_data('allura', 'grouping_threshold', 1)
        anchored_tools = self.neighborhood.get_anchored_tools()
        children = []

        def make_entry(s, app_config):
            entry = dict(name=s.label,
                         url=s.url,
                         icon=s.ui_icon or 'tool-admin',
                         tool_name=s.tool_name or 'sub',
                         mount_point=s.mount_point,
                         is_anchored=s.tool_name in list(anchored_tools.keys()),
                         )
            if admin_options and app_config:
                try:
                    entry['admin_options'] = ProjectAdminRestController().admin_options(app_config)['options']
                except exc.HTTPError:
                    log.debug('Could not get admin_options mount_point for tool: %s', s.url, exc_info=True)
            if admin_options and not s.tool_name:
                entry['admin_options'] = [dict(text='Subproject Admin', href=s.url + 'admin', className=None)]
            return entry

        if navbar_entries is None:
            navbar_entries = self.grouped_navbar_entries()
        tools_by_mount = {ac.options.mount_point: ac for ac in self.app_configs if ac.options.mount_point}
        for s in navbar_entries:
            entry = make_entry(s, tools_by_mount.get(s.mount_point))
            if s.children:
                entry['children'] = [make_entry(child, tools_by_mount.get(child.mount_point))
                                     for child in s.children]
            children.append(entry)

        response = dict(grouping_threshold=grouping_threshold, menu=children)

        if admin_options:
            _href = '{}admin/install_tool?tool_name={}'
            response['installable_tools'] = [dict(text=t['tool_label'],
                                                  href=_href.format(self.url(), t['name']),
                                                  tooltip=t['description'])
                                             for t in ProjectAdminRestController().installable_tools()['tools']]
        return response 
開發者ID:apache,項目名稱:allura,代碼行數:52,代碼來源:project.py

示例6: test_check_permissions

# 需要導入模塊: from webob import exc [as 別名]
# 或者: from webob.exc import HTTPError [as 別名]
def test_check_permissions(self, mock_get_user_id,
                               mock_is_authenticated,
                               mock_get_test_result,
                               mock_get_test_result_meta_key,
                               mock_pecan_abort,
                               mock_foundation_check):

        @api_utils.check_permissions(level=const.ROLE_USER)
        class ControllerWithPermissions(rest.RestController):

            def get(self, test_id):
                return test_id

            @api_utils.check_permissions(level=const.ROLE_OWNER)
            def delete(self, test_id):
                return test_id

            @api_utils.check_permissions(level='fake_role')
            def post(self, test_id):
                return test_id

        fake_controller = ControllerWithPermissions()

        public_test = 'fake_public_test'
        private_test = 'fake_test'

        mock_get_user_id.return_value = 'fake_openid'
        mock_get_test_result.return_value = {}
        mock_get_test_result_meta_key.side_effect = lambda *args: {
            (public_test, const.USER): None,
            (private_test, const.USER): 'fake_openid',
            (private_test, const.SHARED_TEST_RUN): None,
        }.get(args)

        mock_is_authenticated.return_value = True
        mock_foundation_check.return_value = False
        self.assertEqual(public_test, fake_controller.get(public_test))
        self.assertRaises(exc.HTTPError, fake_controller.delete, public_test)
        self.assertEqual(private_test, fake_controller.get(private_test))
        self.assertEqual(private_test, fake_controller.delete(private_test))

        mock_is_authenticated.return_value = False
        self.assertEqual(public_test, fake_controller.get(public_test))
        self.assertRaises(exc.HTTPError, fake_controller.delete, public_test)
        self.assertRaises(exc.HTTPError, fake_controller.get, private_test)
        self.assertRaises(exc.HTTPError, fake_controller.delete, private_test)

        self.assertRaises(ValueError, fake_controller.post, public_test) 
開發者ID:openstack-archive,項目名稱:refstack,代碼行數:50,代碼來源:test_api_utils.py


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