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. 2
      server/controller.py
  7. 2
      server/irc.py
  8. 8
      server/mempool.py
  9. 14
      server/peers.py

4
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:

2
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'

4
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):

6
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+')

2
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)

2
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}'

2
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)

8
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))

14
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)

Loading…
Cancel
Save