MCPcopy Index your code
hub / github.com/python/cpython / fsencode

Function fsencode

Lib/os.py:870–880  ·  view source on GitHub ↗

Encode filename (an os.PathLike, bytes, or str) to the filesystem encoding with 'surrogateescape' error handler, return bytes unchanged. On Windows, use 'strict' error handler if the file system encoding is 'mbcs' (which is the default encoding).

(filename)

Source from the content-addressed store, hash-verified

868 errors = sys.getfilesystemencodeerrors()
869
870 def fsencode(filename):
871 """Encode filename (an os.PathLike, bytes, or str) to the filesystem
872 encoding with 'surrogateescape' error handler, return bytes unchanged.
873 On Windows, use 'strict' error handler if the file system encoding is
874 'mbcs' (which is the default encoding).
875 """
876 filename = fspath(filename) # Does type-checking of `filename`.
877 if isinstance(filename, str):
878 return filename.encode(encoding, errors)
879 else:
880 return filename
881
882 def fsdecode(filename):
883 """Decode filename (an os.PathLike, bytes, or str) from the filesystem

Callers 3

_fwalkFunction · 0.85
_execvpeFunction · 0.85
_iterdirFunction · 0.85

Calls 1

encodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…