mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -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.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
|
||||
__all__ = ["Collection"]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -167,6 +167,8 @@ you can enter it here. Use \\t to represent tab."""),
|
|||
err = repr(str(e))
|
||||
if "1-character string" in err:
|
||||
msg += err
|
||||
elif "invalidTempFolder" in err:
|
||||
msg += self.mw.errorHandler.tempFolderMsg()
|
||||
else:
|
||||
msg += unicode(traceback.format_exc(), "ascii", "replace")
|
||||
showText(msg)
|
||||
|
|
109
aqt/sync.py
109
aqt/sync.py
|
@ -449,70 +449,53 @@ httplib.HTTPConnection.send = _incrementalSend
|
|||
|
||||
# receiving in httplib2
|
||||
def _conn_request(self, conn, request_uri, method, body, headers):
|
||||
for i in range(httplib2.RETRIES):
|
||||
try:
|
||||
if conn.sock is None:
|
||||
conn.connect()
|
||||
conn.request(method, request_uri, body, headers)
|
||||
except socket.timeout:
|
||||
raise
|
||||
except socket.gaierror:
|
||||
conn.close()
|
||||
raise httplib2.ServerNotFoundError(
|
||||
"Unable to find the server at %s" % conn.host)
|
||||
except httplib2.ssl_SSLError:
|
||||
conn.close()
|
||||
raise
|
||||
except socket.error, e:
|
||||
err = 0
|
||||
if hasattr(e, 'args'):
|
||||
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
|
||||
try:
|
||||
if conn.sock is None:
|
||||
conn.connect()
|
||||
conn.request(method, request_uri, body, headers)
|
||||
except socket.timeout:
|
||||
raise
|
||||
except socket.gaierror:
|
||||
conn.close()
|
||||
raise httplib2.ServerNotFoundError(
|
||||
"Unable to find the server at %s" % conn.host)
|
||||
except httplib2.ssl_SSLError:
|
||||
conn.close()
|
||||
raise
|
||||
except socket.error, e:
|
||||
err = 0
|
||||
if hasattr(e, 'args'):
|
||||
err = getattr(e, 'args')[0]
|
||||
else:
|
||||
content = ""
|
||||
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)
|
||||
break
|
||||
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:
|
||||
conn.close()
|
||||
raise
|
||||
try:
|
||||
response = conn.getresponse()
|
||||
except (socket.error, httplib.HTTPException):
|
||||
raise
|
||||
else:
|
||||
content = ""
|
||||
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)
|
||||
|
||||
httplib2.Http._conn_request = _conn_request
|
||||
|
|
Loading…
Reference in a new issue