def __init__(self, *args, **kwargs): # We'll append the filename to one of the provided urls # to create the download link try: self.filename = args[0] except IndexError: raise FileDownloaderError('No filename provided', expected=True) try: self.urls = args[1] except IndexError: raise FileDownloaderError('No urls provided', expected=True) # User may have accidently passed a string to # the urls para if isinstance(self.urls, list) is False: raise FileDownloaderError('Must pass list of urls', expected=True) try: self.hexdigest = args[2] except IndexError: self.hexdigest = kwargs.get('hexdigest') self.verify = kwargs.get('verify', True) self.progress_hooks = kwargs.get('progress_hooks', []) # End of user configurable options self.b_size = 4096 * 4 self.file_binary_data = None self.my_file = BytesIO() self.content_length = None if self.verify is True: self.http_pool = get_http_pool() else: self.http_pool = get_http_pool(secure=False)
def __init__(self, filename, urls, hexdigest=None, verify=True, progress_hooks=None): self.filename = filename if isinstance(urls, list) is False: self.urls = [urls] else: self.urls = urls self.hexdigest = hexdigest self.verify = verify self.b_size = 4096 * 4 self.file_binary_data = None self.my_file = BytesIO() self.content_length = None if progress_hooks is None: progress_hooks = [] self.progress_hooks = progress_hooks if self.verify is True: self.http_pool = get_http_pool() else: self.http_pool = get_http_pool(secure=False)
def __init__(self, *args, **kwargs): # We'll append the filename to one of the provided urls # to create the download link try: self.filename = args[0] except IndexError: raise FileDownloaderError('No filename provided', expected=True) try: self.urls = args[1] except IndexError: raise FileDownloaderError('No urls provided', expected=True) # User may have accidentally passed a # string to the urls parameter if isinstance(self.urls, list) is False: raise FileDownloaderError('Must pass list of urls', expected=True) try: self.hexdigest = args[2] except IndexError: self.hexdigest = kwargs.get('hexdigest') # Specify if we want to verify TLS connections self.verify = kwargs.get('verify', True) # Progress hooks to be called self.progress_hooks = kwargs.get('progress_hooks', []) # Initial block size for each read self.block_size = 4096 * 4 self.file_binary_data = None self.my_file = BytesIO() self.content_length = None if self.verify is True: self.http_pool = get_http_pool() else: self.http_pool = get_http_pool(secure=False)
def _upload(data): api = 'https://api.github.com/' gist_url = api + 'gists' http = get_http_pool() headers = {"Accept": "application/vnd.github.v3+json"} r = http.request('POST', gist_url, headers=headers, data=json.dumps(data)) try: r_string = r.read() data = json.loads(r_string) url = data['html_url'] except Exception as err: log.debug(err, exc_info=True) log.debug(json.dumps(r.json(), indent=2)) url = None return url
def _upload(data): api = "https://api.github.com/" gist_url = api + "gists" http = get_http_pool() headers = { "Accept": "application/vnd.github.v3+json", "User-Agent": "PyUpdater", } r = http.urlopen("POST", gist_url, headers=headers, body=json.dumps(data)) try: data = json.loads(r.data) url = data["html_url"] except Exception as err: log.debug(err, exc_info=True) log.debug(json.dumps(r.data, indent=2)) url = None return url
def _upload(data): api = 'https://api.github.com/' gist_url = api + 'gists' http = get_http_pool() headers = { "Accept": "application/vnd.github.v3+json", "User-Agent": "PyUpdater", } r = http.urlopen('POST', gist_url, headers=headers, body=json.dumps(data)) try: data = json.loads(r.data) url = data['html_url'] except Exception as err: log.debug(err, exc_info=True) log.debug(json.dumps(r.data, indent=2)) url = None return url