# HG changeset patch # Parent 970f33dff5cadd1169a1f658dabe69a0423f7241 diff -r 970f33dff5ca Doc/library/binascii.rst --- a/Doc/library/binascii.rst Sat Mar 21 17:24:50 2015 +0100 +++ b/Doc/library/binascii.rst Sun Mar 22 04:42:58 2015 +0000 @@ -59,7 +59,7 @@ should be at most 57 to adhere to the base64 standard. -.. function:: a2b_qp(string, header=False) +.. function:: a2b_qp(data, header=False) Convert a block of quoted-printable data back to binary and return the binary data. More than one line may be passed at a time. If the optional argument diff -r 970f33dff5ca Doc/library/fcntl.rst --- a/Doc/library/fcntl.rst Sat Mar 21 17:24:50 2015 +0100 +++ b/Doc/library/fcntl.rst Sun Mar 22 04:42:58 2015 +0000 @@ -28,7 +28,7 @@ The module defines the following functions: -.. function:: fcntl(fd, cmd, arg=0) +.. function:: fcntl(fd, cmd, arg=0, /) Perform the operation *cmd* on file descriptor *fd* (file objects providing a :meth:`~io.IOBase.fileno` method are accepted as well). The values used @@ -50,7 +50,7 @@ If the :c:func:`fcntl` fails, an :exc:`OSError` is raised. -.. function:: ioctl(fd, request, arg=0, mutate_flag=True) +.. function:: ioctl(fd, request, arg=0, mutate_flag=True, /) This function is identical to the :func:`~fcntl.fcntl` function, except that the argument handling is even more complicated. @@ -105,7 +105,7 @@ using :c:func:`fcntl`.) -.. function:: lockf(fd, cmd, len=0, start=0, whence=0) +.. function:: lockf(fd, cmd, len=0, start=0, whence=0, /) This is essentially a wrapper around the :func:`~fcntl.fcntl` locking calls. *fd* is the file descriptor of the file to lock or unlock, and *cmd* diff -r 970f33dff5ca Doc/library/functions.rst --- a/Doc/library/functions.rst Sat Mar 21 17:24:50 2015 +0100 +++ b/Doc/library/functions.rst Sun Mar 22 04:42:58 2015 +0000 @@ -380,7 +380,7 @@ n += 1 -.. function:: eval(expression, globals=None, locals=None) +.. function:: eval(expression, globals=None, locals=None, /) The arguments are a string and optional globals and locals. If provided, *globals* must be a dictionary. If provided, *locals* can be any mapping diff -r 970f33dff5ca Doc/library/os.rst --- a/Doc/library/os.rst Sat Mar 21 17:24:50 2015 +0100 +++ b/Doc/library/os.rst Sun Mar 22 04:42:58 2015 +0000 @@ -875,9 +875,9 @@ :data:`os.SEEK_HOLE` or :data:`os.SEEK_DATA`. -.. function:: open(file, flags, mode=0o777, *, dir_fd=None) - - Open the file *file* and set various flags according to *flags* and possibly +.. function:: open(path, flags, mode=0o777, *, dir_fd=None) + + Open the file *path* and set various flags according to *flags* and possibly its mode according to *mode*. When computing *mode*, the current umask value is first masked out. Return the file descriptor for the newly opened file. The new file descriptor is :ref:`non-inheritable `. @@ -1083,10 +1083,10 @@ :meth:`~file.read` or :meth:`~file.readline` methods. -.. function:: sendfile(out, in, offset, nbytes) - sendfile(out, in, offset, nbytes, headers=None, trailers=None, flags=0) - - Copy *nbytes* bytes from file descriptor *in* to file descriptor *out* +.. function:: sendfile(out, in, offset, count) + sendfile(out, in, offset, count, headers=None, trailers=None, flags=0) + + Copy *count* bytes from file descriptor *in* to file descriptor *out* starting at *offset*. Return the number of bytes sent. When EOF is reached return 0. @@ -1100,7 +1100,7 @@ *trailers* are arbitrary sequences of buffers that are written before and after the data from *in* is written. It returns the same as the first case. - On Mac OS X and FreeBSD, a value of 0 for *nbytes* specifies to send until + On Mac OS X and FreeBSD, a value of 0 for *count* specifies to send until the end of *in* is reached. All platforms support sockets as *out* file descriptor, and some platforms @@ -1217,7 +1217,7 @@ .. versionadded:: 3.3 -.. function:: get_terminal_size(fd=STDOUT_FILENO) +.. function:: get_terminal_size(fd=STDOUT_FILENO, /) Return the size of the terminal window as ``(columns, lines)``, tuple of type :class:`terminal_size`. @@ -1712,10 +1712,10 @@ The *dir_fd* argument. -.. function:: mknod(filename, mode=0o600, device=0, *, dir_fd=None) +.. function:: mknod(path, mode=0o600, device=0, *, dir_fd=None) Create a filesystem node (file, device special file or named pipe) named - *filename*. *mode* specifies both the permissions to use and the type of node + *path*. *mode* specifies both the permissions to use and the type of node to be created, being combined (bitwise OR) with one of ``stat.S_IFREG``, ``stat.S_IFCHR``, ``stat.S_IFBLK``, and ``stat.S_IFIFO`` (those constants are available in :mod:`stat`). For ``stat.S_IFCHR`` and ``stat.S_IFBLK``, @@ -2423,9 +2423,9 @@ .. versionadded:: 3.3 -.. function:: symlink(source, link_name, target_is_directory=False, *, dir_fd=None) - - Create a symbolic link pointing to *source* named *link_name*. +.. function:: symlink(src, dst, target_is_directory=False, *, dir_fd=None) + + Create a symbolic link pointing to *src* named *dst*. On Windows, a symlink represents either a file or a directory, and does not morph to the target dynamically. If the target is present, the type of the @@ -2495,20 +2495,20 @@ The *dir_fd* parameter. -.. function:: utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True) +.. function:: utime(path, times=None, *[, ns], dir_fd=None, follow_symlinks=True) Set the access and modified times of the file specified by *path*. :func:`utime` takes two optional parameters, *times* and *ns*. These specify the times set on *path* and are used as follows: - - If *ns* is not ``None``, + - If *ns* is specified, it must be a 2-tuple of the form ``(atime_ns, mtime_ns)`` where each member is an int expressing nanoseconds. - If *times* is not ``None``, it must be a 2-tuple of the form ``(atime, mtime)`` where each member is an int or float expressing seconds. - - If *times* and *ns* are both ``None``, + - If *times* is ``None`` and *ns* is unspecified, this is equivalent to specifying ``ns=(atime_ns, mtime_ns)`` where both times are the current time. @@ -3064,9 +3064,10 @@ Availability: Unix. -.. function:: popen(command, mode='r', buffering=-1) - - Open a pipe to or from *command*. The return value is an open file object +.. function:: popen(cmd, mode='r', buffering=-1) + + Open a pipe to or from command *cmd*. + The return value is an open file object connected to the pipe, which can be read or written depending on whether *mode* is ``'r'`` (default) or ``'w'``. The *buffering* argument has the same meaning as the corresponding argument to the built-in :func:`open` function. The diff -r 970f33dff5ca Doc/library/zlib.rst --- a/Doc/library/zlib.rst Sat Mar 21 17:24:50 2015 +0100 +++ b/Doc/library/zlib.rst Sun Mar 22 04:42:58 2015 +0000 @@ -58,7 +58,7 @@ Raises the :exc:`error` exception if any error occurs. -.. function:: compressobj(level=-1, method=DEFLATED, wbits=15, memlevel=8, strategy=Z_DEFAULT_STRATEGY[, zdict]) +.. function:: compressobj(level=-1, method=DEFLATED, wbits=15, memLevel=8, strategy=Z_DEFAULT_STRATEGY[, zdict]) Returns a compression object, to be used for compressing data streams that won't fit into memory at once. @@ -75,9 +75,9 @@ should be an integer from ``8`` to ``15``. Higher values give better compression, but use more memory. - *memlevel* controls the amount of memory used for internal compression state. - Valid values range from ``1`` to ``9``. Higher values using more memory, - but are faster and produce smaller output. + The *memLevel* argument controls the amount of memory used for the + internal compression state. Valid values range from ``1`` to ``9``. + Higher values use more memory, but are faster and produce smaller output. *strategy* is used to tune the compression algorithm. Possible values are ``Z_DEFAULT_STRATEGY``, ``Z_FILTERED``, and ``Z_HUFFMAN_ONLY``. diff -r 970f33dff5ca Lib/test/test_binascii.py --- a/Lib/test/test_binascii.py Sat Mar 21 17:24:50 2015 +0100 +++ b/Lib/test/test_binascii.py Sun Mar 22 04:42:58 2015 +0000 @@ -167,6 +167,8 @@ self.assertEqual(binascii.unhexlify(self.type2test(t)), u) def test_qp(self): + binascii.a2b_qp(data=b"", header=False) # Keyword arguments allowed + # A test for SF bug 534347 (segfaults without the proper fix) try: binascii.a2b_qp(b"", **{1:1}) @@ -174,6 +176,7 @@ pass else: self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError") + self.assertEqual(binascii.a2b_qp(b"= "), b"= ") self.assertEqual(binascii.a2b_qp(b"=="), b"=") self.assertEqual(binascii.a2b_qp(b"=AX"), b"=AX") diff -r 970f33dff5ca Lib/test/test_os.py --- a/Lib/test/test_os.py Sat Mar 21 17:24:50 2015 +0100 +++ b/Lib/test/test_os.py Sun Mar 22 04:42:58 2015 +0000 @@ -219,6 +219,19 @@ with open(TESTFN2, 'r') as f: self.assertEqual(f.read(), "1") + def test_open_keywords(self): + f = os.open(path=__file__, flags=os.O_RDONLY, mode=0o777, + dir_fd=None) + os.close(f) + + def test_symlink_keywords(self): + symlink = support.get_attribute(os, "symlink") + try: + symlink(src='target', dst=support.TESTFN, + target_is_directory=False, dir_fd=None) + except (NotImplementedError, OSError): + pass # No OS support or unprivileged user + # Test attributes on return values from os.*stat* family. class StatAttributeTests(unittest.TestCase): @@ -2298,6 +2311,14 @@ os.sendfile(self.sockno, self.fileno, -1, 4096) self.assertEqual(cm.exception.errno, errno.EINVAL) + def test_keywords(self): + # Keyword arguments should be supported + os.sendfile(out=self.sockno, offset=0, count=4096, + **{'in': self.fileno}) + if self.SUPPORT_HEADERS_TRAILERS: + os.sendfile(self.sockno, self.fileno, offset=0, count=4096, + headers=None, trailers=None, flags=0) + # --- headers / trailers tests @requires_headers_trailers diff -r 970f33dff5ca Lib/test/test_popen.py --- a/Lib/test/test_popen.py Sat Mar 21 17:24:50 2015 +0100 +++ b/Lib/test/test_popen.py Sun Mar 22 04:42:58 2015 +0000 @@ -57,6 +57,10 @@ with os.popen("echo hello") as f: self.assertEqual(list(f), ["hello\n"]) + def test_keywords(self): + with os.popen(cmd="exit 0", mode="w", buffering=-1): + pass + def test_main(): support.run_unittest(PopenTest) diff -r 970f33dff5ca Lib/test/test_posix.py --- a/Lib/test/test_posix.py Sat Mar 21 17:24:50 2015 +0100 +++ b/Lib/test/test_posix.py Sun Mar 22 04:42:58 2015 +0000 @@ -442,6 +442,14 @@ else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) + # Keyword arguments are also supported + support.unlink(support.TESTFN) + try: + posix.mknod(path=support.TESTFN, mode=mode, device=0, + dir_fd=None) + except OSError as e: + self.assertIn(e.errno, (errno.EPERM, errno.EINVAL)) + def _test_all_chown_common(self, chown_func, first_param, stat_func): """Common code for chown, fchown and lchown tests.""" def check_stat(uid, gid): diff -r 970f33dff5ca Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py Sat Mar 21 17:24:50 2015 +0100 +++ b/Lib/test/test_zlib.py Sun Mar 22 04:42:58 2015 +0000 @@ -222,9 +222,9 @@ level = 2 method = zlib.DEFLATED wbits = -12 - memlevel = 9 + memLevel = 9 strategy = zlib.Z_FILTERED - co = zlib.compressobj(level, method, wbits, memlevel, strategy) + co = zlib.compressobj(level, method, wbits, memLevel, strategy) x1 = co.compress(HAMLET_SCENE) x2 = co.flush() dco = zlib.decompressobj(wbits) @@ -232,6 +232,10 @@ y2 = dco.flush() self.assertEqual(HAMLET_SCENE, y1 + y2) + # keyword arguments should also be supported + zlib.compressobj(level=level, method=method, wbits=wbits, + memLevel=memLevel, strategy=strategy, zdict=b"") + def test_compressincremental(self): # compress object in steps, decompress object as one-shot data = HAMLET_SCENE * 128 diff -r 970f33dff5ca Modules/posixmodule.c --- a/Modules/posixmodule.c Sat Mar 21 17:24:50 2015 +0100 +++ b/Modules/posixmodule.c Sun Mar 22 04:42:58 2015 +0000 @@ -6050,7 +6050,7 @@ dir_fd: dir_fd(requires='futimensat') = None follow_symlinks: bool=True -# "utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)\n\ +# "utime(path, times=None, *[, ns], dir_fd=None, follow_symlinks=True)\n\ Set the access and modified time of path. @@ -6060,10 +6060,10 @@ If times is not None, it must be a tuple (atime, mtime); atime and mtime should be expressed as float seconds since the epoch. -If ns is not None, it must be a tuple (atime_ns, mtime_ns); +If ns is specified, it must be a tuple (atime_ns, mtime_ns); atime_ns and mtime_ns should be expressed as integer nanoseconds since the epoch. -If both times and ns are None, utime uses the current time. +If times is None and ns is unspecified, utime uses the current time. Specifying tuples for both times and ns is an error. If dir_fd is not None, it should be a file descriptor open to a directory, @@ -11536,10 +11536,10 @@ #ifdef HAVE_SENDFILE PyDoc_STRVAR(posix_sendfile__doc__, -"sendfile(out, in, offset, nbytes) -> byteswritten\n\ -sendfile(out, in, offset, nbytes, headers=None, trailers=None, flags=0)\n\ +"sendfile(out, in, offset, count) -> byteswritten\n\ +sendfile(out, in, offset, count, headers=None, trailers=None, flags=0)\n\ -> byteswritten\n\ -Copy nbytes bytes from file descriptor in to file descriptor out."); +Copy count bytes from file descriptor in to file descriptor out."); /* AC 3.5: don't bother converting, has optional group*/ static PyObject * @@ -11559,6 +11559,7 @@ off_t sbytes; struct sf_hdtr sf; int flags = 0; + /* Beware that "in" clashes with Python's own "in" operator keyword */ static char *keywords[] = {"out", "in", "offset", "count", "headers", "trailers", "flags", NULL};