當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。