Port of  official SphinxAPI to Python 3