Skip to content

Commit

Permalink
patch feedparser which incorrectly detects base64
Browse files Browse the repository at this point in the history
  • Loading branch information
brutasse committed Apr 26, 2017
1 parent d48f026 commit 5b70cce
Show file tree
Hide file tree
Showing 4 changed files with 1,861 additions and 0 deletions.
19 changes: 19 additions & 0 deletions feedhq/monkey.py
@@ -1,3 +1,4 @@
import feedparser
from html5lib.filters import alphabeticalattributes


Expand All @@ -21,3 +22,21 @@ def __iter__(self):

def patch_html5lib():
alphabeticalattributes.Filter = Filter


def _isBase64(self, attrsD, contentparams):
if attrsD.get('mode', '') == 'base64':
return 1
if self.contentparams['type'].startswith('text/'):
return 0
if self.contentparams['type'].endswith('+xml'):
return 0
if self.contentparams['type'].endswith('/xml'):
return 0
if self.contentparams['type'] == 'markdown':
return 0
return 1


def patch_feedparser():
feedparser._FeedParserMixin._isBase64 = _isBase64
1 change: 1 addition & 0 deletions feedhq/urls.py
Expand Up @@ -10,6 +10,7 @@

from . import monkey
monkey.patch_html5lib()
monkey.patch_feedparser()

from . import views # noqa
from .logging import configure_logging # noqa
Expand Down

0 comments on commit 5b70cce

Please sign in to comment.