Example #1
0
    def print_svg(self, filename, *args, **kwargs):
        if is_string_like(filename):
            with io.open(filename, 'w', encoding='utf-8') as svgwriter:
                return self._print_svg(filename, svgwriter, **kwargs)

        if not is_writable_file_like(filename):
            raise ValueError("filename must be a path or a file-like object")

        svgwriter = filename
        filename = getattr(svgwriter, 'name', '')
        if not isinstance(filename, six.string_types):
            filename = ''

        if not isinstance(svgwriter, io.TextIOBase):
            if six.PY3:
                svgwriter = io.TextIOWrapper(svgwriter, 'utf-8')
            else:
                svgwriter = codecs.getwriter('utf-8')(svgwriter)
            detach = True
        else:
            detach = False

        result = self._print_svg(filename, svgwriter, **kwargs)

        # Detach underlying stream from wrapper so that it remains open in the
        # caller.
        if detach:
            if six.PY3:
                svgwriter.detach()
            else:
                svgwriter.reset()
                svgwriter.stream = io.BytesIO()

        return result
    def _print_image(self, filename, format):
        if self.flags() & gtk.REALIZED == 0:
            # for self.window(for pixmap) and has a side effect of altering
            # figure width,height (via configure-event?)
            gtk.DrawingArea.realize(self)

        width, height = self.get_width_height()
        pixmap = gdk.Pixmap (self.window, width, height)
        self._renderer.set_pixmap (pixmap)
        self._render_figure(pixmap, width, height)

        # jpg colors don't match the display very well, png colors match
        # better
        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, 0, 8, width, height)
        pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
                                     0, 0, 0, 0, width, height)

        if is_string_like(filename):
            try:
                pixbuf.save(filename, format)
            except gobject.GError as exc:
                error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
        elif is_writable_file_like(filename):
            if hasattr(pixbuf, 'save_to_callback'):
                def save_callback(buf, data=None):
                    data.write(buf)
                try:
                    pixbuf.save_to_callback(save_callback, format, user_data=filename)
                except gobject.GError as exc:
                    error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
            else:
                raise ValueError("Saving to a Python file-like object is only supported by PyGTK >= 2.8")
        else:
            raise ValueError("filename must be a path or a file-like object")
Example #3
0
 def print_svg(self, filename, *args, **kwargs):
     if is_string_like(filename):
         fh_to_close = svgwriter = codecs.open(filename, "w", "utf-8")
     elif is_writable_file_like(filename):
         svgwriter = codecs.EncodedFile(filename, "utf-8")
         fh_to_close = None
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close)
Example #4
0
 def print_svg(self, filename, *args, **kwargs):
     if is_string_like(filename):
         fh_to_close = svgwriter = io.open(filename, 'w', encoding='utf-8')
     elif is_writable_file_like(filename):
         svgwriter = io.TextIOWrapper(filename, encoding='utf-8')
         fh_to_close = None
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
Example #5
0
 def print_svgz(self, filename, *args, **kwargs):
     if is_string_like(filename):
         fh_to_close = gzipwriter = gzip.GzipFile(filename, 'w')
         svgwriter = io.TextIOWrapper(gzipwriter, 'utf-8')
     elif is_writable_file_like(filename):
         fh_to_close = gzipwriter = gzip.GzipFile(fileobj=filename, mode='w')
         svgwriter = io.TextIOWrapper(gzipwriter, 'utf-8')
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close)
Example #6
0
    def print_svgz(self, filename, *args, **kwargs):
        if is_string_like(filename):
            options = dict(filename=filename)
        elif is_writable_file_like(filename):
            options = dict(fileobj=filename)
        else:
            raise ValueError("filename must be a path or a file-like object")

        with gzip.GzipFile(mode='w', **options) as gzipwriter:
            return self.print_svg(gzipwriter)
Example #7
0
 def print_svgz(self, filename, *args, **kwargs):
     if is_string_like(filename):
         gzipwriter = gzip.GzipFile(filename, "w")
         fh_to_close = svgwriter = codecs.EncodedFile(gzipwriter, "utf-8")
     elif is_writable_file_like(filename):
         fh_to_close = gzipwriter = gzip.GzipFile(fileobj=filename, mode="w")
         svgwriter = codecs.EncodedFile(gzipwriter, "utf-8")
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close)
 def print_png(self, fname_or_fh, *args, **kwargs):
     """
     Use LaTeX to compile a pgf figure to pdf and convert it to png.
     """
     if is_string_like(fname_or_fh):
         with open(fname_or_fh, "wb") as fh:
             self._print_png_to_fh(fh)
     elif is_writable_file_like(fname_or_fh):
         self._print_png_to_fh(fname_or_fh)
     else:
         raise ValueError("filename must be a path or a file-like object")
 def print_pdf(self, fname_or_fh, *args, **kwargs):
     """
     Use LaTeX to compile a Pgf generated figure to PDF.
     """
     # figure out where the pdf is to be written to
     if is_string_like(fname_or_fh):
         with open(fname_or_fh, "wb") as fh:
             self._print_pdf_to_fh(fh)
     elif is_writable_file_like(fname_or_fh):
         self._print_pdf_to_fh(fname_or_fh)
     else:
         raise ValueError("filename must be a path or a file-like object")
Example #10
0
 def print_svg(self, filename, *args, **kwargs):
     if is_string_like(filename):
         fh_to_close = svgwriter = io.open(filename, "w", encoding="utf-8")
     elif is_writable_file_like(filename):
         if not isinstance(filename, io.TextIOBase):
             if sys.version_info[0] >= 3:
                 svgwriter = io.TextIOWrapper(filename, "utf-8")
             else:
                 svgwriter = codecs.getwriter("utf-8")(filename)
         fh_to_close = None
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
Example #11
0
    def print_png(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a pgf figure to pdf and convert it to png.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        if isinstance(fname_or_fh, six.string_types):
            with open(fname_or_fh, "wb") as fh:
                self._print_png_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_png_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object")
Example #12
0
 def print_svg(self, filename, *args, **kwargs):
     if is_string_like(filename):
         fh_to_close = svgwriter = io.open(filename, 'w', encoding='utf-8')
     elif is_writable_file_like(filename):
         if not isinstance(filename, io.TextIOBase):
             if six.PY3:
                 svgwriter = io.TextIOWrapper(filename, 'utf-8')
             else:
                 svgwriter = codecs.getwriter('utf-8')(filename)
         else:
             svgwriter = filename
         fh_to_close = None
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_svg(filename, svgwriter, fh_to_close, **kwargs)
Example #13
0
 def print_ipe(self, filename, *args, **kwargs):
     if isinstance(filename, string_types):
         fh_to_close = ipewriter = io.open(filename, 'w', encoding='utf-8')
     elif is_writable_file_like(filename):
         if not isinstance(filename, io.TextIOBase):
             if sys.version_info[0] >= 3:
                 ipewriter = io.TextIOWrapper(filename, 'utf-8')
             else:
                 ipewriter = codecs.getwriter('utf-8')(filename)
         else:
             ipewriter = filename
         fh_to_close = None
     else:
         raise ValueError("filename must be a path or a file-like object")
     return self._print_ipe(filename, ipewriter, fh_to_close, **kwargs)
Example #14
0
    def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False): return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh)
        elif is_writable_file_like(fname_or_fh):
            raise ValueError("saving pgf to a stream is not supported, " + \
            "consider using the pdf option of the pgf-backend")
        else:
            raise ValueError("filename must be a path")
Example #15
0
    def print_pdf(self, fname_or_fh, *args, **kwargs):
        """
        Use LaTeX to compile a Pgf generated figure to PDF.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pdf is to be written to
        if isinstance(fname_or_fh, six.string_types):
            with open(fname_or_fh, "wb") as fh:
                self._print_pdf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            self._print_pdf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path or a file-like object")
Example #16
0
    def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            fh = codecs.getwriter("utf-8")(fname_or_fh)
            self._print_pgf_to_fh(fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path")
Example #17
0
    def _print_image(self, filename, format, *args, **kwargs):
        if self.flags() & gtk.REALIZED == 0:
            # for self.window(for pixmap) and has a side effect of altering
            # figure width,height (via configure-event?)
            gtk.DrawingArea.realize(self)

        width, height = self.get_width_height()
        pixmap = gdk.Pixmap(self.window, width, height)
        self._renderer.set_pixmap(pixmap)
        self._render_figure(pixmap, width, height)

        # jpg colors don't match the display very well, png colors match
        # better
        pixbuf = gdk.Pixbuf(gdk.COLORSPACE_RGB, 0, 8, width, height)
        pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, width, height)

        # set the default quality, if we are writing a JPEG.
        # http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save
        options = cbook.restrict_dict(kwargs, ["quality"])
        if format in ["jpg", "jpeg"]:
            if "quality" not in options:
                options["quality"] = rcParams["savefig.jpeg_quality"]

            options["quality"] = str(options["quality"])

        if is_string_like(filename):
            try:
                pixbuf.save(filename, format, options=options)
            except gobject.GError as exc:
                error_msg_gtk("Save figure failure:\n%s" % (exc,), parent=self)
        elif is_writable_file_like(filename):
            if hasattr(pixbuf, "save_to_callback"):

                def save_callback(buf, data=None):
                    data.write(buf)

                try:
                    pixbuf.save_to_callback(save_callback, format, user_data=filename, options=options)
                except gobject.GError as exc:
                    error_msg_gtk("Save figure failure:\n%s" % (exc,), parent=self)
            else:
                raise ValueError("Saving to a Python file-like object is only supported by PyGTK >= 2.8")
        else:
            raise ValueError("filename must be a path or a file-like object")
Example #18
0
    def print_pgf(self, fname_or_fh, *args, **kwargs):
        """
        Output pgf commands for drawing the figure so it can be included and
        rendered in latex documents.
        """
        if kwargs.get("dryrun", False):
            self._print_pgf_to_fh(None, *args, **kwargs)
            return

        # figure out where the pgf is to be written to
        if is_string_like(fname_or_fh):
            with codecs.open(fname_or_fh, "w", encoding="utf-8") as fh:
                self._print_pgf_to_fh(fh, *args, **kwargs)
        elif is_writable_file_like(fname_or_fh):
            if not os.path.exists(fname_or_fh.name):
                warnings.warn("streamed pgf-code does not support raster "
                              "graphics, consider using the pgf-to-pdf option",
                              UserWarning)
            self._print_pgf_to_fh(fname_or_fh, *args, **kwargs)
        else:
            raise ValueError("filename must be a path")
Example #19
0
    def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
                      orientation='portrait', isLandscape=False, papertype=None):
        """
        Render the figure to hardcopy.  Set the figure patch face and
        edge colors.  This is useful because some of the GUIs have a
        gray figure face color background and you'll probably want to
        override this on hardcopy

        If outfile is a string, it is interpreted as a file name.
        If the extension matches .ep* write encapsulated postscript,
        otherwise write a stand-alone PostScript file.

        If outfile is a file object, a stand-alone PostScript file is
        written into this file object.
        """
        isEPSF = format == 'eps'
        passed_in_file_object = False
        if is_string_like(outfile):
            title = outfile
            tmpfile = os.path.join(gettempdir(), md5(outfile).hexdigest())
        elif is_writable_file_like(outfile):
            title = None
            tmpfile = os.path.join(gettempdir(), md5(str(hash(outfile))).hexdigest())
            passed_in_file_object = True
        else:
            raise ValueError("outfile must be a path or a file-like object")
        fh = file(tmpfile, 'w')

        # find the appropriate papertype
        width, height = self.figure.get_size_inches()
        if papertype == 'auto':
            if isLandscape: papertype = _get_papertype(height, width)
            else: papertype = _get_papertype(width, height)

        if isLandscape: paperHeight, paperWidth = papersize[papertype]
        else: paperWidth, paperHeight = papersize[papertype]

        if rcParams['ps.usedistiller'] and not papertype == 'auto':
            # distillers will improperly clip eps files if the pagesize is
            # too small
            if width>paperWidth or height>paperHeight:
                if isLandscape:
                    papertype = _get_papertype(height, width)
                    paperHeight, paperWidth = papersize[papertype]
                else:
                    papertype = _get_papertype(width, height)
                    paperWidth, paperHeight = papersize[papertype]

        # center the figure on the paper
        xo = 72*0.5*(paperWidth - width)
        yo = 72*0.5*(paperHeight - height)

        l, b, w, h = self.figure.bbox.bounds
        llx = xo
        lly = yo
        urx = llx + w
        ury = lly + h
        rotation = 0
        if isLandscape:
            llx, lly, urx, ury = lly, llx, ury, urx
            xo, yo = 72*paperHeight - yo, xo
            rotation = 90
        bbox = (llx, lly, urx, ury)

        # generate PostScript code for the figure and store it in a string
        origfacecolor = self.figure.get_facecolor()
        origedgecolor = self.figure.get_edgecolor()
        self.figure.set_facecolor(facecolor)
        self.figure.set_edgecolor(edgecolor)

        self._pswriter = StringIO()
        renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
        self.figure.draw(renderer)

        self.figure.set_facecolor(origfacecolor)
        self.figure.set_edgecolor(origedgecolor)

        # write the PostScript headers
        if isEPSF: print >>fh, "%!PS-Adobe-3.0 EPSF-3.0"
        else: print >>fh, "%!PS-Adobe-3.0"
        if title: print >>fh, "%%Title: "+title
        print >>fh, ("%%Creator: matplotlib version "
                     +__version__+", http://matplotlib.sourceforge.net/")
        print >>fh, "%%CreationDate: "+time.ctime(time.time())
        print >>fh, "%%Orientation: " + orientation
        if not isEPSF: print >>fh, "%%DocumentPaperSizes: "+papertype
        print >>fh, "%%%%BoundingBox: %d %d %d %d" % bbox
        if not isEPSF: print >>fh, "%%Pages: 1"
        print >>fh, "%%EndComments"

        Ndict = len(psDefs)
        print >>fh, "%%BeginProlog"
        if not rcParams['ps.useafm']:
            Ndict += len(renderer.used_characters)
        print >>fh, "/mpldict %d dict def"%Ndict
        print >>fh, "mpldict begin"
        for d in psDefs:
            d=d.strip()
            for l in d.split('\n'):
                print >>fh, l.strip()
        if not rcParams['ps.useafm']:
            for font_filename, chars in renderer.used_characters.values():
                if len(chars):
                    font = FT2Font(font_filename)
                    cmap = font.get_charmap()
                    glyph_ids = []
                    for c in chars:
                        gind = cmap.get(c) or 0
                        glyph_ids.append(gind)
                    # The ttf to ps (subsetting) support doesn't work for
                    # OpenType fonts that are Postscript inside (like the
                    # STIX fonts).  This will simply turn that off to avoid
                    # errors.
                    if is_opentype_cff_font(font_filename):
                        raise RuntimeError("OpenType CFF fonts can not be saved using the internal Postscript backend at this time.\nConsider using the Cairo backend.")
                    else:
                        fonttype = rcParams['ps.fonttype']
                        convert_ttf_to_ps(font_filename, fh, rcParams['ps.fonttype'], glyph_ids)
        print >>fh, "end"
        print >>fh, "%%EndProlog"

        if not isEPSF: print >>fh, "%%Page: 1 1"
        print >>fh, "mpldict begin"
        #print >>fh, "gsave"
        print >>fh, "%s translate"%_nums_to_str(xo, yo)
        if rotation: print >>fh, "%d rotate"%rotation
        print >>fh, "%s clipbox"%_nums_to_str(width*72, height*72, 0, 0)

        # write the figure
        print >>fh, self._pswriter.getvalue()

        # write the trailer
        #print >>fh, "grestore"
        print >>fh, "end"
        print >>fh, "showpage"
        if not isEPSF: print >>fh, "%%EOF"
        fh.close()

        if rcParams['ps.usedistiller'] == 'ghostscript':
            gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
        elif rcParams['ps.usedistiller'] == 'xpdf':
            xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)

        if passed_in_file_object:
            fh = file(tmpfile)
            print >>outfile, fh.read()
        else:
            shutil.move(tmpfile, outfile)
Example #20
0
 def _print_figure(self, outfile, format, dpi=72, facecolor='w', edgecolor='w',
                   orientation='portrait', isLandscape=False, papertype=None,
                   **kwargs):
     """
     Render the figure to hardcopy.  Set the figure patch face and
     edge colors.  This is useful because some of the GUIs have a
     gray figure face color background and you'll probably want to
     override this on hardcopy
     If outfile is a string, it is interpreted as a file name.
     If the extension matches .ep* write encapsulated postscript,
     otherwise write a stand-alone PostScript file.
     If outfile is a file object, a stand-alone PostScript file is
     written into this file object.
     """
     isEPSF = format == 'eps'
     passed_in_file_object = False
     fd, tmpfile = mkstemp()
     if is_string_like(outfile):
         title = outfile
     elif is_writable_file_like(outfile):
         title = None
         passed_in_file_object = True
     else:
         raise ValueError("outfile must be a path or a file-like object")
     os.close(fd)
     fh = file(tmpfile, 'w')
     width, height = self.figure.get_size_inches()
     if papertype == 'auto':
         if isLandscape: papertype = _get_papertype(height, width)
         else: papertype = _get_papertype(width, height)
     if isLandscape: paperHeight, paperWidth = papersize[papertype]
     else: paperWidth, paperHeight = papersize[papertype]
     if rcParams['ps.usedistiller'] and not papertype == 'auto':
         if width>paperWidth or height>paperHeight:
             if isLandscape:
                 papertype = _get_papertype(height, width)
                 paperHeight, paperWidth = papersize[papertype]
             else:
                 papertype = _get_papertype(width, height)
                 paperWidth, paperHeight = papersize[papertype]
     xo = 72*0.5*(paperWidth - width)
     yo = 72*0.5*(paperHeight - height)
     l, b, w, h = self.figure.bbox.bounds
     llx = xo
     lly = yo
     urx = llx + w
     ury = lly + h
     rotation = 0
     if isLandscape:
         llx, lly, urx, ury = lly, llx, ury, urx
         xo, yo = 72*paperHeight - yo, xo
         rotation = 90
     bbox = (llx, lly, urx, ury)
     origfacecolor = self.figure.get_facecolor()
     origedgecolor = self.figure.get_edgecolor()
     self.figure.set_facecolor(facecolor)
     self.figure.set_edgecolor(edgecolor)
     dryrun = kwargs.get("dryrun", False)
     if dryrun:
         class NullWriter(object):
             def write(self, *kl, **kwargs):
                 pass
         self._pswriter = NullWriter()
     else:
         self._pswriter = StringIO()
     _bbox_inches_restore = kwargs.pop("bbox_inches_restore", None)
     ps_renderer = RendererPS(width, height, self._pswriter, imagedpi=dpi)
     renderer = MixedModeRenderer(self.figure,
         width, height, dpi, ps_renderer,
         bbox_inches_restore=_bbox_inches_restore)
     self.figure.draw(renderer)
     if dryrun: # return immediately if dryrun (tightbbox=True)
         return
     self.figure.set_facecolor(origfacecolor)
     self.figure.set_edgecolor(origedgecolor)
     if isEPSF: print >>fh, "%!PS-Adobe-3.0 EPSF-3.0"
     else: print >>fh, "%!PS-Adobe-3.0"
     if title: print >>fh, "%%Title: "+title
     print >>fh, ("%%Creator: matplotlib version "
                  +__version__+", http://matplotlib.sourceforge.net/")
     print >>fh, "%%CreationDate: "+time.ctime(time.time())
     print >>fh, "%%Orientation: " + orientation
     if not isEPSF: print >>fh, "%%DocumentPaperSizes: "+papertype
     print >>fh, "%%%%BoundingBox: %d %d %d %d" % bbox
     if not isEPSF: print >>fh, "%%Pages: 1"
     print >>fh, "%%EndComments"
     Ndict = len(psDefs)
     print >>fh, "%%BeginProlog"
     if not rcParams['ps.useafm']:
         Ndict += len(ps_renderer.used_characters)
     print >>fh, "/mpldict %d dict def"%Ndict
     print >>fh, "mpldict begin"
     for d in psDefs:
         d=d.strip()
         for l in d.split('\n'):
             print >>fh, l.strip()
     if not rcParams['ps.useafm']:
         for font_filename, chars in ps_renderer.used_characters.values():
             if len(chars):
                 font = FT2Font(font_filename)
                 cmap = font.get_charmap()
                 glyph_ids = []
                 for c in chars:
                     gind = cmap.get(c) or 0
                     glyph_ids.append(gind)
                 if is_opentype_cff_font(font_filename):
                     raise RuntimeError("OpenType CFF fonts can not be saved using the internal Postscript backend at this time.\nConsider using the Cairo backend.")
                 else:
                     fonttype = rcParams['ps.fonttype']
                     convert_ttf_to_ps(font_filename, fh, rcParams['ps.fonttype'], glyph_ids)
     print >>fh, "end"
     print >>fh, "%%EndProlog"
     if not isEPSF: print >>fh, "%%Page: 1 1"
     print >>fh, "mpldict begin"
     print >>fh, "%s translate"%_nums_to_str(xo, yo)
     if rotation: print >>fh, "%d rotate"%rotation
     print >>fh, "%s clipbox"%_nums_to_str(width*72, height*72, 0, 0)
     print >>fh, self._pswriter.getvalue()
     print >>fh, "end"
     print >>fh, "showpage"
     if not isEPSF: print >>fh, "%%EOF"
     fh.close()
     if rcParams['ps.usedistiller'] == 'ghostscript':
         gs_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
     elif rcParams['ps.usedistiller'] == 'xpdf':
         xpdf_distill(tmpfile, isEPSF, ptype=papertype, bbox=bbox)
     if passed_in_file_object:
         fh = file(tmpfile)
         print >>outfile, fh.read()
     else:
         shutil.move(tmpfile, outfile)