mpd: Add protocol.position_or_range converter

This commit is contained in:
Thomas Adamcik 2014-01-23 00:40:18 +01:00
parent b9b5a78938
commit e7017f3ccb

View File

@ -108,6 +108,21 @@ def boolean(value):
raise ValueError('%r is not 0 or 1' % value)
def position_or_range(value):
# TODO: test and check that values are positive
if ':' in value:
start, stop = value.split(':', 1)
start = int(start)
if stop.strip():
stop = int(stop)
else:
stop = None
else:
start = int(value)
stop = start + 1
return slice(start, stop)
class Commands(object):
def __init__(self):
self.handlers = {}