commit 5e4a4ae16bdd9e9c7a7ce056a352531a8870b74b
parent 32d53052956bbbc60683cec0308afe127eed304e
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 28 Sep 2018 17:58:46 +0200
minor clean-up (prints/types/imports)
Diffstat:
4 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/electrum/daemon.py b/electrum/daemon.py
@@ -29,6 +29,7 @@ import time
import traceback
import sys
import threading
+from typing import Dict
import jsonrpclib
@@ -37,7 +38,7 @@ from .version import ELECTRUM_VERSION
from .network import Network
from .util import json_decode, DaemonThread
from .util import print_error, to_string
-from .wallet import Wallet
+from .wallet import Wallet, Abstract_Wallet
from .storage import WalletStorage
from .commands import known_commands, Commands
from .simple_config import SimpleConfig
@@ -131,7 +132,7 @@ class Daemon(DaemonThread):
if self.network:
self.network.start([self.fx.run])
self.gui = None
- self.wallets = {}
+ self.wallets = {} # type: Dict[str, Abstract_Wallet]
# Setup JSONRPC server
self.init_server(config, fd)
diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py
@@ -1,6 +1,4 @@
import asyncio
-import aiohttp
-from aiohttp_socks import SocksConnector, SocksVer
from datetime import datetime
import inspect
import sys
@@ -12,6 +10,7 @@ import decimal
from decimal import Decimal
import concurrent.futures
import traceback
+from typing import Sequence
from .bitcoin import COIN
from .i18n import _
@@ -27,6 +26,7 @@ CCY_PRECISIONS = {'BHD': 3, 'BIF': 0, 'BYR': 0, 'CLF': 4, 'CLP': 0,
'RWF': 0, 'TND': 3, 'UGX': 0, 'UYI': 0, 'VND': 0,
'VUV': 0, 'XAF': 0, 'XAU': 4, 'XOF': 0, 'XPF': 0}
+
class ExchangeBase(PrintError):
def __init__(self, on_quotes, on_history):
@@ -65,7 +65,7 @@ class ExchangeBase(PrintError):
self.quotes = await self.get_rates(ccy)
self.print_error("received fx quotes")
except BaseException as e:
- self.print_error("failed fx quotes:", e)
+ self.print_error("failed fx quotes:", repr(e))
self.quotes = {}
self.on_quotes()
@@ -452,12 +452,14 @@ class FxThread(ThreadJob):
def set_proxy(self, trigger_name, *args):
self._trigger.set()
- def get_currencies(self, h):
- d = get_exchanges_by_ccy(h)
+ @staticmethod
+ def get_currencies(history: bool) -> Sequence[str]:
+ d = get_exchanges_by_ccy(history)
return sorted(d.keys())
- def get_exchanges_by_ccy(self, ccy, h):
- d = get_exchanges_by_ccy(h)
+ @staticmethod
+ def get_exchanges_by_ccy(ccy: str, history: bool) -> Sequence[str]:
+ d = get_exchanges_by_ccy(history)
return d.get(ccy, [])
def ccy_amount_str(self, amount, commas):
diff --git a/electrum/interface.py b/electrum/interface.py
@@ -63,7 +63,7 @@ class NotificationSession(ClientSession):
for queue in self.subscriptions[key]:
await queue.put(request.args)
else:
- assert False, request.method
+ raise Exception('unexpected request: {}'.format(repr(request)))
async def send_request(self, *args, timeout=-1, **kwargs):
# note: the timeout starts after the request touches the wire!
@@ -255,12 +255,12 @@ class Interface(PrintError):
try:
ssl_context = await self._get_ssl_context()
except (ErrorParsingSSLCert, ErrorGettingSSLCertFromServer) as e:
- self.print_error('disconnecting due to: {} {}'.format(e, type(e)))
+ self.print_error('disconnecting due to: {}'.format(repr(e)))
return
try:
- await self.open_session(ssl_context, exit_early=False)
+ await self.open_session(ssl_context)
except (asyncio.CancelledError, OSError, aiorpcx.socks.SOCKSFailure) as e:
- self.print_error('disconnecting due to: {} {}'.format(e, type(e)))
+ self.print_error('disconnecting due to: {}'.format(repr(e)))
return
def mark_ready(self):
@@ -338,7 +338,7 @@ class Interface(PrintError):
return conn, 0
return conn, res['count']
- async def open_session(self, sslc, exit_early):
+ async def open_session(self, sslc, exit_early=False):
self.session = NotificationSession(self.host, self.port, ssl=sslc, proxy=self.proxy)
async with self.session as session:
try:
diff --git a/electrum/plugin.py b/electrum/plugin.py
@@ -134,7 +134,7 @@ class Plugins(DaemonThread):
try:
__import__(dep)
except ImportError as e:
- self.print_error('Plugin', name, 'unavailable:', type(e).__name__, ':', str(e))
+ self.print_error('Plugin', name, 'unavailable:', repr(e))
return False
requires = d.get('requires_wallet_type', [])
return not requires or w.wallet_type in requires