ci: Use black instead of flake8
It results in mostly the same style, plus it’s configurable via pyproject.toml.
This commit is contained in:
@@ -34,8 +34,8 @@ class MuxRPCAPIException(Exception):
|
||||
class MuxRPCHandler(object):
|
||||
def check_message(self, msg):
|
||||
body = msg.body
|
||||
if isinstance(body, dict) and 'name' in body and body['name'] == 'Error':
|
||||
raise MuxRPCAPIException(body['message'])
|
||||
if isinstance(body, dict) and "name" in body and body["name"] == "Error":
|
||||
raise MuxRPCAPIException(body["message"])
|
||||
|
||||
|
||||
class MuxRPCRequestHandler(MuxRPCHandler):
|
||||
@@ -43,7 +43,7 @@ class MuxRPCRequestHandler(MuxRPCHandler):
|
||||
self.ps_handler = ps_handler
|
||||
|
||||
def __await__(self):
|
||||
msg = (yield from self.ps_handler.__await__())
|
||||
msg = yield from self.ps_handler.__await__()
|
||||
self.check_message(msg)
|
||||
return msg
|
||||
|
||||
@@ -63,7 +63,6 @@ class MuxRPCSourceHandler(MuxRPCHandler):
|
||||
|
||||
|
||||
class MuxRPCSinkHandlerMixin(object):
|
||||
|
||||
def send(self, msg, msg_type=PSMessageType.JSON, end=False):
|
||||
self.connection.send(msg, stream=True, msg_type=msg_type, req=self.req, end_err=end)
|
||||
|
||||
@@ -82,13 +81,13 @@ class MuxRPCSinkHandler(MuxRPCHandler, MuxRPCSinkHandlerMixin):
|
||||
|
||||
|
||||
def _get_appropriate_api_handler(type_, connection, ps_handler, req):
|
||||
if type_ in {'sync', 'async'}:
|
||||
if type_ in {"sync", "async"}:
|
||||
return MuxRPCRequestHandler(ps_handler)
|
||||
elif type_ == 'source':
|
||||
elif type_ == "source":
|
||||
return MuxRPCSourceHandler(ps_handler)
|
||||
elif type_ == 'sink':
|
||||
elif type_ == "sink":
|
||||
return MuxRPCSinkHandler(connection, req)
|
||||
elif type_ == 'duplex':
|
||||
elif type_ == "duplex":
|
||||
return MuxRPCDuplexHandler(ps_handler, connection, req)
|
||||
|
||||
|
||||
@@ -96,14 +95,14 @@ class MuxRPCRequest(object):
|
||||
@classmethod
|
||||
def from_message(cls, message):
|
||||
body = message.body
|
||||
return cls('.'.join(body['name']), body['args'])
|
||||
return cls(".".join(body["name"]), body["args"])
|
||||
|
||||
def __init__(self, name, args):
|
||||
self.name = name
|
||||
self.args = args
|
||||
|
||||
def __repr__(self):
|
||||
return '<MuxRPCRequest {0.name} {0.args}>'.format(self)
|
||||
return "<MuxRPCRequest {0.name} {0.args}>".format(self)
|
||||
|
||||
|
||||
class MuxRPCMessage(object):
|
||||
@@ -115,7 +114,7 @@ class MuxRPCMessage(object):
|
||||
self.body = body
|
||||
|
||||
def __repr__(self):
|
||||
return '<MuxRPCMessage {0.body}}>'.format(self)
|
||||
return "<MuxRPCMessage {0.body}}>".format(self)
|
||||
|
||||
|
||||
class MuxRPCAPI(object):
|
||||
@@ -128,7 +127,7 @@ class MuxRPCAPI(object):
|
||||
body = req_message.body
|
||||
if req_message is None:
|
||||
return
|
||||
if isinstance(body, dict) and body.get('name'):
|
||||
if isinstance(body, dict) and body.get("name"):
|
||||
self.process(self.connection, MuxRPCRequest.from_message(req_message))
|
||||
|
||||
def add_connection(self, connection):
|
||||
@@ -141,22 +140,23 @@ class MuxRPCAPI(object):
|
||||
@wraps(f)
|
||||
def _f(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return f
|
||||
|
||||
return _handle
|
||||
|
||||
def process(self, connection, request):
|
||||
handler = self.handlers.get(request.name)
|
||||
if not handler:
|
||||
raise MuxRPCAPIException('Method {} not found!'.format(request.name))
|
||||
raise MuxRPCAPIException("Method {} not found!".format(request.name))
|
||||
handler(connection, request)
|
||||
|
||||
def call(self, name, args, type_='sync'):
|
||||
def call(self, name, args, type_="sync"):
|
||||
if not self.connection.is_connected:
|
||||
raise Exception('not connected')
|
||||
raise Exception("not connected")
|
||||
old_counter = self.connection.req_counter
|
||||
ps_handler = self.connection.send({
|
||||
'name': name.split('.'),
|
||||
'args': args,
|
||||
'type': type_
|
||||
}, stream=type_ in {'sink', 'source', 'duplex'})
|
||||
ps_handler = self.connection.send(
|
||||
{"name": name.split("."), "args": args, "type": type_},
|
||||
stream=type_ in {"sink", "source", "duplex"},
|
||||
)
|
||||
return _get_appropriate_api_handler(type_, self.connection, ps_handler, old_counter)
|
||||
|
||||
Reference in New Issue
Block a user