Encode a filesystem path to the proper filesystem encoding

    :param Union[str, bytes] path: A string-like path
    :returns: A bytes-encoded filesystem path representation
767213
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):
        if six.PY2:
            return b"".join(
                (
                    _byte(ord(c) - 0xDC00)
                    if 0xDC00 <= ord(c) <= 0xDCFF
                    else c.encode(_fs_encoding, _fs_encode_errors)
                )
                for c in path
            )
        return path.encode(_fs_encoding, _fs_encode_errors)
    return path
892936
def WriteFileEntry(self, path):
    
    string = '{0:s}\n'.format(path)

    encoded_string = self._EncodeString(string)
    self._file_object.write(encoded_string)
1175237
def convert_to_base64(self, path):
        

        mime = magic.Magic(mime=True)
        content_type = mime.from_file(path)
        archive = ''
        with open(path, "rb") as image_file:
            archive = b64encode(image_file.read())
            archive = archive.decode('utf-8')
        return 'data:' + content_type + ';base64,' + archive
1360419
public static String encodePath(String path) {
        if (path != null) {
            path = encodeUrl(path);
            path = path.replaceAll("/jcr:", "/_jcr_");
            path = path.replaceAll("\\?", "%3F");
            path = path.replaceAll("=", "%3D");
            path = path.replaceAll(";", "%3B");
            path = path.replaceAll(":", "%3A");
            path = path.replaceAll("\\+", "%2B");
            path = path.replaceAll("&", "%26");
            path = path.replaceAll("#", "%23");
        }
        return path;
    }
269457
public static CheckpointStorageLocationReference encodePathAsReference(Path path) {
		byte[] refBytes = path.toString().getBytes(StandardCharsets.UTF_8);
		byte[] bytes = new byte[REFERENCE_MAGIC_NUMBER.length + refBytes.length];

		System.arraycopy(REFERENCE_MAGIC_NUMBER, 0, bytes, 0, REFERENCE_MAGIC_NUMBER.length);
		System.arraycopy(refBytes, 0, bytes, REFERENCE_MAGIC_NUMBER.length, refBytes.length);

		return new CheckpointStorageLocationReference(bytes);
	}
1153092
def _normalize_path(self, path):
        
        if type(path) is str:
            path = path.encode()
        path = path.split(b'\0')[0]

        if path[0:1] != self.pathsep:
            path = self.cwd + self.pathsep + path
        keys = path.split(self.pathsep)
        i = 0
        while i < len(keys):
            if keys[i] == b'':
                keys.pop(i)
            elif keys[i] == b'.':
                keys.pop(i)
            elif keys[i] == b'..':
                keys.pop(i)
                if i != 0:
                    keys.pop(i-1)
                    i -= 1
            else:
                i += 1
        return keys
455254
def path_to_url(path):
    
    path = os.path.normcase(os.path.abspath(path))
    if _drive_re.match(path):
        path = path[0] + '|' + path[2:]
    url = urllib.quote(path)
    url = url.replace(os.path.sep, '/')
    url = url.lstrip('/')
    return 'file:///' + url
1314130
def load_file_to_base64_str(f_path):
    
    path = abs_path(f_path)
    with io.open(path, 'rb') as f:
        f_bytes = f.read()
        base64_str = base64.b64encode(f_bytes).decode("utf-8")
        return base64_str
1123460
def read(self, path, encoding=None):
        
        b = common.read(path)

        if encoding is None:
            encoding = self.file_encoding

        return self.unicode(b, encoding)
1015488
def decode_git_path(path)
      if path[0] == ?" && path[-1] == ?"
        path = path[1...-1]
        path.gsub!(/\\\d{3}/) { |m| m[1..-1].to_i(8).chr }
      end
      path.gsub!(/\\[rn"\\]/) { |m| eval(%("#{m}")) }
      path
    end
1089971
def save(self, path: Union[str, bytes, int]) -> None:
        """"""
        with open(path, 'w') as f:
            def write(s: str) -> None:
                f.write(s)
            self._write_qasm(write)
1121473
def to_unicode(path, errors="replace"):
    """"""
    if isinstance(path, UNICODE):
        return path
    return path.decode(sys.getfilesystemencoding(), errors)
277075
function encodePagePath(path) {
  const paths = path.split('/');
  paths.forEach((item, index) => {
    paths[index] = encodeURIComponent(item);
  });
  return paths.join('/');
}
403800
private static StringBuilder encodePath(StringBuilder buf, String path, int offset) {
        byte[] bytes = null;
        if (buf == null) {
            loop:
            for (int i = offset; i < path.length(); i++) {
                char c = path.charAt(i);
                switch (c) {
                    case '%':
                    case '?':
                    case ';':
                    case '#':
                    case '"':
                    case '\'':
                    case '<':
                    case '>':
                    case ' ':
                    case '[':
                    case '\\':
                    case ']':
                    case '^':
                    case '`':
                    case '{':
                    case '|':
                    case '}':
                        buf = new StringBuilder(path.length() * 2);
                        break loop;
                    default:
                        if (c > 127) {
                            bytes = path.getBytes(URIUtils.__CHARSET);
                            buf = new StringBuilder(path.length() * 2);
                            break loop;
                        }
                }
            }
            if (buf == null)
                return null;
        }

        int i;

        loop:
        for (i = offset; i < path.length(); i++) {
            char c = path.charAt(i);
            switch (c) {
                case '%':
                    buf.append("%25");
                    continue;
                case '?':
                    buf.append("%3F");
                    continue;
                case ';':
                    buf.append("%3B");
                    continue;
                case '#':
                    buf.append("%23");
                    continue;
                case '"':
                    buf.append("%22");
                    continue;
                case '\'':
                    buf.append("%27");
                    continue;
                case '<':
                    buf.append("%3C");
                    continue;
                case '>':
                    buf.append("%3E");
                    continue;
                case ' ':
                    buf.append("%20");
                    continue;
                case '[':
                    buf.append("%5B");
                    continue;
                case '\\':
                    buf.append("%5C");
                    continue;
                case ']':
                    buf.append("%5D");
                    continue;
                case '^':
                    buf.append("%5E");
                    continue;
                case '`':
                    buf.append("%60");
                    continue;
                case '{':
                    buf.append("%7B");
                    continue;
                case '|':
                    buf.append("%7C");
                    continue;
                case '}':
                    buf.append("%7D");
                    continue;

                default:
                    if (c > 127) {
                        bytes = path.getBytes(URIUtils.__CHARSET);
                        break loop;
                    }
                    buf.append(c);
            }
        }

        if (bytes != null) {
            for (; i < bytes.length; i++) {
                byte c = bytes[i];
                switch (c) {
                    case '%':
                        buf.append("%25");
                        continue;
                    case '?':
                        buf.append("%3F");
                        continue;
                    case ';':
                        buf.append("%3B");
                        continue;
                    case '#':
                        buf.append("%23");
                        continue;
                    case '"':
                        buf.append("%22");
                        continue;
                    case '\'':
                        buf.append("%27");
                        continue;
                    case '<':
                        buf.append("%3C");
                        continue;
                    case '>':
                        buf.append("%3E");
                        continue;
                    case ' ':
                        buf.append("%20");
                        continue;
                    case '[':
                        buf.append("%5B");
                        continue;
                    case '\\':
                        buf.append("%5C");
                        continue;
                    case ']':
                        buf.append("%5D");
                        continue;
                    case '^':
                        buf.append("%5E");
                        continue;
                    case '`':
                        buf.append("%60");
                        continue;
                    case '{':
                        buf.append("%7B");
                        continue;
                    case '|':
                        buf.append("%7C");
                        continue;
                    case '}':
                        buf.append("%7D");
                        continue;
                    default:
                        if (c < 0) {
                            buf.append('%');
                            TypeUtils.toHex(c, buf);
                        } else
                            buf.append((char) c);
                }
            }
        }

        return buf;
    }
1001829
def decode_to_bin_keypath(path):
    
    path = encode_to_bin(path)
    if path[0] == 1:
        path = path[4:]
    assert path[0:2] == PREFIX_00
    padded_len = TWO_BITS.index(path[2:4])
    return path[4+((4 - padded_len) % 4):]
197293
def encode(data: Union[str, bytes]) -> str:
        
        return ensure_str(base58.b58encode(ensure_bytes(data)))
870097
def get_path_signature(self, path):
        
        if not os.path.exists(path):
            return None
        if os.path.isdir(path):
            merge = {}
            for root, dirs, files in os.walk(path):
                for name in files:
                    full_name = os.path.join(root, name)
                    merge[full_name] = os.stat(full_name)
            return merge
        else:
            return os.stat(path)