diff --git a/anki/utils.py b/anki/utils.py index 0eeb3dfdd..06be1de67 100644 --- a/anki/utils.py +++ b/anki/utils.py @@ -3,12 +3,24 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from __future__ import division -import re, os, random, time, math, htmlentitydefs, subprocess, \ - tempfile, shutil, string, httplib2, sys, locale +import re +import os +import random +import time +import math +import htmlentitydefs +import subprocess +import tempfile +import shutil +import string +import sys +import locale from hashlib import sha1 -from anki.lang import _, ngettext import platform +from anki.lang import _, ngettext + + if sys.version_info[1] < 5: def format_string(a, b): return a % b @@ -16,6 +28,14 @@ if sys.version_info[1] < 5: try: import simplejson as json + # make sure simplejson's loads() always returns unicode + # we don't try to support .load() + origLoads = json.loads + def loads(s, *args, **kwargs): + if not isinstance(s, unicode): + s = unicode(s, "utf8") + return origLoads(s, *args, **kwargs) + json.loads = loads except ImportError: import json