Handle encoding at the borders and only use unicode objects internally
This commit is contained in:
parent
4605a9e8c9
commit
ecd5e686f6
@ -1,2 +1,2 @@
|
|||||||
def get_version():
|
def get_version():
|
||||||
return '0'
|
return u'0'
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import socket
|
|||||||
from mopidy import settings
|
from mopidy import settings
|
||||||
from mopidy.session import MpdSession
|
from mopidy.session import MpdSession
|
||||||
|
|
||||||
logger = logging.getLogger('server')
|
logger = logging.getLogger(u'server')
|
||||||
|
|
||||||
class MpdServer(asyncore.dispatcher):
|
class MpdServer(asyncore.dispatcher):
|
||||||
def __init__(self, handler_class=MpdSession):
|
def __init__(self, handler_class=MpdSession):
|
||||||
@ -18,7 +18,7 @@ class MpdServer(asyncore.dispatcher):
|
|||||||
|
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
(client_socket, client_address) = self.accept()
|
(client_socket, client_address) = self.accept()
|
||||||
logger.info('Connection from: [%s]:%s', *client_address)
|
logger.info(u'Connection from: [%s]:%s', *client_address)
|
||||||
self.handler_class(client_socket, client_address)
|
self.handler_class(client_socket, client_address)
|
||||||
|
|
||||||
def handle_close(self):
|
def handle_close(self):
|
||||||
|
|||||||
@ -3,21 +3,31 @@ import logging
|
|||||||
|
|
||||||
from mopidy import get_version, settings
|
from mopidy import get_version, settings
|
||||||
|
|
||||||
logger = logging.getLogger('session')
|
logger = logging.getLogger(u'session')
|
||||||
|
|
||||||
class MpdSession(asynchat.async_chat):
|
class MpdSession(asynchat.async_chat):
|
||||||
def __init__(self, client_socket, client_address):
|
def __init__(self, client_socket, client_address):
|
||||||
asynchat.async_chat.__init__(self, sock=client_socket)
|
asynchat.async_chat.__init__(self, sock=client_socket)
|
||||||
self.input_buffer = []
|
self.input_buffer = []
|
||||||
self.set_terminator(settings.LINE_TERMINATOR)
|
self.set_terminator(settings.MPD_LINE_TERMINATOR)
|
||||||
self.respond('OK MPD (mopidy %s)' % get_version())
|
self.send_response(u'OK MPD (mopidy %s)' % get_version())
|
||||||
|
|
||||||
def collect_incoming_data(self, data):
|
def collect_incoming_data(self, data):
|
||||||
self.input_buffer.append(data)
|
self.input_buffer.append(data)
|
||||||
|
|
||||||
def found_terminator(self):
|
def found_terminator(self):
|
||||||
logger.debug('Input: %s', ''.join(self.input_buffer))
|
data = ''.join(self.input_buffer)
|
||||||
self.input_buffer = []
|
self.input_buffer = []
|
||||||
|
input = data.decode(settings.MPD_LINE_ENCODING)
|
||||||
|
logger.debug(u'Input: %s', input)
|
||||||
|
self.handle_request(input)
|
||||||
|
|
||||||
|
def handle_request(self, input):
|
||||||
|
pass # TODO
|
||||||
|
|
||||||
|
def send_response(self, output):
|
||||||
|
logger.debug(u'Output: %s', output)
|
||||||
|
output = u'%s%s' % (output, settings.MPD_LINE_TERMINATOR)
|
||||||
|
data = output.encode(settings.MPD_LINE_ENCODING)
|
||||||
|
self.push(data)
|
||||||
|
|
||||||
def respond(self, data):
|
|
||||||
self.push('%s%s' % (data, settings.LINE_TERMINATOR))
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
CONSOLE_LOG_FORMAT = '%(levelname)-8s %(asctime)s\n %(message)s'
|
CONSOLE_LOG_FORMAT = u'%(levelname)-8s %(asctime)s\n %(message)s'
|
||||||
LINE_TERMINATOR = '\n'
|
MPD_LINE_ENCODING = u'utf-8'
|
||||||
MPD_SERVER_HOSTNAME = 'localhost'
|
MPD_LINE_TERMINATOR = u'\n'
|
||||||
|
MPD_SERVER_HOSTNAME = u'localhost'
|
||||||
MPD_SERVER_PORT = 6600
|
MPD_SERVER_PORT = 6600
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user