mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Remove util.import_module
This commit is contained in:
parent
679c3727df
commit
6df58a99b5
@ -109,7 +109,7 @@ class Application(BaseApplication):
|
|||||||
return vars(mod)
|
return vars(mod)
|
||||||
|
|
||||||
def get_config_from_module_name(self, module_name):
|
def get_config_from_module_name(self, module_name):
|
||||||
return vars(util.import_module(module_name))
|
return vars(importlib.import_module(module_name))
|
||||||
|
|
||||||
def load_config_from_module_name_or_filename(self, location):
|
def load_config_from_module_name_or_filename(self, location):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -54,43 +54,6 @@ except ImportError:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from importlib import import_module
|
|
||||||
except ImportError:
|
|
||||||
def _resolve_name(name, package, level):
|
|
||||||
"""Return the absolute name of the module to be imported."""
|
|
||||||
if not hasattr(package, 'rindex'):
|
|
||||||
raise ValueError("'package' not set to a string")
|
|
||||||
dot = len(package)
|
|
||||||
for _ in range(level, 1, -1):
|
|
||||||
try:
|
|
||||||
dot = package.rindex('.', 0, dot)
|
|
||||||
except ValueError:
|
|
||||||
msg = "attempted relative import beyond top-level package"
|
|
||||||
raise ValueError(msg)
|
|
||||||
return "%s.%s" % (package[:dot], name)
|
|
||||||
|
|
||||||
def import_module(name, package=None):
|
|
||||||
"""Import a module.
|
|
||||||
|
|
||||||
The 'package' argument is required when performing a relative import. It
|
|
||||||
specifies the package to use as the anchor point from which to resolve the
|
|
||||||
relative import to an absolute import.
|
|
||||||
|
|
||||||
"""
|
|
||||||
if name.startswith('.'):
|
|
||||||
if not package:
|
|
||||||
raise TypeError("relative imports require the 'package' argument")
|
|
||||||
level = 0
|
|
||||||
for character in name:
|
|
||||||
if character != '.':
|
|
||||||
break
|
|
||||||
level += 1
|
|
||||||
name = _resolve_name(name[level:], package, level)
|
|
||||||
__import__(name)
|
|
||||||
return sys.modules[name]
|
|
||||||
|
|
||||||
|
|
||||||
def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
||||||
section="gunicorn.workers"):
|
section="gunicorn.workers"):
|
||||||
if inspect.isclass(uri):
|
if inspect.isclass(uri):
|
||||||
@ -132,7 +95,7 @@ def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
|
|||||||
klass = components.pop(-1)
|
klass = components.pop(-1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mod = import_module('.'.join(components))
|
mod = importlib.import_module('.'.join(components))
|
||||||
except:
|
except:
|
||||||
exc = traceback.format_exc()
|
exc = traceback.format_exc()
|
||||||
msg = "class uri %r invalid or not found: \n\n[%s]"
|
msg = "class uri %r invalid or not found: \n\n[%s]"
|
||||||
@ -521,6 +484,7 @@ def to_bytestring(value, encoding="utf8"):
|
|||||||
|
|
||||||
return value.encode(encoding)
|
return value.encode(encoding)
|
||||||
|
|
||||||
|
|
||||||
def has_fileno(obj):
|
def has_fileno(obj):
|
||||||
if not hasattr(obj, "fileno"):
|
if not hasattr(obj, "fileno"):
|
||||||
return False
|
return False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user