Module h2o_wave.routing
Functions
handle_on
on
Indicate that a function is a query handler that should be invoked when q.args or q.events contains an argument that matches a specific name or pattern or value.
Examples: A function annotated with @on('foo') is invoked whenever q.args.foo is found and the value is truthy. A function annotated with @on('foo', lambda x: x is False) is invoked whenever q.args.foo is False. A function annotated with @on('foo', lambda x: isinstance(x, bool) is invoked whenever q.args.foo is True or False. A function annotated with @on('foo', lambda x: 42 <= x <= 420) is invoked whenever q.args.foo between 42 and 420. A function annotated with @on('foo.bar') is invoked whenever q.events.foo.bar is found and the value is truthy. A function annotated with @on('foo.bar', lambda x: x is False) is invoked whenever q.events.foo.bar is False. A function annotated with @on('foo.bar', lambda x: isinstance(x, bool) is invoked whenever q.events.foo.bar is True or False. A function annotated with @on('foo.bar', lambda x: 42 <= x <= 420) is invoked whenever q.events.foo.bar between 42 and 420. A function annotated with @on('#foo') is invoked whenever q.args['#'] equals 'foo'. A function annotated with @on('#foo/bar') is invoked whenever q.args['#'] equals 'foo/bar'. A function annotated with @on('#foo/{fruit}') is invoked whenever q.args['#'] matches 'foo/apple', 'foo/orange', etc. The parameter 'fruit' is passed to the function (in this case, 'apple', 'orange', etc.)
Parameters in patterns (indicated within curly braces) can be converted to str, int, float or uuid.UUID instances by suffixing the parameters with str, int, float or uuid, respectively.
Examples: - user_id:int: user_id is converted to an integer. - amount:float: amount is converted to a float. - id:uuid: id is converted to a uuid.UUID.
Args
arg- The name of the
q.argargument (in case of plain arguments) or the event_source.event_type (in case of events) or a pattern (in case of hash arguments, orq.args['#']). If not provided, theq.argargument is assumed to be the same as the name of the function. predicate- A function (or lambda) to test the value of the argument. If provided, the query handler is invoked if the function returns a truthy value.