mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Merge branch 'master' of https://github.com/dae/anki
This commit is contained in:
commit
69d7e10e7d
4 changed files with 72 additions and 67 deletions
|
@ -30,6 +30,6 @@ if arch[1] == "ELF":
|
||||||
sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % (
|
sys.path.insert(0, os.path.join(ext, "py2.%d-%s" % (
|
||||||
sys.version_info[1], arch[0][0:2])))
|
sys.version_info[1], arch[0][0:2])))
|
||||||
|
|
||||||
version="2.0.16" # build scripts grep this line, so preserve formatting
|
version="2.0.17" # build scripts grep this line, so preserve formatting
|
||||||
from anki.storage import Collection
|
from anki.storage import Collection
|
||||||
__all__ = ["Collection"]
|
__all__ = ["Collection"]
|
||||||
|
|
|
@ -3,12 +3,24 @@
|
||||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
import re, os, random, time, math, htmlentitydefs, subprocess, \
|
import re
|
||||||
tempfile, shutil, string, httplib2, sys, locale
|
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 hashlib import sha1
|
||||||
from anki.lang import _, ngettext
|
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
|
from anki.lang import _, ngettext
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[1] < 5:
|
if sys.version_info[1] < 5:
|
||||||
def format_string(a, b):
|
def format_string(a, b):
|
||||||
return a % b
|
return a % b
|
||||||
|
@ -16,6 +28,14 @@ if sys.version_info[1] < 5:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import simplejson as json
|
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:
|
except ImportError:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,8 @@ you can enter it here. Use \\t to represent tab."""),
|
||||||
err = repr(str(e))
|
err = repr(str(e))
|
||||||
if "1-character string" in err:
|
if "1-character string" in err:
|
||||||
msg += err
|
msg += err
|
||||||
|
elif "invalidTempFolder" in err:
|
||||||
|
msg += self.mw.errorHandler.tempFolderMsg()
|
||||||
else:
|
else:
|
||||||
msg += unicode(traceback.format_exc(), "ascii", "replace")
|
msg += unicode(traceback.format_exc(), "ascii", "replace")
|
||||||
showText(msg)
|
showText(msg)
|
||||||
|
|
109
aqt/sync.py
109
aqt/sync.py
|
@ -449,70 +449,53 @@ httplib.HTTPConnection.send = _incrementalSend
|
||||||
|
|
||||||
# receiving in httplib2
|
# receiving in httplib2
|
||||||
def _conn_request(self, conn, request_uri, method, body, headers):
|
def _conn_request(self, conn, request_uri, method, body, headers):
|
||||||
for i in range(httplib2.RETRIES):
|
try:
|
||||||
try:
|
if conn.sock is None:
|
||||||
if conn.sock is None:
|
conn.connect()
|
||||||
conn.connect()
|
conn.request(method, request_uri, body, headers)
|
||||||
conn.request(method, request_uri, body, headers)
|
except socket.timeout:
|
||||||
except socket.timeout:
|
raise
|
||||||
raise
|
except socket.gaierror:
|
||||||
except socket.gaierror:
|
conn.close()
|
||||||
conn.close()
|
raise httplib2.ServerNotFoundError(
|
||||||
raise httplib2.ServerNotFoundError(
|
"Unable to find the server at %s" % conn.host)
|
||||||
"Unable to find the server at %s" % conn.host)
|
except httplib2.ssl_SSLError:
|
||||||
except httplib2.ssl_SSLError:
|
conn.close()
|
||||||
conn.close()
|
raise
|
||||||
raise
|
except socket.error, e:
|
||||||
except socket.error, e:
|
err = 0
|
||||||
err = 0
|
if hasattr(e, 'args'):
|
||||||
if hasattr(e, 'args'):
|
err = getattr(e, 'args')[0]
|
||||||
err = getattr(e, 'args')[0]
|
|
||||||
else:
|
|
||||||
err = e.errno
|
|
||||||
if err == errno.ECONNREFUSED: # Connection refused
|
|
||||||
raise
|
|
||||||
except httplib.HTTPException:
|
|
||||||
# Just because the server closed the connection doesn't apparently mean
|
|
||||||
# that the server didn't send a response.
|
|
||||||
if conn.sock is None:
|
|
||||||
if i == 0:
|
|
||||||
conn.close()
|
|
||||||
conn.connect()
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
conn.close()
|
|
||||||
raise
|
|
||||||
if i == 0:
|
|
||||||
conn.close()
|
|
||||||
conn.connect()
|
|
||||||
continue
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
response = conn.getresponse()
|
|
||||||
except (socket.error, httplib.HTTPException):
|
|
||||||
if i == 0:
|
|
||||||
conn.close()
|
|
||||||
conn.connect()
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
else:
|
else:
|
||||||
content = ""
|
err = e.errno
|
||||||
if method == "HEAD":
|
if err == errno.ECONNREFUSED: # Connection refused
|
||||||
response.close()
|
raise
|
||||||
else:
|
except httplib.HTTPException:
|
||||||
buf = StringIO()
|
# Just because the server closed the connection doesn't apparently mean
|
||||||
while 1:
|
# that the server didn't send a response.
|
||||||
data = response.read(CHUNK_SIZE)
|
if conn.sock is None:
|
||||||
if not data:
|
conn.close()
|
||||||
break
|
raise
|
||||||
buf.write(data)
|
try:
|
||||||
runHook("httpRecv", len(data))
|
response = conn.getresponse()
|
||||||
content = buf.getvalue()
|
except (socket.error, httplib.HTTPException):
|
||||||
response = httplib2.Response(response)
|
raise
|
||||||
if method != "HEAD":
|
else:
|
||||||
content = httplib2._decompressContent(response, content)
|
content = ""
|
||||||
break
|
if method == "HEAD":
|
||||||
|
response.close()
|
||||||
|
else:
|
||||||
|
buf = StringIO()
|
||||||
|
while 1:
|
||||||
|
data = response.read(CHUNK_SIZE)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
buf.write(data)
|
||||||
|
runHook("httpRecv", len(data))
|
||||||
|
content = buf.getvalue()
|
||||||
|
response = httplib2.Response(response)
|
||||||
|
if method != "HEAD":
|
||||||
|
content = httplib2._decompressContent(response, content)
|
||||||
return (response, content)
|
return (response, content)
|
||||||
|
|
||||||
httplib2.Http._conn_request = _conn_request
|
httplib2.Http._conn_request = _conn_request
|
||||||
|
|
Loading…
Reference in a new issue