From 382d108db238f8ac8c8b63295f88b2f696295e84 Mon Sep 17 00:00:00 2001 From: Labrys Date: Sat, 4 Jun 2016 22:10:26 -0400 Subject: [PATCH] Optimize imports * PEP8: Fix module level import not at top of file * Remove unused imports * Remove simplejson * Replace mimetools with email --- core/__init__.py | 10 ++++++---- core/databases/mainDB.py | 2 +- core/gh_api.py | 2 +- core/nzbToMediaAutoFork.py | 5 +++-- core/synchronousdeluge/__init__.py | 5 ++--- core/synchronousdeluge/rencode.py | 7 ++++--- core/transcoder/transcoder.py | 2 -- core/transmissionrpc/utils.py | 7 +++++-- core/utorrent/client.py | 6 +----- core/utorrent/upload.py | 4 ++-- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index 12c413f1..9f9fe812 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -33,10 +33,12 @@ from core.autoProcess.autoProcessMusic import autoProcessMusic from core.autoProcess.autoProcessTV import autoProcessTV from core import logger, versionCheck, nzbToMediaDB from core.nzbToMediaConfig import config -from core.nzbToMediaUtil import category_search, sanitizeName, copy_link, parse_args, flatten, getDirs, \ - rmReadOnly, rmDir, pause_torrent, resume_torrent, remove_torrent, listMediaFiles, \ - extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo, WakeUp, makeDir, cleanDir, \ - create_torrent_class, listMediaFiles, RunningProcess +from core.nzbToMediaUtil import ( + category_search, sanitizeName, copy_link, parse_args, flatten, getDirs, + rmReadOnly, rmDir, pause_torrent, resume_torrent, remove_torrent, listMediaFiles, + extractFiles, cleanDir, update_downloadInfoStatus, get_downloadInfo, WakeUp, makeDir, cleanDir, + create_torrent_class, listMediaFiles, RunningProcess, + ) from core.transcoder import transcoder from core.databases import mainDB diff --git a/core/databases/mainDB.py b/core/databases/mainDB.py index 0d27b526..e32e6dae 100644 --- a/core/databases/mainDB.py +++ b/core/databases/mainDB.py @@ -1,5 +1,5 @@ # coding=utf-8 -import core + from core import logger, nzbToMediaDB from core.nzbToMediaUtil import backupVersionedFile diff --git a/core/gh_api.py b/core/gh_api.py index 95faf10e..1db7faf7 100644 --- a/core/gh_api.py +++ b/core/gh_api.py @@ -1,5 +1,5 @@ # coding=utf-8 -import json + import requests diff --git a/core/nzbToMediaAutoFork.py b/core/nzbToMediaAutoFork.py index d1c122c1..cfb4e60c 100644 --- a/core/nzbToMediaAutoFork.py +++ b/core/nzbToMediaAutoFork.py @@ -1,7 +1,8 @@ # coding=utf-8 -import urllib -import core + import requests + +import core from core import logger diff --git a/core/synchronousdeluge/__init__.py b/core/synchronousdeluge/__init__.py index 6155881f..9d4d8c77 100644 --- a/core/synchronousdeluge/__init__.py +++ b/core/synchronousdeluge/__init__.py @@ -15,10 +15,9 @@ Example usage: download_location = client.core.get_config_value("download_location").get() """ +from core.synchronousdeluge.exceptions import DelugeRPCError + __title__ = "synchronous-deluge" __version__ = "0.1" __author__ = "Christian Dale" - -from core.synchronousdeluge.exceptions import DelugeRPCError - diff --git a/core/synchronousdeluge/rencode.py b/core/synchronousdeluge/rencode.py index 62e22b08..0d960255 100644 --- a/core/synchronousdeluge/rencode.py +++ b/core/synchronousdeluge/rencode.py @@ -19,6 +19,10 @@ rencode module versions, so you should check that you are using the same rencode version throughout your project. """ +import struct +from threading import Lock + + __version__ = '1.0.1' __all__ = ['dumps', 'loads'] @@ -62,9 +66,6 @@ __all__ = ['dumps', 'loads'] # (The rencode module is licensed under the above license as well). # -import struct -from threading import Lock - # Default number of bits for serialized floats, either 32 or 64 (also a parameter for dumps()). DEFAULT_FLOAT_BITS = 32 diff --git a/core/transcoder/transcoder.py b/core/transcoder/transcoder.py index d31ef25e..9065c78a 100644 --- a/core/transcoder/transcoder.py +++ b/core/transcoder/transcoder.py @@ -3,8 +3,6 @@ import errno import os import platform import subprocess -import urllib2 -import traceback import core import json import shutil diff --git a/core/transmissionrpc/utils.py b/core/transmissionrpc/utils.py index 223921d6..c2bca855 100644 --- a/core/transmissionrpc/utils.py +++ b/core/transmissionrpc/utils.py @@ -2,10 +2,13 @@ # Copyright (c) 2008-2013 Erik Svensson # Licensed under the MIT license. -import socket, datetime, logging, constants +import constants +import datetime +import logging +import socket from collections import namedtuple -from constants import LOGGER +from constants import LOGGER from six import string_types, iteritems UNITS = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB'] diff --git a/core/utorrent/client.py b/core/utorrent/client.py index ae5d4634..f8989acf 100644 --- a/core/utorrent/client.py +++ b/core/utorrent/client.py @@ -4,14 +4,10 @@ import urllib import urllib2 import urlparse import cookielib +import json import re import StringIO -try: - import json -except ImportError: - import simplejson as json - from core.utorrent.upload import MultiPartForm diff --git a/core/utorrent/upload.py b/core/utorrent/upload.py index de149efc..ddf228cc 100644 --- a/core/utorrent/upload.py +++ b/core/utorrent/upload.py @@ -1,8 +1,8 @@ # coding=utf-8 # code copied from http://www.doughellmann.com/PyMOTW/urllib2/ +from email.generator import _make_boundary as make_boundary import itertools -import mimetools import mimetypes @@ -12,7 +12,7 @@ class MultiPartForm(object): def __init__(self): self.form_fields = [] self.files = [] - self.boundary = mimetools.choose_boundary() + self.boundary = make_boundary() return def get_content_type(self):