diff --git a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py index 804dcc75d51..6c8f7ca0193 100644 --- a/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py +++ b/src/tribler-core/tribler_core/components/gigachannel_manager/tests/test_gigachannel_manager.py @@ -12,8 +12,8 @@ from tribler_common.simpledefs import DLSTATUS_SEEDING -from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.gigachannel_manager.gigachannel_manager import GigaChannelManager +from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.tests.tools.base_test import MockObject from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py index 3940d7f0a54..24e8dcacff3 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/orm_bindings/channel_metadata.py @@ -27,8 +27,8 @@ HealthItemsPayload, ) from tribler_core.utilities.path_util import Path -from tribler_core.utilities.utilities import random_infohash from tribler_core.utilities.unicode import hexlify +from tribler_core.utilities.utilities import random_infohash CHANNEL_DIR_NAME_PK_LENGTH = 32 # Its not 40 so it could be distinguished from infohash CHANNEL_DIR_NAME_ID_LENGTH = 16 # Zero-padded long int in hex form diff --git a/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_store.py b/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_store.py index 904523509d2..6968b013c5f 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_store.py +++ b/src/tribler-core/tribler_core/components/metadata_store/db/tests/test_store.py @@ -6,13 +6,16 @@ from datetime import datetime from unittest.mock import patch -import pytest +from ipv8.keyvault.crypto import default_eccrypto + from pony.orm import db_session -from ipv8.keyvault.crypto import default_eccrypto -from tribler_core.components.metadata_store.remote_query_community.payload_checker import ObjState, ProcessingResult -from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import CHANNEL_DIR_NAME_LENGTH, \ - entries_to_chunk +import pytest + +from tribler_core.components.metadata_store.db.orm_bindings.channel_metadata import ( + CHANNEL_DIR_NAME_LENGTH, + entries_to_chunk, +) from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW from tribler_core.components.metadata_store.db.serialization import ( CHANNEL_TORRENT, @@ -22,12 +25,12 @@ UnknownBlobTypeException, int2time, ) +from tribler_core.components.metadata_store.remote_query_community.payload_checker import ObjState, ProcessingResult from tribler_core.components.metadata_store.tests.test_channel_download import CHANNEL_METADATA_UPDATED from tribler_core.tests.tools.common import TESTS_DATA_DIR from tribler_core.utilities.path_util import Path from tribler_core.utilities.utilities import random_infohash - # pylint: disable=protected-access,unused-argument diff --git a/src/tribler-core/tribler_core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py b/src/tribler-core/tribler_core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py index 0e85ada1abb..222a5aa7acc 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py +++ b/src/tribler-core/tribler_core/components/metadata_store/remote_query_community/tests/test_remote_query_community.py @@ -26,8 +26,8 @@ ) from tribler_core.components.metadata_store.remote_query_community.settings import RemoteQueryCommunitySettings from tribler_core.utilities.path_util import Path -from tribler_core.utilities.utilities import random_infohash from tribler_core.utilities.unicode import hexlify +from tribler_core.utilities.utilities import random_infohash # pylint: disable=protected-access diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py index 6153ee00052..4d85220605a 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_channels_endpoint.py @@ -24,8 +24,8 @@ from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE -from tribler_core.utilities.utilities import random_infohash from tribler_core.utilities.unicode import hexlify +from tribler_core.utilities.utilities import random_infohash PNG_DATA = unhexlify( "89504e470d0a1a0a0000000d494844520" diff --git a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_remote_query_endpoint.py b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_remote_query_endpoint.py index 2478f991183..5cb8d31482f 100644 --- a/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_remote_query_endpoint.py +++ b/src/tribler-core/tribler_core/components/metadata_store/restapi/tests/test_remote_query_endpoint.py @@ -14,8 +14,8 @@ from tribler_core.components.metadata_store.restapi.remote_query_endpoint import RemoteQueryEndpoint from tribler_core.components.restapi.rest.base_api_test import do_request from tribler_core.components.restapi.rest.rest_manager import error_middleware -from tribler_core.utilities.utilities import random_infohash from tribler_core.utilities.unicode import hexlify +from tribler_core.utilities.utilities import random_infohash # pylint: disable=unused-argument diff --git a/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py b/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py index 42c4d1a0b6b..63a8e9574aa 100644 --- a/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py +++ b/src/tribler-core/tribler_core/utilities/tests/test_utilities2.py @@ -1,12 +1,14 @@ -import pytest from aiohttp import ClientSession +import pytest + from tribler_core.utilities.utilities import ( is_channel_public_key, is_infohash, is_simple_match_query, is_valid_url, - parse_magnetlink, random_infohash, + parse_magnetlink, + random_infohash, ) diff --git a/src/tribler-core/tribler_core/utilities/utilities.py b/src/tribler-core/tribler_core/utilities/utilities.py index a2f0a4e19e2..d7b127c009d 100644 --- a/src/tribler-core/tribler_core/utilities/utilities.py +++ b/src/tribler-core/tribler_core/utilities/utilities.py @@ -3,11 +3,9 @@ provides a method for HTTP GET requests as well as a function to translate peers into health. Author(s): Jie Yang """ -import os -import random - import binascii import logging +import random import re from base64 import b32decode from functools import wraps @@ -40,6 +38,7 @@ def init_decorator(func): def wrapper(self, *args, **kwargs): func(self, *args, **kwargs) self.__frozen = True + return wrapper cls.__setattr__ = frozensetattr @@ -63,7 +62,7 @@ def is_valid_url(url): url = url.lower().replace('udp', 'http', 1) split_url = urlsplit(url) - return not(split_url[0] == '' or split_url[1] == '') + return not (split_url[0] == '' or split_url[1] == '') def parse_magnetlink(url): @@ -169,5 +168,4 @@ def bdecode_compat(packet_buffer): def random_infohash(random_gen=None): r = random_gen or random - """ Generates a random torrent infohash binary string """ - return r.getrandbits(20*8).to_bytes(20, byteorder='big') \ No newline at end of file + return r.getrandbits(20 * 8).to_bytes(20, byteorder='big')