def thread_do(self): self.response = urllib.request.urlopen(self.uri) def url_name(url): return os.path.basename(url.rstrip("/")) def header_name(headers): content_disp = headers.get("Content-Disposition", "") for part in content_disp.split(";"): if part.strip().lower().startswith("filename="): return part.split("=", 1)[-1] return content_disp destname = (header_name(self.response.headers) or url_name(self.response.url)) if self.use_tempfile: (self.destfile, self.destpath) = utils.get_safe_tempfile() else: (self.destfile, self.destpath) = \ utils.get_destfile_in_directory(self.destdir, destname) try: if not self.destfile: raise IOError("Could not write output file") shutil.copyfileobj(self.response, self.destfile) finally: self.destfile.close() self.response.close()
def activate(self, leaf): finput = open(leaf.object, "rb") (foutput, fpath) = utils.get_safe_tempfile() try: docutils.core.publish_file(finput, destination=foutput, writer_name="html") finally: finput.close() foutput.close() utils.show_path(fpath)
def activate(self, obj, iobj, ctx): tmpf, tmpname = utils.get_safe_tempfile() tmpf.write(kupferstring.tolocale(obj.object)) tmpf.close() vim_cmd = "r %s" % tmpname glib.timeout_add_seconds(10, os.unlink, tmpname) def error_handler(exc): ctx.register_late_error(OperationError(exc)) proxy_obj = get_plugin_service_obj(PLUGID) if proxy_obj: proxy_obj.SendEx(iobj.serverid, vim_cmd, reply_handler=_dummy_handler, error_handler=error_handler)