recommendations from pycodestyle (pep8 style)
This commit is contained in:
parent
09c4bdc5c3
commit
a03665696c
@ -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)
|
||||||
|
|||||||
@ -87,7 +87,7 @@ class JSONRPCv1(JSONRPC):
|
|||||||
def is_request(cls, payload):
|
def is_request(cls, payload):
|
||||||
'''Returns True if the payload (which has a method) is a request.
|
'''Returns True if the payload (which has a method) is a request.
|
||||||
False means it is a notification.'''
|
False means it is a notification.'''
|
||||||
return payload.get('id') != None
|
return payload.get('id') is not None
|
||||||
|
|
||||||
|
|
||||||
class JSONRPCv2(JSONRPC):
|
class JSONRPCv2(JSONRPC):
|
||||||
@ -296,7 +296,7 @@ class JSONSessionBase(util.LoggedClass):
|
|||||||
'''Extract and return the ID from the payload.
|
'''Extract and return the ID from the payload.
|
||||||
|
|
||||||
Raises an RPCError if it is missing or invalid.'''
|
Raises an RPCError if it is missing or invalid.'''
|
||||||
if not 'id' in payload:
|
if 'id' not in payload:
|
||||||
raise RPCError('missing id', JSONRPC.INVALID_REQUEST)
|
raise RPCError('missing id', JSONRPC.INVALID_REQUEST)
|
||||||
|
|
||||||
id_ = payload['id']
|
id_ = payload['id']
|
||||||
|
|||||||
@ -24,6 +24,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.'''
|
||||||
|
|
||||||
|
|||||||
@ -109,6 +109,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
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()
|
||||||
|
|||||||
@ -170,7 +170,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)
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import lib.util as util
|
|||||||
class DaemonError(Exception):
|
class DaemonError(Exception):
|
||||||
'''Raised when the daemon returns an error in its results.'''
|
'''Raised when the daemon returns an error in its results.'''
|
||||||
|
|
||||||
|
|
||||||
class Daemon(util.LoggedClass):
|
class Daemon(util.LoggedClass):
|
||||||
'''Handles connections to a daemon at the given URL.'''
|
'''Handles connections to a daemon at the given URL.'''
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ from server.version import VERSION
|
|||||||
|
|
||||||
UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value")
|
UTXO = namedtuple("UTXO", "tx_num tx_pos tx_hash height value")
|
||||||
|
|
||||||
|
|
||||||
class DB(util.LoggedClass):
|
class DB(util.LoggedClass):
|
||||||
'''Simple wrapper of the backend database for querying.
|
'''Simple wrapper of the backend database for querying.
|
||||||
|
|
||||||
|
|||||||
@ -85,7 +85,6 @@ class Env(LoggedClass):
|
|||||||
if self.identity.tcp_port == self.identity.ssl_port:
|
if self.identity.tcp_port == self.identity.ssl_port:
|
||||||
raise self.Error('IRC TCP and SSL ports are the same')
|
raise self.Error('IRC TCP and SSL ports are the same')
|
||||||
|
|
||||||
|
|
||||||
def default(self, envvar, default):
|
def default(self, envvar, default):
|
||||||
return environ.get(envvar, default)
|
return environ.get(envvar, default)
|
||||||
|
|
||||||
|
|||||||
@ -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()
|
||||||
|
|||||||
@ -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):
|
||||||
|
|||||||
@ -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)))
|
||||||
|
|||||||
@ -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…
Reference in New Issue
Block a user