From 3f35bc029836851479796c0ecb0483b69690f0c2 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sat, 18 Feb 2017 13:05:26 +0900 Subject: [PATCH] More PEP8 stuff --- lib/coins.py | 4 ++-- lib/peer.py | 2 +- lib/tx.py | 4 ++-- lib/util.py | 6 ++++-- server/block_processor.py | 2 +- server/controller.py | 2 +- server/irc.py | 2 +- server/mempool.py | 8 ++++---- server/peers.py | 14 +++++++------- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/coins.py b/lib/coins.py index fb5391d..c9ad2ea 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -71,8 +71,8 @@ class Coin(object): req_attrs = ('TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK', 'IRC_CHANNEL') for coin in util.subclasses(Coin): - if (coin.NAME.lower() == name.lower() - and coin.NET.lower() == net.lower()): + if (coin.NAME.lower() == name.lower() and + coin.NET.lower() == net.lower()): missing = [attr for attr in req_attrs if not hasattr(coin, attr)] if missing: diff --git a/lib/peer.py b/lib/peer.py index a5ff3df..52ad340 100644 --- a/lib/peer.py +++ b/lib/peer.py @@ -88,7 +88,7 @@ class Peer(object): minor_version) pair. ''' if isinstance(vstr, str) and VERSION_REGEX.match(vstr): - if not '.' in vstr: + if '.' not in vstr: vstr += '.0' else: vstr = '1.0' diff --git a/lib/tx.py b/lib/tx.py index 6fa24ad..ceed127 100644 --- a/lib/tx.py +++ b/lib/tx.py @@ -52,8 +52,8 @@ class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")): @cachedproperty def is_coinbase(self): - return (self.prev_hash == TxInput.ZERO - and self.prev_idx == TxInput.MINUS_1) + return (self.prev_hash == TxInput.ZERO and + self.prev_idx == TxInput.MINUS_1) @cachedproperty def script_sig_info(self): diff --git a/lib/util.py b/lib/util.py index 991c68c..e35d3b8 100644 --- a/lib/util.py +++ b/lib/util.py @@ -34,6 +34,7 @@ import logging import sys from collections import Container, Mapping + class LoggedClass(object): def __init__(self): @@ -131,8 +132,8 @@ def deep_getsizeof(obj): def subclasses(base_class, strict=True): '''Return a list of subclasses of base_class in its module.''' def select(obj): - return (inspect.isclass(obj) and issubclass(obj, base_class) - and (not strict or obj != base_class)) + return (inspect.isclass(obj) and issubclass(obj, base_class) and + (not strict or obj != base_class)) pairs = inspect.getmembers(sys.modules[base_class.__module__], select) return [pair[1] for pair in pairs] @@ -222,6 +223,7 @@ def open_file(filename, create=False): return open(filename, 'wb+') raise + def open_truncate(filename): '''Open the file name. Return its handle.''' return open(filename, 'wb+') diff --git a/server/block_processor.py b/server/block_processor.py index e449c37..3d6297e 100644 --- a/server/block_processor.py +++ b/server/block_processor.py @@ -568,7 +568,7 @@ class BlockProcessor(server.db.DB): header = coin.block_header(block, self.height) header_hash = coin.header_hash(header) if header_hash != self.tip: - raise ChainError('backup block {} is not tip {} at height {:,d}' + raise ChainError('backup block {} not tip {} at height {:,d}' .format(hash_to_str(header_hash), hash_to_str(self.tip), self.height)) self.tip = coin.header_prevhash(header) diff --git a/server/controller.py b/server/controller.py index 07b21ac..e5b2898 100644 --- a/server/controller.py +++ b/server/controller.py @@ -394,7 +394,7 @@ class Controller(util.LoggedClass): .format(session.kind, session.peername(), len(self.sessions))) if (len(self.sessions) >= self.max_sessions - and self.state == self.LISTENING): + and self.state == self.LISTENING): self.state = self.PAUSED session.log_info('maximum sessions {:,d} reached, stopping new ' 'connections until count drops to {:,d}' diff --git a/server/irc.py b/server/irc.py index 0457a3d..ace4d04 100644 --- a/server/irc.py +++ b/server/irc.py @@ -105,7 +105,7 @@ class IRC(LoggedClass): nick = event.arguments[4] if nick.startswith(self.prefix): line = event.arguments[6].split() - hp_string = ' '.join(line[1:]) # hostname, ports, version etc. + hp_string = ' '.join(line[1:]) # hostname, ports, version etc. self.peer_mgr.add_irc_peer(nick, hp_string) diff --git a/server/mempool.py b/server/mempool.py index d957905..35d177f 100644 --- a/server/mempool.py +++ b/server/mempool.py @@ -162,8 +162,8 @@ class MemPool(util.LoggedClass): deferred = pending pending = [] - result, deferred = await self.controller.run_in_executor \ - (self.process_raw_txs, raw_txs, deferred) + result, deferred = await self.controller.run_in_executor( + self.process_raw_txs, raw_txs, deferred) pending.extend(deferred) hashXs = self.hashXs @@ -279,8 +279,8 @@ class MemPool(util.LoggedClass): if not item or not raw_tx: continue txin_pairs, txout_pairs = item - tx_fee = (sum(v for hashX, v in txin_pairs) - - sum(v for hashX, v in txout_pairs)) + tx_fee = (sum(v for hashX, v in txin_pairs) - + sum(v for hashX, v in txout_pairs)) tx, tx_hash = deserializer(raw_tx).read_tx() unconfirmed = any(txin.prev_hash in self.txs for txin in tx.inputs) result.append((hex_hash, tx_fee, unconfirmed)) diff --git a/server/peers.py b/server/peers.py index 6ddf77b..c5bb5c3 100644 --- a/server/peers.py +++ b/server/peers.py @@ -32,8 +32,8 @@ WAKEUP_SECS = 300 def peer_from_env(env): '''Return ourself as a peer from the environment settings.''' main_identity = env.identities[0] - hosts = {identity.host : {'tcp_port': identity.tcp_port, - 'ssl_port': identity.ssl_port} + hosts = {identity.host: {'tcp_port': identity.tcp_port, + 'ssl_port': identity.ssl_port} for identity in env.identities} features = { 'hosts': hosts, @@ -156,7 +156,7 @@ class PeerSession(JSONSession): our_height = self.peer_mgr.controller.bp.db_height their_height = result.get('block_height') if (not isinstance(their_height, int) or - abs(our_height - their_height) > 5): + abs(our_height - their_height) > 5): self.failed = True self.peer.mark_bad() self.log_warning('bad height {}'.format(their_height)) @@ -244,9 +244,9 @@ class PeerManager(util.LoggedClass): def rpc_data(self): '''Peer data for the peers RPC method.''' self.set_peer_statuses() - descs = ['good', 'stale', 'never', 'bad'] - def peer_data( peer): + + def peer_data(peer): data = peer.serialize() data['status'] = descs[peer.status] return data @@ -304,8 +304,8 @@ class PeerManager(util.LoggedClass): ''' cutoff = time.time() - STALE_SECS recent = [peer for peer in self.peers - if peer.last_connect > cutoff - and not peer.bad and peer.is_public] + if peer.last_connect > cutoff and + not peer.bad and peer.is_public] onion_peers = [] # Always report ourselves if valid (even if not public)