Fixed #21628 by removing the last usage of the imp module.
This commit is contained in:
parent
b09faa497e
commit
9e9e73735e
|
@ -1,4 +1,3 @@
|
|||
import imp
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
@ -13,11 +12,6 @@ from django.utils.module_loading import (
|
|||
|
||||
|
||||
class DefaultLoader(unittest.TestCase):
|
||||
def setUp(self):
|
||||
sys.meta_path.insert(0, ProxyFinder())
|
||||
|
||||
def tearDown(self):
|
||||
sys.meta_path.pop(0)
|
||||
|
||||
def test_loader(self):
|
||||
"Normal module existence can be tested"
|
||||
|
@ -178,35 +172,6 @@ class AutodiscoverModulesTestCase(SimpleTestCase):
|
|||
self.assertEqual(site._registry, {'lorem': 'ipsum'})
|
||||
|
||||
|
||||
class ProxyFinder:
|
||||
def __init__(self):
|
||||
self._cache = {}
|
||||
|
||||
def find_module(self, fullname, path=None):
|
||||
tail = fullname.rsplit('.', 1)[-1]
|
||||
try:
|
||||
fd, fn, info = imp.find_module(tail, path)
|
||||
if fullname in self._cache:
|
||||
old_fd = self._cache[fullname][0]
|
||||
if old_fd:
|
||||
old_fd.close()
|
||||
self._cache[fullname] = (fd, fn, info)
|
||||
except ImportError:
|
||||
return None
|
||||
else:
|
||||
return self # this is a loader as well
|
||||
|
||||
def load_module(self, fullname):
|
||||
if fullname in sys.modules:
|
||||
return sys.modules[fullname]
|
||||
fd, fn, info = self._cache[fullname]
|
||||
try:
|
||||
return imp.load_module(fullname, fd, fn, info)
|
||||
finally:
|
||||
if fd:
|
||||
fd.close()
|
||||
|
||||
|
||||
class TestFinder:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.importer = zipimporter(*args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue