This provides a class which works as a command registry. Functions are added to
the registry through a method on the class `add`. Add acts as a decorator
taking in the name of the command and optionally type converters for arguments.
When handling requests, we can now tokenize the line, and then just pass the
arguments to our commands helper. It will lookup the correct handler and apply
any validation before calling the original function.
For the sake of testing the original function is not wrapped. This the
functions, and anything testing them directly can simply assume pre-converted
data as long as type annotations are in place.
A sample usage would be:
@protocol.commands.add('addid', position=protocol.integer)
def addid(context, uri, position=None)
pass
def handle_request(line):
tokens = protocol.tokenizer(line)
context = ...
result = protocol.commands.call(tokens, context=context)
- Adds tests for correctness of tokenizer (which also would have shown shlex
wouldn't have worked).
- Should conform with the original's behavior, though we won't be able to match
the error messages without a lot of extra work as a non-regexp version is
likely a no go on python due to speed.
This commit does not try to make the events correct/perfect with regard to
GStreamer states, end-of-stream signalling, etc. It only tries to make the
events work consistently across all the methods on the playback controller.
* play(track) while already playing has changed from:
- playback_state_changed(old_state='playing', new_state='playing')
- track_playback_started(track=...)
to:
- playback_state_changed(old_state='playing', new_state='stopped')
- track_playback_ended(track=..., time_position=...)
- playback_state_changed(old_state='stopped', new_state='playing')
- track_playback_started(track=...)
* next() has changed from:
- track_playback_ended(track=..., time_position=...)
- playback_state_changed(old_state='playing', new_state='stopped')
- track_playback_ended(track=..., time_position=0)
- playback_state_changed(old_state='stopped', new_state='playing')
- track_playback_started(track=...)
to same as play() above.
* previous() has changed in the same way as next().
* on_end_of_track() has changed from:
- track_playback_ended(track=..., time_position=...)
- playback_state_changed(old_state='playing', new_state='playing')
- track_playback_started(track=...)
to same as play() above.
* stop() has reordered its events from:
- track_playback_ended(track=..., time_position=...)
- playback_state_changed(old_state='playing', new_state='stopped')
to:
- playback_state_changed(old_state='playing', new_state='stopped')
- track_playback_ended(track=..., time_position=...)