def _write_tempfile(self, fileName=None, encoding="utf-8"): if fileName is None: fd, fileName = tempfile.mkstemp(".svg", "svgfig-") os.close(fd) else: fileName = defaults._expand_fileName(fileName) self.save(fileName, encoding) return fileName
def save(self, fileName, encoding="utf-8", compresslevel=None): fileName = defaults._expand_fileName(fileName) if compresslevel is not None or re.search(r"\.svgz$", fileName, re.I) or re.search(r"\.gz$", fileName, re.I): import gzip if compresslevel is None: f = gzip.GzipFile(fileName, "w") else: f = gzip.GzipFile(fileName, "w", compresslevel) f = codecs.EncodedFile(f, "utf-16", encoding) f.write(self.xml()) f.close() else: f = codecs.open(fileName, "w", encoding=encoding) f.write(self.xml()) f.close() saved.append(fileName)