From d1f2ab570d437184c025247a98ea4b6f3d5b8b6e Mon Sep 17 00:00:00 2001 From: Marcel Hellkamp Date: Fri, 27 May 2022 11:06:54 +0200 Subject: fix #1251: Deprecation warning for imp module. --- bottle.py | 6 ++++-- test/test_importhook.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bottle.py b/bottle.py index 48aefbb..8e7e3d7 100755 --- a/bottle.py +++ b/bottle.py @@ -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__ = '' % name mod.__dict__.update(**args) return mod -- cgit v1.2.1