mopidy/mopidy/mpd
Thomas Adamcik 455f3dd403 mpd: Write commands helper for tokenized command handling
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)
2014-01-19 19:59:07 +01:00
..
protocol mpd: Write commands helper for tokenized command handling 2014-01-19 19:59:07 +01:00
__init__.py ext: Switch rest of bundled extensions to registry 2014-01-09 22:35:54 +01:00
actor.py The harmless Zeroconf warning is confusing users 2014-01-12 12:19:04 +01:00
dispatcher.py Merge pull request #647 from adamcik/feature/browse-by-uri 2014-01-17 15:58:39 -08:00
exceptions.py mpd: Annotate exceptions with current command automatically (fixes #649) 2014-01-18 00:34:41 +01:00
ext.conf mpd: Move mopidy.{frontends => }.mpd 2013-12-31 14:11:16 +01:00
session.py log: Use loggers named after __name__ 2014-01-01 13:31:20 +01:00
translator.py mpd: Switch mpd to use path<->uri mapping for browsing 2014-01-17 17:16:24 +01:00