Use py3_path for sqlite3.connect (part of #2096)

This commit is contained in:
Adrian Sampson 2016-06-30 14:54:38 -07:00
parent e25a95b2d3
commit d04fe42cee
2 changed files with 7 additions and 2 deletions

View file

@ -27,6 +27,7 @@ import collections
import beets
from beets.util.functemplate import Template
from beets.util import py3_path
from beets.dbcore import types
from .query import MatchQuery, NullSort, TrueQuery
import six
@ -727,9 +728,11 @@ class Database(object):
if thread_id in self._connections:
return self._connections[thread_id]
else:
# Make a new connection.
# Make a new connection. The `sqlite3` module can't use
# bytestring paths here on Python 3, so we need to
# provide a `str` using `py3_path`.
conn = sqlite3.connect(
self.path,
py3_path(self.path),
timeout=beets.config['timeout'].as_number(),
)

View file

@ -635,6 +635,8 @@ def py3_path(path):
it is. So this function helps us "smuggle" the true bytes data
through APIs that took Python 3's Unicode mandate too seriously.
"""
if isinstance(path, six.text_type):
return path
assert isinstance(path, bytes)
if six.PY2:
return path