Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- # # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with # the additional special exception to link portions of this program with the OpenSSL library. # See LICENSE for more details. #
""" Factory class for downloading files and keeping track of progress. """ force_filename=False, allow_compression=True): """ :param url: the url to download from :type url: string :param filename: the filename to save the file as :type filename: string :param force_filename: forces use of the supplied filename, regardless of header content :type force_filename: bool :param part_callback: a function to be called when a part of data is received, it's signature should be: func(data, current_length, total_length) :type part_callback: function :param headers: any optional headers to send :type headers: dictionary """
else:
headers["content-encoding"][0] in ("gzip", "x-gzip", "deflate"): # Adding 32 to the wbits enables gzip & zlib decoding (with automatic header detection) # Adding 16 just enables gzip decoding (no zlib)
# Increment filename if already exists
self.part_callback(data, self.current_length, self.total_length)
""" Sanitises a filename to use as a download destination file. Logs any filenames that could be considered malicious.
:param filename: the filename to sanitise :type filename: string :returns: the sanitised filename :rtype: string """
# Remove any quotes
# Dodgy server, log it # Only use the basename
# Dodgy server, log it log.warning("Potentially malicious server: trying to write to file '%s'" % filename)
""" 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.
:param url: the url to download from :type url: string :param filename: the filename to save the file as :type filename: string :param callback: a function to be called when a part of data is received, it's signature should be: func(data, current_length, total_length) :type callback: function :param headers: any optional headers to send :type headers: dictionary :param force_filename: force us to use the filename specified rather than one the server may suggest :type force_filename: boolean :param allow_compression: allows gzip & deflate decoding :type allow_compression: boolean
:returns: the filename of the downloaded file :rtype: 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) """
# In twisted 13.1.0 the _parse() function was replaced by the _URI class scheme, host, port, path = client._parse(url) else:
from twisted.internet import ssl reactor.connectSSL(host, port, factory, ssl.ClientContextFactory()) else:
|