scope#

starlite.utils.scope.get_serializer_from_scope(scope: Scope) Optional[Serializer]#

Return a serializer given a scope object.

Parameters:

scope – The ASGI connection scope.

Returns:

A serializer function

starlite.utils.scope.get_starlite_scope_state(scope: Scope, key: str, default: Any = None, pop: bool = False) Any#

Get an internal value from connection scope state.

Note

If called with a default value, this method behaves like to dict.set_default(), both setting the key in the namespace to the default value, and returning it.

If called without a default value, the method behaves like dict.get(), returning None if the key does not exist.

Parameters:
  • scope – The connection scope.

  • key – Key to get from internal namespace in scope state.

  • default – Default value to return.

  • pop – Boolean flag dictating whether the value should be deleted from the state.

Returns:

Value mapped to key in internal connection scope namespace.

starlite.utils.scope.set_starlite_scope_state(scope: Scope, key: str, value: Any) None#

Set an internal value in connection scope state.

Parameters:
  • scope – The connection scope.

  • key – Key to set under internal namespace in scope state.

  • value – Value for key.