Assuming that the MPD line terminator does not vary neither
This commit is contained in:
parent
cade4b67f8
commit
3f0b216d19
@ -1,16 +1,18 @@
|
||||
import asynchat
|
||||
import logging
|
||||
|
||||
from mopidy import get_mpd_protocol_version, config
|
||||
from mopidy import get_mpd_protocol_version
|
||||
from mopidy.exceptions import MpdAckError
|
||||
from mopidy.mpd.handler import MpdHandler
|
||||
|
||||
logger = logging.getLogger(u'mpd.session')
|
||||
|
||||
#: All data between the client and the server is encoded in UTF-8.
|
||||
ENCODING = 'utf-8'
|
||||
ENCODING = u'utf-8'
|
||||
|
||||
def indent(string, places=4, linebreak=config.MPD_LINE_TERMINATOR):
|
||||
LINE_TERMINATOR = u'\n'
|
||||
|
||||
def indent(string, places=4, linebreak=LINE_TERMINATOR):
|
||||
lines = string.split(linebreak)
|
||||
if len(lines) == 1:
|
||||
return string
|
||||
@ -26,7 +28,7 @@ class MpdSession(asynchat.async_chat):
|
||||
self.server = server
|
||||
self.client_address = client_address
|
||||
self.input_buffer = []
|
||||
self.set_terminator(config.MPD_LINE_TERMINATOR.encode(ENCODING))
|
||||
self.set_terminator(LINE_TERMINATOR.encode(ENCODING))
|
||||
self.handler = handler_class(session=self, backend=backend)
|
||||
self.send_response(u'OK MPD %s' % get_mpd_protocol_version())
|
||||
|
||||
@ -57,11 +59,11 @@ class MpdSession(asynchat.async_chat):
|
||||
return self.send_response(u'ACK %s' % e)
|
||||
|
||||
def handle_response(self, response):
|
||||
self.send_response(config.MPD_LINE_TERMINATOR.join(response))
|
||||
self.send_response(LINE_TERMINATOR.join(response))
|
||||
|
||||
def send_response(self, output):
|
||||
logger.debug(u'Output: %s', indent(output))
|
||||
output = u'%s%s' % (output, config.MPD_LINE_TERMINATOR)
|
||||
output = u'%s%s' % (output, LINE_TERMINATOR)
|
||||
data = output.encode(ENCODING)
|
||||
self.push(data)
|
||||
|
||||
|
||||
@ -31,9 +31,6 @@ BACKENDS = (
|
||||
#: the format.
|
||||
CONSOLE_LOG_FORMAT = u'%(levelname)-8s %(asctime)s [%(threadName)s] %(name)s\n %(message)s'
|
||||
|
||||
#: Line terminator character used in MPD protocol. *Default:* ``\n``
|
||||
MPD_LINE_TERMINATOR = u'\n'
|
||||
|
||||
#: Which address Mopidy should bind to. Examples:
|
||||
#:
|
||||
#: ``localhost``
|
||||
|
||||
Loading…
Reference in New Issue
Block a user