-
Notifications
You must be signed in to change notification settings - Fork 20
/
reflection.py
94 lines (69 loc) · 2.6 KB
/
reflection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from mopidy_mpd import exceptions, protocol
@protocol.commands.add("config", list_command=False)
def config(context):
"""
*musicpd.org, reflection section:*
``config``
Dumps configuration values that may be interesting for the client. This
command is only permitted to "local" clients (connected via UNIX domain
socket).
"""
raise exceptions.MpdPermissionError(command="config")
@protocol.commands.add("commands", auth_required=False)
def commands(context):
"""
*musicpd.org, reflection section:*
``commands``
Shows which commands the current user has access to.
"""
command_names = set()
for name, handler in protocol.commands.handlers.items():
if not handler.list_command:
continue
if context.dispatcher.authenticated or not handler.auth_required:
command_names.add(name)
return [("command", command_name) for command_name in sorted(command_names)]
@protocol.commands.add("decoders")
def decoders(context):
"""
*musicpd.org, reflection section:*
``decoders``
Print a list of decoder plugins, followed by their supported
suffixes and MIME types. Example response::
plugin: mad
suffix: mp3
suffix: mp2
mime_type: audio/mpeg
plugin: mpcdec
suffix: mpc
*Clarifications:*
- ncmpcpp asks for decoders the first time you open the browse view. By
returning nothing and OK instead of an not implemented error, we avoid
"Not implemented" showing up in the ncmpcpp interface, and we get the
list of playlists without having to enter the browse interface twice.
"""
return # TODO
@protocol.commands.add("notcommands", auth_required=False)
def notcommands(context):
"""
*musicpd.org, reflection section:*
``notcommands``
Shows which commands the current user does not have access to.
"""
command_names = {"config", "kill"} # No permission to use
for name, handler in protocol.commands.handlers.items():
if not handler.list_command:
continue
if not context.dispatcher.authenticated and handler.auth_required:
command_names.add(name)
return [("command", command_name) for command_name in sorted(command_names)]
@protocol.commands.add("urlhandlers")
def urlhandlers(context):
"""
*musicpd.org, reflection section:*
``urlhandlers``
Gets a list of available URL handlers.
"""
return [
("handler", uri_scheme) for uri_scheme in context.core.get_uri_schemes().get()
]