From 5ddc4c639e1b8170be320d0e6152a17ac62b1d9f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 19 Jul 2012 15:34:19 +0900 Subject: [PATCH] make sure we feed sqlite utf8, and use unicode for tmp filenames --- anki/db.py | 2 ++ anki/utils.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/anki/db.py b/anki/db.py index bd8fc1797..3453ad113 100644 --- a/anki/db.py +++ b/anki/db.py @@ -12,6 +12,8 @@ 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) if text: self._db.text_factory = text diff --git a/anki/utils.py b/anki/utils.py index 69a67cbd6..3c4ae3fa8 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -3,11 +3,10 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import re, os, random, time, types, math, htmlentitydefs, subprocess, \ - tempfile, shutil, string, httplib2 + tempfile, shutil, string, httplib2, sys, locale from hashlib import sha1 from anki.lang import _, ngettext from anki.consts import * -import locale, sys if sys.version_info[1] < 5: def format_string(a, b): @@ -254,7 +253,7 @@ def tmpdir(): def tmpfile(prefix="", suffix=""): (fd, name) = tempfile.mkstemp(dir=tmpdir(), prefix=prefix, suffix=suffix) os.close(fd) - return name + return unicode(name, sys.getfilesystemencoding()) def namedtmp(name, rm=True): "Return tmpdir+name. Deletes any existing file."