From f56c2156a24b2ea77fe02a8f6d93cd8fbb197558 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 19 Jul 2012 17:37:47 +0900 Subject: [PATCH] pass utf8 to sqlite but don't clobber our original format --- anki/db.py | 7 ++++--- anki/upgrade.py | 9 ++------- anki/utils.py | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/anki/db.py b/anki/db.py index 3453ad113..8929c3024 100644 --- a/anki/db.py +++ b/anki/db.py @@ -12,9 +12,10 @@ from anki.hooks import runHook class DB(object): def __init__(self, path, text=None, timeout=0): - if isinstance(path, unicode): - path = path.encode("utf-8") - self._db = sqlite.connect(path, timeout=timeout) + encpath = path + if isinstance(encpath, unicode): + encpath = path.encode("utf-8") + self._db = sqlite.connect(encpath, timeout=timeout) if text: self._db.text_factory = text self._path = path diff --git a/anki/upgrade.py b/anki/upgrade.py index b8804017a..0c5a7617d 100644 --- a/anki/upgrade.py +++ b/anki/upgrade.py @@ -37,7 +37,7 @@ class Upgrader(object): def check(self, path): "True if deck looks ok." - with DB(self._utf8(path)) as db: + with DB(path) as db: return self._check(db) def _check(self, db): @@ -111,17 +111,12 @@ f.id = cards.factId)"""): def _openDB(self, path): self.tmppath = tmpfile(suffix=".anki2") - shutil.copy(path, self._utf8(self.tmppath)) + shutil.copy(path, self.tmppath) self.db = DB(self.tmppath) def _openCol(self): self.col = _Collection(self.db) - def _utf8(self, txt): - if isinstance(txt, unicode): - return txt.encode("utf8") - return txt - # Schema upgrade ###################################################################### diff --git a/anki/utils.py b/anki/utils.py index 3c4ae3fa8..05d44c4e8 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -245,7 +245,7 @@ def tmpdir(): shutil.rmtree(_tmpdir) import atexit atexit.register(cleanup) - _tmpdir = os.path.join(tempfile.gettempdir(), "anki_temp") + _tmpdir = unicode(os.path.join(tempfile.gettempdir(), "anki_temp"), sys.getfilesystemencoding()) if not os.path.exists(_tmpdir): os.mkdir(_tmpdir) return _tmpdir @@ -253,7 +253,7 @@ def tmpdir(): def tmpfile(prefix="", suffix=""): (fd, name) = tempfile.mkstemp(dir=tmpdir(), prefix=prefix, suffix=suffix) os.close(fd) - return unicode(name, sys.getfilesystemencoding()) + return name def namedtmp(name, rm=True): "Return tmpdir+name. Deletes any existing file."