Create new filename with *encoding* and *text*
962799
def new(self, filename, encoding, text, default_content=False,
            empty=False):
        
        finfo = self.create_new_editor(filename, encoding, text,
                                       set_current=False, new=True)
        finfo.editor.set_cursor_position('eof')
        if not empty:
            finfo.editor.insert_text(os.linesep)
        if default_content:
            finfo.default = True
            finfo.editor.document().setModified(False)
        return finfo
350119
def open_with_encoding(filename,
                       encoding=None, mode='r', limit_byte_check=-1):
    """"""
    if not encoding:
        encoding = detect_encoding(filename, limit_byte_check=limit_byte_check)

    return io.open(filename, mode=mode, encoding=encoding,
                   newline='')
359961
def new_output_file(filename = 'foo')
      File.new( File.expand_path(File.join(export_path, filename)), 'w+')
    end
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
958327
def htmlCreateFileParserCtxt(filename, encoding):
    
    ret = libxml2mod.htmlCreateFileParserCtxt(filename, encoding)
    if ret is None:raise parserError('htmlCreateFileParserCtxt() failed')
    return parserCtxt(_obj=ret)
938443
function createResourceName(share, directory, file, forSAS) {
  var encode = function(name) {
    if (name && !forSAS) {
      name = encodeURIComponent(name);
      name = name.replace(/%2F/g, '/');
      name = name.replace(/%5C/g, '/');
      name = name.replace(/\+/g, '%20');
    }
    return name;
  };

  var name = share;

  if (directory) {
    // if directory does not start with '/', add it
    if (directory[0] !== '/') {
      name += ('/');
    }

    name += encode(directory);
  } 

  if (file) {
    // if the current path does not end with '/', add it
    if (name[name.length - 1] !== '/') {
      name += ('/');
    }
    
    name += encode(file);
  }

  return path.normalize(name).replace(/\\/g, '/');
}
433074
def read(filename, encoding='utf-8'):
    
    text, encoding = decode( open(filename, 'rb').read() )
    return text, encoding
505092
def _encode_filename_to_filesystem(f):
    ''''''
    log.debug('_encode_filename_to_filesystem(%s)', repr(f))
    if isinstance(f, str):
        return f
    try:
        return f.encode(sys.getfilesystemencoding())
    except UnicodeEncodeError:
        raise
587699
public static String createEncodedName(File source) {
        String fileURI = source.toURI().toString();
        String userDirURI = new File(System.getProperty("user.dir")).toURI()
                .toString();
        fileURI = fileURI.replace(userDirURI, "");
        String encodedName = fileURI.substring(fileURI.lastIndexOf(':') + 1)
                .replace("%20", "-").replace('/', '_');
        return encodedName;
    }
1112318
def punify_filename(filename):
    
    path, extension = splitext(filename)
    return path.encode('punycode').decode('utf8') + extension
637344
def fmt_filename(text):
    
    forbidden_char = ["\\", "/", ":", "*", "?", "|", "<", ">", '"']
    for char in forbidden_char:
        text = text.replace(char, "")
    return text
129628
def write_file(filename, string):
    """"""
    import sys
    #ugly fix, hopefully we can find a better one
    if sys.version_info[0] >= 3:
        with open(filename, 'w', encoding="utf-8") as f:
            f.write(string)
    else:
        with open(filename, 'w') as f:
            f.write(string.encode("utf-8"))
1315055
def build_filename(filename, filetype='png', resolution=300):
    
    filevals = os.path.splitext(filename)
    if filevals[1]:
        filetype = filevals[1][1:]
    if not filetype:
        filetype = 'png'
    filename = filevals[0] + '.' + filetype

    if not resolution:
        resolution = 300
    return filename, filetype, resolution
783685
def _read_file(name, encoding='utf-8') -> str:
    
    with open(name, encoding=encoding) as f:
        return f.read()
789650
def create_file(self, filename, indented_data=None):
        
        filedir, filename = os.path.split(filename)
        if filedir:
            self.create_directory(filedir)
        path = os.path.join(self.path, filedir, filename)
        data = indented_data
        if isinstance(data, bytes) and not isinstance(data, str):
            # This is binary data rather than text.
            mode = 'wb'
        else:
            mode = 'w'
            if data:
                data = textwrap.dedent(data)
        with open(path, mode) as fi:
            if data:
                fi.write(data)
        return path
986230
def normalizeFilename(filename):
    
    result = os.path.expanduser(filename)
    result = os.path.abspath(result)
    return result
110506
def safe_filename(file_name, sep='_', default=None, extension=None):
    """"""
    if file_name is None:
        return decode_path(default)

    file_name = decode_path(file_name)
    file_name = os.path.basename(file_name)
    file_name, _extension = os.path.splitext(file_name)
    file_name = _safe_name(file_name, sep=sep)
    if file_name is None:
        return decode_path(default)
    file_name = file_name[:MAX_LENGTH]
    extension = _safe_name(extension or _extension, sep=sep)
    if extension is not None:
        file_name = '.'.join((file_name, extension))
        file_name = file_name[:MAX_LENGTH]
    return file_name