Ensure that the given path is decoded,
    NONE when no expected encoding works
775837
def filesys_decode(path):
    

    if isinstance(path, six.text_type):
        return path

    fs_enc = sys.getfilesystemencoding() or 'utf-8'
    candidates = fs_enc, 'utf-8'

    for enc in candidates:
        try:
            return path.decode(enc)
        except UnicodeDecodeError:
            continue
157991
def smartread(path):
    
    with open(path, "rb") as f:
        content = f.read()
        result = chardet.detect(content)
        return content.decode(result["encoding"])
226040
def _detect_encoding(self, source_file):
        """"""

        encoding = self._guess(source_file)
        # If we didn't explicitly detect an encoding, assume default.
        if encoding is None:
            encoding = self.default_encoding

        return encoding
484837
def fs_encode(path):
    

    path = _get_path(path)
    if path is None:
        raise TypeError("expected a valid path to encode")
    if isinstance(path, six.text_type):
        path = path.encode(_fs_encoding, _fs_encode_errors)
    return path
804766
def normalize_path(path)
      if(path.size > 256)
        path = "\\\\?\\" + Pathname.new(path).realpath.to_s
      end
#      require 'rchardet'
#      require 'iconv'
#      cd = CharDet.detect(path)
#      encoding = cd['encoding']
#      converter = Iconv.new("UTF-16LE", encoding)
#      converter.iconv(path)
      # path.encode!("UTF-16LE")
    end
508312
static public function sanitizePath(string $path,
                                        string $pathEncoding = null): string {
        if ($pathEncoding === null) {
            self::detectPathEncoding();
            $pathEncoding = self::$pathEncoding;
        }
        $path = iconv($pathEncoding, 'utf-8', $path);
        $path = str_replace('\\', '/', $path);
        return $path;
    }
129203
def _ensure_decoded(s):
    
    if isinstance(s, (np.bytes_, bytes)):
        s = s.decode(pd.get_option('display.encoding'))
    return s
89986
function( /*String*/ path, /*String?*/ encoding) {
					path = frontSlash(path);
					if (encoding === 'utf-8') {
						encoding = 'utf8';
					}
					if (!encoding) {
						encoding = 'utf8';
					}

					var text = cache[path].contents + "";
					//Hmm, would not expect to get A BOM, but it seems to happen,
					//remove it just in case.
					if (text.indexOf('\uFEFF') === 0) {
						text = text.substring(1, text.length);
					}


					return text;
				}
1197590
def is_valid_path(path):
    
    if not path.startswith('/'):
        msg = 'Invalid path "%s". Paths need to start with "/".'
        raise ValueError(msg % path[:40])

    for c in ' \t':
        if c in path:
            msg = ('Invalid character "%s" found in path. Paths need to be'
                   ' URL-encoded.')
            raise ValueError(msg % c)

    return True
894311
public static String pathEncode(String path, Charset charset) {
    return encodeReserved(path, FragmentType.PATH_SEGMENT, charset);

    /*
     * path encoding is not equivalent to query encoding, there are few differences, namely dealing
     * with spaces, !, ', (, ), and ~ characters. we will need to manually process those values.
     */
    // return encoded.replaceAll("\\+", "%20");
  }
481180
def _read(path, encoding="utf-8", comment=";;;"):
    
    if path:
        if isinstance(path, basestring) and os.path.exists(path):
            # From file path.
            if PY2:
                f = codecs.open(path, 'r', encoding='utf-8')
            else:
                f = open(path, 'r', encoding='utf-8')
        elif isinstance(path, basestring):
            # From string.
            f = path.splitlines()
        else:
            # From file or buffer.
            f = path
        for i, line in enumerate(f):
            line = line.strip(codecs.BOM_UTF8) if i == 0 and isinstance(line, binary_type) else line
            line = line.strip()
            line = decode_utf8(line, encoding)
            if not line or (comment and line.startswith(comment)):
                continue
            yield line
    return
390149
def normalize_path(path, encoding='utf-8'):
    '''
    '''
    if not path.startswith('/'):
        path = '/' + path
    path = percent_encode(flatten_path(path, flatten_slashes=True), encoding=encoding)
    return uppercase_percent_encoding(path)
461212
def check_path(filename, reporter=modReporter.Default, settings_path=None, **setting_overrides):
    """"""
    try:
        with open(filename, 'U') as f:
            codestr = f.read() + '\n'
    except UnicodeError:
        reporter.unexpected_error(filename, 'problem decoding source')
        return 1
    except IOError:
        msg = sys.exc_info()[1]
        reporter.unexpected_error(filename, msg.args[1])
        return 1
    return check(codestr, filename, reporter, settings_path, **setting_overrides)
231400
def native_path(path):  # pragma: no cover
    
    if PY2 and not isinstance(path, bytes):
        return path.encode(fs_encoding)
    return path
362930
function (/*String*/path, /*String?*/encoding) {
            if (encoding === 'utf-8') {
                encoding = 'utf8';
            }
            if (!encoding) {
                encoding = 'utf8';
            }

            var text = fs.readFileSync(path, encoding);

            //Hmm, would not expect to get A BOM, but it seems to happen,
            //remove it just in case.
            if (text.indexOf('\uFEFF') === 0) {
                text = text.substring(1, text.length);
            }

            return text;
        }
1348832
def safe_read_file(file_path: Path) -> str:
    
    for encoding in FILE_ENCODINGS:
        try:
            return file_path.read_text(encoding=encoding)
        except UnicodeError:
            pass  # Ignore encoding error

    raise GuesslangError('Encoding not supported for {!s}'.format(file_path))
39156
function (/*String*/path, /*String?*/encoding) {
        if (encoding === 'utf-8') {
            encoding = 'utf8';
        }
        if (!encoding) {
            encoding = 'utf8';
        }

        return fs.readFileSync(path, encoding);
    }