()
| 864 | __all__.extend(("environb", "getenvb")) |
| 865 | |
| 866 | def _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 | |
| 896 | fsencode, fsdecode = _fscodec() |
| 897 | del _fscodec |
no outgoing calls
no test coverage detected
searching dependent graphs…