async def main_commands(loop, shutdown_routine, parser_object, windows, media): """Coroutine which processes the input of stdin""" try: async for line in aio.LineReader(loop, sys.stdin): if not line: break try: data = parser_object.parse(line[:-1]) command = action.Command(data.pop('action')) #pylint: disable=E1120 command.action_class(windows, media) \ .execute(**data) except (parser.ParseError, KeyError, ValueError, TypeError) as error: cause = (error.args[0] if isinstance(error, parser.ParseError) else error) print( parser_object.unparse({ 'type': 'error', 'name': type(cause).__name__, 'message': str(error), #'stack': traceback.format_exc() }), file=sys.stderr) finally: asyncio.ensure_future(shutdown_routine)
async def process_commands(loop, shutdown_routine_factory, windows, view, tools): """Coroutine which processes the input of stdin""" try: async for line in files.LineReader(loop, sys.stdin): if not line: break try: data = tools.parser.parse(line[:-1]) command = action.Command(data['action']) await command.action_class(**data) \ .apply(windows, view, tools) except (OSError, KeyError, ValueError, TypeError) as error: tools.error_handler(error) finally: asyncio.ensure_future(shutdown_routine_factory())
async def main_commands(loop, shutdown_routine_factory, parser_object, windows, view): """Coroutine which processes the input of stdin""" try: async for line in files.LineReader(loop, sys.stdin): if not line: break try: data = parser_object.parse(line[:-1]) command = action.Command(data['action']) command.action_class(**data) \ .apply(parser_object, windows, view) except (OSError, KeyError, ValueError, TypeError) as error: result.ErrorResult(error) \ .print(parser_object) finally: asyncio.ensure_future(shutdown_routine_factory())