| 800 | __all__.extend(("environb", "getenvb")) |
| 801 | |
| 802 | def _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 | |
| 832 | fsencode, fsdecode = _fscodec() |
| 833 | del _fscodec |