From e8de4cc67d32ca1c6c22c3a68fb32932406d1d06 Mon Sep 17 00:00:00 2001 From: lemon24 Date: Tue, 25 Jan 2022 23:05:52 +0200 Subject: [PATCH] Update JSONParser.feed() to take a file instead of a string. For #296. --- feedparser/api.py | 2 +- feedparser/parsers/json.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/feedparser/api.py b/feedparser/api.py index 6f598622..dbfbfc4c 100644 --- a/feedparser/api.py +++ b/feedparser/api.py @@ -288,7 +288,7 @@ def _parse_file_inplace( result['version'] = None feed_parser = JSONParser(baseuri, baselang, 'utf-8') try: - feed_parser.feed(data) + feed_parser.feed(io.BytesIO(data)) except Exception as e: result['bozo'] = 1 result['bozo_exception'] = e diff --git a/feedparser/parsers/json.py b/feedparser/parsers/json.py index ae43163c..ccfd065d 100644 --- a/feedparser/parsers/json.py +++ b/feedparser/parsers/json.py @@ -61,8 +61,8 @@ def __init__(self, baseuri=None, baselang=None, encoding=None): self.namespacesInUse = [] self.entries = [] - def feed(self, data): - data = json.loads(data) + def feed(self, file): + data = json.load(file) v = data.get('version', '') try: