Write in-memory file object to real file.
497256
def membuf_tempfile(memfile):
    """"""
    memfile.seek(0, 0)

    tmpfd, tmpname = mkstemp(suffix='.rar')
    tmpf = os.fdopen(tmpfd, "wb")

    try:
        while True:
            buf = memfile.read(BSIZE)
            if not buf:
                break
            tmpf.write(buf)
        tmpf.close()
    except:
        tmpf.close()
        os.unlink(tmpname)
        raise
    return tmpname
700825
def convert_to_file(cgi_input, output_file, twobit_ref, twobit_name, var_only=False):
    """"""

    if isinstance(output_file, str):
        output_file = auto_zip_open(output_file, 'w')

    conversion = convert(cgi_input=cgi_input, twobit_ref=twobit_ref, twobit_name=twobit_name, var_only=var_only)
    for line in conversion:
        output_file.write(line + "\n")
    output_file.close()
517661
def write_raw(self, resp: Union[bytes, requests.Response], filename: str) -> None:
        """"""
        self.log(filename, end=' ', flush=True)
        with open(filename, 'wb') as file:
            if isinstance(resp, requests.Response):
                shutil.copyfileobj(resp.raw, file)
            else:
                file.write(resp)
95922
def serialize_to_file(obj, file_name, append=False):
  """"""
  logging.info("Serializing to file %s.", file_name)
  with tf.gfile.Open(file_name, "a+" if append else "wb") as output_file:
    pickle.dump(obj, output_file)
  logging.info("Done serializing to file %s.", file_name)
895023
def copyfileobj(fsrc, fdst, length=16*1024):
    """"""
    while 1:
        buf = fsrc.read(length)
        if not buf:
            break
        fdst.write(buf)
98208
def write_data(data, out_file):
    """"""
    with open(out_file, 'w') as handle_out:
        handle_out.write(json.dumps([data], skipkeys=True, indent=2))
214944
def dump(obj, f, preserve=False):
    
    if not f.write:
        raise TypeError('You can only dump an object into a file object')
    encoder = Encoder(f, preserve=preserve)
    return encoder.write_dict(obj)
296918
def _chunk_write(chunk, local_file, progress):
    """"""
    local_file.write(chunk)
    progress.update_with_increment_value(len(chunk))
1151862
def tofile(self, fileobj):
		
		for entry in self:
			print >>fileobj, str(entry)
		fileobj.close()
643790
def write_to_cache(self, data, filename):
        '''  '''

        json_data = json.dumps(data, sort_keys=True, indent=2)
        cache = open(filename, 'w')
        cache.write(json_data)
        cache.close()
285284
def write_to_textfile(path, registry):
    """"""
    tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
    with open(tmppath, 'wb') as f:
        f.write(generate_latest(registry))
    # rename(2) is atomic.
    os.rename(tmppath, path)
1352225
def write_file(self, name, contents):
        """"""
        # TODO: find a way to make ZipFile accept a file object.
        zi = zipfile.ZipInfo(name)
        zi.date_time = time.localtime(time.time())[:6]
        zi.compress_type = zipfile.ZIP_DEFLATED
        zi.external_attr = 0777 << 16L
        self.zip_file.writestr(zi, contents)
249920
def write_file(self, fileobject, skip_unknown=False):
        """"""
        self.set_metadata_version()

        for field in _version2fieldlist(self['Metadata-Version']):
            values = self.get(field)
            if skip_unknown and values in ('UNKNOWN', [], ['UNKNOWN']):
                continue
            if field in _ELEMENTSFIELD:
                self._write_field(fileobject, field, ','.join(values))
                continue
            if field not in _LISTFIELDS:
                if field == 'Description':
                    if self.metadata_version in ('1.0', '1.1'):
                        values = values.replace('\n', '\n        ')
                    else:
                        values = values.replace('\n', '\n       |')
                values = [values]

            if field in _LISTTUPLEFIELDS:
                values = [','.join(value) for value in values]

            for value in values:
                self._write_field(fileobject, field, value)
406225
def _write_object(self, path, value):
    ''''''
    ensure_directory_exists(os.path.dirname(path))

    with open(path, 'w') as f:
      f.write(value)
1243718
def writeFile(filename, content, encoding=None):
    """"""
    if not content:
        raise OSError("empty content for file %s" % filename)

    def getfp(filename, encoding):
        """Get open file object."""
        if encoding:
            return codecs.open(filename, 'w', encoding)
        return open(filename, 'wb')

    try:
        with getfp(filename, encoding) as fp:
            fp.write(content)
            fp.flush()
            os.fsync(fp.fileno())
            size = os.path.getsize(filename)
            if size == 0:
                raise OSError("empty file %s" % filename)
    except Exception:
        if os.path.isfile(filename):
            os.remove(filename)
        raise
    else:
        out.info(u"Saved %s (%s)." % (filename, strsize(size)))
155847
def _write(self, str_buf):
    """"""
    self._filehandle.write(str_buf)
    self._buf_size += len(str_buf)
833992
def writef(notebook, nb_file, fmt=None):
    """"""
    if nb_file == '-':
        write(notebook, sys.stdout, fmt)
        return

    _, ext = os.path.splitext(nb_file)
    fmt = copy(fmt or {})
    fmt = long_form_one_format(fmt, update={'extension': ext})

    create_prefix_dir(nb_file, fmt)

    with io.open(nb_file, 'w', encoding='utf-8') as stream:
        write(notebook, stream, fmt)