core.download module¶
Background download management.
- class core.download.DownloadQueue(name)[source]¶
Bases:
object
Queue used for downloading files.
- add(url, target, end_callback)[source]¶
Adds a download to the queue.
- Parameters:
url – the URL to download.
target – the target path for the download.
end_callback – a function(url, filename, success) which is called when the download finishes.
- register_begin_download(func)[source]¶
Registers a function func(queue_name, url) to be called when a download is started.
- register_end_download(func)[source]¶
Registers a function func(queue_name, url, filename, success) to be called when a download is finished.
- register_end_queue(func)[source]¶
Registers a function func(queue_name) to be called when the queue is emptied.
- register_progress(func)[source]¶
Registers a function func(queue_name, url, downloaded, total_size) to be called for download progress reports. If total size is unknown, None will be sent.
- register_start_queue(func)[source]¶
Registers a function func(queue_name) to be called when the queue is started. If False is returned by any function, the queue is cleared.
- unregister_begin_download(func)[source]¶
Unregisters a function func from being called when a download is started.
- unregister_end_download(func)[source]¶
Unregisters a function func from being called when a download is finished.
- unregister_end_queue(func)[source]¶
Unregisters a function func from being called when the queue is emptied.
- core.download.download(queue, url, destination, end_callback=None, **kwargs)[source]¶
Adds a download to the specified queue.
- core.download.download_str(url, **kwargs)[source]¶
Instantly download a file from <url> and return its contents. Failed downloads return None. NOTE: This is a blocking method. Use a download queue for non-blocking downloads.
- Parameters:
url – the URL to download
encoding – used to decode the data to text. Defaults to UTF-8.
timeout – timeout used for the URL request, in seconds. Defaults to 3.
- Returns:
The contents of the downloaded file as text, or None.