1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

unicode: Audited syndication framework for unicode correctness.

git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-05-15 18:11:15 +00:00
parent 9d001fa7f9
commit 267dcdb1e6
2 changed files with 9 additions and 6 deletions

View File

@ -2,10 +2,13 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.template import Context, loader, Template, TemplateDoesNotExist from django.template import Context, loader, Template, TemplateDoesNotExist
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.utils import feedgenerator from django.utils import feedgenerator
from django.utils.encoding import smart_unicode
from django.conf import settings from django.conf import settings
def add_domain(domain, url): def add_domain(domain, url):
if not url.startswith('http://'): 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) url = u'http://%s%s' % (domain, url)
return url return url
@ -97,9 +100,9 @@ class Feed(object):
enc_url = self.__get_dynamic_attr('item_enclosure_url', item) enc_url = self.__get_dynamic_attr('item_enclosure_url', item)
if enc_url: if enc_url:
enc = feedgenerator.Enclosure( enc = feedgenerator.Enclosure(
url = enc_url.decode('utf-8'), url = smart_unicode(enc_url),
length = str(self.__get_dynamic_attr('item_enclosure_length', item)).decode('utf-8'), length = smart_unicode(self.__get_dynamic_attr('item_enclosure_length', item)),
mime_type = self.__get_dynamic_attr('item_enclosure_mime_type', item).decode('utf-8'), mime_type = smart_unicode(self.__get_dynamic_attr('item_enclosure_mime_type', item))
) )
author_name = self.__get_dynamic_attr('item_author_name', item) author_name = self.__get_dynamic_attr('item_author_name', item)
if author_name is not None: if author_name is not None:
@ -108,9 +111,9 @@ class Feed(object):
else: else:
author_email = author_link = None author_email = author_link = None
feed.add_item( 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, 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, unique_id = link,
enclosure = enc, enclosure = enc,
pubdate = self.__get_dynamic_attr('item_pubdate', item), pubdate = self.__get_dynamic_attr('item_pubdate', item),

View File

@ -34,7 +34,7 @@ def get_tag_uri(url, date):
if date is not None: if date is not None:
tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1) tag = re.sub('/', ',%s:/' % date.strftime('%Y-%m-%d'), tag, 1)
tag = re.sub('#', '/', tag) tag = re.sub('#', '/', tag)
return 'tag:' + tag return u'tag:' + tag
class SyndicationFeed(object): class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()" "Base class for all syndication feeds. Subclasses should provide write()"