From 267dcdb1e6b8573343f67c1f2cfe2548ae8b002b Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 15 May 2007 18:11:15 +0000 Subject: [PATCH] unicode: Audited syndication framework for unicode correctness. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5251 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/syndication/feeds.py | 13 ++++++++----- django/utils/feedgenerator.py | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/django/contrib/syndication/feeds.py b/django/contrib/syndication/feeds.py index af00bdc3e9..9f5a8f42f3 100644 --- a/django/contrib/syndication/feeds.py +++ b/django/contrib/syndication/feeds.py @@ -2,10 +2,13 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist from django.template import Context, loader, Template, TemplateDoesNotExist from django.contrib.sites.models import Site from django.utils import feedgenerator +from django.utils.encoding import smart_unicode from django.conf import settings def add_domain(domain, url): if not url.startswith('http://'): + # 'url' must already be ASCII and URL-quoted, so no need for encodign + # conversions here. url = u'http://%s%s' % (domain, url) return url @@ -97,9 +100,9 @@ class Feed(object): enc_url = self.__get_dynamic_attr('item_enclosure_url', item) if enc_url: enc = feedgenerator.Enclosure( - url = enc_url.decode('utf-8'), - length = str(self.__get_dynamic_attr('item_enclosure_length', item)).decode('utf-8'), - mime_type = self.__get_dynamic_attr('item_enclosure_mime_type', item).decode('utf-8'), + url = smart_unicode(enc_url), + length = smart_unicode(self.__get_dynamic_attr('item_enclosure_length', item)), + mime_type = smart_unicode(self.__get_dynamic_attr('item_enclosure_mime_type', item)) ) author_name = self.__get_dynamic_attr('item_author_name', item) if author_name is not None: @@ -108,9 +111,9 @@ class Feed(object): else: author_email = author_link = None feed.add_item( - title = title_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8'), + title = title_tmp.render(Context({'obj': item, 'site': current_site})), link = link, - description = description_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8'), + description = description_tmp.render(Context({'obj': item, 'site': current_site})), unique_id = link, enclosure = enc, pubdate = self.__get_dynamic_attr('item_pubdate', item), diff --git a/django/utils/feedgenerator.py b/django/utils/feedgenerator.py index aa315b5292..4e435b608d 100644 --- a/django/utils/feedgenerator.py +++ b/django/utils/feedgenerator.py @@ -34,7 +34,7 @@ def get_tag_uri(url, date): if date is not None: tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1) tag = re.sub('#', '/', tag) - return 'tag:' + tag + return u'tag:' + tag class SyndicationFeed(object): "Base class for all syndication feeds. Subclasses should provide write()"