Skip to content

Commit

Permalink
Flake&Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Dec 3, 2021
1 parent f8875eb commit 7e19225
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from datetime import datetime
from time import time

import pytest
from ipv8.keyvault.crypto import default_eccrypto

from pony import orm
from pony.orm import db_session

from ipv8.keyvault.crypto import default_eccrypto
import pytest

from tribler_core.components.libtorrent.torrentdef import TorrentDef
from tribler_core.components.metadata_store.db.orm_bindings.channel_node import TODELETE
from tribler_core.components.metadata_store.db.orm_bindings.discrete_clock import clock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from typing import Type

from ipv8.REST.root_endpoint import RootEndpoint as IPV8RootEndpoint

from tribler_common.reported_error import ReportedError

from tribler_core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler_core.components.bandwidth_accounting.restapi.bandwidth_endpoint import BandwidthEndpoint
from tribler_core.components.base import Component, NoneComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import random

from binascii import unhexlify

from cryptography.exceptions import InvalidSignature
from pony.orm import db_session

from ipv8.keyvault.private.libnaclkey import LibNaCLSK
from ipv8.lazy_community import lazy_wrapper
from ipv8.types import Key

from pony.orm import db_session

from tribler_core.components.ipv8.tribler_community import TriblerCommunity
from tribler_core.components.tag.community.tag_payload import (
RawTagOperationMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from dataclasses import dataclass
from itertools import count

from ipv8.test.base import TestBase

from pony.orm import commit, db_session

from ipv8.test.base import TestBase
from tribler_core.components.tag.community.tag_payload import TagOperation, TagOperationEnum
from tribler_core.components.tag.db.tag_db import TagDatabase


# pylint: disable=protected-access

@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import binascii
from binascii import unhexlify
from itertools import chain
from typing import Optional, Sequence, Set

import binascii
from aiohttp import web

from aiohttp_apispec import docs
from binascii import unhexlify

from ipv8.REST.schema import schema

from marshmallow.fields import Boolean, List, String

from pony.orm import db_session

from ipv8.REST.schema import schema
from tribler_core.components.metadata_store.db.store import MetadataStore
from tribler_core.components.restapi.rest.rest_endpoint import HTTP_BAD_REQUEST, RESTEndpoint, RESTResponse
from tribler_core.components.restapi.rest.schema import HandledErrorSchema
Expand Down Expand Up @@ -38,13 +42,15 @@ def validate_infohash(infohash: str) -> Optional[RESTResponse]:
return RESTResponse({"error": "Invalid infohash"}, status=HTTP_BAD_REQUEST)
except binascii.Error:
return RESTResponse({"error": "Invalid infohash"}, status=HTTP_BAD_REQUEST)
return None

@staticmethod
def validate_tag(tag: str) -> Optional[RESTResponse]:
try:
validate_tag(tag)
except AssertionError as e:
return RESTResponse({"error": f'{e}'}, status=HTTP_BAD_REQUEST)
return None

def setup_routes(self):
self.app.add_routes(
Expand Down Expand Up @@ -181,8 +187,8 @@ def search_by_tags(self, tags: Optional[Set[str]]) -> Sequence[Set[str]]:

return intersection, symmetric_difference

def replace_infohash_list_by_metadata_gen(self, infohash_list: Sequence[str]):
for infohash_list in infohash_list:
def replace_infohash_list_by_metadata_gen(self, list_of_infohash_list: Sequence[str]):
for infohash_list in list_of_infohash_list:
raw_metadata = self.mds.get_entries_query(infohash=infohash_list)
metadata_without_tags = ((entry.to_simple_dict(), entry.infohash) for entry in raw_metadata)
for entry, infohash in metadata_without_tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
from unittest.mock import Mock, patch

import pytest
from aiohttp.web_app import Application

from freezegun import freeze_time
from pony.orm import db_session

from ipv8.keyvault.crypto import default_eccrypto

from pony.orm import db_session

import pytest

from tribler_core.components.restapi.rest.base_api_test import do_request
from tribler_core.components.tag.community.tag_payload import TagOperation, TagOperationEnum
from tribler_core.components.tag.restapi.tags_endpoint import TagsEndpoint
from tribler_core.conftest import TEST_PERSONAL_KEY
from tribler_core.utilities.unicode import hexlify


# pylint: disable=redefined-outer-name

@pytest.fixture
Expand Down Expand Up @@ -137,6 +140,7 @@ def get_infohashes(self, tag):
return [b'3']
if tag == 'tag3':
return [b'3', b'4']
return []

endpoint = TagsEndpoint(db=TagDb(), community=Mock(), mds=Mock())

Expand Down
45 changes: 24 additions & 21 deletions src/tribler-gui/tribler_gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@
QSystemTrayIcon,
QTreeWidget,
)

from psutil import LINUX

from tribler_common.network_utils import NetworkUtils
from tribler_common.process_checker import ProcessChecker
from tribler_common.utilities import extract_plain_fts_query_text, extract_tags, parse_query, uri_to_path
from tribler_common.utilities import parse_query, uri_to_path
from tribler_common.version_manager import VersionHistory

from tribler_core.utilities.unicode import hexlify
from tribler_core.version import version_id

from tribler_gui.core_manager import CoreManager
from tribler_gui.debug_window import DebugWindow
from tribler_gui.defs import (
Expand Down Expand Up @@ -122,14 +125,14 @@ class TriblerWindow(QMainWindow):
received_search_completions = pyqtSignal(object)

def __init__(
self,
settings,
root_state_dir,
core_args=None,
core_env=None,
api_port=None,
api_key=None,
run_core=True,
self,
settings,
root_state_dir,
core_args=None,
core_env=None,
api_port=None,
api_key=None,
run_core=True,
):
QMainWindow.__init__(self)
self._logger = logging.getLogger(self.__class__.__name__)
Expand Down Expand Up @@ -574,14 +577,14 @@ def update_recent_download_locations(self, destination):
self.gui_settings.setValue("recent_download_locations", ','.join(recent_locations))

def perform_start_download_request(
self,
uri,
anon_download,
safe_seeding,
destination,
selected_files,
add_to_channel=False,
callback=None,
self,
uri,
anon_download,
safe_seeding,
destination,
selected_files,
add_to_channel=False,
callback=None,
):
# Check if destination directory is writable
is_writable, error = is_dir_writable(destination)
Expand Down Expand Up @@ -1130,10 +1133,10 @@ def closeEvent(self, close_event):
def event(self, event):
# Minimize to tray
if (
not DARWIN
and event.type() == QtCore.QEvent.WindowStateChange
and self.window().isMinimized()
and get_gui_setting(self.gui_settings, "minimize_to_tray", False, is_bool=True)
not DARWIN
and event.type() == QtCore.QEvent.WindowStateChange
and self.window().isMinimized()
and get_gui_setting(self.gui_settings, "minimize_to_tray", False, is_bool=True)
):
self.window().hide()
return True
Expand Down
21 changes: 11 additions & 10 deletions src/tribler-gui/tribler_gui/widgets/searchresultswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from tribler_common.sentry_reporter.sentry_mixin import AddBreadcrumbOnShowMixin
from tribler_common.utilities import to_fts_query

from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT

from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import connect, get_ui_file_path, tr
from tribler_gui.widgets.tablecontentmodel import SearchResultsModel, TagsSearchResultsModel
Expand All @@ -24,11 +26,11 @@ def format_search_loading_label(search_request):
}

return (
tr(
"Remote responses: %(num_complete_peers)i / %(total_peers)i"
"\nNew remote results received: %(num_remote_results)i"
)
% data
tr(
"Remote responses: %(num_complete_peers)i / %(total_peers)i"
"\nNew remote results received: %(num_remote_results)i"
)
% data
)


Expand Down Expand Up @@ -93,9 +95,9 @@ def show_results(self, *_):

def check_can_show(self, query):
if (
self.last_search_query == query
and self.last_search_time is not None
and time.time() - self.last_search_time < 1
self.last_search_query == query
and self.last_search_time is not None
and time.time() - self.last_search_time < 1
):
logging.info("Same search query already sent within 500ms so dropping this one")
return False
Expand All @@ -111,8 +113,7 @@ def response(r):
model.update()

logging.info(f'Request to "tags/search": {tags}')
TriblerNetworkRequest('tags/search', response, data={'tags': list(tags),
'limit': 50})
TriblerNetworkRequest('tags/search', response, data={'tags': list(tags), 'limit': 50})

def search(self, query):
if not self.check_can_show(query):
Expand Down
46 changes: 20 additions & 26 deletions src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@

from tribler_common.simpledefs import CHANNELS_VIEW_UUID, CHANNEL_STATE
from tribler_common.utilities import to_fts_query

from tribler_core.components.metadata_store.db.orm_bindings.channel_node import NEW
from tribler_core.components.metadata_store.db.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT

from tribler_gui.defs import BITTORRENT_BIRTHDAY, COMMIT_STATUS_TODELETE, HEALTH_CHECKING
from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import (
connect,
format_size,
format_votes,
get_votes_rating_description,
pretty_date,
tr,
)
from tribler_gui.utilities import connect, format_size, format_votes, get_votes_rating_description, pretty_date, tr

EXPANDING = 0

Expand Down Expand Up @@ -328,15 +323,15 @@ class ChannelContentModel(RemoteTableModel):
columns_shown = (Column.ACTIONS, Column.CATEGORY, Column.NAME, Column.SIZE, Column.HEALTH, Column.UPDATED)

def __init__(
self,
channel_info=None,
hide_xxx=None,
exclude_deleted=None,
subscribed_only=None,
endpoint_url=None,
text_filter='',
type_filter=None,
do_perform_query=True
self,
channel_info=None,
hide_xxx=None,
exclude_deleted=None,
subscribed_only=None,
endpoint_url=None,
text_filter='',
type_filter=None,
do_perform_query=True,
):
RemoteTableModel.__init__(self, parent=None)

Expand Down Expand Up @@ -415,10 +410,10 @@ def item_txt(self, index, role):

# Print number of torrents in the channel for channel rows in the "size" column
if (
column_type == Column.SIZE
and "torrents" not in self.columns
and "torrents" in item
and item["type"] in (CHANNEL_TORRENT, COLLECTION_NODE)
column_type == Column.SIZE
and "torrents" not in self.columns
and "torrents" in item
and item["type"] in (CHANNEL_TORRENT, COLLECTION_NODE)
):
return item["torrents"]

Expand Down Expand Up @@ -459,8 +454,8 @@ def update_node_info(self, update_dict):
"""

if (
self.channel_info.get("public_key") == update_dict.get("public_key") is not None
and self.channel_info.get("id") == update_dict.get("id") is not None
self.channel_info.get("public_key") == update_dict.get("public_key") is not None
and self.channel_info.get("id") == update_dict.get("id") is not None
):
self.channel_info.update(**update_dict)
self.info_changed.emit([])
Expand Down Expand Up @@ -618,9 +613,8 @@ def delete_rows(self, rows):

def create_new_channel(self, channel_name=None):
url = (
self.endpoint_url_override or "channels/%s/%i" % (
self.channel_info["public_key"], self.channel_info["id"])
) + ("/channels" if self.channel_info.get("id", 0) == 0 else "/collections")
self.endpoint_url_override or "channels/%s/%i" % (self.channel_info["public_key"], self.channel_info["id"])
) + ("/channels" if self.channel_info.get("id", 0) == 0 else "/collections")
TriblerNetworkRequest(
url,
self.on_create_query_results,
Expand Down

0 comments on commit 7e19225

Please sign in to comment.