diff options
author | Marcel Hellkamp <marc@gsites.de> | 2022-05-27 11:06:54 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2022-06-12 15:17:06 +0200 |
commit | d1f2ab570d437184c025247a98ea4b6f3d5b8b6e (patch) | |
tree | f31b87a30b32aa0e5cddf8eb874544d967b77dd0 | |
parent | 5a6c620b2a51adad2591e0d161d392cb8c0d4c50 (diff) | |
download | bottle-d1f2ab570d437184c025247a98ea4b6f3d5b8b6e.tar.gz |
fix #1251: Deprecation warning for imp module.
-rwxr-xr-x | bottle.py | 6 | ||||
-rw-r--r-- | test/test_importhook.py | 4 |
2 files changed, 6 insertions, 4 deletions
@@ -69,7 +69,7 @@ if __name__ == '__main__': # Imports and Python 2/3 unification ########################################## ############################################################################### -import base64, calendar, cgi, email.utils, functools, hmac, imp, itertools,\ +import base64, calendar, cgi, email.utils, functools, hmac, itertools,\ mimetypes, os, re, tempfile, threading, time, warnings, weakref, hashlib from types import FunctionType @@ -123,6 +123,7 @@ if py3k: urlunquote = functools.partial(urlunquote, encoding='latin1') from http.cookies import SimpleCookie, Morsel, CookieError from collections.abc import MutableMapping as DictMixin + from types import ModuleType as new_module import pickle from io import BytesIO import configparser @@ -143,6 +144,7 @@ else: # 2.x from Cookie import SimpleCookie, Morsel, CookieError from itertools import imap import cPickle as pickle + from imp import new_module from StringIO import StringIO as BytesIO import ConfigParser as configparser from collections import MutableMapping as DictMixin @@ -2057,7 +2059,7 @@ class _ImportRedirect(object): """ Create a virtual package that redirects imports (see PEP 302). """ self.name = name self.impmask = impmask - self.module = sys.modules.setdefault(name, imp.new_module(name)) + self.module = sys.modules.setdefault(name, new_module(name)) self.module.__dict__.update({ '__file__': __file__, '__path__': [], diff --git a/test/test_importhook.py b/test/test_importhook.py index 95f1239..b8154d5 100644 --- a/test/test_importhook.py +++ b/test/test_importhook.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- import unittest import sys, os -import imp +import bottle class TestImportHooks(unittest.TestCase): def make_module(self, name, **args): - mod = sys.modules.setdefault(name, imp.new_module(name)) + mod = sys.modules.setdefault(name, bottle.new_module(name)) mod.__file__ = '<virtual %s>' % name mod.__dict__.update(**args) return mod |