From a6b643bb341c4866264482b8da279f09cdc678f8 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 7 Nov 2018 15:15:05 -0500 Subject: [PATCH] move files --- lbrynet/blob/EncryptedFileCreator.py | 2 +- lbrynet/blob/EncryptedFileDownloader.py | 4 ++-- lbrynet/blob/EncryptedFileManager.py | 4 ++-- lbrynet/blob/blob_file.py | 4 ++-- lbrynet/blob/client/CryptStreamDownloader.py | 8 ++++--- .../blob/client/EncryptedFileDownloader.py | 2 +- lbrynet/blob/creator.py | 2 +- lbrynet/blob/writer.py | 2 +- lbrynet/{extras/daemon => }/conf.py | 2 +- lbrynet/{p2p => }/cryptoutils.py | 0 lbrynet/{p2p => dht}/call_later_manager.py | 0 lbrynet/dht/contact.py | 2 +- lbrynet/dht/distance.py | 2 +- lbrynet/dht/msgtypes.py | 2 +- lbrynet/dht/node.py | 5 ++--- lbrynet/extras/cli.py | 2 +- lbrynet/extras/daemon/ComponentManager.py | 4 ++-- lbrynet/extras/daemon/Components.py | 18 +++++++-------- lbrynet/extras/daemon/Daemon.py | 13 ++++------- lbrynet/extras/daemon/DaemonConsole.py | 6 ++--- lbrynet/extras/daemon/DaemonControl.py | 5 ++--- lbrynet/extras/daemon/Downloader.py | 4 ++-- lbrynet/extras/daemon/HashAnnouncer.py | 3 +-- .../daemon/PeerFinder.py} | 2 +- lbrynet/{p2p => extras/daemon}/PeerManager.py | 0 lbrynet/extras/daemon/analytics.py | 4 ++-- lbrynet/extras/daemon/auth/client.py | 2 +- lbrynet/extras/daemon/auth/factory.py | 2 +- lbrynet/extras/daemon/auth/keyring.py | 2 +- lbrynet/extras/daemon/auth/server.py | 7 +++--- lbrynet/extras/daemon/migrator/migrate5to6.py | 2 +- lbrynet/extras/daemon/storage.py | 3 +-- .../{p2p => extras}/looping_call_manager.py | 0 lbrynet/extras/reflector/reupload.py | 2 +- lbrynet/extras/reflector/server/server.py | 2 +- lbrynet/{p2p => }/log_support.py | 8 +++---- lbrynet/p2p/HTTPBlobDownloader.py | 2 +- lbrynet/p2p/PaymentRateManager.py | 2 +- lbrynet/p2p/Peer.py | 2 +- lbrynet/p2p/PriceModel.py | 3 +-- lbrynet/p2p/SinglePeerDownloader.py | 2 +- lbrynet/p2p/Strategy.py | 3 +-- lbrynet/p2p/StreamDescriptor.py | 2 +- lbrynet/p2p/client/ClientProtocol.py | 3 +-- lbrynet/p2p/client/ConnectionManager.py | 3 +-- .../p2p/client/StandaloneBlobDownloader.py | 2 +- lbrynet/{p2p => }/system_info.py | 0 lbrynet/{p2p => }/utils.py | 3 ++- lbrynet/{extras/daemon => }/winpaths.py | 0 scripts/encrypt_blob.py | 2 +- tests/functional/test_misc.py | 6 ++--- tests/functional/test_reflector.py | 5 +++-- tests/functional/test_streamify.py | 2 +- tests/integration/cli/test_cli.py | 2 +- tests/integration/wallet/test_commands.py | 2 +- tests/mocks.py | 4 ++-- tests/{util.py => test_utils.py} | 5 +++-- .../core/client/test_ConnectionManager.py | 15 ++++++------- tests/unit/core/test_BlobManager.py | 6 ++--- tests/unit/core/test_HTTPBlobDownloader.py | 2 +- tests/unit/core/test_HashBlob.py | 2 +- tests/unit/core/test_Wallet.py | 3 --- tests/unit/core/test_utils.py | 2 +- tests/unit/database/test_SQLiteStorage.py | 4 ++-- tests/unit/dht/test_contact.py | 2 +- tests/unit/dht/test_hash_announcer.py | 4 ++-- tests/unit/dht/test_kbucket.py | 2 +- tests/unit/dht/test_node.py | 2 +- tests/unit/dht/test_routingtable.py | 2 +- .../test_EncryptedFileCreator.py | 4 ++-- tests/unit/lbrynet_daemon/auth/test_server.py | 2 +- tests/unit/lbrynet_daemon/test_Daemon.py | 22 +++++++------------ tests/unit/lbrynet_daemon/test_Downloader.py | 2 +- .../test_ExchangeRateManager.py | 16 +++++++------- .../lbrynet_daemon/test_claims_comparator.py | 2 +- tests/unit/test_cli.py | 2 +- tests/unit/test_conf.py | 2 +- 77 files changed, 131 insertions(+), 154 deletions(-) rename lbrynet/{extras/daemon => }/conf.py (99%) rename lbrynet/{p2p => }/cryptoutils.py (100%) rename lbrynet/{p2p => dht}/call_later_manager.py (100%) rename lbrynet/{dht/peerfinder.py => extras/daemon/PeerFinder.py} (98%) rename lbrynet/{p2p => extras/daemon}/PeerManager.py (100%) rename lbrynet/{p2p => extras}/looping_call_manager.py (100%) rename lbrynet/{p2p => }/log_support.py (99%) rename lbrynet/{p2p => }/system_info.py (100%) rename lbrynet/{p2p => }/utils.py (99%) rename lbrynet/{extras/daemon => }/winpaths.py (100%) rename tests/{util.py => test_utils.py} (91%) diff --git a/lbrynet/blob/EncryptedFileCreator.py b/lbrynet/blob/EncryptedFileCreator.py index 7d1fec30a..d8ee1868d 100644 --- a/lbrynet/blob/EncryptedFileCreator.py +++ b/lbrynet/blob/EncryptedFileCreator.py @@ -2,8 +2,8 @@ Utilities for turning plain files into LBRY Files. """ -import logging import os +import logging from binascii import hexlify from twisted.internet import defer diff --git a/lbrynet/blob/EncryptedFileDownloader.py b/lbrynet/blob/EncryptedFileDownloader.py index 12664a0c6..108bb2f80 100644 --- a/lbrynet/blob/EncryptedFileDownloader.py +++ b/lbrynet/blob/EncryptedFileDownloader.py @@ -5,10 +5,10 @@ import logging from binascii import hexlify, unhexlify from twisted.internet import defer -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.p2p.client.StreamProgressManager import FullStreamProgressManager from lbrynet.p2p.HTTPBlobDownloader import HTTPBlobDownloader -from lbrynet.p2p.utils import short_hash +from lbrynet.utils import short_hash from lbrynet.blob.client.EncryptedFileDownloader import EncryptedFileSaver from lbrynet.blob.client.EncryptedFileDownloader import EncryptedFileDownloader from lbrynet.blob.EncryptedFileStatusReport import EncryptedFileStatusReport diff --git a/lbrynet/blob/EncryptedFileManager.py b/lbrynet/blob/EncryptedFileManager.py index f7d138db3..902ecae88 100644 --- a/lbrynet/blob/EncryptedFileManager.py +++ b/lbrynet/blob/EncryptedFileManager.py @@ -7,14 +7,14 @@ from binascii import hexlify, unhexlify from twisted.internet import defer, task, reactor from twisted.python.failure import Failure +from lbrynet import conf from lbrynet.extras.reflector.reupload import reflect_file from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloader from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory from lbrynet.p2p.StreamDescriptor import EncryptedFileStreamType, get_sd_info from lbrynet.blob.client.CryptStreamDownloader import AlreadyStoppedError from lbrynet.blob.client.CryptStreamDownloader import CurrentlyStoppingError -from lbrynet.p2p.utils import safe_start_looping_call, safe_stop_looping_call -from lbrynet.extras.daemon import conf +from lbrynet.utils import safe_start_looping_call, safe_stop_looping_call log = logging.getLogger(__name__) diff --git a/lbrynet/blob/blob_file.py b/lbrynet/blob/blob_file.py index 0046b6c5a..5f9173969 100644 --- a/lbrynet/blob/blob_file.py +++ b/lbrynet/blob/blob_file.py @@ -1,10 +1,10 @@ -import logging import os +import logging from twisted.internet import defer, threads from twisted.web.client import FileBodyProducer from twisted.python.failure import Failure from lbrynet.p2p.Error import DownloadCanceledError, InvalidDataError, InvalidBlobHashError -from lbrynet.p2p.utils import is_valid_blobhash +from lbrynet.utils import is_valid_blobhash from lbrynet.blob.writer import HashBlobWriter from lbrynet.blob.reader import HashBlobReader diff --git a/lbrynet/blob/client/CryptStreamDownloader.py b/lbrynet/blob/client/CryptStreamDownloader.py index ffc0844cf..985e399b7 100644 --- a/lbrynet/blob/client/CryptStreamDownloader.py +++ b/lbrynet/blob/client/CryptStreamDownloader.py @@ -1,12 +1,14 @@ -from binascii import unhexlify import logging +from binascii import unhexlify +from twisted.internet import defer +from twisted.python.failure import Failure + from lbrynet.p2p.client.BlobRequester import BlobRequester from lbrynet.p2p.client.ConnectionManager import ConnectionManager from lbrynet.p2p.client.DownloadManager import DownloadManager from lbrynet.p2p.client.StreamProgressManager import FullStreamProgressManager from lbrynet.blob.client.CryptBlobHandler import CryptBlobHandler -from twisted.internet import defer -from twisted.python.failure import Failure + log = logging.getLogger(__name__) diff --git a/lbrynet/blob/client/EncryptedFileDownloader.py b/lbrynet/blob/client/EncryptedFileDownloader.py index 735ea3bf4..48e7b6565 100644 --- a/lbrynet/blob/client/EncryptedFileDownloader.py +++ b/lbrynet/blob/client/EncryptedFileDownloader.py @@ -2,13 +2,13 @@ import os import logging import traceback from binascii import hexlify, unhexlify +from twisted.internet import defer, threads from lbrynet.p2p.StreamDescriptor import save_sd_info from lbrynet.blob.client.CryptStreamDownloader import CryptStreamDownloader from lbrynet.p2p.client.StreamProgressManager import FullStreamProgressManager from lbrynet.p2p.Error import FileOpenError from lbrynet.blob.client.EncryptedFileMetadataHandler import EncryptedFileMetadataHandler -from twisted.internet import defer, threads log = logging.getLogger(__name__) diff --git a/lbrynet/blob/creator.py b/lbrynet/blob/creator.py index 04b42961b..af9dc213f 100644 --- a/lbrynet/blob/creator.py +++ b/lbrynet/blob/creator.py @@ -3,7 +3,7 @@ import logging from io import BytesIO from twisted.internet import defer from twisted.web.client import FileBodyProducer -from lbrynet.p2p.cryptoutils import get_lbry_hash_obj +from lbrynet.cryptoutils import get_lbry_hash_obj log = logging.getLogger(__name__) diff --git a/lbrynet/blob/writer.py b/lbrynet/blob/writer.py index 5332d3533..c66e3b037 100644 --- a/lbrynet/blob/writer.py +++ b/lbrynet/blob/writer.py @@ -2,7 +2,7 @@ import logging from io import BytesIO from twisted.python.failure import Failure from lbrynet.p2p.Error import DownloadCanceledError, InvalidDataError -from lbrynet.p2p.cryptoutils import get_lbry_hash_obj +from lbrynet.cryptoutils import get_lbry_hash_obj log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/conf.py b/lbrynet/conf.py similarity index 99% rename from lbrynet/extras/daemon/conf.py rename to lbrynet/conf.py index 311ba64cc..72ba2b700 100644 --- a/lbrynet/extras/daemon/conf.py +++ b/lbrynet/conf.py @@ -7,7 +7,7 @@ import sys import yaml import envparse from appdirs import user_data_dir, user_config_dir -from lbrynet.p2p import utils +from lbrynet import utils from lbrynet.p2p.Error import InvalidCurrencyError, NoSuchDirectoryError from lbrynet.androidhelpers.paths import ( android_internal_storage_dir, diff --git a/lbrynet/p2p/cryptoutils.py b/lbrynet/cryptoutils.py similarity index 100% rename from lbrynet/p2p/cryptoutils.py rename to lbrynet/cryptoutils.py diff --git a/lbrynet/p2p/call_later_manager.py b/lbrynet/dht/call_later_manager.py similarity index 100% rename from lbrynet/p2p/call_later_manager.py rename to lbrynet/dht/call_later_manager.py diff --git a/lbrynet/dht/contact.py b/lbrynet/dht/contact.py index 99c84532b..afd2b4718 100644 --- a/lbrynet/dht/contact.py +++ b/lbrynet/dht/contact.py @@ -1,7 +1,7 @@ import ipaddress from binascii import hexlify from functools import reduce -from lbrynet.dht import constants +from . import constants def is_valid_ipv4(address): diff --git a/lbrynet/dht/distance.py b/lbrynet/dht/distance.py index 2c1099535..94de80433 100644 --- a/lbrynet/dht/distance.py +++ b/lbrynet/dht/distance.py @@ -1,4 +1,4 @@ -from lbrynet.dht import constants +from . import constants class Distance: diff --git a/lbrynet/dht/msgtypes.py b/lbrynet/dht/msgtypes.py index 8bf8f3227..59f9440bd 100644 --- a/lbrynet/dht/msgtypes.py +++ b/lbrynet/dht/msgtypes.py @@ -7,7 +7,7 @@ # The docstrings in this module contain epytext markup; API documentation # may be created by processing this file with epydoc: http://epydoc.sf.net -from lbrynet.p2p.utils import generate_id +from lbrynet.utils import generate_id from . import constants diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 64c1a64ab..eb929803a 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -5,9 +5,8 @@ from functools import reduce from twisted.internet import defer, error, task -from lbrynet.p2p.utils import generate_id, DeferredDict -from lbrynet.p2p.call_later_manager import CallLaterManager -from lbrynet.p2p.PeerManager import PeerManager +from lbrynet.utils import generate_id, DeferredDict +from .call_later_manager import CallLaterManager from .error import TimeoutError from . import constants from . import routingtable diff --git a/lbrynet/extras/cli.py b/lbrynet/extras/cli.py index 3ebaf7b8a..3fa0dce11 100644 --- a/lbrynet/extras/cli.py +++ b/lbrynet/extras/cli.py @@ -24,7 +24,7 @@ from lbrynet.extras.daemon.Daemon import Daemon from lbrynet.extras.daemon.DaemonControl import start as daemon_main from lbrynet.extras.daemon.DaemonConsole import main as daemon_console from lbrynet.extras.daemon.auth.client import LBRYAPIClient -from lbrynet.p2p.system_info import get_platform +from lbrynet.system_info import get_platform async def execute_command(method, params, conf_path=None): diff --git a/lbrynet/extras/daemon/ComponentManager.py b/lbrynet/extras/daemon/ComponentManager.py index 59f1304aa..3ccf5889b 100644 --- a/lbrynet/extras/daemon/ComponentManager.py +++ b/lbrynet/extras/daemon/ComponentManager.py @@ -1,8 +1,8 @@ import logging from twisted.internet import defer from lbrynet.p2p.Error import ComponentStartConditionNotMet -from lbrynet.core.PeerManager import PeerManager -from lbrynet.dht.peerfinder import DHTPeerFinder +from .PeerManager import PeerManager +from .PeerFinder import DHTPeerFinder log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/Components.py b/lbrynet/extras/daemon/Components.py index 8642e34d9..8ba078eef 100644 --- a/lbrynet/extras/daemon/Components.py +++ b/lbrynet/extras/daemon/Components.py @@ -11,8 +11,8 @@ import lbrynet.schema from aioupnp import __version__ as aioupnp_version from aioupnp.upnp import UPnP from aioupnp.fault import UPnPError -from lbrynet.extras.daemon import conf -from lbrynet.p2p.utils import DeferredDict +from lbrynet import conf, system_info +from lbrynet.utils import DeferredDict, generate_id from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager from lbrynet.p2p.RateLimiter import RateLimiter from lbrynet.p2p.BlobManager import DiskBlobManager @@ -23,16 +23,15 @@ from lbrynet.p2p.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.p2p.server.ServerProtocol import ServerProtocolFactory from .Component import Component from .ExchangeRateManager import ExchangeRateManager -from lbrynet.extras.daemon.storage import SQLiteStorage -from lbrynet.dht import node -from lbrynet.extras.daemon.HashAnnouncer import DHTHashAnnouncer +from .storage import SQLiteStorage +from .HashAnnouncer import DHTHashAnnouncer + +from lbrynet.dht.node import Node from lbrynet.blob.EncryptedFileManager import EncryptedFileManager from lbrynet.blob.client.EncryptedFileDownloader import EncryptedFileSaverFactory from lbrynet.blob.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier from lbrynet.extras.reflector import ServerFactory as reflector_server_factory -from lbrynet.p2p.utils import generate_id - log = logging.getLogger(__name__) # settings must be initialized before this file is imported @@ -95,8 +94,7 @@ class ConfigSettings: @staticmethod def get_external_ip(): - from lbrynet.p2p.system_info import get_platform - platform = get_platform(get_ip=True) + platform = system_info.get_platform(get_ip=True) return platform['ip'] @@ -435,7 +433,7 @@ class DHTComponent(Component): if not external_ip: log.warning("failed to get external ip") - self.dht_node = node.Node( + self.dht_node = Node( node_id=node_id, udpPort=GCS('dht_node_port'), externalUDPPort=self.external_udp_port, diff --git a/lbrynet/extras/daemon/Daemon.py b/lbrynet/extras/daemon/Daemon.py index 8e8c13fd4..00b4c747c 100644 --- a/lbrynet/extras/daemon/Daemon.py +++ b/lbrynet/extras/daemon/Daemon.py @@ -16,6 +16,8 @@ from twisted.python.failure import Failure from torba.client.baseaccount import SingleKey, HierarchicalDeterministic +from lbrynet import conf, utils, system_info +from lbrynet.system_info import get_lbrynet_version from lbrynet.schema.claim import ClaimDict from lbrynet.schema.uri import parse_lbry_uri from lbrynet.schema.error import URIParseError, DecodeError @@ -23,19 +25,15 @@ from lbrynet.schema.validator import validate_claim_id from lbrynet.schema.address import decode_address from lbrynet.schema.decode import smart_decode -# TODO: importing this when internet is disabled raises a socket.gaierror -from lbrynet.p2p.system_info import get_lbrynet_version -from lbrynet.extras.daemon import conf from lbrynet.extras.reflector import reupload from .Components import d2f, f2d from .Components import WALLET_COMPONENT, DATABASE_COMPONENT, DHT_COMPONENT, BLOB_COMPONENT -from .Components import STREAM_IDENTIFIER_COMPONENT, FILE_MANAGER_COMPONENT, RATE_LIMITER_COMPONENT +from .Components import FILE_MANAGER_COMPONENT, RATE_LIMITER_COMPONENT from .Components import EXCHANGE_RATE_MANAGER_COMPONENT, PAYMENT_RATE_COMPONENT, UPNP_COMPONENT from .ComponentManager import RequiredCondition from .Downloader import GetStream from .Publisher import Publisher from .auth.server import AuthJSONRPCServer -from lbrynet.p2p import utils, system_info from lbrynet.p2p.StreamDescriptor import download_sd_blob from lbrynet.p2p.Error import InsufficientFundsError, UnknownNameError from lbrynet.p2p.Error import DownloadDataTimeout, DownloadSDTimeout @@ -448,7 +446,7 @@ class Daemon(AuthJSONRPCServer): Get total stream size in bytes from a sd blob """ - d = self.sd_identifier.get_metadata_for_sd_blob(sd_blob) + d = self.file_manager.sd_identifier.get_metadata_for_sd_blob(sd_blob) d.addCallback(lambda metadata: metadata.validator.info_to_show()) d.addCallback(lambda info: int(dict(info)['stream_size'])) return d @@ -466,9 +464,7 @@ class Daemon(AuthJSONRPCServer): """ Calculate estimated LBC cost for a stream given its size in bytes """ - cost = self._get_est_cost_from_stream_size(size) - resolved = await self.wallet_manager.resolve(uri) if uri in resolved and 'claim' in resolved[uri]: @@ -533,7 +529,6 @@ class Daemon(AuthJSONRPCServer): sd blob will be downloaded to determine the stream size """ - if size is not None: return self.get_est_cost_using_known_size(uri, size) return self.get_est_cost_from_uri(uri) diff --git a/lbrynet/extras/daemon/DaemonConsole.py b/lbrynet/extras/daemon/DaemonConsole.py index 5a7d6caa0..c7e82c6ac 100644 --- a/lbrynet/extras/daemon/DaemonConsole.py +++ b/lbrynet/extras/daemon/DaemonConsole.py @@ -6,9 +6,9 @@ import logging.handlers from twisted.internet import defer, reactor, threads from aiohttp import client_exceptions -from lbrynet.extras.daemon import analytics, conf -from lbrynet.p2p import utils -from lbrynet.p2p import log_support +from lbrynet.extras.daemon import analytics +from lbrynet import utils, conf +from lbrynet import log_support from .auth.client import LBRYAPIClient from .Daemon import Daemon diff --git a/lbrynet/extras/daemon/DaemonControl.py b/lbrynet/extras/daemon/DaemonControl.py index 09fa07cf8..1cb0a8a4a 100644 --- a/lbrynet/extras/daemon/DaemonControl.py +++ b/lbrynet/extras/daemon/DaemonControl.py @@ -7,15 +7,14 @@ if 'win' in sys.platform: import certifi os.environ['SSL_CERT_FILE'] = certifi.where() -from lbrynet.p2p import log_support +from lbrynet import log_support import argparse import logging.handlers from twisted.internet import reactor -from lbrynet.extras.daemon import conf -from lbrynet.p2p import utils, system_info +from lbrynet import utils, system_info, conf from .Daemon import Daemon log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/Downloader.py b/lbrynet/extras/daemon/Downloader.py index fe036b3cd..5c73c49e7 100644 --- a/lbrynet/extras/daemon/Downloader.py +++ b/lbrynet/extras/daemon/Downloader.py @@ -4,14 +4,14 @@ from twisted.internet import defer from twisted.internet.task import LoopingCall from .Components import f2d +from lbrynet import conf from lbrynet.schema.fee import Fee from lbrynet.p2p.Error import InsufficientFundsError, KeyFeeAboveMaxAllowed, InvalidStreamDescriptorError from lbrynet.p2p.Error import DownloadDataTimeout, DownloadCanceledError, DownloadSDTimeout -from lbrynet.p2p.utils import safe_start_looping_call, safe_stop_looping_call +from lbrynet.utils import safe_start_looping_call, safe_stop_looping_call from lbrynet.p2p.StreamDescriptor import download_sd_blob from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloaderFactory -from lbrynet.extras.daemon import conf from torba.client.constants import COIN from lbrynet.extras.wallet.dewies import dewies_to_lbc diff --git a/lbrynet/extras/daemon/HashAnnouncer.py b/lbrynet/extras/daemon/HashAnnouncer.py index d1cc26d85..819f890fa 100644 --- a/lbrynet/extras/daemon/HashAnnouncer.py +++ b/lbrynet/extras/daemon/HashAnnouncer.py @@ -2,8 +2,7 @@ import binascii import logging from twisted.internet import defer, task -from lbrynet.p2p import utils -from lbrynet.extras.daemon import conf +from lbrynet import utils, conf log = logging.getLogger(__name__) diff --git a/lbrynet/dht/peerfinder.py b/lbrynet/extras/daemon/PeerFinder.py similarity index 98% rename from lbrynet/dht/peerfinder.py rename to lbrynet/extras/daemon/PeerFinder.py index edabb9ee7..2934b13f5 100644 --- a/lbrynet/dht/peerfinder.py +++ b/lbrynet/extras/daemon/PeerFinder.py @@ -2,7 +2,7 @@ import binascii import logging from twisted.internet import defer -from lbrynet.extras.daemon import conf +from lbrynet import conf log = logging.getLogger(__name__) diff --git a/lbrynet/p2p/PeerManager.py b/lbrynet/extras/daemon/PeerManager.py similarity index 100% rename from lbrynet/p2p/PeerManager.py rename to lbrynet/extras/daemon/PeerManager.py diff --git a/lbrynet/extras/daemon/analytics.py b/lbrynet/extras/daemon/analytics.py index 2fe911b2f..907d524f6 100644 --- a/lbrynet/extras/daemon/analytics.py +++ b/lbrynet/extras/daemon/analytics.py @@ -4,8 +4,8 @@ import logging import treq from twisted.internet import defer, task -from lbrynet.extras.daemon import conf -from lbrynet.p2p import looping_call_manager, utils, system_info +from lbrynet import conf, utils, system_info +from lbrynet.extras import looping_call_manager # Things We Track SERVER_STARTUP = 'Server Startup' diff --git a/lbrynet/extras/daemon/auth/client.py b/lbrynet/extras/daemon/auth/client.py index b34e61e50..cb9c657f9 100644 --- a/lbrynet/extras/daemon/auth/client.py +++ b/lbrynet/extras/daemon/auth/client.py @@ -3,7 +3,7 @@ import aiohttp import logging from urllib.parse import urlparse -from lbrynet.extras.daemon import conf +from lbrynet import conf from .keyring import Keyring, APIKey log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/auth/factory.py b/lbrynet/extras/daemon/auth/factory.py index e9bb29375..549b9bd68 100644 --- a/lbrynet/extras/daemon/auth/factory.py +++ b/lbrynet/extras/daemon/auth/factory.py @@ -3,7 +3,7 @@ import logging from twisted.web import server, guard, resource from twisted.cred import portal -from lbrynet.extras.daemon import conf +from lbrynet import conf from .auth import PasswordChecker, HttpPasswordRealm from ..auth.keyring import Keyring diff --git a/lbrynet/extras/daemon/auth/keyring.py b/lbrynet/extras/daemon/auth/keyring.py index 01ac81f16..91d9290a1 100644 --- a/lbrynet/extras/daemon/auth/keyring.py +++ b/lbrynet/extras/daemon/auth/keyring.py @@ -13,7 +13,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization from twisted.internet import ssl import logging -from lbrynet.extras.daemon import conf +from lbrynet import conf log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/auth/server.py b/lbrynet/extras/daemon/auth/server.py index 3e94231db..93d0e8b26 100644 --- a/lbrynet/extras/daemon/auth/server.py +++ b/lbrynet/extras/daemon/auth/server.py @@ -13,12 +13,11 @@ from twisted.python.failure import Failure from twisted.internet.error import ConnectionDone, ConnectionLost from txjsonrpc import jsonrpclib from traceback import format_exc - -from lbrynet.extras.daemon import analytics, conf +from lbrynet import conf, utils +from lbrynet.extras.daemon import analytics from lbrynet.p2p.Error import InvalidAuthenticationToken -from lbrynet.p2p import utils from lbrynet.p2p.Error import ComponentsNotStarted, ComponentStartConditionNotMet -from lbrynet.p2p.looping_call_manager import LoopingCallManager +from lbrynet.extras.looping_call_manager import LoopingCallManager from lbrynet.extras.daemon.ComponentManager import ComponentManager from .keyring import APIKey, Keyring from .undecorated import undecorated diff --git a/lbrynet/extras/daemon/migrator/migrate5to6.py b/lbrynet/extras/daemon/migrator/migrate5to6.py index 367039ab7..017aa965f 100644 --- a/lbrynet/extras/daemon/migrator/migrate5to6.py +++ b/lbrynet/extras/daemon/migrator/migrate5to6.py @@ -3,7 +3,7 @@ import os import json import logging from lbrynet.schema.decode import smart_decode -from lbrynet.extras.daemon import conf +from lbrynet import conf log = logging.getLogger(__name__) diff --git a/lbrynet/extras/daemon/storage.py b/lbrynet/extras/daemon/storage.py index 48742034b..724aabeef 100644 --- a/lbrynet/extras/daemon/storage.py +++ b/lbrynet/extras/daemon/storage.py @@ -6,10 +6,9 @@ from binascii import hexlify, unhexlify from decimal import Decimal from twisted.internet import defer, task, threads from twisted.enterprise import adbapi - +from lbrynet import conf from lbrynet.schema.claim import ClaimDict from lbrynet.schema.decode import smart_decode -from lbrynet.extras.daemon import conf from lbrynet.blob.CryptBlob import CryptBlobInfo from lbrynet.dht.constants import dataExpireTimeout from torba.client.constants import COIN diff --git a/lbrynet/p2p/looping_call_manager.py b/lbrynet/extras/looping_call_manager.py similarity index 100% rename from lbrynet/p2p/looping_call_manager.py rename to lbrynet/extras/looping_call_manager.py diff --git a/lbrynet/extras/reflector/reupload.py b/lbrynet/extras/reflector/reupload.py index 5eca291d5..a2b1548e3 100644 --- a/lbrynet/extras/reflector/reupload.py +++ b/lbrynet/extras/reflector/reupload.py @@ -1,7 +1,7 @@ import random from twisted.internet import reactor, defer -from lbrynet.extras.daemon import conf +from lbrynet import conf from . import ClientFactory, BlobClientFactory diff --git a/lbrynet/extras/reflector/server/server.py b/lbrynet/extras/reflector/server/server.py index 14bf2f889..c1d5f9ac1 100644 --- a/lbrynet/extras/reflector/server/server.py +++ b/lbrynet/extras/reflector/server/server.py @@ -3,7 +3,7 @@ import json from twisted.python import failure from twisted.internet import error, defer from twisted.internet.protocol import Protocol, ServerFactory -from lbrynet.p2p.utils import is_valid_blobhash +from lbrynet.utils import is_valid_blobhash from lbrynet.p2p.Error import DownloadCanceledError, InvalidBlobHashError from lbrynet.p2p.StreamDescriptor import BlobStreamDescriptorReader from lbrynet.p2p.StreamDescriptor import save_sd_info diff --git a/lbrynet/p2p/log_support.py b/lbrynet/log_support.py similarity index 99% rename from lbrynet/p2p/log_support.py rename to lbrynet/log_support.py index 1eed6659a..72cacc2fb 100644 --- a/lbrynet/p2p/log_support.py +++ b/lbrynet/log_support.py @@ -3,14 +3,11 @@ import logging import logging.handlers import sys import traceback - import treq -from twisted.internet import defer import twisted.python.log - +from twisted.internet import defer from lbrynet import __version__ as lbrynet_version, build_type -from lbrynet.extras.daemon import conf -from lbrynet.p2p import utils +from lbrynet import utils, conf class HTTPSHandler(logging.Handler): @@ -214,6 +211,7 @@ def configure_logging(file_name, console, verbose=None): verbose: a list of loggers to set to debug level. See `convert_verbose` for more details. """ + logger = logging.getLoggerClass() verbose = convert_verbose(verbose) configure_twisted() configure_file_handler(file_name) diff --git a/lbrynet/p2p/HTTPBlobDownloader.py b/lbrynet/p2p/HTTPBlobDownloader.py index 8619737fa..62e685f48 100644 --- a/lbrynet/p2p/HTTPBlobDownloader.py +++ b/lbrynet/p2p/HTTPBlobDownloader.py @@ -4,7 +4,7 @@ from twisted.internet import defer, task from twisted.internet.error import ConnectingCancelledError from twisted.web._newclient import ResponseNeverReceived import treq -from lbrynet.p2p.utils import DeferredDict +from lbrynet.utils import DeferredDict from lbrynet.p2p.Error import DownloadCanceledError log = logging.getLogger(__name__) diff --git a/lbrynet/p2p/PaymentRateManager.py b/lbrynet/p2p/PaymentRateManager.py index fcf7bbd54..372204365 100644 --- a/lbrynet/p2p/PaymentRateManager.py +++ b/lbrynet/p2p/PaymentRateManager.py @@ -1,5 +1,5 @@ from lbrynet.p2p.Strategy import get_default_strategy, OnlyFreeStrategy -from lbrynet.extras.daemon import conf +from lbrynet import conf from decimal import Decimal diff --git a/lbrynet/p2p/Peer.py b/lbrynet/p2p/Peer.py index f06ce806d..bd52e0da3 100644 --- a/lbrynet/p2p/Peer.py +++ b/lbrynet/p2p/Peer.py @@ -1,6 +1,6 @@ import datetime from collections import defaultdict -from lbrynet.p2p import utils +from lbrynet import utils # Do not create this object except through PeerManager class Peer: diff --git a/lbrynet/p2p/PriceModel.py b/lbrynet/p2p/PriceModel.py index 14d7f0c34..4d065d47a 100644 --- a/lbrynet/p2p/PriceModel.py +++ b/lbrynet/p2p/PriceModel.py @@ -1,6 +1,5 @@ from decimal import Decimal - -from lbrynet.extras.daemon import conf +from lbrynet import conf def get_default_price_model(blob_tracker, base_price, **kwargs): diff --git a/lbrynet/p2p/SinglePeerDownloader.py b/lbrynet/p2p/SinglePeerDownloader.py index ab1eee31f..7936caa85 100644 --- a/lbrynet/p2p/SinglePeerDownloader.py +++ b/lbrynet/p2p/SinglePeerDownloader.py @@ -12,7 +12,7 @@ from lbrynet.p2p.client.BlobRequester import BlobRequester from lbrynet.p2p.client.StandaloneBlobDownloader import StandaloneBlobDownloader from lbrynet.p2p.client.ConnectionManager import ConnectionManager from lbrynet.extras.daemon.storage import SQLiteStorage -from lbrynet.dht.peerfinder import DummyPeerFinder +from lbrynet.extras.daemon.PeerFinder import DummyPeerFinder log = logging.getLogger(__name__) diff --git a/lbrynet/p2p/Strategy.py b/lbrynet/p2p/Strategy.py index 3477985ca..da478fb67 100644 --- a/lbrynet/p2p/Strategy.py +++ b/lbrynet/p2p/Strategy.py @@ -1,5 +1,5 @@ from decimal import Decimal -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.p2p.Offer import Offer from lbrynet.p2p.PriceModel import MeanAvailabilityWeightedPrice, ZeroPrice @@ -133,7 +133,6 @@ class BasicAvailabilityWeightedStrategy(Strategy): class OnlyFreeStrategy(Strategy): - def __init__(self, *args, **kwargs): price_model = ZeroPrice() super().__init__(price_model, 0.0, 0.0, True) diff --git a/lbrynet/p2p/StreamDescriptor.py b/lbrynet/p2p/StreamDescriptor.py index 9e8849dcb..534d02db6 100644 --- a/lbrynet/p2p/StreamDescriptor.py +++ b/lbrynet/p2p/StreamDescriptor.py @@ -5,7 +5,7 @@ import json import logging from twisted.internet import threads, defer -from lbrynet.p2p.cryptoutils import get_lbry_hash_obj +from lbrynet.cryptoutils import get_lbry_hash_obj from lbrynet.p2p.client.StandaloneBlobDownloader import StandaloneBlobDownloader from lbrynet.p2p.Error import UnknownStreamTypeError, InvalidStreamDescriptorError from lbrynet.p2p.HTTPBlobDownloader import HTTPBlobDownloader diff --git a/lbrynet/p2p/client/ClientProtocol.py b/lbrynet/p2p/client/ClientProtocol.py index 20568dc97..0f8167b79 100644 --- a/lbrynet/p2p/client/ClientProtocol.py +++ b/lbrynet/p2p/client/ClientProtocol.py @@ -5,8 +5,7 @@ from twisted.internet import error, defer from twisted.internet.protocol import Protocol, ClientFactory from twisted.protocols.policies import TimeoutMixin from twisted.python import failure -from lbrynet.extras.daemon import conf -from lbrynet.p2p import utils +from lbrynet import conf, utils from lbrynet.p2p.Error import ConnectionClosedBeforeResponseError, NoResponseError from lbrynet.p2p.Error import DownloadCanceledError, MisbehavingPeerError from lbrynet.p2p.Error import RequestCanceledError diff --git a/lbrynet/p2p/client/ConnectionManager.py b/lbrynet/p2p/client/ConnectionManager.py index f56fb0382..af299d167 100644 --- a/lbrynet/p2p/client/ConnectionManager.py +++ b/lbrynet/p2p/client/ConnectionManager.py @@ -1,10 +1,9 @@ import random import logging from twisted.internet import defer, reactor -from lbrynet.extras.daemon import conf +from lbrynet import utils, conf from lbrynet.p2p.client.ClientProtocol import ClientProtocolFactory from lbrynet.p2p.Error import InsufficientFundsError -from lbrynet.p2p import utils log = logging.getLogger(__name__) diff --git a/lbrynet/p2p/client/StandaloneBlobDownloader.py b/lbrynet/p2p/client/StandaloneBlobDownloader.py index 08aa0b386..6715f10b3 100644 --- a/lbrynet/p2p/client/StandaloneBlobDownloader.py +++ b/lbrynet/p2p/client/StandaloneBlobDownloader.py @@ -4,7 +4,7 @@ from lbrynet.p2p.client.BlobRequester import BlobRequester from lbrynet.p2p.client.ConnectionManager import ConnectionManager from lbrynet.p2p.client.DownloadManager import DownloadManager from lbrynet.p2p.Error import InvalidBlobHashError, DownloadSDTimeout -from lbrynet.p2p.utils import is_valid_blobhash, safe_start_looping_call, safe_stop_looping_call +from lbrynet.utils import is_valid_blobhash, safe_start_looping_call, safe_stop_looping_call from twisted.python.failure import Failure from twisted.internet import defer from twisted.internet.task import LoopingCall diff --git a/lbrynet/p2p/system_info.py b/lbrynet/system_info.py similarity index 100% rename from lbrynet/p2p/system_info.py rename to lbrynet/system_info.py diff --git a/lbrynet/p2p/utils.py b/lbrynet/utils.py similarity index 99% rename from lbrynet/p2p/utils.py rename to lbrynet/utils.py index e7a459edf..52a33e581 100644 --- a/lbrynet/p2p/utils.py +++ b/lbrynet/utils.py @@ -12,7 +12,7 @@ import pkg_resources from twisted.python.failure import Failure from twisted.internet import defer from lbrynet.schema.claim import ClaimDict -from lbrynet.p2p.cryptoutils import get_lbry_hash_obj +from lbrynet.cryptoutils import get_lbry_hash_obj log = logging.getLogger(__name__) @@ -52,6 +52,7 @@ def call_later(delay, func, *args, **kwargs): from twisted.internet import reactor return reactor.callLater(delay, func, *args, **kwargs) + def safe_start_looping_call(looping_call, interval_sec): if not looping_call.running: looping_call.start(interval_sec) diff --git a/lbrynet/extras/daemon/winpaths.py b/lbrynet/winpaths.py similarity index 100% rename from lbrynet/extras/daemon/winpaths.py rename to lbrynet/winpaths.py diff --git a/scripts/encrypt_blob.py b/scripts/encrypt_blob.py index 2b83dce3e..3993ffaeb 100644 --- a/scripts/encrypt_blob.py +++ b/scripts/encrypt_blob.py @@ -9,7 +9,7 @@ from twisted.web.client import FileBodyProducer from lbrynet import conf from lbrynet.core import log_support -from lbrynet.dht.hashannouncer import DummyHashAnnouncer +from lbrynet.extras.daemon.HashAnnouncer import DHTHashAnnouncer from lbrynet.core.BlobManager import DiskBlobManager from lbrynet.cryptstream.CryptStreamCreator import CryptStreamCreator diff --git a/tests/functional/test_misc.py b/tests/functional/test_misc.py index 0cbead0c7..606c2b372 100644 --- a/tests/functional/test_misc.py +++ b/tests/functional/test_misc.py @@ -2,13 +2,13 @@ import os from hashlib import md5 from twisted.internet import defer, reactor from twisted.trial import unittest -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.p2p.server.BlobAvailabilityHandler import BlobAvailabilityHandlerFactory from lbrynet.p2p.StreamDescriptor import StreamDescriptorIdentifier from lbrynet.p2p.StreamDescriptor import download_sd_blob from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager from lbrynet.p2p.BlobManager import DiskBlobManager -from lbrynet.p2p.PeerManager import PeerManager +from lbrynet.extras.daemon.PeerManager import PeerManager from lbrynet.p2p.RateLimiter import RateLimiter from lbrynet.p2p.server.BlobRequestHandler import BlobRequestHandlerFactory from lbrynet.p2p.server.ServerProtocol import ServerProtocolFactory @@ -18,7 +18,7 @@ from lbrynet.blob.EncryptedFileManager import EncryptedFileManager from lbrynet.blob.client.EncryptedFileOptions import add_lbry_file_to_sd_identifier from tests import mocks -from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir +from tests.test_utils import mk_db_and_blob_dir, rm_db_and_blob_dir FakeNode = mocks.Node FakeWallet = mocks.Wallet diff --git a/tests/functional/test_reflector.py b/tests/functional/test_reflector.py index c6b4128ac..bac25c3a4 100644 --- a/tests/functional/test_reflector.py +++ b/tests/functional/test_reflector.py @@ -5,7 +5,8 @@ from twisted.internet import defer, error from twisted.trial import unittest from lbrynet.p2p.StreamDescriptor import get_sd_info from lbrynet.extras import reflector -from lbrynet.p2p import BlobManager, PeerManager +from lbrynet.extras.daemon.PeerManager import PeerManager +from lbrynet.p2p import BlobManager from lbrynet.p2p import StreamDescriptor from lbrynet.blob import EncryptedFileCreator from lbrynet.blob.EncryptedFileManager import EncryptedFileManager @@ -13,7 +14,7 @@ from lbrynet.p2p.RateLimiter import DummyRateLimiter from lbrynet.extras.daemon.storage import SQLiteStorage from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager from tests import mocks -from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir +from tests.test_utils import mk_db_and_blob_dir, rm_db_and_blob_dir class TestReflector(unittest.TestCase): diff --git a/tests/functional/test_streamify.py b/tests/functional/test_streamify.py index a044624b7..52008aeb9 100644 --- a/tests/functional/test_streamify.py +++ b/tests/functional/test_streamify.py @@ -7,8 +7,8 @@ from twisted.internet import defer, threads from lbrynet.p2p.StreamDescriptor import StreamDescriptorIdentifier from lbrynet.p2p.BlobManager import DiskBlobManager from lbrynet.p2p.StreamDescriptor import get_sd_info -from lbrynet.p2p.PeerManager import PeerManager from lbrynet.p2p.RateLimiter import DummyRateLimiter +from lbrynet.extras.daemon.PeerManager import PeerManager from lbrynet.extras.daemon.storage import SQLiteStorage from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager from lbrynet.blob.EncryptedFileCreator import create_lbry_file diff --git a/tests/integration/cli/test_cli.py b/tests/integration/cli/test_cli.py index cd652b2f7..d2861ec87 100644 --- a/tests/integration/cli/test_cli.py +++ b/tests/integration/cli/test_cli.py @@ -4,7 +4,7 @@ from io import StringIO from twisted.internet import defer from lbrynet import conf -from lbrynet import cli +from lbrynet.extras import cli from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, WALLET_COMPONENT, \ DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, FILE_MANAGER_COMPONENT, \ PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, UPNP_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, \ diff --git a/tests/integration/wallet/test_commands.py b/tests/integration/wallet/test_commands.py index 65e095515..0bdc2cf3c 100644 --- a/tests/integration/wallet/test_commands.py +++ b/tests/integration/wallet/test_commands.py @@ -15,7 +15,7 @@ from torba.testcase import IntegrationTestCase as BaseIntegrationTestCase import lbrynet.schema lbrynet.schema.BLOCKCHAIN_NAME = 'lbrycrd_regtest' -from lbrynet.extras.daemon import conf as lbry_conf +from lbrynet import conf as lbry_conf from lbrynet.dht.node import Node from lbrynet.extras.daemon.Daemon import Daemon from lbrynet.extras.wallet import LbryWalletManager diff --git a/tests/mocks.py b/tests/mocks.py index 8e9be2294..47ec2e583 100644 --- a/tests/mocks.py +++ b/tests/mocks.py @@ -7,13 +7,13 @@ from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization from twisted.internet import defer from twisted.python.failure import Failure - +from lbrynet import conf from lbrynet.p2p.client.ClientRequest import ClientRequest from lbrynet.p2p.Error import RequestCanceledError from lbrynet.p2p import BlobAvailability from lbrynet.blob.EncryptedFileManager import EncryptedFileManager from lbrynet.dht.node import Node as RealNode -from lbrynet.extras.daemon import ExchangeRateManager as ERM, conf +from lbrynet.extras.daemon import ExchangeRateManager as ERM KB = 2**10 PUBLIC_EXPONENT = 65537 # http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html diff --git a/tests/util.py b/tests/test_utils.py similarity index 91% rename from tests/util.py rename to tests/test_utils.py index 8b65b7033..c03de4745 100644 --- a/tests/util.py +++ b/tests/test_utils.py @@ -32,13 +32,14 @@ def resetTime(test_case, timestamp=DEFAULT_TIMESTAMP): patcher.start().return_value = iso_time test_case.addCleanup(patcher.stop) - patcher = mock.patch('lbrynet.p2p.utils.now') + patcher = mock.patch('lbrynet.utils.now') patcher.start().return_value = timestamp test_case.addCleanup(patcher.stop) - patcher = mock.patch('lbrynet.p2p.utils.utcnow') + patcher = mock.patch('lbrynet.utils.utcnow') patcher.start().return_value = timestamp test_case.addCleanup(patcher.stop) + def is_android(): return 'ANDROID_ARGUMENT' in os.environ # detect Android using the Kivy way diff --git a/tests/unit/core/client/test_ConnectionManager.py b/tests/unit/core/client/test_ConnectionManager.py index b8c0b301d..7a9d95069 100644 --- a/tests/unit/core/client/test_ConnectionManager.py +++ b/tests/unit/core/client/test_ConnectionManager.py @@ -1,17 +1,16 @@ +from twisted.trial.unittest import TestCase +from twisted.internet import defer, reactor, task +from twisted.internet.task import deferLater +from twisted.internet.protocol import ServerFactory + +from lbrynet import conf, utils from lbrynet.p2p.client.ClientRequest import ClientRequest from lbrynet.p2p.server.ServerProtocol import ServerProtocol from lbrynet.p2p.client.ClientProtocol import ClientProtocol from lbrynet.p2p.RateLimiter import RateLimiter from lbrynet.p2p.Peer import Peer -from lbrynet.p2p.PeerManager import PeerManager from lbrynet.p2p.Error import NoResponseError - -from twisted.trial.unittest import TestCase -from twisted.internet import defer, reactor, task -from twisted.internet.task import deferLater -from twisted.internet.protocol import ServerFactory -from lbrynet.extras.daemon import conf -from lbrynet.p2p import utils +from lbrynet.extras.daemon.PeerManager import PeerManager PEER_PORT = 5551 LOCAL_HOST = '127.0.0.1' diff --git a/tests/unit/core/test_BlobManager.py b/tests/unit/core/test_BlobManager.py index 590cb6225..70338ff1f 100644 --- a/tests/unit/core/test_BlobManager.py +++ b/tests/unit/core/test_BlobManager.py @@ -6,12 +6,12 @@ import string from twisted.trial import unittest from twisted.internet import defer -from tests.util import random_lbry_hash +from tests.test_utils import random_lbry_hash from lbrynet.p2p.BlobManager import DiskBlobManager from lbrynet.extras.daemon.storage import SQLiteStorage from lbrynet.p2p.Peer import Peer -from lbrynet.extras.daemon import conf -from lbrynet.p2p.cryptoutils import get_lbry_hash_obj +from lbrynet import conf +from lbrynet.cryptoutils import get_lbry_hash_obj class BlobManagerTest(unittest.TestCase): diff --git a/tests/unit/core/test_HTTPBlobDownloader.py b/tests/unit/core/test_HTTPBlobDownloader.py index 40fb98452..5112e38aa 100644 --- a/tests/unit/core/test_HTTPBlobDownloader.py +++ b/tests/unit/core/test_HTTPBlobDownloader.py @@ -5,7 +5,7 @@ from twisted.internet import defer from lbrynet.blob import BlobFile from lbrynet.p2p.HTTPBlobDownloader import HTTPBlobDownloader -from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir +from tests.test_utils import mk_db_and_blob_dir, rm_db_and_blob_dir class HTTPBlobDownloaderTest(unittest.TestCase): diff --git a/tests/unit/core/test_HashBlob.py b/tests/unit/core/test_HashBlob.py index 5e7ab86ff..d7c5003c6 100644 --- a/tests/unit/core/test_HashBlob.py +++ b/tests/unit/core/test_HashBlob.py @@ -1,7 +1,7 @@ from lbrynet.blob import BlobFile from lbrynet.p2p.Error import DownloadCanceledError, InvalidDataError -from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir, random_lbry_hash +from tests.test_utils import mk_db_and_blob_dir, rm_db_and_blob_dir, random_lbry_hash from twisted.trial import unittest from twisted.internet import defer diff --git a/tests/unit/core/test_Wallet.py b/tests/unit/core/test_Wallet.py index 3083be6f4..d5fa5e193 100644 --- a/tests/unit/core/test_Wallet.py +++ b/tests/unit/core/test_Wallet.py @@ -5,9 +5,6 @@ from decimal import Decimal from twisted.trial import unittest from twisted.internet import defer from lbrynet.p2p.Error import InsufficientFundsError -#from lbrynet.p2p.Wallet import LBRYumWallet, ReservedPoints -#from lbryum.commands import Commands -#from lbryum.simple_config import SimpleConfig from lbrynet.schema.claim import ClaimDict test_metadata = { diff --git a/tests/unit/core/test_utils.py b/tests/unit/core/test_utils.py index c4f1289e2..bfb5f8b86 100644 --- a/tests/unit/core/test_utils.py +++ b/tests/unit/core/test_utils.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from lbrynet.p2p import utils +from lbrynet import utils from twisted.trial import unittest diff --git a/tests/unit/database/test_SQLiteStorage.py b/tests/unit/database/test_SQLiteStorage.py index 318a05a8e..e8794bbb7 100644 --- a/tests/unit/database/test_SQLiteStorage.py +++ b/tests/unit/database/test_SQLiteStorage.py @@ -5,10 +5,10 @@ import logging from copy import deepcopy from twisted.internet import defer from twisted.trial import unittest -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.extras.daemon.storage import SQLiteStorage, open_file_for_writing from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloader -from tests.util import random_lbry_hash +from tests.test_utils import random_lbry_hash log = logging.getLogger() diff --git a/tests/unit/dht/test_contact.py b/tests/unit/dht/test_contact.py index 3543854d9..2721a8fe7 100644 --- a/tests/unit/dht/test_contact.py +++ b/tests/unit/dht/test_contact.py @@ -1,7 +1,7 @@ from binascii import hexlify from twisted.internet import task from twisted.trial import unittest -from lbrynet.p2p.utils import generate_id +from lbrynet.utils import generate_id from lbrynet.dht.contact import ContactManager from lbrynet.dht import constants diff --git a/tests/unit/dht/test_hash_announcer.py b/tests/unit/dht/test_hash_announcer.py index 5aeb54943..5d7179712 100644 --- a/tests/unit/dht/test_hash_announcer.py +++ b/tests/unit/dht/test_hash_announcer.py @@ -1,8 +1,8 @@ from twisted.trial import unittest from twisted.internet import defer, task -from lbrynet.p2p import utils +from lbrynet import utils from lbrynet.extras.daemon.HashAnnouncer import DHTHashAnnouncer -from tests.util import random_lbry_hash +from tests.test_utils import random_lbry_hash from tests.mocks import mock_conf_settings diff --git a/tests/unit/dht/test_kbucket.py b/tests/unit/dht/test_kbucket.py index b746afa7b..360dee32d 100644 --- a/tests/unit/dht/test_kbucket.py +++ b/tests/unit/dht/test_kbucket.py @@ -6,7 +6,7 @@ from twisted.trial import unittest import struct -from lbrynet.p2p.utils import generate_id +from lbrynet.utils import generate_id from lbrynet.dht import kbucket from lbrynet.dht.contact import ContactManager from lbrynet.dht import constants diff --git a/tests/unit/dht/test_node.py b/tests/unit/dht/test_node.py index a82cdb803..983975235 100644 --- a/tests/unit/dht/test_node.py +++ b/tests/unit/dht/test_node.py @@ -5,7 +5,7 @@ from twisted.trial import unittest from twisted.internet import defer from lbrynet.dht.node import Node from lbrynet.dht import constants -from lbrynet.p2p.utils import generate_id +from lbrynet.utils import generate_id class NodeIDTest(unittest.TestCase): diff --git a/tests/unit/dht/test_routingtable.py b/tests/unit/dht/test_routingtable.py index 37131b53f..1c7985cc8 100644 --- a/tests/unit/dht/test_routingtable.py +++ b/tests/unit/dht/test_routingtable.py @@ -6,7 +6,7 @@ from lbrynet.dht import constants from lbrynet.dht.routingtable import TreeRoutingTable from lbrynet.dht.contact import ContactManager from lbrynet.dht.distance import Distance -from lbrynet.p2p.utils import generate_id +from lbrynet.utils import generate_id class FakeRPCProtocol: diff --git a/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py b/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py index 8266f29bf..36d6db299 100644 --- a/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py +++ b/tests/unit/lbryfilemanager/test_EncryptedFileCreator.py @@ -3,10 +3,10 @@ from twisted.trial import unittest from twisted.internet import defer from cryptography.hazmat.primitives.ciphers.algorithms import AES +from lbrynet.extras.daemon.PeerManager import PeerManager from lbrynet.p2p.StreamDescriptor import get_sd_info, BlobStreamDescriptorReader from lbrynet.p2p.StreamDescriptor import StreamDescriptorIdentifier from lbrynet.p2p.BlobManager import DiskBlobManager -from lbrynet.p2p.PeerManager import PeerManager from lbrynet.p2p.RateLimiter import DummyRateLimiter from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager from lbrynet.extras.daemon.storage import SQLiteStorage @@ -14,7 +14,7 @@ from lbrynet.blob import EncryptedFileCreator from lbrynet.blob.EncryptedFileManager import EncryptedFileManager from lbrynet.p2p.StreamDescriptor import JSONBytesEncoder from tests import mocks -from tests.util import mk_db_and_blob_dir, rm_db_and_blob_dir +from tests.test_utils import mk_db_and_blob_dir, rm_db_and_blob_dir FakeNode = mocks.Node diff --git a/tests/unit/lbrynet_daemon/auth/test_server.py b/tests/unit/lbrynet_daemon/auth/test_server.py index 69b1a12be..849a2634c 100644 --- a/tests/unit/lbrynet_daemon/auth/test_server.py +++ b/tests/unit/lbrynet_daemon/auth/test_server.py @@ -1,7 +1,7 @@ import mock from twisted.internet import reactor from twisted.trial import unittest -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.extras.daemon.auth import server from tests.mocks import mock_conf_settings diff --git a/tests/unit/lbrynet_daemon/test_Daemon.py b/tests/unit/lbrynet_daemon/test_Daemon.py index eed2d60a8..fd8b6d5ce 100644 --- a/tests/unit/lbrynet_daemon/test_Daemon.py +++ b/tests/unit/lbrynet_daemon/test_Daemon.py @@ -7,9 +7,8 @@ from twisted.internet import defer from twisted.trial import unittest from faker import Faker - +from lbrynet import conf from lbrynet.schema.decode import smart_decode -from lbrynet.extras.daemon import conf from lbrynet.extras.daemon.storage import SQLiteStorage from lbrynet.extras.daemon.ComponentManager import ComponentManager from lbrynet.extras.daemon.Components import DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT @@ -23,24 +22,19 @@ from lbrynet.extras.wallet import LbryWalletManager from torba.client.wallet import Wallet from lbrynet.p2p.PaymentRateManager import OnlyFreePaymentsManager -from tests import util +from tests import test_utils from tests.mocks import mock_conf_settings, FakeNetwork, FakeFileManager from tests.mocks import ExchangeRateManager as DummyExchangeRateManager from tests.mocks import BTCLBCFeed, USDBTCFeed -from tests.util import is_android - - -import logging -logging.getLogger("lbryum").setLevel(logging.WARNING) +from tests.test_utils import is_android def get_test_daemon(data_rate=None, generous=True, with_fee=False): if data_rate is None: data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1] - rates = { - 'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1}, - 'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2} + 'BTCLBC': {'spot': 3.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1}, + 'USDBTC': {'spot': 2.0, 'ts': test_utils.DEFAULT_ISO_TIME + 2} } component_manager = ComponentManager( skip_components=[DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, UPNP_COMPONENT, @@ -89,7 +83,7 @@ class TestCostEst(unittest.TestCase): def setUp(self): mock_conf_settings(self) - util.resetTime(self) + test_utils.resetTime(self) @defer.inlineCallbacks def test_fee_and_generous_data(self): @@ -134,7 +128,7 @@ class TestJsonRpc(unittest.TestCase): return None mock_conf_settings(self) - util.resetTime(self) + test_utils.resetTime(self) self.test_daemon = get_test_daemon() self.test_daemon.wallet_manager.is_first_run = False self.test_daemon.wallet_manager.get_best_blockhash = noop @@ -156,7 +150,7 @@ class TestFileListSorting(unittest.TestCase): def setUp(self): mock_conf_settings(self) - util.resetTime(self) + test_utils.resetTime(self) self.faker = Faker('en_US') self.faker.seed(129) # contains 3 same points paid (5.9) self.test_daemon = get_test_daemon() diff --git a/tests/unit/lbrynet_daemon/test_Downloader.py b/tests/unit/lbrynet_daemon/test_Downloader.py index f930d2d5e..aaf600b5e 100644 --- a/tests/unit/lbrynet_daemon/test_Downloader.py +++ b/tests/unit/lbrynet_daemon/test_Downloader.py @@ -12,7 +12,7 @@ from lbrynet.p2p.RateLimiter import DummyRateLimiter from lbrynet.extras.daemon import Downloader from lbrynet.extras.daemon import ExchangeRateManager from lbrynet.extras.daemon.storage import SQLiteStorage -from lbrynet.dht.peerfinder import DummyPeerFinder +from lbrynet.extras.daemon.PeerFinder import DummyPeerFinder from lbrynet.blob.EncryptedFileStatusReport import EncryptedFileStatusReport from lbrynet.blob.EncryptedFileDownloader import ManagedEncryptedFileDownloader from lbrynet.extras.wallet import LbryWalletManager diff --git a/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py b/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py index b3f2f1b3e..651d3c35e 100644 --- a/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py +++ b/tests/unit/lbrynet_daemon/test_ExchangeRateManager.py @@ -3,7 +3,7 @@ from lbrynet.extras.daemon import ExchangeRateManager from lbrynet.p2p.Error import InvalidExchangeRateResponse from twisted.trial import unittest from twisted.internet import defer -from tests import util +from tests import test_utils from tests.mocks import ExchangeRateManager as DummyExchangeRateManager from tests.mocks import BTCLBCFeed, USDBTCFeed @@ -32,18 +32,18 @@ class FeeFormatTest(unittest.TestCase): class ExchangeRateTest(unittest.TestCase): def setUp(self): - util.resetTime(self) + test_utils.resetTime(self) def test_invalid_rates(self): with self.assertRaises(ValueError): - ExchangeRateManager.ExchangeRate('USDBTC', 0, util.DEFAULT_ISO_TIME) + ExchangeRateManager.ExchangeRate('USDBTC', 0, test_utils.DEFAULT_ISO_TIME) with self.assertRaises(ValueError): - ExchangeRateManager.ExchangeRate('USDBTC', -1, util.DEFAULT_ISO_TIME) + ExchangeRateManager.ExchangeRate('USDBTC', -1, test_utils.DEFAULT_ISO_TIME) class FeeTest(unittest.TestCase): def setUp(self): - util.resetTime(self) + test_utils.resetTime(self) def test_fee_converts_to_lbc(self): fee = Fee({ @@ -53,8 +53,8 @@ class FeeTest(unittest.TestCase): }) rates = { - 'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1}, - 'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2} + 'BTCLBC': {'spot': 3.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1}, + 'USDBTC': {'spot': 2.0, 'ts': test_utils.DEFAULT_ISO_TIME + 2} } market_feeds = [BTCLBCFeed(), USDBTCFeed()] @@ -71,7 +71,7 @@ class FeeTest(unittest.TestCase): }) rates = { - 'BTCLBC': {'spot': 1.0, 'ts': util.DEFAULT_ISO_TIME + 1}, + 'BTCLBC': {'spot': 1.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1}, } market_feeds = [BTCLBCFeed()] manager = DummyExchangeRateManager(market_feeds, rates) diff --git a/tests/unit/lbrynet_daemon/test_claims_comparator.py b/tests/unit/lbrynet_daemon/test_claims_comparator.py index afd246900..a1d6dd0aa 100644 --- a/tests/unit/lbrynet_daemon/test_claims_comparator.py +++ b/tests/unit/lbrynet_daemon/test_claims_comparator.py @@ -1,4 +1,4 @@ -import unittest +from twisted.trial import unittest from lbrynet.extras.daemon.Daemon import sort_claim_results diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index d4cbf96a1..a3b49047c 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -3,7 +3,7 @@ from io import StringIO from twisted.trial import unittest from lbrynet.extras.cli import normalize_value, main -from lbrynet.p2p.system_info import get_platform +from lbrynet.system_info import get_platform class CLITest(unittest.TestCase): diff --git a/tests/unit/test_conf.py b/tests/unit/test_conf.py index 8958d64d6..5ab939b6d 100644 --- a/tests/unit/test_conf.py +++ b/tests/unit/test_conf.py @@ -4,7 +4,7 @@ import sys import tempfile from unittest import skipIf from twisted.trial import unittest -from lbrynet.extras.daemon import conf +from lbrynet import conf from lbrynet.p2p.Error import InvalidCurrencyError