django_unicorn.call_method_parser#

Module Contents#

exception django_unicorn.call_method_parser.InvalidKwargError#

Bases: Exception

Common base class for all non-exit exceptions.

django_unicorn.call_method_parser.eval_value(value)#

Uses ast.literal_eval to parse strings into an appropriate Python primitive.

Also returns an appropriate object for strings that look like they represent datetime, date, time, duration, or UUID.

django_unicorn.call_method_parser.parse_kwarg(kwarg: str, *, raise_if_unparseable=False) Dict[str, Any]#

Parses a potential kwarg as a string into a dictionary.

Example

parse_kwarg(β€œtest=’1’”) == {β€œtest”: β€œ1”}

Parameters:
  • kwarg – Potential kwarg as a string. e.g. β€œtest=’1’”.

  • raise_if_unparseable – Raise an error if the kwarg cannot be parsed. Defaults to False.

Returns:

Dictionary of key-value pairs.

django_unicorn.call_method_parser.parse_call_method_name(call_method_name: str) Tuple[str, Tuple[Any], Mapping[str, Any]]#

Parses the method name from the request payload into a set of parameters to pass to a method.

Parameters:

call_method_name (param) – String representation of a method name with parameters, e.g. β€œset_name(β€˜Bob’)”

Returns:

Tuple of method_name, a list of arguments and a dict of keyword arguments