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


Python Feed.from_dict方法代码示例

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


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

示例1: test_from_dict

# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import from_dict [as 别名]
    def test_from_dict(self):
        example_name = 'Name here'
        example_uri = 'URI here'

        attribute_dict = {'name': example_name, 'uri': example_uri}
        f = Feed.from_dict(attribute_dict)
        self.assertEquals(f.name, example_name)
        self.assertEquals(f.uri, example_uri)

        # Unsupported attributes should just be ignored
        invalid = 'invalid'
        attribute_dict[invalid] = 'better not show up'
        f = Feed.from_dict(attribute_dict)
        with self.assertRaises(AttributeError):
            f.invalid
        attribute_dict.pop(invalid)

        # Missing attributes should trigger an error
        attribute_dict.pop('name')
        with self.assertRaises(RuntimeError):
            Feed.from_dict(attribute_dict)
开发者ID:glu10,项目名称:trough,代码行数:23,代码来源:test_feed.py

示例2: load_preferences

# 需要导入模块: from feed import Feed [as 别名]
# 或者: from feed.Feed import from_dict [as 别名]
    def load_preferences(self):
        self.preferences = load_file(self.preferences_directory, self.preferences_file, self.preferences)

        if self.preferences['Feeds'] is None:
            self.preferences['Feeds'] = self.default_feeds_preferences()
        else:
            # Since we used JSON and not pickling, need to transform the serialized feed information into Feed objects
            feed_object_dict = dict()
            for feed_name, feed_attributes in self.preferences['Feeds'].items():
                feed_object_dict[feed_name] = Feed.from_dict(feed_attributes)
            self.preferences['Feeds'] = feed_object_dict
            #self.preferences['Categories'] = self.construct_categories()

        if self.preferences['Filters'] is None:
            self.preferences['Filters'] = self.default_filtration_preferences()
        else:
            filter_objects = list()
            for filt, case_sensitive, hide_matches in self.preferences['Filters']:
                filter_objects.append(ItemFilter(filt, case_sensitive, hide_matches))
            self.preferences['Filters'] = filter_objects
开发者ID:glu10,项目名称:trough,代码行数:22,代码来源:preferences.py


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