mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: Fixed #4430 -- Handle bytestrings and IRIs more robustly in feed
production. Thanks to Almad and Michal@plovarna.cz for some good debugging here. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5389 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
790d9ecf67
commit
8b3781cc68
@ -19,6 +19,7 @@ http://diveintomark.org/archives/2004/02/04/incompatible-rss
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from django.utils.xmlutils import SimplerXMLGenerator
|
from django.utils.xmlutils import SimplerXMLGenerator
|
||||||
|
from django.utils.encoding import force_unicode, iri_to_uri
|
||||||
import datetime, re, time
|
import datetime, re, time
|
||||||
import email.Utils
|
import email.Utils
|
||||||
|
|
||||||
@ -41,18 +42,20 @@ class SyndicationFeed(object):
|
|||||||
def __init__(self, title, link, description, language=None, author_email=None,
|
def __init__(self, title, link, description, language=None, author_email=None,
|
||||||
author_name=None, author_link=None, subtitle=None, categories=None,
|
author_name=None, author_link=None, subtitle=None, categories=None,
|
||||||
feed_url=None, feed_copyright=None):
|
feed_url=None, feed_copyright=None):
|
||||||
|
if categories:
|
||||||
|
categories = [force_unicode(c) for c in categories]
|
||||||
self.feed = {
|
self.feed = {
|
||||||
'title': title,
|
'title': force_unicode(title),
|
||||||
'link': link,
|
'link': iri_to_uri(link),
|
||||||
'description': description,
|
'description': force_unicode(description),
|
||||||
'language': language,
|
'language': force_unicode(language),
|
||||||
'author_email': author_email,
|
'author_email': force_unicode(author_email),
|
||||||
'author_name': author_name,
|
'author_name': force_unicode(author_name),
|
||||||
'author_link': author_link,
|
'author_link': iri_to_uri(author_link),
|
||||||
'subtitle': subtitle,
|
'subtitle': force_unicode(subtitle),
|
||||||
'categories': categories or (),
|
'categories': categories or (),
|
||||||
'feed_url': feed_url,
|
'feed_url': iri_to_uri(feed_url),
|
||||||
'feed_copyright': feed_copyright,
|
'feed_copyright': force_unicode(feed_copyright),
|
||||||
}
|
}
|
||||||
self.items = []
|
self.items = []
|
||||||
|
|
||||||
@ -64,19 +67,21 @@ class SyndicationFeed(object):
|
|||||||
objects except pubdate, which is a datetime.datetime object, and
|
objects except pubdate, which is a datetime.datetime object, and
|
||||||
enclosure, which is an instance of the Enclosure class.
|
enclosure, which is an instance of the Enclosure class.
|
||||||
"""
|
"""
|
||||||
|
if categories:
|
||||||
|
categories = [force_unicode(c) for c in categories]
|
||||||
self.items.append({
|
self.items.append({
|
||||||
'title': title,
|
'title': force_unicode(title),
|
||||||
'link': link,
|
'link': iri_to_uri(link),
|
||||||
'description': description,
|
'description': force_unicode(description),
|
||||||
'author_email': author_email,
|
'author_email': force_unicode(author_email),
|
||||||
'author_name': author_name,
|
'author_name': force_unicode(author_name),
|
||||||
'author_link': author_link,
|
'author_link': iri_to_uri(author_link),
|
||||||
'pubdate': pubdate,
|
'pubdate': pubdate,
|
||||||
'comments': comments,
|
'comments': force_unicode(comments),
|
||||||
'unique_id': unique_id,
|
'unique_id': force_unicode(unique_id),
|
||||||
'enclosure': enclosure,
|
'enclosure': enclosure,
|
||||||
'categories': categories or (),
|
'categories': categories or (),
|
||||||
'item_copyright': item_copyright,
|
'item_copyright': force_unicode(item_copyright),
|
||||||
})
|
})
|
||||||
|
|
||||||
def num_items(self):
|
def num_items(self):
|
||||||
@ -114,7 +119,8 @@ class Enclosure(object):
|
|||||||
"Represents an RSS enclosure"
|
"Represents an RSS enclosure"
|
||||||
def __init__(self, url, length, mime_type):
|
def __init__(self, url, length, mime_type):
|
||||||
"All args are expected to be Python Unicode objects"
|
"All args are expected to be Python Unicode objects"
|
||||||
self.url, self.length, self.mime_type = url, length, mime_type
|
self.length, self.mime_type = length, mime_type
|
||||||
|
self.url = iri_to_uri(url)
|
||||||
|
|
||||||
class RssFeed(SyndicationFeed):
|
class RssFeed(SyndicationFeed):
|
||||||
mime_type = 'application/rss+xml'
|
mime_type = 'application/rss+xml'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user