config: Serialize unicode to bytes using sys.getfilesystemencoding()
This commit is contained in:
parent
3417abfe64
commit
9974f77f1b
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
import logging
|
||||
import re
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from mopidy.utils import path
|
||||
from mopidy.config import validators
|
||||
@ -254,6 +255,8 @@ class Path(ConfigValue):
|
||||
return ExpandedPath(value, expanded)
|
||||
|
||||
def serialize(self, value, display=False):
|
||||
if isinstance(value, unicode):
|
||||
value = value.encode(sys.getfilesystemencoding())
|
||||
if isinstance(value, ExpandedPath):
|
||||
return value.original
|
||||
return value
|
||||
|
||||
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
||||
import logging
|
||||
import mock
|
||||
import socket
|
||||
import sys
|
||||
|
||||
from mopidy.config import types
|
||||
|
||||
@ -364,3 +365,10 @@ class PathTest(unittest.TestCase):
|
||||
def test_serialize_plain_string(self):
|
||||
value = types.Path()
|
||||
self.assertEqual('path', value.serialize(b'path'))
|
||||
|
||||
def test_serialize_unicode_string(self):
|
||||
value = types.Path()
|
||||
expected = 'æøå'.encode(sys.getfilesystemencoding())
|
||||
result = value.serialize('æøå')
|
||||
self.assertEqual(expected, result)
|
||||
self.assertIsInstance(result, bytes)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user