Browse Source

minor clean-up (prints/types/imports)

3.3.3.1
SomberNight 6 years ago
parent
commit
5e4a4ae16b
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/daemon.py
  2. 16
      electrum/exchange_rate.py
  3. 10
      electrum/interface.py
  4. 2
      electrum/plugin.py

5
electrum/daemon.py

@ -29,6 +29,7 @@ import time
import traceback import traceback
import sys import sys
import threading import threading
from typing import Dict
import jsonrpclib import jsonrpclib
@ -37,7 +38,7 @@ from .version import ELECTRUM_VERSION
from .network import Network from .network import Network
from .util import json_decode, DaemonThread from .util import json_decode, DaemonThread
from .util import print_error, to_string from .util import print_error, to_string
from .wallet import Wallet from .wallet import Wallet, Abstract_Wallet
from .storage import WalletStorage from .storage import WalletStorage
from .commands import known_commands, Commands from .commands import known_commands, Commands
from .simple_config import SimpleConfig from .simple_config import SimpleConfig
@ -131,7 +132,7 @@ class Daemon(DaemonThread):
if self.network: if self.network:
self.network.start([self.fx.run]) self.network.start([self.fx.run])
self.gui = None self.gui = None
self.wallets = {} self.wallets = {} # type: Dict[str, Abstract_Wallet]
# Setup JSONRPC server # Setup JSONRPC server
self.init_server(config, fd) self.init_server(config, fd)

16
electrum/exchange_rate.py

@ -1,6 +1,4 @@
import asyncio import asyncio
import aiohttp
from aiohttp_socks import SocksConnector, SocksVer
from datetime import datetime from datetime import datetime
import inspect import inspect
import sys import sys
@ -12,6 +10,7 @@ import decimal
from decimal import Decimal from decimal import Decimal
import concurrent.futures import concurrent.futures
import traceback import traceback
from typing import Sequence
from .bitcoin import COIN from .bitcoin import COIN
from .i18n import _ 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, 'RWF': 0, 'TND': 3, 'UGX': 0, 'UYI': 0, 'VND': 0,
'VUV': 0, 'XAF': 0, 'XAU': 4, 'XOF': 0, 'XPF': 0} 'VUV': 0, 'XAF': 0, 'XAU': 4, 'XOF': 0, 'XPF': 0}
class ExchangeBase(PrintError): class ExchangeBase(PrintError):
def __init__(self, on_quotes, on_history): def __init__(self, on_quotes, on_history):
@ -65,7 +65,7 @@ class ExchangeBase(PrintError):
self.quotes = await self.get_rates(ccy) self.quotes = await self.get_rates(ccy)
self.print_error("received fx quotes") self.print_error("received fx quotes")
except BaseException as e: except BaseException as e:
self.print_error("failed fx quotes:", e) self.print_error("failed fx quotes:", repr(e))
self.quotes = {} self.quotes = {}
self.on_quotes() self.on_quotes()
@ -452,12 +452,14 @@ class FxThread(ThreadJob):
def set_proxy(self, trigger_name, *args): def set_proxy(self, trigger_name, *args):
self._trigger.set() self._trigger.set()
def get_currencies(self, h): @staticmethod
d = get_exchanges_by_ccy(h) def get_currencies(history: bool) -> Sequence[str]:
d = get_exchanges_by_ccy(history)
return sorted(d.keys()) return sorted(d.keys())
def get_exchanges_by_ccy(self, ccy, h): @staticmethod
d = get_exchanges_by_ccy(h) def get_exchanges_by_ccy(ccy: str, history: bool) -> Sequence[str]:
d = get_exchanges_by_ccy(history)
return d.get(ccy, []) return d.get(ccy, [])
def ccy_amount_str(self, amount, commas): def ccy_amount_str(self, amount, commas):

10
electrum/interface.py

@ -63,7 +63,7 @@ class NotificationSession(ClientSession):
for queue in self.subscriptions[key]: for queue in self.subscriptions[key]:
await queue.put(request.args) await queue.put(request.args)
else: else:
assert False, request.method raise Exception('unexpected request: {}'.format(repr(request)))
async def send_request(self, *args, timeout=-1, **kwargs): async def send_request(self, *args, timeout=-1, **kwargs):
# note: the timeout starts after the request touches the wire! # note: the timeout starts after the request touches the wire!
@ -255,12 +255,12 @@ class Interface(PrintError):
try: try:
ssl_context = await self._get_ssl_context() ssl_context = await self._get_ssl_context()
except (ErrorParsingSSLCert, ErrorGettingSSLCertFromServer) as e: 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 return
try: 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: 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 return
def mark_ready(self): def mark_ready(self):
@ -338,7 +338,7 @@ class Interface(PrintError):
return conn, 0 return conn, 0
return conn, res['count'] 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) self.session = NotificationSession(self.host, self.port, ssl=sslc, proxy=self.proxy)
async with self.session as session: async with self.session as session:
try: try:

2
electrum/plugin.py

@ -134,7 +134,7 @@ class Plugins(DaemonThread):
try: try:
__import__(dep) __import__(dep)
except ImportError as e: 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 return False
requires = d.get('requires_wallet_type', []) requires = d.get('requires_wallet_type', [])
return not requires or w.wallet_type in requires return not requires or w.wallet_type in requires

Loading…
Cancel
Save