[pypy-commit] pypy stdlib-2.7.8: merged upstream

alex_gaynor noreply at buildbot.pypy.org
Wed Aug 27 23:13:02 CEST 2014


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: stdlib-2.7.8
Changeset: r73104:96013c5bad15
Date: 2014-08-27 14:12 -0700
http://bitbucket.org/pypy/pypy/changeset/96013c5bad15/

Log:	merged upstream

diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -8,7 +8,7 @@
 from rpython.rlib.rstring import StringBuilder
 from pypy.module._file.interp_stream import W_AbstractStream, StreamErrors
 from pypy.module.posix.interp_posix import dispatch_filename
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import OperationError, oefmt, wrap_oserror
 from pypy.interpreter.typedef import (TypeDef, GetSetProperty,
     interp_attrproperty, make_weakref_descr, interp_attrproperty_w)
 from pypy.interpreter.gateway import interp2app, unwrap_spec
@@ -299,8 +299,8 @@
     def file_fdopen(self, fd, mode="r", buffering=-1):
         try:
             self.direct_fdopen(fd, mode, buffering)
-        except StreamErrors, e:
-            raise wrap_streamerror(self.space, e, self.w_name)
+        except OSError as e:
+            raise wrap_oserror(self.space, e)
 
     _exposed_method_names = []
 
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -320,7 +320,8 @@
         path = self.path
         posix = self.posix
         fd = posix.open(path, posix.O_RDONLY)
-        raises(OSError, posix.fdopen, fd, 'w')
+        exc = raises(OSError, posix.fdopen, fd, 'w')
+        assert str(exc.value) == "[Errno 22] Invalid argument"
         posix.close(fd)  # fd should not be closed
 
     def test_getcwd(self):
diff --git a/pypy/module/thread/test/test_fork.py b/pypy/module/thread/test/test_fork.py
--- a/pypy/module/thread/test/test_fork.py
+++ b/pypy/module/thread/test/test_fork.py
@@ -13,16 +13,17 @@
             skip("No fork on this platform")
 
         def busy_thread():
+            print 'sleep'
             while run:
                 time.sleep(0)
             done.append(None)
 
-        for i in range(1):
+        for i in range(5):
             run = True
             done = []
             try:
+                print 'sleep'
                 thread.start_new(busy_thread, ())
-                print 'sleep'
 
                 pid = os.fork()
                 if pid == 0:
diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -428,7 +428,7 @@
 
         def _parse_spec(self, default_type, default_align):
             space = self.space
-            self._fill_char = self._lit("\0")[0]
+            self._fill_char = self._lit(" ")[0]
             self._align = default_align
             self._alternate = False
             self._sign = "\0"
@@ -441,9 +441,11 @@
             length = len(spec)
             i = 0
             got_align = True
+            got_fill_char = False
             if length - i >= 2 and self._is_alignment(spec[i + 1]):
                 self._align = spec[i + 1]
                 self._fill_char = spec[i]
+                got_fill_char = True
                 i += 2
             elif length - i >= 1 and self._is_alignment(spec[i]):
                 self._align = spec[i]
@@ -456,7 +458,7 @@
             if length - i >= 1 and spec[i] == "#":
                 self._alternate = True
                 i += 1
-            if self._fill_char == "\0" and length - i >= 1 and spec[i] == "0":
+            if not got_fill_char and length - i >= 1 and spec[i] == "0":
                 self._fill_char = self._lit("0")[0]
                 if not got_align:
                     self._align = "="
@@ -569,8 +571,6 @@
                 assert precision >= 0
                 length = precision
                 string = string[:precision]
-            if self._fill_char == "\0":
-                self._fill_char = self._lit(" ")[0]
             self._calc_padding(string, length)
             return space.wrap(self._pad(string))
 
@@ -811,7 +811,7 @@
             self._get_locale(tp)
             spec = self._calc_num_width(n_prefix, sign_char, to_numeric, n_digits,
                                         n_remainder, False, result)
-            fill = self._lit(" ") if self._fill_char == "\0" else self._fill_char
+            fill = self._fill_char
             upper = self._type == "X"
             return self.space.wrap(self._fill_number(spec, result, to_numeric,
                                      to_prefix, fill, to_remainder, upper))
@@ -957,7 +957,7 @@
                 digits = result
             spec = self._calc_num_width(0, sign, to_number, n_digits,
                                         n_remainder, have_dec_point, digits)
-            fill = self._lit(" ") if self._fill_char == "\0" else self._fill_char
+            fill = self._fill_char
             return self.space.wrap(self._fill_number(spec, digits, to_number, 0,
                                       fill, to_remainder, False))
 
@@ -1092,8 +1092,6 @@
 
             out = self._builder()
             fill = self._fill_char
-            if fill == "\0":
-                fill = self._lit(" ")[0]
 
             #compose the string
             #add left padding
diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -184,6 +184,20 @@
         format_string = self.s("{{{}:.6f}}").format(sys.maxsize + 1)
         raises(ValueError, "format(2.34, format_string)")
 
+    def test_format_null_fill_char(self):
+        assert self.s('{0:\x00<6s}').format('foo') == 'foo' + '\x00' * 3
+        assert self.s('{0:\x01<6s}').format('foo') == 'foo' + '\x01' * 3
+        assert self.s('{0:\x00^6s}').format('foo') == '\x00foo\x00\x00'
+
+        assert self.s('{0:\x00<6}').format(3) == '3' + '\x00' * 5
+        assert self.s('{0:\x01<6}').format(3) == '3' + '\x01' * 5
+
+        assert self.s('{0:\x00<6}').format(3.14) == '3.14' + '\x00' * 2
+        assert self.s('{0:\x01<6}').format(3.14) == '3.14' + '\x01' * 2
+
+        assert self.s('{0:\x00<12}').format(3+2.0j) == '(3+2j)' + '\x00' * 6
+        assert self.s('{0:\x01<12}').format(3+2.0j) == '(3+2j)' + '\x01' * 6
+
 
 class AppTestUnicodeFormat(BaseStringFormatTests):
     def setup_class(cls):
diff --git a/rpython/rlib/_rsocket_rffi.py b/rpython/rlib/_rsocket_rffi.py
--- a/rpython/rlib/_rsocket_rffi.py
+++ b/rpython/rlib/_rsocket_rffi.py
@@ -105,6 +105,9 @@
     linux = platform.Defined('linux')
     WIN32 = platform.Defined('_WIN32')
 
+    O_RDONLY = platform.DefinedConstantInteger('O_RDONLY')
+    O_WRONLY = platform.DefinedConstantInteger('O_WRONLY')
+    O_RDWR = platform.DefinedConstantInteger('O_RDWR')
     O_NONBLOCK = platform.DefinedConstantInteger('O_NONBLOCK')
     F_GETFL = platform.DefinedConstantInteger('F_GETFL')
     F_SETFL = platform.DefinedConstantInteger('F_SETFL')
@@ -406,6 +409,9 @@
 
 locals().update(constants)
 
+O_RDONLY = cConfig.O_RDONLY
+O_WRONLY = cConfig.O_WRONLY
+O_RDWR = cConfig.O_RDWR
 O_NONBLOCK = cConfig.O_NONBLOCK
 F_GETFL = cConfig.F_GETFL
 F_SETFL = cConfig.F_SETFL
diff --git a/rpython/rlib/streamio.py b/rpython/rlib/streamio.py
--- a/rpython/rlib/streamio.py
+++ b/rpython/rlib/streamio.py
@@ -37,7 +37,7 @@
 import os, sys, errno
 from rpython.rlib.objectmodel import specialize, we_are_translated
 from rpython.rlib.rarithmetic import r_longlong, intmask
-from rpython.rlib import rposix, nonconst
+from rpython.rlib import rposix, nonconst, _rsocket_rffi as _c
 from rpython.rlib.rstring import StringBuilder
 
 from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, O_APPEND
@@ -85,10 +85,26 @@
 def _setfd_binary(fd):
     pass
 
+if hasattr(_c, 'fcntl'):
+    def _check_fd_mode(fd, reading, writing):
+        flags = intmask(_c.fcntl(fd, _c.F_GETFL, 0))
+        if flags & _c.O_RDWR:
+            return
+        elif flags & _c.O_WRONLY:
+            if not reading:
+                return
+        else:  # O_RDONLY
+            if not writing:
+                return
+        raise OSError(22, "Invalid argument")
+else:
+    def _check_fd_mode(fd, reading, writing):
+        # XXX
+        pass
+
 def fdopen_as_stream(fd, mode, buffering=-1, signal_checker=None):
-    # XXX XXX XXX you want do check whether the modes are compatible
-    # otherwise you get funny results
     os_flags, universal, reading, writing, basemode, binary = decode_mode(mode)
+    _check_fd_mode(fd, reading, writing)
     _setfd_binary(fd)
     stream = DiskFile(fd, signal_checker)
     return construct_stream_tower(stream, buffering, universal, reading,


More information about the pypy-commit mailing list