From 749e3ef281e20e16ec6917a7fd42daa1a5051c64 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sat, 20 Mar 2010 03:15:27 +0100 Subject: [PATCH] docs: Document handle_pattern decorator --- mopidy/mpd/frontend.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mopidy/mpd/frontend.py b/mopidy/mpd/frontend.py index f9404eb4..f2c10bbb 100644 --- a/mopidy/mpd/frontend.py +++ b/mopidy/mpd/frontend.py @@ -22,6 +22,23 @@ logger = logging.getLogger('mopidy.mpd.frontend') _request_handlers = {} def handle_pattern(pattern): + """ + Decorator for connecting command handlers to command patterns. + + If you use named groups in the pattern, the decorated method will get the + groups as keyword arguments. If the group is optional, remember to give the + argument a default value. + + For example, if the command is ``do that thing`` the ``what`` argument will + be ``this thing``:: + + @handle_pattern('^do (?P.+)$') + def do(what): + ... + + :param pattern: regexp pattern for matching commands + :type pattern: string + """ def decorator(func): if pattern in _request_handlers: raise ValueError(u'Tried to redefine handler for %s with %s' % (