Browse Source

More PEP8 stuff

master
Neil Booth 8 years ago
parent
commit
3f35bc0298
  1. 4
      lib/coins.py
  2. 2
      lib/peer.py
  3. 4
      lib/tx.py
  4. 6
      lib/util.py
  5. 2
      server/block_processor.py
  6. 8
      server/mempool.py
  7. 6
      server/peers.py

4
lib/coins.py

@ -71,8 +71,8 @@ class Coin(object):
req_attrs = ('TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK', req_attrs = ('TX_COUNT', 'TX_COUNT_HEIGHT', 'TX_PER_BLOCK',
'IRC_CHANNEL') 'IRC_CHANNEL')
for coin in util.subclasses(Coin): for coin in util.subclasses(Coin):
if (coin.NAME.lower() == name.lower() if (coin.NAME.lower() == name.lower() and
and coin.NET.lower() == net.lower()): coin.NET.lower() == net.lower()):
missing = [attr for attr in req_attrs missing = [attr for attr in req_attrs
if not hasattr(coin, attr)] if not hasattr(coin, attr)]
if missing: if missing:

2
lib/peer.py

@ -88,7 +88,7 @@ class Peer(object):
minor_version) pair. minor_version) pair.
''' '''
if isinstance(vstr, str) and VERSION_REGEX.match(vstr): if isinstance(vstr, str) and VERSION_REGEX.match(vstr):
if not '.' in vstr: if '.' not in vstr:
vstr += '.0' vstr += '.0'
else: else:
vstr = '1.0' vstr = '1.0'

4
lib/tx.py

@ -52,8 +52,8 @@ class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")):
@cachedproperty @cachedproperty
def is_coinbase(self): def is_coinbase(self):
return (self.prev_hash == TxInput.ZERO return (self.prev_hash == TxInput.ZERO and
and self.prev_idx == TxInput.MINUS_1) self.prev_idx == TxInput.MINUS_1)
@cachedproperty @cachedproperty
def script_sig_info(self): def script_sig_info(self):

6
lib/util.py

@ -34,6 +34,7 @@ import logging
import sys import sys
from collections import Container, Mapping from collections import Container, Mapping
class LoggedClass(object): class LoggedClass(object):
def __init__(self): def __init__(self):
@ -131,8 +132,8 @@ def deep_getsizeof(obj):
def subclasses(base_class, strict=True): def subclasses(base_class, strict=True):
'''Return a list of subclasses of base_class in its module.''' '''Return a list of subclasses of base_class in its module.'''
def select(obj): def select(obj):
return (inspect.isclass(obj) and issubclass(obj, base_class) return (inspect.isclass(obj) and issubclass(obj, base_class) and
and (not strict or obj != base_class)) (not strict or obj != base_class))
pairs = inspect.getmembers(sys.modules[base_class.__module__], select) pairs = inspect.getmembers(sys.modules[base_class.__module__], select)
return [pair[1] for pair in pairs] return [pair[1] for pair in pairs]
@ -222,6 +223,7 @@ def open_file(filename, create=False):
return open(filename, 'wb+') return open(filename, 'wb+')
raise raise
def open_truncate(filename): def open_truncate(filename):
'''Open the file name. Return its handle.''' '''Open the file name. Return its handle.'''
return open(filename, 'wb+') return open(filename, 'wb+')

2
server/block_processor.py

@ -568,7 +568,7 @@ class BlockProcessor(server.db.DB):
header = coin.block_header(block, self.height) header = coin.block_header(block, self.height)
header_hash = coin.header_hash(header) header_hash = coin.header_hash(header)
if header_hash != self.tip: 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), .format(hash_to_str(header_hash),
hash_to_str(self.tip), self.height)) hash_to_str(self.tip), self.height))
self.tip = coin.header_prevhash(header) self.tip = coin.header_prevhash(header)

8
server/mempool.py

@ -162,8 +162,8 @@ class MemPool(util.LoggedClass):
deferred = pending deferred = pending
pending = [] pending = []
result, deferred = await self.controller.run_in_executor \ result, deferred = await self.controller.run_in_executor(
(self.process_raw_txs, raw_txs, deferred) self.process_raw_txs, raw_txs, deferred)
pending.extend(deferred) pending.extend(deferred)
hashXs = self.hashXs hashXs = self.hashXs
@ -279,8 +279,8 @@ class MemPool(util.LoggedClass):
if not item or not raw_tx: if not item or not raw_tx:
continue continue
txin_pairs, txout_pairs = item txin_pairs, txout_pairs = item
tx_fee = (sum(v for hashX, v in txin_pairs) tx_fee = (sum(v for hashX, v in txin_pairs) -
- sum(v for hashX, v in txout_pairs)) sum(v for hashX, v in txout_pairs))
tx, tx_hash = deserializer(raw_tx).read_tx() tx, tx_hash = deserializer(raw_tx).read_tx()
unconfirmed = any(txin.prev_hash in self.txs for txin in tx.inputs) unconfirmed = any(txin.prev_hash in self.txs for txin in tx.inputs)
result.append((hex_hash, tx_fee, unconfirmed)) result.append((hex_hash, tx_fee, unconfirmed))

6
server/peers.py

@ -244,8 +244,8 @@ class PeerManager(util.LoggedClass):
def rpc_data(self): def rpc_data(self):
'''Peer data for the peers RPC method.''' '''Peer data for the peers RPC method.'''
self.set_peer_statuses() self.set_peer_statuses()
descs = ['good', 'stale', 'never', 'bad'] descs = ['good', 'stale', 'never', 'bad']
def peer_data(peer): def peer_data(peer):
data = peer.serialize() data = peer.serialize()
data['status'] = descs[peer.status] data['status'] = descs[peer.status]
@ -304,8 +304,8 @@ class PeerManager(util.LoggedClass):
''' '''
cutoff = time.time() - STALE_SECS cutoff = time.time() - STALE_SECS
recent = [peer for peer in self.peers recent = [peer for peer in self.peers
if peer.last_connect > cutoff if peer.last_connect > cutoff and
and not peer.bad and peer.is_public] not peer.bad and peer.is_public]
onion_peers = [] onion_peers = []
# Always report ourselves if valid (even if not public) # Always report ourselves if valid (even if not public)

Loading…
Cancel
Save