[python] refactor message parsing