def downloadFile(self): url = QUrl(self.url_to_download) fileName = QFileDialog.getSaveFileName(self, "Enregistrer la liste des dossiers", self.nameFile, "conf") if QFile.exists(fileName): QFile.remove(fileName) self.outFile = QFile(fileName) if not self.outFile.open(QIODevice.WriteOnly): QMessageBox.information(self, 'Erreur','Impossible d\'enregistrer le fichier %s: %s.' % (fileName, self.outFile.errorString())) self.outFile = None return #Création que la connexion HTTPS mode = QHttp.ConnectionModeHttps port = 0 self.http.setHost(url.host(), mode, port) self.requeteHTTPannule = False path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/") if path: path = str(path) else: path = '/' #Concaténation des paramètres à l'URL path = path+("?") for item in url.queryItems(): path = path + item[0] + "=" + item[1] + "&" self.http.setUser(self.login, self.password) self.httpGetId = self.http.get(path, self.outFile)
def data(self): """Return all the data for this model (including dependencies) in a structured dict """ empty_template = '{}' param_map = {PATH: 'Path', GET: 'GET', POST: 'POST', COOKIE: 'Cookie'} url = QUrl(self.transition.url) path_dict = path_to_dict(url.path()) get_keys, post_keys = set(), set() output = {} if self.override: output['variables'] = [] for param_type, key, template, parent_model in self.override: parent = parent_model if isinstance( parent_model, basestring) else parent_model.data() output['variables'].append({ 'key': key, 'origin': param_map[param_type], 'source': parent, 'template': template, }) if param_type == PATH: path_dict[key] = empty_template elif param_type == GET: get_keys.add(key) elif param_type == POST: post_keys.add(key) url.setPath(dict_to_path(path_dict)) qs_items = [(key, empty_template if key in get_keys else value) for (key, value) in url.queryItems() if (GET, key) not in self.ignored] url.setEncodedQueryItems(qs_items) output['url'] = url.toString() data = dict([(key, empty_template if key in post_keys else value) for (key, value) in self.transition.data if (POST, key) not in self.ignored]) if data: output['data'] = data #if self.ignored: # output['ignored'] = [(param_map[param_type], value) for (param_type, value) in self.ignored] if self.selector is not None: output['columns'] = {'data': str(self.selector)} elif self.columns is not None: output['columns'] = { field: str(selector) for (field, selector) in self.columns.items() } output['headers'] = [(str(key), str(value)) for (key, value) in self.transition.request_headers if str(key).lower() not in ('content-length', )] output['verb'] = self.transition.verb return output
def parse_data(self, data): """Parse this posted data into a list of key/value pairs """ if data is None: result = [] else: try: result = json.loads(unicode(data)) if isinstance(result, dict): result = result.items() if not isinstance(result, list): common.logger.info( u'Unexpected data format: {}'.format(result)) result = [] except ValueError: url = QUrl('') url.setEncodedQuery(data) result = url.queryItems() return result