Skip to content

Commit c852030

Browse files
committed
Ignore locale outside of Windows
The C calls I use are okay with UTF-8 on Unix platforms.
1 parent b032d80 commit c852030

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ Changes relevant to the users of python-tcod are documented here.
44
This project adheres to [Semantic Versioning](https://semver.org/) since version `2.0.0`.
55

66
## [Unreleased]
7+
### Fixed
8+
- Ignore the locale when encoding file paths outside of Windows.
79

810
## [16.2.1] - 2023-09-24
911
### Fixed
10-
- Fixed errors loading files where their paths are non-ASCII and the C locale is not UTF-8.
12+
- Fixed errors loading files on Windows where their paths are non-ASCII and the locale is not UTF-8.
1113

1214
## [16.2.0] - 2023-09-20
1315
### Changed

tcod/_internal.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ def _fmt(string: str, stacklevel: int = 2) -> bytes:
130130

131131

132132
def _path_encode(path: Path) -> bytes:
133-
"""Return a bytes file path for the current C locale."""
133+
"""Return a bytes file path for the current locale when on Windows, uses fsdecode for other platforms."""
134+
if sys.platform != "win32":
135+
return bytes(path) # Sane and expected behavior for converting Path into bytes
134136
try:
135-
return str(path).encode(locale.getlocale()[1] or "utf-8")
137+
return str(path).encode(locale.getlocale()[1] or "utf-8") # Stay classy, Windows
136138
except UnicodeEncodeError as exc:
137139
if sys.version_info >= (3, 11):
138140
exc.add_note("""Consider calling 'locale.setlocale(locale.LC_CTYPES, ".UTF8")' to support Unicode paths.""")

0 commit comments

Comments
 (0)