Browse Source

Merge branch 'nmarley-pep8' into develop

master
Neil Booth 8 years ago
parent
commit
33cdfa4fc8
  1. 3
      electrumx_server.py
  2. 1
      lib/tx.py
  3. 1
      lib/util.py
  4. 1
      query.py
  5. 2
      server/controller.py
  6. 4
      server/mempool.py
  7. 1
      server/storage.py
  8. 4
      tests/test_storage.py
  9. 3
      tests/test_util.py

3
electrumx_server.py

@ -25,6 +25,7 @@ SUPPRESS_MESSAGES = [
'Fatal write error on socket transport', 'Fatal write error on socket transport',
] ]
def main_loop(): def main_loop():
'''Start the server.''' '''Start the server.'''
if os.geteuid() == 0: if os.geteuid() == 0:
@ -43,7 +44,7 @@ def main_loop():
def on_exception(loop, context): def on_exception(loop, context):
'''Suppress spurious messages it appears we cannot control.''' '''Suppress spurious messages it appears we cannot control.'''
message = context.get('message') message = context.get('message')
if not message in SUPPRESS_MESSAGES: if message not in SUPPRESS_MESSAGES:
if not ('task' in context and if not ('task' in context and
'accept_connection2()' in repr(context.get('task'))): 'accept_connection2()' in repr(context.get('task'))):
loop.default_exception_handler(context) loop.default_exception_handler(context)

1
lib/tx.py

@ -43,6 +43,7 @@ class Tx(namedtuple("Tx", "version inputs outputs locktime")):
# FIXME: add hash as a cached property? # FIXME: add hash as a cached property?
class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")): class TxInput(namedtuple("TxInput", "prev_hash prev_idx script sequence")):
'''Class representing a transaction input.''' '''Class representing a transaction input.'''

1
lib/util.py

@ -127,6 +127,7 @@ def deep_getsizeof(obj):
return size(obj) return size(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):

1
query.py

@ -71,5 +71,6 @@ def main():
print('Balance: {} {}'.format(coin.decimal_value(balance), print('Balance: {} {}'.format(coin.decimal_value(balance),
coin.SHORTNAME)) coin.SHORTNAME))
if __name__ == '__main__': if __name__ == '__main__':
main() main()

2
server/controller.py

@ -167,7 +167,7 @@ class Controller(util.LoggedClass):
def enqueue_session(self, session): def enqueue_session(self, session):
# Might have disconnected whilst waiting # Might have disconnected whilst waiting
if not session in self.sessions: if session not in self.sessions:
return return
priority = self.session_priority(session) priority = self.session_priority(session)
item = (priority, self.next_queue_id, session) item = (priority, self.next_queue_id, session)

4
server/mempool.py

@ -204,7 +204,7 @@ class MemPool(util.LoggedClass):
# Deserialize each tx and put it in our priority queue # Deserialize each tx and put it in our priority queue
for tx_hash, raw_tx in raw_tx_map.items(): for tx_hash, raw_tx in raw_tx_map.items():
if not tx_hash in txs: if tx_hash not in txs:
continue continue
tx, _tx_hash = deserializer(raw_tx).read_tx() tx, _tx_hash = deserializer(raw_tx).read_tx()
@ -267,7 +267,7 @@ class MemPool(util.LoggedClass):
unconfirmed is True if any txin is unconfirmed. unconfirmed is True if any txin is unconfirmed.
''' '''
# hashXs is a defaultdict # hashXs is a defaultdict
if not hashX in self.hashXs: if hashX not in self.hashXs:
return [] return []
deserializer = self.coin.deserializer() deserializer = self.coin.deserializer()

1
server/storage.py

@ -12,6 +12,7 @@ from functools import partial
import lib.util as util import lib.util as util
def db_class(name): def db_class(name):
'''Returns a DB engine class.''' '''Returns a DB engine class.'''
for db_class in util.subclasses(Storage): for db_class in util.subclasses(Storage):

4
tests/test_storage.py

@ -44,8 +44,8 @@ def test_batch(db):
def test_iterator(db): def test_iterator(db):
""" """
The iterator should contain all key/value pairs starting with prefix ordered The iterator should contain all key/value pairs starting with prefix
by key. ordered by key.
""" """
for i in range(5): for i in range(5):
db.put(b"abc" + str.encode(str(i)), str.encode(str(i))) db.put(b"abc" + str.encode(str(i)), str.encode(str(i)))

3
tests/test_util.py

@ -19,7 +19,6 @@ def test_cachedproperty():
cls.CALL_COUNT += 1 cls.CALL_COUNT += 1
return cls.CALL_COUNT return cls.CALL_COUNT
t = Target() t = Target()
assert t.prop == t.prop == 1 assert t.prop == t.prop == 1
assert Target.cls_prop == Target.cls_prop == 1 assert Target.cls_prop == Target.cls_prop == 1
@ -56,4 +55,4 @@ def test_chunks():
def test_increment_byte_string(): def test_increment_byte_string():
assert util.increment_byte_string(b'1') == b'2' assert util.increment_byte_string(b'1') == b'2'
assert util.increment_byte_string(b'\x01\x01') == b'\x01\x02' assert util.increment_byte_string(b'\x01\x01') == b'\x01\x02'
assert util.increment_byte_string(b'\xff\xff') == None assert util.increment_byte_string(b'\xff\xff') is None

Loading…
Cancel
Save