Normalize case of pathname. Makes all characters lowercase and all slashes into backslashes.
(s)
| 49 | LCMAP_LOWERCASE as _LCMAP_LOWERCASE) |
| 50 | |
| 51 | def normcase(s): |
| 52 | """Normalize case of pathname. |
| 53 | |
| 54 | Makes all characters lowercase and all slashes into backslashes. |
| 55 | """ |
| 56 | s = os.fspath(s) |
| 57 | if not s: |
| 58 | return s |
| 59 | if isinstance(s, bytes): |
| 60 | encoding = sys.getfilesystemencoding() |
| 61 | s = s.decode(encoding, 'surrogateescape').replace('/', '\\') |
| 62 | s = _LCMapStringEx(_LOCALE_NAME_INVARIANT, |
| 63 | _LCMAP_LOWERCASE, s) |
| 64 | return s.encode(encoding, 'surrogateescape') |
| 65 | else: |
| 66 | return _LCMapStringEx(_LOCALE_NAME_INVARIANT, |
| 67 | _LCMAP_LOWERCASE, |
| 68 | s.replace('/', '\\')) |
| 69 | except ImportError: |
| 70 | def normcase(s): |
| 71 | """Normalize case of pathname. |