make sure we feed sqlite utf8, and use unicode for tmp filenames

This commit is contained in:
Damien Elmes 2012-07-19 15:34:19 +09:00
parent 9d153313e5
commit 5ddc4c639e
2 changed files with 4 additions and 3 deletions

View file

@ -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

View file

@ -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."