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

Function _fscodec

Lib/os.py:866–894  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

864 __all__.extend(("environb", "getenvb"))
865
866def _fscodec():
867 encoding = sys.getfilesystemencoding()
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
884 encoding with 'surrogateescape' error handler, return str unchanged. On
885 Windows, use 'strict' error handler if the file system encoding is
886 'mbcs' (which is the default encoding).
887 """
888 filename = fspath(filename) # Does type-checking of `filename`.
889 if isinstance(filename, bytes):
890 return filename.decode(encoding, errors)
891 else:
892 return filename
893
894 return fsencode, fsdecode
895
896fsencode, fsdecode = _fscodec()
897del _fscodec

Callers 1

os.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…