From 01b4c069162bb332d2c3cef6e9d324abebe4317c Mon Sep 17 00:00:00 2001 From: Alexander Artemenko Date: Sun, 26 Dec 2010 23:59:30 +0300 Subject: [PATCH] Custom bicycle 'update_dict' was replaced with 'collections.defaultdict'. --- pelican/generators.py | 10 +++++----- pelican/utils.py | 11 ----------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/pelican/generators.py b/pelican/generators.py index 88ee6919..18dba81a 100755 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -8,7 +8,7 @@ import os from jinja2 import Environment, FileSystemLoader from jinja2.exceptions import TemplateNotFound -from pelican.utils import update_dict, copytree, process_translations, open +from pelican.utils import copytree, process_translations, open from pelican.contents import Article, Page, is_valid_content from pelican.readers import read_file @@ -81,8 +81,8 @@ class ArticlesGenerator(Generator): self.articles = [] # only articles in default language self.translations = [] self.dates = {} - self.tags = {} - self.categories = {} + self.tags = defaultdict(list) + self.categories = defaultdict(list) super(ArticlesGenerator, self).__init__(*args, **kwargs) def generate_feeds(self, writer): @@ -178,14 +178,14 @@ class ArticlesGenerator(Generator): if hasattr(article, 'tags'): for tag in article.tags: - update_dict(self.tags, tag, article) + self.tags[tag].append(article) all_articles.append(article) self.articles, self.translations = process_translations(all_articles) for article in self.articles: # only main articles are listed in categories, not translations - update_dict(self.categories, article.category, article) + self.categories[article.category].append(article) # sort the articles by date diff --git a/pelican/utils.py b/pelican/utils.py index fe7ab009..9641b078 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -7,17 +7,6 @@ from codecs import open as _open from itertools import groupby from operator import attrgetter -def update_dict(mapping, key, value): - """Update a dict intenal list - - :param mapping: the mapping to update - :param key: the key of the mapping to update. - :param value: the value to append to the list. - """ - if key not in mapping: - mapping[key] = [] - mapping[key].append(value) - def get_date(string): """Return a datetime object from a string.