httplib2 und callback

Sockets, TCP/IP, (XML-)RPC und ähnliche Themen gehören in dieses Forum
Antworten
Herr Lehmann
User
Beiträge: 81
Registriert: Samstag 14. August 2010, 22:20

Hallo,

ich möchte große Dateien von einem Webdav server laden.

Als library benutze ich python-webdav.

Diese funktioniert auch soweit tadellos, da ich allerdings relativ große Dateien abrufen möchte wäre ein Download mit Chunks (Callback) sehr wünscheswert.
Das wird auch im Quellcode erwähnt aber ist noch nicht implementiert:

Code: Alles auswählen

def send_get(self, path, headers=None, callback=False):
 	""" Send a GET request
 	NOTE: callback is not yet implimented. It's purpose is to allow
 	the user to specify a callback so that when x percent of the file
 	has been retrieved, the callback will be executed. This makes
 	allowances for users who may require a progress to be kept track of.
 	
 	:param path: The path (without host) to the resource to get
 	:type path: String
 	
 	:param headers: Additional headers for the request should be added here
 	:type headers: Dict
 	
 	:param callback: Not yet implimented. This will allow a callback to
	be added to the method. This is for such uses as
 	keeping track ofupload progress.
 	:type callback: Method or Function
 	
 	"""
 	if not headers:
 	headers = {}
 	
 	try:
 	resp, content = self._send_request('GET', path, headers=headers,
	callback=callback)
 	return resp, content
 	except httplib2.ServerNotFoundError:
 	raise
hier die send_request Funktion:

Code: Alles auswählen

def _send_request(self, request_method, path, body='', headers=None,
 	callback=None):
 	""" Send a request over http to the webdav server
 	
 	:param request_method: HTML / WebDAV request method
 	(such as GET or PUT)
 	:type request_method: String
 	
 	:param path: The path (without host) to the target of the request
 	:type path: String
 	
 	:param body: Keyword argument. The body of the request method
 	:type body: String
 	
 	:param headers: Keyword argument. This is where additional headers
 	for the request can be added
 	:type headers: Dict
 	
 	"""
 	if not headers:
 	headers = {}
 	uri = httplib2.urlparse.urljoin(self.host, path)
 	try:
 	resp, content = self.httpcon.request(uri, request_method,
 	body=body, headers=headers)
 	except httplib2.ServerNotFoundError:
 	raise
return resp, content

httpcon kommt von

Code: Alles auswählen

self.httpcon = httplib2.Http()
Als ich dann versucht habe selber diesen callback zu implementieren musste ich feststellen, das die httplib2 soetwas garnicht vorsieht.

Jemand eine Idee wie ich das in die bestehende Library implementieren könnte ohne was komplett neues zu versuchen (z.b. mit urllib)
Antworten