Ticket #4430: rss-unicode.patch
File rss-unicode.patch, 5.9 KB (added by , 17 years ago) |
---|
-
django/utils/feedgenerator.py
19 19 """ 20 20 21 21 from django.utils.xmlutils import SimplerXMLGenerator 22 from django.utils.encoding import smart_unicode 22 23 import datetime, re, time 23 24 import email.Utils 24 25 … … 157 158 def write_items(self, handler): 158 159 for item in self.items: 159 160 handler.startElement(u"item", {}) 160 handler.addQuickElement(u"title", item['title'])161 handler.addQuickElement(u"link", item['link'])161 handler.addQuickElement(u"title", smart_unicode(item['title'])) 162 handler.addQuickElement(u"link", smart_unicode(item['link'])) 162 163 if item['description'] is not None: 163 handler.addQuickElement(u"description", item['description'])164 164 handler.addQuickElement(u"description", smart_unicode(item['description'])) 165 165 166 # Author information. 166 167 if item["author_name"] and item["author_email"]: 167 handler.addQuickElement(u"author", "%s (%s)" % \168 ( item['author_email'], item['author_name']))168 handler.addQuickElement(u"author", u"%s (%s)" % \ 169 (smart_unicode(item['author_email']), smart_unicode(item['author_name']))) 169 170 elif item["author_email"]: 170 handler.addQuickElement(u"author", item["author_email"])171 handler.addQuickElement(u"author", smart_unicode(item["author_email"])) 171 172 elif item["author_name"]: 172 handler.addQuickElement(u"dc:creator", item["author_name"], {"xmlns:dc": u"http://purl.org/dc/elements/1.1/"})173 173 handler.addQuickElement(u"dc:creator", smart_unicode(item["author_name"]), {"xmlns:dc": u"http://purl.org/dc/elements/1.1/"}) 174 174 175 if item['pubdate'] is not None: 175 176 handler.addQuickElement(u"pubDate", rfc2822_date(item['pubdate']).decode('ascii')) 176 177 if item['comments'] is not None: 177 handler.addQuickElement(u"comments", item['comments'])178 handler.addQuickElement(u"comments", smart_unicode(item['comments'])) 178 179 if item['unique_id'] is not None: 179 handler.addQuickElement(u"guid", item['unique_id'])180 180 handler.addQuickElement(u"guid", smart_unicode(item['unique_id'])) 181 181 182 # Enclosure. 182 183 if item['enclosure'] is not None: 183 184 handler.addQuickElement(u"enclosure", '', 184 185 {u"url": item['enclosure'].url, u"length": item['enclosure'].length, 185 186 u"type": item['enclosure'].mime_type}) 186 187 187 188 # Categories. 188 189 for cat in item['categories']: 189 handler.addQuickElement(u"category", cat)190 handler.addQuickElement(u"category", smart_unicode(cat)) 190 191 191 192 handler.endElement(u"item") 192 193 … … 227 228 def write_items(self, handler): 228 229 for item in self.items: 229 230 handler.startElement(u"entry", {}) 230 handler.addQuickElement(u"title", item['title'])231 handler.addQuickElement(u"link", u"", {u"href": item['link'], u"rel": u"alternate"})231 handler.addQuickElement(u"title", smart_unicode(item['title'])) 232 handler.addQuickElement(u"link", u"", {u"href": smart_unicode(item['link']), u"rel": u"alternate"}) 232 233 if item['pubdate'] is not None: 233 234 handler.addQuickElement(u"updated", rfc3339_date(item['pubdate']).decode('ascii')) 234 235 235 236 # Author information. 236 237 if item['author_name'] is not None: 237 238 handler.startElement(u"author", {}) 238 handler.addQuickElement(u"name", item['author_name'])239 handler.addQuickElement(u"name", smart_unicode(item['author_name'])) 239 240 if item['author_email'] is not None: 240 handler.addQuickElement(u"email", item['author_email'])241 handler.addQuickElement(u"email", smart_unicode(item['author_email'])) 241 242 if item['author_link'] is not None: 242 handler.addQuickElement(u"uri", item['author_link'])243 handler.addQuickElement(u"uri", smart_unicode(item['author_link'])) 243 244 handler.endElement(u"author") 244 245 245 246 # Unique ID. 246 247 if item['unique_id'] is not None: 247 248 unique_id = item['unique_id'] 248 249 else: 249 unique_id = get_tag_uri( item['link'], item['pubdate'])250 unique_id = get_tag_uri(smart_unicode(item['link']), smart_unicode(item['pubdate'])) 250 251 handler.addQuickElement(u"id", unique_id) 251 252 252 253 # Summary. 253 254 if item['description'] is not None: 254 handler.addQuickElement(u"summary", item['description'], {u"type": u"html"})255 handler.addQuickElement(u"summary", smart_unicode(item['description']), {u"type": u"html"}) 255 256 256 257 # Enclosure. 257 258 if item['enclosure'] is not None: 258 259 handler.addQuickElement(u"link", '', 259 260 {u"rel": u"enclosure", 260 u"href": item['enclosure'].url,261 u"href": smart_unicode(item['enclosure'].url), 261 262 u"length": item['enclosure'].length, 262 263 u"type": item['enclosure'].mime_type}) 263 264 264 265 # Categories. 265 266 for cat in item['categories']: 266 handler.addQuickElement(u"category", u"", {u"term": cat})267 handler.addQuickElement(u"category", u"", {u"term": smart_unicode(cat)}) 267 268 268 269 # Rights. 269 270 if item['item_copyright'] is not None: 270 handler.addQuickElement(u"rights", item['item_copyright'])271 handler.addQuickElement(u"rights", smart_unicode(item['item_copyright'])) 271 272 272 273 handler.endElement(u"entry") 273 274