python: move more logic from XBPython to CPythonInvoker