-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supprime les caractères non supportés par les flux RSS et ATOM lors d…
…e leur génération Une erreur 500 UnserializableContentError est levée sinon. Détecté grâce à Sentry.
- Loading branch information
1 parent
2f18d2b
commit 1d5654a
Showing
5 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import re | ||
|
||
from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed | ||
from django.utils.xmlutils import SimplerXMLGenerator | ||
|
||
|
||
class DropControlCharsXMLGenerator(SimplerXMLGenerator): | ||
def characters(self, content): | ||
# From django.utils.xmlutils.SimplerXMLGenerator.characters() | ||
super().characters(re.sub(r"[\x00-\x08\x0B-\x0C\x0E-\x1F]", "", content)) | ||
|
||
|
||
class DropControlCharsRss201rev2Feed(Rss201rev2Feed): | ||
def write(self, outfile, encoding): | ||
# From django.utils.feedgenerator.RssFeed.write() | ||
handler = DropControlCharsXMLGenerator(outfile, encoding) | ||
handler.startDocument() | ||
handler.startElement("rss", self.rss_attributes()) | ||
handler.startElement("channel", self.root_attributes()) | ||
self.add_root_elements(handler) | ||
self.write_items(handler) | ||
self.endChannelElement(handler) | ||
handler.endElement("rss") | ||
|
||
|
||
class DropControlCharsAtom1Feed(Atom1Feed): | ||
def write(self, outfile, encoding): | ||
# From django.utils.feedgenerator.Atom1Feed.write() | ||
handler = DropControlCharsXMLGenerator(outfile, encoding) | ||
handler.startDocument() | ||
handler.startElement("feed", self.root_attributes()) | ||
self.add_root_elements(handler) | ||
self.write_items(handler) | ||
handler.endElement("feed") |