Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add encoding='locale' support for TextIOWrapper
  • Loading branch information
MegasKomnenos authored and youknowone committed Mar 28, 2023
commit 7e6c33152e77371a4c62fd2eb5cfd1eb5689d279
4 changes: 0 additions & 4 deletions Lib/test/test_fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ def test__getitem__(self):
retval2 = fi[1]
self.assertEqual(retval2, "line2\n")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test__getitem___deprecation(self):
t = self.writeTmp("line1\nline2\n")
with self.assertWarnsRegex(DeprecationWarning,
Expand Down Expand Up @@ -914,8 +912,6 @@ def test_empty_string(self):
def test_no_ext(self):
self.do_test_use_builtin_open("abcd", 2)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.skipUnless(gzip, "Requires gzip and zlib")
def test_gz_ext_fake(self):
original_open = gzip.open
Expand Down
12 changes: 8 additions & 4 deletions vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2193,10 +2193,14 @@ mod _io {
*data = None;

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

Expand Down