From 4293cb0fabb41d75da0f576e1dc7ed5479769156 Mon Sep 17 00:00:00 2001 From: Harmon Date: Sat, 4 May 2019 01:37:16 -0500 Subject: [PATCH] Improve import organization --- bindings_url_parser.py | 3 ++- docs/conf.py | 3 ++- examples/streaming.py | 4 +--- setup.py | 5 +++-- tests/config.py | 3 ++- tests/test_api.py | 8 ++++---- tests/test_auth.py | 6 +++--- tests/test_cursors.py | 3 +-- tests/test_rate_limit.py | 4 ++-- tests/test_streaming.py | 10 +++++----- tests/test_utils.py | 4 ++-- tweepy/__init__.py | 10 +++++----- tweepy/api.py | 2 +- tweepy/auth.py | 9 +++++---- tweepy/binder.py | 17 ++++++++--------- tweepy/cache.py | 5 +++-- tweepy/error.py | 1 + tweepy/models.py | 2 +- tweepy/parsers.py | 3 ++- tweepy/streaming.py | 9 ++++----- tweepy/utils.py | 3 +-- 21 files changed, 58 insertions(+), 56 deletions(-) diff --git a/bindings_url_parser.py b/bindings_url_parser.py index 252fbb7..fd5f632 100644 --- a/bindings_url_parser.py +++ b/bindings_url_parser.py @@ -1,7 +1,8 @@ """ script to parse the url of bindings and find if the page exists or not """ + +import os import pprint import re -import os import requests __author__ = 'jordiriera' diff --git a/docs/conf.py b/docs/conf.py index 4bb556e..7c121f6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,7 +11,8 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys, os +import os +import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the diff --git a/examples/streaming.py b/examples/streaming.py index e90bc5e..1ecc01f 100644 --- a/examples/streaming.py +++ b/examples/streaming.py @@ -1,8 +1,6 @@ from __future__ import absolute_import, print_function -from tweepy.streaming import StreamListener -from tweepy import OAuthHandler -from tweepy import Stream +from tweepy import OAuthHandler, Stream, StreamListener # Go to http://apps.twitter.com and create an app. # The consumer key and secret will be generated for you after diff --git a/setup.py b/setup.py index 9e86d44..9da3af5 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,8 @@ #!/usr/bin/env python -#from distutils.core import setup + +# from distutils.core import setup import re -from setuptools import setup, find_packages +from setuptools import find_packages, setup VERSIONFILE = "tweepy/__init__.py" ver_file = open(VERSIONFILE, "rt").read() diff --git a/tests/config.py b/tests/config.py index 9a33412..9ca122c 100644 --- a/tests/config.py +++ b/tests/config.py @@ -1,9 +1,10 @@ import os import unittest + import vcr -from tweepy.auth import OAuthHandler from tweepy.api import API +from tweepy.auth import OAuthHandler username = os.environ.get('TWITTER_USERNAME', 'tweepytest') diff --git a/tests/test_api.py b/tests/test_api.py index d1e1e32..e057c44 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,15 +1,15 @@ -import unittest +import os import random import shutil import time -import os +import unittest from ast import literal_eval from nose import SkipTest -from tweepy import Friendship, MemoryCache, FileCache, API +from .config import tape, TweepyTestCase, use_replay, username +from tweepy import API, FileCache, Friendship, MemoryCache from tweepy.parsers import Parser -from .config import TweepyTestCase, username, use_replay, tape test_tweet_id = '266367358078169089' tweet_text = 'testing 1000' diff --git a/tests/test_auth.py b/tests/test_auth.py index e09d0e3..cc889fb 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,11 +1,11 @@ from __future__ import absolute_import -from .config import * -from tweepy import API, OAuthHandler - import random import unittest +from .config import * +from tweepy import API, OAuthHandler + class TweepyAuthTests(unittest.TestCase): diff --git a/tests/test_cursors.py b/tests/test_cursors.py index 29ca5a7..b707b34 100644 --- a/tests/test_cursors.py +++ b/tests/test_cursors.py @@ -1,7 +1,6 @@ +from .config import tape, TweepyTestCase, username from tweepy import Cursor -from .config import TweepyTestCase, username, tape - class TweepyCursorTests(TweepyTestCase): @tape.use_cassette('testidcursoritems.json') diff --git a/tests/test_rate_limit.py b/tests/test_rate_limit.py index 7be9af5..bd9a5b7 100644 --- a/tests/test_rate_limit.py +++ b/tests/test_rate_limit.py @@ -1,13 +1,13 @@ import os import unittest +from .config import create_auth from tweepy import API from tweepy.error import TweepError -from .config import create_auth - testratelimit = 'TEST_RATE_LIMIT' in os.environ + @unittest.skipIf(not testratelimit, "skipping rate limiting test since testratelimit is not specified") class TweepyRateLimitTests(unittest.TestCase): diff --git a/tests/test_streaming.py b/tests/test_streaming.py index 6f5daa0..4c3020c 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py @@ -4,14 +4,14 @@ import six import unittest from unittest.case import skip -from tweepy.api import API -from tweepy.auth import OAuthHandler -from tweepy.models import Status -from tweepy.streaming import Stream, StreamListener, ReadBuffer +from mock import MagicMock, patch from .config import create_auth from .test_utils import mock_tweet -from mock import MagicMock, patch +from tweepy.api import API +from tweepy.auth import OAuthHandler +from tweepy.models import Status +from tweepy.streaming import ReadBuffer, Stream, StreamListener if six.PY3: diff --git a/tests/test_utils.py b/tests/test_utils.py index 5ead6b8..3885167 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,9 +1,9 @@ -from tweepy.utils import * - import random import string import unittest +from tweepy.utils import * + def mock_tweet(): """Generate some random tweet text.""" diff --git a/tweepy/__init__.py b/tweepy/__init__.py index 5d3ec56..1c89715 100644 --- a/tweepy/__init__.py +++ b/tweepy/__init__.py @@ -9,13 +9,13 @@ __version__ = '3.7.0' __author__ = 'Joshua Roesslein' __license__ = 'MIT' -from tweepy.models import Status, User, DirectMessage, Friendship, SavedSearch, SearchResults, ModelFactory, Category -from tweepy.error import TweepError, RateLimitError from tweepy.api import API -from tweepy.cache import Cache, MemoryCache, FileCache -from tweepy.auth import OAuthHandler, AppAuthHandler -from tweepy.streaming import Stream, StreamListener +from tweepy.auth import AppAuthHandler, OAuthHandler +from tweepy.cache import Cache, FileCache, MemoryCache from tweepy.cursor import Cursor +from tweepy.error import RateLimitError, TweepError +from tweepy.models import Category, DirectMessage, Friendship, ModelFactory, SavedSearch, SearchResults, Status, User +from tweepy.streaming import Stream, StreamListener # Global, unauthenticated instance of API api = API() diff --git a/tweepy/api.py b/tweepy/api.py index 2741e0c..599e260 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -2,8 +2,8 @@ # Copyright 2009-2019 Joshua Roesslein # See LICENSE for details. -import os import mimetypes +import os import six diff --git a/tweepy/auth.py b/tweepy/auth.py index dd6b8a4..5838d0c 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -2,16 +2,17 @@ # Copyright 2009-2019 Joshua Roesslein # See LICENSE for details. -import six import logging -from tweepy.error import TweepError -from tweepy.api import API import requests -from requests_oauthlib import OAuth1Session, OAuth1 +import six from requests.auth import AuthBase +from requests_oauthlib import OAuth1, OAuth1Session from six.moves.urllib.parse import parse_qs +from tweepy.api import API +from tweepy.error import TweepError + WARNING_MESSAGE = """Warning! Due to a Twitter API bug, signin_with_twitter and access_type don't always play nice together. Details https://dev.twitter.com/discussions/21281""" diff --git a/tweepy/binder.py b/tweepy/binder.py index b3e4c66..e2903cd 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -2,25 +2,24 @@ # Copyright 2009-2019 Joshua Roesslein # See LICENSE for details. -import time +import logging import re +import sys +import time -from six.moves.urllib.parse import quote, urlencode import requests - -import logging - -from tweepy.error import TweepError, RateLimitError, is_rate_limit_error_message -from tweepy.utils import convert_to_utf8_str -from tweepy.models import Model import six -import sys +from six.moves.urllib.parse import quote, urlencode +from tweepy.error import is_rate_limit_error_message, RateLimitError, TweepError +from tweepy.models import Model +from tweepy.utils import convert_to_utf8_str re_path_template = re.compile('{\w+}') log = logging.getLogger('tweepy.binder') + def bind_api(**config): class APIMethod(object): diff --git a/tweepy/cache.py b/tweepy/cache.py index 2adba3d..1f848dc 100644 --- a/tweepy/cache.py +++ b/tweepy/cache.py @@ -2,12 +2,12 @@ # Copyright 2009-2019 Joshua Roesslein # See LICENSE for details. -import time import datetime import hashlib +import logging import threading +import time import os -import logging try: import cPickle as pickle @@ -23,6 +23,7 @@ except ImportError: log = logging.getLogger('tweepy.cache') + class Cache(object): """Cache interface""" diff --git a/tweepy/error.py b/tweepy/error.py index 587195a..8832dd9 100644 --- a/tweepy/error.py +++ b/tweepy/error.py @@ -4,6 +4,7 @@ import six + class TweepError(Exception): """Tweepy exception""" diff --git a/tweepy/models.py b/tweepy/models.py index 284ad5a..bd98ab9 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -4,7 +4,7 @@ from __future__ import absolute_import -from tweepy.utils import parse_datetime, parse_html_value, parse_a_href +from tweepy.utils import parse_a_href, parse_datetime, parse_html_value class ResultSet(list): diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 3d5528f..70fd978 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -3,8 +3,9 @@ # See LICENSE for details. import json as json_lib -from tweepy.models import ModelFactory + from tweepy.error import TweepError +from tweepy.models import ModelFactory class Parser(object): diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 27a5d11..9fa352a 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -6,22 +6,21 @@ from __future__ import absolute_import +import json import logging import re import requests +import ssl import sys -import json -from requests.exceptions import Timeout from threading import Thread from time import sleep import six +from requests.exceptions import Timeout -import ssl - -from tweepy.models import Status from tweepy.api import API from tweepy.error import TweepError +from tweepy.models import Status STREAM_VERSION = '1.1' diff --git a/tweepy/utils.py b/tweepy/utils.py index 7859121..fa39f54 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -3,11 +3,10 @@ # See LICENSE for details. from datetime import datetime +from email.utils import parsedate import six -from email.utils import parsedate - def parse_datetime(string): return datetime(*(parsedate(string)[:6])) -- 2.25.1