Skip to content

Commit 7e6c331

Browse files
MegasKomnenosyouknowone
authored andcommitted
Add encoding='locale' support for TextIOWrapper
1 parent e48ca28 commit 7e6c331

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Lib/test/test_fileinput.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,6 @@ def test__getitem__(self):
391391
retval2 = fi[1]
392392
self.assertEqual(retval2, "line2\n")
393393

394-
# TODO: RUSTPYTHON
395-
@unittest.expectedFailure
396394
def test__getitem___deprecation(self):
397395
t = self.writeTmp("line1\nline2\n")
398396
with self.assertWarnsRegex(DeprecationWarning,
@@ -914,8 +912,6 @@ def test_empty_string(self):
914912
def test_no_ext(self):
915913
self.do_test_use_builtin_open("abcd", 2)
916914

917-
# TODO: RUSTPYTHON
918-
@unittest.expectedFailure
919915
@unittest.skipUnless(gzip, "Requires gzip and zlib")
920916
def test_gz_ext_fake(self):
921917
original_open = gzip.open

vm/src/stdlib/io.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,10 +2193,14 @@ mod _io {
21932193
*data = None;
21942194

21952195
let encoding = match args.encoding {
2196-
Some(enc) => enc,
2197-
None => {
2198-
// TODO: try os.device_encoding(fileno) and then locale.getpreferredencoding()
2199-
PyStr::from(crate::codecs::DEFAULT_ENCODING).into_ref(&vm.ctx)
2196+
None if vm.state.settings.utf8_mode > 0 => PyStr::from("utf-8").into_ref(&vm.ctx),
2197+
Some(enc) if enc.as_str() != "locale" => enc,
2198+
_ => {
2199+
// None without utf8_mode or "locale" encoding
2200+
vm.import("locale", None, 0)?
2201+
.get_attr("getencoding", vm)?
2202+
.call((), vm)?
2203+
.try_into_value(vm)?
22002204
}
22012205
};
22022206

0 commit comments

Comments
 (0)