MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _fscodec

Function _fscodec

tools/python-3.11.9-amd64/Lib/os.py:802–830  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

800 __all__.extend(("environb", "getenvb"))
801
802def _fscodec():
803 encoding = sys.getfilesystemencoding()
804 errors = sys.getfilesystemencodeerrors()
805
806 def fsencode(filename):
807 """Encode filename (an os.PathLike, bytes, or str) to the filesystem
808 encoding with 'surrogateescape' error handler, return bytes unchanged.
809 On Windows, use 'strict' error handler if the file system encoding is
810 'mbcs' (which is the default encoding).
811 """
812 filename = fspath(filename) # Does type-checking of `filename`.
813 if isinstance(filename, str):
814 return filename.encode(encoding, errors)
815 else:
816 return filename
817
818 def fsdecode(filename):
819 """Decode filename (an os.PathLike, bytes, or str) from the filesystem
820 encoding with 'surrogateescape' error handler, return str unchanged. On
821 Windows, use 'strict' error handler if the file system encoding is
822 'mbcs' (which is the default encoding).
823 """
824 filename = fspath(filename) # Does type-checking of `filename`.
825 if isinstance(filename, bytes):
826 return filename.decode(encoding, errors)
827 else:
828 return filename
829
830 return fsencode, fsdecode
831
832fsencode, fsdecode = _fscodec()
833del _fscodec

Callers 1

os.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected