def METHOD_NAME(self, args, images):
    e = None
    handle = args.file
    issysout = (handle == sys.stdout)
    c = self.ctx.conn(args)
    e = c.getSession().createExporter()
    remove = True
    try:
        for img in images:
            e.addImage(img)
        import omero
        try:
            if args.type == "TIFF":
                l = e.generateTiff()
            else:
                l = e.generateXml()
        except omero.ServerError as se:
            self.ctx.err("%s: %s" % (se.__class__.__name__, se.message))
            return
        remove = False
        offset = 0
        while True:
            rv = e.read(offset, DEFAULT_READ_LENGTH)
            if not rv:
                break
            rv = rv[:min(DEFAULT_READ_LENGTH, l - offset)]
            offset += len(rv)
            handle.write(rv)
    finally:
        try:
            if not issysout:
                handle.close()
                if remove:
                    os.remove(handle.name)
        except Exception as e:
            self.ctx.err("Failed to close handle: %s" % e)
        e.close()