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


Python ProviderError.ruleError方法代码示例

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


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

示例1: apply_rule_set

# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import ruleError [as 别名]
def apply_rule_set(item, provider, rule_set=None):
    """Applies rules set on the item to be ingested into the system.

    If there's no rule set then the item will
    be returned without any change.

    :param item: Item to be ingested
    :param provider: provider object from whom the item was received
    :return: item
    """
    try:
        if rule_set is None and provider.get('rule_set') is not None:
            rule_set = superdesk.get_resource_service('rule_sets').find_one(_id=provider['rule_set'], req=None)

        if rule_set and 'body_html' in item:
            body = item['body_html']

            for rule in rule_set['rules']:
                body = body.replace(rule['old'], rule['new'])

            item['body_html'] = body

        return item
    except Exception as ex:
        raise ProviderError.ruleError(ex, provider)
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:27,代码来源:update_ingest.py

示例2: test_raise_ruleError

# 需要导入模块: from superdesk.errors import ProviderError [as 别名]
# 或者: from superdesk.errors.ProviderError import ruleError [as 别名]
 def test_raise_ruleError(self):
     with assert_raises(ProviderError) as error_context:
         try:
             ex = Exception("Testing ruleError")
             raise ex
         except Exception:
             raise ProviderError.ruleError(ex, self.provider)
     exception = error_context.exception
     self.assertTrue(exception.code == 2003)
     self.assertTrue(exception.message == "Rule could not be applied")
     self.assertIsNotNone(exception.system_exception)
     self.assertEqual(exception.system_exception.args[0], "Testing ruleError")
     self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
     self.assertEqual(self.mock_logger_handler.messages['error'][0],
                      "ProviderError Error 2003 - Rule could not be applied: "
                      "Testing ruleError on channel TestProvider")
开发者ID:ancafarcas,项目名称:superdesk-core,代码行数:18,代码来源:errors_test.py


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