Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

unicode: Audited syndication framework for unicode correctness.

git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 267dcdb1e6b8573343f67c1f2cfe2548ae8b002b 1 parent 9d001fa
@malcolmt malcolmt authored
View
13 django/contrib/syndication/feeds.py
@@ -2,10 +2,13 @@
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 @@ def get_feed(self, url=None):
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 @@ def get_feed(self, url=None):
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),
View
2  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()"
Please sign in to comment.
Something went wrong with that request. Please try again.