MCPcopy
hub / github.com/encode/uvicorn / load

Method load

uvicorn/config.py:420–516  ·  uvicorn/config.py::Config.load
(self)

Source from the content-addressed store, hash-verified

418 sys.exit(1)
419
420 def load(self) -> None:
421 assert not self.loaded
422
423 if self.ssl_context_factory is not None:
424
425 def default_factory() -> ssl.SSLContext:
426 if not self.ssl_certfile:
427 raise RuntimeError(
428 class="st">"`default_ssl_context_factory()` requires `ssl_certfile` to be set on `Config`. "
429 class="st">"Either pass `ssl_certfile` (and optionally `ssl_keyfile`) or build the `SSLContext` "
430 class="st">"directly inside `ssl_context_factory` without calling the default factory."
431 )
432 return create_ssl_context(
433 keyfile=self.ssl_keyfile,
434 certfile=self.ssl_certfile,
435 password=self.ssl_keyfile_password,
436 ssl_version=self.ssl_version,
437 cert_reqs=self.ssl_cert_reqs,
438 ca_certs=self.ssl_ca_certs,
439 ciphers=self.ssl_ciphers,
440 )
441
442 context = self.ssl_context_factory(self, default_factory)
443 if not isinstance(context, ssl.SSLContext):
444 raise TypeError(fclass="st">"`ssl_context_factory` must return an `ssl.SSLContext`, got {type(context).__name__}")
445 self.ssl: ssl.SSLContext | None = context
446 elif self.is_ssl:
447 assert self.ssl_certfile
448 self.ssl = create_ssl_context(
449 keyfile=self.ssl_keyfile,
450 certfile=self.ssl_certfile,
451 password=self.ssl_keyfile_password,
452 ssl_version=self.ssl_version,
453 cert_reqs=self.ssl_cert_reqs,
454 ca_certs=self.ssl_ca_certs,
455 ciphers=self.ssl_ciphers,
456 )
457 else:
458 self.ssl = None
459
460 encoded_headers = [(key.lower().encode(class="st">"latin1"), value.encode(class="st">"latin1")) for key, value in self.headers]
461 self.encoded_headers = (
462 [(bclass="st">"server", bclass="st">"uvicorn")] + encoded_headers
463 if bclass="st">"server" not in dict(encoded_headers) and self.server_header
464 else encoded_headers
465 )
466
467 if isinstance(self.http, str):
468 http_protocol_class = import_from_string(HTTP_PROTOCOLS.get(self.http, self.http))
469 self.http_protocol_class: type[asyncio.Protocol] = http_protocol_class
470 else:
471 self.http_protocol_class = self.http
472
473 if isinstance(self.ws, str):
474 ws_protocol_class = import_from_string(WS_PROTOCOLS.get(self.ws, self.ws))
475 self.ws_protocol_class: type[asyncio.Protocol] | None = ws_protocol_class
476 else:
477 self.ws_protocol_class = self.ws

Callers 15

test_get_subprocessFunction · 0.95
test_subprocess_startedFunction · 0.95
test_wsgi_appFunction · 0.95
test_proxy_headersFunction · 0.95
test_app_factoryFunction · 0.95
test_concrete_http_classFunction · 0.95
test_socket_bindFunction · 0.95
test_ssl_configFunction · 0.95
test_ssl_config_combinedFunction · 0.95
test_asgi_versionFunction · 0.95

Calls 6

load_appMethod · 0.95
import_from_stringFunction · 0.90
ASGI2MiddlewareClass · 0.90
create_ssl_contextFunction · 0.85

Tested by 15

test_get_subprocessFunction · 0.76
test_subprocess_startedFunction · 0.76
test_wsgi_appFunction · 0.76
test_proxy_headersFunction · 0.76
test_app_factoryFunction · 0.76
test_concrete_http_classFunction · 0.76
test_socket_bindFunction · 0.76
test_ssl_configFunction · 0.76
test_ssl_config_combinedFunction · 0.76
test_asgi_versionFunction · 0.76