Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions 8 Lib/test/test_winconsoleio.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def test_write_empty_data(self):
with ConIO('CONOUT$', 'w') as f:
self.assertEqual(f.write(b''), 0)

def test_fileno_raises_correct_exception(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest replacing "correct_exception" with something about the file being closed.

# Test that WindowsConsoleIO implementation of fileno
# raises a ValueError instead of io.UnsupportedOperation
# if the internal handle value is INVALID_HANDLE_VALUE.
f = open('conin$', 'r')
f.close()
self.assertRaisesRegex(ValueError, "I/O operation on closed file", f.fileno)

def assertStdinRoundTrip(self, text):
stdin = open('CONIN$', 'r')
old_stdin = sys.stdin
Expand Down
15 changes: 12 additions & 3 deletions 15 Modules/_io/winconsoleio.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,16 +474,25 @@ static PyObject *
_io__WindowsConsoleIO_fileno_impl(winconsoleio *self)
/*[clinic end generated code: output=006fa74ce3b5cfbf input=079adc330ddaabe6]*/
{
if (self->fd < 0 && self->handle != INVALID_HANDLE_VALUE) {
if (self->handle == INVALID_HANDLE_VALUE) {
return err_closed();
}

if (self->fd < 0) {
_Py_BEGIN_SUPPRESS_IPH
if (self->writable)
self->fd = _open_osfhandle((intptr_t)self->handle, _O_WRONLY | _O_BINARY);
else
self->fd = _open_osfhandle((intptr_t)self->handle, _O_RDONLY | _O_BINARY);
_Py_END_SUPPRESS_IPH
}
if (self->fd < 0)
return err_mode("fileno");

if (self->fd < 0) {
if (self->closehandle)
CloseHandle(self->handle);
self->handle = INVALID_HANDLE_VALUE;
return err_closed();
}
return PyLong_FromLong(self->fd);
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.