From 4133e62087993c7bb3ecb2d555b28c61b196e841 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Wobst?= Date: Mon, 22 May 2006 17:05:20 +0000 Subject: [PATCH] allow file instances as paramter of the writeXXXfile methods git-svn-id: https://pyx.svn.sourceforge.net/svnroot/pyx/trunk/pyx@2779 069f4177-920e-0410-937b-c2a4a81bcd90 --- CHANGES | 2 ++ pyx/pdfwriter.py | 15 ++++++++++----- pyx/pswriter.py | 33 ++++++++++++++++++++++----------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 2a7f3bff..2be50d72 100644 --- a/CHANGES +++ b/CHANGES @@ -175,6 +175,8 @@ TODO: - move bbox handling to registry - rename outputPS/outputPDF -> processPS/processPDF - remove set method of canvas + - canvas and document modules: + - allow file instances as paramter of the writeXXXfile methods (feature request #1419658 by Jason Pratt) - style module: - make rellength the default for dash styles - random notes: diff --git a/pyx/pdfwriter.py b/pyx/pdfwriter.py index c11e8bad..43d4af51 100644 --- a/pyx/pdfwriter.py +++ b/pyx/pdfwriter.py @@ -438,12 +438,17 @@ class PDFwriter: def __init__(self, document, filename, title=None, author=None, subject=None, keywords=None, fullscreen=0, writebbox=0, compress=1, compresslevel=6): - if not filename.endswith(".pdf"): - filename = filename + ".pdf" try: - file = open(filename, "wb") - except IOError: - raise IOError("cannot open output file") + filename.write("") + except: + if not filename.endswith(".pdf"): + filename = filename + ".pdf" + try: + file = open(filename, "wb") + except IOError: + raise IOError("cannot open output file") + else: + file = filename self.title = title self.author = author diff --git a/pyx/pswriter.py b/pyx/pswriter.py index 6fb2e750..56e3a099 100644 --- a/pyx/pswriter.py +++ b/pyx/pswriter.py @@ -248,12 +248,18 @@ class epswriter: page = document.pages[0] canvas = page.canvas - if not filename.endswith(".eps"): - filename = filename + ".eps" try: - file = open(filename, "w") - except IOError: - raise IOError("cannot open output file") + filename.write("") + except: + if not filename.endswith(".eps"): + filename = filename + ".eps" + try: + file = open(filename, "w") + except IOError: + raise IOError("cannot open output file") + else: + file = filename + filename = "stream" pagefile = cStringIO.StringIO() registry = PSregistry() @@ -287,13 +293,18 @@ class epswriter: class pswriter: def __init__(self, document, filename, writebbox=0): - if not filename.endswith(".ps"): - filename = filename + ".ps" try: - file = open(filename, "w") - except IOError: - raise IOError("cannot open output file") - + filename.write("") + except: + if not filename.endswith(".ps"): + filename = filename + ".ps" + try: + file = open(filename, "w") + except IOError: + raise IOError("cannot open output file") + else: + file = filename + filename = "stream" # We first have to process the content of the pages, writing them into the stream pagesfile # Doing so, we fill the registry and also calculate the page bounding boxes, which are -- 2.11.4.GIT