Write 'text' to file ('filename') assuming 'encoding' in an atomic way
    Return (eventually new) encoding
763189
def write(text, filename, encoding='utf-8', mode='wb'):
    
    text, encoding = encode(text, encoding)
    if 'a' in mode:
        with open(filename, mode) as textfile:
            textfile.write(text)
    else:
        with atomic_write(filename,
                          overwrite=True,
                          mode=mode) as textfile:
            textfile.write(text)
    return encoding
970265
def get_encoded_filename(self, filename_parm):
        
        encoded_filename = force_text(filename_parm['filename*'])
        try:
            charset, lang, filename = encoded_filename.split('\'', 2)
            filename = urlparse.unquote(filename)
        except (ValueError, LookupError):
            filename = force_text(filename_parm['filename'])
        return filename
1284573
def writeFile(filename, data):
		
		with open(filename, 'wb') as f:
			f.write(data.encode('utf-8'))
437298
def write_file(writer, filename):
  """"""
  for line in txt_line_iterator(filename):
    writer.write(line)
    writer.write("\n")
812821
def write_file(filename, content):
    """"""
    print 'Generating {0}'.format(filename)
    with open(filename, 'wb') as out_f:
        out_f.write(content)
503496
def _read_file(name, encoding='utf-8'):
    
    with codecs.open(name, encoding=encoding) as f:
        return f.read()
285609
def create_textfile_with_contents(filename, contents, encoding='utf-8'):
    
    ensure_directory_exists(os.path.dirname(filename))
    if os.path.exists(filename):
        os.remove(filename)
    outstream = codecs.open(filename, "w", encoding)
    outstream.write(contents)
    if contents and not contents.endswith("\n"):
        outstream.write("\n")
    outstream.flush()
    outstream.close()
    assert os.path.exists(filename), "ENSURE file exists: %s" % filename
312079
def encode (text):
    """"""
    if isinstance(text, unicode):
        return text.encode(i18n.default_encoding, 'ignore')
    return text
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)
538599
def write(self, location, text, encoding):
        
        location = os.path.expanduser(location)

        with gzip.open(location, 'wb') as f:
            f.write(text.encode(encoding))
20014
def write(self, location, text, encoding):
        
        location = os.path.expanduser(location)

        with codecs.open(location, 'w', encoding) as f:
            f.write(text)
1014929
def write_utf(self, s):
        """"""
        utfstr = s.encode('utf-8')
        length = len(utfstr)
        if length > 64:
            raise NamePartTooLongException
        self.write_byte(length)
        self.write_string(utfstr, length)
1187198
def write_file(self, new_text, filename, old_text, encoding=None):
        
        try:
            f = _open_with_encoding(filename, "w", encoding=encoding)
        except os.error as err:
            self.log_error("Can't create %s: %s", filename, err)
            return
        try:
            f.write(_to_system_newlines(new_text))
        except os.error as err:
            self.log_error("Can't write %s: %s", filename, err)
        finally:
            f.close()
        self.log_debug("Wrote changes to %s", filename)
        self.wrote = True
783685
def _read_file(name, encoding='utf-8') -> str:
    
    with open(name, encoding=encoding) as f:
        return f.read()
417399
def write_in_tmpfile(text, tmpfile):
        
        try:
            tmpfile.write(text)
        except TypeError:
            tmpfile.write(str.encode(text))
        except UnicodeEncodeError:
            tmpfile.write(text.encode("utf-8"))
399991
def atomic_write(filename)
      dirname, basename = File.split(filename)
      basename = [
        basename,
        Thread.current.object_id,
        Process.pid,
        rand(1000000)
      ].join('.'.freeze)
      tmpname = File.join(dirname, basename)

      File.open(tmpname, 'wb+') do |f|
        yield f
      end

      File.rename(tmpname, filename)
    ensure
      File.delete(tmpname) if File.exist?(tmpname)
    end
1098510
def __write_text(self, outfile):
        
        for k, v in self.text.items():
            if not isinstance(v, bytes):
                try:
                    international = False
                    v = v.encode('latin-1')
                except UnicodeEncodeError:
                    international = True
                    v = v.encode('utf-8')
            else:
                international = False
            if not isinstance(k, bytes):
                k = strtobytes(k)
            if international:
                # No compress, language tag or translated keyword for now
                write_chunk(outfile, 'iTXt', k + zerobyte +
                            zerobyte + zerobyte +
                            zerobyte + zerobyte + v)
            else:
                write_chunk(outfile, 'tEXt', k + zerobyte + v)