Author: andrewjlawrence
Branch: winconsoleio
Changeset: r97520:63fa74a8e4b7
Date: 2019-09-17 22:10 +0100
http://bitbucket.org/pypy/pypy/changeset/63fa74a8e4b7/
Log: Fixed construction
diff --git a/pypy/module/_io/interp_win32consoleio.py
b/pypy/module/_io/interp_win32consoleio.py
--- a/pypy/module/_io/interp_win32consoleio.py
+++ b/pypy/module/_io/interp_win32consoleio.py
@@ -185,8 +185,8 @@
return i
return SMALLBUF
- @unwrap_spec(w_mode=WrappedDefault("r"), w_closefd=WrappedDefault(True),
w_opener=WrappedDefault(None))
- def descr_init(self, space, w_nameobj, w_mode, w_closefd, w_opener):
+ @unwrap_spec(mode='text', closefd=int)
+ def descr_init(self, space, w_nameobj, mode='r', closefd=True,
w_opener=None):
name = rffi.cast(rffi.CWCHARP, 0)
self.fd = -1
self.handle = rwin32.INVALID_HANDLE_VALUE
@@ -200,12 +200,10 @@
try:
if space.isinstance_w(w_nameobj, space.w_int):
self.fd = space.int_w(w_nameobj)
- closefd = space.bool_w(w_closefd)
if self.fd < 0:
from pypy.module.posix.interp_posix import fspath
w_path = fspath(space, w_nameobj)
- name = rffi.unicode2wcharp(space.utf8_w(w_path))
console_type = _pyio_get_console_type(space, w_path)
if not console_type:
raise oefmt(space.w_ValueError,
@@ -213,9 +211,8 @@
if console_type == '\0':
raise oefmt(space.w_ValueError,
"Cannot open non-console file")
- s = space.text_w(w_mode)
- for char in s:
+ for char in mode:
if char in "+abx":
# OK do nothing
pass
@@ -254,11 +251,14 @@
if self.writable:
access = rwin32.GENERIC_WRITE
- traits = _preferred_traits(space.wcharp2unicode(name))
+ traits = _preferred_traits(space.realunicode_w(w_path))
if not (traits.str is unicode):
raise oefmt(space.w_ValueError,
"Non-unicode string name %s", traits.str)
win32traits = make_win32_traits(traits)
+
+ pathlen = space.len_w(w_path)
+ name = rffi.utf82wcharp(space.utf8_w(w_path), pathlen)
self.handle = win32traits.CreateFile(name,
rwin32.GENERIC_READ | rwin32.GENERIC_WRITE,
rwin32.FILE_SHARE_READ | rwin32.FILE_SHARE_WRITE,
@@ -268,7 +268,8 @@
access,
rwin32.FILE_SHARE_READ | rwin32.FILE_SHARE_WRITE,
rffi.NULL, win32traits.OPEN_EXISTING, 0, rffi.NULL)
-
+ lltype.free(name, flavor='raw')
+
if self.handle == rwin32.INVALID_HANDLE_VALUE:
raise WindowsError(rwin32.GetLastError_saved(),
"Failed to open handle")
diff --git a/pypy/module/_io/test/test_win32consoleio.py
b/pypy/module/_io/test/test_win32consoleio.py
--- a/pypy/module/_io/test/test_win32consoleio.py
+++ b/pypy/module/_io/test/test_win32consoleio.py
@@ -8,15 +8,14 @@
cls.w_UINT_MAX = space.wrap(UINT_MAX)
def test_open_fd(self):
- self.assertRaisesRegex(ValueError,
- "negative file descriptor", _io._WindowsConsoleIO, -1)
+ import _io
+ raises(ValueError, _io._WindowsConsoleIO, -1)
fd, _ = tempfile.mkstemp()
try:
# Windows 10: "Cannot open non-console file"
# Earlier: "Cannot open console output buffer for reading"
- self.assertRaisesRegex(ValueError,
- "Cannot open (console|non-console file)",
_io._WindowsConsoleIO, fd)
+ raises(ValueError, _io._WindowsConsoleIO, fd)
finally:
os.close(fd)
@@ -26,9 +25,9 @@
# cannot open console because it's not a real console
pass
else:
- self.assertTrue(f.readable())
- self.assertFalse(f.writable())
- self.assertEqual(0, f.fileno())
+ assert f.readable() == True
+ assert f.writable() == False
+ assert 0 == f.fileno()
f.close() # multiple close should not crash
f.close()
@@ -38,9 +37,9 @@
# cannot open console because it's not a real console
pass
else:
- self.assertFalse(f.readable())
- self.assertTrue(f.writable())
- self.assertEqual(1, f.fileno())
+ assert f.readable() == False
+ assert True == f.writable()
+ assert 1 == f.fileno()
f.close()
f.close()
@@ -50,9 +49,9 @@
# cannot open console because it's not a real console
pass
else:
- self.assertFalse(f.readable())
- self.assertTrue(f.writable())
- self.assertEqual(2, f.fileno())
+ assert False == f.readable()
+ assert True == f.writable()
+ assert 2 == f.fileno()
f.close()
f.close()
diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -255,12 +255,9 @@
fd = _open_osfhandle(handle, flags)
with FdValidator(fd):
return fd
-
- wcsicmp = rffi.llexternal('_wcsicmp', [rffi.CWCHARP, rffi.CWCHARP],
rffi.INT)
wcsncpy_s = rffi.llexternal('wcsncpy_s',
[rffi.CWCHARP, rffi.SIZE_T, rffi.CWCHARP, rffi.SIZE_T],
rffi.INT)
-
def build_winerror_to_errno():
"""Build a dictionary mapping windows error numbers to POSIX errno.
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit