Drop Python 2.6 support too

See #701.
This commit is contained in:
Olly Betts 2018-05-18 15:52:46 +12:00
commit 1198155083
3 changed files with 31 additions and 50 deletions

View file

@ -830,58 +830,39 @@ public:
if (!builtin && fastproxy) {
Printv(default_import_code, "if _swig_python_version_info >= (3, 0, 0):\n", NULL);
Printf(default_import_code, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, "elif _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(default_import_code, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, tab4, "raise RuntimeError('Python 2.7 or later required')\n", NULL);
} else {
Printv(default_import_code, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(default_import_code, tab4, "raise RuntimeError('Python 2.7 or later required')\n", NULL);
}
/* Import the C-extension module. This should be a relative import,
* since the shadow module may also have been imported by a relative
* import, and there is thus no guarantee that the C-extension is on
* sys.path. Relative imports must be explicitly specified from 2.6.0
* onwards (implicit relative imports will raise a DeprecationWarning
* in 2.6, and fail in 2.7 onwards).
* onwards (implicit relative imports raised a DeprecationWarning in 2.6,
* and fail in 2.7 onwards).
*
* For python 2.7.0 and newer, first determine the shadow wrappers package
* based on the __name__ it was given by the importer that loaded it.
* Then construct a name for the module based on the package name and the
* module name (we know the module name). Use importlib to try and load
* it. If an attempt to load the module with importlib fails with an
* ImportError then fallback and try and load just the module name from
* the global namespace.
* First determine the shadow wrappers package based on the __name__ it
* was given by the importer that loaded it. Then construct a name for
* the module based on the package name and the module name (we know the
* module name). Use importlib to try and load it. If an attempt to
* load the module with importlib fails with an ImportError then fallback
* and try and load just the module name from the global namespace.
*/
Printv(default_import_code, "if _swig_python_version_info >= (2, 7, 0):\n", NULL);
Printv(default_import_code, tab4, "def swig_import_helper():\n", NULL);
Printv(default_import_code, tab8, "import importlib\n", NULL);
Printv(default_import_code, tab8, "pkg = __name__.rpartition('.')[0]\n", NULL);
Printf(default_import_code, tab8 "mname = '.'.join((pkg, '%s')).lstrip('.')\n", module);
Printv(default_import_code, tab8, "try:\n", NULL);
Printv(default_import_code, tab8, tab4, "return importlib.import_module(mname)\n", NULL);
Printv(default_import_code, tab8, "except ImportError:\n", NULL);
Printf(default_import_code, tab8 tab4 "return importlib.import_module('%s')\n", module);
Printf(default_import_code, tab4 "%s = swig_import_helper()\n", module);
Printv(default_import_code, tab4, "del swig_import_helper\n", NULL);
Printv(default_import_code, "elif _swig_python_version_info >= (2, 6, 0):\n", NULL);
Printv(default_import_code, tab4, "def swig_import_helper():\n", NULL);
Printv(default_import_code, tab8, "from os.path import dirname\n", NULL);
Printv(default_import_code, tab8, "import imp\n", NULL);
Printv(default_import_code, tab8, "fp = None\n", NULL);
Printv(default_import_code, tab8, "try:\n", NULL);
Printf(default_import_code, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
Printf(default_import_code, tab8 "except ImportError:\n");
/* At here, the module may already loaded, so simply import it. */
Printf(default_import_code, tab4 tab8 "import %s\n", module);
Printf(default_import_code, tab4 tab8 "return %s\n", module);
Printv(default_import_code, tab8 "try:\n", NULL);
/* imp.load_module() handles fp being None. */
Printf(default_import_code, tab4 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
Printv(default_import_code, tab8, "finally:\n", NULL);
Printv(default_import_code, tab4 tab8 "if fp is not None:\n", NULL);
Printv(default_import_code, tab8 tab8, "fp.close()\n", NULL);
Printv(default_import_code, tab8, "return _mod\n", NULL);
Printf(default_import_code, tab4 "%s = swig_import_helper()\n", module);
Printv(default_import_code, tab4, "del swig_import_helper\n", NULL);
Printv(default_import_code, "else:\n", NULL);
Printv(default_import_code, tab4, "raise RuntimeError('Python 2.6 or later required')\n", NULL);
Printv(default_import_code, "def swig_import_helper():\n", NULL);
Printv(default_import_code, tab4, "import importlib\n", NULL);
Printv(default_import_code, tab4, "pkg = __name__.rpartition('.')[0]\n", NULL);
Printf(default_import_code, tab4 "mname = '.'.join((pkg, '%s')).lstrip('.')\n", module);
Printv(default_import_code, tab4, "try:\n", NULL);
Printv(default_import_code, tab8, "return importlib.import_module(mname)\n", NULL);
Printv(default_import_code, tab4, "except ImportError:\n", NULL);
Printf(default_import_code, tab8 "return importlib.import_module('%s')\n", module);
Printf(default_import_code, "%s = swig_import_helper()\n", module);
Printv(default_import_code, "del swig_import_helper\n", NULL);
if (builtin) {
/*