mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
further simplify augmented httplib2 conn_request
This commit is contained in:
parent
927e618f53
commit
9c678c32ad
1 changed files with 8 additions and 13 deletions
15
aqt/sync.py
15
aqt/sync.py
|
@ -421,7 +421,7 @@ class SyncThread(QThread):
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
CHUNK_SIZE = 65536
|
CHUNK_SIZE = 65536
|
||||||
import httplib, httplib2, errno
|
import httplib, httplib2
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
from anki.hooks import runHook
|
from anki.hooks import runHook
|
||||||
|
|
||||||
|
@ -448,6 +448,9 @@ def _incrementalSend(self, data):
|
||||||
httplib.HTTPConnection.send = _incrementalSend
|
httplib.HTTPConnection.send = _incrementalSend
|
||||||
|
|
||||||
# receiving in httplib2
|
# receiving in httplib2
|
||||||
|
# this is an augmented version of httplib's request routine that:
|
||||||
|
# - doesn't assume requests will be tried more than once
|
||||||
|
# - calls a hook for each chunk of data so we can update the gui
|
||||||
def _conn_request(self, conn, request_uri, method, body, headers):
|
def _conn_request(self, conn, request_uri, method, body, headers):
|
||||||
try:
|
try:
|
||||||
if conn.sock is None:
|
if conn.sock is None:
|
||||||
|
@ -463,17 +466,9 @@ def _conn_request(self, conn, request_uri, method, body, headers):
|
||||||
conn.close()
|
conn.close()
|
||||||
raise
|
raise
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
err = 0
|
conn.close()
|
||||||
if hasattr(e, 'args'):
|
|
||||||
err = getattr(e, 'args')[0]
|
|
||||||
else:
|
|
||||||
err = e.errno
|
|
||||||
if err == errno.ECONNREFUSED: # Connection refused
|
|
||||||
raise
|
raise
|
||||||
except httplib.HTTPException:
|
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()
|
conn.close()
|
||||||
raise
|
raise
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue