From e8b2b581dad3470479017d3678f465f170c348f5 Mon Sep 17 00:00:00 2001 From: fitnr Date: Mon, 2 Jan 2017 21:39:39 -0500 Subject: [PATCH] use standard json library Tweepy no longer supports python 2.5 --- tweepy/parsers.py | 9 +++------ tweepy/streaming.py | 4 +--- tweepy/utils.py | 18 ------------------ 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 046cf50..3586487 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -4,8 +4,8 @@ from __future__ import print_function +import json as json_lib from tweepy.models import ModelFactory -from tweepy.utils import import_simplejson from tweepy.error import TweepError @@ -44,12 +44,9 @@ class JSONParser(Parser): payload_format = 'json' - def __init__(self): - self.json_lib = import_simplejson() - def parse(self, method, payload): try: - json = self.json_lib.loads(payload) + json = json_lib.loads(payload) except Exception as e: raise TweepError('Failed to parse JSON payload: %s' % e) @@ -63,7 +60,7 @@ class JSONParser(Parser): return json def parse_error(self, payload): - error_object = self.json_lib.loads(payload) + error_object = json_lib.loads(payload) if 'error' in error_object: reason = error_object['error'] diff --git a/tweepy/streaming.py b/tweepy/streaming.py index e272fb8..945bae5 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -10,6 +10,7 @@ import logging import re import requests import sys +import json from requests.exceptions import Timeout from threading import Thread from time import sleep @@ -22,9 +23,6 @@ from tweepy.models import Status from tweepy.api import API from tweepy.error import TweepError -from tweepy.utils import import_simplejson -json = import_simplejson() - STREAM_VERSION = '1.1' diff --git a/tweepy/utils.py b/tweepy/utils.py index 36d3402..17504b6 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -17,12 +17,10 @@ def parse_datetime(string): def parse_html_value(html): - return html[html.find('>')+1:html.rfind('<')] def parse_a_href(atag): - start = atag.find('"') + 1 end = atag.find('"', start) return atag[start:end] @@ -37,22 +35,6 @@ def convert_to_utf8_str(arg): return arg -def import_simplejson(): - try: - import simplejson as json - except ImportError: - try: - import json # Python 2.6+ - except ImportError: - try: - # Google App Engine - from django.utils import simplejson as json - except ImportError: - raise ImportError("Can't load a json library") - - return json - - def list_to_csv(item_list): if item_list: return ','.join([str(i) for i in item_list]) -- 2.25.1