From d04fe42cee9be8b0cdb10813a4af100e5f573688 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 30 Jun 2016 14:54:38 -0700 Subject: [PATCH] Use py3_path for sqlite3.connect (part of #2096) --- beets/dbcore/db.py | 7 +++++-- beets/util/__init__.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/beets/dbcore/db.py b/beets/dbcore/db.py index c0f329468..539658578 100644 --- a/beets/dbcore/db.py +++ b/beets/dbcore/db.py @@ -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(), ) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 83d1f18f3..0715459af 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -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