MCPcopy
hub / github.com/benoitc/gunicorn / load_class

Function load_class

gunicorn/util.py:79–126  ·  view source on GitHub ↗
(uri, default="gunicorn.workers.sync.SyncWorker",
               section="gunicorn.workers")

Source from the content-addressed store, hash-verified

77
78
79def load_class(uri, default="gunicorn.workers.sync.SyncWorker",
80 section="gunicorn.workers"):
81 if inspect.isclass(uri):
82 return uri
83 if uri.startswith("egg:"):
84 # uses entry points
85 entry_str = uri.split("egg:")[1]
86 try:
87 dist, name = entry_str.rsplit("#", 1)
88 except ValueError:
89 dist = entry_str
90 name = default
91
92 try:
93 return load_entry_point(dist, section, name)
94 except Exception:
95 exc = traceback.format_exc()
96 msg = "class uri %r invalid or not found: \n\n[%s]"
97 raise RuntimeError(msg % (uri, exc))
98 else:
99 components = uri.split('.')
100 if len(components) == 1:
101 while True:
102 if uri.startswith("#"):
103 uri = uri[1:]
104
105 if uri in SUPPORTED_WORKERS:
106 components = SUPPORTED_WORKERS[uri].split(".")
107 break
108
109 try:
110 return load_entry_point(
111 "gunicorn", section, uri
112 )
113 except Exception:
114 exc = traceback.format_exc()
115 msg = "class uri %r invalid or not found: \n\n[%s]"
116 raise RuntimeError(msg % (uri, exc))
117
118 klass = components.pop(-1)
119
120 try:
121 mod = importlib.import_module('.'.join(components))
122 except Exception:
123 exc = traceback.format_exc()
124 msg = "class uri %r invalid or not found: \n\n[%s]"
125 raise RuntimeError(msg % (uri, exc))
126 return getattr(mod, klass)
127
128
129positionals = (

Callers 1

test_worker_classFunction · 0.90

Calls 1

load_entry_pointFunction · 0.85

Tested by 1

test_worker_classFunction · 0.72