def _get_md5_and_file_size_via_url(self, error_log, url, file_info, callback_function=None, *args): if not isinstance(url, (str, unicode)): raise ValueError("Url must be in string form ") try: remote = urllib2.urlopen(url) except urllib2.HTTPError as error: umbrella_error = UmbrellaError( error_code=BAD_URL_ERROR_CODE, description="Http error \"" + str(error) + '"', may_be_temporary=True, component_name=str(file_info[COMPONENT_NAME]), file_name=str(file_info[FILE_NAME]), url=str(url) ) error_log.append(umbrella_error) return None, None except urllib2.URLError as error: umbrella_error = UmbrellaError( error_code=BAD_URL_ERROR_CODE, description="Url error \"" + str(error) + '"', may_be_temporary=True, component_name=str(file_info[COMPONENT_NAME]), file_name=str(file_info[FILE_NAME]), url=str(url) ) error_log.append(umbrella_error) return None, None # Get the file_size from the website. Some websites (old ones) may not give this information try: file_size_from_url = int(remote.headers["content-length"]) except KeyError: file_size_from_url = None return get_md5_and_file_size(remote, file_size_from_url, callback_function, *args)
def _get_md5_and_file_size_via_file(self, the_file, actual_file_size, callback_function=None, *args): if not hasattr(the_file, "read"): raise ValueError("the_file must be an open file ") return get_md5_and_file_size(the_file, actual_file_size, callback_function, *args)