deluge.httpdownloader

deluge.httpdownloader.download_file(url, filename, callback=None, headers=None, force_filename=False, allow_compression=True)

Downloads a file from a specific URL and returns a Deferred. You can also specify a callback function to be called as parts are received.

Parameters:
  • url (string) – the url to download from
  • filename (string) – the filename to save the file as
  • callback (function) – a function to be called when a part of data is received, it’s signature should be: func(data, current_length, total_length)
  • headers (dictionary) – any optional headers to send
  • force_filename (boolean) – force us to use the filename specified rather than one the server may suggest
  • allow_compression (boolean) – allows gzip & deflate decoding
Returns:

the filename of the downloaded file

Return type:

Deferred

Raises t.w.e.PageRedirect:
 

when server responds with a temporary redirect or permanently moved.

Raises t.w.e.Error:
 

for all other HTTP response errors (besides OK)

deluge.httpdownloader.sanitise_filename(filename)

Sanitises a filename to use as a download destination file. Logs any filenames that could be considered malicious.

Parameter:filename (string) – the filename to sanitise
Returns:the sanitised filename
Return type:string
Raises IOError:when the filename exists

Previous topic

deluge.event

Next topic

deluge.log

This Page