diff -r 79e469ae13b7 -r 01438f18ee18 Doc/c-api/exceptions.rst --- a/Doc/c-api/exceptions.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/c-api/exceptions.rst Fri Jul 25 11:39:11 2014 -0400 @@ -443,18 +443,13 @@ .. c:function:: int PySignal_SetWakeupFd(int fd) - This utility function specifies a file descriptor to which the signal number - is written as a single byte whenever a signal is received. *fd* must be - non-blocking. It returns the previous such file descriptor. - - The value ``-1`` disables the feature; this is the initial state. + This utility function specifies a file descriptor to which a ``'\0'`` byte will + be written whenever a signal is received. It returns the previous such file + descriptor. The value ``-1`` disables the feature; this is the initial state. This is equivalent to :func:`signal.set_wakeup_fd` in Python, but without any error checking. *fd* should be a valid file descriptor. The function should only be called from the main thread. - .. versionchanged:: 3.5 - On Windows, the function now also supports socket handles. - .. c:function:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict) diff -r 79e469ae13b7 -r 01438f18ee18 Doc/c-api/init.rst --- a/Doc/c-api/init.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/c-api/init.rst Fri Jul 25 11:39:11 2014 -0400 @@ -134,9 +134,6 @@ change for the duration of the program's execution. No code in the Python interpreter will change the contents of this storage. - Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a - :c:type:`wchar_*` string. - .. c:function:: wchar* Py_GetProgramName() @@ -246,9 +243,6 @@ :data:`sys.exec_prefix` to be empty. It is up to the caller to modify these if required after calling :c:func:`Py_Initialize`. - Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a - :c:type:`wchar_*` string. - .. c:function:: const char* Py_GetVersion() @@ -345,9 +339,6 @@ :data:`sys.path`, which is the same as prepending the current working directory (``"."``). - Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a - :c:type:`wchar_*` string. - .. note:: It is recommended that applications embedding the Python interpreter for purposes other than executing a single script pass 0 as *updatepath*, @@ -372,9 +363,6 @@ to 1 unless the :program:`python` interpreter was started with the :option:`-I`. - Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a - :c:type:`wchar_*` string. - .. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`. @@ -389,9 +377,6 @@ execution. No code in the Python interpreter will change the contents of this storage. - Use :c:func:`Py_DecodeLocale` to decode a bytes string to get a - :c:type:`wchar_*` string. - .. c:function:: w_char* Py_GetPythonHome() diff -r 79e469ae13b7 -r 01438f18ee18 Doc/c-api/sys.rst --- a/Doc/c-api/sys.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/c-api/sys.rst Fri Jul 25 11:39:11 2014 -0400 @@ -47,60 +47,6 @@ not call those functions directly! :c:type:`PyOS_sighandler_t` is a typedef alias for :c:type:`void (\*)(int)`. -.. c:function:: wchar_t* Py_DecodeLocale(const char* arg, size_t *size) - - Decode a byte string from the locale encoding with the :ref:`surrogateescape - error handler `: undecodable bytes are decoded as - characters in range U+DC80..U+DCFF. If a byte sequence can be decoded as a - surrogate character, escape the bytes using the surrogateescape error - handler instead of decoding them. - - Return a pointer to a newly allocated wide character string, use - :c:func:`PyMem_RawFree` to free the memory. If size is not ``NULL``, write - the number of wide characters excluding the null character into ``*size`` - - Return ``NULL`` on decoding error or memory allocation error. If *size* is - not ``NULL``, ``*size`` is set to ``(size_t)-1`` on memory error or set to - ``(size_t)-2`` on decoding error. - - Decoding errors should never happen, unless there is a bug in the C - library. - - Use the :c:func:`Py_EncodeLocale` function to encode the character string - back to a byte string. - - .. seealso:: - - The :c:func:`PyUnicode_DecodeFSDefaultAndSize` and - :c:func:`PyUnicode_DecodeLocaleAndSize` functions. - - .. versionadded:: 3.5 - - -.. c:function:: char* Py_EncodeLocale(const wchar_t *text, size_t *error_pos) - - Encode a wide character string to the locale encoding with the - :ref:`surrogateescape error handler `: surrogate characters - in the range U+DC80..U+DCFF are converted to bytes 0x80..0xFF. - - Return a pointer to a newly allocated byte string, use :c:func:`PyMem_Free` - to free the memory. Return ``NULL`` on encoding error or memory allocation - error - - If error_pos is not ``NULL``, ``*error_pos`` is set to the index of the - invalid character on encoding error, or set to ``(size_t)-1`` otherwise. - - Use the :c:func:`Py_DecodeLocale` function to decode the bytes string back - to a wide character string. - - .. seealso:: - - The :c:func:`PyUnicode_EncodeFSDefault` and - :c:func:`PyUnicode_EncodeLocale` functions. - - .. versionadded:: 3.5 - - .. _systemfunctions: System Functions diff -r 79e469ae13b7 -r 01438f18ee18 Doc/c-api/unicode.rst --- a/Doc/c-api/unicode.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/c-api/unicode.rst Fri Jul 25 11:39:11 2014 -0400 @@ -758,13 +758,11 @@ *errors* is ``NULL``. *str* must end with a null character but cannot contain embedded null characters. - Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` to decode a string from - :c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at - Python startup). - .. seealso:: - The :c:func:`Py_DecodeLocale` function. + Use :c:func:`PyUnicode_DecodeFSDefaultAndSize` to decode a string from + :c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at + Python startup). .. versionadded:: 3.3 @@ -785,13 +783,11 @@ *errors* is ``NULL``. Return a :class:`bytes` object. *str* cannot contain embedded null characters. - Use :c:func:`PyUnicode_EncodeFSDefault` to encode a string to - :c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at - Python startup). - .. seealso:: - The :c:func:`Py_EncodeLocale` function. + Use :c:func:`PyUnicode_EncodeFSDefault` to encode a string to + :c:data:`Py_FileSystemDefaultEncoding` (the locale encoding read at + Python startup). .. versionadded:: 3.3 @@ -836,14 +832,12 @@ If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the locale encoding. - :c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the - locale encoding and cannot be modified later. If you need to decode a string - from the current locale encoding, use - :c:func:`PyUnicode_DecodeLocaleAndSize`. - .. seealso:: - The :c:func:`Py_DecodeLocale` function. + :c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the + locale encoding and cannot be modified later. If you need to decode a + string from the current locale encoding, use + :c:func:`PyUnicode_DecodeLocaleAndSize`. .. versionchanged:: 3.2 Use ``"strict"`` error handler on Windows. @@ -873,13 +867,12 @@ If :c:data:`Py_FileSystemDefaultEncoding` is not set, fall back to the locale encoding. - :c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the - locale encoding and cannot be modified later. If you need to encode a string - to the current locale encoding, use :c:func:`PyUnicode_EncodeLocale`. - .. seealso:: - The :c:func:`Py_EncodeLocale` function. + :c:data:`Py_FileSystemDefaultEncoding` is initialized at startup from the + locale encoding and cannot be modified later. If you need to encode a + string to the current locale encoding, use + :c:func:`PyUnicode_EncodeLocale`. .. versionadded:: 3.2 diff -r 79e469ae13b7 -r 01438f18ee18 Doc/extending/embedding.rst --- a/Doc/extending/embedding.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/extending/embedding.rst Fri Jul 25 11:39:11 2014 -0400 @@ -58,18 +58,12 @@ int main(int argc, char *argv[]) { - wchar_t *program = Py_DecodeLocale(argv[0], NULL); - if (program == NULL) { - fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); - exit(1); - } - Py_SetProgramName(program); /* optional but recommended */ - Py_Initialize(); - PyRun_SimpleString("from time import time,ctime\n" - "print('Today is', ctime(time()))\n"); - Py_Finalize(); - PyMem_RawFree(program); - return 0; + Py_SetProgramName(argv[0]); /* optional but recommended */ + Py_Initialize(); + PyRun_SimpleString("from time import time,ctime\n" + "print('Today is', ctime(time()))\n"); + Py_Finalize(); + return 0; } The :c:func:`Py_SetProgramName` function should be called before @@ -166,7 +160,7 @@ interesting part with respect to embedding Python starts with :: Py_Initialize(); - pName = PyUnicode_DecodeFSDefault(argv[1]); + pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); diff -r 79e469ae13b7 -r 01438f18ee18 Doc/extending/extending.rst --- a/Doc/extending/extending.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/extending/extending.rst Fri Jul 25 11:39:11 2014 -0400 @@ -370,17 +370,11 @@ int main(int argc, char *argv[]) { - wchar_t *program = Py_DecodeLocale(argv[0], NULL); - if (program == NULL) { - fprintf(stderr, "Fatal error: cannot decode argv[0]\n"); - exit(1); - } - /* Add a built-in module, before Py_Initialize */ PyImport_AppendInittab("spam", PyInit_spam); /* Pass argv[0] to the Python interpreter */ - Py_SetProgramName(program); + Py_SetProgramName(argv[0]); /* Initialize the Python interpreter. Required. */ Py_Initialize(); @@ -392,10 +386,6 @@ ... - PyMem_RawFree(program); - return 0; - } - .. note:: Removing entries from ``sys.modules`` or importing compiled modules into diff -r 79e469ae13b7 -r 01438f18ee18 Doc/faq/programming.rst --- a/Doc/faq/programming.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/faq/programming.rst Fri Jul 25 11:39:11 2014 -0400 @@ -1786,10 +1786,19 @@ __import__('x.y.z') returns ; how do I get z? --------------------------------------------------------- -Consider using the convenience function :func:`~importlib.import_module` from -:mod:`importlib` instead:: +Try:: - z = importlib.import_module('x.y.z') + __import__('x.y.z').y.z + +For more realistic situations, you may have to do something like :: + + m = __import__(s) + for i in s.split(".")[1:]: + m = getattr(m, i) + +See :mod:`importlib` for a convenience function called +:func:`~importlib.import_module`. + When I edit an imported module and reimport it, the changes don't show up. Why does this happen? diff -r 79e469ae13b7 -r 01438f18ee18 Doc/includes/run-func.c --- a/Doc/includes/run-func.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/includes/run-func.c Fri Jul 25 11:39:11 2014 -0400 @@ -13,7 +13,7 @@ } Py_Initialize(); - pName = PyUnicode_DecodeFSDefault(argv[1]); + pName = PyUnicode_FromString(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName); diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/argparse.rst --- a/Doc/library/argparse.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/argparse.rst Fri Jul 25 11:39:11 2014 -0400 @@ -683,7 +683,7 @@ actions can do just about anything with the command-line arguments associated with them, though most actions simply add an attribute to the object returned by :meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies -how the command-line arguments should be handled. The supplied actions are: +how the command-line arguments should be handled. The supported actions are: * ``'store'`` - This just stores the argument's value. This is the default action. For example:: @@ -757,18 +757,28 @@ >>> parser.parse_args(['--version']) PROG 2.0 -You may also specify an arbitrary action by passing an Action subclass or -other object that implements the same interface. The recommended way to do -this is to extend :class:`Action`, overriding the ``__call__`` method -and optionally the ``__init__`` method. +You can also specify an arbitrary action by passing an object that implements +the Action API. The easiest way to do this is to extend +:class:`argparse.Action`, supplying an appropriate ``__call__`` method. The +``__call__`` method should accept four parameters: + +* ``parser`` - The ArgumentParser object which contains this action. + +* ``namespace`` - The :class:`Namespace` object that will be returned by + :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this + object. + +* ``values`` - The associated command-line arguments, with any type conversions + applied. (Type conversions are specified with the type_ keyword argument to + :meth:`~ArgumentParser.add_argument`.) + +* ``option_string`` - The option string that was used to invoke this action. + The ``option_string`` argument is optional, and will be absent if the action + is associated with a positional argument. An example of a custom action:: >>> class FooAction(argparse.Action): - ... def __init__(self, option_strings, dest, nargs=None, **kwargs): - ... if nargs is not None: - ... raise ValueError("nargs not allowed") - ... super(FooAction, self).__init__(option_strings, dest, **kwargs) ... def __call__(self, parser, namespace, values, option_string=None): ... print('%r %r %r' % (namespace, values, option_string)) ... setattr(namespace, self.dest, values) @@ -782,7 +792,6 @@ >>> args Namespace(bar='1', foo='2') -For more details, see :class:`Action`. nargs ^^^^^ @@ -1229,49 +1238,6 @@ >>> parser.parse_args('--foo XXX'.split()) Namespace(bar='XXX') -Action classes -^^^^^^^^^^^^^^ - -Action classes implement the Action API, a callable which returns a callable -which processes arguments from the command-line. Any object which follows -this API may be passed as the ``action`` parameter to -:meth:`add_argument`. - -.. class:: Action(option_strings, dest, nargs=None, const=None, default=None, - type=None, choices=None, required=False, help=None, - metavar=None) - -Action objects are used by an ArgumentParser to represent the information -needed to parse a single argument from one or more strings from the -command line. The Action class must accept the two positional arguments -plus any keyword arguments passed to :meth:`ArgumentParser.add_argument` -except for the ``action`` itself. - -Instances of Action (or return value of any callable to the ``action`` -parameter) should have attributes "dest", "option_strings", "default", "type", -"required", "help", etc. defined. The easiest way to ensure these attributes -are defined is to call ``Action.__init__``. - -Action instances should be callable, so subclasses must override the -``__call__`` method, which should accept four parameters: - -* ``parser`` - The ArgumentParser object which contains this action. - -* ``namespace`` - The :class:`Namespace` object that will be returned by - :meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this - object using :func:`setattr`. - -* ``values`` - The associated command-line arguments, with any type conversions - applied. Type conversions are specified with the type_ keyword argument to - :meth:`~ArgumentParser.add_argument`. - -* ``option_string`` - The option string that was used to invoke this action. - The ``option_string`` argument is optional, and will be absent if the action - is associated with a positional argument. - -The ``__call__`` method may perform arbitrary actions, but will typically set -attributes on the ``namespace`` based on ``dest`` and ``values``. - The parse_args() method ----------------------- diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/asyncio-eventloop.rst --- a/Doc/library/asyncio-eventloop.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/asyncio-eventloop.rst Fri Jul 25 11:39:11 2014 -0400 @@ -337,8 +337,6 @@ representing the data received. The maximum amount of data to be received at once is specified by *nbytes*. - The socket *sock* must be non-blocking. - This method is a :ref:`coroutine `. .. seealso:: @@ -353,8 +351,6 @@ an exception is raised, and there is no way to determine how much data, if any, was successfully processed by the receiving end of the connection. - The socket *sock* must be non-blocking. - This method is a :ref:`coroutine `. .. seealso:: @@ -371,8 +367,6 @@ :py:data:`~socket.AF_INET` and :py:data:`~socket.AF_INET6` address families. Use :meth:`getaddrinfo` to resolve the hostname asynchronously. - The socket *sock* must be non-blocking. - This method is a :ref:`coroutine `. .. seealso:: @@ -390,8 +384,6 @@ and *address* is the address bound to the socket on the other end of the connection. - The socket *sock* must be non-blocking. - This method is a :ref:`coroutine `. .. seealso:: diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/asyncio-sync.rst --- a/Doc/library/asyncio-sync.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/asyncio-sync.rst Fri Jul 25 11:39:11 2014 -0400 @@ -130,7 +130,7 @@ Condition ^^^^^^^^^ -.. class:: Condition(lock=None, \*, loop=None) +.. class:: Condition(\*, loop=None) A Condition implementation, asynchronous equivalent to :class:`threading.Condition`. @@ -139,9 +139,7 @@ allows one or more coroutines to wait until they are notified by another coroutine. - If the *lock* argument is given and not ``None``, it must be a :class:`Lock` - object, and it is used as the underlying lock. Otherwise, - a new :class:`Lock` object is created and used as the underlying lock. + A new :class:`Lock` object is created and used as the underlying lock. .. method:: acquire() diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/codecs.rst --- a/Doc/library/codecs.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/codecs.rst Fri Jul 25 11:39:11 2014 -0400 @@ -318,7 +318,6 @@ encodings. -.. _surrogateescape: .. _codec-base-classes: Codec Base Classes diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/csv.rst --- a/Doc/library/csv.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/csv.rst Fri Jul 25 11:39:11 2014 -0400 @@ -345,7 +345,13 @@ .. attribute:: Dialect.skipinitialspace - When :const:`True`, whitespace immediately following the *delimiter* is ignored. + When :const:`True`, spaces (and only spaces) immediately following the *delimiter* are ignored. + The default is :const:`False`. + + +.. attribute:: Dialect.skipinitialwhitespace + + When :const:`True`, whitespace characters immediately following the *delimiter* are ignored. The default is :const:`False`. diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/functools.rst --- a/Doc/library/functools.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/functools.rst Fri Jul 25 11:39:11 2014 -0400 @@ -413,10 +413,9 @@ .. decorator:: wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES) - This is a convenience function for invoking :func:`update_wrapper` as a - function decorator when defining a wrapper function. It is equivalent to - ``partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated)``. - For example:: + This is a convenience function for invoking ``partial(update_wrapper, + wrapped=wrapped, assigned=assigned, updated=updated)`` as a function decorator + when defining a wrapper function. For example: >>> from functools import wraps >>> def my_decorator(f): diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/html.parser.rst --- a/Doc/library/html.parser.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/html.parser.rst Fri Jul 25 11:39:11 2014 -0400 @@ -16,13 +16,21 @@ This module defines a class :class:`HTMLParser` which serves as the basis for parsing text files formatted in HTML (HyperText Mark-up Language) and XHTML. -.. class:: HTMLParser(*, convert_charrefs=True) +.. class:: HTMLParser(strict=False, *, convert_charrefs=False) - Create a parser instance able to parse invalid markup. + Create a parser instance. - If *convert_charrefs* is ``True`` (the default), all character + If *convert_charrefs* is ``True`` (default: ``False``), all character references (except the ones in ``script``/``style`` elements) are automatically converted to the corresponding Unicode characters. + The use of ``convert_charrefs=True`` is encouraged and will become + the default in Python 3.5. + + If *strict* is ``False`` (the default), the parser will accept and parse + invalid markup. If *strict* is ``True`` the parser will raise an + :exc:`~html.parser.HTMLParseError` exception instead [#]_ when it's not + able to parse the markup. The use of ``strict=True`` is discouraged and + the *strict* argument is deprecated. An :class:`.HTMLParser` instance is fed HTML data and calls handler methods when start tags, end tags, text, comments, and other markup elements are @@ -32,11 +40,31 @@ This parser does not check that end tags match start tags or call the end-tag handler for elements which are closed implicitly by closing an outer element. + .. versionchanged:: 3.2 + *strict* argument added. + + .. deprecated-removed:: 3.3 3.5 + The *strict* argument and the strict mode have been deprecated. + The parser is now able to accept and parse invalid markup too. + .. versionchanged:: 3.4 *convert_charrefs* keyword argument added. - .. versionchanged:: 3.5 - The default value for argument *convert_charrefs* is now ``True``. +An exception is defined as well: + + +.. exception:: HTMLParseError + + Exception raised by the :class:`HTMLParser` class when it encounters an error + while parsing and *strict* is ``True``. This exception provides three + attributes: :attr:`msg` is a brief message explaining the error, + :attr:`lineno` is the number of the line on which the broken construct was + detected, and :attr:`offset` is the number of characters into the line at + which the construct starts. + + .. deprecated-removed:: 3.3 3.5 + This exception has been deprecated because it's never raised by the parser + (when the default non-strict mode is used). Example HTML Parser Application @@ -218,7 +246,8 @@ The *data* parameter will be the entire contents of the declaration inside the ```` markup. It is sometimes useful to be overridden by a - derived class. The base class implementation does nothing. + derived class. The base class implementation raises an :exc:`HTMLParseError` + when *strict* is ``True``. .. _htmlparser-examples: @@ -329,3 +358,9 @@ Data : tag soup End tag : p End tag : a + +.. rubric:: Footnotes + +.. [#] For backward compatibility reasons *strict* mode does not raise + exceptions for all non-compliant HTML. That is, some invalid HTML + is tolerated even in *strict* mode. diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/logging.config.rst --- a/Doc/library/logging.config.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/logging.config.rst Fri Jul 25 11:39:11 2014 -0400 @@ -105,7 +105,7 @@ :param disable_existing_loggers: If specified as ``False``, loggers which exist when this call is made are left - enabled. The default is ``True`` because this + alone. The default is ``True`` because this enables old behaviour in a backward- compatible way. This behaviour is to disable any existing loggers unless they or diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/os.rst --- a/Doc/library/os.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/os.rst Fri Jul 25 11:39:11 2014 -0400 @@ -78,10 +78,9 @@ .. versionchanged:: 3.1 On some systems, conversion using the file system encoding may fail. In this - case, Python uses the :ref:`surrogateescape encoding error handler - `, which means that undecodable bytes are replaced by a - Unicode character U+DCxx on decoding, and these are again translated to the - original byte on encoding. + case, Python uses the ``surrogateescape`` encoding error handler, which means + that undecodable bytes are replaced by a Unicode character U+DCxx on + decoding, and these are again translated to the original byte on encoding. The file system encoding must guarantee to successfully decode all bytes @@ -808,17 +807,6 @@ Availability: Unix. -.. function:: get_blocking(fd) - - Get the blocking mode of the file descriptor: ``False`` if the - :data:`O_NONBLOCK` flag is set, ``True`` if the flag is cleared. - - See also :func:`set_blocking` and :meth:`socket.socket.setblocking`. - - Availability: Unix. - - .. versionadded:: 3.5 - .. function:: isatty(fd) Return ``True`` if the file descriptor *fd* is open and connected to a @@ -1119,18 +1107,6 @@ .. versionadded:: 3.3 -.. function:: set_blocking(fd, blocking) - - Set the blocking mode of the specified file descriptor. Set the - :data:`O_NONBLOCK` flag if blocking is ``False``, clear the flag otherwise. - - See also :func:`get_blocking` and :meth:`socket.socket.setblocking`. - - Availability: Unix. - - .. versionadded:: 3.5 - - .. data:: SF_NODISKIO SF_MNOWAIT SF_SYNC diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/pathlib.rst --- a/Doc/library/pathlib.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/pathlib.rst Fri Jul 25 11:39:11 2014 -0400 @@ -791,7 +791,7 @@ the symbolic link's information rather than its target's. -.. method:: Path.mkdir(mode=0o777, parents=False, exist_ok=False) +.. method:: Path.mkdir(mode=0o777, parents=False) Create a new directory at this given path. If *mode* is given, it is combined with the process' ``umask`` value to determine the file mode @@ -805,16 +805,6 @@ If *parents* is false (the default), a missing parent raises :exc:`FileNotFoundError`. - If *exist_ok* is false (the default), an :exc:`FileExistsError` is - raised if the target directory already exists. - - If *exist_ok* is true, :exc:`FileExistsError` exceptions will be - ignored (same behavior as the POSIX ``mkdir -p`` command), but only if the - last path component is not an existing non-directory file. - - .. versionchanged:: 3.5 - The *exist_ok* parameter was added. - .. method:: Path.open(mode='r', buffering=-1, encoding=None, errors=None, newline=None) diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/re.rst --- a/Doc/library/re.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/re.rst Fri Jul 25 11:39:11 2014 -0400 @@ -1333,7 +1333,7 @@ Token = collections.namedtuple('Token', ['typ', 'value', 'line', 'column']) - def tokenize(code): + def tokenize(s): keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'} token_specification = [ ('NUMBER', r'\d+(\.\d*)?'), # Integer or decimal number @@ -1343,26 +1343,26 @@ ('OP', r'[+\-*/]'), # Arithmetic operators ('NEWLINE', r'\n'), # Line endings ('SKIP', r'[ \t]+'), # Skip over spaces and tabs - ('MISMATCH',r'.'), # Any other character ] tok_regex = '|'.join('(?P<%s>%s)' % pair for pair in token_specification) - line_num = 1 - line_start = 0 - for mo in re.finditer(tok_regex, code): - kind = mo.lastgroup - value = mo.group(kind) - if kind == 'NEWLINE': - line_start = mo.end() - line_num += 1 - elif kind == 'SKIP': - pass - elif kind == 'MISMATCH': - raise RuntimeError('%r unexpected on line %d' % (value, line_num)) - else: - if kind == 'ID' and value in keywords: - kind = value - column = mo.start() - line_start - yield Token(kind, value, line_num, column) + get_token = re.compile(tok_regex).match + line = 1 + pos = line_start = 0 + mo = get_token(s) + while mo is not None: + typ = mo.lastgroup + if typ == 'NEWLINE': + line_start = pos + line += 1 + elif typ != 'SKIP': + val = mo.group(typ) + if typ == 'ID' and val in keywords: + typ = val + yield Token(typ, val, line, mo.start()-line_start) + pos = mo.end() + mo = get_token(s, pos) + if pos != len(s): + raise RuntimeError('Unexpected character %r on line %d' %(s[pos], line)) statements = ''' IF quantity THEN @@ -1376,22 +1376,22 @@ The tokenizer produces the following output:: - Token(typ='IF', value='IF', line=2, column=4) - Token(typ='ID', value='quantity', line=2, column=7) - Token(typ='THEN', value='THEN', line=2, column=16) - Token(typ='ID', value='total', line=3, column=8) - Token(typ='ASSIGN', value=':=', line=3, column=14) - Token(typ='ID', value='total', line=3, column=17) - Token(typ='OP', value='+', line=3, column=23) - Token(typ='ID', value='price', line=3, column=25) - Token(typ='OP', value='*', line=3, column=31) - Token(typ='ID', value='quantity', line=3, column=33) - Token(typ='END', value=';', line=3, column=41) - Token(typ='ID', value='tax', line=4, column=8) - Token(typ='ASSIGN', value=':=', line=4, column=12) - Token(typ='ID', value='price', line=4, column=15) - Token(typ='OP', value='*', line=4, column=21) - Token(typ='NUMBER', value='0.05', line=4, column=23) - Token(typ='END', value=';', line=4, column=27) - Token(typ='ENDIF', value='ENDIF', line=5, column=4) - Token(typ='END', value=';', line=5, column=9) + Token(typ='IF', value='IF', line=2, column=5) + Token(typ='ID', value='quantity', line=2, column=8) + Token(typ='THEN', value='THEN', line=2, column=17) + Token(typ='ID', value='total', line=3, column=9) + Token(typ='ASSIGN', value=':=', line=3, column=15) + Token(typ='ID', value='total', line=3, column=18) + Token(typ='OP', value='+', line=3, column=24) + Token(typ='ID', value='price', line=3, column=26) + Token(typ='OP', value='*', line=3, column=32) + Token(typ='ID', value='quantity', line=3, column=34) + Token(typ='END', value=';', line=3, column=42) + Token(typ='ID', value='tax', line=4, column=9) + Token(typ='ASSIGN', value=':=', line=4, column=13) + Token(typ='ID', value='price', line=4, column=16) + Token(typ='OP', value='*', line=4, column=22) + Token(typ='NUMBER', value='0.05', line=4, column=24) + Token(typ='END', value=';', line=4, column=28) + Token(typ='ENDIF', value='ENDIF', line=5, column=5) + Token(typ='END', value=';', line=5, column=10) diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/reprlib.rst --- a/Doc/library/reprlib.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/reprlib.rst Fri Jul 25 11:39:11 2014 -0400 @@ -49,8 +49,8 @@ >>> class MyList(list): ... @recursive_repr() - ... def __repr__(self): - ... return '<' + '|'.join(map(repr, self)) + '>' + ... def __repr__(self): + ... return '<' + '|'.join(map(repr, self)) + '>' ... >>> m = MyList('abc') >>> m.append(m) diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/shutil.rst --- a/Doc/library/shutil.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/shutil.rst Fri Jul 25 11:39:11 2014 -0400 @@ -469,8 +469,7 @@ *base_name* is the name of the file to create, including the path, minus any format-specific extension. *format* is the archive format: one of - "zip", "tar", "bztar" (if the :mod:`bz2` module is available), "xztar" - (if the :mod:`lzma` module is available) or "gztar". + "zip", "tar", "bztar" (if the :mod:`bz2` module is available) or "gztar". *root_dir* is a directory that will be the root directory of the archive; for example, we typically chdir into *root_dir* before creating the @@ -488,9 +487,6 @@ *logger* must be an object compatible with :pep:`282`, usually an instance of :class:`logging.Logger`. - .. versionchanged:: 3.5 - Added support for the *xztar* format. - .. function:: get_archive_formats() @@ -501,7 +497,6 @@ - *gztar*: gzip'ed tar-file - *bztar*: bzip2'ed tar-file (if the :mod:`bz2` module is available.) - - *xztar*: xz'ed tar-file (if the :mod:`lzma` module is available.) - *tar*: uncompressed tar file - *zip*: ZIP file @@ -572,7 +567,6 @@ - *gztar*: gzip'ed tar-file - *bztar*: bzip2'ed tar-file (if the :mod:`bz2` module is available.) - - *xztar*: xz'ed tar-file (if the :mod:`lzma` module is available.) - *tar*: uncompressed tar file - *zip*: ZIP file diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/signal.rst --- a/Doc/library/signal.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/signal.rst Fri Jul 25 11:39:11 2014 -0400 @@ -318,9 +318,6 @@ attempting to call it from other threads will cause a :exc:`ValueError` exception to be raised. - .. versionchanged:: 3.5 - On Windows, the function now also supports socket handles. - .. function:: siginterrupt(signalnum, flag) diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/ssl.rst --- a/Doc/library/ssl.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/ssl.rst Fri Jul 25 11:39:11 2014 -0400 @@ -808,7 +808,7 @@ Perform the SSL setup handshake. .. versionchanged:: 3.4 - The handshake method also performs :func:`match_hostname` when the + The handshake method also performce :func:`match_hostname` when the :attr:`~SSLContext.check_hostname` attribute of the socket's :attr:`~SSLSocket.context` is true. @@ -1132,7 +1132,7 @@ returned. Other return values will result in a TLS fatal error with :const:`ALERT_DESCRIPTION_INTERNAL_ERROR`. - If there is an IDNA decoding error on the server name, the TLS connection + If there is a IDNA decoding error on the server name, the TLS connection will terminate with an :const:`ALERT_DESCRIPTION_INTERNAL_ERROR` fatal TLS alert message to the client. diff -r 79e469ae13b7 -r 01438f18ee18 Doc/library/timeit.rst --- a/Doc/library/timeit.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/library/timeit.rst Fri Jul 25 11:39:11 2014 -0400 @@ -28,23 +28,22 @@ .. code-block:: sh - $ python3 -m timeit '"-".join(str(n) for n in range(100))' - 10000 loops, best of 3: 30.2 usec per loop - $ python3 -m timeit '"-".join([str(n) for n in range(100)])' - 10000 loops, best of 3: 27.5 usec per loop - $ python3 -m timeit '"-".join(map(str, range(100)))' - 10000 loops, best of 3: 23.2 usec per loop + $ python -m timeit '"-".join(str(n) for n in range(100))' + 10000 loops, best of 3: 40.3 usec per loop + $ python -m timeit '"-".join([str(n) for n in range(100)])' + 10000 loops, best of 3: 33.4 usec per loop + $ python -m timeit '"-".join(map(str, range(100)))' + 10000 loops, best of 3: 25.2 usec per loop This can be achieved from the :ref:`python-interface` with:: >>> import timeit >>> timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) - 0.3018611848820001 + 0.8187260627746582 >>> timeit.timeit('"-".join([str(n) for n in range(100)])', number=10000) - 0.2727368790656328 + 0.7288308143615723 >>> timeit.timeit('"-".join(map(str, range(100)))', number=10000) - 0.23702679807320237 - + 0.5858950614929199 Note however that :mod:`timeit` will automatically determine the number of repetitions only when the command-line interface is used. In the diff -r 79e469ae13b7 -r 01438f18ee18 Doc/reference/lexical_analysis.rst --- a/Doc/reference/lexical_analysis.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/reference/lexical_analysis.rst Fri Jul 25 11:39:11 2014 -0400 @@ -689,7 +689,7 @@ The following tokens are operators:: - + - * ** / // % @ + + - * ** / // % << >> & | ^ ~ < > <= >= == != @@ -705,7 +705,7 @@ ( ) [ ] { } , : . ; @ = -> - += -= *= /= //= %= @= + += -= *= /= //= %= &= |= ^= >>= <<= **= The period can also occur in floating-point and imaginary literals. A sequence diff -r 79e469ae13b7 -r 01438f18ee18 Doc/tutorial/classes.rst --- a/Doc/tutorial/classes.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/tutorial/classes.rst Fri Jul 25 11:39:11 2014 -0400 @@ -802,7 +802,7 @@ for char in "123": print(char) for line in open("myfile.txt"): - print(line, end='') + print(line) This style of access is clear, concise, and convenient. The use of iterators pervades and unifies Python. Behind the scenes, the :keyword:`for` statement diff -r 79e469ae13b7 -r 01438f18ee18 Doc/whatsnew/3.5.rst --- a/Doc/whatsnew/3.5.rst Fri Aug 08 17:24:06 2014 +0300 +++ b/Doc/whatsnew/3.5.rst Fri Jul 25 11:39:11 2014 -0400 @@ -335,12 +335,6 @@ attribute, the qualified name, which is now used for the representation of a generator (``repr(gen)``). See :issue:`21205`. -* The deprecated "strict" mode and argument of :class:`~html.parser.HTMLParser`, - :meth:`HTMLParser.error`, and the :exc:`HTMLParserError` exception have been - removed (contributed by Ezio Melotti in :issue:`15114`). - The *convert_charrefs* argument of :class:`~html.parser.HTMLParser` is - now ``True`` by default (contributed by Berker Peksag in :issue:`21047`). - Changes in the C API -------------------- diff -r 79e469ae13b7 -r 01438f18ee18 Grammar/Grammar --- a/Grammar/Grammar Fri Aug 08 17:24:06 2014 +0300 +++ b/Grammar/Grammar Fri Jul 25 11:39:11 2014 -0400 @@ -89,7 +89,7 @@ not_test: 'not' not_test | comparison comparison: expr (comp_op expr)* # <> isn't actually a valid comparison operator in Python. It's here for the -# sake of a __future__ import described in PEP 401 (which really works :-) +# sake of a __future__ import described in PEP 401 comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' star_expr: '*' expr expr: xor_expr ('|' xor_expr)* diff -r 79e469ae13b7 -r 01438f18ee18 Include/bytes_methods.h --- a/Include/bytes_methods.h Fri Aug 08 17:24:06 2014 +0300 +++ b/Include/bytes_methods.h Fri Jul 25 11:39:11 2014 -0400 @@ -21,8 +21,8 @@ extern void _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len); extern void _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len); -/* The maketrans() static method. */ -extern PyObject* _Py_bytes_maketrans(PyObject *frm, PyObject *to); +/* This one gets the raw argument list. */ +extern PyObject* _Py_bytes_maketrans(PyObject *args); /* Shared __doc__ strings. */ extern const char _Py_isspace__doc__[]; diff -r 79e469ae13b7 -r 01438f18ee18 Include/fileutils.h --- a/Include/fileutils.h Fri Aug 08 17:24:06 2014 +0300 +++ b/Include/fileutils.h Fri Jul 25 11:39:11 2014 -0400 @@ -7,11 +7,11 @@ PyAPI_FUNC(PyObject *) _Py_device_encoding(int); -PyAPI_FUNC(wchar_t *) Py_DecodeLocale( +PyAPI_FUNC(wchar_t *) _Py_char2wchar( const char *arg, size_t *size); -PyAPI_FUNC(char*) Py_EncodeLocale( +PyAPI_FUNC(char*) _Py_wchar2char( const wchar_t *text, size_t *error_pos); @@ -70,14 +70,7 @@ int *atomic_flag_works); PyAPI_FUNC(int) _Py_dup(int fd); - -#ifndef MS_WINDOWS -PyAPI_FUNC(int) _Py_get_blocking(int fd); - -PyAPI_FUNC(int) _Py_set_blocking(int fd, int blocking); -#endif /* !MS_WINDOWS */ - -#endif /* Py_LIMITED_API */ +#endif #ifdef __cplusplus } diff -r 79e469ae13b7 -r 01438f18ee18 Include/methodobject.h --- a/Include/methodobject.h Fri Aug 08 17:24:06 2014 +0300 +++ b/Include/methodobject.h Fri Jul 25 11:39:11 2014 -0400 @@ -77,7 +77,6 @@ PyMethodDef *m_ml; /* Description of the C function to call */ PyObject *m_self; /* Passed as 'self' arg to the C func, can be NULL */ PyObject *m_module; /* The __module__ attribute, can be anything */ - PyObject *m_weakreflist; /* List of weak references */ } PyCFunctionObject; #endif diff -r 79e469ae13b7 -r 01438f18ee18 Lib/_pyio.py --- a/Lib/_pyio.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/_pyio.py Fri Jul 25 11:39:11 2014 -0400 @@ -808,14 +808,13 @@ .format(self.__class__.__name__)) def __repr__(self): - modname = self.__class__.__module__ - clsname = self.__class__.__qualname__ + clsname = self.__class__.__name__ try: name = self.name except AttributeError: - return "<{}.{}>".format(modname, clsname) + return "<_pyio.{0}>".format(clsname) else: - return "<{}.{} name={!r}>".format(modname, clsname, name) + return "<_pyio.{0} name={1!r}>".format(clsname, name) ### Lower-level APIs ### @@ -1636,8 +1635,7 @@ # - "chars_..." for integer variables that count decoded characters def __repr__(self): - result = "<{}.{}".format(self.__class__.__module__, - self.__class__.__qualname__) + result = "<_pyio.TextIOWrapper" try: name = self.name except AttributeError: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/events.py --- a/Lib/asyncio/events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/events.py Fri Jul 25 11:39:11 2014 -0400 @@ -10,12 +10,11 @@ import functools import inspect -import reprlib +import subprocess +import traceback +import threading import socket -import subprocess import sys -import threading -import traceback _PY34 = sys.version_info >= (3, 4) @@ -37,12 +36,8 @@ def _format_args(args): - """Format function arguments. - - Special case for a single parameter: ('hello',) is formatted as ('hello'). - """ - # use reprlib to limit the length of the output - args_repr = reprlib.repr(args) + # function formatting ('hello',) as ('hello') + args_repr = repr(args) if len(args) == 1 and args_repr.endswith(',)'): args_repr = args_repr[:-2] + ')' return args_repr diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/futures.py --- a/Lib/asyncio/futures.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/futures.py Fri Jul 25 11:39:11 2014 -0400 @@ -7,7 +7,6 @@ import concurrent.futures._base import logging -import reprlib import sys import traceback @@ -176,25 +175,20 @@ format_cb(cb[-1])) return 'cb=[%s]' % cb - def _repr_info(self): + def _format_result(self): + if self._state != _FINISHED: + return None + elif self._exception is not None: + return 'exception={!r}'.format(self._exception) + else: + return 'result={!r}'.format(self._result) + + def __repr__(self): info = [self._state.lower()] if self._state == _FINISHED: - if self._exception is not None: - info.append('exception={!r}'.format(self._exception)) - else: - # use reprlib to limit the length of the output, especially - # for very long strings - result = reprlib.repr(self._result) - info.append('result={}'.format(result)) + info.append(self._format_result()) if self._callbacks: info.append(self._format_callbacks()) - if self._source_traceback: - frame = self._source_traceback[-1] - info.append('created at %s:%s' % (frame[0], frame[1])) - return info - - def __repr__(self): - info = self._repr_info() return '<%s %s>' % (self.__class__.__name__, ' '.join(info)) # On Python 3.3 or older, objects with a destructor part of a reference diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/locks.py --- a/Lib/asyncio/locks.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/locks.py Fri Jul 25 11:39:11 2014 -0400 @@ -255,17 +255,14 @@ A new Lock object is created and used as the underlying lock. """ - def __init__(self, lock=None, *, loop=None): + def __init__(self, *, loop=None): if loop is not None: self._loop = loop else: self._loop = events.get_event_loop() - if lock is None: - lock = Lock(loop=self._loop) - elif lock._loop is not self._loop: - raise ValueError("loop argument must agree with lock") - + # Lock as an attribute as in threading.Condition. + lock = Lock(loop=self._loop) self._lock = lock # Export the lock's locked(), acquire() and release() methods. self.locked = lock.locked diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/proactor_events.py --- a/Lib/asyncio/proactor_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/proactor_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -385,18 +385,12 @@ self._selector = None def sock_recv(self, sock, n): - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") return self._proactor.recv(sock, n) def sock_sendall(self, sock, data): - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") return self._proactor.send(sock, data) def sock_connect(self, sock, address): - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") try: base_events._check_resolved_address(sock, address) except ValueError as err: @@ -407,8 +401,6 @@ return self._proactor.connect(sock, address) def sock_accept(self, sock): - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") return self._proactor.accept(sock) def _socketpair(self): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/selector_events.py --- a/Lib/asyncio/selector_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/selector_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -120,10 +120,7 @@ try: csock.send(b'\0') except OSError: - if self._debug: - logger.debug("Fail to write a null byte into the " - "self-pipe socket", - exc_info=True) + pass def _start_serving(self, protocol_factory, sock, sslcontext=None, server=None): @@ -256,8 +253,6 @@ This method is a coroutine. """ - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") fut = futures.Future(loop=self) self._sock_recv(fut, False, sock, n) return fut @@ -294,8 +289,6 @@ This method is a coroutine. """ - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") fut = futures.Future(loop=self) if data: self._sock_sendall(fut, False, sock, data) @@ -337,8 +330,6 @@ This method is a coroutine. """ - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") fut = futures.Future(loop=self) try: base_events._check_resolved_address(sock, address) @@ -380,8 +371,6 @@ This method is a coroutine. """ - if self.get_debug() and sock.gettimeout() != 0: - raise ValueError("the socket must be non-blocking") fut = futures.Future(loop=self) self._sock_accept(fut, False, sock) return fut diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/tasks.py --- a/Lib/asyncio/tasks.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/tasks.py Fri Jul 25 11:39:11 2014 -0400 @@ -92,19 +92,30 @@ self._loop.call_exception_handler(context) futures.Future.__del__(self) - def _repr_info(self): - info = super()._repr_info() - + def __repr__(self): + info = [] if self._must_cancel: - # replace status - info[0] = 'cancelling' + info.append('cancelling') + else: + info.append(self._state.lower()) coro = coroutines._format_coroutine(self._coro) - info.insert(1, 'coro=<%s>' % coro) + info.append('coro=<%s>' % coro) + + if self._source_traceback: + frame = self._source_traceback[-1] + info.append('created at %s:%s' % (frame[0], frame[1])) + + if self._state == futures._FINISHED: + info.append(self._format_result()) + + if self._callbacks: + info.append(self._format_callbacks()) if self._fut_waiter is not None: - info.insert(2, 'wait_for=%r' % self._fut_waiter) - return info + info.append('wait_for=%r' % self._fut_waiter) + + return '<%s %s>' % (self.__class__.__name__, ' '.join(info)) def get_stack(self, *, limit=None): """Return the list of stack frames for this task's coroutine. diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/unix_events.py --- a/Lib/asyncio/unix_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/unix_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -1,6 +1,7 @@ """Selector event loop for Unix with signal handling.""" import errno +import fcntl import os import signal import socket @@ -258,14 +259,10 @@ return server -if hasattr(os, 'set_blocking'): - def _set_nonblocking(fd): - os.set_blocking(fd, False) -else: - def _set_nonblocking(fd): - flags = fcntl.fcntl(fd, fcntl.F_GETFL) - flags = flags | os.O_NONBLOCK - fcntl.fcntl(fd, fcntl.F_SETFL, flags) +def _set_nonblocking(fd): + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(fd, fcntl.F_SETFL, flags) class _UnixReadPipeTransport(transports.ReadTransport): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncio/windows_events.py --- a/Lib/asyncio/windows_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncio/windows_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -42,12 +42,16 @@ del self._source_traceback[-1] self._ov = ov - def _repr_info(self): - info = super()._repr_info() + def __repr__(self): + info = [self._state.lower()] if self._ov is not None: state = 'pending' if self._ov.pending else 'completed' - info.insert(1, 'overlapped=<%s, %#x>' % (state, self._ov.address)) - return info + info.append('overlapped=<%s, %#x>' % (state, self._ov.address)) + if self._state == futures._FINISHED: + info.append(self._format_result()) + if self._callbacks: + info.append(self._format_callbacks()) + return '<%s %s>' % (self.__class__.__name__, ' '.join(info)) def _cancel_overlapped(self): if self._ov is None: @@ -73,22 +77,12 @@ super().set_exception(exception) self._cancel_overlapped() - def set_result(self, result): - super().set_result(result) - self._ov = None - class _WaitHandleFuture(futures.Future): """Subclass of Future which represents a wait handle.""" - def __init__(self, iocp, ov, handle, wait_handle, *, loop=None): + def __init__(self, handle, wait_handle, *, loop=None): super().__init__(loop=loop) - if self._source_traceback: - del self._source_traceback[-1] - # iocp and ov are only used by cancel() to notify IocpProactor - # that the wait was cancelled - self._iocp = iocp - self._ov = ov self._handle = handle self._wait_handle = wait_handle @@ -97,16 +91,19 @@ return (_winapi.WaitForSingleObject(self._handle, 0) == _winapi.WAIT_OBJECT_0) - def _repr_info(self): - info = super()._repr_info() - info.insert(1, 'handle=%#x' % self._handle) + def __repr__(self): + info = [self._state.lower()] if self._wait_handle: - state = 'signaled' if self._poll() else 'waiting' - info.insert(1, 'wait_handle=<%s, %#x>' - % (state, self._wait_handle)) - return info + state = 'pending' if self._poll() else 'completed' + info.append('wait_handle=<%s, %#x>' % (state, self._wait_handle)) + info.append('handle=<%#x>' % self._handle) + if self._state == futures._FINISHED: + info.append(self._format_result()) + if self._callbacks: + info.append(self._format_callbacks()) + return '<%s %s>' % (self.__class__.__name__, ' '.join(info)) - def _unregister_wait(self): + def _unregister(self): if self._wait_handle is None: return try: @@ -116,25 +113,10 @@ raise # ERROR_IO_PENDING is not an error, the wait was unregistered self._wait_handle = None - self._iocp = None - self._ov = None def cancel(self): - result = super().cancel() - if self._ov is not None: - # signal the cancellation to the overlapped object - _overlapped.PostQueuedCompletionStatus(self._iocp, True, - 0, self._ov.address) - self._unregister_wait() - return result - - def set_exception(self, exception): - super().set_exception(exception) - self._unregister_wait() - - def set_result(self, result): - super().set_result(result) - self._unregister_wait() + self._unregister() + return super().cancel() class PipeServer(object): @@ -383,10 +365,7 @@ ov.getresult() return pipe - # FIXME: Tulip issue 196: why to we neeed register=False? - # See also the comment in the _register() method - return self._register(ov, pipe, finish_accept_pipe, - register=False) + return self._register(ov, pipe, finish_accept_pipe) def connect_pipe(self, address): ov = _overlapped.Overlapped(NULL) @@ -419,9 +398,7 @@ ov = _overlapped.Overlapped(NULL) wh = _overlapped.RegisterWaitWithQueue( handle, self._iocp, ov.address, ms) - f = _WaitHandleFuture(self._iocp, ov, handle, wh, loop=self._loop) - if f._source_traceback: - del f._source_traceback[-1] + f = _WaitHandleFuture(handle, wh, loop=self._loop) def finish_wait_for_handle(trans, key, ov): # Note that this second wait means that we should only use @@ -430,17 +407,12 @@ # or semaphores are not. Also note if the handle is # signalled and then quickly reset, then we may return # False even though we have not timed out. - return f._poll() + try: + return f._poll() + finally: + f._unregister() - if f._poll(): - try: - result = f._poll() - except OSError as exc: - f.set_exception(exc) - else: - f.set_result(result) - - self._cache[ov.address] = (f, ov, 0, finish_wait_for_handle) + self._cache[ov.address] = (f, ov, None, finish_wait_for_handle) return f def _register_with_iocp(self, obj): @@ -453,15 +425,17 @@ # to avoid sending notifications to completion port of ops # that succeed immediately. - def _register(self, ov, obj, callback, - wait_for_post=False, register=True): + def _register(self, ov, obj, callback, wait_for_post=False): # Return a future which will be set with the result of the # operation when it completes. The future's value is actually # the value returned by callback(). f = _OverlappedFuture(ov, loop=self._loop) - if f._source_traceback: - del f._source_traceback[-1] - if not ov.pending and not wait_for_post: + if ov.pending or wait_for_post: + # Register the overlapped operation for later. Note that + # we only store obj to prevent it from being garbage + # collected too early. + self._cache[ov.address] = (f, ov, obj, callback) + else: # The operation has completed, so no need to postpone the # work. We cannot take this short cut if we need the # NumberOfBytes, CompletionKey values returned by @@ -472,23 +446,6 @@ f.set_exception(e) else: f.set_result(value) - # Even if GetOverlappedResult() was called, we have to wait for the - # notification of the completion in GetQueuedCompletionStatus(). - # Register the overlapped operation to keep a reference to the - # OVERLAPPED object, otherwise the memory is freed and Windows may - # read uninitialized memory. - # - # For an unknown reason, ConnectNamedPipe() behaves differently: - # the completion is not notified by GetOverlappedResult() if we - # already called GetOverlappedResult(). For this specific case, we - # don't expect notification (register is set to False). - else: - register = True - if register: - # Register the overlapped operation for later. Note that - # we only store obj to prevent it from being garbage - # collected too early. - self._cache[ov.address] = (f, ov, obj, callback) return f def _get_accept_socket(self, family): @@ -507,36 +464,23 @@ ms = math.ceil(timeout * 1e3) if ms >= INFINITE: raise ValueError("timeout too big") - while True: status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms) if status is None: return - ms = 0 - err, transferred, key, address = status try: f, ov, obj, callback = self._cache.pop(address) except KeyError: - if self._loop.get_debug(): - self._loop.call_exception_handler({ - 'message': ('GetQueuedCompletionStatus() returned an ' - 'unexpected event'), - 'status': ('err=%s transferred=%s key=%#x address=%#x' - % (err, transferred, key, address)), - }) - # key is either zero, or it is used to return a pipe # handle which should be closed to avoid a leak. if key not in (0, _overlapped.INVALID_HANDLE_VALUE): _winapi.CloseHandle(key) + ms = 0 continue - if obj in self._stopped_serving: f.cancel() - # Don't call the callback if _register() already read the result or - # if the overlapped has been cancelled - elif not f.done(): + elif not f.cancelled(): try: value = callback(transferred, key, ov) except OSError as e: @@ -545,6 +489,7 @@ else: f.set_result(value) self._results.append(f) + ms = 0 def _stop_serving(self, obj): # obj is a socket or pipe handle. It will be closed in @@ -560,9 +505,6 @@ # queues a task to Windows' thread pool. This cannot # be cancelled, so just forget it. del self._cache[address] - # FIXME: Tulip issue 196: remove this case, it should not happen - elif fut.done() and not fut.cancelled(): - del self._cache[address] else: try: fut.cancel() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/asyncore.py --- a/Lib/asyncore.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/asyncore.py Fri Jul 25 11:39:11 2014 -0400 @@ -590,6 +590,8 @@ # Regardless, this is useful for pipes, and stdin/stdout... if os.name == 'posix': + import fcntl + class file_wrapper: # Here we override just enough to make a file # look like a socket for the purposes of asyncore. @@ -640,7 +642,9 @@ pass self.set_file(fd) # set it to non-blocking mode - os.set_blocking(fd, False) + flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(fd, fcntl.F_SETFL, flags) def set_file(self, fd): self.socket = file_wrapper(fd) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/concurrent/futures/_base.py --- a/Lib/concurrent/futures/_base.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/concurrent/futures/_base.py Fri Jul 25 11:39:11 2014 -0400 @@ -302,20 +302,17 @@ with self._condition: if self._state == FINISHED: if self._exception: - return '<%s at %#x state=%s raised %s>' % ( - self.__class__.__name__, - id(self), + return '' % ( + hex(id(self)), _STATE_TO_DESCRIPTION_MAP[self._state], self._exception.__class__.__name__) else: - return '<%s at %#x state=%s returned %s>' % ( - self.__class__.__name__, - id(self), + return '' % ( + hex(id(self)), _STATE_TO_DESCRIPTION_MAP[self._state], self._result.__class__.__name__) - return '<%s at %#x state=%s>' % ( - self.__class__.__name__, - id(self), + return '' % ( + hex(id(self)), _STATE_TO_DESCRIPTION_MAP[self._state]) def cancel(self): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/csv.py --- a/Lib/csv.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/csv.py Fri Jul 25 11:39:11 2014 -0400 @@ -24,7 +24,7 @@ This must be subclassed (see csv.excel). Valid attributes are: delimiter, quotechar, escapechar, doublequote, skipinitialspace, - lineterminator, quoting. + skipinitialwhitespace, lineterminator, quoting. """ _name = "" @@ -35,6 +35,7 @@ escapechar = None doublequote = None skipinitialspace = None + skipinitialwhitespace = None lineterminator = None quoting = None @@ -56,6 +57,7 @@ quotechar = '"' doublequote = True skipinitialspace = False + skipinitialwhitespace = False lineterminator = '\r\n' quoting = QUOTE_MINIMAL register_dialect("excel", excel) @@ -71,6 +73,7 @@ quotechar = '"' doublequote = True skipinitialspace = False + skipinitialwhitespace = False lineterminator = '\n' quoting = QUOTE_ALL register_dialect("unix", unix_dialect) @@ -199,6 +202,7 @@ # _csv.reader won't accept a quotechar of '' dialect.quotechar = quotechar or '"' dialect.skipinitialspace = skipinitialspace + dialect.skipinitialwhitespace = False return dialect diff -r 79e469ae13b7 -r 01438f18ee18 Lib/datetime.py --- a/Lib/datetime.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/datetime.py Fri Jul 25 11:39:11 2014 -0400 @@ -414,19 +414,15 @@ def __repr__(self): if self._microseconds: - return "%s.%s(%d, %d, %d)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._days, - self._seconds, - self._microseconds) + return "%s(%d, %d, %d)" % ('datetime.' + self.__class__.__name__, + self._days, + self._seconds, + self._microseconds) if self._seconds: - return "%s.%s(%d, %d)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._days, - self._seconds) - return "%s.%s(%d)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._days) + return "%s(%d, %d)" % ('datetime.' + self.__class__.__name__, + self._days, + self._seconds) + return "%s(%d)" % ('datetime.' + self.__class__.__name__, self._days) def __str__(self): mm, ss = divmod(self._seconds, 60) @@ -704,11 +700,10 @@ >>> repr(dt) 'datetime.datetime(2010, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)' """ - return "%s.%s(%d, %d, %d)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._year, - self._month, - self._day) + return "%s(%d, %d, %d)" % ('datetime.' + self.__class__.__name__, + self._year, + self._month, + self._day) # XXX These shouldn't depend on time.localtime(), because that # clips the usable dates to [1970 .. 2038). At least ctime() is # easily done without using strftime() -- that's better too because @@ -1160,9 +1155,8 @@ s = ", %d" % self._second else: s = "" - s= "%s.%s(%d, %d%s)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._hour, self._minute, s) + s= "%s(%d, %d%s)" % ('datetime.' + self.__class__.__name__, + self._hour, self._minute, s) if self._tzinfo is not None: assert s[-1:] == ")" s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")" @@ -1575,9 +1569,8 @@ del L[-1] if L[-1] == 0: del L[-1] - s = "%s.%s(%s)" % (self.__class__.__module__, - self.__class__.__qualname__, - ", ".join(map(str, L))) + s = ", ".join(map(str, L)) + s = "%s(%s)" % ('datetime.' + self.__class__.__name__, s) if self._tzinfo is not None: assert s[-1:] == ")" s = s[:-1] + ", tzinfo=%r" % self._tzinfo + ")" @@ -1864,12 +1857,10 @@ if self is self.utc: return 'datetime.timezone.utc' if self._name is None: - return "%s.%s(%r)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._offset) - return "%s.%s(%r, %r)" % (self.__class__.__module__, - self.__class__.__qualname__, - self._offset, self._name) + return "%s(%r)" % ('datetime.' + self.__class__.__name__, + self._offset) + return "%s(%r, %r)" % ('datetime.' + self.__class__.__name__, + self._offset, self._name) def __str__(self): return self.tzname(None) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/difflib.py --- a/Lib/difflib.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/difflib.py Fri Jul 25 11:39:11 2014 -0400 @@ -30,7 +30,7 @@ 'Differ','IS_CHARACTER_JUNK', 'IS_LINE_JUNK', 'context_diff', 'unified_diff', 'HtmlDiff', 'Match'] -from heapq import nlargest as _nlargest +import heapq from collections import namedtuple as _namedtuple Match = _namedtuple('Match', 'a b size') @@ -729,7 +729,7 @@ result.append((s.ratio(), x)) # Move the best scorers to head of list - result = _nlargest(n, result) + result = heapq.nlargest(n, result) # Strip scores for the best n matches return [x for score, x in result] @@ -1410,7 +1410,7 @@ change_re.sub(record_sub_info,markers) # process each tuple inserting our special marks that won't be # noticed by an xml/html escaper. - for key,(begin,end) in reversed(sub_info): + for key,(begin,end) in sub_info[::-1]: text = text[0:begin]+'\0'+key+text[begin:end]+'\1'+text[end:] text = text[2:] # Handle case of add/delete entire line @@ -1448,7 +1448,10 @@ # are a concatenation of the first character of each of the 4 lines # so we can do some very readable comparisons. while len(lines) < 4: - lines.append(next(diff_lines_iterator, 'X')) + try: + lines.append(next(diff_lines_iterator)) + except StopIteration: + lines.append('X') s = ''.join([line[0] for line in lines]) if s.startswith('X'): # When no more lines, pump out any remaining blank lines so the @@ -1511,7 +1514,7 @@ num_blanks_to_yield -= 1 yield ('','\n'),None,True if s.startswith('X'): - return + raise StopIteration else: yield from_line,to_line,True diff -r 79e469ae13b7 -r 01438f18ee18 Lib/doctest.py --- a/Lib/doctest.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/doctest.py Fri Jul 25 11:39:11 2014 -0400 @@ -533,9 +533,8 @@ examples = '1 example' else: examples = '%d examples' % len(self.examples) - return ('<%s %s from %s:%s (%s)>' % - (self.__class__.__name__, - self.name, self.filename, self.lineno, examples)) + return ('' % + (self.name, self.filename, self.lineno, examples)) def __eq__(self, other): if type(self) is not type(other): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/email/_header_value_parser.py --- a/Lib/email/_header_value_parser.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/email/_header_value_parser.py Fri Jul 25 11:39:11 2014 -0400 @@ -2897,7 +2897,7 @@ try: token, value = get_token(value) except errors.HeaderParseError: - disp_header.defects.append(errors.InvalidHeaderDefect( + ctype.defects.append(errors.InvalidHeaderDefect( "Expected content disposition but found {!r}".format(value))) _find_mime_parameters(disp_header, value) return disp_header @@ -2928,8 +2928,8 @@ try: token, value = get_token(value) except errors.HeaderParseError: - cte_header.defects.append(errors.InvalidHeaderDefect( - "Expected content transfer encoding but found {!r}".format(value))) + ctype.defects.append(errors.InvalidHeaderDefect( + "Expected content trnasfer encoding but found {!r}".format(value))) else: cte_header.append(token) cte_header.cte = token.value.strip().lower() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/email/headerregistry.py --- a/Lib/email/headerregistry.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/email/headerregistry.py Fri Jul 25 11:39:11 2014 -0400 @@ -80,8 +80,7 @@ return lp def __repr__(self): - return "{}(display_name={!r}, username={!r}, domain={!r})".format( - self.__class__.__name__, + return "Address(display_name={!r}, username={!r}, domain={!r})".format( self.display_name, self.username, self.domain) def __str__(self): @@ -132,8 +131,7 @@ return self._addresses def __repr__(self): - return "{}(display_name={!r}, addresses={!r}".format( - self.__class__.__name__, + return "Group(display_name={!r}, addresses={!r}".format( self.display_name, self.addresses) def __str__(self): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/fractions.py --- a/Lib/fractions.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/fractions.py Fri Jul 25 11:39:11 2014 -0400 @@ -280,8 +280,7 @@ def __repr__(self): """repr(self)""" - return '%s(%s, %s)' % (self.__class__.__name__, - self._numerator, self._denominator) + return ('Fraction(%s, %s)' % (self._numerator, self._denominator)) def __str__(self): """str(self)""" diff -r 79e469ae13b7 -r 01438f18ee18 Lib/html/entities.py --- a/Lib/html/entities.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/html/entities.py Fri Jul 25 11:39:11 2014 -0400 @@ -1,8 +1,5 @@ """HTML character entity references.""" -__all__ = ['html5', 'name2codepoint', 'codepoint2name', 'entitydefs'] - - # maps the HTML entity name to the Unicode codepoint name2codepoint = { 'AElig': 0x00c6, # latin capital letter AE = latin capital ligature AE, U+00C6 ISOlat1 diff -r 79e469ae13b7 -r 01438f18ee18 Lib/html/parser.py --- a/Lib/html/parser.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/html/parser.py Fri Jul 25 11:39:11 2014 -0400 @@ -29,15 +29,35 @@ piclose = re.compile('>') commentclose = re.compile(r'--\s*>') # Note: -# 1) if you change tagfind/attrfind remember to update locatestarttagend too; -# 2) if you change tagfind/attrfind and/or locatestarttagend the parser will +# 1) the strict attrfind isn't really strict, but we can't make it +# correctly strict without breaking backward compatibility; +# 2) if you change tagfind/attrfind remember to update locatestarttagend too; +# 3) if you change tagfind/attrfind and/or locatestarttagend the parser will # explode, so don't do it. +tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*') # see http://www.w3.org/TR/html5/tokenization.html#tag-open-state # and http://www.w3.org/TR/html5/tokenization.html#tag-name-state tagfind_tolerant = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*') +attrfind = re.compile( + r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*' + r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?') attrfind_tolerant = re.compile( r'((?<=[\'"\s/])[^\s/>][^\s/=>]*)(\s*=+\s*' r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*') +locatestarttagend = re.compile(r""" + <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name + (?:\s+ # whitespace before attribute name + (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name + (?:\s*=\s* # value indicator + (?:'[^']*' # LITA-enclosed value + |\"[^\"]*\" # LIT-enclosed value + |[^'\">\s]+ # bare value + ) + )? + ) + )* + \s* # trailing whitespace +""", re.VERBOSE) locatestarttagend_tolerant = re.compile(r""" <[a-zA-Z][^\t\n\r\f />\x00]* # tag name (?:[\s/]* # optional whitespace before attribute name @@ -59,6 +79,25 @@ endtagfind = re.compile('') +class HTMLParseError(Exception): + """Exception raised for all parse errors.""" + + def __init__(self, msg, position=(None, None)): + assert msg + self.msg = msg + self.lineno = position[0] + self.offset = position[1] + + def __str__(self): + result = self.msg + if self.lineno is not None: + result = result + ", at line %d" % self.lineno + if self.offset is not None: + result = result + ", column %d" % (self.offset + 1) + return result + + +_default_sentinel = object() class HTMLParser(_markupbase.ParserBase): """Find tags and other markup and call handler functions. @@ -84,12 +123,27 @@ CDATA_CONTENT_ELEMENTS = ("script", "style") - def __init__(self, *, convert_charrefs=True): + def __init__(self, strict=_default_sentinel, *, + convert_charrefs=_default_sentinel): """Initialize and reset this instance. - If convert_charrefs is True (the default), all character references + If convert_charrefs is True (default: False), all character references are automatically converted to the corresponding Unicode characters. + If strict is set to False (the default) the parser will parse invalid + markup, otherwise it will raise an error. Note that the strict mode + and argument are deprecated. """ + if strict is not _default_sentinel: + warnings.warn("The strict argument and mode are deprecated.", + DeprecationWarning, stacklevel=2) + else: + strict = False # default + self.strict = strict + if convert_charrefs is _default_sentinel: + convert_charrefs = False # default + warnings.warn("The value of convert_charrefs will become True in " + "3.5. You are encouraged to set the value explicitly.", + DeprecationWarning, stacklevel=2) self.convert_charrefs = convert_charrefs self.reset() @@ -114,6 +168,11 @@ """Handle any buffered data.""" self.goahead(1) + def error(self, message): + warnings.warn("The 'error' method is deprecated.", + DeprecationWarning, stacklevel=2) + raise HTMLParseError(message, self.getpos()) + __starttag_text = None def get_starttag_text(self): @@ -168,7 +227,10 @@ elif startswith("', i + 1) if k < 0: k = rawdata.find('<', i + 1) @@ -218,10 +282,13 @@ if match: # match.group() will contain at least 2 chars if end and match.group() == rawdata[i:]: - k = match.end() - if k <= i: - k = n - i = self.updatepos(i, i + 1) + if self.strict: + self.error("EOF in middle of entity or char ref") + else: + k = match.end() + if k <= i: + k = n + i = self.updatepos(i, i + 1) # incomplete break elif (i + 1) < n: @@ -300,12 +367,18 @@ # Now parse the data between i+1 and j into a tag and attrs attrs = [] - match = tagfind_tolerant.match(rawdata, i+1) + if self.strict: + match = tagfind.match(rawdata, i+1) + else: + match = tagfind_tolerant.match(rawdata, i+1) assert match, 'unexpected call to parse_starttag()' k = match.end() self.lasttag = tag = match.group(1).lower() while k < endpos: - m = attrfind_tolerant.match(rawdata, k) + if self.strict: + m = attrfind.match(rawdata, k) + else: + m = attrfind_tolerant.match(rawdata, k) if not m: break attrname, rest, attrvalue = m.group(1, 2, 3) @@ -328,6 +401,9 @@ - self.__starttag_text.rfind("\n") else: offset = offset + len(self.__starttag_text) + if self.strict: + self.error("junk characters in start tag: %r" + % (rawdata[k:endpos][:20],)) self.handle_data(rawdata[i:endpos]) return endpos if end.endswith('/>'): @@ -343,7 +419,10 @@ # or -1 if incomplete. def check_for_whole_start_tag(self, i): rawdata = self.rawdata - m = locatestarttagend_tolerant.match(rawdata, i) + if self.strict: + m = locatestarttagend.match(rawdata, i) + else: + m = locatestarttagend_tolerant.match(rawdata, i) if m: j = m.end() next = rawdata[j:j+1] @@ -356,6 +435,9 @@ # buffer boundary return -1 # else bogus input + if self.strict: + self.updatepos(i, j + 1) + self.error("malformed empty start tag") if j > i: return j else: @@ -368,6 +450,9 @@ # end of input in or before attribute value, or we have the # '/' from a '/>' ending return -1 + if self.strict: + self.updatepos(i, j) + self.error("malformed start tag") if j > i: return j else: @@ -387,6 +472,8 @@ if self.cdata_elem is not None: self.handle_data(rawdata[i:gtpos]) return gtpos + if self.strict: + self.error("bad end tag: %r" % (rawdata[i:gtpos],)) # find the name: w3.org/TR/html5/tokenization.html#tag-name-state namematch = tagfind_tolerant.match(rawdata, i+2) if not namematch: @@ -452,7 +539,8 @@ pass def unknown_decl(self, data): - pass + if self.strict: + self.error("unknown declaration: %r" % (data,)) # Internal -- helper to remove special character quoting def unescape(self, s): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/http/client.py --- a/Lib/http/client.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/http/client.py Fri Jul 25 11:39:11 2014 -0400 @@ -1334,8 +1334,7 @@ e = ', %i more expected' % self.expected else: e = '' - return '%s(%i bytes read%s)' % (self.__class__.__name__, - len(self.partial), e) + return 'IncompleteRead(%i bytes read%s)' % (len(self.partial), e) def __str__(self): return repr(self) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/http/cookiejar.py --- a/Lib/http/cookiejar.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/http/cookiejar.py Fri Jul 25 11:39:11 2014 -0400 @@ -805,7 +805,7 @@ args.append("%s=%s" % (name, repr(attr))) args.append("rest=%s" % repr(self._rest)) args.append("rfc2109=%s" % repr(self.rfc2109)) - return "%s(%s)" % (self.__class__.__name__, ", ".join(args)) + return "Cookie(%s)" % ", ".join(args) class CookiePolicy: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/idlelib/Bindings.py --- a/Lib/idlelib/Bindings.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/idlelib/Bindings.py Fri Jul 25 11:39:11 2014 -0400 @@ -8,8 +8,6 @@ windows. """ -from importlib.util import find_spec - from idlelib.configHandler import idleConf # Warning: menudefs is altered in macosxSupport.overrideRootMenu() @@ -88,7 +86,4 @@ ]), ] -if find_spec('turtledemo'): - menudefs[-1][1].append(('Turtle Demo', '<>')) - default_keydefs = idleConf.GetCurrentKeySet() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/idlelib/EditorWindow.py Fri Jul 25 11:39:11 2014 -0400 @@ -222,7 +222,6 @@ text.bind("<>", self.flist.close_all_callback) text.bind("<>", self.open_class_browser) text.bind("<>", self.open_path_browser) - text.bind("<>", self.open_turtle_demo) self.set_status_bar() vbar['command'] = text.yview @@ -706,14 +705,6 @@ from idlelib import PathBrowser PathBrowser.PathBrowser(self.flist) - def open_turtle_demo(self, event = None): - import subprocess - - cmd = [sys.executable, - '-c', - 'from turtledemo.__main__ import main; main()'] - p = subprocess.Popen(cmd, shell=False) - def gotoline(self, lineno): if lineno is not None and lineno > 0: self.text.mark_set("insert", "%d.0" % lineno) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/idlelib/WidgetRedirector.py --- a/Lib/idlelib/WidgetRedirector.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/idlelib/WidgetRedirector.py Fri Jul 25 11:39:11 2014 -0400 @@ -47,9 +47,8 @@ tk.createcommand(w, self.dispatch) def __repr__(self): - return "%s(%s<%s>)" % (self.__class__.__name__, - self.widget.__class__.__name__, - self.widget._w) + return "WidgetRedirector(%s<%s>)" % (self.widget.__class__.__name__, + self.widget._w) def close(self): "Unregister operations and revert redirection created by .__init__." @@ -143,8 +142,7 @@ self.orig_and_operation = (redir.orig, operation) def __repr__(self): - return "%s(%r, %r)" % (self.__class__.__name__, - self.redir, self.operation) + return "OriginalCommand(%r, %r)" % (self.redir, self.operation) def __call__(self, *args): return self.tk_call(self.orig_and_operation + args) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/idlelib/configDialog.py Fri Jul 25 11:39:11 2014 -0400 @@ -30,45 +30,43 @@ _utest - bool, don't wait_window when running unittest """ Toplevel.__init__(self, parent) - self.parent = parent - if _htest: - parent.instance_dict = {} self.wm_withdraw() self.configure(borderwidth=5) self.title('IDLE Preferences') - self.geometry( - "+%d+%d" % (parent.winfo_rootx() + 20, - parent.winfo_rooty() + (30 if not _htest else 150))) + if _htest: + parent.instance_dict = {} + self.geometry("+%d+%d" % (parent.winfo_rootx()+20, + parent.winfo_rooty()+(30 if not _htest else 150))) #Theme Elements. Each theme element key is its display name. #The first value of the tuple is the sample area tag name. #The second value is the display name list sort index. - self.themeElements={ - 'Normal Text':('normal', '00'), - 'Python Keywords':('keyword', '01'), - 'Python Definitions':('definition', '02'), + self.themeElements={'Normal Text':('normal','00'), + 'Python Keywords':('keyword','01'), + 'Python Definitions':('definition','02'), 'Python Builtins':('builtin', '03'), - 'Python Comments':('comment', '04'), - 'Python Strings':('string', '05'), - 'Selected Text':('hilite', '06'), - 'Found Text':('hit', '07'), - 'Cursor':('cursor', '08'), - 'Error Text':('error', '09'), - 'Shell Normal Text':('console', '10'), - 'Shell Stdout Text':('stdout', '11'), - 'Shell Stderr Text':('stderr', '12'), + 'Python Comments':('comment','04'), + 'Python Strings':('string','05'), + 'Selected Text':('hilite','06'), + 'Found Text':('hit','07'), + 'Cursor':('cursor','08'), + 'Error Text':('error','09'), + 'Shell Normal Text':('console','10'), + 'Shell Stdout Text':('stdout','11'), + 'Shell Stderr Text':('stderr','12'), } self.ResetChangedItems() #load initial values in changed items dict self.CreateWidgets() - self.resizable(height=FALSE, width=FALSE) + self.resizable(height=FALSE,width=FALSE) self.transient(parent) self.grab_set() self.protocol("WM_DELETE_WINDOW", self.Cancel) + self.parent = parent self.tabPages.focus_set() #key bindings for this dialog - #self.bind('', self.Cancel) #dismiss dialog, no save - #self.bind('', self.Apply) #apply changes, save - #self.bind('', self.Help) #context help + #self.bind('',self.Cancel) #dismiss dialog, no save + #self.bind('',self.Apply) #apply changes, save + #self.bind('',self.Help) #context help self.LoadConfigs() self.AttachVarCallbacks() #avoid callbacks during LoadConfigs @@ -78,517 +76,477 @@ def CreateWidgets(self): self.tabPages = TabbedPageSet(self, - page_names=['Fonts/Tabs', 'Highlighting', 'Keys', 'General']) - frameActionButtons = Frame(self, pady=2) + page_names=['Fonts/Tabs','Highlighting','Keys','General']) + frameActionButtons = Frame(self,pady=2) #action buttons + if macosxSupport.isAquaTk(): - # Changing the default padding on OSX results in unreadable - # text in the buttons - paddingArgs = {} + # Surpress the padx and pady arguments when + # running as IDLE.app, otherwise the text + # on these buttons will not be readable. + extraKwds={} else: - paddingArgs = {'padx':6, 'pady':3} + extraKwds=dict(padx=6, pady=3) # Comment out button creation and packing until implement self.Help -## self.buttonHelp = Button(frameActionButtons, text='Help', -## command=self.Help, takefocus=FALSE, -## **paddingArgs) - self.buttonOk = Button( - frameActionButtons, text='Ok', - command=self.Ok, takefocus=FALSE, **paddingArgs) - self.buttonApply = Button( - frameActionButtons, text='Apply', - command=self.Apply, takefocus=FALSE, **paddingArgs) - self.buttonCancel = Button( - frameActionButtons, text='Cancel', - command=self.Cancel, takefocus=FALSE, **paddingArgs) +## self.buttonHelp = Button(frameActionButtons,text='Help', +## command=self.Help,takefocus=FALSE, +## **extraKwds) + self.buttonOk = Button(frameActionButtons,text='Ok', + command=self.Ok,takefocus=FALSE, + **extraKwds) + self.buttonApply = Button(frameActionButtons,text='Apply', + command=self.Apply,takefocus=FALSE, + **extraKwds) + self.buttonCancel = Button(frameActionButtons,text='Cancel', + command=self.Cancel,takefocus=FALSE, + **extraKwds) self.CreatePageFontTab() self.CreatePageHighlight() self.CreatePageKeys() self.CreatePageGeneral() -## self.buttonHelp.pack(side=RIGHT, padx=5) - self.buttonOk.pack(side=LEFT, padx=5) - self.buttonApply.pack(side=LEFT, padx=5) - self.buttonCancel.pack(side=LEFT, padx=5) +## self.buttonHelp.pack(side=RIGHT,padx=5) + self.buttonOk.pack(side=LEFT,padx=5) + self.buttonApply.pack(side=LEFT,padx=5) + self.buttonCancel.pack(side=LEFT,padx=5) frameActionButtons.pack(side=BOTTOM) Frame(self, height=2, borderwidth=0).pack(side=BOTTOM) - self.tabPages.pack(side=TOP, expand=TRUE, fill=BOTH) + self.tabPages.pack(side=TOP,expand=TRUE,fill=BOTH) def CreatePageFontTab(self): - parent = self.parent - self.fontSize = StringVar(parent) - self.fontBold = BooleanVar(parent) - self.fontName = StringVar(parent) - self.spaceNum = IntVar(parent) - self.editFont = tkFont.Font(parent, ('courier', 10, 'normal')) - + #tkVars + self.fontSize=StringVar(self) + self.fontBold=BooleanVar(self) + self.fontName=StringVar(self) + self.spaceNum=IntVar(self) + self.editFont=tkFont.Font(self,('courier',10,'normal')) ##widget creation #body frame - frame = self.tabPages.pages['Fonts/Tabs'].frame + frame=self.tabPages.pages['Fonts/Tabs'].frame #body section frames - frameFont = LabelFrame( - frame, borderwidth=2, relief=GROOVE, text=' Base Editor Font ') - frameIndent = LabelFrame( - frame, borderwidth=2, relief=GROOVE, text=' Indentation Width ') + frameFont=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Base Editor Font ') + frameIndent=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Indentation Width ') #frameFont - frameFontName = Frame(frameFont) - frameFontParam = Frame(frameFont) - labelFontNameTitle = Label( - frameFontName, justify=LEFT, text='Font Face :') - self.listFontName = Listbox( - frameFontName, height=5, takefocus=FALSE, exportselection=FALSE) - self.listFontName.bind( - '', self.OnListFontButtonRelease) - scrollFont = Scrollbar(frameFontName) + frameFontName=Frame(frameFont) + frameFontParam=Frame(frameFont) + labelFontNameTitle=Label(frameFontName,justify=LEFT, + text='Font Face :') + self.listFontName=Listbox(frameFontName,height=5,takefocus=FALSE, + exportselection=FALSE) + self.listFontName.bind('',self.OnListFontButtonRelease) + scrollFont=Scrollbar(frameFontName) scrollFont.config(command=self.listFontName.yview) self.listFontName.config(yscrollcommand=scrollFont.set) - labelFontSizeTitle = Label(frameFontParam, text='Size :') - self.optMenuFontSize = DynOptionMenu( - frameFontParam, self.fontSize, None, command=self.SetFontSample) - checkFontBold = Checkbutton( - frameFontParam, variable=self.fontBold, onvalue=1, - offvalue=0, text='Bold', command=self.SetFontSample) - frameFontSample = Frame(frameFont, relief=SOLID, borderwidth=1) - self.labelFontSample = Label( - frameFontSample, justify=LEFT, font=self.editFont, - text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]') + labelFontSizeTitle=Label(frameFontParam,text='Size :') + self.optMenuFontSize=DynOptionMenu(frameFontParam,self.fontSize,None, + command=self.SetFontSample) + checkFontBold=Checkbutton(frameFontParam,variable=self.fontBold, + onvalue=1,offvalue=0,text='Bold',command=self.SetFontSample) + frameFontSample=Frame(frameFont,relief=SOLID,borderwidth=1) + self.labelFontSample=Label(frameFontSample, + text='AaBbCcDdEe\nFfGgHhIiJjK\n1234567890\n#:+=(){}[]', + justify=LEFT,font=self.editFont) #frameIndent - frameIndentSize = Frame(frameIndent) - labelSpaceNumTitle = Label( - frameIndentSize, justify=LEFT, - text='Python Standard: 4 Spaces!') - self.scaleSpaceNum = Scale( - frameIndentSize, variable=self.spaceNum, - orient='horizontal', tickinterval=2, from_=2, to=16) - + frameIndentSize=Frame(frameIndent) + labelSpaceNumTitle=Label(frameIndentSize, justify=LEFT, + text='Python Standard: 4 Spaces!') + self.scaleSpaceNum=Scale(frameIndentSize, variable=self.spaceNum, + orient='horizontal', + tickinterval=2, from_=2, to=16) #widget packing #body - frameFont.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH) - frameIndent.pack(side=LEFT, padx=5, pady=5, fill=Y) + frameFont.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH) + frameIndent.pack(side=LEFT,padx=5,pady=5,fill=Y) #frameFont - frameFontName.pack(side=TOP, padx=5, pady=5, fill=X) - frameFontParam.pack(side=TOP, padx=5, pady=5, fill=X) - labelFontNameTitle.pack(side=TOP, anchor=W) - self.listFontName.pack(side=LEFT, expand=TRUE, fill=X) - scrollFont.pack(side=LEFT, fill=Y) - labelFontSizeTitle.pack(side=LEFT, anchor=W) - self.optMenuFontSize.pack(side=LEFT, anchor=W) - checkFontBold.pack(side=LEFT, anchor=W, padx=20) - frameFontSample.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) - self.labelFontSample.pack(expand=TRUE, fill=BOTH) + frameFontName.pack(side=TOP,padx=5,pady=5,fill=X) + frameFontParam.pack(side=TOP,padx=5,pady=5,fill=X) + labelFontNameTitle.pack(side=TOP,anchor=W) + self.listFontName.pack(side=LEFT,expand=TRUE,fill=X) + scrollFont.pack(side=LEFT,fill=Y) + labelFontSizeTitle.pack(side=LEFT,anchor=W) + self.optMenuFontSize.pack(side=LEFT,anchor=W) + checkFontBold.pack(side=LEFT,anchor=W,padx=20) + frameFontSample.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) + self.labelFontSample.pack(expand=TRUE,fill=BOTH) #frameIndent - frameIndentSize.pack(side=TOP, fill=X) - labelSpaceNumTitle.pack(side=TOP, anchor=W, padx=5) - self.scaleSpaceNum.pack(side=TOP, padx=5, fill=X) + frameIndentSize.pack(side=TOP,fill=X) + labelSpaceNumTitle.pack(side=TOP,anchor=W,padx=5) + self.scaleSpaceNum.pack(side=TOP,padx=5,fill=X) return frame def CreatePageHighlight(self): - parent = self.parent - self.builtinTheme = StringVar(parent) - self.customTheme = StringVar(parent) - self.fgHilite = BooleanVar(parent) - self.colour = StringVar(parent) - self.fontName = StringVar(parent) - self.themeIsBuiltin = BooleanVar(parent) - self.highlightTarget = StringVar(parent) - + self.builtinTheme=StringVar(self) + self.customTheme=StringVar(self) + self.fgHilite=BooleanVar(self) + self.colour=StringVar(self) + self.fontName=StringVar(self) + self.themeIsBuiltin=BooleanVar(self) + self.highlightTarget=StringVar(self) ##widget creation #body frame - frame = self.tabPages.pages['Highlighting'].frame + frame=self.tabPages.pages['Highlighting'].frame #body section frames - frameCustom = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Custom Highlighting ') - frameTheme = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Highlighting Theme ') + frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Custom Highlighting ') + frameTheme=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Highlighting Theme ') #frameCustom - self.textHighlightSample=Text( - frameCustom, relief=SOLID, borderwidth=1, - font=('courier', 12, ''), cursor='hand2', width=21, height=11, - takefocus=FALSE, highlightthickness=0, wrap=NONE) + self.textHighlightSample=Text(frameCustom,relief=SOLID,borderwidth=1, + font=('courier',12,''),cursor='hand2',width=21,height=11, + takefocus=FALSE,highlightthickness=0,wrap=NONE) text=self.textHighlightSample - text.bind('', lambda e: 'break') - text.bind('', lambda e: 'break') - textAndTags=( - ('#you can click here', 'comment'), ('\n', 'normal'), - ('#to choose items', 'comment'), ('\n', 'normal'), - ('def', 'keyword'), (' ', 'normal'), - ('func', 'definition'), ('(param):\n ', 'normal'), - ('"""string"""', 'string'), ('\n var0 = ', 'normal'), - ("'string'", 'string'), ('\n var1 = ', 'normal'), - ("'selected'", 'hilite'), ('\n var2 = ', 'normal'), - ("'found'", 'hit'), ('\n var3 = ', 'normal'), - ('list', 'builtin'), ('(', 'normal'), - ('None', 'keyword'), (')\n\n', 'normal'), - (' error ', 'error'), (' ', 'normal'), - ('cursor |', 'cursor'), ('\n ', 'normal'), - ('shell', 'console'), (' ', 'normal'), - ('stdout', 'stdout'), (' ', 'normal'), - ('stderr', 'stderr'), ('\n', 'normal')) + text.bind('',lambda e: 'break') + text.bind('',lambda e: 'break') + textAndTags=(('#you can click here','comment'),('\n','normal'), + ('#to choose items','comment'),('\n','normal'),('def','keyword'), + (' ','normal'),('func','definition'),('(param):','normal'), + ('\n ','normal'),('"""string"""','string'),('\n var0 = ','normal'), + ("'string'",'string'),('\n var1 = ','normal'),("'selected'",'hilite'), + ('\n var2 = ','normal'),("'found'",'hit'), + ('\n var3 = ','normal'),('list', 'builtin'), ('(','normal'), + ('None', 'keyword'),(')\n\n','normal'), + (' error ','error'),(' ','normal'),('cursor |','cursor'), + ('\n ','normal'),('shell','console'),(' ','normal'),('stdout','stdout'), + (' ','normal'),('stderr','stderr'),('\n','normal')) for txTa in textAndTags: - text.insert(END, txTa[0], txTa[1]) + text.insert(END,txTa[0],txTa[1]) for element in self.themeElements: - def tem(event, elem=element): - event.widget.winfo_toplevel().highlightTarget.set(elem) - text.tag_bind( - self.themeElements[element][0], '', tem) + text.tag_bind(self.themeElements[element][0],'', + lambda event,elem=element: event.widget.winfo_toplevel() + .highlightTarget.set(elem)) text.config(state=DISABLED) - self.frameColourSet = Frame(frameCustom, relief=SOLID, borderwidth=1) - frameFgBg = Frame(frameCustom) - buttonSetColour = Button( - self.frameColourSet, text='Choose Colour for :', - command=self.GetColour, highlightthickness=0) - self.optMenuHighlightTarget = DynOptionMenu( - self.frameColourSet, self.highlightTarget, None, - highlightthickness=0) #, command=self.SetHighlightTargetBinding - self.radioFg = Radiobutton( - frameFgBg, variable=self.fgHilite, value=1, - text='Foreground', command=self.SetColourSampleBinding) - self.radioBg=Radiobutton( - frameFgBg, variable=self.fgHilite, value=0, - text='Background', command=self.SetColourSampleBinding) + self.frameColourSet=Frame(frameCustom,relief=SOLID,borderwidth=1) + frameFgBg=Frame(frameCustom) + buttonSetColour=Button(self.frameColourSet,text='Choose Colour for :', + command=self.GetColour,highlightthickness=0) + self.optMenuHighlightTarget=DynOptionMenu(self.frameColourSet, + self.highlightTarget,None,highlightthickness=0)#,command=self.SetHighlightTargetBinding + self.radioFg=Radiobutton(frameFgBg,variable=self.fgHilite, + value=1,text='Foreground',command=self.SetColourSampleBinding) + self.radioBg=Radiobutton(frameFgBg,variable=self.fgHilite, + value=0,text='Background',command=self.SetColourSampleBinding) self.fgHilite.set(1) - buttonSaveCustomTheme = Button( - frameCustom, text='Save as New Custom Theme', - command=self.SaveAsNewTheme) + buttonSaveCustomTheme=Button(frameCustom, + text='Save as New Custom Theme',command=self.SaveAsNewTheme) #frameTheme - labelTypeTitle = Label(frameTheme, text='Select : ') - self.radioThemeBuiltin = Radiobutton( - frameTheme, variable=self.themeIsBuiltin, value=1, - command=self.SetThemeType, text='a Built-in Theme') - self.radioThemeCustom = Radiobutton( - frameTheme, variable=self.themeIsBuiltin, value=0, - command=self.SetThemeType, text='a Custom Theme') - self.optMenuThemeBuiltin = DynOptionMenu( - frameTheme, self.builtinTheme, None, command=None) - self.optMenuThemeCustom=DynOptionMenu( - frameTheme, self.customTheme, None, command=None) - self.buttonDeleteCustomTheme=Button( - frameTheme, text='Delete Custom Theme', + labelTypeTitle=Label(frameTheme,text='Select : ') + self.radioThemeBuiltin=Radiobutton(frameTheme,variable=self.themeIsBuiltin, + value=1,command=self.SetThemeType,text='a Built-in Theme') + self.radioThemeCustom=Radiobutton(frameTheme,variable=self.themeIsBuiltin, + value=0,command=self.SetThemeType,text='a Custom Theme') + self.optMenuThemeBuiltin=DynOptionMenu(frameTheme, + self.builtinTheme,None,command=None) + self.optMenuThemeCustom=DynOptionMenu(frameTheme, + self.customTheme,None,command=None) + self.buttonDeleteCustomTheme=Button(frameTheme,text='Delete Custom Theme', command=self.DeleteCustomTheme) - ##widget packing #body - frameCustom.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH) - frameTheme.pack(side=LEFT, padx=5, pady=5, fill=Y) + frameCustom.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH) + frameTheme.pack(side=LEFT,padx=5,pady=5,fill=Y) #frameCustom - self.frameColourSet.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=X) - frameFgBg.pack(side=TOP, padx=5, pady=0) - self.textHighlightSample.pack( - side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) - buttonSetColour.pack(side=TOP, expand=TRUE, fill=X, padx=8, pady=4) - self.optMenuHighlightTarget.pack( - side=TOP, expand=TRUE, fill=X, padx=8, pady=3) - self.radioFg.pack(side=LEFT, anchor=E) - self.radioBg.pack(side=RIGHT, anchor=W) - buttonSaveCustomTheme.pack(side=BOTTOM, fill=X, padx=5, pady=5) + self.frameColourSet.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=X) + frameFgBg.pack(side=TOP,padx=5,pady=0) + self.textHighlightSample.pack(side=TOP,padx=5,pady=5,expand=TRUE, + fill=BOTH) + buttonSetColour.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=4) + self.optMenuHighlightTarget.pack(side=TOP,expand=TRUE,fill=X,padx=8,pady=3) + self.radioFg.pack(side=LEFT,anchor=E) + self.radioBg.pack(side=RIGHT,anchor=W) + buttonSaveCustomTheme.pack(side=BOTTOM,fill=X,padx=5,pady=5) #frameTheme - labelTypeTitle.pack(side=TOP, anchor=W, padx=5, pady=5) - self.radioThemeBuiltin.pack(side=TOP, anchor=W, padx=5) - self.radioThemeCustom.pack(side=TOP, anchor=W, padx=5, pady=2) - self.optMenuThemeBuiltin.pack(side=TOP, fill=X, padx=5, pady=5) - self.optMenuThemeCustom.pack(side=TOP, fill=X, anchor=W, padx=5, pady=5) - self.buttonDeleteCustomTheme.pack(side=TOP, fill=X, padx=5, pady=5) + labelTypeTitle.pack(side=TOP,anchor=W,padx=5,pady=5) + self.radioThemeBuiltin.pack(side=TOP,anchor=W,padx=5) + self.radioThemeCustom.pack(side=TOP,anchor=W,padx=5,pady=2) + self.optMenuThemeBuiltin.pack(side=TOP,fill=X,padx=5,pady=5) + self.optMenuThemeCustom.pack(side=TOP,fill=X,anchor=W,padx=5,pady=5) + self.buttonDeleteCustomTheme.pack(side=TOP,fill=X,padx=5,pady=5) return frame def CreatePageKeys(self): - parent = self.parent - self.bindingTarget = StringVar(parent) - self.builtinKeys = StringVar(parent) - self.customKeys = StringVar(parent) - self.keysAreBuiltin = BooleanVar(parent) - self.keyBinding = StringVar(parent) - + #tkVars + self.bindingTarget=StringVar(self) + self.builtinKeys=StringVar(self) + self.customKeys=StringVar(self) + self.keysAreBuiltin=BooleanVar(self) + self.keyBinding=StringVar(self) ##widget creation #body frame - frame = self.tabPages.pages['Keys'].frame + frame=self.tabPages.pages['Keys'].frame #body section frames - frameCustom = LabelFrame( - frame, borderwidth=2, relief=GROOVE, - text=' Custom Key Bindings ') - frameKeySets = LabelFrame( - frame, borderwidth=2, relief=GROOVE, text=' Key Set ') + frameCustom=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Custom Key Bindings ') + frameKeySets=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Key Set ') #frameCustom - frameTarget = Frame(frameCustom) - labelTargetTitle = Label(frameTarget, text='Action - Key(s)') - scrollTargetY = Scrollbar(frameTarget) - scrollTargetX = Scrollbar(frameTarget, orient=HORIZONTAL) - self.listBindings = Listbox( - frameTarget, takefocus=FALSE, exportselection=FALSE) - self.listBindings.bind('', self.KeyBindingSelected) + frameTarget=Frame(frameCustom) + labelTargetTitle=Label(frameTarget,text='Action - Key(s)') + scrollTargetY=Scrollbar(frameTarget) + scrollTargetX=Scrollbar(frameTarget,orient=HORIZONTAL) + self.listBindings=Listbox(frameTarget,takefocus=FALSE, + exportselection=FALSE) + self.listBindings.bind('',self.KeyBindingSelected) scrollTargetY.config(command=self.listBindings.yview) scrollTargetX.config(command=self.listBindings.xview) self.listBindings.config(yscrollcommand=scrollTargetY.set) self.listBindings.config(xscrollcommand=scrollTargetX.set) - self.buttonNewKeys = Button( - frameCustom, text='Get New Keys for Selection', - command=self.GetNewKeys, state=DISABLED) + self.buttonNewKeys=Button(frameCustom,text='Get New Keys for Selection', + command=self.GetNewKeys,state=DISABLED) #frameKeySets frames = [Frame(frameKeySets, padx=2, pady=2, borderwidth=0) for i in range(2)] - self.radioKeysBuiltin = Radiobutton( - frames[0], variable=self.keysAreBuiltin, value=1, - command=self.SetKeysType, text='Use a Built-in Key Set') - self.radioKeysCustom = Radiobutton( - frames[0], variable=self.keysAreBuiltin, value=0, - command=self.SetKeysType, text='Use a Custom Key Set') - self.optMenuKeysBuiltin = DynOptionMenu( - frames[0], self.builtinKeys, None, command=None) - self.optMenuKeysCustom = DynOptionMenu( - frames[0], self.customKeys, None, command=None) - self.buttonDeleteCustomKeys = Button( - frames[1], text='Delete Custom Key Set', + self.radioKeysBuiltin=Radiobutton(frames[0],variable=self.keysAreBuiltin, + value=1,command=self.SetKeysType,text='Use a Built-in Key Set') + self.radioKeysCustom=Radiobutton(frames[0],variable=self.keysAreBuiltin, + value=0,command=self.SetKeysType,text='Use a Custom Key Set') + self.optMenuKeysBuiltin=DynOptionMenu(frames[0], + self.builtinKeys,None,command=None) + self.optMenuKeysCustom=DynOptionMenu(frames[0], + self.customKeys,None,command=None) + self.buttonDeleteCustomKeys=Button(frames[1],text='Delete Custom Key Set', command=self.DeleteCustomKeys) - buttonSaveCustomKeys = Button( - frames[1], text='Save as New Custom Key Set', - command=self.SaveAsNewKeySet) - + buttonSaveCustomKeys=Button(frames[1], + text='Save as New Custom Key Set',command=self.SaveAsNewKeySet) ##widget packing #body - frameCustom.pack(side=BOTTOM, padx=5, pady=5, expand=TRUE, fill=BOTH) - frameKeySets.pack(side=BOTTOM, padx=5, pady=5, fill=BOTH) + frameCustom.pack(side=BOTTOM,padx=5,pady=5,expand=TRUE,fill=BOTH) + frameKeySets.pack(side=BOTTOM,padx=5,pady=5,fill=BOTH) #frameCustom - self.buttonNewKeys.pack(side=BOTTOM, fill=X, padx=5, pady=5) - frameTarget.pack(side=LEFT, padx=5, pady=5, expand=TRUE, fill=BOTH) + self.buttonNewKeys.pack(side=BOTTOM,fill=X,padx=5,pady=5) + frameTarget.pack(side=LEFT,padx=5,pady=5,expand=TRUE,fill=BOTH) #frame target - frameTarget.columnconfigure(0, weight=1) - frameTarget.rowconfigure(1, weight=1) - labelTargetTitle.grid(row=0, column=0, columnspan=2, sticky=W) - self.listBindings.grid(row=1, column=0, sticky=NSEW) - scrollTargetY.grid(row=1, column=1, sticky=NS) - scrollTargetX.grid(row=2, column=0, sticky=EW) + frameTarget.columnconfigure(0,weight=1) + frameTarget.rowconfigure(1,weight=1) + labelTargetTitle.grid(row=0,column=0,columnspan=2,sticky=W) + self.listBindings.grid(row=1,column=0,sticky=NSEW) + scrollTargetY.grid(row=1,column=1,sticky=NS) + scrollTargetX.grid(row=2,column=0,sticky=EW) #frameKeySets self.radioKeysBuiltin.grid(row=0, column=0, sticky=W+NS) self.radioKeysCustom.grid(row=1, column=0, sticky=W+NS) self.optMenuKeysBuiltin.grid(row=0, column=1, sticky=NSEW) self.optMenuKeysCustom.grid(row=1, column=1, sticky=NSEW) - self.buttonDeleteCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2) - buttonSaveCustomKeys.pack(side=LEFT, fill=X, expand=True, padx=2) + self.buttonDeleteCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2) + buttonSaveCustomKeys.pack(side=LEFT,fill=X,expand=True,padx=2) frames[0].pack(side=TOP, fill=BOTH, expand=True) frames[1].pack(side=TOP, fill=X, expand=True, pady=2) return frame def CreatePageGeneral(self): - parent = self.parent - self.winWidth = StringVar(parent) - self.winHeight = StringVar(parent) - self.paraWidth = StringVar(parent) - self.startupEdit = IntVar(parent) - self.autoSave = IntVar(parent) - self.encoding = StringVar(parent) - self.userHelpBrowser = BooleanVar(parent) - self.helpBrowser = StringVar(parent) - + #tkVars + self.winWidth=StringVar(self) + self.winHeight=StringVar(self) + self.paraWidth=StringVar(self) + self.startupEdit=IntVar(self) + self.autoSave=IntVar(self) + self.encoding=StringVar(self) + self.userHelpBrowser=BooleanVar(self) + self.helpBrowser=StringVar(self) #widget creation #body - frame = self.tabPages.pages['General'].frame + frame=self.tabPages.pages['General'].frame #body section frames - frameRun = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Startup Preferences ') - frameSave = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Autosave Preferences ') - frameWinSize = Frame(frame, borderwidth=2, relief=GROOVE) - frameParaSize = Frame(frame, borderwidth=2, relief=GROOVE) - frameHelp = LabelFrame(frame, borderwidth=2, relief=GROOVE, - text=' Additional Help Sources ') + frameRun=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Startup Preferences ') + frameSave=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Autosave Preferences ') + frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE) + frameParaSize=Frame(frame,borderwidth=2,relief=GROOVE) + frameHelp=LabelFrame(frame,borderwidth=2,relief=GROOVE, + text=' Additional Help Sources ') #frameRun - labelRunChoiceTitle = Label(frameRun, text='At Startup') - radioStartupEdit = Radiobutton( - frameRun, variable=self.startupEdit, value=1, - command=self.SetKeysType, text="Open Edit Window") - radioStartupShell = Radiobutton( - frameRun, variable=self.startupEdit, value=0, - command=self.SetKeysType, text='Open Shell Window') + labelRunChoiceTitle=Label(frameRun,text='At Startup') + radioStartupEdit=Radiobutton(frameRun,variable=self.startupEdit, + value=1,command=self.SetKeysType,text="Open Edit Window") + radioStartupShell=Radiobutton(frameRun,variable=self.startupEdit, + value=0,command=self.SetKeysType,text='Open Shell Window') #frameSave - labelRunSaveTitle = Label(frameSave, text='At Start of Run (F5) ') - radioSaveAsk = Radiobutton( - frameSave, variable=self.autoSave, value=0, - command=self.SetKeysType, text="Prompt to Save") - radioSaveAuto = Radiobutton( - frameSave, variable=self.autoSave, value=1, - command=self.SetKeysType, text='No Prompt') + labelRunSaveTitle=Label(frameSave,text='At Start of Run (F5) ') + radioSaveAsk=Radiobutton(frameSave,variable=self.autoSave, + value=0,command=self.SetKeysType,text="Prompt to Save") + radioSaveAuto=Radiobutton(frameSave,variable=self.autoSave, + value=1,command=self.SetKeysType,text='No Prompt') #frameWinSize - labelWinSizeTitle = Label( - frameWinSize, text='Initial Window Size (in characters)') - labelWinWidthTitle = Label(frameWinSize, text='Width') - entryWinWidth = Entry( - frameWinSize, textvariable=self.winWidth, width=3) - labelWinHeightTitle = Label(frameWinSize, text='Height') - entryWinHeight = Entry( - frameWinSize, textvariable=self.winHeight, width=3) + labelWinSizeTitle=Label(frameWinSize,text='Initial Window Size'+ + ' (in characters)') + labelWinWidthTitle=Label(frameWinSize,text='Width') + entryWinWidth=Entry(frameWinSize,textvariable=self.winWidth, + width=3) + labelWinHeightTitle=Label(frameWinSize,text='Height') + entryWinHeight=Entry(frameWinSize,textvariable=self.winHeight, + width=3) #paragraphFormatWidth - labelParaWidthTitle = Label( - frameParaSize, text='Paragraph reformat width (in characters)') - entryParaWidth = Entry( - frameParaSize, textvariable=self.paraWidth, width=3) + labelParaWidthTitle=Label(frameParaSize,text='Paragraph reformat'+ + ' width (in characters)') + entryParaWidth=Entry(frameParaSize,textvariable=self.paraWidth, + width=3) #frameHelp - frameHelpList = Frame(frameHelp) - frameHelpListButtons = Frame(frameHelpList) - scrollHelpList = Scrollbar(frameHelpList) - self.listHelp = Listbox( - frameHelpList, height=5, takefocus=FALSE, + frameHelpList=Frame(frameHelp) + frameHelpListButtons=Frame(frameHelpList) + scrollHelpList=Scrollbar(frameHelpList) + self.listHelp=Listbox(frameHelpList,height=5,takefocus=FALSE, exportselection=FALSE) scrollHelpList.config(command=self.listHelp.yview) self.listHelp.config(yscrollcommand=scrollHelpList.set) - self.listHelp.bind('', self.HelpSourceSelected) - self.buttonHelpListEdit = Button( - frameHelpListButtons, text='Edit', state=DISABLED, - width=8, command=self.HelpListItemEdit) - self.buttonHelpListAdd = Button( - frameHelpListButtons, text='Add', - width=8, command=self.HelpListItemAdd) - self.buttonHelpListRemove = Button( - frameHelpListButtons, text='Remove', state=DISABLED, - width=8, command=self.HelpListItemRemove) - + self.listHelp.bind('',self.HelpSourceSelected) + self.buttonHelpListEdit=Button(frameHelpListButtons,text='Edit', + state=DISABLED,width=8,command=self.HelpListItemEdit) + self.buttonHelpListAdd=Button(frameHelpListButtons,text='Add', + width=8,command=self.HelpListItemAdd) + self.buttonHelpListRemove=Button(frameHelpListButtons,text='Remove', + state=DISABLED,width=8,command=self.HelpListItemRemove) #widget packing #body - frameRun.pack(side=TOP, padx=5, pady=5, fill=X) - frameSave.pack(side=TOP, padx=5, pady=5, fill=X) - frameWinSize.pack(side=TOP, padx=5, pady=5, fill=X) - frameParaSize.pack(side=TOP, padx=5, pady=5, fill=X) - frameHelp.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) + frameRun.pack(side=TOP,padx=5,pady=5,fill=X) + frameSave.pack(side=TOP,padx=5,pady=5,fill=X) + frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X) + frameParaSize.pack(side=TOP,padx=5,pady=5,fill=X) + frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) #frameRun - labelRunChoiceTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5) - radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5) + labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) + radioStartupShell.pack(side=RIGHT,anchor=W,padx=5,pady=5) + radioStartupEdit.pack(side=RIGHT,anchor=W,padx=5,pady=5) #frameSave - labelRunSaveTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5) - radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5) + labelRunSaveTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) + radioSaveAuto.pack(side=RIGHT,anchor=W,padx=5,pady=5) + radioSaveAsk.pack(side=RIGHT,anchor=W,padx=5,pady=5) #frameWinSize - labelWinSizeTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5) - labelWinHeightTitle.pack(side=RIGHT, anchor=E, pady=5) - entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5) - labelWinWidthTitle.pack(side=RIGHT, anchor=E, pady=5) + labelWinSizeTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) + entryWinHeight.pack(side=RIGHT,anchor=E,padx=10,pady=5) + labelWinHeightTitle.pack(side=RIGHT,anchor=E,pady=5) + entryWinWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5) + labelWinWidthTitle.pack(side=RIGHT,anchor=E,pady=5) #paragraphFormatWidth - labelParaWidthTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - entryParaWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5) + labelParaWidthTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) + entryParaWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5) #frameHelp - frameHelpListButtons.pack(side=RIGHT, padx=5, pady=5, fill=Y) - frameHelpList.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) - scrollHelpList.pack(side=RIGHT, anchor=W, fill=Y) - self.listHelp.pack(side=LEFT, anchor=E, expand=TRUE, fill=BOTH) - self.buttonHelpListEdit.pack(side=TOP, anchor=W, pady=5) - self.buttonHelpListAdd.pack(side=TOP, anchor=W) - self.buttonHelpListRemove.pack(side=TOP, anchor=W, pady=5) + frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y) + frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) + scrollHelpList.pack(side=RIGHT,anchor=W,fill=Y) + self.listHelp.pack(side=LEFT,anchor=E,expand=TRUE,fill=BOTH) + self.buttonHelpListEdit.pack(side=TOP,anchor=W,pady=5) + self.buttonHelpListAdd.pack(side=TOP,anchor=W) + self.buttonHelpListRemove.pack(side=TOP,anchor=W,pady=5) return frame def AttachVarCallbacks(self): - self.fontSize.trace_variable('w', self.VarChanged_fontSize) - self.fontName.trace_variable('w', self.VarChanged_fontName) - self.fontBold.trace_variable('w', self.VarChanged_fontBold) - self.spaceNum.trace_variable('w', self.VarChanged_spaceNum) - self.colour.trace_variable('w', self.VarChanged_colour) - self.builtinTheme.trace_variable('w', self.VarChanged_builtinTheme) - self.customTheme.trace_variable('w', self.VarChanged_customTheme) - self.themeIsBuiltin.trace_variable('w', self.VarChanged_themeIsBuiltin) - self.highlightTarget.trace_variable('w', self.VarChanged_highlightTarget) - self.keyBinding.trace_variable('w', self.VarChanged_keyBinding) - self.builtinKeys.trace_variable('w', self.VarChanged_builtinKeys) - self.customKeys.trace_variable('w', self.VarChanged_customKeys) - self.keysAreBuiltin.trace_variable('w', self.VarChanged_keysAreBuiltin) - self.winWidth.trace_variable('w', self.VarChanged_winWidth) - self.winHeight.trace_variable('w', self.VarChanged_winHeight) - self.paraWidth.trace_variable('w', self.VarChanged_paraWidth) - self.startupEdit.trace_variable('w', self.VarChanged_startupEdit) - self.autoSave.trace_variable('w', self.VarChanged_autoSave) - self.encoding.trace_variable('w', self.VarChanged_encoding) + self.fontSize.trace_variable('w',self.VarChanged_fontSize) + self.fontName.trace_variable('w',self.VarChanged_fontName) + self.fontBold.trace_variable('w',self.VarChanged_fontBold) + self.spaceNum.trace_variable('w',self.VarChanged_spaceNum) + self.colour.trace_variable('w',self.VarChanged_colour) + self.builtinTheme.trace_variable('w',self.VarChanged_builtinTheme) + self.customTheme.trace_variable('w',self.VarChanged_customTheme) + self.themeIsBuiltin.trace_variable('w',self.VarChanged_themeIsBuiltin) + self.highlightTarget.trace_variable('w',self.VarChanged_highlightTarget) + self.keyBinding.trace_variable('w',self.VarChanged_keyBinding) + self.builtinKeys.trace_variable('w',self.VarChanged_builtinKeys) + self.customKeys.trace_variable('w',self.VarChanged_customKeys) + self.keysAreBuiltin.trace_variable('w',self.VarChanged_keysAreBuiltin) + self.winWidth.trace_variable('w',self.VarChanged_winWidth) + self.winHeight.trace_variable('w',self.VarChanged_winHeight) + self.paraWidth.trace_variable('w',self.VarChanged_paraWidth) + self.startupEdit.trace_variable('w',self.VarChanged_startupEdit) + self.autoSave.trace_variable('w',self.VarChanged_autoSave) + self.encoding.trace_variable('w',self.VarChanged_encoding) - def VarChanged_fontSize(self, *params): - value = self.fontSize.get() - self.AddChangedItem('main', 'EditorWindow', 'font-size', value) + def VarChanged_fontSize(self,*params): + value=self.fontSize.get() + self.AddChangedItem('main','EditorWindow','font-size',value) - def VarChanged_fontName(self, *params): - value = self.fontName.get() - self.AddChangedItem('main', 'EditorWindow', 'font', value) + def VarChanged_fontName(self,*params): + value=self.fontName.get() + self.AddChangedItem('main','EditorWindow','font',value) - def VarChanged_fontBold(self, *params): - value = self.fontBold.get() - self.AddChangedItem('main', 'EditorWindow', 'font-bold', value) + def VarChanged_fontBold(self,*params): + value=self.fontBold.get() + self.AddChangedItem('main','EditorWindow','font-bold',value) - def VarChanged_spaceNum(self, *params): - value = self.spaceNum.get() - self.AddChangedItem('main', 'Indent', 'num-spaces', value) + def VarChanged_spaceNum(self,*params): + value=self.spaceNum.get() + self.AddChangedItem('main','Indent','num-spaces',value) - def VarChanged_colour(self, *params): + def VarChanged_colour(self,*params): self.OnNewColourSet() - def VarChanged_builtinTheme(self, *params): - value = self.builtinTheme.get() - self.AddChangedItem('main', 'Theme', 'name', value) + def VarChanged_builtinTheme(self,*params): + value=self.builtinTheme.get() + self.AddChangedItem('main','Theme','name',value) self.PaintThemeSample() - def VarChanged_customTheme(self, *params): - value = self.customTheme.get() + def VarChanged_customTheme(self,*params): + value=self.customTheme.get() if value != '- no custom themes -': - self.AddChangedItem('main', 'Theme', 'name', value) + self.AddChangedItem('main','Theme','name',value) self.PaintThemeSample() - def VarChanged_themeIsBuiltin(self, *params): - value = self.themeIsBuiltin.get() - self.AddChangedItem('main', 'Theme', 'default', value) + def VarChanged_themeIsBuiltin(self,*params): + value=self.themeIsBuiltin.get() + self.AddChangedItem('main','Theme','default',value) if value: self.VarChanged_builtinTheme() else: self.VarChanged_customTheme() - def VarChanged_highlightTarget(self, *params): + def VarChanged_highlightTarget(self,*params): self.SetHighlightTarget() - def VarChanged_keyBinding(self, *params): - value = self.keyBinding.get() - keySet = self.customKeys.get() - event = self.listBindings.get(ANCHOR).split()[0] + def VarChanged_keyBinding(self,*params): + value=self.keyBinding.get() + keySet=self.customKeys.get() + event=self.listBindings.get(ANCHOR).split()[0] if idleConf.IsCoreBinding(event): #this is a core keybinding - self.AddChangedItem('keys', keySet, event, value) + self.AddChangedItem('keys',keySet,event,value) else: #this is an extension key binding - extName = idleConf.GetExtnNameForEvent(event) - extKeybindSection = extName + '_cfgBindings' - self.AddChangedItem('extensions', extKeybindSection, event, value) + extName=idleConf.GetExtnNameForEvent(event) + extKeybindSection=extName+'_cfgBindings' + self.AddChangedItem('extensions',extKeybindSection,event,value) - def VarChanged_builtinKeys(self, *params): - value = self.builtinKeys.get() - self.AddChangedItem('main', 'Keys', 'name', value) + def VarChanged_builtinKeys(self,*params): + value=self.builtinKeys.get() + self.AddChangedItem('main','Keys','name',value) self.LoadKeysList(value) - def VarChanged_customKeys(self, *params): - value = self.customKeys.get() + def VarChanged_customKeys(self,*params): + value=self.customKeys.get() if value != '- no custom keys -': - self.AddChangedItem('main', 'Keys', 'name', value) + self.AddChangedItem('main','Keys','name',value) self.LoadKeysList(value) - def VarChanged_keysAreBuiltin(self, *params): - value = self.keysAreBuiltin.get() - self.AddChangedItem('main', 'Keys', 'default', value) + def VarChanged_keysAreBuiltin(self,*params): + value=self.keysAreBuiltin.get() + self.AddChangedItem('main','Keys','default',value) if value: self.VarChanged_builtinKeys() else: self.VarChanged_customKeys() - def VarChanged_winWidth(self, *params): - value = self.winWidth.get() - self.AddChangedItem('main', 'EditorWindow', 'width', value) + def VarChanged_winWidth(self,*params): + value=self.winWidth.get() + self.AddChangedItem('main','EditorWindow','width',value) - def VarChanged_winHeight(self, *params): - value = self.winHeight.get() - self.AddChangedItem('main', 'EditorWindow', 'height', value) + def VarChanged_winHeight(self,*params): + value=self.winHeight.get() + self.AddChangedItem('main','EditorWindow','height',value) - def VarChanged_paraWidth(self, *params): - value = self.paraWidth.get() - self.AddChangedItem('main', 'FormatParagraph', 'paragraph', value) + def VarChanged_paraWidth(self,*params): + value=self.paraWidth.get() + self.AddChangedItem('main','FormatParagraph','paragraph',value) - def VarChanged_startupEdit(self, *params): - value = self.startupEdit.get() - self.AddChangedItem('main', 'General', 'editor-on-startup', value) + def VarChanged_startupEdit(self,*params): + value=self.startupEdit.get() + self.AddChangedItem('main','General','editor-on-startup',value) - def VarChanged_autoSave(self, *params): - value = self.autoSave.get() - self.AddChangedItem('main', 'General', 'autosave', value) + def VarChanged_autoSave(self,*params): + value=self.autoSave.get() + self.AddChangedItem('main','General','autosave',value) - def VarChanged_encoding(self, *params): - value = self.encoding.get() - self.AddChangedItem('main', 'EditorWindow', 'encoding', value) + def VarChanged_encoding(self,*params): + value=self.encoding.get() + self.AddChangedItem('main','EditorWindow','encoding',value) def ResetChangedItems(self): #When any config item is changed in this dialog, an entry @@ -596,25 +554,24 @@ #dictionary. The key should be the config file section name and the #value a dictionary, whose key:value pairs are item=value pairs for #that config file section. - self.changedItems = {'main':{}, 'highlight':{}, 'keys':{}, - 'extensions':{}} + self.changedItems={'main':{},'highlight':{},'keys':{},'extensions':{}} - def AddChangedItem(self, typ, section, item, value): - value = str(value) #make sure we use a string - if section not in self.changedItems[typ]: - self.changedItems[typ][section] = {} - self.changedItems[typ][section][item] = value + def AddChangedItem(self,type,section,item,value): + value=str(value) #make sure we use a string + if section not in self.changedItems[type]: + self.changedItems[type][section]={} + self.changedItems[type][section][item]=value def GetDefaultItems(self): - dItems={'main':{}, 'highlight':{}, 'keys':{}, 'extensions':{}} + dItems={'main':{},'highlight':{},'keys':{},'extensions':{}} for configType in dItems: - sections = idleConf.GetSectionList('default', configType) + sections=idleConf.GetSectionList('default',configType) for section in sections: - dItems[configType][section] = {} - options = idleConf.defaultCfg[configType].GetOptionList(section) + dItems[configType][section]={} + options=idleConf.defaultCfg[configType].GetOptionList(section) for option in options: - dItems[configType][section][option] = ( - idleConf.defaultCfg[configType].Get(section, option)) + dItems[configType][section][option]=( + idleConf.defaultCfg[configType].Get(section,option)) return dItems def SetThemeType(self): @@ -640,26 +597,26 @@ self.buttonDeleteCustomKeys.config(state=NORMAL) def GetNewKeys(self): - listIndex = self.listBindings.index(ANCHOR) - binding = self.listBindings.get(listIndex) - bindName = binding.split()[0] #first part, up to first space + listIndex=self.listBindings.index(ANCHOR) + binding=self.listBindings.get(listIndex) + bindName=binding.split()[0] #first part, up to first space if self.keysAreBuiltin.get(): - currentKeySetName = self.builtinKeys.get() + currentKeySetName=self.builtinKeys.get() else: - currentKeySetName = self.customKeys.get() - currentBindings = idleConf.GetCurrentKeySet() + currentKeySetName=self.customKeys.get() + currentBindings=idleConf.GetCurrentKeySet() if currentKeySetName in self.changedItems['keys']: #unsaved changes - keySetChanges = self.changedItems['keys'][currentKeySetName] + keySetChanges=self.changedItems['keys'][currentKeySetName] for event in keySetChanges: - currentBindings[event] = keySetChanges[event].split() + currentBindings[event]=keySetChanges[event].split() currentKeySequences = list(currentBindings.values()) - newKeys = GetKeysDialog(self, 'Get New Keys', bindName, + newKeys=GetKeysDialog(self,'Get New Keys',bindName, currentKeySequences).result if newKeys: #new keys were specified if self.keysAreBuiltin.get(): #current key set is a built-in - message = ('Your changes will be saved as a new Custom Key Set.' - ' Enter a name for your new Custom Key Set below.') - newKeySet = self.GetNewKeysName(message) + message=('Your changes will be saved as a new Custom Key Set. '+ + 'Enter a name for your new Custom Key Set below.') + newKeySet=self.GetNewKeysName(message) if not newKeySet: #user cancelled custom key set creation self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex) @@ -667,7 +624,7 @@ else: #create new custom key set based on previously active key set self.CreateNewKeySet(newKeySet) self.listBindings.delete(listIndex) - self.listBindings.insert(listIndex, bindName+' - '+newKeys) + self.listBindings.insert(listIndex,bindName+' - '+newKeys) self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex) self.keyBinding.set(newKeys) @@ -675,65 +632,65 @@ self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex) - def GetNewKeysName(self, message): - usedNames = (idleConf.GetSectionList('user', 'keys') + - idleConf.GetSectionList('default', 'keys')) - newKeySet = GetCfgSectionNameDialog( - self, 'New Custom Key Set', message, usedNames).result + def GetNewKeysName(self,message): + usedNames=(idleConf.GetSectionList('user','keys')+ + idleConf.GetSectionList('default','keys')) + newKeySet=GetCfgSectionNameDialog(self,'New Custom Key Set', + message,usedNames).result return newKeySet def SaveAsNewKeySet(self): - newKeysName = self.GetNewKeysName('New Key Set Name:') + newKeysName=self.GetNewKeysName('New Key Set Name:') if newKeysName: self.CreateNewKeySet(newKeysName) - def KeyBindingSelected(self, event): + def KeyBindingSelected(self,event): self.buttonNewKeys.config(state=NORMAL) - def CreateNewKeySet(self, newKeySetName): + def CreateNewKeySet(self,newKeySetName): #creates new custom key set based on the previously active key set, #and makes the new key set active if self.keysAreBuiltin.get(): - prevKeySetName = self.builtinKeys.get() + prevKeySetName=self.builtinKeys.get() else: - prevKeySetName = self.customKeys.get() - prevKeys = idleConf.GetCoreKeys(prevKeySetName) - newKeys = {} + prevKeySetName=self.customKeys.get() + prevKeys=idleConf.GetCoreKeys(prevKeySetName) + newKeys={} for event in prevKeys: #add key set to changed items - eventName = event[2:-2] #trim off the angle brackets - binding = ' '.join(prevKeys[event]) - newKeys[eventName] = binding + eventName=event[2:-2] #trim off the angle brackets + binding=' '.join(prevKeys[event]) + newKeys[eventName]=binding #handle any unsaved changes to prev key set if prevKeySetName in self.changedItems['keys']: - keySetChanges = self.changedItems['keys'][prevKeySetName] + keySetChanges=self.changedItems['keys'][prevKeySetName] for event in keySetChanges: - newKeys[event] = keySetChanges[event] + newKeys[event]=keySetChanges[event] #save the new theme - self.SaveNewKeySet(newKeySetName, newKeys) + self.SaveNewKeySet(newKeySetName,newKeys) #change gui over to the new key set - customKeyList = idleConf.GetSectionList('user', 'keys') + customKeyList=idleConf.GetSectionList('user','keys') customKeyList.sort() - self.optMenuKeysCustom.SetMenu(customKeyList, newKeySetName) + self.optMenuKeysCustom.SetMenu(customKeyList,newKeySetName) self.keysAreBuiltin.set(0) self.SetKeysType() - def LoadKeysList(self, keySetName): - reselect = 0 - newKeySet = 0 + def LoadKeysList(self,keySetName): + reselect=0 + newKeySet=0 if self.listBindings.curselection(): - reselect = 1 - listIndex = self.listBindings.index(ANCHOR) - keySet = idleConf.GetKeySet(keySetName) + reselect=1 + listIndex=self.listBindings.index(ANCHOR) + keySet=idleConf.GetKeySet(keySetName) bindNames = list(keySet.keys()) bindNames.sort() - self.listBindings.delete(0, END) + self.listBindings.delete(0,END) for bindName in bindNames: - key = ' '.join(keySet[bindName]) #make key(s) into a string - bindName = bindName[2:-2] #trim off the angle brackets + key=' '.join(keySet[bindName]) #make key(s) into a string + bindName=bindName[2:-2] #trim off the angle brackets if keySetName in self.changedItems['keys']: #handle any unsaved changes to this key set if bindName in self.changedItems['keys'][keySetName]: - key = self.changedItems['keys'][keySetName][bindName] + key=self.changedItems['keys'][keySetName][bindName] self.listBindings.insert(END, bindName+' - '+key) if reselect: self.listBindings.see(listIndex) @@ -742,9 +699,9 @@ def DeleteCustomKeys(self): keySetName=self.customKeys.get() - delmsg = 'Are you sure you wish to delete the key set %r ?' - if not tkMessageBox.askyesno( - 'Delete Key Set', delmsg % keySetName, parent=self): + if not tkMessageBox.askyesno('Delete Key Set','Are you sure you wish '+ + 'to delete the key set %r ?' % (keySetName), + parent=self): return #remove key set from config idleConf.userCfg['keys'].remove_section(keySetName) @@ -753,25 +710,25 @@ #write changes idleConf.userCfg['keys'].Save() #reload user key set list - itemList = idleConf.GetSectionList('user', 'keys') + itemList=idleConf.GetSectionList('user','keys') itemList.sort() if not itemList: self.radioKeysCustom.config(state=DISABLED) - self.optMenuKeysCustom.SetMenu(itemList, '- no custom keys -') + self.optMenuKeysCustom.SetMenu(itemList,'- no custom keys -') else: - self.optMenuKeysCustom.SetMenu(itemList, itemList[0]) + self.optMenuKeysCustom.SetMenu(itemList,itemList[0]) #revert to default key set - self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys', 'default')) - self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys', 'name')) + self.keysAreBuiltin.set(idleConf.defaultCfg['main'].Get('Keys','default')) + self.builtinKeys.set(idleConf.defaultCfg['main'].Get('Keys','name')) #user can't back out of these changes, they must be applied now self.Apply() self.SetKeysType() def DeleteCustomTheme(self): - themeName = self.customTheme.get() - delmsg = 'Are you sure you wish to delete the theme %r ?' - if not tkMessageBox.askyesno( - 'Delete Theme', delmsg % themeName, parent=self): + themeName=self.customTheme.get() + if not tkMessageBox.askyesno('Delete Theme','Are you sure you wish '+ + 'to delete the theme %r ?' % (themeName,), + parent=self): return #remove theme from config idleConf.userCfg['highlight'].remove_section(themeName) @@ -780,149 +737,153 @@ #write changes idleConf.userCfg['highlight'].Save() #reload user theme list - itemList = idleConf.GetSectionList('user', 'highlight') + itemList=idleConf.GetSectionList('user','highlight') itemList.sort() if not itemList: self.radioThemeCustom.config(state=DISABLED) - self.optMenuThemeCustom.SetMenu(itemList, '- no custom themes -') + self.optMenuThemeCustom.SetMenu(itemList,'- no custom themes -') else: - self.optMenuThemeCustom.SetMenu(itemList, itemList[0]) + self.optMenuThemeCustom.SetMenu(itemList,itemList[0]) #revert to default theme - self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme', 'default')) - self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme', 'name')) + self.themeIsBuiltin.set(idleConf.defaultCfg['main'].Get('Theme','default')) + self.builtinTheme.set(idleConf.defaultCfg['main'].Get('Theme','name')) #user can't back out of these changes, they must be applied now self.Apply() self.SetThemeType() def GetColour(self): - target = self.highlightTarget.get() - prevColour = self.frameColourSet.cget('bg') - rgbTuplet, colourString = tkColorChooser.askcolor( - parent=self, title='Pick new colour for : '+target, - initialcolor=prevColour) - if colourString and (colourString != prevColour): + target=self.highlightTarget.get() + prevColour=self.frameColourSet.cget('bg') + rgbTuplet, colourString = tkColorChooser.askcolor(parent=self, + title='Pick new colour for : '+target,initialcolor=prevColour) + if colourString and (colourString!=prevColour): #user didn't cancel, and they chose a new colour - if self.themeIsBuiltin.get(): #current theme is a built-in - message = ('Your changes will be saved as a new Custom Theme. ' - 'Enter a name for your new Custom Theme below.') - newTheme = self.GetNewThemeName(message) - if not newTheme: #user cancelled custom theme creation + if self.themeIsBuiltin.get(): #current theme is a built-in + message=('Your changes will be saved as a new Custom Theme. '+ + 'Enter a name for your new Custom Theme below.') + newTheme=self.GetNewThemeName(message) + if not newTheme: #user cancelled custom theme creation return - else: #create new custom theme based on previously active theme + else: #create new custom theme based on previously active theme self.CreateNewTheme(newTheme) self.colour.set(colourString) - else: #current theme is user defined + else: #current theme is user defined self.colour.set(colourString) def OnNewColourSet(self): newColour=self.colour.get() - self.frameColourSet.config(bg=newColour) #set sample - plane ='foreground' if self.fgHilite.get() else 'background' - sampleElement = self.themeElements[self.highlightTarget.get()][0] + self.frameColourSet.config(bg=newColour)#set sample + if self.fgHilite.get(): plane='foreground' + else: plane='background' + sampleElement=self.themeElements[self.highlightTarget.get()][0] self.textHighlightSample.tag_config(sampleElement, **{plane:newColour}) - theme = self.customTheme.get() - themeElement = sampleElement + '-' + plane - self.AddChangedItem('highlight', theme, themeElement, newColour) + theme=self.customTheme.get() + themeElement=sampleElement+'-'+plane + self.AddChangedItem('highlight',theme,themeElement,newColour) - def GetNewThemeName(self, message): - usedNames = (idleConf.GetSectionList('user', 'highlight') + - idleConf.GetSectionList('default', 'highlight')) - newTheme = GetCfgSectionNameDialog( - self, 'New Custom Theme', message, usedNames).result + def GetNewThemeName(self,message): + usedNames=(idleConf.GetSectionList('user','highlight')+ + idleConf.GetSectionList('default','highlight')) + newTheme=GetCfgSectionNameDialog(self,'New Custom Theme', + message,usedNames).result return newTheme def SaveAsNewTheme(self): - newThemeName = self.GetNewThemeName('New Theme Name:') + newThemeName=self.GetNewThemeName('New Theme Name:') if newThemeName: self.CreateNewTheme(newThemeName) - def CreateNewTheme(self, newThemeName): + def CreateNewTheme(self,newThemeName): #creates new custom theme based on the previously active theme, #and makes the new theme active if self.themeIsBuiltin.get(): - themeType = 'default' - themeName = self.builtinTheme.get() + themeType='default' + themeName=self.builtinTheme.get() else: - themeType = 'user' - themeName = self.customTheme.get() - newTheme = idleConf.GetThemeDict(themeType, themeName) + themeType='user' + themeName=self.customTheme.get() + newTheme=idleConf.GetThemeDict(themeType,themeName) #apply any of the old theme's unsaved changes to the new theme if themeName in self.changedItems['highlight']: - themeChanges = self.changedItems['highlight'][themeName] + themeChanges=self.changedItems['highlight'][themeName] for element in themeChanges: - newTheme[element] = themeChanges[element] + newTheme[element]=themeChanges[element] #save the new theme - self.SaveNewTheme(newThemeName, newTheme) + self.SaveNewTheme(newThemeName,newTheme) #change gui over to the new theme - customThemeList = idleConf.GetSectionList('user', 'highlight') + customThemeList=idleConf.GetSectionList('user','highlight') customThemeList.sort() - self.optMenuThemeCustom.SetMenu(customThemeList, newThemeName) + self.optMenuThemeCustom.SetMenu(customThemeList,newThemeName) self.themeIsBuiltin.set(0) self.SetThemeType() - def OnListFontButtonRelease(self, event): + def OnListFontButtonRelease(self,event): font = self.listFontName.get(ANCHOR) self.fontName.set(font.lower()) self.SetFontSample() - def SetFontSample(self, event=None): - fontName = self.fontName.get() - fontWeight = tkFont.BOLD if self.fontBold.get() else tkFont.NORMAL + def SetFontSample(self,event=None): + fontName=self.fontName.get() + if self.fontBold.get(): + fontWeight=tkFont.BOLD + else: + fontWeight=tkFont.NORMAL newFont = (fontName, self.fontSize.get(), fontWeight) self.labelFontSample.config(font=newFont) self.textHighlightSample.configure(font=newFont) def SetHighlightTarget(self): - if self.highlightTarget.get() == 'Cursor': #bg not possible + if self.highlightTarget.get()=='Cursor': #bg not possible self.radioFg.config(state=DISABLED) self.radioBg.config(state=DISABLED) self.fgHilite.set(1) - else: #both fg and bg can be set + else: #both fg and bg can be set self.radioFg.config(state=NORMAL) self.radioBg.config(state=NORMAL) self.fgHilite.set(1) self.SetColourSample() - def SetColourSampleBinding(self, *args): + def SetColourSampleBinding(self,*args): self.SetColourSample() def SetColourSample(self): #set the colour smaple area - tag = self.themeElements[self.highlightTarget.get()][0] - plane = 'foreground' if self.fgHilite.get() else 'background' - colour = self.textHighlightSample.tag_cget(tag, plane) + tag=self.themeElements[self.highlightTarget.get()][0] + if self.fgHilite.get(): plane='foreground' + else: plane='background' + colour=self.textHighlightSample.tag_cget(tag,plane) self.frameColourSet.config(bg=colour) def PaintThemeSample(self): - if self.themeIsBuiltin.get(): #a default theme - theme = self.builtinTheme.get() - else: #a user theme - theme = self.customTheme.get() + if self.themeIsBuiltin.get(): #a default theme + theme=self.builtinTheme.get() + else: #a user theme + theme=self.customTheme.get() for elementTitle in self.themeElements: - element = self.themeElements[elementTitle][0] - colours = idleConf.GetHighlight(theme, element) - if element == 'cursor': #cursor sample needs special painting - colours['background'] = idleConf.GetHighlight( - theme, 'normal', fgBg='bg') + element=self.themeElements[elementTitle][0] + colours=idleConf.GetHighlight(theme,element) + if element=='cursor': #cursor sample needs special painting + colours['background']=idleConf.GetHighlight(theme, + 'normal', fgBg='bg') #handle any unsaved changes to this theme if theme in self.changedItems['highlight']: - themeDict = self.changedItems['highlight'][theme] - if element + '-foreground' in themeDict: - colours['foreground'] = themeDict[element + '-foreground'] - if element + '-background' in themeDict: - colours['background'] = themeDict[element + '-background'] + themeDict=self.changedItems['highlight'][theme] + if element+'-foreground' in themeDict: + colours['foreground']=themeDict[element+'-foreground'] + if element+'-background' in themeDict: + colours['background']=themeDict[element+'-background'] self.textHighlightSample.tag_config(element, **colours) self.SetColourSample() - def HelpSourceSelected(self, event): + def HelpSourceSelected(self,event): self.SetHelpListButtonStates() def SetHelpListButtonStates(self): - if self.listHelp.size() < 1: #no entries in list + if self.listHelp.size()<1: #no entries in list self.buttonHelpListEdit.config(state=DISABLED) self.buttonHelpListRemove.config(state=DISABLED) else: #there are some entries - if self.listHelp.curselection(): #there currently is a selection + if self.listHelp.curselection(): #there currently is a selection self.buttonHelpListEdit.config(state=NORMAL) self.buttonHelpListRemove.config(state=NORMAL) else: #there currently is not a selection @@ -930,29 +891,28 @@ self.buttonHelpListRemove.config(state=DISABLED) def HelpListItemAdd(self): - helpSource = GetHelpSourceDialog(self, 'New Help Source').result + helpSource=GetHelpSourceDialog(self,'New Help Source').result if helpSource: - self.userHelpList.append((helpSource[0], helpSource[1])) - self.listHelp.insert(END, helpSource[0]) + self.userHelpList.append( (helpSource[0],helpSource[1]) ) + self.listHelp.insert(END,helpSource[0]) self.UpdateUserHelpChangedItems() self.SetHelpListButtonStates() def HelpListItemEdit(self): - itemIndex = self.listHelp.index(ANCHOR) - helpSource = self.userHelpList[itemIndex] - newHelpSource = GetHelpSourceDialog( - self, 'Edit Help Source', menuItem=helpSource[0], - filePath=helpSource[1]).result - if (not newHelpSource) or (newHelpSource == helpSource): + itemIndex=self.listHelp.index(ANCHOR) + helpSource=self.userHelpList[itemIndex] + newHelpSource=GetHelpSourceDialog(self,'Edit Help Source', + menuItem=helpSource[0],filePath=helpSource[1]).result + if (not newHelpSource) or (newHelpSource==helpSource): return #no changes - self.userHelpList[itemIndex] = newHelpSource + self.userHelpList[itemIndex]=newHelpSource self.listHelp.delete(itemIndex) - self.listHelp.insert(itemIndex, newHelpSource[0]) + self.listHelp.insert(itemIndex,newHelpSource[0]) self.UpdateUserHelpChangedItems() self.SetHelpListButtonStates() def HelpListItemRemove(self): - itemIndex = self.listHelp.index(ANCHOR) + itemIndex=self.listHelp.index(ANCHOR) del(self.userHelpList[itemIndex]) self.listHelp.delete(itemIndex) self.UpdateUserHelpChangedItems() @@ -961,19 +921,18 @@ def UpdateUserHelpChangedItems(self): "Clear and rebuild the HelpFiles section in self.changedItems" self.changedItems['main']['HelpFiles'] = {} - for num in range(1, len(self.userHelpList) + 1): - self.AddChangedItem( - 'main', 'HelpFiles', str(num), + for num in range(1,len(self.userHelpList)+1): + self.AddChangedItem('main','HelpFiles',str(num), ';'.join(self.userHelpList[num-1][:2])) def LoadFontCfg(self): ##base editor font selection list - fonts = list(tkFont.families(self)) + fonts=list(tkFont.families(self)) fonts.sort() for font in fonts: - self.listFontName.insert(END, font) - configuredFont = idleConf.GetOption( - 'main', 'EditorWindow', 'font', default='courier') + self.listFontName.insert(END,font) + configuredFont=idleConf.GetOption('main','EditorWindow','font', + default='courier') lc_configuredFont = configuredFont.lower() self.fontName.set(lc_configuredFont) lc_fonts = [s.lower() for s in fonts] @@ -983,107 +942,107 @@ self.listFontName.select_set(currentFontIndex) self.listFontName.select_anchor(currentFontIndex) ##font size dropdown - fontSize = idleConf.GetOption( - 'main', 'EditorWindow', 'font-size', type='int', default='10') - self.optMenuFontSize.SetMenu(('7', '8', '9', '10', '11', '12', '13', - '14', '16', '18', '20', '22'), fontSize ) + fontSize=idleConf.GetOption('main', 'EditorWindow', 'font-size', + type='int', default='10') + self.optMenuFontSize.SetMenu(('7','8','9','10','11','12','13','14', + '16','18','20','22'), fontSize ) ##fontWeight - self.fontBold.set(idleConf.GetOption( - 'main', 'EditorWindow', 'font-bold', default=0, type='bool')) + self.fontBold.set(idleConf.GetOption('main','EditorWindow', + 'font-bold',default=0,type='bool')) ##font sample self.SetFontSample() def LoadTabCfg(self): ##indent sizes - spaceNum = idleConf.GetOption( - 'main', 'Indent', 'num-spaces', default=4, type='int') + spaceNum=idleConf.GetOption('main','Indent','num-spaces', + default=4,type='int') self.spaceNum.set(spaceNum) def LoadThemeCfg(self): ##current theme type radiobutton - self.themeIsBuiltin.set(idleConf.GetOption( - 'main', 'Theme', 'default', type='bool', default=1)) + self.themeIsBuiltin.set(idleConf.GetOption('main','Theme','default', + type='bool',default=1)) ##currently set theme - currentOption = idleConf.CurrentTheme() + currentOption=idleConf.CurrentTheme() ##load available theme option menus if self.themeIsBuiltin.get(): #default theme selected - itemList = idleConf.GetSectionList('default', 'highlight') + itemList=idleConf.GetSectionList('default','highlight') itemList.sort() - self.optMenuThemeBuiltin.SetMenu(itemList, currentOption) - itemList = idleConf.GetSectionList('user', 'highlight') + self.optMenuThemeBuiltin.SetMenu(itemList,currentOption) + itemList=idleConf.GetSectionList('user','highlight') itemList.sort() if not itemList: self.radioThemeCustom.config(state=DISABLED) self.customTheme.set('- no custom themes -') else: - self.optMenuThemeCustom.SetMenu(itemList, itemList[0]) + self.optMenuThemeCustom.SetMenu(itemList,itemList[0]) else: #user theme selected - itemList = idleConf.GetSectionList('user', 'highlight') + itemList=idleConf.GetSectionList('user','highlight') itemList.sort() - self.optMenuThemeCustom.SetMenu(itemList, currentOption) - itemList = idleConf.GetSectionList('default', 'highlight') + self.optMenuThemeCustom.SetMenu(itemList,currentOption) + itemList=idleConf.GetSectionList('default','highlight') itemList.sort() - self.optMenuThemeBuiltin.SetMenu(itemList, itemList[0]) + self.optMenuThemeBuiltin.SetMenu(itemList,itemList[0]) self.SetThemeType() ##load theme element option menu themeNames = list(self.themeElements.keys()) themeNames.sort(key=lambda x: self.themeElements[x][1]) - self.optMenuHighlightTarget.SetMenu(themeNames, themeNames[0]) + self.optMenuHighlightTarget.SetMenu(themeNames,themeNames[0]) self.PaintThemeSample() self.SetHighlightTarget() def LoadKeyCfg(self): ##current keys type radiobutton - self.keysAreBuiltin.set(idleConf.GetOption( - 'main', 'Keys', 'default', type='bool', default=1)) + self.keysAreBuiltin.set(idleConf.GetOption('main','Keys','default', + type='bool',default=1)) ##currently set keys - currentOption = idleConf.CurrentKeys() + currentOption=idleConf.CurrentKeys() ##load available keyset option menus if self.keysAreBuiltin.get(): #default theme selected - itemList = idleConf.GetSectionList('default', 'keys') + itemList=idleConf.GetSectionList('default','keys') itemList.sort() - self.optMenuKeysBuiltin.SetMenu(itemList, currentOption) - itemList = idleConf.GetSectionList('user', 'keys') + self.optMenuKeysBuiltin.SetMenu(itemList,currentOption) + itemList=idleConf.GetSectionList('user','keys') itemList.sort() if not itemList: self.radioKeysCustom.config(state=DISABLED) self.customKeys.set('- no custom keys -') else: - self.optMenuKeysCustom.SetMenu(itemList, itemList[0]) + self.optMenuKeysCustom.SetMenu(itemList,itemList[0]) else: #user key set selected - itemList = idleConf.GetSectionList('user', 'keys') + itemList=idleConf.GetSectionList('user','keys') itemList.sort() - self.optMenuKeysCustom.SetMenu(itemList, currentOption) - itemList = idleConf.GetSectionList('default', 'keys') + self.optMenuKeysCustom.SetMenu(itemList,currentOption) + itemList=idleConf.GetSectionList('default','keys') itemList.sort() - self.optMenuKeysBuiltin.SetMenu(itemList, itemList[0]) + self.optMenuKeysBuiltin.SetMenu(itemList,itemList[0]) self.SetKeysType() ##load keyset element list - keySetName = idleConf.CurrentKeys() + keySetName=idleConf.CurrentKeys() self.LoadKeysList(keySetName) def LoadGeneralCfg(self): #startup state - self.startupEdit.set(idleConf.GetOption( - 'main', 'General', 'editor-on-startup', default=1, type='bool')) + self.startupEdit.set(idleConf.GetOption('main','General', + 'editor-on-startup',default=1,type='bool')) #autosave state - self.autoSave.set(idleConf.GetOption( - 'main', 'General', 'autosave', default=0, type='bool')) + self.autoSave.set(idleConf.GetOption('main', 'General', 'autosave', + default=0, type='bool')) #initial window size - self.winWidth.set(idleConf.GetOption( - 'main', 'EditorWindow', 'width', type='int')) - self.winHeight.set(idleConf.GetOption( - 'main', 'EditorWindow', 'height', type='int')) + self.winWidth.set(idleConf.GetOption('main','EditorWindow','width', + type='int')) + self.winHeight.set(idleConf.GetOption('main','EditorWindow','height', + type='int')) #initial paragraph reformat size - self.paraWidth.set(idleConf.GetOption( - 'main', 'FormatParagraph', 'paragraph', type='int')) + self.paraWidth.set(idleConf.GetOption('main','FormatParagraph','paragraph', + type='int')) # default source encoding - self.encoding.set(idleConf.GetOption( - 'main', 'EditorWindow', 'encoding', default='none')) + self.encoding.set(idleConf.GetOption('main', 'EditorWindow', + 'encoding', default='none')) # additional help sources self.userHelpList = idleConf.GetAllExtraHelpSourcesList() for helpItem in self.userHelpList: - self.listHelp.insert(END, helpItem[0]) + self.listHelp.insert(END,helpItem[0]) self.SetHelpListButtonStates() def LoadConfigs(self): @@ -1101,7 +1060,7 @@ ### general page self.LoadGeneralCfg() - def SaveNewKeySet(self, keySetName, keySet): + def SaveNewKeySet(self,keySetName,keySet): """ save a newly created core key set. keySetName - string, the name of the new key set @@ -1110,10 +1069,10 @@ if not idleConf.userCfg['keys'].has_section(keySetName): idleConf.userCfg['keys'].add_section(keySetName) for event in keySet: - value = keySet[event] - idleConf.userCfg['keys'].SetOption(keySetName, event, value) + value=keySet[event] + idleConf.userCfg['keys'].SetOption(keySetName,event,value) - def SaveNewTheme(self, themeName, theme): + def SaveNewTheme(self,themeName,theme): """ save a newly created theme. themeName - string, the name of the new theme @@ -1122,16 +1081,16 @@ if not idleConf.userCfg['highlight'].has_section(themeName): idleConf.userCfg['highlight'].add_section(themeName) for element in theme: - value = theme[element] - idleConf.userCfg['highlight'].SetOption(themeName, element, value) + value=theme[element] + idleConf.userCfg['highlight'].SetOption(themeName,element,value) - def SetUserValue(self, configType, section, item, value): - if idleConf.defaultCfg[configType].has_option(section, item): - if idleConf.defaultCfg[configType].Get(section, item) == value: + def SetUserValue(self,configType,section,item,value): + if idleConf.defaultCfg[configType].has_option(section,item): + if idleConf.defaultCfg[configType].Get(section,item)==value: #the setting equals a default setting, remove it from user cfg - return idleConf.userCfg[configType].RemoveOption(section, item) + return idleConf.userCfg[configType].RemoveOption(section,item) #if we got here set the option - return idleConf.userCfg[configType].SetOption(section, item, value) + return idleConf.userCfg[configType].SetOption(section,item,value) def SaveAllChangedConfigs(self): "Save configuration changes to the user config file." @@ -1145,7 +1104,7 @@ cfgTypeHasChanges = True for item in self.changedItems[configType][section]: value = self.changedItems[configType][section][item] - if self.SetUserValue(configType, section, item, value): + if self.SetUserValue(configType,section,item,value): cfgTypeHasChanges = True if cfgTypeHasChanges: idleConf.userCfg[configType].Save() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/connection.py Fri Jul 25 11:39:11 2014 -0400 @@ -400,14 +400,17 @@ if n > 16384: # The payload is large so Nagle's algorithm won't be triggered # and we'd better avoid the cost of concatenation. - self._send(header) - self._send(buf) - else: + chunks = [header, buf] + elif n > 0: # Issue # 20540: concatenate before sending, to avoid delays due # to Nagle's algorithm on a TCP socket. - # Also note we want to avoid sending a 0-length buffer separately, - # to avoid "broken pipe" errors if the other end closed the pipe. - self._send(header + buf) + chunks = [header + buf] + else: + # This code path is necessary to avoid "broken pipe" errors + # when sending a 0-length buffer if the other end closed the pipe. + chunks = [header] + for chunk in chunks: + self._send(chunk) def _recv_bytes(self, maxsize=None): buf = self._recv(4) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/dummy/__init__.py --- a/Lib/multiprocessing/dummy/__init__.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/dummy/__init__.py Fri Jul 25 11:39:11 2014 -0400 @@ -86,7 +86,7 @@ if not name.startswith('_'): temp.append('%s=%r' % (name, value)) temp.sort() - return '%s(%s)' % (self.__class__.__name__, ', '.join(temp)) + return 'Namespace(%s)' % str.join(', ', temp) dict = dict list = list diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/managers.py --- a/Lib/multiprocessing/managers.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/managers.py Fri Jul 25 11:39:11 2014 -0400 @@ -65,8 +65,8 @@ (self.typeid, self.address, self.id) = state def __repr__(self): - return '%s(typeid=%r, address=%r, id=%r)' % \ - (self.__class__.__name__, self.typeid, self.address, self.id) + return 'Token(typeid=%r, address=%r, id=%r)' % \ + (self.typeid, self.address, self.id) # # Function for communication with a manager's server process @@ -803,8 +803,8 @@ return self._getvalue() def __repr__(self): - return '<%s object, typeid %r at %#x>' % \ - (type(self).__name__, self._token.typeid, id(self)) + return '<%s object, typeid %r at %s>' % \ + (type(self).__name__, self._token.typeid, '0x%x' % id(self)) def __str__(self): ''' @@ -901,7 +901,7 @@ if not name.startswith('_'): temp.append('%s=%r' % (name, value)) temp.sort() - return '%s(%s)' % (self.__class__.__name__, ', '.join(temp)) + return 'Namespace(%s)' % str.join(', ', temp) class Value(object): def __init__(self, typecode, value, lock=True): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/pool.py --- a/Lib/multiprocessing/pool.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/pool.py Fri Jul 25 11:39:11 2014 -0400 @@ -87,7 +87,7 @@ self.exc) def __repr__(self): - return "<%s: %s>" % (self.__class__.__name__, self) + return "" % str(self) def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None, diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/synchronize.py --- a/Lib/multiprocessing/synchronize.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/synchronize.py Fri Jul 25 11:39:11 2014 -0400 @@ -134,7 +134,7 @@ value = self._semlock._get_value() except Exception: value = 'unknown' - return '<%s(value=%s)>' % (self.__class__.__name__, value) + return '' % value # # Bounded semaphore @@ -150,8 +150,8 @@ value = self._semlock._get_value() except Exception: value = 'unknown' - return '<%s(value=%s, maxvalue=%s)>' % \ - (self.__class__.__name__, value, self._semlock.maxvalue) + return '' % \ + (value, self._semlock.maxvalue) # # Non-recursive lock @@ -176,7 +176,7 @@ name = 'SomeOtherProcess' except Exception: name = 'unknown' - return '<%s(owner=%s)>' % (self.__class__.__name__, name) + return '' % name # # Recursive lock @@ -202,7 +202,7 @@ name, count = 'SomeOtherProcess', 'nonzero' except Exception: name, count = 'unknown', 'unknown' - return '<%s(%s, %s)>' % (self.__class__.__name__, name, count) + return '' % (name, count) # # Condition variable @@ -243,7 +243,7 @@ self._woken_count._semlock._get_value()) except Exception: num_waiters = 'unknown' - return '<%s(%s, %s)>' % (self.__class__.__name__, self._lock, num_waiters) + return '' % (self._lock, num_waiters) def wait(self, timeout=None): assert self._lock._semlock._is_mine(), \ diff -r 79e469ae13b7 -r 01438f18ee18 Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/multiprocessing/util.py Fri Jul 25 11:39:11 2014 -0400 @@ -212,11 +212,10 @@ obj = None if obj is None: - return '<%s object, dead>' % self.__class__.__name__ + return '' - x = '<%s object, callback=%s' % ( - self.__class__.__name__, - getattr(self._callback, '__name__', self._callback)) + x = '' % (self.__class__.__module__, - self.__class__.__qualname__) + return '' _GoInteractive = object() def __call__(self, request=_GoInteractive): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/shutil.py --- a/Lib/shutil.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/shutil.py Fri Jul 25 11:39:11 2014 -0400 @@ -21,13 +21,6 @@ _BZ2_SUPPORTED = False try: - import lzma - del lzma - _LZMA_SUPPORTED = True -except ImportError: - _LZMA_SUPPORTED = False - -try: from pwd import getpwnam except ImportError: getpwnam = None @@ -587,14 +580,14 @@ """Create a (possibly compressed) tar file from all the files under 'base_dir'. - 'compress' must be "gzip" (the default), "bzip2", "xz", or None. + 'compress' must be "gzip" (the default), "bzip2", or None. 'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owner and group will be used. The output tar file will be named 'base_name' + ".tar", possibly plus - the appropriate compression extension (".gz", ".bz2", or ".xz"). + the appropriate compression extension (".gz", or ".bz2"). Returns the output filename. """ @@ -605,10 +598,6 @@ tar_compression['bzip2'] = 'bz2' compress_ext['bzip2'] = '.bz2' - if _LZMA_SUPPORTED: - tar_compression['xz'] = 'xz' - compress_ext['xz'] = '.xz' - # flags for compression program, each element of list will be an argument if compress is not None and compress not in compress_ext: raise ValueError("bad value for 'compress', or compression format not " @@ -695,10 +684,6 @@ _ARCHIVE_FORMATS['bztar'] = (_make_tarball, [('compress', 'bzip2')], "bzip2'ed tar-file") -if _LZMA_SUPPORTED: - _ARCHIVE_FORMATS['xztar'] = (_make_tarball, [('compress', 'xz')], - "xz'ed tar-file") - def get_archive_formats(): """Returns a list of supported formats for archiving and unarchiving. @@ -887,7 +872,7 @@ zip.close() def _unpack_tarfile(filename, extract_dir): - """Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` + """Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` """ try: tarobj = tarfile.open(filename) @@ -906,13 +891,9 @@ } if _BZ2_SUPPORTED: - _UNPACK_FORMATS['bztar'] = (['.tar.bz2', '.tbz2'], _unpack_tarfile, [], + _UNPACK_FORMATS['bztar'] = (['.bz2'], _unpack_tarfile, [], "bzip2'ed tar-file") -if _LZMA_SUPPORTED: - _UNPACK_FORMATS['xztar'] = (['.tar.xz', '.txz'], _unpack_tarfile, [], - "xz'ed tar-file") - def _find_unpack_format(filename): for name, info in _UNPACK_FORMATS.items(): for extension in info[0]: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/subprocess.py --- a/Lib/subprocess.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/subprocess.py Fri Jul 25 11:39:11 2014 -0400 @@ -464,7 +464,7 @@ raise ValueError("already closed") def __repr__(self): - return "%s(%d)" % (self.__class__.__name__, int(self)) + return "Handle(%d)" % int(self) __del__ = Close __str__ = __repr__ diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/datetimetester.py --- a/Lib/test/datetimetester.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/datetimetester.py Fri Jul 25 11:39:11 2014 -0400 @@ -5,7 +5,6 @@ import sys import pickle -import random import unittest from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod @@ -77,18 +76,8 @@ def __init__(self, offset=None, name=None, dstoffset=None): FixedOffset.__init__(self, offset, name, dstoffset) -class _TZInfo(tzinfo): - def utcoffset(self, datetime_module): - return random.random() - class TestTZInfo(unittest.TestCase): - def test_refcnt_crash_bug_22044(self): - tz1 = _TZInfo() - dt1 = datetime(2014, 7, 21, 11, 32, 3, 0, tz1) - with self.assertRaises(TypeError): - dt1.utcoffset() - def test_non_abstractness(self): # In order to allow subclasses to get pickled, the C implementation # wasn't able to get away with having __init__ raise diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/list_tests.py --- a/Lib/test/list_tests.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/list_tests.py Fri Jul 25 11:39:11 2014 -0400 @@ -30,12 +30,6 @@ self.assertNotEqual(id(a), id(b)) self.assertEqual(a, b) - def test_getitem_error(self): - msg = "list indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - a = [] - a['a'] = "python" - def test_repr(self): l0 = [] l2 = [0, 1, 2] @@ -126,10 +120,6 @@ a[-1] = 9 self.assertEqual(a, self.type2test([5,6,7,8,9])) - msg = "list indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - a['a'] = "python" - def test_delitem(self): a = self.type2test([0, 1]) del a[1] diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/make_ssl_certs.py --- a/Lib/test/make_ssl_certs.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/make_ssl_certs.py Fri Jul 25 11:39:11 2014 -0400 @@ -115,7 +115,7 @@ with open(os.path.join('cadir','index.txt'),'a+') as f: pass # empty file with open(os.path.join('cadir','crl.txt'),'a+') as f: - f.write("00") + r.write("00") with open(os.path.join('cadir','index.txt.attr'),'w+') as f: f.write('unique_subject = no') diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/regrtest.py Fri Jul 25 11:39:11 2014 -0400 @@ -1273,10 +1273,8 @@ # tests. If not, use normal unittest test loading. test_runner = getattr(the_module, "test_main", None) if test_runner is None: - def test_runner(): - loader = unittest.TestLoader() - tests = loader.loadTestsFromModule(the_module) - support.run_unittest(tests) + tests = unittest.TestLoader().loadTestsFromModule(the_module) + test_runner = lambda: support.run_unittest(tests) test_runner() if huntrleaks: refleak = dash_R(the_module, test, test_runner, huntrleaks) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_argparse.py Fri Jul 25 11:39:11 2014 -0400 @@ -226,8 +226,8 @@ parser = self._get_parser(tester) for args_str in tester.failures: args = args_str.split() - with tester.assertRaises(ArgumentParserError, msg=args): - parser.parse_args(args) + raises = tester.assertRaises + raises(ArgumentParserError, parser.parse_args, args) def test_successes(self, tester): parser = self._get_parser(tester) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncio/test_events.py --- a/Lib/test/test_asyncio/test_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncio/test_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -383,24 +383,6 @@ self.assertEqual(read, data) def _basetest_sock_client_ops(self, httpd, sock): - # in debug mode, socket operations must fail - # if the socket is not in blocking mode - self.loop.set_debug(True) - sock.setblocking(True) - with self.assertRaises(ValueError): - self.loop.run_until_complete( - self.loop.sock_connect(sock, httpd.address)) - with self.assertRaises(ValueError): - self.loop.run_until_complete( - self.loop.sock_sendall(sock, b'GET / HTTP/1.0\r\n\r\n')) - with self.assertRaises(ValueError): - self.loop.run_until_complete( - self.loop.sock_recv(sock, 1024)) - with self.assertRaises(ValueError): - self.loop.run_until_complete( - self.loop.sock_accept(sock)) - - # test in non-blocking mode sock.setblocking(False) self.loop.run_until_complete( self.loop.sock_connect(sock, httpd.address)) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncio/test_futures.py --- a/Lib/test/test_asyncio/test_futures.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncio/test_futures.py Fri Jul 25 11:39:11 2014 -0400 @@ -105,15 +105,6 @@ self.assertEqual(next(g), ('C', 42)) # yield 'C', y. def test_future_repr(self): - self.loop.set_debug(True) - f_pending_debug = asyncio.Future(loop=self.loop) - frame = f_pending_debug._source_traceback[-1] - self.assertEqual(repr(f_pending_debug), - '' - % (frame[0], frame[1])) - f_pending_debug.cancel() - - self.loop.set_debug(False) f_pending = asyncio.Future(loop=self.loop) self.assertEqual(repr(f_pending), '') f_pending.cancel() @@ -308,6 +299,12 @@ @mock.patch('asyncio.base_events.logger') def test_future_exception_never_retrieved(self, m_log): + # FIXME: Python issue #21163, other tests may "leak" pending task which + # emit a warning when they are destroyed by the GC + support.gc_collect() + m_log.error.reset_mock() + # --- + self.loop.set_debug(True) def memory_error(): @@ -327,7 +324,7 @@ if sys.version_info >= (3, 4): frame = source_traceback[-1] regex = (r'^Future exception was never retrieved\n' - r'future: \n' + r'future: \n' r'source_traceback: Object created at \(most recent call last\):\n' r' File' r'.*\n' diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncio/test_locks.py --- a/Lib/test/test_asyncio/test_locks.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncio/test_locks.py Fri Jul 25 11:39:11 2014 -0400 @@ -656,21 +656,6 @@ self.assertFalse(cond.locked()) - def test_explicit_lock(self): - lock = asyncio.Lock(loop=self.loop) - cond = asyncio.Condition(lock, loop=self.loop) - - self.assertIs(cond._lock, lock) - self.assertIs(cond._loop, lock._loop) - - def test_ambiguous_loops(self): - loop = self.new_test_loop() - self.addCleanup(loop.close) - - lock = asyncio.Lock(loop=self.loop) - with self.assertRaises(ValueError): - asyncio.Condition(lock, loop=loop) - class SemaphoreTests(test_utils.TestCase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncio/test_tasks.py --- a/Lib/test/test_asyncio/test_tasks.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncio/test_tasks.py Fri Jul 25 11:39:11 2014 -0400 @@ -132,8 +132,6 @@ asyncio.async('ok') def test_task_repr(self): - self.loop.set_debug(False) - @asyncio.coroutine def notmuch(): yield from [] @@ -191,8 +189,6 @@ "" % coro) def test_task_repr_coro_decorator(self): - self.loop.set_debug(False) - @asyncio.coroutine def notmuch(): # notmuch() function doesn't use yield from: it will be wrapped by @@ -256,8 +252,6 @@ self.loop.run_until_complete(t) def test_task_repr_wait_for(self): - self.loop.set_debug(False) - @asyncio.coroutine def wait_for(fut): return (yield from fut) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncio/test_unix_events.py --- a/Lib/test/test_asyncio/test_unix_events.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncio/test_unix_events.py Fri Jul 25 11:39:11 2014 -0400 @@ -306,9 +306,9 @@ self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 - blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') - blocking_patcher.start() - self.addCleanup(blocking_patcher.stop) + fcntl_patcher = mock.patch('fcntl.fcntl') + fcntl_patcher.start() + self.addCleanup(fcntl_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() @@ -469,9 +469,9 @@ self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 - blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') - blocking_patcher.start() - self.addCleanup(blocking_patcher.stop) + fcntl_patcher = mock.patch('fcntl.fcntl') + fcntl_patcher.start() + self.addCleanup(fcntl_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_asyncore.py --- a/Lib/test/test_asyncore.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_asyncore.py Fri Jul 25 11:39:11 2014 -0400 @@ -417,8 +417,6 @@ # Issue #11453 fd = os.open(support.TESTFN, os.O_RDONLY) f = asyncore.file_wrapper(fd) - - os.close(fd) with support.check_warnings(('', ResourceWarning)): f = None support.gc_collect() @@ -426,8 +424,6 @@ def test_close_twice(self): fd = os.open(support.TESTFN, os.O_RDONLY) f = asyncore.file_wrapper(fd) - os.close(fd) - f.close() self.assertEqual(f.fd, -1) # calling close twice should not fail diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_bytes.py --- a/Lib/test/test_bytes.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_bytes.py Fri Jul 25 11:39:11 2014 -0400 @@ -699,13 +699,8 @@ class BytesTest(BaseBytesTest, unittest.TestCase): type2test = bytes - def test_getitem_error(self): - msg = "byte indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - b'python'['a'] - def test_buffer_is_readonly(self): - fd = os.open(__file__, os.O_RDONLY) + fd = os.dup(sys.stdin.fileno()) with open(fd, "rb", buffering=0) as f: self.assertRaises(TypeError, f.readinto, b"") @@ -758,17 +753,6 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase): type2test = bytearray - def test_getitem_error(self): - msg = "bytearray indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - bytearray(b'python')['a'] - - def test_setitem_error(self): - msg = "bytearray indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - b = bytearray(b'python') - b['a'] = "python" - def test_nohash(self): self.assertRaises(TypeError, hash, bytearray()) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_class.py --- a/Lib/test/test_class.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_class.py Fri Jul 25 11:39:11 2014 -0400 @@ -482,6 +482,22 @@ else: self.fail("Failed to raise RuntimeError") + def testCallRecursion(self): + # test for infinite recursion in __call__ + #issue 9743 + + def a(): + pass + + try: + while True: + a = a.__call__ + a() # This should not segfault + except RuntimeError: + pass + else: + self.fail("Failed to raise RuntimeError") + def testForExceptionsRaisedInInstanceGetattr2(self): # Tests for exceptions raised in instance_getattr2(). diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_csv.py --- a/Lib/test/test_csv.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_csv.py Fri Jul 25 11:39:11 2014 -0400 @@ -51,6 +51,7 @@ self.assertEqual(obj.dialect.quotechar, '"') self.assertEqual(obj.dialect.quoting, csv.QUOTE_MINIMAL) self.assertEqual(obj.dialect.skipinitialspace, False) + self.assertEqual(obj.dialect.skipinitialwhitespace, False) self.assertEqual(obj.dialect.strict, False) # Try deleting or changing attributes (they are read-only) self.assertRaises(AttributeError, delattr, obj.dialect, 'delimiter') @@ -69,7 +70,7 @@ # Now try with alternate options kwargs = dict(delimiter=':', doublequote=False, escapechar='\\', lineterminator='\r', quotechar='*', - quoting=csv.QUOTE_NONE, skipinitialspace=True, + quoting=csv.QUOTE_NONE, skipinitialspace=True, skipinitialwhitespace=True, strict=True) obj = ctor(*args, **kwargs) self.assertEqual(obj.dialect.delimiter, ':') @@ -79,6 +80,7 @@ self.assertEqual(obj.dialect.quotechar, '*') self.assertEqual(obj.dialect.quoting, csv.QUOTE_NONE) self.assertEqual(obj.dialect.skipinitialspace, True) + self.assertEqual(obj.dialect.skipinitialwhitespace, True) self.assertEqual(obj.dialect.strict, True) def test_reader_kw_attrs(self): @@ -97,6 +99,7 @@ quotechar='#' quoting=csv.QUOTE_ALL skipinitialspace=True + skipinitialwhitespace=True strict=False args = args + (dialect,) obj = ctor(*args) @@ -107,6 +110,7 @@ self.assertEqual(obj.dialect.quotechar, '#') self.assertEqual(obj.dialect.quoting, csv.QUOTE_ALL) self.assertEqual(obj.dialect.skipinitialspace, True) + self.assertEqual(obj.dialect.skipinitialwhitespace, True) self.assertEqual(obj.dialect.strict, False) def test_reader_dialect_attrs(self): @@ -783,7 +787,7 @@ with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"quotechar" must be a 1-character string') + '"quotechar" must be an 1-character string') mydialect.quotechar = 4 with self.assertRaises(csv.Error) as cm: @@ -806,13 +810,13 @@ with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"delimiter" must be a 1-character string') + '"delimiter" must be an 1-character string') mydialect.delimiter = "" with self.assertRaises(csv.Error) as cm: mydialect() self.assertEqual(str(cm.exception), - '"delimiter" must be a 1-character string') + '"delimiter" must be an 1-character string') mydialect.delimiter = b"," with self.assertRaises(csv.Error) as cm: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_email/test__header_value_parser.py --- a/Lib/test/test_email/test__header_value_parser.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_email/test__header_value_parser.py Fri Jul 25 11:39:11 2014 -0400 @@ -2443,18 +2443,6 @@ self.assertEqual(str(address_list.addresses[1]), str(address_list.mailboxes[2])) - def test_invalid_content_disposition(self): - content_disp = self._test_parse_x( - parser.parse_content_disposition_header, - ";attachment", "; attachment", ";attachment", - [errors.InvalidHeaderDefect]*2 - ) - - def test_invalid_content_transfer_encoding(self): - cte = self._test_parse_x( - parser.parse_content_transfer_encoding_header, - ";foo", ";foo", ";foo", [errors.InvalidHeaderDefect]*3 - ) @parameterize class Test_parse_mime_version(TestParserMixin, TestEmailBase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_htmlparser.py --- a/Lib/test/test_htmlparser.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_htmlparser.py Fri Jul 25 11:39:11 2014 -0400 @@ -85,7 +85,7 @@ class TestCaseBase(unittest.TestCase): def get_collector(self): - return EventCollector(convert_charrefs=False) + raise NotImplementedError def _run_check(self, source, expected_events, collector=None): if collector is None: @@ -105,8 +105,21 @@ self._run_check(source, events, EventCollectorExtra(convert_charrefs=False)) + def _parse_error(self, source): + def parse(source=source): + parser = self.get_collector() + parser.feed(source) + parser.close() + with self.assertRaises(html.parser.HTMLParseError): + with self.assertWarns(DeprecationWarning): + parse() -class HTMLParserTestCase(TestCaseBase): + +class HTMLParserStrictTestCase(TestCaseBase): + + def get_collector(self): + with support.check_warnings(("", DeprecationWarning), quite=False): + return EventCollector(strict=True, convert_charrefs=False) def test_processing_instruction_only(self): self._run_check("", [ @@ -188,6 +201,9 @@ ("data", "this < text > contains < bare>pointy< brackets"), ]) + def test_illegal_declarations(self): + self._parse_error('') + def test_starttag_end_boundary(self): self._run_check("""""", [("starttag", "a", [("b", "<")])]) self._run_check("""""", [("starttag", "a", [("b", ">")])]) @@ -222,6 +238,25 @@ self._run_check(["", ""], output) + def test_starttag_junk_chars(self): + self._parse_error("") + self._parse_error("") + self._parse_error("") + self._parse_error("") + self._parse_error("'") + self._parse_error("" % dtd, [('decl', 'DOCTYPE ' + dtd)]) + def test_declaration_junk_chars(self): + self._parse_error("") + def test_startendtag(self): self._run_check("

", [ ("startendtag", "p", []), @@ -346,8 +384,7 @@ self._run_check(html, expected) def test_convert_charrefs(self): - # default value for convert_charrefs is now True - collector = lambda: EventCollectorCharrefs() + collector = lambda: EventCollectorCharrefs(convert_charrefs=True) self.assertTrue(collector().convert_charrefs) charrefs = ['"', '"', '"', '"', '"', '"'] # check charrefs in the middle of the text/attributes @@ -384,8 +421,23 @@ self._run_check('no charrefs here', [('data', 'no charrefs here')], collector=collector()) - # the remaining tests were for the "tolerant" parser (which is now - # the default), and check various kind of broken markup + +class HTMLParserTolerantTestCase(HTMLParserStrictTestCase): + + def get_collector(self): + return EventCollector(convert_charrefs=False) + + def test_deprecation_warnings(self): + with self.assertWarns(DeprecationWarning): + EventCollector() # convert_charrefs not passed explicitly + with self.assertWarns(DeprecationWarning): + EventCollector(strict=True) + with self.assertWarns(DeprecationWarning): + EventCollector(strict=False) + with self.assertRaises(html.parser.HTMLParseError): + with self.assertWarns(DeprecationWarning): + EventCollector().error('test') + def test_tolerant_parsing(self): self._run_check('te>>xt&a<\n' '", diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_imaplib.py --- a/Lib/test/test_imaplib.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_imaplib.py Fri Jul 25 11:39:11 2014 -0400 @@ -11,8 +11,7 @@ import time import calendar -from test.support import (reap_threads, verbose, transient_internet, - run_with_tz, run_with_locale) +from test.support import reap_threads, verbose, transient_internet, run_with_tz, run_with_locale import unittest from datetime import datetime, timezone, timedelta try: @@ -23,8 +22,8 @@ else: from ssl import HAS_SNI -CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "keycert3.pem") -CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, "pycacert.pem") +CERTFILE = None +CAFILE = None class TestImaplib(unittest.TestCase): @@ -45,15 +44,17 @@ def test_Internaldate2tuple_issue10941(self): self.assertNotEqual(imaplib.Internaldate2tuple( b'25 (INTERNALDATE "02-Apr-2000 02:30:00 +0000")'), - imaplib.Internaldate2tuple( - b'25 (INTERNALDATE "02-Apr-2000 03:30:00 +0000")')) + imaplib.Internaldate2tuple( + b'25 (INTERNALDATE "02-Apr-2000 03:30:00 +0000")')) + + def timevalues(self): return [2000000000, 2000000000.0, time.localtime(2000000000), (2033, 5, 18, 5, 33, 20, -1, -1, -1), (2033, 5, 18, 5, 33, 20, -1, -1, 1), datetime.fromtimestamp(2000000000, - timezone(timedelta(0, 2 * 60 * 60))), + timezone(timedelta(0, 2*60*60))), '"18-May-2033 05:33:20 +0200"'] @run_with_locale('LC_ALL', 'de_DE', 'fr_FR') @@ -74,6 +75,7 @@ if ssl: + class SecureTCPServer(socketserver.TCPServer): def get_request(self): @@ -94,13 +96,13 @@ class SimpleIMAPHandler(socketserver.StreamRequestHandler): + timeout = 1 continuation = None capabilities = '' def _send(self, message): - if verbose: - print("SENT: %r" % message.strip()) + if verbose: print("SENT: %r" % message.strip()) self.wfile.write(message) def _send_line(self, message): @@ -133,8 +135,7 @@ if line.endswith(b'\r\n'): break - if verbose: - print('GOT: %r' % line.strip()) + if verbose: print('GOT: %r' % line.strip()) if self.continuation: try: self.continuation.send(line) @@ -146,8 +147,8 @@ cmd = splitline[1] args = splitline[2:] - if hasattr(self, 'cmd_' + cmd): - continuation = getattr(self, 'cmd_' + cmd)(tag, args) + if hasattr(self, 'cmd_'+cmd): + continuation = getattr(self, 'cmd_'+cmd)(tag, args) if continuation: self.continuation = continuation next(continuation) @@ -155,9 +156,7 @@ self._send_tagged(tag, 'BAD', cmd + ' unknown') def cmd_CAPABILITY(self, tag, args): - caps = ('IMAP4rev1 ' + self.capabilities - if self.capabilities - else 'IMAP4rev1') + caps = 'IMAP4rev1 ' + self.capabilities if self.capabilities else 'IMAP4rev1' self._send_textline('* CAPABILITY ' + caps) self._send_tagged(tag, 'OK', 'CAPABILITY completed') @@ -166,9 +165,7 @@ self._send_tagged(tag, 'OK', 'LOGOUT completed') -class ThreadedNetworkedTests(unittest.TestCase): - server_class = socketserver.TCPServer - imap_class = imaplib.IMAP4 +class BaseThreadedNetworkedTests(unittest.TestCase): def make_server(self, addr, hdlr): @@ -178,8 +175,7 @@ self.server_close() raise - if verbose: - print("creating server") + if verbose: print("creating server") server = MyServer(addr, hdlr) self.assertEqual(server.server_address, server.socket.getsockname()) @@ -195,21 +191,18 @@ # Short poll interval to make the test finish quickly. # Time between requests is short enough that we won't wake # up spuriously too many times. - kwargs={'poll_interval': 0.01}) + kwargs={'poll_interval':0.01}) t.daemon = True # In case this function raises. t.start() - if verbose: - print("server running") + if verbose: print("server running") return server, t def reap_server(self, server, thread): - if verbose: - print("waiting for server") + if verbose: print("waiting for server") server.shutdown() server.server_close() thread.join() - if verbose: - print("done") + if verbose: print("done") @contextmanager def reaped_server(self, hdlr): @@ -266,7 +259,7 @@ def cmd_AUTHENTICATE(self, tag, args): self._send_tagged(tag, 'NO', 'unrecognized authentication ' - 'type {}'.format(args[0])) + 'type {}'.format(args[0])) with self.reaped_pair(MyServer) as (server, client): with self.assertRaises(imaplib.IMAP4.error): @@ -300,13 +293,13 @@ code, data = client.authenticate('MYAUTH', lambda x: b'fake') self.assertEqual(code, 'OK') self.assertEqual(server.response, - b'ZmFrZQ==\r\n') # b64 encoded 'fake' + b'ZmFrZQ==\r\n') #b64 encoded 'fake' with self.reaped_pair(MyServer) as (server, client): code, data = client.authenticate('MYAUTH', lambda x: 'fake') self.assertEqual(code, 'OK') self.assertEqual(server.response, - b'ZmFrZQ==\r\n') # b64 encoded 'fake' + b'ZmFrZQ==\r\n') #b64 encoded 'fake' @reap_threads def test_login_cram_md5(self): @@ -317,10 +310,9 @@ def cmd_AUTHENTICATE(self, tag, args): self._send_textline('+ PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2Uucm' - 'VzdG9uLm1jaS5uZXQ=') + 'VzdG9uLm1jaS5uZXQ=') r = yield - if (r == b'dGltIGYxY2E2YmU0NjRiOWVmYT' - b'FjY2E2ZmZkNmNmMmQ5ZjMy\r\n'): + if r == b'dGltIGYxY2E2YmU0NjRiOWVmYTFjY2E2ZmZkNmNmMmQ5ZjMy\r\n': self._send_tagged(tag, 'OK', 'CRAM-MD5 successful') else: self._send_tagged(tag, 'NO', 'No access') @@ -335,19 +327,27 @@ ret, data = client.login_cram_md5("tim", b"tanstaaftanstaaf") self.assertEqual(ret, "OK") + def test_linetoolong(self): class TooLongHandler(SimpleIMAPHandler): def handle(self): # Send a very long response line - self.wfile.write(b'* OK ' + imaplib._MAXLINE * b'x' + b'\r\n') + self.wfile.write(b'* OK ' + imaplib._MAXLINE*b'x' + b'\r\n') with self.reaped_server(TooLongHandler) as server: self.assertRaises(imaplib.IMAP4.error, self.imap_class, *server.server_address) +class ThreadedNetworkedTests(BaseThreadedNetworkedTests): + + server_class = socketserver.TCPServer + imap_class = imaplib.IMAP4 + + @unittest.skipUnless(ssl, "SSL not available") -class ThreadedNetworkedTestsSSL(ThreadedNetworkedTests): +class ThreadedNetworkedTestsSSL(BaseThreadedNetworkedTests): + server_class = SecureTCPServer imap_class = IMAP4_SSL @@ -359,9 +359,8 @@ ssl_context.check_hostname = True ssl_context.load_verify_locations(CAFILE) - with self.assertRaisesRegex( - ssl.CertificateError, - "hostname '127.0.0.1' doesn't match 'localhost'"): + with self.assertRaisesRegex(ssl.CertificateError, + "hostname '127.0.0.1' doesn't match 'localhost'"): with self.reaped_server(SimpleIMAPHandler) as server: client = self.imap_class(*server.server_address, ssl_context=ssl_context) @@ -373,8 +372,6 @@ client.shutdown() -@unittest.skipUnless( - support.is_resource_enabled('network'), 'network resource disabled') class RemoteIMAPTest(unittest.TestCase): host = 'cyrus.andrew.cmu.edu' port = 143 @@ -408,8 +405,6 @@ @unittest.skipUnless(ssl, "SSL not available") -@unittest.skipUnless( - support.is_resource_enabled('network'), 'network resource disabled') class RemoteIMAP_STARTTLSTest(RemoteIMAPTest): def setUp(self): @@ -463,8 +458,7 @@ def test_logincapa_with_client_ssl_context(self): with transient_internet(self.host): - _server = self.imap_class( - self.host, self.port, ssl_context=self.create_ssl_context()) + _server = self.imap_class(self.host, self.port, ssl_context=self.create_ssl_context()) self.check_logincapa(_server) def test_logout(self): @@ -475,15 +469,35 @@ def test_ssl_context_certfile_exclusive(self): with transient_internet(self.host): - self.assertRaises( - ValueError, self.imap_class, self.host, self.port, - certfile=CERTFILE, ssl_context=self.create_ssl_context()) + self.assertRaises(ValueError, self.imap_class, self.host, self.port, + certfile=CERTFILE, ssl_context=self.create_ssl_context()) def test_ssl_context_keyfile_exclusive(self): with transient_internet(self.host): - self.assertRaises( - ValueError, self.imap_class, self.host, self.port, - keyfile=CERTFILE, ssl_context=self.create_ssl_context()) + self.assertRaises(ValueError, self.imap_class, self.host, self.port, + keyfile=CERTFILE, ssl_context=self.create_ssl_context()) + + +def load_tests(*args): + tests = [TestImaplib] + + if support.is_resource_enabled('network'): + if ssl: + global CERTFILE, CAFILE + CERTFILE = os.path.join(os.path.dirname(__file__) or os.curdir, + "keycert3.pem") + if not os.path.exists(CERTFILE): + raise support.TestFailed("Can't read certificate files!") + CAFILE = os.path.join(os.path.dirname(__file__) or os.curdir, + "pycacert.pem") + if not os.path.exists(CAFILE): + raise support.TestFailed("Can't read CA file!") + tests.extend([ + ThreadedNetworkedTests, ThreadedNetworkedTestsSSL, + RemoteIMAPTest, RemoteIMAP_SSLTest, RemoteIMAP_STARTTLSTest, + ]) + + return unittest.TestSuite([unittest.makeSuite(test) for test in tests]) if __name__ == "__main__": diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_io.py --- a/Lib/test/test_io.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_io.py Fri Jul 25 11:39:11 2014 -0400 @@ -44,6 +44,10 @@ import threading except ImportError: threading = None +try: + import fcntl +except ImportError: + fcntl = None def _default_chunk_size(): """Get the default TextIOWrapper chunk size""" @@ -3226,20 +3230,26 @@ with self.open(support.TESTFN, **kwargs) as f: self.assertRaises(TypeError, pickle.dumps, f, protocol) + @unittest.skipUnless(fcntl, 'fcntl required for this test') def test_nonblock_pipe_write_bigbuf(self): self._test_nonblock_pipe_write(16*1024) + @unittest.skipUnless(fcntl, 'fcntl required for this test') def test_nonblock_pipe_write_smallbuf(self): self._test_nonblock_pipe_write(1024) - @unittest.skipUnless(hasattr(os, 'set_blocking'), - 'os.set_blocking() required for this test') + def _set_non_blocking(self, fd): + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + self.assertNotEqual(flags, -1) + res = fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) + self.assertEqual(res, 0) + def _test_nonblock_pipe_write(self, bufsize): sent = [] received = [] r, w = os.pipe() - os.set_blocking(r, False) - os.set_blocking(w, False) + self._set_non_blocking(r) + self._set_non_blocking(w) # To exercise all code paths in the C implementation we need # to play with buffer sizes. For instance, if we choose a diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_memoryio.py --- a/Lib/test/test_memoryio.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_memoryio.py Fri Jul 25 11:39:11 2014 -0400 @@ -9,7 +9,6 @@ import io import _pyio as pyio import pickle -import sys class MemorySeekTestMixin: @@ -712,57 +711,12 @@ @support.cpython_only def test_sizeof(self): - basesize = support.calcobjsize('P2nN2PnP') + basesize = support.calcobjsize('P2nN2Pn') check = self.check_sizeof self.assertEqual(object.__sizeof__(io.BytesIO()), basesize) check(io.BytesIO(), basesize ) - check(io.BytesIO(b'a'), basesize + 1 ) - check(io.BytesIO(b'a' * 1000), basesize + 1000) - - # Various tests of copy-on-write behaviour for BytesIO. - - def _test_cow_mutation(self, mutation): - # Common code for all BytesIO copy-on-write mutation tests. - imm = b' ' * 1024 - old_rc = sys.getrefcount(imm) - memio = self.ioclass(imm) - self.assertEqual(sys.getrefcount(imm), old_rc + 1) - mutation(memio) - self.assertEqual(sys.getrefcount(imm), old_rc) - - @support.cpython_only - def test_cow_truncate(self): - # Ensure truncate causes a copy. - def mutation(memio): - memio.truncate(1) - self._test_cow_mutation(mutation) - - @support.cpython_only - def test_cow_write(self): - # Ensure write that would not cause a resize still results in a copy. - def mutation(memio): - memio.seek(0) - memio.write(b'foo') - self._test_cow_mutation(mutation) - - @support.cpython_only - def test_cow_setstate(self): - # __setstate__ should cause buffer to be released. - memio = self.ioclass(b'foooooo') - state = memio.__getstate__() - def mutation(memio): - memio.__setstate__(state) - self._test_cow_mutation(mutation) - - @support.cpython_only - def test_cow_mutable(self): - # BytesIO should accept only Bytes for copy-on-write sharing, since - # arbitrary buffer-exporting objects like bytearray() aren't guaranteed - # to be immutable. - ba = bytearray(1024) - old_rc = sys.getrefcount(ba) - memio = self.ioclass(ba) - self.assertEqual(sys.getrefcount(ba), old_rc) + check(io.BytesIO(b'a'), basesize + 1 + 1 ) + check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 ) class CStringIOTest(PyStringIOTest): ioclass = io.StringIO diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_os.py --- a/Lib/test/test_os.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_os.py Fri Jul 25 11:39:11 2014 -0400 @@ -1376,16 +1376,6 @@ def test_writev(self): self.check(os.writev, [b'abc']) - def test_inheritable(self): - self.check(os.get_inheritable) - self.check(os.set_inheritable, True) - - @unittest.skipUnless(hasattr(os, 'get_blocking'), - 'needs os.get_blocking() and os.set_blocking()') - def test_blocking(self): - self.check(os.get_blocking) - self.check(os.set_blocking, True) - class LinkTests(unittest.TestCase): def setUp(self): @@ -2601,21 +2591,6 @@ self.assertEqual(os.get_inheritable(slave_fd), False) -@unittest.skipUnless(hasattr(os, 'get_blocking'), - 'needs os.get_blocking() and os.set_blocking()') -class BlockingTests(unittest.TestCase): - def test_blocking(self): - fd = os.open(__file__, os.O_RDONLY) - self.addCleanup(os.close, fd) - self.assertEqual(os.get_blocking(fd), True) - - os.set_blocking(fd, False) - self.assertEqual(os.get_blocking(fd), False) - - os.set_blocking(fd, True) - self.assertEqual(os.get_blocking(fd), True) - - @support.reap_threads def test_main(): support.run_unittest( @@ -2651,7 +2626,6 @@ CPUCountTests, FDInheritanceTests, Win32JunctionTests, - BlockingTests, ) if __name__ == "__main__": diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_pathlib.py --- a/Lib/test/test_pathlib.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_pathlib.py Fri Jul 25 11:39:11 2014 -0400 @@ -4,10 +4,13 @@ import errno import pathlib import pickle +import shutil import socket import stat +import sys import tempfile import unittest +from contextlib import contextmanager from test import support TESTFN = support.TESTFN @@ -740,6 +743,7 @@ self.assertEqual(P('//Some/SHARE/a/B'), P('//somE/share/A/b')) def test_as_uri(self): + from urllib.parse import quote_from_bytes P = self.cls with self.assertRaises(ValueError): P('/a/b').as_uri() @@ -1613,59 +1617,6 @@ # the parent's permissions follow the default process settings self.assertEqual(stat.S_IMODE(p.parent.stat().st_mode), mode) - def test_mkdir_exist_ok(self): - p = self.cls(BASE, 'dirB') - st_ctime_first = p.stat().st_ctime - self.assertTrue(p.exists()) - self.assertTrue(p.is_dir()) - with self.assertRaises(FileExistsError) as cm: - p.mkdir() - self.assertEqual(cm.exception.errno, errno.EEXIST) - p.mkdir(exist_ok=True) - self.assertTrue(p.exists()) - self.assertEqual(p.stat().st_ctime, st_ctime_first) - - def test_mkdir_exist_ok_with_parent(self): - p = self.cls(BASE, 'dirC') - self.assertTrue(p.exists()) - with self.assertRaises(FileExistsError) as cm: - p.mkdir() - self.assertEqual(cm.exception.errno, errno.EEXIST) - p = p / 'newdirC' - p.mkdir(parents=True) - st_ctime_first = p.stat().st_ctime - self.assertTrue(p.exists()) - with self.assertRaises(FileExistsError) as cm: - p.mkdir(parents=True) - self.assertEqual(cm.exception.errno, errno.EEXIST) - p.mkdir(parents=True, exist_ok=True) - self.assertTrue(p.exists()) - self.assertEqual(p.stat().st_ctime, st_ctime_first) - - def test_mkdir_with_child_file(self): - p = self.cls(BASE, 'dirB', 'fileB') - self.assertTrue(p.exists()) - # An exception is raised when the last path component is an existing - # regular file, regardless of whether exist_ok is true or not. - with self.assertRaises(FileExistsError) as cm: - p.mkdir(parents=True) - self.assertEqual(cm.exception.errno, errno.EEXIST) - with self.assertRaises(FileExistsError) as cm: - p.mkdir(parents=True, exist_ok=True) - self.assertEqual(cm.exception.errno, errno.EEXIST) - - def test_mkdir_no_parents_file(self): - p = self.cls(BASE, 'fileA') - self.assertTrue(p.exists()) - # An exception is raised when the last path component is an existing - # regular file, regardless of whether exist_ok is true or not. - with self.assertRaises(FileExistsError) as cm: - p.mkdir() - self.assertEqual(cm.exception.errno, errno.EEXIST) - with self.assertRaises(FileExistsError) as cm: - p.mkdir(exist_ok=True) - self.assertEqual(cm.exception.errno, errno.EEXIST) - @with_symlinks def test_symlink_to(self): P = self.cls(BASE) @@ -1901,6 +1852,7 @@ @with_symlinks def test_resolve_loop(self): # Loop detection for broken symlinks under POSIX + P = self.cls # Loops with relative symlinks os.symlink('linkX/inside', join('linkX')) self._check_symlink_loop(BASE, 'linkX') diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_pep277.py --- a/Lib/test/test_pep277.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_pep277.py Fri Jul 25 11:39:11 2014 -0400 @@ -56,6 +56,17 @@ "Unicode-friendly filesystem encoding") +# Destroy directory dirname and all files under it, to one level. +def deltree(dirname): + # Don't hide legitimate errors: if one of these suckers exists, it's + # an error if we can't remove it. + if os.path.exists(dirname): + # must pass unicode to os.listdir() so we get back unicode results. + for fname in os.listdir(str(dirname)): + os.unlink(os.path.join(dirname, fname)) + os.rmdir(dirname) + + class UnicodeFileTests(unittest.TestCase): files = set(filenames) normal_form = None @@ -65,8 +76,6 @@ os.mkdir(support.TESTFN) except FileExistsError: pass - self.addCleanup(support.rmtree, support.TESTFN) - files = set() for name in self.files: name = os.path.join(support.TESTFN, self.norm(name)) @@ -76,6 +85,9 @@ files.add(name) self.files = files + def tearDown(self): + deltree(support.TESTFN) + def norm(self, s): if self.normal_form: return normalize(self.normal_form, s) @@ -188,13 +200,16 @@ def test_main(): - support.run_unittest( - UnicodeFileTests, - UnicodeNFCFileTests, - UnicodeNFDFileTests, - UnicodeNFKCFileTests, - UnicodeNFKDFileTests, - ) + try: + support.run_unittest( + UnicodeFileTests, + UnicodeNFCFileTests, + UnicodeNFDFileTests, + UnicodeNFKCFileTests, + UnicodeNFKDFileTests, + ) + finally: + deltree(support.TESTFN) if __name__ == "__main__": diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_platform.py --- a/Lib/test/test_platform.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_platform.py Fri Jul 25 11:39:11 2014 -0400 @@ -307,7 +307,7 @@ with mock.patch('platform._UNIXCONFDIR', tempdir): distname, version, distid = platform.linux_distribution() - self.assertEqual(distname, 'Fedora') + self.assertEqual(distname, 'Fedora') self.assertEqual(version, '19') self.assertEqual(distid, 'Schr\xf6dinger\u2019s Cat') diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_posix.py Fri Jul 25 11:39:11 2014 -0400 @@ -9,6 +9,7 @@ import sys import time import os +import fcntl import platform import pwd import shutil @@ -354,7 +355,7 @@ def test_oscloexec(self): fd = os.open(support.TESTFN, os.O_RDONLY|os.O_CLOEXEC) self.addCleanup(os.close, fd) - self.assertFalse(os.get_inheritable(fd)) + self.assertTrue(fcntl.fcntl(fd, fcntl.F_GETFD) & fcntl.FD_CLOEXEC) @unittest.skipUnless(hasattr(posix, 'O_EXLOCK'), 'test needs posix.O_EXLOCK') @@ -604,8 +605,8 @@ self.addCleanup(os.close, w) self.assertFalse(os.get_inheritable(r)) self.assertFalse(os.get_inheritable(w)) - self.assertFalse(os.get_blocking(r)) - self.assertFalse(os.get_blocking(w)) + self.assertTrue(fcntl.fcntl(r, fcntl.F_GETFL) & os.O_NONBLOCK) + self.assertTrue(fcntl.fcntl(w, fcntl.F_GETFL) & os.O_NONBLOCK) # try reading from an empty pipe: this should fail, not block self.assertRaises(OSError, os.read, r, 1) # try a write big enough to fill-up the pipe: this should either diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_pty.py --- a/Lib/test/test_pty.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_pty.py Fri Jul 25 11:39:11 2014 -0400 @@ -1,6 +1,7 @@ from test.support import verbose, run_unittest, import_module, reap_children -# Skip these tests if termios is not available +#Skip these tests if either fcntl or termios is not available +fcntl = import_module('fcntl') import_module('termios') import errno @@ -83,18 +84,16 @@ # in master_open(), we need to read the EOF. # Ensure the fd is non-blocking in case there's nothing to read. - blocking = os.get_blocking(master_fd) + orig_flags = fcntl.fcntl(master_fd, fcntl.F_GETFL) + fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags | os.O_NONBLOCK) try: - os.set_blocking(master_fd, False) - try: - s1 = os.read(master_fd, 1024) - self.assertEqual(b'', s1) - except OSError as e: - if e.errno != errno.EAGAIN: - raise - finally: - # Restore the original flags. - os.set_blocking(master_fd, blocking) + s1 = os.read(master_fd, 1024) + self.assertEqual(b'', s1) + except OSError as e: + if e.errno != errno.EAGAIN: + raise + # Restore the original flags. + fcntl.fcntl(master_fd, fcntl.F_SETFL, orig_flags) debug("Writing to slave_fd") os.write(slave_fd, TEST_STRING_1) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_shutil.py Fri Jul 25 11:39:11 2014 -0400 @@ -10,7 +10,6 @@ import errno import functools import subprocess -from contextlib import ExitStack from test import support from test.support import TESTFN from os.path import splitdrive @@ -33,12 +32,6 @@ except ImportError: BZ2_SUPPORTED = False -try: - import lzma - LZMA_SUPPORTED = True -except ImportError: - LZMA_SUPPORTED = False - TESTFN2 = TESTFN + "2" try: @@ -123,9 +116,7 @@ write_file(os.path.join(victim, 'somefile'), 'foo') victim = os.fsencode(victim) self.assertIsInstance(victim, bytes) - win = (os.name == 'nt') - with self.assertWarns(DeprecationWarning) if win else ExitStack(): - shutil.rmtree(victim) + shutil.rmtree(victim) @support.skip_unless_symlink def test_rmtree_fails_on_symlink(self): @@ -1165,8 +1156,6 @@ formats = ['tar', 'gztar', 'zip'] if BZ2_SUPPORTED: formats.append('bztar') - if LZMA_SUPPORTED: - formats.append('xztar') for format in formats: tmpdir = self.mkdtemp() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_signal.py --- a/Lib/test/test_signal.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_signal.py Fri Jul 25 11:39:11 2014 -0400 @@ -6,7 +6,6 @@ import pickle import select import signal -import socket import struct import subprocess import traceback @@ -256,13 +255,6 @@ self.assertRaises((ValueError, OSError), signal.set_wakeup_fd, fd) - def test_invalid_socket(self): - sock = socket.socket() - fd = sock.fileno() - sock.close() - self.assertRaises((ValueError, OSError), - signal.set_wakeup_fd, fd) - def test_set_wakeup_fd_result(self): r1, w1 = os.pipe() self.addCleanup(os.close, r1) @@ -276,20 +268,6 @@ self.assertEqual(signal.set_wakeup_fd(-1), w2) self.assertEqual(signal.set_wakeup_fd(-1), -1) - def test_set_wakeup_fd_socket_result(self): - sock1 = socket.socket() - self.addCleanup(sock1.close) - fd1 = sock1.fileno() - - sock2 = socket.socket() - self.addCleanup(sock2.close) - fd2 = sock2.fileno() - - signal.set_wakeup_fd(fd1) - self.assertEqual(signal.set_wakeup_fd(fd2), fd1) - self.assertEqual(signal.set_wakeup_fd(-1), fd2) - self.assertEqual(signal.set_wakeup_fd(-1), -1) - @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class WakeupSignalTests(unittest.TestCase): @@ -298,6 +276,7 @@ # use a subprocess to have only one thread code = """if 1: import _testcapi + import fcntl import os import signal import struct @@ -320,7 +299,10 @@ signal.signal(signal.SIGALRM, handler) read, write = os.pipe() - os.set_blocking(write, False) + for fd in (read, write): + flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(fd, fcntl.F_SETFL, flags) signal.set_wakeup_fd(write) test() @@ -340,6 +322,7 @@ code = """if 1: import _testcapi import errno + import fcntl import os import signal import sys @@ -350,7 +333,8 @@ signal.signal(signal.SIGALRM, handler) r, w = os.pipe() - os.set_blocking(r, False) + flags = fcntl.fcntl(r, fcntl.F_GETFL, 0) + fcntl.fcntl(r, fcntl.F_SETFL, flags | os.O_NONBLOCK) # Set wakeup_fd a read-only file descriptor to trigger the error signal.set_wakeup_fd(r) @@ -457,90 +441,6 @@ """, signal.SIGUSR1, signal.SIGUSR2, ordered=False) -@unittest.skipUnless(hasattr(socket, 'socketpair'), 'need socket.socketpair') -class WakeupSocketSignalTests(unittest.TestCase): - - @unittest.skipIf(_testcapi is None, 'need _testcapi') - def test_socket(self): - # use a subprocess to have only one thread - code = """if 1: - import signal - import socket - import struct - import _testcapi - - signum = signal.SIGINT - signals = (signum,) - - def handler(signum, frame): - pass - - signal.signal(signum, handler) - - read, write = socket.socketpair() - read.setblocking(False) - write.setblocking(False) - signal.set_wakeup_fd(write.fileno()) - - _testcapi.raise_signal(signum) - - data = read.recv(1) - if not data: - raise Exception("no signum written") - raised = struct.unpack('B', data) - if raised != signals: - raise Exception("%r != %r" % (raised, signals)) - - read.close() - write.close() - """ - - assert_python_ok('-c', code) - - @unittest.skipIf(_testcapi is None, 'need _testcapi') - def test_send_error(self): - # Use a subprocess to have only one thread. - if os.name == 'nt': - action = 'send' - else: - action = 'write' - code = """if 1: - import errno - import signal - import socket - import sys - import time - import _testcapi - from test.support import captured_stderr - - signum = signal.SIGINT - - def handler(signum, frame): - pass - - signal.signal(signum, handler) - - read, write = socket.socketpair() - read.setblocking(False) - write.setblocking(False) - - signal.set_wakeup_fd(write.fileno()) - - # Close sockets: send() will fail - read.close() - write.close() - - with captured_stderr() as err: - _testcapi.raise_signal(signum) - - err = err.getvalue() - if ('Exception ignored when trying to {action} to the signal wakeup fd' - not in err): - raise AssertionError(err) - """.format(action=action) - assert_python_ok('-c', code) - - @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class SiginterruptTest(unittest.TestCase): @@ -1090,7 +990,6 @@ try: support.run_unittest(GenericTests, PosixTests, InterProcessSignalTests, WakeupFDTests, WakeupSignalTests, - WakeupSocketSignalTests, SiginterruptTest, ItimerTest, WindowsSignalTests, PendingSignalsTests) finally: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_socket.py --- a/Lib/test/test_socket.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_socket.py Fri Jul 25 11:39:11 2014 -0400 @@ -3,7 +3,6 @@ import errno import io -import itertools import socket import select import tempfile @@ -40,11 +39,6 @@ except ImportError: thread = None threading = None -try: - import _socket -except ImportError: - _socket = None - def _have_socket_can(): """Check whether CAN sockets are supported on this host.""" @@ -665,19 +659,6 @@ self.assertIn('[closed]', repr(s)) self.assertNotIn('laddr', repr(s)) - @unittest.skipUnless(_socket is not None, 'need _socket module') - def test_csocket_repr(self): - s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM) - try: - expected = ('' - % (s.fileno(), s.family, s.type, s.proto)) - self.assertEqual(repr(s), expected) - finally: - s.close() - expected = ('' - % (s.family, s.type, s.proto)) - self.assertEqual(repr(s), expected) - def test_weakref(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) p = proxy(s) @@ -1166,24 +1147,17 @@ sock.close() def test_getsockaddrarg(self): - sock = socket.socket() - self.addCleanup(sock.close) + host = '0.0.0.0' port = support.find_unused_port() big_port = port + 65536 neg_port = port - 65536 - self.assertRaises(OverflowError, sock.bind, (HOST, big_port)) - self.assertRaises(OverflowError, sock.bind, (HOST, neg_port)) - # Since find_unused_port() is inherently subject to race conditions, we - # call it a couple times if necessary. - for i in itertools.count(): - port = support.find_unused_port() - try: - sock.bind((HOST, port)) - except OSError as e: - if e.errno != errno.EADDRINUSE or i == 5: - raise - else: - break + sock = socket.socket() + try: + self.assertRaises(OverflowError, sock.bind, (host, big_port)) + self.assertRaises(OverflowError, sock.bind, (host, neg_port)) + sock.bind((host, port)) + finally: + sock.close() @unittest.skipUnless(os.name == "nt", "Windows specific") def test_sock_ioctl(self): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_sys.py --- a/Lib/test/test_sys.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_sys.py Fri Jul 25 11:39:11 2014 -0400 @@ -784,7 +784,7 @@ # buffer # XXX # builtin_function_or_method - check(len, size('4P')) # XXX check layout + check(len, size('3P')) # XXX check layout # bytearray samples = [b'', b'u'*100000] for sample in samples: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_tcl.py Fri Jul 25 11:39:11 2014 -0400 @@ -389,12 +389,8 @@ self.assertEqual(passValue('str\x00ing'), 'str\x00ing') self.assertEqual(passValue('str\x00ing\xbd'), 'str\x00ing\xbd') self.assertEqual(passValue('str\x00ing\u20ac'), 'str\x00ing\u20ac') - self.assertEqual(passValue(b'str\x00ing'), - b'str\x00ing' if self.wantobjects else 'str\x00ing') - self.assertEqual(passValue(b'str\xc0\x80ing'), - b'str\xc0\x80ing' if self.wantobjects else 'str\xc0\x80ing') - self.assertEqual(passValue(b'str\xbding'), - b'str\xbding' if self.wantobjects else 'str\xbding') + self.assertEqual(passValue(b'str\x00ing'), 'str\x00ing') + self.assertEqual(passValue(b'str\xc0\x80ing'), 'str\x00ing') for i in (0, 1, -1, 2**31-1, -2**31): self.assertEqual(passValue(i), i if self.wantobjects else str(i)) for f in (0.0, 1.0, -1.0, 1/3, @@ -418,7 +414,6 @@ self.assertEqual(passValue(['a', ['b', 'c']]), ('a', ('b', 'c')) if self.wantobjects else 'a {b c}') - @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX') def test_user_command(self): result = None def testfunc(arg): @@ -444,14 +439,12 @@ check('string\xbd', 'string\xbd') check('string\u20ac', 'string\u20ac') check(b'string', 'string') - check(b'string\xe2\x82\xac', 'string\xe2\x82\xac') - check(b'string\xbd', 'string\xbd') + check(b'string\xe2\x82\xac', 'string\u20ac') check('str\x00ing', 'str\x00ing') check('str\x00ing\xbd', 'str\x00ing\xbd') check('str\x00ing\u20ac', 'str\x00ing\u20ac') - check(b'str\x00ing', 'str\x00ing') - check(b'str\xc0\x80ing', 'str\xc0\x80ing') - check(b'str\xc0\x80ing\xe2\x82\xac', 'str\xc0\x80ing\xe2\x82\xac') + check(b'str\xc0\x80ing', 'str\x00ing') + check(b'str\xc0\x80ing\xe2\x82\xac', 'str\x00ing\u20ac') for i in (0, 1, -1, 2**31-1, -2**31): check(i, str(i)) for f in (0.0, 1.0, -1.0): @@ -499,9 +492,9 @@ if tcl_version >= (8, 5): if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5): # Before 8.5.5 dicts were converted to lists through string - expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4') + expected = ('12', '\u20ac', '\u20ac', '3.4') else: - expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,)) + expected = (12, '\u20ac', '\u20ac', (3.4,)) testcases += [ (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)), expected), @@ -549,9 +542,9 @@ if tcl_version >= (8, 5): if not self.wantobjects or get_tk_patchlevel() < (8, 5, 5): # Before 8.5.5 dicts were converted to lists through string - expected = ('12', '\u20ac', '\xe2\x82\xac', '3.4') + expected = ('12', '\u20ac', '\u20ac', '3.4') else: - expected = (12, '\u20ac', b'\xe2\x82\xac', (3.4,)) + expected = (12, '\u20ac', '\u20ac', (3.4,)) testcases += [ (call('dict', 'create', 12, '\u20ac', b'\xe2\x82\xac', (3.4,)), expected), diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_tempfile.py --- a/Lib/test/test_tempfile.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_tempfile.py Fri Jul 25 11:39:11 2014 -0400 @@ -762,10 +762,8 @@ def test_no_leak_fd(self): # Issue #21058: don't leak file descriptor when io.open() fails closed = [] - os_close = os.close def close(fd): closed.append(fd) - os_close(fd) with mock.patch('os.close', side_effect=close): with mock.patch('io.open', side_effect=ValueError): @@ -1078,10 +1076,8 @@ def test_no_leak_fd(self): # Issue #21058: don't leak file descriptor when io.open() fails closed = [] - os_close = os.close def close(fd): closed.append(fd) - os_close(fd) with mock.patch('os.close', side_effect=close): with mock.patch('io.open', side_effect=ValueError): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_tuple.py --- a/Lib/test/test_tuple.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_tuple.py Fri Jul 25 11:39:11 2014 -0400 @@ -6,11 +6,6 @@ class TupleTest(seq_tests.CommonTest): type2test = tuple - def test_getitem_error(self): - msg = "tuple indices must be integers or slices" - with self.assertRaisesRegex(TypeError, msg): - ()['a'] - def test_constructors(self): super().test_constructors() # calling built-in types without argument must return empty diff -r 79e469ae13b7 -r 01438f18ee18 Lib/test/test_weakref.py --- a/Lib/test/test_weakref.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/test/test_weakref.py Fri Jul 25 11:39:11 2014 -0400 @@ -92,18 +92,6 @@ self.check_basic_callback(create_function) self.check_basic_callback(create_bound_method) - @support.cpython_only - def test_cfunction(self): - import _testcapi - create_cfunction = _testcapi.create_cfunction - f = create_cfunction() - wr = weakref.ref(f) - self.assertIs(wr(), f) - del f - self.assertIsNone(wr()) - self.check_basic_ref(create_cfunction) - self.check_basic_callback(create_cfunction) - def test_multiple_callbacks(self): o = C() ref1 = weakref.ref(o, self.callback) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/tkinter/__init__.py --- a/Lib/tkinter/__init__.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/tkinter/__init__.py Fri Jul 25 11:39:11 2014 -0400 @@ -3789,7 +3789,8 @@ def _test(): root = Tk() text = "This is Tcl/Tk version %s" % TclVersion - text += "\nThis should be a cedilla: \xe7" + if TclVersion >= 8.1: + text += "\nThis should be a cedilla: \xe7" label = Label(root, text=text) label.pack() test = Button(root, text="Click me!", diff -r 79e469ae13b7 -r 01438f18ee18 Lib/tkinter/test/test_tkinter/test_images.py --- a/Lib/tkinter/test/test_tkinter/test_images.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/tkinter/test/test_tkinter/test_images.py Fri Jul 25 11:39:11 2014 -0400 @@ -161,18 +161,21 @@ def test_create_from_ppm_file(self): self.check_create_from_file('ppm') + @unittest.skip('issue #21580') def test_create_from_ppm_data(self): self.check_create_from_data('ppm') def test_create_from_pgm_file(self): self.check_create_from_file('pgm') + @unittest.skip('issue #21580') def test_create_from_pgm_data(self): self.check_create_from_data('pgm') def test_create_from_gif_file(self): self.check_create_from_file('gif') + @unittest.skip('issue #21580') def test_create_from_gif_data(self): self.check_create_from_data('gif') @@ -180,10 +183,12 @@ def test_create_from_png_file(self): self.check_create_from_file('png') + @unittest.skip('issue #21580') @requires_tcl(8, 6) def test_create_from_png_data(self): self.check_create_from_data('png') + @unittest.skip('issue #21580') def test_configure_data(self): image = tkinter.PhotoImage('::img::test', master=self.root) self.assertEqual(image['data'], '') diff -r 79e469ae13b7 -r 01438f18ee18 Lib/turtledemo/__main__.py --- a/Lib/turtledemo/__main__.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/turtledemo/__main__.py Fri Jul 25 11:39:11 2014 -0400 @@ -112,22 +112,6 @@ root.title('Python turtle-graphics examples') root.wm_protocol("WM_DELETE_WINDOW", self._destroy) - if sys.platform == 'darwin': - import subprocess - # Make sure we are the currently activated OS X application - # so that our menu bar appears. - p = subprocess.Popen( - [ - 'osascript', - '-e', 'tell application "System Events"', - '-e', 'set frontmost of the first process whose ' - 'unix id is {} to true'.format(os.getpid()), - '-e', 'end tell', - ], - stderr=subprocess.DEVNULL, - stdout=subprocess.DEVNULL, - ) - root.grid_rowconfigure(1, weight=1) root.grid_columnconfigure(0, weight=1) root.grid_columnconfigure(1, minsize=90, weight=1) @@ -215,12 +199,25 @@ def configGUI(self, menu, start, stop, clear, txt="", color="blue"): self.ExamplesBtn.config(state=menu) - self.start_btn.config(state=start, - bg="#d00" if start == NORMAL else "#fca") - self.stop_btn.config(state=stop, - bg="#d00" if stop == NORMAL else "#fca") - self.clear_btn.config(state=clear, - bg="#d00" if clear == NORMAL else"#fca") + self.start_btn.config(state=start) + if start == NORMAL: + self.start_btn.config(bg="#d00") + else: + self.start_btn.config(bg="#fca") + + self.stop_btn.config(state=stop) + if stop == NORMAL: + self.stop_btn.config(bg="#d00") + else: + self.stop_btn.config(bg="#fca") + self.clear_btn.config(state=clear) + + self.clear_btn.config(state=clear) + if clear == NORMAL: + self.clear_btn.config(bg="#d00") + else: + self.clear_btn.config(bg="#fca") + self.output_lbl.config(text=txt, fg=color) def makeLoadDemoMenu(self): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/__init__.py --- a/Lib/unittest/__init__.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/__init__.py Fri Jul 25 11:39:11 2014 -0400 @@ -47,7 +47,7 @@ __all__ = ['TestResult', 'TestCase', 'TestSuite', 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main', 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless', - 'expectedFailure', 'TextTestResult', 'installHandler', + 'expectedFailure', 'testBaseClass', 'TextTestResult', 'installHandler', 'registerResult', 'removeResult', 'removeHandler'] # Expose obsolete functions for backwards compatibility @@ -57,7 +57,7 @@ from .result import TestResult from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf, - skipUnless, expectedFailure) + skipUnless, expectedFailure, testBaseClass) from .suite import BaseTestSuite, TestSuite from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames, findTestCases) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/case.py --- a/Lib/unittest/case.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/case.py Fri Jul 25 11:39:11 2014 -0400 @@ -119,6 +119,9 @@ test_item.__unittest_expecting_failure__ = True return test_item +def testBaseClass(base_class): + base_class.__unittest_base_class__ = True + return base_class class _BaseTestCaseContext: diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/loader.py --- a/Lib/unittest/loader.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/loader.py Fri Jul 25 11:39:11 2014 -0400 @@ -64,6 +64,8 @@ raise TypeError("Test cases should not be derived from " "TestSuite. Maybe you meant to derive from " "TestCase?") + if testCaseClass.__dict__.get('__unittest_base_class__', False): + raise TypeError("Base test class should not be run.") testCaseNames = self.getTestCaseNames(testCaseClass) if not testCaseNames and hasattr(testCaseClass, 'runTest'): testCaseNames = ['runTest'] @@ -75,7 +77,9 @@ tests = [] for name in dir(module): obj = getattr(module, name) - if isinstance(obj, type) and issubclass(obj, case.TestCase): + if isinstance(obj, type) and \ + issubclass(obj, case.TestCase) and \ + (not obj.__dict__.get('__unittest_base_class__', False)): tests.append(self.loadTestsFromTestCase(obj)) load_tests = getattr(module, 'load_tests', None) diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/baseclassdecorator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/unittest/test/baseclassdecorator.py Fri Jul 25 11:39:11 2014 -0400 @@ -0,0 +1,20 @@ +import unittest + +@unittest.testBaseClass +class TestBaseDecoratorBase(unittest.TestCase): + def setUp(self): + self.is_base_class = True + + def test_base_class_should_not_run(self): + """ + This test will fail if run by the base class but will pass + if run by the child class. + """ + self.assertFalse(self.is_base_class) + +class TestBaseDecoratorChild(TestBaseDecoratorBase): + def setUp(self): + self.is_base_class = False + +if __name__ == "__main__": + unittest.main() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_case.py Fri Jul 25 11:39:11 2014 -0400 @@ -14,7 +14,7 @@ import unittest -from unittest.test.support import ( +from .support import ( TestEquality, TestHashing, LoggingResult, LegacyLoggingResult, ResultWithNoStartTestRunStopTestRun ) @@ -1569,6 +1569,17 @@ testcase.run() self.assertEqual(MyException.ninstance, 0) + def test_base_class_should_not_run(self): + # Issue #14534: Add method to mark unittest.TestCases as "do not run" + from unittest.test import baseclassdecorator + + result = unittest.TestResult() + + loader = unittest.TestLoader() + suite = loader.loadTestsFromModule(baseclassdecorator) + + suite.run(result) + self.assertEqual(result.testsRun, 1) if __name__ == "__main__": unittest.main() diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_discovery.py --- a/Lib/unittest/test/test_discovery.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_discovery.py Fri Jul 25 11:39:11 2014 -0400 @@ -6,7 +6,6 @@ from test import support import unittest -import unittest.test class TestableTestProgram(unittest.TestProgram): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_functiontestcase.py --- a/Lib/unittest/test/test_functiontestcase.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_functiontestcase.py Fri Jul 25 11:39:11 2014 -0400 @@ -1,6 +1,6 @@ import unittest -from unittest.test.support import LoggingResult +from .support import LoggingResult class Test_FunctionTestCase(unittest.TestCase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_program.py --- a/Lib/unittest/test/test_program.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_program.py Fri Jul 25 11:39:11 2014 -0400 @@ -4,7 +4,6 @@ import sys from test import support import unittest -import unittest.test class Test_TestProgram(unittest.TestCase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_runner.py --- a/Lib/unittest/test/test_runner.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_runner.py Fri Jul 25 11:39:11 2014 -0400 @@ -7,8 +7,7 @@ import unittest from unittest.case import _Outcome -from unittest.test.support import (LoggingResult, - ResultWithNoStartTestRunStopTestRun) +from .support import LoggingResult, ResultWithNoStartTestRunStopTestRun class TestCleanUp(unittest.TestCase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_skipping.py --- a/Lib/unittest/test/test_skipping.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_skipping.py Fri Jul 25 11:39:11 2014 -0400 @@ -1,6 +1,6 @@ import unittest -from unittest.test.support import LoggingResult +from .support import LoggingResult class Test_TestSkipping(unittest.TestCase): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/unittest/test/test_suite.py --- a/Lib/unittest/test/test_suite.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/unittest/test/test_suite.py Fri Jul 25 11:39:11 2014 -0400 @@ -3,7 +3,7 @@ import gc import sys import weakref -from unittest.test.support import LoggingResult, TestEquality +from .support import LoggingResult, TestEquality ### Support code for Test_TestSuite diff -r 79e469ae13b7 -r 01438f18ee18 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/urllib/parse.py Fri Jul 25 11:39:11 2014 -0400 @@ -641,7 +641,7 @@ def __repr__(self): # Without this, will just display as a defaultdict - return "<%s %r>" % (self.__class__.__name__, dict(self)) + return "" % dict(self) def __missing__(self, b): # Handle a cache miss. Store quoted string in cache and return. diff -r 79e469ae13b7 -r 01438f18ee18 Lib/uuid.py --- a/Lib/uuid.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/uuid.py Fri Jul 25 11:39:11 2014 -0400 @@ -222,7 +222,7 @@ return self.int def __repr__(self): - return '%s(%r)' % (self.__class__.__name__, str(self)) + return 'UUID(%r)' % str(self) def __setattr__(self, name, value): raise TypeError('UUID objects are immutable') diff -r 79e469ae13b7 -r 01438f18ee18 Lib/weakref.py --- a/Lib/weakref.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/weakref.py Fri Jul 25 11:39:11 2014 -0400 @@ -144,7 +144,7 @@ return o is not None def __repr__(self): - return "<%s at %#x>" % (self.__class__.__name__, id(self)) + return "" % id(self) def __setitem__(self, key, value): if self._pending_removals: @@ -348,7 +348,7 @@ return len(self.data) - len(self._pending_removals) def __repr__(self): - return "<%s at %#x>" % (self.__class__.__name__, id(self)) + return "" % id(self) def __setitem__(self, key, value): self.data[ref(key, self._remove)] = value diff -r 79e469ae13b7 -r 01438f18ee18 Lib/wsgiref/headers.py --- a/Lib/wsgiref/headers.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/wsgiref/headers.py Fri Jul 25 11:39:11 2014 -0400 @@ -131,7 +131,7 @@ return self._headers[:] def __repr__(self): - return "%s(%r)" % (self.__class__.__name__, self._headers) + return "Headers(%r)" % self._headers def __str__(self): """str() returns the formatted headers, complete with end line, diff -r 79e469ae13b7 -r 01438f18ee18 Lib/xml/dom/minidom.py --- a/Lib/xml/dom/minidom.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/xml/dom/minidom.py Fri Jul 25 11:39:11 2014 -0400 @@ -648,10 +648,9 @@ def __repr__(self): if self.namespace: - return "<%s %r (from %r)>" % (self.__class__.__name__, self.name, - self.namespace) + return "" % (self.name, self.namespace) else: - return "<%s %r>" % (self.__class__.__name__, self.name) + return "" % self.name def _get_name(self): return self.name diff -r 79e469ae13b7 -r 01438f18ee18 Lib/xml/etree/ElementTree.py --- a/Lib/xml/etree/ElementTree.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/xml/etree/ElementTree.py Fri Jul 25 11:39:11 2014 -0400 @@ -174,7 +174,7 @@ self._children = [] def __repr__(self): - return "<%s %r at %#x>" % (self.__class__.__name__, self.tag, id(self)) + return "" % (repr(self.tag), id(self)) def makeelement(self, tag, attrib): """Create a new element with the same type. @@ -509,7 +509,7 @@ def __str__(self): return self.text def __repr__(self): - return '<%s %r>' % (self.__class__.__name__, self.text) + return '' % (self.text,) def __hash__(self): return hash(self.text) def __le__(self, other): diff -r 79e469ae13b7 -r 01438f18ee18 Lib/xmlrpc/client.py --- a/Lib/xmlrpc/client.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Lib/xmlrpc/client.py Fri Jul 25 11:39:11 2014 -0400 @@ -207,8 +207,8 @@ self.headers = headers def __repr__(self): return ( - "<%s for %s: %s %s>" % - (self.__class__.__name__, self.url, self.errcode, self.errmsg) + "" % + (self.url, self.errcode, self.errmsg) ) ## @@ -236,8 +236,7 @@ self.faultCode = faultCode self.faultString = faultString def __repr__(self): - return "<%s %s: %r>" % (self.__class__.__name__, - self.faultCode, self.faultString) + return "" % (self.faultCode, self.faultString) # -------------------------------------------------------------------- # Special values @@ -355,7 +354,7 @@ return self.value def __repr__(self): - return "<%s %r at %#x>" % (self.__class__.__name__, self.value, id(self)) + return "" % (self.value, id(self)) def decode(self, data): self.value = str(data).strip() @@ -847,7 +846,7 @@ self.__call_list = [] def __repr__(self): - return "<%s at %#x>" % (self.__class__.__name__, id(self)) + return "" % id(self) __str__ = __repr__ @@ -1427,8 +1426,8 @@ def __repr__(self): return ( - "<%s for %s%s>" % - (self.__class__.__name__, self.__host, self.__handler) + "" % + (self.__host, self.__handler) ) __str__ = __repr__ diff -r 79e469ae13b7 -r 01438f18ee18 Misc/ACKS --- a/Misc/ACKS Fri Aug 08 17:24:06 2014 +0300 +++ b/Misc/ACKS Fri Jul 25 11:39:11 2014 -0400 @@ -35,7 +35,6 @@ Kevin Altis Skyler Leigh Amador Joe Amenta -Rose Ames A. Amoroso Mark Anacker Shashwat Anand @@ -99,7 +98,6 @@ Samuel L. Bayer Donald Beaudry David Beazley -Ingolf Becker Neal Becker Robin Becker Torsten Becker @@ -413,7 +411,6 @@ Dan Finnie Nils Fischbeck Frederik Fix -Tom Flanagan Matt Fleming Hernán Martínez Foffani Artem Fokin @@ -553,7 +550,6 @@ Magnus L. Hetland Raymond Hettinger Kevan Heydon -Wouter van Heyst Kelsey Hightower Jason Hildebrand Richie Hindle @@ -1459,7 +1455,6 @@ Carol Willing Steven Willis Frank Willison -David Wilson Geoff Wilson Greg V. Wilson J Derek Wilson @@ -1484,7 +1479,6 @@ Darren Worrall Thomas Wouters Daniel Wozniak -Wei Wu Heiko Wundram Doug Wyatt Robert Xiao diff -r 79e469ae13b7 -r 01438f18ee18 Misc/NEWS --- a/Misc/NEWS Fri Aug 08 17:24:06 2014 +0300 +++ b/Misc/NEWS Fri Jul 25 11:39:11 2014 -0400 @@ -10,18 +10,6 @@ Core and Builtins ----------------- -- Issue #22116: C functions and methods (of the 'builtin_function_or_method' - type) can now be weakref'ed. Patch by Wei Wu. - -- Issue #22077: Improve index error messages for bytearrays, bytes, lists, - and tuples by adding 'or slices'. Added ', not 1) { PyErr_Format(PyExc_TypeError, - "\"%s\" must be a 1-character string", + "\"%s\" must be an 1-character string", name); return -1; } @@ -301,6 +304,7 @@ static struct PyMemberDef Dialect_memberlist[] = { { "skipinitialspace", T_INT, D_OFF(skipinitialspace), READONLY }, + { "skipinitialwhitespace", T_INT, D_OFF(skipinitialwhitespace), READONLY }, { "doublequote", T_INT, D_OFF(doublequote), READONLY }, { "strict", T_INT, D_OFF(strict), READONLY }, { NULL } @@ -331,6 +335,7 @@ "quotechar", "quoting", "skipinitialspace", + "skipinitialwhitespace", "strict", NULL }; @@ -348,10 +353,11 @@ PyObject *quotechar = NULL; PyObject *quoting = NULL; PyObject *skipinitialspace = NULL; + PyObject *skipinitialwhitespace = NULL; PyObject *strict = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|OOOOOOOOO", dialect_kws, + "|OOOOOOOOOO", dialect_kws, &dialect, &delimiter, &doublequote, @@ -360,6 +366,7 @@ "echar, "ing, &skipinitialspace, + &skipinitialwhitespace, &strict)) return NULL; @@ -380,6 +387,7 @@ quotechar == 0 && quoting == 0 && skipinitialspace == 0 && + skipinitialwhitespace == 0 && strict == 0) return dialect; } @@ -398,6 +406,7 @@ Py_XINCREF(quotechar); Py_XINCREF(quoting); Py_XINCREF(skipinitialspace); + Py_XINCREF(skipinitialwhitespace); Py_XINCREF(strict); if (dialect != NULL) { #define DIALECT_GETATTR(v, n) \ @@ -410,6 +419,7 @@ DIALECT_GETATTR(quotechar, "quotechar"); DIALECT_GETATTR(quoting, "quoting"); DIALECT_GETATTR(skipinitialspace, "skipinitialspace"); + DIALECT_GETATTR(skipinitialwhitespace, "skipinitialwhitespace"); DIALECT_GETATTR(strict, "strict"); PyErr_Clear(); } @@ -425,6 +435,7 @@ DIASET(_set_char, "quotechar", &self->quotechar, quotechar, '"'); DIASET(_set_int, "quoting", &self->quoting, quoting, QUOTE_MINIMAL); DIASET(_set_bool, "skipinitialspace", &self->skipinitialspace, skipinitialspace, 0); + DIASET(_set_bool, "skipinitialwhitespace", &self->skipinitialwhitespace, skipinitialwhitespace, 0); DIASET(_set_bool, "strict", &self->strict, strict, 0); /* validate options */ @@ -432,7 +443,7 @@ goto err; if (self->delimiter == 0) { PyErr_SetString(PyExc_TypeError, - "\"delimiter\" must be a 1-character string"); + "\"delimiter\" must be an 1-character string"); goto err; } if (quotechar == Py_None && quoting == NULL) @@ -459,6 +470,7 @@ Py_XDECREF(quotechar); Py_XDECREF(quoting); Py_XDECREF(skipinitialspace); + Py_XDECREF(skipinitialwhitespace); Py_XDECREF(strict); return ret; } @@ -638,6 +650,9 @@ else if (c == ' ' && dialect->skipinitialspace) /* ignore space at start of field */ ; + else if (CSV_IS_WHITESPACE(c) && dialect->skipinitialwhitespace) + /* ignore all whitespace characters at start of field */ + ; else if (c == dialect->delimiter) { /* save empty field */ if (parse_save_field(self) < 0) @@ -1518,6 +1533,7 @@ " escapechar = None\n" " doublequote = True\n" " skipinitialspace = False\n" +" skipinitialwhitespace = False\n" " lineterminator = '\\r\\n'\n" " quoting = QUOTE_MINIMAL\n" "\n" @@ -1527,9 +1543,13 @@ " quoting character. It defaults to '\"'.\n" " * delimiter - specifies a one-character string to use as the \n" " field separator. It defaults to ','.\n" -" * skipinitialspace - specifies how to interpret whitespace which\n" -" immediately follows a delimiter. It defaults to False, which\n" -" means that whitespace immediately following a delimiter is part\n" +" * skipinitialspace - specifies how to interpret spaces which\n" +" immediately follow a delimiter. It defaults to False, which\n" +" means that spaces (and only spaces) immediately following a delimiter are part\n" +" of the following field.\n" +" * skipinitialwhitespace - specifies how to interpret whitespace characters which\n" +" immediately follow a delimiter. It defaults to False, which\n" +" means that whitespace characters immediately following a delimiter are part\n" " of the following field.\n" " * lineterminator - specifies the character sequence which should \n" " terminate rows.\n" diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_datetimemodule.c --- a/Modules/_datetimemodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_datetimemodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -897,11 +897,11 @@ } } else { + Py_DECREF(offset); PyErr_Format(PyExc_TypeError, "tzinfo.%s() must return None or " "timedelta, not '%.200s'", name, Py_TYPE(offset)->tp_name); - Py_DECREF(offset); return NULL; } @@ -2153,7 +2153,7 @@ * is odd. Note that x is odd when it's last bit is 1. The * code below uses bitwise and operation to check the last * bit. */ - temp = PyNumber_And(x, one); /* temp <- x & 1 */ + temp = PyNumber_And(x, one); /* temp <- x & 1 */ if (temp == NULL) { Py_DECREF(x); goto Done; @@ -3224,10 +3224,10 @@ if (op != Py_EQ && op != Py_NE) Py_RETURN_NOTIMPLEMENTED; if (Py_TYPE(other) != &PyDateTime_TimeZoneType) { - if (op == Py_EQ) - Py_RETURN_FALSE; - else - Py_RETURN_TRUE; + if (op == Py_EQ) + Py_RETURN_FALSE; + else + Py_RETURN_TRUE; } return delta_richcompare(self->offset, other->offset, op); } @@ -4778,7 +4778,7 @@ static char *keywords[] = {"tz", NULL}; if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:astimezone", keywords, - &tzinfo)) + &tzinfo)) return NULL; if (check_tzinfo_subclass(tzinfo) == -1) diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_io/bytesio.c --- a/Modules/_io/bytesio.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_io/bytesio.c Fri Jul 25 11:39:11 2014 -0400 @@ -11,10 +11,6 @@ PyObject *dict; PyObject *weakreflist; Py_ssize_t exports; - /** If `initvalue' != NULL, `buf' is a read-only pointer into the PyBytes - * referenced by `initvalue'. It must be copied prior to mutation, and - * released during finalization */ - PyObject *initvalue; } bytesio; typedef struct { @@ -23,11 +19,11 @@ } bytesiobuf; -#define CHECK_CLOSED(self, ret) \ +#define CHECK_CLOSED(self) \ if ((self)->buf == NULL) { \ PyErr_SetString(PyExc_ValueError, \ "I/O operation on closed file."); \ - return ret; \ + return NULL; \ } #define CHECK_EXPORTS(self) \ @@ -37,45 +33,6 @@ return NULL; \ } -/* Ensure we have a buffer suitable for writing, in the case that an initvalue - * object was provided, and we're currently borrowing its buffer. `size' - * indicates the new buffer size allocated as part of unsharing, to avoid a - * redundant reallocation caused by any subsequent mutation. `truncate' - * indicates whether truncation should occur if `size` < self->string_size. - * - * Do nothing if the buffer wasn't shared. Returns 0 on success, or sets an - * exception and returns -1 on failure. Existing state is preserved on failure. - */ -static int -unshare(bytesio *self, size_t preferred_size, int truncate) -{ - if (self->initvalue) { - Py_ssize_t copy_size; - char *new_buf; - - if((! truncate) && preferred_size < self->string_size) { - preferred_size = self->string_size; - } - - new_buf = (char *)PyMem_Malloc(preferred_size); - if (new_buf == NULL) { - PyErr_NoMemory(); - return -1; - } - - copy_size = self->string_size; - if (copy_size > preferred_size) { - copy_size = preferred_size; - } - - memcpy(new_buf, self->buf, copy_size); - Py_CLEAR(self->initvalue); - self->buf = new_buf; - self->buf_size = preferred_size; - self->string_size = (Py_ssize_t) copy_size; - } - return 0; -} /* Internal routine to get a line from the buffer of a BytesIO object. Returns the length between the current position to the @@ -168,18 +125,11 @@ static Py_ssize_t write_bytes(bytesio *self, const char *bytes, Py_ssize_t len) { - size_t desired; - assert(self->buf != NULL); assert(self->pos >= 0); assert(len >= 0); - desired = (size_t)self->pos + len; - if (unshare(self, desired, 0) < 0) { - return -1; - } - - if (desired > self->buf_size) { + if ((size_t)self->pos + len > self->buf_size) { if (resize_buffer(self, (size_t)self->pos + len) < 0) return -1; } @@ -210,74 +160,6 @@ return len; } -/* Release or free any existing buffer, and place the BytesIO in the closed - * state. */ -static void -reset(bytesio *self) -{ - if (self->initvalue) { - Py_CLEAR(self->initvalue); - } else if (self->buf) { - PyMem_Free(self->buf); - } - self->buf = NULL; - self->string_size = 0; - self->pos = 0; -} - -/* Reinitialize with a new heap-allocated buffer of size `size`. Returns 0 on - * success, or sets an exception and returns -1 on failure. Existing state is - * preserved on failure. */ -static int -reinit_private(bytesio *self, Py_ssize_t size) -{ - char *tmp = (char *)PyMem_Malloc(size); - if (tmp == NULL) { - PyErr_NoMemory(); - return -1; - } - reset(self); - self->buf = tmp; - self->buf_size = size; - return 0; -} - -/* Internal version of BytesIO.__init__; resets the object to its initial - * (closed) state before repopulating it, optionally by sharing a PyBytes - * buffer provided by `initvalue'. Returns 0 on success, or sets an exception - * and returns -1 on failure. */ -static int -reinit(bytesio *self, PyObject *initvalue) -{ - CHECK_CLOSED(self, -1); - - if (initvalue == NULL || initvalue == Py_None) { - if (reinit_private(self, 0) < 0) { - return -1; - } - } else if (PyBytes_CheckExact(initvalue)) { - reset(self); - Py_INCREF(initvalue); - self->initvalue = initvalue; - self->buf = PyBytes_AS_STRING(initvalue); - self->buf_size = PyBytes_GET_SIZE(initvalue); - self->string_size = PyBytes_GET_SIZE(initvalue); - } else { - Py_buffer buf; - if (PyObject_GetBuffer(initvalue, &buf, PyBUF_CONTIG_RO) < 0) { - return -1; - } - if (reinit_private(self, buf.len) < 0) { - PyBuffer_Release(&buf); - return -1; - } - memcpy(self->buf, buf.buf, buf.len); - self->string_size = buf.len; - PyBuffer_Release(&buf); - } - return 0; -} - static PyObject * bytesio_get_closed(bytesio *self) { @@ -302,7 +184,7 @@ static PyObject * return_not_closed(bytesio *self) { - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); Py_RETURN_TRUE; } @@ -312,7 +194,7 @@ static PyObject * bytesio_flush(bytesio *self) { - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); Py_RETURN_NONE; } @@ -328,7 +210,7 @@ bytesiobuf *buf; PyObject *view; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); buf = (bytesiobuf *) type->tp_alloc(type, 0); if (buf == NULL) @@ -348,7 +230,7 @@ static PyObject * bytesio_getvalue(bytesio *self) { - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); return PyBytes_FromStringAndSize(self->buf, self->string_size); } @@ -361,7 +243,7 @@ static PyObject * bytesio_isatty(bytesio *self) { - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); Py_RETURN_FALSE; } @@ -371,7 +253,7 @@ static PyObject * bytesio_tell(bytesio *self) { - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); return PyLong_FromSsize_t(self->pos); } @@ -388,7 +270,7 @@ char *output; PyObject *arg = Py_None; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); if (!PyArg_ParseTuple(args, "|O:read", &arg)) return NULL; @@ -457,7 +339,7 @@ char *output; PyObject *arg = Py_None; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); if (!PyArg_ParseTuple(args, "|O:readline", &arg)) return NULL; @@ -503,7 +385,7 @@ char *output; PyObject *arg = Py_None; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); if (!PyArg_ParseTuple(args, "|O:readlines", &arg)) return NULL; @@ -560,7 +442,7 @@ void *raw_buffer; Py_ssize_t len, n; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); if (PyObject_AsWriteBuffer(buffer, &raw_buffer, &len) == -1) return NULL; @@ -593,7 +475,7 @@ Py_ssize_t size; PyObject *arg = Py_None; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); CHECK_EXPORTS(self); if (!PyArg_ParseTuple(args, "|O:truncate", &arg)) @@ -620,10 +502,6 @@ return NULL; } - if (unshare(self, size, 1) < 0) { - return NULL; - } - if (size < self->string_size) { self->string_size = size; if (resize_buffer(self, size) < 0) @@ -639,7 +517,7 @@ char *next; Py_ssize_t n; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); n = get_line(self, &next); @@ -664,7 +542,7 @@ Py_ssize_t pos; int mode = 0; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); if (!PyArg_ParseTuple(args, "n|i:seek", &pos, &mode)) return NULL; @@ -719,7 +597,7 @@ Py_buffer buf; PyObject *result = NULL; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); CHECK_EXPORTS(self); if (PyObject_GetBuffer(obj, &buf, PyBUF_CONTIG_RO) < 0) @@ -747,7 +625,7 @@ PyObject *it, *item; PyObject *ret; - CHECK_CLOSED(self, NULL); + CHECK_CLOSED(self); it = PyObject_GetIter(v); if (it == NULL) @@ -777,7 +655,10 @@ static PyObject * bytesio_close(bytesio *self) { - reset(self); + if (self->buf != NULL) { + PyMem_Free(self->buf); + self->buf = NULL; + } Py_RETURN_NONE; } @@ -825,11 +706,11 @@ static PyObject * bytesio_setstate(bytesio *self, PyObject *state) { + PyObject *result; PyObject *position_obj; PyObject *dict; Py_ssize_t pos; - CHECK_EXPORTS(self); assert(state != NULL); /* We allow the state tuple to be longer than 3, because we may need @@ -841,13 +722,18 @@ Py_TYPE(self)->tp_name, Py_TYPE(state)->tp_name); return NULL; } + CHECK_EXPORTS(self); + /* Reset the object to its default state. This is only needed to handle + the case of repeated calls to __setstate__. */ + self->string_size = 0; + self->pos = 0; - /* Reset the object to its default state and set the value of the internal - * buffer. If state[0] does not support the buffer protocol, reinit() will - * raise the appropriate TypeError. */ - if (reinit(self, PyTuple_GET_ITEM(state, 0)) < 0) { + /* Set the value of the internal buffer. If state[0] does not support the + buffer protocol, bytesio_write will raise the appropriate TypeError. */ + result = bytesio_write(self, PyTuple_GET_ITEM(state, 0)); + if (result == NULL) return NULL; - } + Py_DECREF(result); /* Set carefully the position value. Alternatively, we could use the seek method instead of modifying self->pos directly to better protect the @@ -902,9 +788,10 @@ "deallocated BytesIO object has exported buffers"); PyErr_Print(); } - - reset(self); - + if (self->buf != NULL) { + PyMem_Free(self->buf); + self->buf = NULL; + } Py_CLEAR(self->dict); if (self->weakreflist != NULL) PyObject_ClearWeakRefs((PyObject *) self); @@ -943,7 +830,20 @@ &initvalue)) return -1; - return reinit(self, initvalue); + /* In case, __init__ is called multiple times. */ + self->string_size = 0; + self->pos = 0; + + if (initvalue && initvalue != Py_None) { + PyObject *res; + res = bytesio_write(self, initvalue); + if (res == NULL) + return -1; + Py_DECREF(res); + self->pos = 0; + } + + return 0; } static PyObject * diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_multiprocessing/multiprocessing.c --- a/Modules/_multiprocessing/multiprocessing.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_multiprocessing/multiprocessing.c Fri Jul 25 11:39:11 2014 -0400 @@ -128,9 +128,7 @@ {"recv", multiprocessing_recv, METH_VARARGS, ""}, {"send", multiprocessing_send, METH_VARARGS, ""}, #endif -#ifndef POSIX_SEMAPHORES_NOT_ENABLED {"sem_unlink", _PyMp_sem_unlink, METH_VARARGS, ""}, -#endif {NULL} }; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_sqlite/row.c --- a/Modules/_sqlite/row.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_sqlite/row.c Fri Jul 25 11:39:11 2014 -0400 @@ -32,41 +32,35 @@ Py_TYPE(self)->tp_free((PyObject*)self); } -static PyObject * -pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +int pysqlite_row_init(pysqlite_Row* self, PyObject* args, PyObject* kwargs) { - pysqlite_Row *self; PyObject* data; pysqlite_Cursor* cursor; - assert(type != NULL && type->tp_alloc != NULL); + self->data = 0; + self->description = 0; - if (!_PyArg_NoKeywords("Row()", kwargs)) - return NULL; - if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) - return NULL; + if (!PyArg_ParseTuple(args, "OO", &cursor, &data)) { + return -1; + } if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pysqlite_CursorType)) { PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument"); - return NULL; + return -1; } if (!PyTuple_Check(data)) { PyErr_SetString(PyExc_TypeError, "tuple required for second argument"); - return NULL; + return -1; } - self = (pysqlite_Row *) type->tp_alloc(type, 0); - if (self == NULL) - return NULL; - Py_INCREF(data); self->data = data; Py_INCREF(cursor->description); self->description = cursor->description; - return (PyObject *) self; + return 0; } PyObject* pysqlite_row_item(pysqlite_Row* self, Py_ssize_t idx) @@ -266,7 +260,7 @@ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ + (initproc)pysqlite_row_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ 0 /* tp_free */ @@ -274,7 +268,7 @@ extern int pysqlite_row_setup_types(void) { - pysqlite_RowType.tp_new = pysqlite_row_new; + pysqlite_RowType.tp_new = PyType_GenericNew; pysqlite_RowType.tp_as_mapping = &pysqlite_row_as_mapping; pysqlite_RowType.tp_as_sequence = &pysqlite_row_as_sequence; return PyType_Ready(&pysqlite_RowType); diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_testcapimodule.c --- a/Modules/_testcapimodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_testcapimodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -2653,21 +2653,6 @@ return obj; } -static PyMethodDef ml; - -static PyObject * -create_cfunction(PyObject *self, PyObject *args) -{ - return PyCFunction_NewEx(&ml, self, NULL); -} - -static PyMethodDef ml = { - "create_cfunction", - create_cfunction, - METH_NOARGS, - NULL -}; - static PyObject * _test_incref(PyObject *ob) { @@ -3201,7 +3186,6 @@ {"pytime_object_to_timeval", test_pytime_object_to_timeval, METH_VARARGS}, {"pytime_object_to_timespec", test_pytime_object_to_timespec, METH_VARARGS}, {"with_tp_del", with_tp_del, METH_VARARGS}, - {"create_cfunction", create_cfunction, METH_NOARGS}, {"test_pymem_alloc0", (PyCFunction)test_pymem_alloc0, METH_NOARGS}, {"test_pymem_setrawallocators", diff -r 79e469ae13b7 -r 01438f18ee18 Modules/_tkinter.c --- a/Modules/_tkinter.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/_tkinter.c Fri Jul 25 11:39:11 2014 -0400 @@ -9,8 +9,8 @@ /* TCL/TK VERSION INFO: - Only Tcl/Tk 8.4 and later are supported. Older versions are not - supported. Use Python 3.4 or older if you cannot upgrade your + Only Tcl/Tk 8.3.1 and later are supported. Older versions are not + supported. Use Python 2.6 or older if you cannot upgrade your Tcl/Tk libraries. */ @@ -36,6 +36,13 @@ #define CHECK_SIZE(size, elemsize) \ ((size_t)(size) <= Py_MAX((size_t)INT_MAX, UINT_MAX / (size_t)(elemsize))) +/* Starting with Tcl 8.4, many APIs offer const-correctness. Unfortunately, + making _tkinter correct for this API means to break earlier + versions. USE_COMPAT_CONST allows to make _tkinter work with both 8.4 and + earlier versions. Once Tcl releases before 8.4 don't need to be supported + anymore, this should go. */ +#define USE_COMPAT_CONST + /* If Tcl is compiled for threads, we must also define TCL_THREAD. We define it always; if Tcl is not threaded, the thread functions in Tcl are empty. */ @@ -51,8 +58,15 @@ #include "tkinter.h" -#if TK_VERSION_HEX < 0x08040002 -#error "Tk older than 8.4 not supported" +/* For Tcl 8.2 and 8.3, CONST* is not defined (except on Cygwin). */ +#ifndef CONST84_RETURN +#define CONST84_RETURN +#undef CONST +#define CONST +#endif + +#if TK_VERSION_HEX < 0x08030102 +#error "Tk older than 8.3.1 not supported" #endif #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) @@ -228,13 +242,13 @@ int dispatching; /* We cannot include tclInt.h, as this is internal. So we cache interesting types here. */ - const Tcl_ObjType *BooleanType; - const Tcl_ObjType *ByteArrayType; - const Tcl_ObjType *DoubleType; - const Tcl_ObjType *IntType; - const Tcl_ObjType *ListType; - const Tcl_ObjType *ProcBodyType; - const Tcl_ObjType *StringType; + Tcl_ObjType *BooleanType; + Tcl_ObjType *ByteArrayType; + Tcl_ObjType *DoubleType; + Tcl_ObjType *IntType; + Tcl_ObjType *ListType; + Tcl_ObjType *ProcBodyType; + Tcl_ObjType *StringType; } TkappObject; #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) @@ -362,10 +376,10 @@ static PyObject * -Split(const char *list) +Split(char *list) { int argc; - const char **argv; + char **argv; PyObject *v; if (list == NULL) { @@ -467,7 +481,7 @@ } else if (PyUnicode_Check(arg)) { int argc; - const char **argv; + char **argv; char *list = PyUnicode_AsUTF8(arg); if (list == NULL || @@ -482,7 +496,7 @@ } else if (PyBytes_Check(arg)) { int argc; - const char **argv; + char **argv; char *list = PyBytes_AsString(arg); if (Tcl_SplitList((Tcl_Interp *)NULL, list, &argc, &argv) != TCL_OK) { @@ -549,9 +563,8 @@ static void DisableEventHook(void); /* Forward */ static TkappObject * -Tkapp_New(const char *screenName, const char *className, - int interactive, int wantobjects, int wantTk, int sync, - const char *use) +Tkapp_New(char *screenName, char *className, + int interactive, int wantobjects, int wantTk, int sync, char *use) { TkappObject *v; char *argv0; @@ -888,8 +901,8 @@ int overflow; if (PyBytes_Check(value)) - return Tcl_NewByteArrayObj((unsigned char *)PyBytes_AS_STRING(value), - PyBytes_GET_SIZE(value)); + return Tcl_NewStringObj(PyBytes_AS_STRING(value), + PyBytes_GET_SIZE(value)); else if (PyBool_Check(value)) return Tcl_NewBooleanObj(PyObject_IsTrue(value)); else if (PyLong_CheckExact(value) && @@ -1844,7 +1857,7 @@ { char *list; int argc; - const char **argv; + char **argv; PyObject *arg, *v; int i; @@ -1971,7 +1984,7 @@ * function or method. */ static int -PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]) +PythonCmd(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) { PythonCmd_ClientData *data = (PythonCmd_ClientData *)clientData; PyObject *func, *arg, *res; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/clinic/binascii.c.h --- a/Modules/clinic/binascii.c.h Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/clinic/binascii.c.h Fri Jul 25 11:39:11 2014 -0400 @@ -320,7 +320,7 @@ &data, &crc)) goto exit; _return_value = binascii_crc32_impl(module, &data, crc); - if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) + if ((_return_value == -1) && PyErr_Occurred()) goto exit; return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); @@ -475,4 +475,4 @@ return return_value; } -/*[clinic end generated code: output=53cd6b379c745220 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=68e2bcc6956b6213 input=a9049054013a1b77]*/ diff -r 79e469ae13b7 -r 01438f18ee18 Modules/getpath.c --- a/Modules/getpath.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/getpath.c Fri Jul 25 11:39:11 2014 -0400 @@ -336,7 +336,7 @@ joinpath(prefix, L"Modules/Setup"); if (isfile(prefix)) { /* Check VPATH to see if argv0_path is in the build directory. */ - vpath = Py_DecodeLocale(VPATH, NULL); + vpath = _Py_char2wchar(VPATH, NULL); if (vpath != NULL) { wcsncpy(prefix, argv0_path, MAXPATHLEN); prefix[MAXPATHLEN] = L'\0'; @@ -491,10 +491,10 @@ wchar_t *_pythonpath, *_prefix, *_exec_prefix; wchar_t *lib_python; - _pythonpath = Py_DecodeLocale(PYTHONPATH, NULL); - _prefix = Py_DecodeLocale(PREFIX, NULL); - _exec_prefix = Py_DecodeLocale(EXEC_PREFIX, NULL); - lib_python = Py_DecodeLocale("lib/python" VERSION, NULL); + _pythonpath = _Py_char2wchar(PYTHONPATH, NULL); + _prefix = _Py_char2wchar(PREFIX, NULL); + _exec_prefix = _Py_char2wchar(EXEC_PREFIX, NULL); + lib_python = _Py_char2wchar("lib/python" VERSION, NULL); if (!_pythonpath || !_prefix || !_exec_prefix || !lib_python) { Py_FatalError( @@ -503,7 +503,7 @@ } if (_path) { - path_buffer = Py_DecodeLocale(_path, NULL); + path_buffer = _Py_char2wchar(_path, NULL); path = path_buffer; } @@ -584,7 +584,7 @@ ** be running the interpreter in the build directory, so we use the ** build-directory-specific logic to find Lib and such. */ - wchar_t* wbuf = Py_DecodeLocale(modPath, NULL); + wchar_t* wbuf = _Py_char2wchar(modPath, NULL); if (wbuf == NULL) { Py_FatalError("Cannot decode framework location"); } @@ -709,7 +709,7 @@ if (_rtpypath && _rtpypath[0] != '\0') { size_t rtpypath_len; - rtpypath = Py_DecodeLocale(_rtpypath, &rtpypath_len); + rtpypath = _Py_char2wchar(_rtpypath, &rtpypath_len); if (rtpypath != NULL) bufsz += rtpypath_len + 1; } diff -r 79e469ae13b7 -r 01438f18ee18 Modules/main.c --- a/Modules/main.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/main.c Fri Jul 25 11:39:11 2014 -0400 @@ -647,7 +647,7 @@ /* Used by Mac/Tools/pythonw.c to forward * the argv0 of the stub executable */ - wchar_t* wbuf = Py_DecodeLocale(pyvenv_launcher, NULL); + wchar_t* wbuf = _Py_char2wchar(pyvenv_launcher, NULL); if (wbuf == NULL) { Py_FatalError("Cannot decode __PYVENV_LAUNCHER__"); @@ -730,7 +730,7 @@ char *cfilename_buffer; const char *cfilename; int err = errno; - cfilename_buffer = Py_EncodeLocale(filename, NULL); + cfilename_buffer = _Py_wchar2char(filename, NULL); if (cfilename_buffer != NULL) cfilename = cfilename_buffer; else diff -r 79e469ae13b7 -r 01438f18ee18 Modules/md5module.c --- a/Modules/md5module.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/md5module.c Fri Jul 25 11:39:11 2014 -0400 @@ -19,11 +19,6 @@ #include "Python.h" #include "hashlib.h" -/*[clinic input] -module _md5 -class MD5Type "MD5object *" "&PyType_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6e5261719957a912]*/ /* Some useful types */ @@ -337,33 +332,10 @@ /* External methods for a hash object */ -/*[clinic input] -MD5Type.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -PyDoc_STRVAR(MD5Type_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define MD5TYPE_COPY_METHODDEF \ - {"copy", (PyCFunction)MD5Type_copy, METH_NOARGS, MD5Type_copy__doc__}, +PyDoc_STRVAR(MD5_copy__doc__, "Return a copy of the hash object."); static PyObject * -MD5Type_copy_impl(MD5object *self); - -static PyObject * -MD5Type_copy(MD5object *self, PyObject *Py_UNUSED(ignored)) -{ - return MD5Type_copy_impl(self); -} - -static PyObject * -MD5Type_copy_impl(MD5object *self) -/*[clinic end generated code: output=3b3a88920b3dc7f4 input=2c09e6d2493f3079]*/ +MD5_copy(MD5object *self, PyObject *unused) { MD5object *newobj; @@ -379,33 +351,11 @@ return (PyObject *)newobj; } -/*[clinic input] -MD5Type.digest - -Return the digest value as a string of binary data. -[clinic start generated code]*/ - -PyDoc_STRVAR(MD5Type_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(MD5_digest__doc__, "Return the digest value as a string of binary data."); -#define MD5TYPE_DIGEST_METHODDEF \ - {"digest", (PyCFunction)MD5Type_digest, METH_NOARGS, MD5Type_digest__doc__}, - static PyObject * -MD5Type_digest_impl(MD5object *self); - -static PyObject * -MD5Type_digest(MD5object *self, PyObject *Py_UNUSED(ignored)) -{ - return MD5Type_digest_impl(self); -} - -static PyObject * -MD5Type_digest_impl(MD5object *self) -/*[clinic end generated code: output=7a796b28fa89485f input=7b96e65389412a34]*/ +MD5_digest(MD5object *self, PyObject *unused) { unsigned char digest[MD5_DIGESTSIZE]; struct md5_state temp; @@ -415,33 +365,11 @@ return PyBytes_FromStringAndSize((const char *)digest, MD5_DIGESTSIZE); } -/*[clinic input] -MD5Type.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -PyDoc_STRVAR(MD5Type_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(MD5_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); -#define MD5TYPE_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)MD5Type_hexdigest, METH_NOARGS, MD5Type_hexdigest__doc__}, - static PyObject * -MD5Type_hexdigest_impl(MD5object *self); - -static PyObject * -MD5Type_hexdigest(MD5object *self, PyObject *Py_UNUSED(ignored)) -{ - return MD5Type_hexdigest_impl(self); -} - -static PyObject * -MD5Type_hexdigest_impl(MD5object *self) -/*[clinic end generated code: output=daa73609f94f92e1 input=b60b19de644798dd]*/ +MD5_hexdigest(MD5object *self, PyObject *unused) { unsigned char digest[MD5_DIGESTSIZE]; struct md5_state temp; @@ -473,30 +401,18 @@ return retval; } -/*[clinic input] -MD5Type.update - - obj: object - / - -Update this hash object's state with the provided string. -[clinic start generated code]*/ - -PyDoc_STRVAR(MD5Type_update__doc__, -"update($self, obj, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided string."); - -#define MD5TYPE_UPDATE_METHODDEF \ - {"update", (PyCFunction)MD5Type_update, METH_O, MD5Type_update__doc__}, +PyDoc_STRVAR(MD5_update__doc__, +"Update this hash object's state with the provided string."); static PyObject * -MD5Type_update(MD5object *self, PyObject *obj) -/*[clinic end generated code: output=9d09b6c6cdc6cac3 input=6e1efcd9ecf17032]*/ +MD5_update(MD5object *self, PyObject *args) { + PyObject *obj; Py_buffer buf; + if (!PyArg_ParseTuple(args, "O:update", &obj)) + return NULL; + GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); md5_process(&self->hash_state, buf.buf, buf.len); @@ -507,10 +423,10 @@ } static PyMethodDef MD5_methods[] = { - MD5TYPE_COPY_METHODDEF - MD5TYPE_DIGEST_METHODDEF - MD5TYPE_HEXDIGEST_METHODDEF - MD5TYPE_UPDATE_METHODDEF + {"copy", (PyCFunction)MD5_copy, METH_NOARGS, MD5_copy__doc__}, + {"digest", (PyCFunction)MD5_digest, METH_NOARGS, MD5_digest__doc__}, + {"hexdigest", (PyCFunction)MD5_hexdigest, METH_NOARGS, MD5_hexdigest__doc__}, + {"update", (PyCFunction)MD5_update, METH_VARARGS, MD5_update__doc__}, {NULL, NULL} /* sentinel */ }; @@ -586,55 +502,27 @@ /* The single module-level function: new() */ -/*[clinic input] -_md5.md5 - - string: object(c_default="NULL") = b'' - -Return a new MD5 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_md5_md5__doc__, -"md5($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(MD5_new__doc__, "Return a new MD5 hash object; optionally initialized with a string."); -#define _MD5_MD5_METHODDEF \ - {"md5", (PyCFunction)_md5_md5, METH_VARARGS|METH_KEYWORDS, _md5_md5__doc__}, - static PyObject * -_md5_md5_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_md5_md5(PyModuleDef *module, PyObject *args, PyObject *kwargs) +MD5_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:md5", _keywords, - &string)) - goto exit; - return_value = _md5_md5_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_md5_md5_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=1039e912d919880e input=d12ef8f72d684f7b]*/ -{ + static char *kwlist[] = {"string", NULL}; MD5object *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newMD5object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -643,11 +531,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { md5_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -659,7 +547,7 @@ /* List of functions exported by this module */ static struct PyMethodDef MD5_functions[] = { - _MD5_MD5_METHODDEF + {"md5", (PyCFunction)MD5_new, METH_VARARGS|METH_KEYWORDS, MD5_new__doc__}, {NULL, NULL} /* Sentinel */ }; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/posixmodule.c --- a/Modules/posixmodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/posixmodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -184,10 +184,9 @@ /*[clinic input] -# one of the few times we lie about this name! module os [clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=94a0f0f978acae17]*/ +/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8cff096d1133288f]*/ #ifndef _MSC_VER @@ -684,6 +683,7 @@ } + /* * A PyArg_ParseTuple "converter" function * that handles filesystem paths in the manner @@ -779,8 +779,8 @@ PyObject *cleanup; } path_t; -#define PATH_T_INITIALIZE(function_name, argument_name, nullable, allow_fd) \ - {function_name, argument_name, nullable, allow_fd, NULL, NULL, -1, 0, NULL, NULL} +#define PATH_T_INITIALIZE(function_name, nullable, allow_fd) \ + {function_name, NULL, nullable, allow_fd, NULL, NULL, 0, 0, NULL, NULL} static void path_cleanup(path_t *path) { @@ -1004,35 +1004,21 @@ return 0; } -#ifdef MS_WINDOWS - typedef PY_LONG_LONG Py_off_t; -#else - typedef off_t Py_off_t; -#endif - +/* A helper used by a number of POSIX-only functions */ +#ifndef MS_WINDOWS static int -Py_off_t_converter(PyObject *arg, void *addr) -{ -#ifdef HAVE_LARGEFILE_SUPPORT - *((Py_off_t *)addr) = PyLong_AsLongLong(arg); -#else - *((Py_off_t *)addr) = PyLong_AsLong(arg); +_parse_off_t(PyObject* arg, void* addr) +{ +#if !defined(HAVE_LARGEFILE_SUPPORT) + *((off_t*)addr) = PyLong_AsLong(arg); +#else + *((off_t*)addr) = PyLong_AsLongLong(arg); #endif if (PyErr_Occurred()) return 0; return 1; } - -static PyObject * -PyLong_FromPy_off_t(Py_off_t offset) -{ -#ifdef HAVE_LARGEFILE_SUPPORT - return PyLong_FromLongLong(offset); -#else - return PyLong_FromLong(offset); -#endif -} - +#endif #if defined _MSC_VER && _MSC_VER >= 1400 /* Microsoft CRT in VS2005 and higher will verify that a filehandle is @@ -1312,26 +1298,16 @@ /* POSIX generic methods */ -static int -fildes_converter(PyObject *o, void *p) +static PyObject * +posix_fildes(PyObject *fdobj, int (*func)(int)) { int fd; - int *pointer = (int *)p; - fd = PyObject_AsFileDescriptor(o); + int res; + fd = PyObject_AsFileDescriptor(fdobj); if (fd < 0) - return 0; - if (!_PyVerify_fd(fd)) { - posix_error(); - return 0; - } - *pointer = fd; - return 1; -} - -static PyObject * -posix_fildes_fd(int fd, int (*func)(int)) -{ - int res; + return NULL; + if (!_PyVerify_fd(fd)) + return posix_error(); Py_BEGIN_ALLOW_THREADS res = (*func)(fd); Py_END_ALLOW_THREADS @@ -1341,6 +1317,30 @@ return Py_None; } +static PyObject * +posix_1str(const char *func_name, PyObject *args, char *format, + int (*func)(const char*)) +{ + path_t path; + int res; + memset(&path, 0, sizeof(path)); + path.function_name = func_name; + if (!PyArg_ParseTuple(args, format, + path_converter, &path)) + return NULL; + Py_BEGIN_ALLOW_THREADS + res = (*func)(path.narrow); + Py_END_ALLOW_THREADS + if (res < 0) { + path_error(&path); + path_cleanup(&path); + return NULL; + } + path_cleanup(&path); + Py_INCREF(Py_None); + return Py_None; +} + #ifdef MS_WINDOWS /* This is a reimplementation of the C library's chdir function, @@ -2113,12 +2113,10 @@ PyDoc_STRVAR(stat_float_times__doc__, "stat_float_times([newval]) -> oldval\n\n\ Determine whether os.[lf]stat represents time stamps as float objects.\n\ -\n\ -If value is True, future calls to stat() return floats; if it is False,\n\ -future calls return ints.\n\ -If value is omitted, return the current setting.\n"); - -/* AC 3.5: the public default value should be None, not ready for that yet */ +If newval is True, future calls to stat() return floats, if it is False,\n\ +future calls return ints. \n\ +If newval is omitted, return the current setting.\n"); + static PyObject* stat_float_times(PyObject* self, PyObject *args) { @@ -2348,176 +2346,11 @@ return _pystat_fromstructstat(&st); } -/*[python input] - -for s in """ - -FACCESSAT -FCHMODAT -FCHOWNAT -FSTATAT -LINKAT -MKDIRAT -MKFIFOAT -MKNODAT -OPENAT -READLINKAT -SYMLINKAT -UNLINKAT - -""".strip().split(): - s = s.strip() - print(""" -#ifdef HAVE_{s} - #define {s}_DIR_FD_CONVERTER dir_fd_converter -#else - #define {s}_DIR_FD_CONVERTER dir_fd_unavailable -#endif -""".rstrip().format(s=s)) - -for s in """ - -FCHDIR -FCHMOD -FCHOWN -FDOPENDIR -FEXECVE -FPATHCONF -FSTATVFS -FTRUNCATE - -""".strip().split(): - s = s.strip() - print(""" -#ifdef HAVE_{s} - #define PATH_HAVE_{s} 1 -#else - #define PATH_HAVE_{s} 0 -#endif - -""".rstrip().format(s=s)) -[python start generated code]*/ - -#ifdef HAVE_FACCESSAT - #define FACCESSAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define FACCESSAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_FCHMODAT - #define FCHMODAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define FCHMODAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_FCHOWNAT - #define FCHOWNAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define FCHOWNAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - #ifdef HAVE_FSTATAT - #define FSTATAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define FSTATAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_LINKAT - #define LINKAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define LINKAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_MKDIRAT - #define MKDIRAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define MKDIRAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_MKFIFOAT - #define MKFIFOAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define MKFIFOAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_MKNODAT - #define MKNODAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define MKNODAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_OPENAT - #define OPENAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define OPENAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_READLINKAT - #define READLINKAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define READLINKAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_SYMLINKAT - #define SYMLINKAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define SYMLINKAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_UNLINKAT - #define UNLINKAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define UNLINKAT_DIR_FD_CONVERTER dir_fd_unavailable -#endif - -#ifdef HAVE_FCHDIR - #define PATH_HAVE_FCHDIR 1 -#else - #define PATH_HAVE_FCHDIR 0 -#endif - -#ifdef HAVE_FCHMOD - #define PATH_HAVE_FCHMOD 1 -#else - #define PATH_HAVE_FCHMOD 0 -#endif - -#ifdef HAVE_FCHOWN - #define PATH_HAVE_FCHOWN 1 -#else - #define PATH_HAVE_FCHOWN 0 -#endif - -#ifdef HAVE_FDOPENDIR - #define PATH_HAVE_FDOPENDIR 1 -#else - #define PATH_HAVE_FDOPENDIR 0 -#endif - -#ifdef HAVE_FEXECVE - #define PATH_HAVE_FEXECVE 1 -#else - #define PATH_HAVE_FEXECVE 0 -#endif - -#ifdef HAVE_FPATHCONF - #define PATH_HAVE_FPATHCONF 1 -#else - #define PATH_HAVE_FPATHCONF 0 -#endif - -#ifdef HAVE_FSTATVFS - #define PATH_HAVE_FSTATVFS 1 -#else - #define PATH_HAVE_FSTATVFS 0 -#endif - -#ifdef HAVE_FTRUNCATE - #define PATH_HAVE_FTRUNCATE 1 -#else - #define PATH_HAVE_FTRUNCATE 0 -#endif -/*[python end generated code: output=4bd4f6f7d41267f1 input=80b4c890b6774ea5]*/ + #define OS_STAT_DIR_FD_CONVERTER dir_fd_converter +#else + #define OS_STAT_DIR_FD_CONVERTER dir_fd_unavailable +#endif /*[python input] @@ -2533,25 +2366,22 @@ def converter_init(self, *, allow_fd=False, nullable=False): # right now path_t doesn't support default values. # to support a default value, you'll need to override initialize(). - if self.default not in (unspecified, None): + if self.default is not unspecified: fail("Can't specify a default to the path_t converter!") - if self.c_default not in (None, 'Py_None'): - raise RuntimeError("Can't specify a c_default to the path_t converter!") + if self.c_default is not None: + fail("Can't specify a c_default to the path_t converter!") self.nullable = nullable self.allow_fd = allow_fd def pre_render(self): def strify(value): - if isinstance(value, str): - return value return str(int(bool(value))) # add self.py_name here when merging with posixmodule conversion - self.c_default = 'PATH_T_INITIALIZE("{}", "{}", {}, {})'.format( + self.c_default = 'PATH_T_INITIALIZE("{}", {}, {})'.format( self.function.name, - self.name, strify(self.nullable), strify(self.allow_fd), ) @@ -2562,78 +2392,15 @@ class dir_fd_converter(CConverter): type = 'int' - - def converter_init(self, requires=None): + converter = 'OS_STAT_DIR_FD_CONVERTER' + + def converter_init(self): if self.default in (unspecified, None): self.c_default = 'DEFAULT_DIR_FD' - if isinstance(requires, str): - self.converter = requires.upper() + '_DIR_FD_CONVERTER' - else: - self.converter = 'dir_fd_converter' - -class fildes_converter(CConverter): - type = 'int' - converter = 'fildes_converter' - -class uid_t_converter(CConverter): - type = "uid_t" - converter = '_Py_Uid_Converter' - -class gid_t_converter(CConverter): - type = "gid_t" - converter = '_Py_Gid_Converter' - -class FSConverter_converter(CConverter): - type = 'PyObject *' - converter = 'PyUnicode_FSConverter' - def converter_init(self): - if self.default is not unspecified: - fail("FSConverter_converter does not support default values") - self.c_default = 'NULL' - - def cleanup(self): - return "Py_XDECREF(" + self.name + ");\n" - -class pid_t_converter(CConverter): - type = 'pid_t' - format_unit = '" _Py_PARSE_PID "' - -class idtype_t_converter(int_converter): - type = 'idtype_t' - -class id_t_converter(CConverter): - type = 'id_t' - format_unit = '" _Py_PARSE_PID "' - -class Py_intptr_t_converter(CConverter): - type = 'Py_intptr_t' - format_unit = '" _Py_PARSE_INTPTR "' - -class Py_off_t_converter(CConverter): - type = 'Py_off_t' - converter = 'Py_off_t_converter' - -class Py_off_t_return_converter(long_return_converter): - type = 'Py_off_t' - conversion_fn = 'PyLong_FromPy_off_t' - -class path_confname_converter(CConverter): - type="int" - converter="conv_path_confname" - -class confstr_confname_converter(path_confname_converter): - converter='conv_confstr_confname' - -class sysconf_confname_converter(path_confname_converter): - converter="conv_sysconf_confname" - -class sched_param_converter(CConverter): - type = 'struct sched_param' - converter = 'convert_sched_param' - impl_by_reference = True; + [python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=147ba8f52a05aca4]*/ +/*[python end generated code: output=da39a3ee5e6b4b0d input=5c9f456f53244fc3]*/ /*[clinic input] @@ -2644,7 +2411,7 @@ * - dir_fd : dir_fd(requires='fstatat') = None + dir_fd : dir_fd = None If not None, it should be a file descriptor open to a directory, and path should be a relative string; path will then be relative to that directory. @@ -2700,13 +2467,13 @@ { PyObject *return_value = NULL; static char *_keywords[] = {"path", "dir_fd", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("stat", "path", 0, 1); + path_t path = PATH_T_INITIALIZE("stat", 0, 1); int dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&p:stat", _keywords, - path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) + path_converter, &path, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) goto exit; return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks); @@ -2719,74 +2486,49 @@ static PyObject * os_stat_impl(PyModuleDef *module, path_t *path, int dir_fd, int follow_symlinks) -/*[clinic end generated code: output=0e9f9508fa0c0607 input=099d356c306fa24a]*/ +/*[clinic end generated code: output=f1dcaa5e24db9882 input=5ae155bd475fd20a]*/ { return posix_do_stat("stat", path, dir_fd, follow_symlinks); } - +PyDoc_STRVAR(posix_lstat__doc__, +"lstat(path, *, dir_fd=None) -> stat result\n\n\ +Like stat(), but do not follow symbolic links.\n\ +Equivalent to stat(path, follow_symlinks=False)."); + +static PyObject * +posix_lstat(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"path", "dir_fd", NULL}; + path_t path; + int dir_fd = DEFAULT_DIR_FD; + int follow_symlinks = 0; + PyObject *return_value; + + memset(&path, 0, sizeof(path)); + path.function_name = "lstat"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:lstat", keywords, + path_converter, &path, +#ifdef HAVE_FSTATAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; + return_value = posix_do_stat("lstat", &path, dir_fd, follow_symlinks); + path_cleanup(&path); + return return_value; +} + + +#ifdef HAVE_FACCESSAT + #define OS_ACCESS_DIR_FD_CONVERTER dir_fd_converter +#else + #define OS_ACCESS_DIR_FD_CONVERTER dir_fd_unavailable +#endif /*[clinic input] -os.lstat - - path : path_t - - * - - dir_fd : dir_fd(requires='fstatat') = None - -Perform a stat system call on the given path, without following symbolic links. - -Like stat(), but do not follow symbolic links. -Equivalent to stat(path, follow_symlinks=False). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lstat__doc__, -"lstat($module, /, path, *, dir_fd=None)\n" -"--\n" -"\n" -"Perform a stat system call on the given path, without following symbolic links.\n" -"\n" -"Like stat(), but do not follow symbolic links.\n" -"Equivalent to stat(path, follow_symlinks=False)."); - -#define OS_LSTAT_METHODDEF \ - {"lstat", (PyCFunction)os_lstat, METH_VARARGS|METH_KEYWORDS, os_lstat__doc__}, - -static PyObject * -os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd); - -static PyObject * -os_lstat(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("lstat", "path", 0, 0); - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|$O&:lstat", _keywords, - path_converter, &path, FSTATAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_lstat_impl(module, &path, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_lstat_impl(PyModuleDef *module, path_t *path, int dir_fd) -/*[clinic end generated code: output=85702247224a2b1c input=0b7474765927b925]*/ -{ - int follow_symlinks = 0; - return posix_do_stat("lstat", path, dir_fd, follow_symlinks); -} - - -/*[clinic input] -os.access -> bool +os.access path: path_t(allow_fd=True) Path to be tested; can be string, bytes, or open-file-descriptor int. @@ -2797,7 +2539,7 @@ * - dir_fd : dir_fd(requires='faccessat') = None + dir_fd : dir_fd = None If not None, it should be a file descriptor open to a directory, and path should be relative; path will then be relative to that directory. @@ -2859,7 +2601,7 @@ #define OS_ACCESS_METHODDEF \ {"access", (PyCFunction)os_access, METH_VARARGS|METH_KEYWORDS, os_access__doc__}, -static int +static PyObject * os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks); static PyObject * @@ -2867,21 +2609,17 @@ { PyObject *return_value = NULL; static char *_keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("access", "path", 0, 1); + path_t path = PATH_T_INITIALIZE("access", 0, 1); int mode; int dir_fd = DEFAULT_DIR_FD; int effective_ids = 0; int follow_symlinks = 1; - int _return_value; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&pp:access", _keywords, - path_converter, &path, &mode, FACCESSAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) + path_converter, &path, &mode, OS_STAT_DIR_FD_CONVERTER, &dir_fd, &effective_ids, &follow_symlinks)) goto exit; - _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); + return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks); exit: /* Cleanup for path */ @@ -2890,11 +2628,11 @@ return return_value; } -static int +static PyObject * os_access_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int effective_ids, int follow_symlinks) -/*[clinic end generated code: output=dfd404666906f012 input=b75a756797af45ec]*/ -{ - int return_value; +/*[clinic end generated code: output=a6ed4f151be9df0f input=2e2e7594371f5b7e]*/ +{ + PyObject *return_value = NULL; #ifdef MS_WINDOWS DWORD attr; @@ -2904,11 +2642,11 @@ #ifndef HAVE_FACCESSAT if (follow_symlinks_specified("access", follow_symlinks)) - return -1; + goto exit; if (effective_ids) { argument_unavailable_error("access", "effective_ids"); - return -1; + goto exit; } #endif @@ -2928,10 +2666,11 @@ * * or it's a directory. * (Directories cannot be read-only on Windows.) */ - return_value = (attr != INVALID_FILE_ATTRIBUTES) && + return_value = PyBool_FromLong( + (attr != INVALID_FILE_ATTRIBUTES) && (!(mode & 2) || !(attr & FILE_ATTRIBUTE_READONLY) || - (attr & FILE_ATTRIBUTE_DIRECTORY)); + (attr & FILE_ATTRIBUTE_DIRECTORY))); #else Py_BEGIN_ALLOW_THREADS @@ -2950,9 +2689,12 @@ #endif result = access(path->narrow, mode); Py_END_ALLOW_THREADS - return_value = !result; -#endif - + return_value = PyBool_FromLong(!result); +#endif + +#ifndef HAVE_FACCESSAT +exit: +#endif return return_value; } @@ -2971,6 +2713,7 @@ #ifdef HAVE_TTYNAME + /*[clinic input] os.ttyname -> DecodeFSDefault @@ -3028,36 +2771,17 @@ posix_error(); return ret; } +#else +#define OS_TTYNAME_METHODDEF #endif #ifdef HAVE_CTERMID -/*[clinic input] -os.ctermid - -Return the name of the controlling terminal for this process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_ctermid__doc__, -"ctermid($module, /)\n" -"--\n" -"\n" -"Return the name of the controlling terminal for this process."); - -#define OS_CTERMID_METHODDEF \ - {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__}, - -static PyObject * -os_ctermid_impl(PyModuleDef *module); - -static PyObject * -os_ctermid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_ctermid_impl(module); -} - -static PyObject * -os_ctermid_impl(PyModuleDef *module) -/*[clinic end generated code: output=277bf7964ec2d782 input=3b87fdd52556382d]*/ +PyDoc_STRVAR(posix_ctermid__doc__, +"ctermid() -> string\n\n\ +Return the name of the controlling terminal for this process."); + +static PyObject * +posix_ctermid(PyObject *self, PyObject *noargs) { char *ret; char buffer[L_ctermid]; @@ -3071,234 +2795,106 @@ return posix_error(); return PyUnicode_DecodeFSDefault(buffer); } -#endif /* HAVE_CTERMID */ - - -/*[clinic input] -os.chdir - - path: path_t(allow_fd='PATH_HAVE_FCHDIR') - -Change the current working directory to the specified path. - -path may always be specified as a string. -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_chdir__doc__, -"chdir($module, /, path)\n" -"--\n" -"\n" -"Change the current working directory to the specified path.\n" -"\n" -"path may always be specified as a string.\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception."); - -#define OS_CHDIR_METHODDEF \ - {"chdir", (PyCFunction)os_chdir, METH_VARARGS|METH_KEYWORDS, os_chdir__doc__}, - -static PyObject * -os_chdir_impl(PyModuleDef *module, path_t *path); - -static PyObject * -os_chdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ +#endif + +PyDoc_STRVAR(posix_chdir__doc__, +"chdir(path)\n\n\ +Change the current working directory to the specified path.\n\ +\n\ +path may always be specified as a string.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception."); + +static PyObject * +posix_chdir(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int result; PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - path_t path = PATH_T_INITIALIZE("chdir", "path", 0, PATH_HAVE_FCHDIR); - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:chdir", _keywords, - path_converter, &path)) - goto exit; - return_value = os_chdir_impl(module, &path); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_chdir_impl(PyModuleDef *module, path_t *path) -/*[clinic end generated code: output=cc07592dd23ca9e0 input=1a4a15b4d12cb15d]*/ -{ - int result; + static char *keywords[] = {"path", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "chdir"; +#ifdef HAVE_FCHDIR + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:chdir", keywords, + path_converter, &path + )) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - if (path->wide) - result = win32_wchdir(path->wide); + if (path.wide) + result = win32_wchdir(path.wide); else - result = win32_chdir(path->narrow); + result = win32_chdir(path.narrow); result = !result; /* on unix, success = 0, on windows, success = !0 */ #else #ifdef HAVE_FCHDIR - if (path->fd != -1) - result = fchdir(path->fd); + if (path.fd != -1) + result = fchdir(path.fd); else #endif - result = chdir(path->narrow); + result = chdir(path.narrow); #endif Py_END_ALLOW_THREADS if (result) { - return path_error(path); - } - - Py_RETURN_NONE; -} - + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; +} #ifdef HAVE_FCHDIR -/*[clinic input] -os.fchdir - - fd: fildes - -Change to the directory of the given file descriptor. - -fd must be opened on a directory, not a file. -Equivalent to os.chdir(fd). - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fchdir__doc__, -"fchdir($module, /, fd)\n" -"--\n" -"\n" -"Change to the directory of the given file descriptor.\n" -"\n" -"fd must be opened on a directory, not a file.\n" -"Equivalent to os.chdir(fd)."); - -#define OS_FCHDIR_METHODDEF \ - {"fchdir", (PyCFunction)os_fchdir, METH_VARARGS|METH_KEYWORDS, os_fchdir__doc__}, - -static PyObject * -os_fchdir_impl(PyModuleDef *module, int fd); - -static PyObject * -os_fchdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; - int fd; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:fchdir", _keywords, - fildes_converter, &fd)) - goto exit; - return_value = os_fchdir_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_fchdir_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=9f6dbc89b2778834 input=18e816479a2fa985]*/ -{ - return posix_fildes_fd(fd, fchdir); +PyDoc_STRVAR(posix_fchdir__doc__, +"fchdir(fd)\n\n\ +Change to the directory of the given file descriptor. fd must be\n\ +opened on a directory, not a file. Equivalent to os.chdir(fd)."); + +static PyObject * +posix_fchdir(PyObject *self, PyObject *fdobj) +{ + return posix_fildes(fdobj, fchdir); } #endif /* HAVE_FCHDIR */ -/*[clinic input] -os.chmod - - path: path_t(allow_fd='PATH_HAVE_FCHMOD') - Path to be modified. May always be specified as a str or bytes. - On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. - - mode: int - Operating-system mode bitfield. - - * - - dir_fd : dir_fd(requires='fchmodat') = None - If not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that - directory. - - follow_symlinks: bool = True - If False, and the last element of the path is a symbolic link, - chmod will modify the symbolic link itself instead of the file - the link points to. - -Change the access permissions of a file. - -It is an error to use dir_fd or follow_symlinks when specifying path as - an open file descriptor. -dir_fd and follow_symlinks may not be implemented on your platform. - If they are unavailable, using them will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_chmod__doc__, -"chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n" -"--\n" -"\n" -"Change the access permissions of a file.\n" -"\n" -" path\n" -" Path to be modified. May always be specified as a str or bytes.\n" -" On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception.\n" -" mode\n" -" Operating-system mode bitfield.\n" -" dir_fd\n" -" If not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that\n" -" directory.\n" -" follow_symlinks\n" -" If False, and the last element of the path is a symbolic link,\n" -" chmod will modify the symbolic link itself instead of the file\n" -" the link points to.\n" -"\n" -"It is an error to use dir_fd or follow_symlinks when specifying path as\n" -" an open file descriptor.\n" -"dir_fd and follow_symlinks may not be implemented on your platform.\n" -" If they are unavailable, using them will raise a NotImplementedError."); - -#define OS_CHMOD_METHODDEF \ - {"chmod", (PyCFunction)os_chmod, METH_VARARGS|METH_KEYWORDS, os_chmod__doc__}, - -static PyObject * -os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int follow_symlinks); - -static PyObject * -os_chmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("chmod", "path", 0, PATH_HAVE_FCHMOD); +PyDoc_STRVAR(posix_chmod__doc__, +"chmod(path, mode, *, dir_fd=None, follow_symlinks=True)\n\n\ +Change the access permissions of a file.\n\ +\n\ +path may always be specified as a string.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception.\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, chmod will modify the symbolic link itself instead of the file the\n\ + link points to.\n\ +It is an error to use dir_fd or follow_symlinks when specifying path as\n\ + an open file descriptor.\n\ +dir_fd and follow_symlinks may not be implemented on your platform.\n\ + If they are unavailable, using them will raise a NotImplementedError."); + +static PyObject * +posix_chmod(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; int mode; int dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&i|$O&p:chmod", _keywords, - path_converter, &path, &mode, FCHMODAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) - goto exit; - return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_chmod_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd, int follow_symlinks) -/*[clinic end generated code: output=1e9db031aea46422 input=7f1618e5e15cc196]*/ -{ int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "mode", "dir_fd", + "follow_symlinks", NULL}; #ifdef MS_WINDOWS DWORD attr; @@ -3308,17 +2904,33 @@ int fchmodat_nofollow_unsupported = 0; #endif + memset(&path, 0, sizeof(path)); + path.function_name = "chmod"; +#ifdef HAVE_FCHMOD + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|$O&p:chmod", keywords, + path_converter, &path, + &mode, +#ifdef HAVE_FCHMODAT + dir_fd_converter, &dir_fd, +#else + dir_fd_unavailable, &dir_fd, +#endif + &follow_symlinks)) + return NULL; + #if !(defined(HAVE_FCHMODAT) || defined(HAVE_LCHMOD)) if (follow_symlinks_specified("chmod", follow_symlinks)) - return NULL; + goto exit; #endif #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS - if (path->wide) - attr = GetFileAttributesW(path->wide); + if (path.wide) + attr = GetFileAttributesW(path.wide); else - attr = GetFileAttributesA(path->narrow); + attr = GetFileAttributesA(path.narrow); if (attr == INVALID_FILE_ATTRIBUTES) result = 0; else { @@ -3326,26 +2938,27 @@ attr &= ~FILE_ATTRIBUTE_READONLY; else attr |= FILE_ATTRIBUTE_READONLY; - if (path->wide) - result = SetFileAttributesW(path->wide, attr); + if (path.wide) + result = SetFileAttributesW(path.wide, attr); else - result = SetFileAttributesA(path->narrow, attr); + result = SetFileAttributesA(path.narrow, attr); } Py_END_ALLOW_THREADS if (!result) { - return path_error(path); + return_value = path_error(&path); + goto exit; } #else /* MS_WINDOWS */ Py_BEGIN_ALLOW_THREADS #ifdef HAVE_FCHMOD - if (path->fd != -1) - result = fchmod(path->fd, mode); + if (path.fd != -1) + result = fchmod(path.fd, mode); else #endif #ifdef HAVE_LCHMOD if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD)) - result = lchmod(path->narrow, mode); + result = lchmod(path.narrow, mode); else #endif #ifdef HAVE_FCHMODAT @@ -3360,7 +2973,7 @@ * support dir_fd and follow_symlinks=False. (Hopefully.) * Until then, we need to be careful what exception we raise. */ - result = fchmodat(dir_fd, path->narrow, mode, + result = fchmodat(dir_fd, path.narrow, mode, follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW); /* * But wait! We can't throw the exception without allowing threads, @@ -3373,7 +2986,7 @@ } else #endif - result = chmod(path->narrow, mode); + result = chmod(path.narrow, mode); Py_END_ALLOW_THREADS if (result) { @@ -3387,63 +3000,31 @@ } else #endif - return path_error(path); - } -#endif - - Py_RETURN_NONE; + return_value = path_error(&path); + goto exit; + } +#endif + + Py_INCREF(Py_None); + return_value = Py_None; +exit: + path_cleanup(&path); + return return_value; } #ifdef HAVE_FCHMOD -/*[clinic input] -os.fchmod - - fd: int - mode: int - -Change the access permissions of the file given by file descriptor fd. - -Equivalent to os.chmod(fd, mode). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fchmod__doc__, -"fchmod($module, /, fd, mode)\n" -"--\n" -"\n" -"Change the access permissions of the file given by file descriptor fd.\n" -"\n" -"Equivalent to os.chmod(fd, mode)."); - -#define OS_FCHMOD_METHODDEF \ - {"fchmod", (PyCFunction)os_fchmod, METH_VARARGS|METH_KEYWORDS, os_fchmod__doc__}, - -static PyObject * -os_fchmod_impl(PyModuleDef *module, int fd, int mode); - -static PyObject * -os_fchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", "mode", NULL}; - int fd; - int mode; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ii:fchmod", _keywords, - &fd, &mode)) - goto exit; - return_value = os_fchmod_impl(module, fd, mode); - -exit: - return return_value; -} - -static PyObject * -os_fchmod_impl(PyModuleDef *module, int fd, int mode) -/*[clinic end generated code: output=3c19fbfd724a8e0f input=8ab11975ca01ee5b]*/ -{ - int res; +PyDoc_STRVAR(posix_fchmod__doc__, +"fchmod(fd, mode)\n\n\ +Change the access permissions of the file given by file\n\ +descriptor fd. Equivalent to os.chmod(fd, mode)."); + +static PyObject * +posix_fchmod(PyObject *self, PyObject *args) +{ + int fd, mode, res; + if (!PyArg_ParseTuple(args, "ii:fchmod", &fd, &mode)) + return NULL; Py_BEGIN_ALLOW_THREADS res = fchmod(fd, mode); Py_END_ALLOW_THREADS @@ -3453,528 +3034,238 @@ } #endif /* HAVE_FCHMOD */ - #ifdef HAVE_LCHMOD -/*[clinic input] -os.lchmod - - path: path_t - mode: int - -Change the access permissions of a file, without following symbolic links. - -If path is a symlink, this affects the link itself rather than the target. -Equivalent to chmod(path, mode, follow_symlinks=False)." -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lchmod__doc__, -"lchmod($module, /, path, mode)\n" -"--\n" -"\n" -"Change the access permissions of a file, without following symbolic links.\n" -"\n" -"If path is a symlink, this affects the link itself rather than the target.\n" -"Equivalent to chmod(path, mode, follow_symlinks=False).\""); - -#define OS_LCHMOD_METHODDEF \ - {"lchmod", (PyCFunction)os_lchmod, METH_VARARGS|METH_KEYWORDS, os_lchmod__doc__}, - -static PyObject * -os_lchmod_impl(PyModuleDef *module, path_t *path, int mode); - -static PyObject * -os_lchmod(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "mode", NULL}; - path_t path = PATH_T_INITIALIZE("lchmod", "path", 0, 0); - int mode; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&i:lchmod", _keywords, - path_converter, &path, &mode)) - goto exit; - return_value = os_lchmod_impl(module, &path, mode); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_lchmod_impl(PyModuleDef *module, path_t *path, int mode) -/*[clinic end generated code: output=2849977d65f8c68c input=90c5663c7465d24f]*/ -{ +PyDoc_STRVAR(posix_lchmod__doc__, +"lchmod(path, mode)\n\n\ +Change the access permissions of a file. If path is a symlink, this\n\ +affects the link itself rather than the target.\n\ +Equivalent to chmod(path, mode, follow_symlinks=False)."); + +static PyObject * +posix_lchmod(PyObject *self, PyObject *args) +{ + path_t path; + int i; int res; + memset(&path, 0, sizeof(path)); + path.function_name = "lchmod"; + if (!PyArg_ParseTuple(args, "O&i:lchmod", + path_converter, &path, &i)) + return NULL; Py_BEGIN_ALLOW_THREADS - res = lchmod(path->narrow, mode); + res = lchmod(path.narrow, i); Py_END_ALLOW_THREADS if (res < 0) { - path_error(path); - return NULL; - } + path_error(&path); + path_cleanup(&path); + return NULL; + } + path_cleanup(&path); Py_RETURN_NONE; } #endif /* HAVE_LCHMOD */ #ifdef HAVE_CHFLAGS -/*[clinic input] -os.chflags - - path: path_t - flags: unsigned_long(bitwise=True) - follow_symlinks: bool=True - -Set file flags. - -If follow_symlinks is False, and the last element of the path is a symbolic - link, chflags will change flags on the symbolic link itself instead of the - file the link points to. -follow_symlinks may not be implemented on your platform. If it is -unavailable, using it will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_chflags__doc__, -"chflags($module, /, path, flags, follow_symlinks=True)\n" -"--\n" -"\n" -"Set file flags.\n" -"\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, chflags will change flags on the symbolic link itself instead of the\n" -" file the link points to.\n" -"follow_symlinks may not be implemented on your platform. If it is\n" -"unavailable, using it will raise a NotImplementedError."); - -#define OS_CHFLAGS_METHODDEF \ - {"chflags", (PyCFunction)os_chflags, METH_VARARGS|METH_KEYWORDS, os_chflags__doc__}, - -static PyObject * -os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags, int follow_symlinks); - -static PyObject * -os_chflags(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "flags", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("chflags", "path", 0, 0); +PyDoc_STRVAR(posix_chflags__doc__, +"chflags(path, flags, *, follow_symlinks=True)\n\n\ +Set file flags.\n\ +\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, chflags will change flags on the symbolic link itself instead of the\n\ + file the link points to.\n\ +follow_symlinks may not be implemented on your platform. If it is\n\ +unavailable, using it will raise a NotImplementedError."); + +static PyObject * +posix_chflags(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; unsigned long flags; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&k|p:chflags", _keywords, - path_converter, &path, &flags, &follow_symlinks)) - goto exit; - return_value = os_chflags_impl(module, &path, flags, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_chflags_impl(PyModuleDef *module, path_t *path, unsigned long flags, int follow_symlinks) -/*[clinic end generated code: output=2767927bf071e3cf input=0327e29feb876236]*/ -{ int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "flags", "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "chflags"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&k|$i:chflags", keywords, + path_converter, &path, + &flags, &follow_symlinks)) + return NULL; #ifndef HAVE_LCHFLAGS if (follow_symlinks_specified("chflags", follow_symlinks)) - return NULL; + goto exit; #endif Py_BEGIN_ALLOW_THREADS #ifdef HAVE_LCHFLAGS if (!follow_symlinks) - result = lchflags(path->narrow, flags); + result = lchflags(path.narrow, flags); else #endif - result = chflags(path->narrow, flags); + result = chflags(path.narrow, flags); Py_END_ALLOW_THREADS - if (result) - return path_error(path); - - Py_RETURN_NONE; + if (result) { + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; } #endif /* HAVE_CHFLAGS */ - #ifdef HAVE_LCHFLAGS -/*[clinic input] -os.lchflags - - path: path_t - flags: unsigned_long(bitwise=True) - -Set file flags. - -This function will not follow symbolic links. -Equivalent to chflags(path, flags, follow_symlinks=False). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lchflags__doc__, -"lchflags($module, /, path, flags)\n" -"--\n" -"\n" -"Set file flags.\n" -"\n" -"This function will not follow symbolic links.\n" -"Equivalent to chflags(path, flags, follow_symlinks=False)."); - -#define OS_LCHFLAGS_METHODDEF \ - {"lchflags", (PyCFunction)os_lchflags, METH_VARARGS|METH_KEYWORDS, os_lchflags__doc__}, - -static PyObject * -os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags); - -static PyObject * -os_lchflags(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "flags", NULL}; - path_t path = PATH_T_INITIALIZE("lchflags", "path", 0, 0); +PyDoc_STRVAR(posix_lchflags__doc__, +"lchflags(path, flags)\n\n\ +Set file flags.\n\ +This function will not follow symbolic links.\n\ +Equivalent to chflags(path, flags, follow_symlinks=False)."); + +static PyObject * +posix_lchflags(PyObject *self, PyObject *args) +{ + path_t path; unsigned long flags; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&k:lchflags", _keywords, - path_converter, &path, &flags)) - goto exit; - return_value = os_lchflags_impl(module, &path, flags); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_lchflags_impl(PyModuleDef *module, path_t *path, unsigned long flags) -/*[clinic end generated code: output=bb93b6b8a5e45aa7 input=f9f82ea8b585ca9d]*/ -{ int res; + memset(&path, 0, sizeof(path)); + path.function_name = "lchflags"; + if (!PyArg_ParseTuple(args, "O&k:lchflags", + path_converter, &path, &flags)) + return NULL; Py_BEGIN_ALLOW_THREADS - res = lchflags(path->narrow, flags); + res = lchflags(path.narrow, flags); Py_END_ALLOW_THREADS if (res < 0) { - return path_error(path); - } + path_error(&path); + path_cleanup(&path); + return NULL; + } + path_cleanup(&path); Py_RETURN_NONE; } #endif /* HAVE_LCHFLAGS */ - #ifdef HAVE_CHROOT -/*[clinic input] -os.chroot - path: path_t - -Change root directory to path. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_chroot__doc__, -"chroot($module, /, path)\n" -"--\n" -"\n" -"Change root directory to path."); - -#define OS_CHROOT_METHODDEF \ - {"chroot", (PyCFunction)os_chroot, METH_VARARGS|METH_KEYWORDS, os_chroot__doc__}, - -static PyObject * -os_chroot_impl(PyModuleDef *module, path_t *path); - -static PyObject * -os_chroot(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - path_t path = PATH_T_INITIALIZE("chroot", "path", 0, 0); - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:chroot", _keywords, - path_converter, &path)) - goto exit; - return_value = os_chroot_impl(module, &path); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_chroot_impl(PyModuleDef *module, path_t *path) -/*[clinic end generated code: output=15b1256cbe4f24a1 input=14822965652c3dc3]*/ -{ - int res; - Py_BEGIN_ALLOW_THREADS - res = chroot(path->narrow); - Py_END_ALLOW_THREADS - if (res < 0) - return path_error(path); - Py_RETURN_NONE; -} -#endif /* HAVE_CHROOT */ - +PyDoc_STRVAR(posix_chroot__doc__, +"chroot(path)\n\n\ +Change root directory to path."); + +static PyObject * +posix_chroot(PyObject *self, PyObject *args) +{ + return posix_1str("chroot", args, "O&:chroot", chroot); +} +#endif #ifdef HAVE_FSYNC -/*[clinic input] -os.fsync - - fd: fildes - -Force write of fd to disk. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fsync__doc__, -"fsync($module, /, fd)\n" -"--\n" -"\n" -"Force write of fd to disk."); - -#define OS_FSYNC_METHODDEF \ - {"fsync", (PyCFunction)os_fsync, METH_VARARGS|METH_KEYWORDS, os_fsync__doc__}, - -static PyObject * -os_fsync_impl(PyModuleDef *module, int fd); - -static PyObject * -os_fsync(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; - int fd; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:fsync", _keywords, - fildes_converter, &fd)) - goto exit; - return_value = os_fsync_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_fsync_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=59f32d3a0b360133 input=21c3645c056967f2]*/ -{ - return posix_fildes_fd(fd, fsync); +PyDoc_STRVAR(posix_fsync__doc__, +"fsync(fildes)\n\n\ +force write of file with filedescriptor to disk."); + +static PyObject * +posix_fsync(PyObject *self, PyObject *fdobj) +{ + return posix_fildes(fdobj, fsync); } #endif /* HAVE_FSYNC */ - #ifdef HAVE_SYNC -/*[clinic input] -os.sync - -Force write of everything to disk. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sync__doc__, -"sync($module, /)\n" -"--\n" -"\n" -"Force write of everything to disk."); - -#define OS_SYNC_METHODDEF \ - {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__}, - -static PyObject * -os_sync_impl(PyModuleDef *module); - -static PyObject * -os_sync(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_sync_impl(module); -} - -static PyObject * -os_sync_impl(PyModuleDef *module) -/*[clinic end generated code: output=526c495683d0bb38 input=84749fe5e9b404ff]*/ +PyDoc_STRVAR(posix_sync__doc__, +"sync()\n\n\ +Force write of everything to disk."); + +static PyObject * +posix_sync(PyObject *self, PyObject *noargs) { Py_BEGIN_ALLOW_THREADS sync(); Py_END_ALLOW_THREADS Py_RETURN_NONE; } -#endif /* HAVE_SYNC */ - +#endif #ifdef HAVE_FDATASYNC + #ifdef __hpux extern int fdatasync(int); /* On HP-UX, in libc but not in unistd.h */ #endif -/*[clinic input] -os.fdatasync - - fd: fildes - -Force write of fd to disk without forcing update of metadata. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fdatasync__doc__, -"fdatasync($module, /, fd)\n" -"--\n" -"\n" -"Force write of fd to disk without forcing update of metadata."); - -#define OS_FDATASYNC_METHODDEF \ - {"fdatasync", (PyCFunction)os_fdatasync, METH_VARARGS|METH_KEYWORDS, os_fdatasync__doc__}, - -static PyObject * -os_fdatasync_impl(PyModuleDef *module, int fd); - -static PyObject * -os_fdatasync(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; - int fd; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:fdatasync", _keywords, - fildes_converter, &fd)) - goto exit; - return_value = os_fdatasync_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_fdatasync_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=2335fdfd37c92180 input=bc74791ee54dd291]*/ -{ - return posix_fildes_fd(fd, fdatasync); +PyDoc_STRVAR(posix_fdatasync__doc__, +"fdatasync(fildes)\n\n\ +force write of file with filedescriptor to disk.\n\ + does not force update of metadata."); + +static PyObject * +posix_fdatasync(PyObject *self, PyObject *fdobj) +{ + return posix_fildes(fdobj, fdatasync); } #endif /* HAVE_FDATASYNC */ #ifdef HAVE_CHOWN -/*[clinic input] -os.chown - - path : path_t(allow_fd='PATH_HAVE_FCHOWN') - Path to be examined; can be string, bytes, or open-file-descriptor int. - - uid: uid_t - - gid: gid_t - - * - - dir_fd : dir_fd(requires='fchownat') = None - If not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that - directory. - - follow_symlinks: bool = True - If False, and the last element of the path is a symbolic link, - stat will examine the symbolic link itself instead of the file - the link points to. - -Change the owner and group id of path to the numeric uid and gid.\ - -path may always be specified as a string. -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -If follow_symlinks is False, and the last element of the path is a symbolic - link, chown will modify the symbolic link itself instead of the file the - link points to. -It is an error to use dir_fd or follow_symlinks when specifying path as - an open file descriptor. -dir_fd and follow_symlinks may not be implemented on your platform. - If they are unavailable, using them will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_chown__doc__, -"chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n" -"--\n" -"\n" -"Change the owner and group id of path to the numeric uid and gid.\\\n" -"\n" -" path\n" -" Path to be examined; can be string, bytes, or open-file-descriptor int.\n" -" dir_fd\n" -" If not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that\n" -" directory.\n" -" follow_symlinks\n" -" If False, and the last element of the path is a symbolic link,\n" -" stat will examine the symbolic link itself instead of the file\n" -" the link points to.\n" -"\n" -"path may always be specified as a string.\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception.\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, chown will modify the symbolic link itself instead of the file the\n" -" link points to.\n" -"It is an error to use dir_fd or follow_symlinks when specifying path as\n" -" an open file descriptor.\n" -"dir_fd and follow_symlinks may not be implemented on your platform.\n" -" If they are unavailable, using them will raise a NotImplementedError."); - -#define OS_CHOWN_METHODDEF \ - {"chown", (PyCFunction)os_chown, METH_VARARGS|METH_KEYWORDS, os_chown__doc__}, - -static PyObject * -os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid, int dir_fd, int follow_symlinks); - -static PyObject * -os_chown(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("chown", "path", 0, PATH_HAVE_FCHOWN); +PyDoc_STRVAR(posix_chown__doc__, +"chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n\n\ +Change the owner and group id of path to the numeric uid and gid.\n\ +\n\ +path may always be specified as a string.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception.\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, chown will modify the symbolic link itself instead of the file the\n\ + link points to.\n\ +It is an error to use dir_fd or follow_symlinks when specifying path as\n\ + an open file descriptor.\n\ +dir_fd and follow_symlinks may not be implemented on your platform.\n\ + If they are unavailable, using them will raise a NotImplementedError."); + +static PyObject * +posix_chown(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; uid_t uid; gid_t gid; int dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&O&|$O&p:chown", _keywords, - path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid, FCHOWNAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) - goto exit; - return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_chown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid, int dir_fd, int follow_symlinks) -/*[clinic end generated code: output=22f011e3b4f9ff49 input=a61cc35574814d5d]*/ -{ int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "uid", "gid", "dir_fd", + "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "chown"; +#ifdef HAVE_FCHOWN + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&O&|$O&p:chown", keywords, + path_converter, &path, + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid, +#ifdef HAVE_FCHOWNAT + dir_fd_converter, &dir_fd, +#else + dir_fd_unavailable, &dir_fd, +#endif + &follow_symlinks)) + return NULL; #if !(defined(HAVE_LCHOWN) || defined(HAVE_FCHOWNAT)) if (follow_symlinks_specified("chown", follow_symlinks)) - return NULL; -#endif - if (dir_fd_and_fd_invalid("chown", dir_fd, path->fd) || - fd_and_follow_symlinks_invalid("chown", path->fd, follow_symlinks)) - return NULL; + goto exit; +#endif + if (dir_fd_and_fd_invalid("chown", dir_fd, path.fd) || + fd_and_follow_symlinks_invalid("chown", path.fd, follow_symlinks)) + goto exit; #ifdef __APPLE__ /* @@ -3985,90 +3276,61 @@ */ if ((!follow_symlinks) && (lchown == NULL)) { follow_symlinks_specified("chown", follow_symlinks); - return NULL; + goto exit; } #endif Py_BEGIN_ALLOW_THREADS #ifdef HAVE_FCHOWN - if (path->fd != -1) - result = fchown(path->fd, uid, gid); + if (path.fd != -1) + result = fchown(path.fd, uid, gid); else #endif #ifdef HAVE_LCHOWN if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD)) - result = lchown(path->narrow, uid, gid); + result = lchown(path.narrow, uid, gid); else #endif #ifdef HAVE_FCHOWNAT if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks)) - result = fchownat(dir_fd, path->narrow, uid, gid, + result = fchownat(dir_fd, path.narrow, uid, gid, follow_symlinks ? 0 : AT_SYMLINK_NOFOLLOW); else #endif - result = chown(path->narrow, uid, gid); + result = chown(path.narrow, uid, gid); Py_END_ALLOW_THREADS - if (result) - return path_error(path); - - Py_RETURN_NONE; + if (result) { + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; } #endif /* HAVE_CHOWN */ - #ifdef HAVE_FCHOWN -/*[clinic input] -os.fchown - - fd: int - uid: uid_t - gid: gid_t - -Change the owner and group id of the file specified by file descriptor. - -Equivalent to os.chown(fd, uid, gid). - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fchown__doc__, -"fchown($module, /, fd, uid, gid)\n" -"--\n" -"\n" -"Change the owner and group id of the file specified by file descriptor.\n" -"\n" -"Equivalent to os.chown(fd, uid, gid)."); - -#define OS_FCHOWN_METHODDEF \ - {"fchown", (PyCFunction)os_fchown, METH_VARARGS|METH_KEYWORDS, os_fchown__doc__}, - -static PyObject * -os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid); - -static PyObject * -os_fchown(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", "uid", "gid", NULL}; +PyDoc_STRVAR(posix_fchown__doc__, +"fchown(fd, uid, gid)\n\n\ +Change the owner and group id of the file given by file descriptor\n\ +fd to the numeric uid and gid. Equivalent to os.chown(fd, uid, gid)."); + +static PyObject * +posix_fchown(PyObject *self, PyObject *args) +{ int fd; uid_t uid; gid_t gid; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "iO&O&:fchown", _keywords, - &fd, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) - goto exit; - return_value = os_fchown_impl(module, fd, uid, gid); - -exit: - return return_value; -} - -static PyObject * -os_fchown_impl(PyModuleDef *module, int fd, uid_t uid, gid_t gid) -/*[clinic end generated code: output=687781cb7d8974d6 input=3af544ba1b13a0d7]*/ -{ int res; + if (!PyArg_ParseTuple(args, "iO&O&:fchown", &fd, + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid)) + return NULL; Py_BEGIN_ALLOW_THREADS res = fchown(fd, uid, gid); Py_END_ALLOW_THREADS @@ -4078,70 +3340,38 @@ } #endif /* HAVE_FCHOWN */ - #ifdef HAVE_LCHOWN -/*[clinic input] -os.lchown - - path : path_t - uid: uid_t - gid: gid_t - -Change the owner and group id of path to the numeric uid and gid. - -This function will not follow symbolic links. -Equivalent to os.chown(path, uid, gid, follow_symlinks=False). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lchown__doc__, -"lchown($module, /, path, uid, gid)\n" -"--\n" -"\n" -"Change the owner and group id of path to the numeric uid and gid.\n" -"\n" -"This function will not follow symbolic links.\n" -"Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); - -#define OS_LCHOWN_METHODDEF \ - {"lchown", (PyCFunction)os_lchown, METH_VARARGS|METH_KEYWORDS, os_lchown__doc__}, - -static PyObject * -os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid); - -static PyObject * -os_lchown(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "uid", "gid", NULL}; - path_t path = PATH_T_INITIALIZE("lchown", "path", 0, 0); +PyDoc_STRVAR(posix_lchown__doc__, +"lchown(path, uid, gid)\n\n\ +Change the owner and group id of path to the numeric uid and gid.\n\ +This function will not follow symbolic links.\n\ +Equivalent to os.chown(path, uid, gid, follow_symlinks=False)."); + +static PyObject * +posix_lchown(PyObject *self, PyObject *args) +{ + path_t path; uid_t uid; gid_t gid; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&O&:lchown", _keywords, - path_converter, &path, _Py_Uid_Converter, &uid, _Py_Gid_Converter, &gid)) - goto exit; - return_value = os_lchown_impl(module, &path, uid, gid); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_lchown_impl(PyModuleDef *module, path_t *path, uid_t uid, gid_t gid) -/*[clinic end generated code: output=bf25fdb0d25130e2 input=b1c6014d563a7161]*/ -{ int res; + memset(&path, 0, sizeof(path)); + path.function_name = "lchown"; + if (!PyArg_ParseTuple(args, "O&O&O&:lchown", + path_converter, &path, + _Py_Uid_Converter, &uid, + _Py_Gid_Converter, &gid)) + return NULL; Py_BEGIN_ALLOW_THREADS - res = lchown(path->narrow, uid, gid); + res = lchown(path.narrow, uid, gid); Py_END_ALLOW_THREADS if (res < 0) { - return path_error(path); - } - Py_RETURN_NONE; + path_error(&path); + path_cleanup(&path); + return NULL; + } + path_cleanup(&path); + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_LCHOWN */ @@ -4198,209 +3428,148 @@ return PyUnicode_DecodeFSDefault(buf); } - -/*[clinic input] -os.getcwd - -Return a unicode string representing the current working directory. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getcwd__doc__, -"getcwd($module, /)\n" -"--\n" -"\n" -"Return a unicode string representing the current working directory."); - -#define OS_GETCWD_METHODDEF \ - {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__}, - -static PyObject * -os_getcwd_impl(PyModuleDef *module); - -static PyObject * -os_getcwd(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getcwd_impl(module); -} - -static PyObject * -os_getcwd_impl(PyModuleDef *module) -/*[clinic end generated code: output=d70b281db5c78ff7 input=f069211bb70e3d39]*/ +PyDoc_STRVAR(posix_getcwd__doc__, +"getcwd() -> path\n\n\ +Return a unicode string representing the current working directory."); + +static PyObject * +posix_getcwd_unicode(PyObject *self) { return posix_getcwd(0); } - -/*[clinic input] -os.getcwdb - -Return a bytes string representing the current working directory. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getcwdb__doc__, -"getcwdb($module, /)\n" -"--\n" -"\n" -"Return a bytes string representing the current working directory."); - -#define OS_GETCWDB_METHODDEF \ - {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__}, - -static PyObject * -os_getcwdb_impl(PyModuleDef *module); - -static PyObject * -os_getcwdb(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getcwdb_impl(module); -} - -static PyObject * -os_getcwdb_impl(PyModuleDef *module) -/*[clinic end generated code: output=75da47f2d75f9166 input=f6f6a378dad3d9cb]*/ +PyDoc_STRVAR(posix_getcwdb__doc__, +"getcwdb() -> path\n\n\ +Return a bytes string representing the current working directory."); + +static PyObject * +posix_getcwd_bytes(PyObject *self) { return posix_getcwd(1); } - #if ((!defined(HAVE_LINK)) && defined(MS_WINDOWS)) #define HAVE_LINK 1 #endif #ifdef HAVE_LINK -/*[clinic input] - -os.link - - src : path_t - dst : path_t - * - src_dir_fd : dir_fd = None - dst_dir_fd : dir_fd = None - follow_symlinks: bool = True - -Create a hard link to a file. - -If either src_dir_fd or dst_dir_fd is not None, it should be a file - descriptor open to a directory, and the respective path string (src or dst) - should be relative; the path will then be relative to that directory. -If follow_symlinks is False, and the last element of src is a symbolic - link, link will create a link to the symbolic link itself instead of the - file the link points to. -src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your - platform. If they are unavailable, using them will raise a - NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_link__doc__, -"link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n" -" follow_symlinks=True)\n" -"--\n" -"\n" -"Create a hard link to a file.\n" -"\n" -"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" -" descriptor open to a directory, and the respective path string (src or dst)\n" -" should be relative; the path will then be relative to that directory.\n" -"If follow_symlinks is False, and the last element of src is a symbolic\n" -" link, link will create a link to the symbolic link itself instead of the\n" -" file the link points to.\n" -"src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n" -" platform. If they are unavailable, using them will raise a\n" -" NotImplementedError."); - -#define OS_LINK_METHODDEF \ - {"link", (PyCFunction)os_link, METH_VARARGS|METH_KEYWORDS, os_link__doc__}, - -static PyObject * -os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int follow_symlinks); - -static PyObject * -os_link(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL}; - path_t src = PATH_T_INITIALIZE("link", "src", 0, 0); - path_t dst = PATH_T_INITIALIZE("link", "dst", 0, 0); +PyDoc_STRVAR(posix_link__doc__, +"link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True)\n\n\ +Create a hard link to a file.\n\ +\n\ +If either src_dir_fd or dst_dir_fd is not None, it should be a file\n\ + descriptor open to a directory, and the respective path string (src or dst)\n\ + should be relative; the path will then be relative to that directory.\n\ +If follow_symlinks is False, and the last element of src is a symbolic\n\ + link, link will create a link to the symbolic link itself instead of the\n\ + file the link points to.\n\ +src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n\ + platform. If they are unavailable, using them will raise a\n\ + NotImplementedError."); + +static PyObject * +posix_link(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t src, dst; int src_dir_fd = DEFAULT_DIR_FD; int dst_dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|$O&O&p:link", _keywords, - path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd, &follow_symlinks)) - goto exit; - return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks); - -exit: - /* Cleanup for src */ - path_cleanup(&src); - /* Cleanup for dst */ - path_cleanup(&dst); - - return return_value; -} - -static PyObject * -os_link_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int follow_symlinks) -/*[clinic end generated code: output=53477662fe02e183 input=b0095ebbcbaa7e04]*/ -{ + PyObject *return_value = NULL; + static char *keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", + "follow_symlinks", NULL}; #ifdef MS_WINDOWS BOOL result; #else int result; #endif + memset(&src, 0, sizeof(src)); + memset(&dst, 0, sizeof(dst)); + src.function_name = "link"; + dst.function_name = "link"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|O&O&p:link", keywords, + path_converter, &src, + path_converter, &dst, + dir_fd_converter, &src_dir_fd, + dir_fd_converter, &dst_dir_fd, + &follow_symlinks)) + return NULL; + #ifndef HAVE_LINKAT if ((src_dir_fd != DEFAULT_DIR_FD) || (dst_dir_fd != DEFAULT_DIR_FD)) { argument_unavailable_error("link", "src_dir_fd and dst_dir_fd"); - return NULL; - } -#endif - - if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) { + goto exit; + } +#endif + + if ((src.narrow && dst.wide) || (src.wide && dst.narrow)) { PyErr_SetString(PyExc_NotImplementedError, "link: src and dst must be the same type"); - return NULL; + goto exit; } #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS - if (src->wide) - result = CreateHardLinkW(dst->wide, src->wide, NULL); + if (src.wide) + result = CreateHardLinkW(dst.wide, src.wide, NULL); else - result = CreateHardLinkA(dst->narrow, src->narrow, NULL); + result = CreateHardLinkA(dst.narrow, src.narrow, NULL); Py_END_ALLOW_THREADS - if (!result) - return path_error2(src, dst); + if (!result) { + return_value = path_error2(&src, &dst); + goto exit; + } #else Py_BEGIN_ALLOW_THREADS #ifdef HAVE_LINKAT if ((src_dir_fd != DEFAULT_DIR_FD) || (dst_dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks)) - result = linkat(src_dir_fd, src->narrow, - dst_dir_fd, dst->narrow, + result = linkat(src_dir_fd, src.narrow, + dst_dir_fd, dst.narrow, follow_symlinks ? AT_SYMLINK_FOLLOW : 0); else #endif - result = link(src->narrow, dst->narrow); + result = link(src.narrow, dst.narrow); Py_END_ALLOW_THREADS - if (result) - return path_error2(src, dst); -#endif - - Py_RETURN_NONE; -} -#endif - + if (result) { + return_value = path_error2(&src, &dst); + goto exit; + } +#endif + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&src); + path_cleanup(&dst); + return return_value; +} +#endif + + + +PyDoc_STRVAR(posix_listdir__doc__, +"listdir(path='.') -> list_of_filenames\n\n\ +Return a list containing the names of the files in the directory.\n\ +The list is in arbitrary order. It does not include the special\n\ +entries '.' and '..' even if they are present in the directory.\n\ +\n\ +path can be specified as either str or bytes. If path is bytes,\n\ + the filenames returned will also be bytes; in all other circumstances\n\ + the filenames returned will be str.\n\ +On some platforms, path may also be specified as an open file descriptor;\n\ + the file descriptor must refer to a directory.\n\ + If this functionality is unavailable, using it raises NotImplementedError."); #if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) static PyObject * _listdir_windows_no_opendir(path_t *path, PyObject *list) { + static char *keywords[] = {"path", NULL}; PyObject *v; HANDLE hFindFile = INVALID_HANDLE_VALUE; BOOL result; @@ -4659,85 +3828,38 @@ } /* end of _posix_listdir */ #endif /* which OS */ - -/*[clinic input] -os.listdir - - path : path_t(nullable=True, allow_fd='PATH_HAVE_FDOPENDIR') = None - -Return a list containing the names of the files in the directory. - -path can be specified as either str or bytes. If path is bytes, - the filenames returned will also be bytes; in all other circumstances - the filenames returned will be str. -If path is None, uses the path='.'. -On some platforms, path may also be specified as an open file descriptor;\ - the file descriptor must refer to a directory. - If this functionality is unavailable, using it raises NotImplementedError. - -The list is in arbitrary order. It does not include the special -entries '.' and '..' even if they are present in the directory. - - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_listdir__doc__, -"listdir($module, /, path=None)\n" -"--\n" -"\n" -"Return a list containing the names of the files in the directory.\n" -"\n" -"path can be specified as either str or bytes. If path is bytes,\n" -" the filenames returned will also be bytes; in all other circumstances\n" -" the filenames returned will be str.\n" -"If path is None, uses the path=\'.\'.\n" -"On some platforms, path may also be specified as an open file descriptor;\\\n" -" the file descriptor must refer to a directory.\n" -" If this functionality is unavailable, using it raises NotImplementedError.\n" -"\n" -"The list is in arbitrary order. It does not include the special\n" -"entries \'.\' and \'..\' even if they are present in the directory."); - -#define OS_LISTDIR_METHODDEF \ - {"listdir", (PyCFunction)os_listdir, METH_VARARGS|METH_KEYWORDS, os_listdir__doc__}, - -static PyObject * -os_listdir_impl(PyModuleDef *module, path_t *path); - -static PyObject * -os_listdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - path_t path = PATH_T_INITIALIZE("listdir", "path", 1, PATH_HAVE_FDOPENDIR); - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O&:listdir", _keywords, - path_converter, &path)) - goto exit; - return_value = os_listdir_impl(module, &path); - -exit: - /* Cleanup for path */ +static PyObject * +posix_listdir(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + PyObject *list = NULL; + static char *keywords[] = {"path", NULL}; + PyObject *return_value; + + memset(&path, 0, sizeof(path)); + path.function_name = "listdir"; + path.nullable = 1; +#ifdef HAVE_FDOPENDIR + path.allow_fd = 1; + path.fd = -1; +#endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&:listdir", keywords, + path_converter, &path)) { + return NULL; + } + +#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) + return_value = _listdir_windows_no_opendir(&path, list); +#else + return_value = _posix_listdir(&path, list); +#endif path_cleanup(&path); - return return_value; } -static PyObject * -os_listdir_impl(PyModuleDef *module, path_t *path) -/*[clinic end generated code: output=e159bd9be6909018 input=09e300416e3cd729]*/ -{ -#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR) - return _listdir_windows_no_opendir(path, NULL); -#else - return _posix_listdir(path, NULL); -#endif -} - #ifdef MS_WINDOWS /* A helper function for abspath on win32 */ -/* AC 3.5: probably just convert to using path converter */ static PyObject * posix__getfullpathname(PyObject *self, PyObject *args) { @@ -4793,59 +3915,25 @@ Py_FileSystemDefaultEncoding, NULL); } return PyBytes_FromString(outbuf); -} - - -/*[clinic input] -os._getfinalpathname - - path: unicode - / - -A helper function for samepath on windows. -[clinic start generated code]*/ - -PyDoc_STRVAR(os__getfinalpathname__doc__, -"_getfinalpathname($module, path, /)\n" -"--\n" -"\n" -"A helper function for samepath on windows."); - -#define OS__GETFINALPATHNAME_METHODDEF \ - {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_VARARGS, os__getfinalpathname__doc__}, - -static PyObject * -os__getfinalpathname_impl(PyModuleDef *module, PyObject *path); - -static PyObject * -os__getfinalpathname(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *path; - - if (!PyArg_ParseTuple(args, - "U:_getfinalpathname", - &path)) - goto exit; - return_value = os__getfinalpathname_impl(module, path); - -exit: - return return_value; -} - -static PyObject * -os__getfinalpathname_impl(PyModuleDef *module, PyObject *path) -/*[clinic end generated code: output=4563c6eacf1b0881 input=71d5e89334891bf4]*/ +} /* end of posix__getfullpathname */ + + + +/* A helper function for samepath on windows */ +static PyObject * +posix__getfinalpathname(PyObject *self, PyObject *args) { HANDLE hFile; int buf_size; wchar_t *target_path; int result_length; - PyObject *result; - wchar_t *path_wchar; - - path_wchar = PyUnicode_AsUnicode(path); - if (path_wchar == NULL) + PyObject *po, *result; + wchar_t *path; + + if (!PyArg_ParseTuple(args, "U|:_getfinalpathname", &po)) + return NULL; + path = PyUnicode_AsUnicode(po); + if (path == NULL) return NULL; if(!check_GetFinalPathNameByHandle()) { @@ -4856,7 +3944,7 @@ } hFile = CreateFileW( - path_wchar, + path, 0, /* desired access */ 0, /* share mode */ NULL, /* security attributes */ @@ -4866,14 +3954,14 @@ NULL); if(hFile == INVALID_HANDLE_VALUE) - return win32_error_object("CreateFileW", path); + return win32_error_object("CreateFileW", po); /* We have a good handle to the target, use it to determine the target path name. */ buf_size = Py_GetFinalPathNameByHandleW(hFile, 0, 0, VOLUME_NAME_NT); if(!buf_size) - return win32_error_object("GetFinalPathNameByHandle", path); + return win32_error_object("GetFinalPathNameByHandle", po); target_path = (wchar_t *)PyMem_Malloc((buf_size+1)*sizeof(wchar_t)); if(!target_path) @@ -4882,21 +3970,21 @@ result_length = Py_GetFinalPathNameByHandleW(hFile, target_path, buf_size, VOLUME_NAME_DOS); if(!result_length) - return win32_error_object("GetFinalPathNamyByHandle", path); + return win32_error_object("GetFinalPathNamyByHandle", po); if(!CloseHandle(hFile)) - return win32_error_object("CloseHandle", path); + return win32_error_object("CloseHandle", po); target_path[result_length] = 0; result = PyUnicode_FromWideChar(target_path, result_length); PyMem_Free(target_path); return result; -} + +} /* end of posix__getfinalpathname */ PyDoc_STRVAR(posix__isdir__doc__, "Return true if the pathname refers to an existing directory."); -/* AC 3.5: convert using path converter */ static PyObject * posix__isdir(PyObject *self, PyObject *args) { @@ -4933,55 +4021,22 @@ Py_RETURN_FALSE; } - -/*[clinic input] -os._getvolumepathname - - path: unicode - -A helper function for ismount on Win32. -[clinic start generated code]*/ - -PyDoc_STRVAR(os__getvolumepathname__doc__, -"_getvolumepathname($module, /, path)\n" -"--\n" -"\n" -"A helper function for ismount on Win32."); - -#define OS__GETVOLUMEPATHNAME_METHODDEF \ - {"_getvolumepathname", (PyCFunction)os__getvolumepathname, METH_VARARGS|METH_KEYWORDS, os__getvolumepathname__doc__}, - -static PyObject * -os__getvolumepathname_impl(PyModuleDef *module, PyObject *path); - -static PyObject * -os__getvolumepathname(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - PyObject *path; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "U:_getvolumepathname", _keywords, - &path)) - goto exit; - return_value = os__getvolumepathname_impl(module, path); - -exit: - return return_value; -} - -static PyObject * -os__getvolumepathname_impl(PyModuleDef *module, PyObject *path) -/*[clinic end generated code: output=ac0833b6d6da7657 input=7eacadc40acbda6b]*/ -{ - PyObject *result; - wchar_t *path_wchar, *mountpath=NULL; +PyDoc_STRVAR(posix__getvolumepathname__doc__, +"Return volume mount point of the specified path."); + +/* A helper function for ismount on windows */ +static PyObject * +posix__getvolumepathname(PyObject *self, PyObject *args) +{ + PyObject *po, *result; + wchar_t *path, *mountpath=NULL; size_t buflen; BOOL ret; - path_wchar = PyUnicode_AsUnicodeAndSize(path, &buflen); - if (path_wchar == NULL) + if (!PyArg_ParseTuple(args, "U|:_getvolumepathname", &po)) + return NULL; + path = PyUnicode_AsUnicodeAndSize(po, &buflen); + if (path == NULL) return NULL; buflen += 1; @@ -4998,12 +4053,12 @@ return PyErr_NoMemory(); Py_BEGIN_ALLOW_THREADS - ret = GetVolumePathNameW(path_wchar, mountpath, + ret = GetVolumePathNameW(path, mountpath, Py_SAFE_DOWNCAST(buflen, size_t, DWORD)); Py_END_ALLOW_THREADS if (!ret) { - result = win32_error_object("_getvolumepathname", path); + result = win32_error_object("_getvolumepathname", po); goto exit; } result = PyUnicode_FromWideChar(mountpath, wcslen(mountpath)); @@ -5012,107 +4067,78 @@ PyMem_Free(mountpath); return result; } +/* end of posix__getvolumepathname */ #endif /* MS_WINDOWS */ - -/*[clinic input] -os.mkdir - - path : path_t - - mode: int = 0o777 - - * - - dir_fd : dir_fd(requires='mkdirat') = None - -# "mkdir(path, mode=0o777, *, dir_fd=None)\n\n\ - -Create a directory. - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. - -The mode argument is ignored on Windows. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_mkdir__doc__, -"mkdir($module, /, path, mode=511, *, dir_fd=None)\n" -"--\n" -"\n" -"Create a directory.\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError.\n" -"\n" -"The mode argument is ignored on Windows."); - -#define OS_MKDIR_METHODDEF \ - {"mkdir", (PyCFunction)os_mkdir, METH_VARARGS|METH_KEYWORDS, os_mkdir__doc__}, - -static PyObject * -os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd); - -static PyObject * -os_mkdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ +PyDoc_STRVAR(posix_mkdir__doc__, +"mkdir(path, mode=0o777, *, dir_fd=None)\n\n\ +Create a directory.\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError.\n\ +\n\ +The mode argument is ignored on Windows."); + +static PyObject * +posix_mkdir(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int mode = 0777; + int dir_fd = DEFAULT_DIR_FD; + static char *keywords[] = {"path", "mode", "dir_fd", NULL}; PyObject *return_value = NULL; - static char *_keywords[] = {"path", "mode", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("mkdir", "path", 0, 0); - int mode = 511; - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|i$O&:mkdir", _keywords, - path_converter, &path, &mode, MKDIRAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_mkdir_impl(module, &path, mode, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_mkdir_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd) -/*[clinic end generated code: output=55c6ef2bc1b207e6 input=e965f68377e9b1ce]*/ -{ int result; + memset(&path, 0, sizeof(path)); + path.function_name = "mkdir"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkdir", keywords, + path_converter, &path, &mode, +#ifdef HAVE_MKDIRAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; + #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS - if (path->wide) - result = CreateDirectoryW(path->wide, NULL); + if (path.wide) + result = CreateDirectoryW(path.wide, NULL); else - result = CreateDirectoryA(path->narrow, NULL); + result = CreateDirectoryA(path.narrow, NULL); Py_END_ALLOW_THREADS - if (!result) - return path_error(path); + if (!result) { + return_value = path_error(&path); + goto exit; + } #else Py_BEGIN_ALLOW_THREADS #if HAVE_MKDIRAT if (dir_fd != DEFAULT_DIR_FD) - result = mkdirat(dir_fd, path->narrow, mode); + result = mkdirat(dir_fd, path.narrow, mode); else #endif #if ( defined(__WATCOMC__) || defined(PYCC_VACPP) ) && !defined(__QNX__) - result = mkdir(path->narrow); -#else - result = mkdir(path->narrow, mode); + result = mkdir(path.narrow); +#else + result = mkdir(path.narrow, mode); #endif Py_END_ALLOW_THREADS - if (result < 0) - return path_error(path); -#endif - Py_RETURN_NONE; + if (result < 0) { + return_value = path_error(&path); + goto exit; + } +#endif + return_value = Py_None; + Py_INCREF(Py_None); +exit: + path_cleanup(&path); + return return_value; } @@ -5123,48 +4149,17 @@ #ifdef HAVE_NICE -/*[clinic input] -os.nice - - increment: int - / - -Add increment to the priority of process and return the new priority. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_nice__doc__, -"nice($module, increment, /)\n" -"--\n" -"\n" -"Add increment to the priority of process and return the new priority."); - -#define OS_NICE_METHODDEF \ - {"nice", (PyCFunction)os_nice, METH_VARARGS, os_nice__doc__}, - -static PyObject * -os_nice_impl(PyModuleDef *module, int increment); - -static PyObject * -os_nice(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int increment; - - if (!PyArg_ParseTuple(args, - "i:nice", - &increment)) - goto exit; - return_value = os_nice_impl(module, increment); - -exit: - return return_value; -} - -static PyObject * -os_nice_impl(PyModuleDef *module, int increment) -/*[clinic end generated code: output=c360dc2a3bd8e3d0 input=864be2d402a21da2]*/ -{ - int value; +PyDoc_STRVAR(posix_nice__doc__, +"nice(inc) -> new_priority\n\n\ +Decrease the priority of process by inc and return the new priority."); + +static PyObject * +posix_nice(PyObject *self, PyObject *args) +{ + int increment, value; + + if (!PyArg_ParseTuple(args, "i:nice", &increment)) + return NULL; /* There are two flavours of 'nice': one that returns the new priority (as required by almost all standards out there) and the @@ -5191,51 +4186,17 @@ #ifdef HAVE_GETPRIORITY -/*[clinic input] -os.getpriority - - which: int - who: int - -Return program scheduling priority. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getpriority__doc__, -"getpriority($module, /, which, who)\n" -"--\n" -"\n" -"Return program scheduling priority."); - -#define OS_GETPRIORITY_METHODDEF \ - {"getpriority", (PyCFunction)os_getpriority, METH_VARARGS|METH_KEYWORDS, os_getpriority__doc__}, - -static PyObject * -os_getpriority_impl(PyModuleDef *module, int which, int who); - -static PyObject * -os_getpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"which", "who", NULL}; - int which; - int who; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ii:getpriority", _keywords, - &which, &who)) - goto exit; - return_value = os_getpriority_impl(module, which, who); - -exit: - return return_value; -} - -static PyObject * -os_getpriority_impl(PyModuleDef *module, int which, int who) -/*[clinic end generated code: output=81639cf765f05dae input=9be615d40e2544ef]*/ -{ - int retval; - +PyDoc_STRVAR(posix_getpriority__doc__, +"getpriority(which, who) -> current_priority\n\n\ +Get program scheduling priority."); + +static PyObject * +posix_getpriority(PyObject *self, PyObject *args) +{ + int which, who, retval; + + if (!PyArg_ParseTuple(args, "ii", &which, &who)) + return NULL; errno = 0; retval = getpriority(which, who); if (errno != 0) @@ -5246,66 +4207,37 @@ #ifdef HAVE_SETPRIORITY -/*[clinic input] -os.setpriority - - which: int - who: int - priority: int - -Set program scheduling priority. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setpriority__doc__, -"setpriority($module, /, which, who, priority)\n" -"--\n" -"\n" -"Set program scheduling priority."); - -#define OS_SETPRIORITY_METHODDEF \ - {"setpriority", (PyCFunction)os_setpriority, METH_VARARGS|METH_KEYWORDS, os_setpriority__doc__}, - -static PyObject * -os_setpriority_impl(PyModuleDef *module, int which, int who, int priority); - -static PyObject * -os_setpriority(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ +PyDoc_STRVAR(posix_setpriority__doc__, +"setpriority(which, who, prio) -> None\n\n\ +Set program scheduling priority."); + +static PyObject * +posix_setpriority(PyObject *self, PyObject *args) +{ + int which, who, prio, retval; + + if (!PyArg_ParseTuple(args, "iii", &which, &who, &prio)) + return NULL; + retval = setpriority(which, who, prio); + if (retval == -1) + return posix_error(); + Py_RETURN_NONE; +} +#endif /* HAVE_SETPRIORITY */ + + +static PyObject * +internal_rename(PyObject *args, PyObject *kwargs, int is_replace) +{ + char *function_name = is_replace ? "replace" : "rename"; + path_t src; + path_t dst; + int src_dir_fd = DEFAULT_DIR_FD; + int dst_dir_fd = DEFAULT_DIR_FD; + int dir_fd_specified; PyObject *return_value = NULL; - static char *_keywords[] = {"which", "who", "priority", NULL}; - int which; - int who; - int priority; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "iii:setpriority", _keywords, - &which, &who, &priority)) - goto exit; - return_value = os_setpriority_impl(module, which, who, priority); - -exit: - return return_value; -} - -static PyObject * -os_setpriority_impl(PyModuleDef *module, int which, int who, int priority) -/*[clinic end generated code: output=ddad62651fb2120c input=710ccbf65b9dc513]*/ -{ - int retval; - - retval = setpriority(which, who, priority); - if (retval == -1) - return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_SETPRIORITY */ - - -static PyObject * -internal_rename(path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd, int is_replace) -{ - char *function_name = is_replace ? "replace" : "rename"; - int dir_fd_specified; + char format[24]; + static char *keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; #ifdef MS_WINDOWS BOOL result; @@ -5314,419 +4246,210 @@ int result; #endif + memset(&src, 0, sizeof(src)); + memset(&dst, 0, sizeof(dst)); + src.function_name = function_name; + dst.function_name = function_name; + strcpy(format, "O&O&|$O&O&:"); + strcat(format, function_name); + if (!PyArg_ParseTupleAndKeywords(args, kwargs, format, keywords, + path_converter, &src, + path_converter, &dst, + dir_fd_converter, &src_dir_fd, + dir_fd_converter, &dst_dir_fd)) + return NULL; + dir_fd_specified = (src_dir_fd != DEFAULT_DIR_FD) || (dst_dir_fd != DEFAULT_DIR_FD); #ifndef HAVE_RENAMEAT if (dir_fd_specified) { argument_unavailable_error(function_name, "src_dir_fd and dst_dir_fd"); - return NULL; - } -#endif - - if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) { + goto exit; + } +#endif + + if ((src.narrow && dst.wide) || (src.wide && dst.narrow)) { PyErr_Format(PyExc_ValueError, "%s: src and dst must be the same type", function_name); - return NULL; + goto exit; } #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS - if (src->wide) - result = MoveFileExW(src->wide, dst->wide, flags); + if (src.wide) + result = MoveFileExW(src.wide, dst.wide, flags); else - result = MoveFileExA(src->narrow, dst->narrow, flags); + result = MoveFileExA(src.narrow, dst.narrow, flags); Py_END_ALLOW_THREADS - if (!result) - return path_error2(src, dst); + if (!result) { + return_value = path_error2(&src, &dst); + goto exit; + } #else Py_BEGIN_ALLOW_THREADS #ifdef HAVE_RENAMEAT if (dir_fd_specified) - result = renameat(src_dir_fd, src->narrow, dst_dir_fd, dst->narrow); + result = renameat(src_dir_fd, src.narrow, dst_dir_fd, dst.narrow); else #endif - result = rename(src->narrow, dst->narrow); + result = rename(src.narrow, dst.narrow); Py_END_ALLOW_THREADS - if (result) - return path_error2(src, dst); -#endif - Py_RETURN_NONE; -} - - -/*[clinic input] -os.rename - - src : path_t - dst : path_t - * - src_dir_fd : dir_fd = None - dst_dir_fd : dir_fd = None - -Rename a file or directory. - -If either src_dir_fd or dst_dir_fd is not None, it should be a file - descriptor open to a directory, and the respective path string (src or dst) - should be relative; the path will then be relative to that directory. -src_dir_fd and dst_dir_fd, may not be implemented on your platform. - If they are unavailable, using them will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_rename__doc__, -"rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" -"--\n" -"\n" -"Rename a file or directory.\n" -"\n" -"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" -" descriptor open to a directory, and the respective path string (src or dst)\n" -" should be relative; the path will then be relative to that directory.\n" -"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" -" If they are unavailable, using them will raise a NotImplementedError."); - -#define OS_RENAME_METHODDEF \ - {"rename", (PyCFunction)os_rename, METH_VARARGS|METH_KEYWORDS, os_rename__doc__}, - -static PyObject * -os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd); - -static PyObject * -os_rename(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ + if (result) { + return_value = path_error2(&src, &dst); + goto exit; + } +#endif + + Py_INCREF(Py_None); + return_value = Py_None; +exit: + path_cleanup(&src); + path_cleanup(&dst); + return return_value; +} + +PyDoc_STRVAR(posix_rename__doc__, +"rename(src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n\n\ +Rename a file or directory.\n\ +\n\ +If either src_dir_fd or dst_dir_fd is not None, it should be a file\n\ + descriptor open to a directory, and the respective path string (src or dst)\n\ + should be relative; the path will then be relative to that directory.\n\ +src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n\ + If they are unavailable, using them will raise a NotImplementedError."); + +static PyObject * +posix_rename(PyObject *self, PyObject *args, PyObject *kwargs) +{ + return internal_rename(args, kwargs, 0); +} + +PyDoc_STRVAR(posix_replace__doc__, +"replace(src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n\n\ +Rename a file or directory, overwriting the destination.\n\ +\n\ +If either src_dir_fd or dst_dir_fd is not None, it should be a file\n\ + descriptor open to a directory, and the respective path string (src or dst)\n\ + should be relative; the path will then be relative to that directory.\n\ +src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n\ + If they are unavailable, using them will raise a NotImplementedError."); + +static PyObject * +posix_replace(PyObject *self, PyObject *args, PyObject *kwargs) +{ + return internal_rename(args, kwargs, 1); +} + +PyDoc_STRVAR(posix_rmdir__doc__, +"rmdir(path, *, dir_fd=None)\n\n\ +Remove a directory.\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +static PyObject * +posix_rmdir(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int dir_fd = DEFAULT_DIR_FD; + static char *keywords[] = {"path", "dir_fd", NULL}; + int result; PyObject *return_value = NULL; - static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; - path_t src = PATH_T_INITIALIZE("rename", "src", 0, 0); - path_t dst = PATH_T_INITIALIZE("rename", "dst", 0, 0); - int src_dir_fd = DEFAULT_DIR_FD; - int dst_dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|$O&O&:rename", _keywords, - path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) - goto exit; - return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); - -exit: - /* Cleanup for src */ - path_cleanup(&src); - /* Cleanup for dst */ - path_cleanup(&dst); - - return return_value; -} - -static PyObject * -os_rename_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd) -/*[clinic end generated code: output=c936bdc81f460a1e input=faa61c847912c850]*/ -{ - return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 0); -} - - -/*[clinic input] -os.replace = os.rename - -Rename a file or directory, overwriting the destination. - -If either src_dir_fd or dst_dir_fd is not None, it should be a file - descriptor open to a directory, and the respective path string (src or dst) - should be relative; the path will then be relative to that directory. -src_dir_fd and dst_dir_fd, may not be implemented on your platform. - If they are unavailable, using them will raise a NotImplementedError." -[clinic start generated code]*/ - -PyDoc_STRVAR(os_replace__doc__, -"replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n" -"--\n" -"\n" -"Rename a file or directory, overwriting the destination.\n" -"\n" -"If either src_dir_fd or dst_dir_fd is not None, it should be a file\n" -" descriptor open to a directory, and the respective path string (src or dst)\n" -" should be relative; the path will then be relative to that directory.\n" -"src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n" -" If they are unavailable, using them will raise a NotImplementedError.\""); - -#define OS_REPLACE_METHODDEF \ - {"replace", (PyCFunction)os_replace, METH_VARARGS|METH_KEYWORDS, os_replace__doc__}, - -static PyObject * -os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd); - -static PyObject * -os_replace(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL}; - path_t src = PATH_T_INITIALIZE("replace", "src", 0, 0); - path_t dst = PATH_T_INITIALIZE("replace", "dst", 0, 0); - int src_dir_fd = DEFAULT_DIR_FD; - int dst_dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|$O&O&:replace", _keywords, - path_converter, &src, path_converter, &dst, dir_fd_converter, &src_dir_fd, dir_fd_converter, &dst_dir_fd)) - goto exit; - return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd); - -exit: - /* Cleanup for src */ - path_cleanup(&src); - /* Cleanup for dst */ - path_cleanup(&dst); - - return return_value; -} - -static PyObject * -os_replace_impl(PyModuleDef *module, path_t *src, path_t *dst, int src_dir_fd, int dst_dir_fd) -/*[clinic end generated code: output=224e4710d290d171 input=25515dfb107c8421]*/ -{ - return internal_rename(src, dst, src_dir_fd, dst_dir_fd, 1); -} - - -/*[clinic input] -os.rmdir - - path: path_t - * - dir_fd: dir_fd(requires='unlinkat') = None - -Remove a directory. - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_rmdir__doc__, -"rmdir($module, /, path, *, dir_fd=None)\n" -"--\n" -"\n" -"Remove a directory.\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_RMDIR_METHODDEF \ - {"rmdir", (PyCFunction)os_rmdir, METH_VARARGS|METH_KEYWORDS, os_rmdir__doc__}, - -static PyObject * -os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd); - -static PyObject * -os_rmdir(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("rmdir", "path", 0, 0); - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|$O&:rmdir", _keywords, - path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_rmdir_impl(module, &path, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_rmdir_impl(PyModuleDef *module, path_t *path, int dir_fd) -/*[clinic end generated code: output=70b9fdbe3bee0591 input=38c8b375ca34a7e2]*/ -{ - int result; + + memset(&path, 0, sizeof(path)); + path.function_name = "rmdir"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:rmdir", keywords, + path_converter, &path, +#ifdef HAVE_UNLINKAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - if (path->wide) - result = RemoveDirectoryW(path->wide); + if (path.wide) + result = RemoveDirectoryW(path.wide); else - result = RemoveDirectoryA(path->narrow); + result = RemoveDirectoryA(path.narrow); result = !result; /* Windows, success=1, UNIX, success=0 */ #else #ifdef HAVE_UNLINKAT if (dir_fd != DEFAULT_DIR_FD) - result = unlinkat(dir_fd, path->narrow, AT_REMOVEDIR); + result = unlinkat(dir_fd, path.narrow, AT_REMOVEDIR); else #endif - result = rmdir(path->narrow); + result = rmdir(path.narrow); #endif Py_END_ALLOW_THREADS - if (result) - return path_error(path); - - Py_RETURN_NONE; + if (result) { + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; } #ifdef HAVE_SYSTEM +PyDoc_STRVAR(posix_system__doc__, +"system(command) -> exit_status\n\n\ +Execute the command (a string) in a subshell."); + +static PyObject * +posix_system(PyObject *self, PyObject *args) +{ + long sts; #ifdef MS_WINDOWS -/*[clinic input] -os.system -> long - - command: Py_UNICODE - -Execute the command in a subshell. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_system__doc__, -"system($module, /, command)\n" -"--\n" -"\n" -"Execute the command in a subshell."); - -#define OS_SYSTEM_METHODDEF \ - {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__}, - -static long -os_system_impl(PyModuleDef *module, Py_UNICODE *command); - -static PyObject * -os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"command", NULL}; - Py_UNICODE *command; - long _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "u:system", _keywords, - &command)) - goto exit; - _return_value = os_system_impl(module, command); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong(_return_value); - -exit: - return return_value; -} - -static long -os_system_impl(PyModuleDef *module, Py_UNICODE *command) -/*[clinic end generated code: output=29fe699c0b2e9d38 input=303f5ce97df606b0]*/ -{ - long result; + wchar_t *command; + if (!PyArg_ParseTuple(args, "u:system", &command)) + return NULL; + Py_BEGIN_ALLOW_THREADS - result = _wsystem(command); + sts = _wsystem(command); Py_END_ALLOW_THREADS - return result; -} -#else /* MS_WINDOWS */ -/*[clinic input] -os.system -> long - - command: FSConverter - -Execute the command in a subshell. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_system__doc__, -"system($module, /, command)\n" -"--\n" -"\n" -"Execute the command in a subshell."); - -#define OS_SYSTEM_METHODDEF \ - {"system", (PyCFunction)os_system, METH_VARARGS|METH_KEYWORDS, os_system__doc__}, - -static long -os_system_impl(PyModuleDef *module, PyObject *command); - -static PyObject * -os_system(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"command", NULL}; - PyObject *command = NULL; - long _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:system", _keywords, - PyUnicode_FSConverter, &command)) - goto exit; - _return_value = os_system_impl(module, command); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong(_return_value); - -exit: - /* Cleanup for command */ - Py_XDECREF(command); - - return return_value; -} - -static long -os_system_impl(PyModuleDef *module, PyObject *command) -/*[clinic end generated code: output=5be9f3c40ead3bad input=86a58554ba6094af]*/ -{ - long result; - char *bytes = PyBytes_AsString(command); +#else + PyObject *command_obj; + char *command; + if (!PyArg_ParseTuple(args, "O&:system", + PyUnicode_FSConverter, &command_obj)) + return NULL; + + command = PyBytes_AsString(command_obj); Py_BEGIN_ALLOW_THREADS - result = system(bytes); + sts = system(command); Py_END_ALLOW_THREADS - return result; -} -#endif -#endif /* HAVE_SYSTEM */ - - -/*[clinic input] -os.umask - - mask: int - / - -Set the current numeric umask and return the previous umask. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_umask__doc__, -"umask($module, mask, /)\n" -"--\n" -"\n" -"Set the current numeric umask and return the previous umask."); - -#define OS_UMASK_METHODDEF \ - {"umask", (PyCFunction)os_umask, METH_VARARGS, os_umask__doc__}, - -static PyObject * -os_umask_impl(PyModuleDef *module, int mask); - -static PyObject * -os_umask(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int mask; - - if (!PyArg_ParseTuple(args, - "i:umask", - &mask)) - goto exit; - return_value = os_umask_impl(module, mask); - -exit: - return return_value; -} - -static PyObject * -os_umask_impl(PyModuleDef *module, int mask) -/*[clinic end generated code: output=90048b39d2d4a961 input=ab6bfd9b24d8a7e8]*/ -{ - int i = (int)umask(mask); + Py_DECREF(command_obj); +#endif + return PyLong_FromLong(sts); +} +#endif + + +PyDoc_STRVAR(posix_umask__doc__, +"umask(new_mask) -> old_mask\n\n\ +Set the current numeric umask and return the previous umask."); + +static PyObject * +posix_umask(PyObject *self, PyObject *args) +{ + int i; + if (!PyArg_ParseTuple(args, "i:umask", &i)) + return NULL; + i = (int)umask(i); if (i < 0) return posix_error(); return PyLong_FromLong((long)i); @@ -5771,147 +4494,81 @@ } #endif /* MS_WINDOWS */ - -/*[clinic input] -os.unlink - - path: path_t - * - dir_fd: dir_fd(requires='unlinkat')=None - -Remove a file (same as remove()). - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_unlink__doc__, -"unlink($module, /, path, *, dir_fd=None)\n" -"--\n" -"\n" -"Remove a file (same as remove()).\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_UNLINK_METHODDEF \ - {"unlink", (PyCFunction)os_unlink, METH_VARARGS|METH_KEYWORDS, os_unlink__doc__}, - -static PyObject * -os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd); - -static PyObject * -os_unlink(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ +PyDoc_STRVAR(posix_unlink__doc__, +"unlink(path, *, dir_fd=None)\n\n\ +Remove a file (same as remove()).\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +PyDoc_STRVAR(posix_remove__doc__, +"remove(path, *, dir_fd=None)\n\n\ +Remove a file (same as unlink()).\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +static PyObject * +posix_unlink(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int dir_fd = DEFAULT_DIR_FD; + static char *keywords[] = {"path", "dir_fd", NULL}; + int result; PyObject *return_value = NULL; - static char *_keywords[] = {"path", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("unlink", "path", 0, 0); - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|$O&:unlink", _keywords, - path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_unlink_impl(module, &path, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_unlink_impl(PyModuleDef *module, path_t *path, int dir_fd) -/*[clinic end generated code: output=59a6e66d67ff2e75 input=d7bcde2b1b2a2552]*/ -{ - int result; + + memset(&path, 0, sizeof(path)); + path.function_name = "unlink"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:unlink", keywords, + path_converter, &path, +#ifdef HAVE_UNLINKAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - if (path->wide) - result = Py_DeleteFileW(path->wide); + if (path.wide) + result = Py_DeleteFileW(path.wide); else - result = DeleteFileA(path->narrow); + result = DeleteFileA(path.narrow); result = !result; /* Windows, success=1, UNIX, success=0 */ #else #ifdef HAVE_UNLINKAT if (dir_fd != DEFAULT_DIR_FD) - result = unlinkat(dir_fd, path->narrow, 0); + result = unlinkat(dir_fd, path.narrow, 0); else #endif /* HAVE_UNLINKAT */ - result = unlink(path->narrow); + result = unlink(path.narrow); #endif Py_END_ALLOW_THREADS - if (result) - return path_error(path); - - Py_RETURN_NONE; -} - - -/*[clinic input] -os.remove = os.unlink - -Remove a file (same as unlink()). - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_remove__doc__, -"remove($module, /, path, *, dir_fd=None)\n" -"--\n" -"\n" -"Remove a file (same as unlink()).\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_REMOVE_METHODDEF \ - {"remove", (PyCFunction)os_remove, METH_VARARGS|METH_KEYWORDS, os_remove__doc__}, - -static PyObject * -os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd); - -static PyObject * -os_remove(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("remove", "path", 0, 0); - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|$O&:remove", _keywords, - path_converter, &path, UNLINKAT_DIR_FD_CONVERTER, &dir_fd)) + if (result) { + return_value = path_error(&path); goto exit; - return_value = os_remove_impl(module, &path, dir_fd); + } + + return_value = Py_None; + Py_INCREF(Py_None); exit: - /* Cleanup for path */ path_cleanup(&path); - return return_value; } -static PyObject * -os_remove_impl(PyModuleDef *module, path_t *path, int dir_fd) -/*[clinic end generated code: output=cb170cf1e195b8ed input=e05c5ab55cd30983]*/ -{ - return os_unlink_impl(module, path, dir_fd); -} - + +PyDoc_STRVAR(posix_uname__doc__, +"uname() -> uname_result\n\n\ +Return an object identifying the current operating system.\n\ +The object behaves like a named tuple with the following fields:\n\ + (sysname, nodename, release, version, machine)"); static PyStructSequence_Field uname_result_fields[] = { {"sysname", "operating system name"}, @@ -5941,40 +4598,8 @@ #ifdef HAVE_UNAME -/*[clinic input] -os.uname - -Return an object identifying the current operating system. - -The object behaves like a named tuple with the following fields: - (sysname, nodename, release, version, machine) - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_uname__doc__, -"uname($module, /)\n" -"--\n" -"\n" -"Return an object identifying the current operating system.\n" -"\n" -"The object behaves like a named tuple with the following fields:\n" -" (sysname, nodename, release, version, machine)"); - -#define OS_UNAME_METHODDEF \ - {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__}, - -static PyObject * -os_uname_impl(PyModuleDef *module); - -static PyObject * -os_uname(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_uname_impl(module); -} - -static PyObject * -os_uname_impl(PyModuleDef *module) -/*[clinic end generated code: output=459a86521ff5041c input=e68bd246db3043ed]*/ +static PyObject * +posix_uname(PyObject *self, PyObject *noargs) { struct utsname u; int res; @@ -6013,6 +4638,31 @@ #endif /* HAVE_UNAME */ +PyDoc_STRVAR(posix_utime__doc__, +"utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)\n\ +Set the access and modified time of path.\n\ +\n\ +path may always be specified as a string.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception.\n\ +\n\ +If times is not None, it must be a tuple (atime, mtime);\n\ + atime and mtime should be expressed as float seconds since the epoch.\n\ +If ns is not None, it must be a tuple (atime_ns, mtime_ns);\n\ + atime_ns and mtime_ns should be expressed as integer nanoseconds\n\ + since the epoch.\n\ +If both times and ns are None, utime uses the current time.\n\ +Specifying tuples for both times and ns is an error.\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, utime will modify the symbolic link itself instead of the file the\n\ + link points to.\n\ +It is an error to use dir_fd or follow_symlinks when specifying path\n\ + as an open file descriptor.\n\ +dir_fd and follow_symlinks may not be available on your platform.\n\ + If they are unavailable, using them will raise a NotImplementedError."); typedef struct { int now; @@ -6098,9 +4748,6 @@ #endif } - #define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_converter -#else - #define FUTIMENSAT_DIR_FD_CONVERTER dir_fd_unavailable #endif #define UTIME_HAVE_FD (defined(HAVE_FUTIMES) || defined(HAVE_FUTIMENS)) @@ -6119,9 +4766,6 @@ #endif } - #define PATH_UTIME_HAVE_FD 1 -#else - #define PATH_UTIME_HAVE_FD 0 #endif @@ -6187,108 +4831,19 @@ return result; } - -/*[clinic input] -os.utime - - path: path_t(allow_fd='PATH_UTIME_HAVE_FD') - times: object = NULL - * - ns: object = NULL - dir_fd: dir_fd(requires='futimensat') = None - follow_symlinks: bool=True - -# "utime(path, times=None, *, ns=None, dir_fd=None, follow_symlinks=True)\n\ - -Set the access and modified time of path. - -path may always be specified as a string. -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. - -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); - 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. -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, - and path should be relative; path will then be relative to that directory. -If follow_symlinks is False, and the last element of the path is a symbolic - link, utime will modify the symbolic link itself instead of the file the - link points to. -It is an error to use dir_fd or follow_symlinks when specifying path - as an open file descriptor. -dir_fd and follow_symlinks may not be available on your platform. - If they are unavailable, using them will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_utime__doc__, -"utime($module, /, path, times=None, *, ns=None, dir_fd=None,\n" -" follow_symlinks=True)\n" -"--\n" -"\n" -"Set the access and modified time of path.\n" -"\n" -"path may always be specified as a string.\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception.\n" -"\n" -"If times is not None, it must be a tuple (atime, mtime);\n" -" atime and mtime should be expressed as float seconds since the epoch.\n" -"If ns is not None, it must be a tuple (atime_ns, mtime_ns);\n" -" atime_ns and mtime_ns should be expressed as integer nanoseconds\n" -" since the epoch.\n" -"If both times and ns are None, utime uses the current time.\n" -"Specifying tuples for both times and ns is an error.\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, utime will modify the symbolic link itself instead of the file the\n" -" link points to.\n" -"It is an error to use dir_fd or follow_symlinks when specifying path\n" -" as an open file descriptor.\n" -"dir_fd and follow_symlinks may not be available on your platform.\n" -" If they are unavailable, using them will raise a NotImplementedError."); - -#define OS_UTIME_METHODDEF \ - {"utime", (PyCFunction)os_utime, METH_VARARGS|METH_KEYWORDS, os_utime__doc__}, - -static PyObject * -os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times, PyObject *ns, int dir_fd, int follow_symlinks); - -static PyObject * -os_utime(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("utime", "path", 0, PATH_UTIME_HAVE_FD); +static PyObject * +posix_utime(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; PyObject *times = NULL; PyObject *ns = NULL; int dir_fd = DEFAULT_DIR_FD; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|O$OO&p:utime", _keywords, - path_converter, &path, ×, &ns, FUTIMENSAT_DIR_FD_CONVERTER, &dir_fd, &follow_symlinks)) - goto exit; - return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_utime_impl(PyModuleDef *module, path_t *path, PyObject *times, PyObject *ns, int dir_fd, int follow_symlinks) -/*[clinic end generated code: output=891489c35cc68c5d input=1f18c17d5941aa82]*/ -{ + char *keywords[] = {"path", "times", "ns", "dir_fd", + "follow_symlinks", NULL}; + + utime_t utime; + #ifdef MS_WINDOWS HANDLE hFile; FILETIME atime, mtime; @@ -6297,9 +4852,25 @@ #endif PyObject *return_value = NULL; - utime_t utime; - + + memset(&path, 0, sizeof(path)); + path.function_name = "utime"; memset(&utime, 0, sizeof(utime_t)); +#if UTIME_HAVE_FD + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O&|O$OO&p:utime", keywords, + path_converter, &path, + ×, &ns, +#if UTIME_HAVE_DIR_FD + dir_fd_converter, &dir_fd, +#else + dir_fd_unavailable, &dir_fd, +#endif + &follow_symlinks + )) + return NULL; if (times && (times != Py_None) && ns) { PyErr_SetString(PyExc_ValueError, @@ -6353,9 +4924,9 @@ goto exit; #endif - if (path_and_dir_fd_invalid("utime", path, dir_fd) || - dir_fd_and_fd_invalid("utime", dir_fd, path->fd) || - fd_and_follow_symlinks_invalid("utime", path->fd, follow_symlinks)) + if (path_and_dir_fd_invalid("utime", &path, dir_fd) || + dir_fd_and_fd_invalid("utime", dir_fd, path.fd) || + fd_and_follow_symlinks_invalid("utime", path.fd, follow_symlinks)) goto exit; #if !defined(HAVE_UTIMENSAT) @@ -6369,17 +4940,17 @@ #ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS - if (path->wide) - hFile = CreateFileW(path->wide, FILE_WRITE_ATTRIBUTES, 0, + if (path.wide) + hFile = CreateFileW(path.wide, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); else - hFile = CreateFileA(path->narrow, FILE_WRITE_ATTRIBUTES, 0, + hFile = CreateFileA(path.narrow, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); Py_END_ALLOW_THREADS if (hFile == INVALID_HANDLE_VALUE) { - path_error(path); + path_error(&path); goto exit; } @@ -6404,23 +4975,23 @@ #if UTIME_HAVE_NOFOLLOW_SYMLINKS if ((!follow_symlinks) && (dir_fd == DEFAULT_DIR_FD)) - result = utime_nofollow_symlinks(&utime, path->narrow); + result = utime_nofollow_symlinks(&utime, path.narrow); else #endif #if UTIME_HAVE_DIR_FD if ((dir_fd != DEFAULT_DIR_FD) || (!follow_symlinks)) - result = utime_dir_fd(&utime, dir_fd, path->narrow, follow_symlinks); + result = utime_dir_fd(&utime, dir_fd, path.narrow, follow_symlinks); else #endif #if UTIME_HAVE_FD - if (path->fd != -1) - result = utime_fd(&utime, path->fd); + if (path.fd != -1) + result = utime_fd(&utime, path.fd); else #endif - result = utime_default(&utime, path->narrow); + result = utime_default(&utime, path.narrow); Py_END_ALLOW_THREADS @@ -6436,6 +5007,7 @@ return_value = Py_None; exit: + path_cleanup(&path); #ifdef MS_WINDOWS if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); @@ -6445,49 +5017,17 @@ /* Process operations */ - -/*[clinic input] -os._exit - - status: int - -Exit to the system with specified status, without normal exit processing. -[clinic start generated code]*/ - -PyDoc_STRVAR(os__exit__doc__, -"_exit($module, /, status)\n" -"--\n" -"\n" -"Exit to the system with specified status, without normal exit processing."); - -#define OS__EXIT_METHODDEF \ - {"_exit", (PyCFunction)os__exit, METH_VARARGS|METH_KEYWORDS, os__exit__doc__}, - -static PyObject * -os__exit_impl(PyModuleDef *module, int status); - -static PyObject * -os__exit(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:_exit", _keywords, - &status)) - goto exit; - return_value = os__exit_impl(module, status); - -exit: - return return_value; -} - -static PyObject * -os__exit_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=4f9858c4cc2dcb89 input=5e6d57556b0c4a62]*/ -{ - _exit(status); +PyDoc_STRVAR(posix__exit__doc__, +"_exit(status)\n\n\ +Exit to the system with specified status, without normal exit processing."); + +static PyObject * +posix__exit(PyObject *self, PyObject *args) +{ + int sts; + if (!PyArg_ParseTuple(args, "i:_exit", &sts)) + return NULL; + _exit(sts); return NULL; /* Make gcc -Wall happy */ } @@ -6625,160 +5165,96 @@ } #endif - #ifdef HAVE_EXECV -/*[clinic input] -os.execv - - path: FSConverter - Path of executable file. - argv: object - Tuple or list of strings. - / - -Execute an executable path with arguments, replacing current process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_execv__doc__, -"execv($module, path, argv, /)\n" -"--\n" -"\n" -"Execute an executable path with arguments, replacing current process.\n" -"\n" -" path\n" -" Path of executable file.\n" -" argv\n" -" Tuple or list of strings."); - -#define OS_EXECV_METHODDEF \ - {"execv", (PyCFunction)os_execv, METH_VARARGS, os_execv__doc__}, - -static PyObject * -os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv); - -static PyObject * -os_execv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *path = NULL; +PyDoc_STRVAR(posix_execv__doc__, +"execv(path, args)\n\n\ +Execute an executable path with arguments, replacing current process.\n\ +\n\ + path: path of executable file\n\ + args: tuple or list of strings"); + +static PyObject * +posix_execv(PyObject *self, PyObject *args) +{ + PyObject *opath; + char *path; PyObject *argv; - - if (!PyArg_ParseTuple(args, - "O&O:execv", - PyUnicode_FSConverter, &path, &argv)) - goto exit; - return_value = os_execv_impl(module, path, argv); - -exit: - /* Cleanup for path */ - Py_XDECREF(path); - - return return_value; -} - -static PyObject * -os_execv_impl(PyModuleDef *module, PyObject *path, PyObject *argv) -/*[clinic end generated code: output=b0f5f2caa6097edc input=96041559925e5229]*/ -{ - char *path_char; char **argvlist; Py_ssize_t argc; /* execv has two arguments: (path, argv), where argv is a list or tuple of strings. */ - path_char = PyBytes_AsString(path); + if (!PyArg_ParseTuple(args, "O&O:execv", + PyUnicode_FSConverter, + &opath, &argv)) + return NULL; + path = PyBytes_AsString(opath); if (!PyList_Check(argv) && !PyTuple_Check(argv)) { PyErr_SetString(PyExc_TypeError, "execv() arg 2 must be a tuple or list"); + Py_DECREF(opath); return NULL; } argc = PySequence_Size(argv); if (argc < 1) { PyErr_SetString(PyExc_ValueError, "execv() arg 2 must not be empty"); + Py_DECREF(opath); return NULL; } argvlist = parse_arglist(argv, &argc); if (argvlist == NULL) { - return NULL; - } - - execv(path_char, argvlist); + Py_DECREF(opath); + return NULL; + } + + execv(path, argvlist); /* If we get here it's definitely an error */ free_string_array(argvlist, argc); + Py_DECREF(opath); return posix_error(); } - -/*[clinic input] -os.execve - - path: path_t(allow_fd='PATH_HAVE_FEXECVE') - Path of executable file. - argv: object - Tuple or list of strings. - env: object - Dictionary of strings mapping to strings. - -Execute an executable path with arguments, replacing current process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_execve__doc__, -"execve($module, /, path, argv, env)\n" -"--\n" -"\n" -"Execute an executable path with arguments, replacing current process.\n" -"\n" -" path\n" -" Path of executable file.\n" -" argv\n" -" Tuple or list of strings.\n" -" env\n" -" Dictionary of strings mapping to strings."); - -#define OS_EXECVE_METHODDEF \ - {"execve", (PyCFunction)os_execve, METH_VARARGS|METH_KEYWORDS, os_execve__doc__}, - -static PyObject * -os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv, PyObject *env); - -static PyObject * -os_execve(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "argv", "env", NULL}; - path_t path = PATH_T_INITIALIZE("execve", "path", 0, PATH_HAVE_FEXECVE); - PyObject *argv; - PyObject *env; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&OO:execve", _keywords, - path_converter, &path, &argv, &env)) - goto exit; - return_value = os_execve_impl(module, &path, argv, env); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_execve_impl(PyModuleDef *module, path_t *path, PyObject *argv, PyObject *env) -/*[clinic end generated code: output=fb283760f5d15ab7 input=626804fa092606d9]*/ -{ +PyDoc_STRVAR(posix_execve__doc__, +"execve(path, args, env)\n\n\ +Execute a path with arguments and environment, replacing current process.\n\ +\n\ + path: path of executable file\n\ + args: tuple or list of arguments\n\ + env: dictionary of strings mapping to strings\n\ +\n\ +On some platforms, you may specify an open file descriptor for path;\n\ + execve will execute the program the file descriptor is open to.\n\ + If this functionality is unavailable, using it raises NotImplementedError."); + +static PyObject * +posix_execve(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + PyObject *argv, *env; char **argvlist = NULL; char **envlist; Py_ssize_t argc, envc; + static char *keywords[] = {"path", "argv", "environment", NULL}; /* execve has three arguments: (path, argv, env), where argv is a list or tuple of strings and env is a dictionary like posix.environ. */ + memset(&path, 0, sizeof(path)); + path.function_name = "execve"; +#ifdef HAVE_FEXECVE + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&OO:execve", keywords, + path_converter, &path, + &argv, &env + )) + return NULL; + if (!PyList_Check(argv) && !PyTuple_Check(argv)) { PyErr_SetString(PyExc_TypeError, "execve: argv must be a tuple or list"); @@ -6801,15 +5277,15 @@ goto fail; #ifdef HAVE_FEXECVE - if (path->fd > -1) - fexecve(path->fd, argvlist, envlist); + if (path.fd > -1) + fexecve(path.fd, argvlist, envlist); else #endif - execve(path->narrow, argvlist, envlist); + execve(path.narrow, argvlist, envlist); /* If we get here it's definitely an error */ - path_error(path); + path_error(&path); while (--envc >= 0) PyMem_DEL(envlist[envc]); @@ -6817,73 +5293,29 @@ fail: if (argvlist) free_string_array(argvlist, argc); + path_cleanup(&path); return NULL; } #endif /* HAVE_EXECV */ #ifdef HAVE_SPAWNV -/*[clinic input] -os.spawnv - - mode: int - Mode of process creation. - path: FSConverter - Path of executable file. - argv: object - Tuple or list of strings. - / - -Execute the program specified by path in a new process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_spawnv__doc__, -"spawnv($module, mode, path, argv, /)\n" -"--\n" -"\n" -"Execute the program specified by path in a new process.\n" -"\n" -" mode\n" -" Mode of process creation.\n" -" path\n" -" Path of executable file.\n" -" argv\n" -" Tuple or list of strings."); - -#define OS_SPAWNV_METHODDEF \ - {"spawnv", (PyCFunction)os_spawnv, METH_VARARGS, os_spawnv__doc__}, - -static PyObject * -os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv); - -static PyObject * -os_spawnv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int mode; - PyObject *path = NULL; +PyDoc_STRVAR(posix_spawnv__doc__, +"spawnv(mode, path, args)\n\n\ +Execute the program 'path' in a new process.\n\ +\n\ + mode: mode of process creation\n\ + path: path of executable file\n\ + args: tuple or list of strings"); + +static PyObject * +posix_spawnv(PyObject *self, PyObject *args) +{ + PyObject *opath; + char *path; PyObject *argv; - - if (!PyArg_ParseTuple(args, - "iO&O:spawnv", - &mode, PyUnicode_FSConverter, &path, &argv)) - goto exit; - return_value = os_spawnv_impl(module, mode, path, argv); - -exit: - /* Cleanup for path */ - Py_XDECREF(path); - - return return_value; -} - -static PyObject * -os_spawnv_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv) -/*[clinic end generated code: output=dfee6be062e780e3 input=042c91dfc1e6debc]*/ -{ - char *path_char; char **argvlist; - int i; + int mode, i; Py_ssize_t argc; Py_intptr_t spawnval; PyObject *(*getitem)(PyObject *, Py_ssize_t); @@ -6891,7 +5323,11 @@ /* spawnv has three arguments: (mode, path, argv), where argv is a list or tuple of strings. */ - path_char = PyBytes_AsString(path); + if (!PyArg_ParseTuple(args, "iO&O:spawnv", &mode, + PyUnicode_FSConverter, + &opath, &argv)) + return NULL; + path = PyBytes_AsString(opath); if (PyList_Check(argv)) { argc = PyList_Size(argv); getitem = PyList_GetItem; @@ -6903,11 +5339,13 @@ else { PyErr_SetString(PyExc_TypeError, "spawnv() arg 2 must be a tuple or list"); + Py_DECREF(opath); return NULL; } argvlist = PyMem_NEW(char *, argc+1); if (argvlist == NULL) { + Py_DECREF(opath); return PyErr_NoMemory(); } for (i = 0; i < argc; i++) { @@ -6917,6 +5355,7 @@ PyErr_SetString( PyExc_TypeError, "spawnv() arg 2 must contain only strings"); + Py_DECREF(opath); return NULL; } } @@ -6926,10 +5365,11 @@ mode = _P_OVERLAY; Py_BEGIN_ALLOW_THREADS - spawnval = _spawnv(mode, path_char, argvlist); + spawnval = _spawnv(mode, path, argvlist); Py_END_ALLOW_THREADS free_string_array(argvlist, argc); + Py_DECREF(opath); if (spawnval == -1) return posix_error(); @@ -6938,73 +5378,25 @@ } -/*[clinic input] -os.spawnve - - mode: int - Mode of process creation. - path: FSConverter - Path of executable file. - argv: object - Tuple or list of strings. - env: object - Dictionary of strings mapping to strings. - / - -Execute the program specified by path in a new process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_spawnve__doc__, -"spawnve($module, mode, path, argv, env, /)\n" -"--\n" -"\n" -"Execute the program specified by path in a new process.\n" -"\n" -" mode\n" -" Mode of process creation.\n" -" path\n" -" Path of executable file.\n" -" argv\n" -" Tuple or list of strings.\n" -" env\n" -" Dictionary of strings mapping to strings."); - -#define OS_SPAWNVE_METHODDEF \ - {"spawnve", (PyCFunction)os_spawnve, METH_VARARGS, os_spawnve__doc__}, - -static PyObject * -os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv, PyObject *env); - -static PyObject * -os_spawnve(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int mode; - PyObject *path = NULL; - PyObject *argv; - PyObject *env; - - if (!PyArg_ParseTuple(args, - "iO&OO:spawnve", - &mode, PyUnicode_FSConverter, &path, &argv, &env)) - goto exit; - return_value = os_spawnve_impl(module, mode, path, argv, env); - -exit: - /* Cleanup for path */ - Py_XDECREF(path); - - return return_value; -} - -static PyObject * -os_spawnve_impl(PyModuleDef *module, int mode, PyObject *path, PyObject *argv, PyObject *env) -/*[clinic end generated code: output=6f7df38473f63c7c input=02362fd937963f8f]*/ -{ - char *path_char; +PyDoc_STRVAR(posix_spawnve__doc__, +"spawnve(mode, path, args, env)\n\n\ +Execute the program 'path' in a new process.\n\ +\n\ + mode: mode of process creation\n\ + path: path of executable file\n\ + args: tuple or list of arguments\n\ + env: dictionary of strings mapping to strings"); + +static PyObject * +posix_spawnve(PyObject *self, PyObject *args) +{ + PyObject *opath; + char *path; + PyObject *argv, *env; char **argvlist; char **envlist; PyObject *res = NULL; + int mode; Py_ssize_t argc, i, envc; Py_intptr_t spawnval; PyObject *(*getitem)(PyObject *, Py_ssize_t); @@ -7014,7 +5406,11 @@ argv is a list or tuple of strings and env is a dictionary like posix.environ. */ - path_char = PyBytes_AsString(path); + if (!PyArg_ParseTuple(args, "iO&OO:spawnve", &mode, + PyUnicode_FSConverter, + &opath, &argv, &env)) + return NULL; + path = PyBytes_AsString(opath); if (PyList_Check(argv)) { argc = PyList_Size(argv); getitem = PyList_GetItem; @@ -7058,7 +5454,7 @@ mode = _P_OVERLAY; Py_BEGIN_ALLOW_THREADS - spawnval = _spawnve(mode, path_char, argvlist, envlist); + spawnval = _spawnve(mode, path, argvlist, envlist); Py_END_ALLOW_THREADS if (spawnval == -1) @@ -7072,6 +5468,7 @@ fail_1: free_string_array(argvlist, lastarg); fail_0: + Py_DECREF(opath); return res; } @@ -7079,37 +5476,14 @@ #ifdef HAVE_FORK1 -/*[clinic input] -os.fork1 - -Fork a child process with a single multiplexed (i.e., not bound) thread. - -Return 0 to child process and PID of child to parent process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fork1__doc__, -"fork1($module, /)\n" -"--\n" -"\n" -"Fork a child process with a single multiplexed (i.e., not bound) thread.\n" -"\n" -"Return 0 to child process and PID of child to parent process."); - -#define OS_FORK1_METHODDEF \ - {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__}, - -static PyObject * -os_fork1_impl(PyModuleDef *module); - -static PyObject * -os_fork1(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_fork1_impl(module); -} - -static PyObject * -os_fork1_impl(PyModuleDef *module) -/*[clinic end generated code: output=fa04088d6bc02efa input=12db02167893926e]*/ +PyDoc_STRVAR(posix_fork1__doc__, +"fork1() -> pid\n\n\ +Fork a child process with a single multiplexed (i.e., not bound) thread.\n\ +\n\ +Return 0 to child process and PID of child to parent process."); + +static PyObject * +posix_fork1(PyObject *self, PyObject *noargs) { pid_t pid; int result = 0; @@ -7132,41 +5506,17 @@ } return PyLong_FromPid(pid); } -#endif /* HAVE_FORK1 */ +#endif #ifdef HAVE_FORK -/*[clinic input] -os.fork - -Fork a child process. - -Return 0 to child process and PID of child to parent process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fork__doc__, -"fork($module, /)\n" -"--\n" -"\n" -"Fork a child process.\n" -"\n" -"Return 0 to child process and PID of child to parent process."); - -#define OS_FORK_METHODDEF \ - {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__}, - -static PyObject * -os_fork_impl(PyModuleDef *module); - -static PyObject * -os_fork(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_fork_impl(module); -} - -static PyObject * -os_fork_impl(PyModuleDef *module) -/*[clinic end generated code: output=b3c8e6bdc11eedc6 input=13c956413110eeaa]*/ +PyDoc_STRVAR(posix_fork__doc__, +"fork() -> pid\n\n\ +Fork a child process.\n\ +Return 0 to child process and PID of child to parent process."); + +static PyObject * +posix_fork(PyObject *self, PyObject *noargs) { pid_t pid; int result = 0; @@ -7189,221 +5539,92 @@ } return PyLong_FromPid(pid); } -#endif /* HAVE_FORK */ - +#endif #ifdef HAVE_SCHED_H + #ifdef HAVE_SCHED_GET_PRIORITY_MAX -/*[clinic input] -os.sched_get_priority_max - - policy: int - -Get the maximum scheduling priority for policy. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_get_priority_max__doc__, -"sched_get_priority_max($module, /, policy)\n" -"--\n" -"\n" -"Get the maximum scheduling priority for policy."); - -#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \ - {"sched_get_priority_max", (PyCFunction)os_sched_get_priority_max, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_max__doc__}, - -static PyObject * -os_sched_get_priority_max_impl(PyModuleDef *module, int policy); - -static PyObject * -os_sched_get_priority_max(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"policy", NULL}; - int policy; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:sched_get_priority_max", _keywords, - &policy)) - goto exit; - return_value = os_sched_get_priority_max_impl(module, policy); - -exit: - return return_value; -} - -static PyObject * -os_sched_get_priority_max_impl(PyModuleDef *module, int policy) -/*[clinic end generated code: output=a580a52f25238c1f input=2097b7998eca6874]*/ -{ - int max; - + +PyDoc_STRVAR(posix_sched_get_priority_max__doc__, +"sched_get_priority_max(policy)\n\n\ +Get the maximum scheduling priority for *policy*."); + +static PyObject * +posix_sched_get_priority_max(PyObject *self, PyObject *args) +{ + int policy, max; + + if (!PyArg_ParseTuple(args, "i:sched_get_priority_max", &policy)) + return NULL; max = sched_get_priority_max(policy); if (max < 0) return posix_error(); return PyLong_FromLong(max); } - -/*[clinic input] -os.sched_get_priority_min - - policy: int - -Get the minimum scheduling priority for policy. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_get_priority_min__doc__, -"sched_get_priority_min($module, /, policy)\n" -"--\n" -"\n" -"Get the minimum scheduling priority for policy."); - -#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \ - {"sched_get_priority_min", (PyCFunction)os_sched_get_priority_min, METH_VARARGS|METH_KEYWORDS, os_sched_get_priority_min__doc__}, - -static PyObject * -os_sched_get_priority_min_impl(PyModuleDef *module, int policy); - -static PyObject * -os_sched_get_priority_min(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"policy", NULL}; +PyDoc_STRVAR(posix_sched_get_priority_min__doc__, +"sched_get_priority_min(policy)\n\n\ +Get the minimum scheduling priority for *policy*."); + +static PyObject * +posix_sched_get_priority_min(PyObject *self, PyObject *args) +{ + int policy, min; + + if (!PyArg_ParseTuple(args, "i:sched_get_priority_min", &policy)) + return NULL; + min = sched_get_priority_min(policy); + if (min < 0) + return posix_error(); + return PyLong_FromLong(min); +} + +#endif /* HAVE_SCHED_GET_PRIORITY_MAX */ + +#ifdef HAVE_SCHED_SETSCHEDULER + +PyDoc_STRVAR(posix_sched_getscheduler__doc__, +"sched_getscheduler(pid)\n\n\ +Get the scheduling policy for the process with a PID of *pid*.\n\ +Passing a PID of 0 returns the scheduling policy for the calling process."); + +static PyObject * +posix_sched_getscheduler(PyObject *self, PyObject *args) +{ + pid_t pid; int policy; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:sched_get_priority_min", _keywords, - &policy)) - goto exit; - return_value = os_sched_get_priority_min_impl(module, policy); - -exit: - return return_value; -} - -static PyObject * -os_sched_get_priority_min_impl(PyModuleDef *module, int policy) -/*[clinic end generated code: output=bad8ba10e7d0e977 input=21bc8fa0d70983bf]*/ -{ - int min = sched_get_priority_min(policy); - if (min < 0) - return posix_error(); - return PyLong_FromLong(min); -} -#endif /* HAVE_SCHED_GET_PRIORITY_MAX */ - - -#ifdef HAVE_SCHED_SETSCHEDULER -/*[clinic input] -os.sched_getscheduler - pid: pid_t - / - -Get the scheduling policy for the process identifiedy by pid. - -Passing 0 for pid returns the scheduling policy for the calling process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_getscheduler__doc__, -"sched_getscheduler($module, pid, /)\n" -"--\n" -"\n" -"Get the scheduling policy for the process identifiedy by pid.\n" -"\n" -"Passing 0 for pid returns the scheduling policy for the calling process."); - -#define OS_SCHED_GETSCHEDULER_METHODDEF \ - {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_VARARGS, os_sched_getscheduler__doc__}, - -static PyObject * -os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_sched_getscheduler(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - pid_t pid; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID ":sched_getscheduler", - &pid)) - goto exit; - return_value = os_sched_getscheduler_impl(module, pid); - -exit: - return return_value; -} - -static PyObject * -os_sched_getscheduler_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=e0d6244207b1d828 input=5f14cfd1f189e1a0]*/ -{ - int policy; - + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":sched_getscheduler", &pid)) + return NULL; policy = sched_getscheduler(pid); if (policy < 0) return posix_error(); return PyLong_FromLong(policy); } -#endif /* HAVE_SCHED_SETSCHEDULER */ - + +#endif #if defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM) -/*[clinic input] -class os.sched_param "PyObject *" "&SchedParamType" - -@classmethod -os.sched_param.__new__ - - sched_priority: object - A scheduling parameter. - -Current has only one field: sched_priority"); -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_param__doc__, -"sched_param(sched_priority)\n" -"--\n" -"\n" -"Current has only one field: sched_priority\");\n" -"\n" -" sched_priority\n" -" A scheduling parameter."); - -static PyObject * -os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority); - -static PyObject * -os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"sched_priority", NULL}; - PyObject *sched_priority; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O:sched_param", _keywords, - &sched_priority)) - goto exit; - return_value = os_sched_param_impl(type, sched_priority); - -exit: - return return_value; -} - -static PyObject * -os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority) -/*[clinic end generated code: output=d3791e345f7fe573 input=73a4c22f7071fc62]*/ -{ - PyObject *res; - + +static PyObject * +sched_param_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) +{ + PyObject *res, *priority; + static char *kwlist[] = {"sched_priority", NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:sched_param", kwlist, &priority)) + return NULL; res = PyStructSequence_New(type); if (!res) return NULL; - Py_INCREF(sched_priority); - PyStructSequence_SET_ITEM(res, 0, sched_priority); + Py_INCREF(priority); + PyStructSequence_SET_ITEM(res, 0, priority); return res; } +PyDoc_STRVAR(sched_param__doc__, +"sched_param(sched_priority): A scheduling parameter.\n\n\ +Current has only one field: sched_priority"); static PyStructSequence_Field sched_param_fields[] = { {"sched_priority", "the scheduling priority"}, @@ -7412,7 +5633,7 @@ static PyStructSequence_Desc sched_param_desc = { "sched_param", /* name */ - os_sched_param__doc__, /* doc */ + sched_param__doc__, /* doc */ sched_param_fields, 1 }; @@ -7436,280 +5657,118 @@ res->sched_priority = Py_SAFE_DOWNCAST(priority, long, int); return 1; } -#endif /* defined(HAVE_SCHED_SETSCHEDULER) || defined(HAVE_SCHED_SETPARAM) */ - + +#endif #ifdef HAVE_SCHED_SETSCHEDULER -/*[clinic input] -os.sched_setscheduler - - pid: pid_t - policy: int - param: sched_param - / - -Set the scheduling policy for the process identified by pid. - -If pid is 0, the calling process is changed. -param is an instance of sched_param. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_setscheduler__doc__, -"sched_setscheduler($module, pid, policy, param, /)\n" -"--\n" -"\n" -"Set the scheduling policy for the process identified by pid.\n" -"\n" -"If pid is 0, the calling process is changed.\n" -"param is an instance of sched_param."); - -#define OS_SCHED_SETSCHEDULER_METHODDEF \ - {"sched_setscheduler", (PyCFunction)os_sched_setscheduler, METH_VARARGS, os_sched_setscheduler__doc__}, - -static PyObject * -os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy, struct sched_param *param); - -static PyObject * -os_sched_setscheduler(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + +PyDoc_STRVAR(posix_sched_setscheduler__doc__, +"sched_setscheduler(pid, policy, param)\n\n\ +Set the scheduling policy, *policy*, for *pid*.\n\ +If *pid* is 0, the calling process is changed.\n\ +*param* is an instance of sched_param."); + +static PyObject * +posix_sched_setscheduler(PyObject *self, PyObject *args) +{ pid_t pid; int policy; struct sched_param param; - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "iO&:sched_setscheduler", - &pid, &policy, convert_sched_param, ¶m)) - goto exit; - return_value = os_sched_setscheduler_impl(module, pid, policy, ¶m); - -exit: - return return_value; -} - -static PyObject * -os_sched_setscheduler_impl(PyModuleDef *module, pid_t pid, int policy, struct sched_param *param) -/*[clinic end generated code: output=36abdb73f81c224f input=c581f9469a5327dd]*/ -{ + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "iO&:sched_setscheduler", + &pid, &policy, &convert_sched_param, ¶m)) + return NULL; + /* ** sched_setscheduler() returns 0 in Linux, but the previous ** scheduling policy under Solaris/Illumos, and others. ** On error, -1 is returned in all Operating Systems. */ - if (sched_setscheduler(pid, policy, param) == -1) + if (sched_setscheduler(pid, policy, ¶m) == -1) return posix_error(); Py_RETURN_NONE; } -#endif /* HAVE_SCHED_SETSCHEDULER*/ - + +#endif #ifdef HAVE_SCHED_SETPARAM -/*[clinic input] -os.sched_getparam - pid: pid_t - / - -Returns scheduling parameters for the process identified by pid. - -If pid is 0, returns parameters for the calling process. -Return value is an instance of sched_param. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_getparam__doc__, -"sched_getparam($module, pid, /)\n" -"--\n" -"\n" -"Returns scheduling parameters for the process identified by pid.\n" -"\n" -"If pid is 0, returns parameters for the calling process.\n" -"Return value is an instance of sched_param."); - -#define OS_SCHED_GETPARAM_METHODDEF \ - {"sched_getparam", (PyCFunction)os_sched_getparam, METH_VARARGS, os_sched_getparam__doc__}, - -static PyObject * -os_sched_getparam_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_sched_getparam(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + +PyDoc_STRVAR(posix_sched_getparam__doc__, +"sched_getparam(pid) -> sched_param\n\n\ +Returns scheduling parameters for the process with *pid* as an instance of the\n\ +sched_param class. A PID of 0 means the calling process."); + +static PyObject * +posix_sched_getparam(PyObject *self, PyObject *args) +{ pid_t pid; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID ":sched_getparam", - &pid)) - goto exit; - return_value = os_sched_getparam_impl(module, pid); - -exit: - return return_value; -} - -static PyObject * -os_sched_getparam_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=b33acc8db004a8c9 input=18a1ef9c2efae296]*/ -{ struct sched_param param; - PyObject *result; - PyObject *priority; - + PyObject *res, *priority; + + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":sched_getparam", &pid)) + return NULL; if (sched_getparam(pid, ¶m)) return posix_error(); - result = PyStructSequence_New(&SchedParamType); - if (!result) + res = PyStructSequence_New(&SchedParamType); + if (!res) return NULL; priority = PyLong_FromLong(param.sched_priority); if (!priority) { - Py_DECREF(result); - return NULL; - } - PyStructSequence_SET_ITEM(result, 0, priority); - return result; -} - - -/*[clinic input] -os.sched_setparam - pid: pid_t - param: sched_param - / - -Set scheduling parameters for the process identified by pid. - -If pid is 0, sets parameters for the calling process. -param should be an instance of sched_param. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_setparam__doc__, -"sched_setparam($module, pid, param, /)\n" -"--\n" -"\n" -"Set scheduling parameters for the process identified by pid.\n" -"\n" -"If pid is 0, sets parameters for the calling process.\n" -"param should be an instance of sched_param."); - -#define OS_SCHED_SETPARAM_METHODDEF \ - {"sched_setparam", (PyCFunction)os_sched_setparam, METH_VARARGS, os_sched_setparam__doc__}, - -static PyObject * -os_sched_setparam_impl(PyModuleDef *module, pid_t pid, struct sched_param *param); - -static PyObject * -os_sched_setparam(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + Py_DECREF(res); + return NULL; + } + PyStructSequence_SET_ITEM(res, 0, priority); + return res; +} + +PyDoc_STRVAR(posix_sched_setparam__doc__, +"sched_setparam(pid, param)\n\n\ +Set scheduling parameters for a process with PID *pid*.\n\ +A PID of 0 means the calling process."); + +static PyObject * +posix_sched_setparam(PyObject *self, PyObject *args) +{ pid_t pid; struct sched_param param; - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "O&:sched_setparam", - &pid, convert_sched_param, ¶m)) - goto exit; - return_value = os_sched_setparam_impl(module, pid, ¶m); - -exit: - return return_value; -} - -static PyObject * -os_sched_setparam_impl(PyModuleDef *module, pid_t pid, struct sched_param *param) -/*[clinic end generated code: output=488bdf5bcbe0d4e8 input=6b8d6dfcecdc21bd]*/ -{ - if (sched_setparam(pid, param)) + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O&:sched_setparam", + &pid, &convert_sched_param, ¶m)) + return NULL; + if (sched_setparam(pid, ¶m)) return posix_error(); Py_RETURN_NONE; } -#endif /* HAVE_SCHED_SETPARAM */ - + +#endif #ifdef HAVE_SCHED_RR_GET_INTERVAL -/*[clinic input] -os.sched_rr_get_interval -> double - pid: pid_t - / - -Return the round-robin quantum for the process identified by pid, in seconds. - -Value returned is a float. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_rr_get_interval__doc__, -"sched_rr_get_interval($module, pid, /)\n" -"--\n" -"\n" -"Return the round-robin quantum for the process identified by pid, in seconds.\n" -"\n" -"Value returned is a float."); - -#define OS_SCHED_RR_GET_INTERVAL_METHODDEF \ - {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_VARARGS, os_sched_rr_get_interval__doc__}, - -static double -os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_sched_rr_get_interval(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + +PyDoc_STRVAR(posix_sched_rr_get_interval__doc__, +"sched_rr_get_interval(pid) -> float\n\n\ +Return the round-robin quantum for the process with PID *pid* in seconds."); + +static PyObject * +posix_sched_rr_get_interval(PyObject *self, PyObject *args) +{ pid_t pid; - double _return_value; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID ":sched_rr_get_interval", - &pid)) - goto exit; - _return_value = os_sched_rr_get_interval_impl(module, pid); - if ((_return_value == -1.0) && PyErr_Occurred()) - goto exit; - return_value = PyFloat_FromDouble(_return_value); - -exit: - return return_value; -} - -static double -os_sched_rr_get_interval_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=5b3b8d1f27fb2c0a input=2a973da15cca6fae]*/ -{ struct timespec interval; - if (sched_rr_get_interval(pid, &interval)) { - posix_error(); - return -1.0; - } - return (double)interval.tv_sec + 1e-9*interval.tv_nsec; -} -#endif /* HAVE_SCHED_RR_GET_INTERVAL */ - - -/*[clinic input] -os.sched_yield - -Voluntarily relinquish the CPU. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_yield__doc__, -"sched_yield($module, /)\n" -"--\n" -"\n" -"Voluntarily relinquish the CPU."); - -#define OS_SCHED_YIELD_METHODDEF \ - {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__}, - -static PyObject * -os_sched_yield_impl(PyModuleDef *module); - -static PyObject * -os_sched_yield(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_sched_yield_impl(module); -} - -static PyObject * -os_sched_yield_impl(PyModuleDef *module) -/*[clinic end generated code: output=9d2e5f29f1370324 input=e54d6f98189391d4]*/ + + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":sched_rr_get_interval", &pid)) + return NULL; + if (sched_rr_get_interval(pid, &interval)) + return posix_error(); + return PyFloat_FromDouble((double)interval.tv_sec + 1e-9*interval.tv_nsec); +} + +#endif + +PyDoc_STRVAR(posix_sched_yield__doc__, +"sched_yield()\n\n\ +Voluntarily relinquish the CPU."); + +static PyObject * +posix_sched_yield(PyObject *self, PyObject *noargs) { if (sched_yield()) return posix_error(); @@ -7717,72 +5776,39 @@ } #ifdef HAVE_SCHED_SETAFFINITY + /* The minimum number of CPUs allocated in a cpu_set_t */ static const int NCPUS_START = sizeof(unsigned long) * CHAR_BIT; -/*[clinic input] -os.sched_setaffinity - pid: pid_t - mask : object - / - -Set the CPU affinity of the process identified by pid to mask. - -mask should be an iterable of integers identifying CPUs. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_setaffinity__doc__, -"sched_setaffinity($module, pid, mask, /)\n" -"--\n" -"\n" -"Set the CPU affinity of the process identified by pid to mask.\n" -"\n" -"mask should be an iterable of integers identifying CPUs."); - -#define OS_SCHED_SETAFFINITY_METHODDEF \ - {"sched_setaffinity", (PyCFunction)os_sched_setaffinity, METH_VARARGS, os_sched_setaffinity__doc__}, - -static PyObject * -os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask); - -static PyObject * -os_sched_setaffinity(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_sched_setaffinity__doc__, +"sched_setaffinity(pid, cpu_set)\n\n\ +Set the affinity of the process with PID *pid* to *cpu_set*."); + +static PyObject * +posix_sched_setaffinity(PyObject *self, PyObject *args) +{ pid_t pid; - PyObject *mask; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "O:sched_setaffinity", - &pid, &mask)) - goto exit; - return_value = os_sched_setaffinity_impl(module, pid, mask); - -exit: - return return_value; -} - -static PyObject * -os_sched_setaffinity_impl(PyModuleDef *module, pid_t pid, PyObject *mask) -/*[clinic end generated code: output=5199929738130196 input=a0791a597c7085ba]*/ -{ int ncpus; size_t setsize; - cpu_set_t *cpu_set = NULL; - PyObject *iterator = NULL, *item; - - iterator = PyObject_GetIter(mask); + cpu_set_t *mask = NULL; + PyObject *iterable, *iterator = NULL, *item; + + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "O:sched_setaffinity", + &pid, &iterable)) + return NULL; + + iterator = PyObject_GetIter(iterable); if (iterator == NULL) return NULL; ncpus = NCPUS_START; setsize = CPU_ALLOC_SIZE(ncpus); - cpu_set = CPU_ALLOC(ncpus); - if (cpu_set == NULL) { + mask = CPU_ALLOC(ncpus); + if (mask == NULL) { PyErr_NoMemory(); goto error; } - CPU_ZERO_S(setsize, cpu_set); + CPU_ZERO_S(setsize, mask); while ((item = PyIter_Next(iterator))) { long cpu; @@ -7823,80 +5849,48 @@ } newsetsize = CPU_ALLOC_SIZE(newncpus); CPU_ZERO_S(newsetsize, newmask); - memcpy(newmask, cpu_set, setsize); - CPU_FREE(cpu_set); + memcpy(newmask, mask, setsize); + CPU_FREE(mask); setsize = newsetsize; - cpu_set = newmask; + mask = newmask; ncpus = newncpus; } - CPU_SET_S(cpu, setsize, cpu_set); + CPU_SET_S(cpu, setsize, mask); } Py_CLEAR(iterator); - if (sched_setaffinity(pid, setsize, cpu_set)) { + if (sched_setaffinity(pid, setsize, mask)) { posix_error(); goto error; } - CPU_FREE(cpu_set); + CPU_FREE(mask); Py_RETURN_NONE; error: - if (cpu_set) - CPU_FREE(cpu_set); + if (mask) + CPU_FREE(mask); Py_XDECREF(iterator); return NULL; } - -/*[clinic input] -os.sched_getaffinity - pid: pid_t - / - -Return the affinity of the process identified by pid. - -The affinity is returned as a set of CPU identifiers. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sched_getaffinity__doc__, -"sched_getaffinity($module, pid, /)\n" -"--\n" -"\n" -"Return the affinity of the process identified by pid.\n" -"\n" -"The affinity is returned as a set of CPU identifiers."); - -#define OS_SCHED_GETAFFINITY_METHODDEF \ - {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_VARARGS, os_sched_getaffinity__doc__}, - -static PyObject * -os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_sched_getaffinity(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_sched_getaffinity__doc__, +"sched_getaffinity(pid, ncpus) -> cpu_set\n\n\ +Return the affinity of the process with PID *pid*.\n\ +The returned cpu_set will be of size *ncpus*."); + +static PyObject * +posix_sched_getaffinity(PyObject *self, PyObject *args) +{ pid_t pid; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID ":sched_getaffinity", - &pid)) - goto exit; - return_value = os_sched_getaffinity_impl(module, pid); - -exit: - return return_value; -} - -static PyObject * -os_sched_getaffinity_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=7b273b0fca9830f0 input=eaf161936874b8a1]*/ -{ int cpu, ncpus, count; size_t setsize; cpu_set_t *mask = NULL; PyObject *res = NULL; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":sched_getaffinity", + &pid)) + return NULL; + ncpus = NCPUS_START; while (1) { setsize = CPU_ALLOC_SIZE(ncpus); @@ -7946,47 +5940,6 @@ #endif /* HAVE_SCHED_H */ -#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF -#define OS_SCHED_GET_PRIORITY_MAX_METHODDEF -#endif /* OS_SCHED_GET_PRIORITY_MAX_METHODDEF */ - -#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF -#define OS_SCHED_GET_PRIORITY_MIN_METHODDEF -#endif /* OS_SCHED_GET_PRIORITY_MIN_METHODDEF */ - -#ifndef OS_SCHED_GETSCHEDULER_METHODDEF -#define OS_SCHED_GETSCHEDULER_METHODDEF -#endif /* OS_SCHED_GETSCHEDULER_METHODDEF */ - -#ifndef OS_SCHED_SETSCHEDULER_METHODDEF -#define OS_SCHED_SETSCHEDULER_METHODDEF -#endif /* OS_SCHED_SETSCHEDULER_METHODDEF */ - -#ifndef OS_SCHED_GETPARAM_METHODDEF -#define OS_SCHED_GETPARAM_METHODDEF -#endif /* OS_SCHED_GETPARAM_METHODDEF */ - -#ifndef OS_SCHED_SETPARAM_METHODDEF -#define OS_SCHED_SETPARAM_METHODDEF -#endif /* OS_SCHED_SETPARAM_METHODDEF */ - -#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF -#define OS_SCHED_RR_GET_INTERVAL_METHODDEF -#endif /* OS_SCHED_RR_GET_INTERVAL_METHODDEF */ - -#ifndef OS_SCHED_YIELD_METHODDEF -#define OS_SCHED_YIELD_METHODDEF -#endif /* OS_SCHED_YIELD_METHODDEF */ - -#ifndef OS_SCHED_SETAFFINITY_METHODDEF -#define OS_SCHED_SETAFFINITY_METHODDEF -#endif /* OS_SCHED_SETAFFINITY_METHODDEF */ - -#ifndef OS_SCHED_GETAFFINITY_METHODDEF -#define OS_SCHED_GETAFFINITY_METHODDEF -#endif /* OS_SCHED_GETAFFINITY_METHODDEF */ - - /* AIX uses /dev/ptc but is otherwise the same as /dev/ptmx */ /* IRIX has both /dev/ptc and /dev/ptmx, use ptmx */ #if defined(HAVE_DEV_PTC) && !defined(HAVE_DEV_PTMX) @@ -8013,41 +5966,13 @@ #endif #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) || defined(HAVE_DEV_PTMX */ - #if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) -/*[clinic input] -os.openpty - -Open a pseudo-terminal. - -Return a tuple of (master_fd, slave_fd) containing open file descriptors -for both the master and slave ends. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_openpty__doc__, -"openpty($module, /)\n" -"--\n" -"\n" -"Open a pseudo-terminal.\n" -"\n" -"Return a tuple of (master_fd, slave_fd) containing open file descriptors\n" -"for both the master and slave ends."); - -#define OS_OPENPTY_METHODDEF \ - {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__}, - -static PyObject * -os_openpty_impl(PyModuleDef *module); - -static PyObject * -os_openpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_openpty_impl(module); -} - -static PyObject * -os_openpty_impl(PyModuleDef *module) -/*[clinic end generated code: output=b12d3c1735468464 input=f3d99fd99e762907]*/ +PyDoc_STRVAR(posix_openpty__doc__, +"openpty() -> (master_fd, slave_fd)\n\n\ +Open a pseudo-terminal, returning open fd's for both master and slave end.\n"); + +static PyObject * +posix_openpty(PyObject *self, PyObject *noargs) { int master_fd = -1, slave_fd = -1; #ifndef HAVE_OPENPTY @@ -8136,45 +6061,15 @@ } #endif /* defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) */ - #ifdef HAVE_FORKPTY -/*[clinic input] -os.forkpty - -Fork a new process with a new pseudo-terminal as controlling tty. - -Returns a tuple of (pid, master_fd). -Like fork(), return pid of 0 to the child process, -and pid of child to the parent process. -To both, return fd of newly opened pseudo-terminal. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_forkpty__doc__, -"forkpty($module, /)\n" -"--\n" -"\n" -"Fork a new process with a new pseudo-terminal as controlling tty.\n" -"\n" -"Returns a tuple of (pid, master_fd).\n" -"Like fork(), return pid of 0 to the child process,\n" -"and pid of child to the parent process.\n" -"To both, return fd of newly opened pseudo-terminal."); - -#define OS_FORKPTY_METHODDEF \ - {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__}, - -static PyObject * -os_forkpty_impl(PyModuleDef *module); - -static PyObject * -os_forkpty(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_forkpty_impl(module); -} - -static PyObject * -os_forkpty_impl(PyModuleDef *module) -/*[clinic end generated code: output=d4f82958d2ed5cad input=f1f7f4bae3966010]*/ +PyDoc_STRVAR(posix_forkpty__doc__, +"forkpty() -> (pid, master_fd)\n\n\ +Fork a new process with a new pseudo-terminal as controlling tty.\n\n\ +Like fork(), return 0 as pid to child process, and PID of child to parent.\n\ +To both, return fd of newly opened pseudo-terminal.\n"); + +static PyObject * +posix_forkpty(PyObject *self, PyObject *noargs) { int master_fd = -1, result = 0; pid_t pid; @@ -8198,145 +6093,59 @@ } return Py_BuildValue("(Ni)", PyLong_FromPid(pid), master_fd); } -#endif /* HAVE_FORKPTY */ +#endif #ifdef HAVE_GETEGID -/*[clinic input] -os.getegid - -Return the current process's effective group id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getegid__doc__, -"getegid($module, /)\n" -"--\n" -"\n" -"Return the current process\'s effective group id."); - -#define OS_GETEGID_METHODDEF \ - {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__}, - -static PyObject * -os_getegid_impl(PyModuleDef *module); - -static PyObject * -os_getegid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getegid_impl(module); -} - -static PyObject * -os_getegid_impl(PyModuleDef *module) -/*[clinic end generated code: output=fd12c346fa41cccb input=1596f79ad1107d5d]*/ +PyDoc_STRVAR(posix_getegid__doc__, +"getegid() -> egid\n\n\ +Return the current process's effective group id."); + +static PyObject * +posix_getegid(PyObject *self, PyObject *noargs) { return _PyLong_FromGid(getegid()); } -#endif /* HAVE_GETEGID */ +#endif #ifdef HAVE_GETEUID -/*[clinic input] -os.geteuid - -Return the current process's effective user id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_geteuid__doc__, -"geteuid($module, /)\n" -"--\n" -"\n" -"Return the current process\'s effective user id."); - -#define OS_GETEUID_METHODDEF \ - {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__}, - -static PyObject * -os_geteuid_impl(PyModuleDef *module); - -static PyObject * -os_geteuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_geteuid_impl(module); -} - -static PyObject * -os_geteuid_impl(PyModuleDef *module) -/*[clinic end generated code: output=03d98e07f4bc03d4 input=4644c662d3bd9f19]*/ +PyDoc_STRVAR(posix_geteuid__doc__, +"geteuid() -> euid\n\n\ +Return the current process's effective user id."); + +static PyObject * +posix_geteuid(PyObject *self, PyObject *noargs) { return _PyLong_FromUid(geteuid()); } -#endif /* HAVE_GETEUID */ +#endif #ifdef HAVE_GETGID -/*[clinic input] -os.getgid - -Return the current process's group id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getgid__doc__, -"getgid($module, /)\n" -"--\n" -"\n" -"Return the current process\'s group id."); - -#define OS_GETGID_METHODDEF \ - {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__}, - -static PyObject * -os_getgid_impl(PyModuleDef *module); - -static PyObject * -os_getgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getgid_impl(module); -} - -static PyObject * -os_getgid_impl(PyModuleDef *module) -/*[clinic end generated code: output=07b0356121b8098d input=58796344cd87c0f6]*/ +PyDoc_STRVAR(posix_getgid__doc__, +"getgid() -> gid\n\n\ +Return the current process's group id."); + +static PyObject * +posix_getgid(PyObject *self, PyObject *noargs) { return _PyLong_FromGid(getgid()); } -#endif /* HAVE_GETGID */ - - -/*[clinic input] -os.getpid - -Return the current process id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getpid__doc__, -"getpid($module, /)\n" -"--\n" -"\n" -"Return the current process id."); - -#define OS_GETPID_METHODDEF \ - {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__}, - -static PyObject * -os_getpid_impl(PyModuleDef *module); - -static PyObject * -os_getpid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getpid_impl(module); -} - -static PyObject * -os_getpid_impl(PyModuleDef *module) -/*[clinic end generated code: output=d63a01a3cebc573d input=5a9a00f0ab68aa00]*/ +#endif + + +PyDoc_STRVAR(posix_getpid__doc__, +"getpid() -> pid\n\n\ +Return the current process id"); + +static PyObject * +posix_getpid(PyObject *self, PyObject *noargs) { return PyLong_FromPid(getpid()); } #ifdef HAVE_GETGROUPLIST - -/* AC 3.5: funny apple logic below */ PyDoc_STRVAR(posix_getgrouplist__doc__, "getgrouplist(user, group) -> list of groups to which a user belongs\n\n\ Returns a list of groups to which a user belongs.\n\n\ @@ -8409,37 +6218,15 @@ return list; } -#endif /* HAVE_GETGROUPLIST */ - +#endif #ifdef HAVE_GETGROUPS -/*[clinic input] -os.getgroups - -Return list of supplemental group IDs for the process. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getgroups__doc__, -"getgroups($module, /)\n" -"--\n" -"\n" -"Return list of supplemental group IDs for the process."); - -#define OS_GETGROUPS_METHODDEF \ - {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__}, - -static PyObject * -os_getgroups_impl(PyModuleDef *module); - -static PyObject * -os_getgroups(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getgroups_impl(module); -} - -static PyObject * -os_getgroups_impl(PyModuleDef *module) -/*[clinic end generated code: output=d9a3559b2e6f4ab8 input=d3f109412e6a155c]*/ +PyDoc_STRVAR(posix_getgroups__doc__, +"getgroups() -> list of group IDs\n\n\ +Return list of supplemental group IDs for the process."); + +static PyObject * +posix_getgroups(PyObject *self, PyObject *noargs) { PyObject *result = NULL; @@ -8538,7 +6325,7 @@ return result; } -#endif /* HAVE_GETGROUPS */ +#endif #ifdef HAVE_INITGROUPS PyDoc_STRVAR(posix_initgroups__doc__, @@ -8547,7 +6334,6 @@ the groups of which the specified username is a member, plus the specified\n\ group id."); -/* AC 3.5: funny apple logic */ static PyObject * posix_initgroups(PyObject *self, PyObject *args) { @@ -8580,52 +6366,20 @@ Py_INCREF(Py_None); return Py_None; } -#endif /* HAVE_INITGROUPS */ - +#endif #ifdef HAVE_GETPGID -/*[clinic input] -os.getpgid - - pid: pid_t - -Call the system call getpgid(), and return the result. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getpgid__doc__, -"getpgid($module, /, pid)\n" -"--\n" -"\n" -"Call the system call getpgid(), and return the result."); - -#define OS_GETPGID_METHODDEF \ - {"getpgid", (PyCFunction)os_getpgid, METH_VARARGS|METH_KEYWORDS, os_getpgid__doc__}, - -static PyObject * -os_getpgid_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_getpgid(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"pid", NULL}; - pid_t pid; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "" _Py_PARSE_PID ":getpgid", _keywords, - &pid)) - goto exit; - return_value = os_getpgid_impl(module, pid); - -exit: - return return_value; -} - -static PyObject * -os_getpgid_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=3db4ed686179160d input=39d710ae3baaf1c7]*/ -{ - pid_t pgid = getpgid(pid); +PyDoc_STRVAR(posix_getpgid__doc__, +"getpgid(pid) -> pgid\n\n\ +Call the system call getpgid()."); + +static PyObject * +posix_getpgid(PyObject *self, PyObject *args) +{ + pid_t pid, pgid; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":getpgid", &pid)) + return NULL; + pgid = getpgid(pid); if (pgid < 0) return posix_error(); return PyLong_FromPid(pgid); @@ -8634,33 +6388,12 @@ #ifdef HAVE_GETPGRP -/*[clinic input] -os.getpgrp - -Return the current process group id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getpgrp__doc__, -"getpgrp($module, /)\n" -"--\n" -"\n" -"Return the current process group id."); - -#define OS_GETPGRP_METHODDEF \ - {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__}, - -static PyObject * -os_getpgrp_impl(PyModuleDef *module); - -static PyObject * -os_getpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getpgrp_impl(module); -} - -static PyObject * -os_getpgrp_impl(PyModuleDef *module) -/*[clinic end generated code: output=3b0d3663ea054277 input=6846fb2bb9a3705e]*/ +PyDoc_STRVAR(posix_getpgrp__doc__, +"getpgrp() -> pgrp\n\n\ +Return the current process group id."); + +static PyObject * +posix_getpgrp(PyObject *self, PyObject *noargs) { #ifdef GETPGRP_HAVE_ARG return PyLong_FromPid(getpgrp(0)); @@ -8672,33 +6405,12 @@ #ifdef HAVE_SETPGRP -/*[clinic input] -os.setpgrp - -Make the current process the leader of its process group. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setpgrp__doc__, -"setpgrp($module, /)\n" -"--\n" -"\n" -"Make the current process the leader of its process group."); - -#define OS_SETPGRP_METHODDEF \ - {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__}, - -static PyObject * -os_setpgrp_impl(PyModuleDef *module); - -static PyObject * -os_setpgrp(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_setpgrp_impl(module); -} - -static PyObject * -os_setpgrp_impl(PyModuleDef *module) -/*[clinic end generated code: output=8fbb0ee29ef6fb2d input=1f0619fcb5731e7e]*/ +PyDoc_STRVAR(posix_setpgrp__doc__, +"setpgrp()\n\n\ +Make this process the process group leader."); + +static PyObject * +posix_setpgrp(PyObject *self, PyObject *noargs) { #ifdef SETPGRP_HAVE_ARG if (setpgrp(0, 0) < 0) @@ -8709,6 +6421,7 @@ Py_INCREF(Py_None); return Py_None; } + #endif /* HAVE_SETPGRP */ #ifdef HAVE_GETPPID @@ -8755,40 +6468,14 @@ } #endif /*MS_WINDOWS*/ - -/*[clinic input] -os.getppid - -Return the parent's process id. - -If the parent process has already exited, Windows machines will still -return its id; others systems will return the id of the 'init' process (1). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getppid__doc__, -"getppid($module, /)\n" -"--\n" -"\n" -"Return the parent\'s process id.\n" -"\n" -"If the parent process has already exited, Windows machines will still\n" -"return its id; others systems will return the id of the \'init\' process (1)."); - -#define OS_GETPPID_METHODDEF \ - {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__}, - -static PyObject * -os_getppid_impl(PyModuleDef *module); - -static PyObject * -os_getppid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getppid_impl(module); -} - -static PyObject * -os_getppid_impl(PyModuleDef *module) -/*[clinic end generated code: output=9ff3b387781edf3a input=e637cb87539c030e]*/ +PyDoc_STRVAR(posix_getppid__doc__, +"getppid() -> ppid\n\n\ +Return the parent's process id. If the parent process has already exited,\n\ +Windows machines will still return its id; others systems will return the id\n\ +of the 'init' process (1)."); + +static PyObject * +posix_getppid(PyObject *self, PyObject *noargs) { #ifdef MS_WINDOWS return win32_getppid(); @@ -8800,33 +6487,12 @@ #ifdef HAVE_GETLOGIN -/*[clinic input] -os.getlogin - -Return the actual login name. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getlogin__doc__, -"getlogin($module, /)\n" -"--\n" -"\n" -"Return the actual login name."); - -#define OS_GETLOGIN_METHODDEF \ - {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__}, - -static PyObject * -os_getlogin_impl(PyModuleDef *module); - -static PyObject * -os_getlogin(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getlogin_impl(module); -} - -static PyObject * -os_getlogin_impl(PyModuleDef *module) -/*[clinic end generated code: output=ab6211dab104cbb2 input=2a21ab1e917163df]*/ +PyDoc_STRVAR(posix_getlogin__doc__, +"getlogin() -> string\n\n\ +Return the actual login name."); + +static PyObject * +posix_getlogin(PyObject *self, PyObject *noargs) { PyObject *result = NULL; #ifdef MS_WINDOWS @@ -8859,101 +6525,77 @@ } #endif /* HAVE_GETLOGIN */ - #ifdef HAVE_GETUID -/*[clinic input] -os.getuid - -Return the current process's user id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getuid__doc__, -"getuid($module, /)\n" -"--\n" -"\n" -"Return the current process\'s user id."); - -#define OS_GETUID_METHODDEF \ - {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__}, - -static PyObject * -os_getuid_impl(PyModuleDef *module); - -static PyObject * -os_getuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getuid_impl(module); -} - -static PyObject * -os_getuid_impl(PyModuleDef *module) -/*[clinic end generated code: output=77e0dcf2e37d1e89 input=b53c8b35f110a516]*/ +PyDoc_STRVAR(posix_getuid__doc__, +"getuid() -> uid\n\n\ +Return the current process's user id."); + +static PyObject * +posix_getuid(PyObject *self, PyObject *noargs) { return _PyLong_FromUid(getuid()); } -#endif /* HAVE_GETUID */ - +#endif + + +#ifdef HAVE_KILL +PyDoc_STRVAR(posix_kill__doc__, +"kill(pid, sig)\n\n\ +Kill a process with a signal."); + +static PyObject * +posix_kill(PyObject *self, PyObject *args) +{ + pid_t pid; + int sig; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:kill", &pid, &sig)) + return NULL; + if (kill(pid, sig) == -1) + return posix_error(); + Py_INCREF(Py_None); + return Py_None; +} +#endif + +#ifdef HAVE_KILLPG +PyDoc_STRVAR(posix_killpg__doc__, +"killpg(pgid, sig)\n\n\ +Kill a process group with a signal."); + +static PyObject * +posix_killpg(PyObject *self, PyObject *args) +{ + int sig; + pid_t pgid; + /* XXX some man pages make the `pgid` parameter an int, others + a pid_t. Since getpgrp() returns a pid_t, we assume killpg should + take the same type. Moreover, pid_t is always at least as wide as + int (else compilation of this module fails), which is safe. */ + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:killpg", &pgid, &sig)) + return NULL; + if (killpg(pgid, sig) == -1) + return posix_error(); + Py_INCREF(Py_None); + return Py_None; +} +#endif #ifdef MS_WINDOWS -#define HAVE_KILL -#endif /* MS_WINDOWS */ - -#ifdef HAVE_KILL -/*[clinic input] -os.kill - - pid: pid_t - signal: Py_ssize_t - / - -Kill a process with a signal. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_kill__doc__, -"kill($module, pid, signal, /)\n" -"--\n" -"\n" -"Kill a process with a signal."); - -#define OS_KILL_METHODDEF \ - {"kill", (PyCFunction)os_kill, METH_VARARGS, os_kill__doc__}, - -static PyObject * -os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal); - -static PyObject * -os_kill(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(win32_kill__doc__, +"kill(pid, sig)\n\n\ +Kill a process with a signal."); + +static PyObject * +win32_kill(PyObject *self, PyObject *args) +{ + PyObject *result; pid_t pid; - Py_ssize_t signal; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "n:kill", - &pid, &signal)) - goto exit; - return_value = os_kill_impl(module, pid, signal); - -exit: - return return_value; -} - -static PyObject * -os_kill_impl(PyModuleDef *module, pid_t pid, Py_ssize_t signal) -/*[clinic end generated code: output=2f5c77920ed575e6 input=61a36b86ca275ab9]*/ -#ifndef MS_WINDOWS -{ - if (kill(pid, (int)signal) == -1) - return posix_error(); - Py_RETURN_NONE; -} -#else /* !MS_WINDOWS */ -{ - PyObject *result; - DWORD sig = (DWORD)signal; - DWORD err; + DWORD sig, err; HANDLE handle; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "k:kill", &pid, &sig)) + return NULL; + /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { @@ -8984,439 +6626,159 @@ CloseHandle(handle); return result; } -#endif /* !MS_WINDOWS */ -#endif /* HAVE_KILL */ - - -#ifdef HAVE_KILLPG -/*[clinic input] -os.killpg - - pgid: pid_t - signal: int - / - -Kill a process group with a signal. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_killpg__doc__, -"killpg($module, pgid, signal, /)\n" -"--\n" -"\n" -"Kill a process group with a signal."); - -#define OS_KILLPG_METHODDEF \ - {"killpg", (PyCFunction)os_killpg, METH_VARARGS, os_killpg__doc__}, - -static PyObject * -os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal); - -static PyObject * -os_killpg(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - pid_t pgid; - int signal; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "i:killpg", - &pgid, &signal)) - goto exit; - return_value = os_killpg_impl(module, pgid, signal); - -exit: - return return_value; -} - -static PyObject * -os_killpg_impl(PyModuleDef *module, pid_t pgid, int signal) -/*[clinic end generated code: output=0e05215d1c007e01 input=38b5449eb8faec19]*/ -{ - /* XXX some man pages make the `pgid` parameter an int, others - a pid_t. Since getpgrp() returns a pid_t, we assume killpg should - take the same type. Moreover, pid_t is always at least as wide as - int (else compilation of this module fails), which is safe. */ - if (killpg(pgid, signal) == -1) - return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_KILLPG */ - +#endif /* MS_WINDOWS */ #ifdef HAVE_PLOCK + #ifdef HAVE_SYS_LOCK_H #include #endif -/*[clinic input] -os.plock - op: int - / - +PyDoc_STRVAR(posix_plock__doc__, +"plock(op)\n\n\ Lock program segments into memory."); -[clinic start generated code]*/ - -PyDoc_STRVAR(os_plock__doc__, -"plock($module, op, /)\n" -"--\n" -"\n" -"Lock program segments into memory.\");"); - -#define OS_PLOCK_METHODDEF \ - {"plock", (PyCFunction)os_plock, METH_VARARGS, os_plock__doc__}, - -static PyObject * -os_plock_impl(PyModuleDef *module, int op); - -static PyObject * -os_plock(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + +static PyObject * +posix_plock(PyObject *self, PyObject *args) +{ int op; - - if (!PyArg_ParseTuple(args, - "i:plock", - &op)) - goto exit; - return_value = os_plock_impl(module, op); - -exit: - return return_value; -} - -static PyObject * -os_plock_impl(PyModuleDef *module, int op) -/*[clinic end generated code: output=2744fe4b6e5f4dbc input=e6e5e348e1525f60]*/ -{ + if (!PyArg_ParseTuple(args, "i:plock", &op)) + return NULL; if (plock(op) == -1) return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_PLOCK */ - + Py_INCREF(Py_None); + return Py_None; +} +#endif #ifdef HAVE_SETUID -/*[clinic input] -os.setuid - - uid: uid_t - / - -Set the current process's user id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setuid__doc__, -"setuid($module, uid, /)\n" -"--\n" -"\n" -"Set the current process\'s user id."); - -#define OS_SETUID_METHODDEF \ - {"setuid", (PyCFunction)os_setuid, METH_VARARGS, os_setuid__doc__}, - -static PyObject * -os_setuid_impl(PyModuleDef *module, uid_t uid); - -static PyObject * -os_setuid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_setuid__doc__, +"setuid(uid)\n\n\ +Set the current process's user id."); + +static PyObject * +posix_setuid(PyObject *self, PyObject *args) +{ uid_t uid; - - if (!PyArg_ParseTuple(args, - "O&:setuid", - _Py_Uid_Converter, &uid)) - goto exit; - return_value = os_setuid_impl(module, uid); - -exit: - return return_value; -} - -static PyObject * -os_setuid_impl(PyModuleDef *module, uid_t uid) -/*[clinic end generated code: output=aea344bc22ccf400 input=c921a3285aa22256]*/ -{ + if (!PyArg_ParseTuple(args, "O&:setuid", _Py_Uid_Converter, &uid)) + return NULL; if (setuid(uid) < 0) return posix_error(); - Py_RETURN_NONE; + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_SETUID */ #ifdef HAVE_SETEUID -/*[clinic input] -os.seteuid - - euid: uid_t - / - -Set the current process's effective user id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_seteuid__doc__, -"seteuid($module, euid, /)\n" -"--\n" -"\n" -"Set the current process\'s effective user id."); - -#define OS_SETEUID_METHODDEF \ - {"seteuid", (PyCFunction)os_seteuid, METH_VARARGS, os_seteuid__doc__}, - -static PyObject * -os_seteuid_impl(PyModuleDef *module, uid_t euid); - -static PyObject * -os_seteuid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_seteuid__doc__, +"seteuid(uid)\n\n\ +Set the current process's effective user id."); + +static PyObject * +posix_seteuid (PyObject *self, PyObject *args) +{ uid_t euid; - - if (!PyArg_ParseTuple(args, - "O&:seteuid", - _Py_Uid_Converter, &euid)) - goto exit; - return_value = os_seteuid_impl(module, euid); - -exit: - return return_value; -} - -static PyObject * -os_seteuid_impl(PyModuleDef *module, uid_t euid) -/*[clinic end generated code: output=6e824cce4f3b8a5d input=ba93d927e4781aa9]*/ -{ - if (seteuid(euid) < 0) - return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_SETEUID */ - - -#ifdef HAVE_SETEGID -/*[clinic input] -os.setegid - - egid: gid_t - / - -Set the current process's effective group id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setegid__doc__, -"setegid($module, egid, /)\n" -"--\n" -"\n" -"Set the current process\'s effective group id."); - -#define OS_SETEGID_METHODDEF \ - {"setegid", (PyCFunction)os_setegid, METH_VARARGS, os_setegid__doc__}, - -static PyObject * -os_setegid_impl(PyModuleDef *module, gid_t egid); - -static PyObject * -os_setegid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - gid_t egid; - - if (!PyArg_ParseTuple(args, - "O&:setegid", - _Py_Gid_Converter, &egid)) - goto exit; - return_value = os_setegid_impl(module, egid); - -exit: - return return_value; -} - -static PyObject * -os_setegid_impl(PyModuleDef *module, gid_t egid) -/*[clinic end generated code: output=80a32263a4d56a9c input=4080526d0ccd6ce3]*/ -{ - if (setegid(egid) < 0) - return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_SETEGID */ - - -#ifdef HAVE_SETREUID -/*[clinic input] -os.setreuid - - ruid: uid_t - euid: uid_t - / - -Set the current process's real and effective user ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setreuid__doc__, -"setreuid($module, ruid, euid, /)\n" -"--\n" -"\n" -"Set the current process\'s real and effective user ids."); - -#define OS_SETREUID_METHODDEF \ - {"setreuid", (PyCFunction)os_setreuid, METH_VARARGS, os_setreuid__doc__}, - -static PyObject * -os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid); - -static PyObject * -os_setreuid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - uid_t ruid; - uid_t euid; - - if (!PyArg_ParseTuple(args, - "O&O&:setreuid", - _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid)) - goto exit; - return_value = os_setreuid_impl(module, ruid, euid); - -exit: - return return_value; -} - -static PyObject * -os_setreuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid) -/*[clinic end generated code: output=d7f226f943dad739 input=0ca8978de663880c]*/ -{ - if (setreuid(ruid, euid) < 0) { + if (!PyArg_ParseTuple(args, "O&:seteuid", _Py_Uid_Converter, &euid)) + return NULL; + if (seteuid(euid) < 0) { return posix_error(); } else { Py_INCREF(Py_None); return Py_None; } } +#endif /* HAVE_SETEUID */ + +#ifdef HAVE_SETEGID +PyDoc_STRVAR(posix_setegid__doc__, +"setegid(gid)\n\n\ +Set the current process's effective group id."); + +static PyObject * +posix_setegid (PyObject *self, PyObject *args) +{ + gid_t egid; + if (!PyArg_ParseTuple(args, "O&:setegid", _Py_Gid_Converter, &egid)) + return NULL; + if (setegid(egid) < 0) { + return posix_error(); + } else { + Py_INCREF(Py_None); + return Py_None; + } +} +#endif /* HAVE_SETEGID */ + +#ifdef HAVE_SETREUID +PyDoc_STRVAR(posix_setreuid__doc__, +"setreuid(ruid, euid)\n\n\ +Set the current process's real and effective user ids."); + +static PyObject * +posix_setreuid (PyObject *self, PyObject *args) +{ + uid_t ruid, euid; + if (!PyArg_ParseTuple(args, "O&O&:setreuid", + _Py_Uid_Converter, &ruid, + _Py_Uid_Converter, &euid)) + return NULL; + if (setreuid(ruid, euid) < 0) { + return posix_error(); + } else { + Py_INCREF(Py_None); + return Py_None; + } +} #endif /* HAVE_SETREUID */ - #ifdef HAVE_SETREGID -/*[clinic input] -os.setregid - - rgid: gid_t - egid: gid_t - / - -Set the current process's real and effective group ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setregid__doc__, -"setregid($module, rgid, egid, /)\n" -"--\n" -"\n" -"Set the current process\'s real and effective group ids."); - -#define OS_SETREGID_METHODDEF \ - {"setregid", (PyCFunction)os_setregid, METH_VARARGS, os_setregid__doc__}, - -static PyObject * -os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid); - -static PyObject * -os_setregid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - gid_t rgid; - gid_t egid; - - if (!PyArg_ParseTuple(args, - "O&O&:setregid", - _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid)) - goto exit; - return_value = os_setregid_impl(module, rgid, egid); - -exit: - return return_value; -} - -static PyObject * -os_setregid_impl(PyModuleDef *module, gid_t rgid, gid_t egid) -/*[clinic end generated code: output=a82d9ab70f8e6562 input=c59499f72846db78]*/ -{ - if (setregid(rgid, egid) < 0) - return posix_error(); - Py_RETURN_NONE; +PyDoc_STRVAR(posix_setregid__doc__, +"setregid(rgid, egid)\n\n\ +Set the current process's real and effective group ids."); + +static PyObject * +posix_setregid (PyObject *self, PyObject *args) +{ + gid_t rgid, egid; + if (!PyArg_ParseTuple(args, "O&O&:setregid", + _Py_Gid_Converter, &rgid, + _Py_Gid_Converter, &egid)) + return NULL; + if (setregid(rgid, egid) < 0) { + return posix_error(); + } else { + Py_INCREF(Py_None); + return Py_None; + } } #endif /* HAVE_SETREGID */ - #ifdef HAVE_SETGID -/*[clinic input] -os.setgid - gid: gid_t - / - -Set the current process's group id. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setgid__doc__, -"setgid($module, gid, /)\n" -"--\n" -"\n" -"Set the current process\'s group id."); - -#define OS_SETGID_METHODDEF \ - {"setgid", (PyCFunction)os_setgid, METH_VARARGS, os_setgid__doc__}, - -static PyObject * -os_setgid_impl(PyModuleDef *module, gid_t gid); - -static PyObject * -os_setgid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_setgid__doc__, +"setgid(gid)\n\n\ +Set the current process's group id."); + +static PyObject * +posix_setgid(PyObject *self, PyObject *args) +{ gid_t gid; - - if (!PyArg_ParseTuple(args, - "O&:setgid", - _Py_Gid_Converter, &gid)) - goto exit; - return_value = os_setgid_impl(module, gid); - -exit: - return return_value; -} - -static PyObject * -os_setgid_impl(PyModuleDef *module, gid_t gid) -/*[clinic end generated code: output=08287886db435f23 input=27d30c4059045dc6]*/ -{ + if (!PyArg_ParseTuple(args, "O&:setgid", _Py_Gid_Converter, &gid)) + return NULL; if (setgid(gid) < 0) return posix_error(); - Py_RETURN_NONE; + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_SETGID */ - #ifdef HAVE_SETGROUPS -/*[clinic input] -os.setgroups - - groups: object - / - -Set the groups of the current process to list. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setgroups__doc__, -"setgroups($module, groups, /)\n" -"--\n" -"\n" -"Set the groups of the current process to list."); - -#define OS_SETGROUPS_METHODDEF \ - {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__}, - -static PyObject * -os_setgroups(PyModuleDef *module, PyObject *groups) -/*[clinic end generated code: output=0b8de65d5b3cda94 input=fa742ca3daf85a7e]*/ +PyDoc_STRVAR(posix_setgroups__doc__, +"setgroups(list)\n\n\ +Set the groups of the current process to list."); + +static PyObject * +posix_setgroups(PyObject *self, PyObject *groups) { int i, len; gid_t grouplist[MAX_GROUPS]; @@ -9517,59 +6879,23 @@ } #endif /* HAVE_WAIT3 || HAVE_WAIT4 */ - #ifdef HAVE_WAIT3 -/*[clinic input] -os.wait3 - - options: int -Wait for completion of a child process. - -Returns a tuple of information about the child process: - (pid, status, rusage) -[clinic start generated code]*/ - -PyDoc_STRVAR(os_wait3__doc__, -"wait3($module, /, options)\n" -"--\n" -"\n" -"Wait for completion of a child process.\n" -"\n" -"Returns a tuple of information about the child process:\n" -" (pid, status, rusage)"); - -#define OS_WAIT3_METHODDEF \ - {"wait3", (PyCFunction)os_wait3, METH_VARARGS|METH_KEYWORDS, os_wait3__doc__}, - -static PyObject * -os_wait3_impl(PyModuleDef *module, int options); - -static PyObject * -os_wait3(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"options", NULL}; +PyDoc_STRVAR(posix_wait3__doc__, +"wait3(options) -> (pid, status, rusage)\n\n\ +Wait for completion of a child process."); + +static PyObject * +posix_wait3(PyObject *self, PyObject *args) +{ + pid_t pid; int options; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:wait3", _keywords, - &options)) - goto exit; - return_value = os_wait3_impl(module, options); - -exit: - return return_value; -} - -static PyObject * -os_wait3_impl(PyModuleDef *module, int options) -/*[clinic end generated code: output=1f2a63b6a93cbb57 input=8ac4c56956b61710]*/ -{ - pid_t pid; struct rusage ru; WAIT_TYPE status; WAIT_STATUS_INT(status) = 0; + if (!PyArg_ParseTuple(args, "i:wait3", &options)) + return NULL; + Py_BEGIN_ALLOW_THREADS pid = wait3(&status, options, &ru); Py_END_ALLOW_THREADS @@ -9578,62 +6904,23 @@ } #endif /* HAVE_WAIT3 */ - #ifdef HAVE_WAIT4 -/*[clinic input] - -os.wait4 - - pid: pid_t - options: int - -Wait for completion of a specific child process. - -Returns a tuple of information about the child process: - (pid, status, rusage) -[clinic start generated code]*/ - -PyDoc_STRVAR(os_wait4__doc__, -"wait4($module, /, pid, options)\n" -"--\n" -"\n" -"Wait for completion of a specific child process.\n" -"\n" -"Returns a tuple of information about the child process:\n" -" (pid, status, rusage)"); - -#define OS_WAIT4_METHODDEF \ - {"wait4", (PyCFunction)os_wait4, METH_VARARGS|METH_KEYWORDS, os_wait4__doc__}, - -static PyObject * -os_wait4_impl(PyModuleDef *module, pid_t pid, int options); - -static PyObject * -os_wait4(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"pid", "options", NULL}; +PyDoc_STRVAR(posix_wait4__doc__, +"wait4(pid, options) -> (pid, status, rusage)\n\n\ +Wait for completion of a given child process."); + +static PyObject * +posix_wait4(PyObject *self, PyObject *args) +{ pid_t pid; int options; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "" _Py_PARSE_PID "i:wait4", _keywords, - &pid, &options)) - goto exit; - return_value = os_wait4_impl(module, pid, options); - -exit: - return return_value; -} - -static PyObject * -os_wait4_impl(PyModuleDef *module, pid_t pid, int options) -/*[clinic end generated code: output=20dfb05289d37dc6 input=d11deed0750600ba]*/ -{ struct rusage ru; WAIT_TYPE status; WAIT_STATUS_INT(status) = 0; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:wait4", &pid, &options)) + return NULL; + Py_BEGIN_ALLOW_THREADS pid = wait4(pid, &status, options, &ru); Py_END_ALLOW_THREADS @@ -9642,76 +6929,28 @@ } #endif /* HAVE_WAIT4 */ - #if defined(HAVE_WAITID) && !defined(__APPLE__) -/*[clinic input] -os.waitid - - idtype: idtype_t - Must be one of be P_PID, P_PGID or P_ALL. - id: id_t - The id to wait on. - options: int - Constructed from the ORing of one or more of WEXITED, WSTOPPED - or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT. - / - -Returns the result of waiting for a process or processes. - -Returns either waitid_result or None if WNOHANG is specified and there are -no children in a waitable state. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_waitid__doc__, -"waitid($module, idtype, id, options, /)\n" -"--\n" -"\n" -"Returns the result of waiting for a process or processes.\n" -"\n" -" idtype\n" -" Must be one of be P_PID, P_PGID or P_ALL.\n" -" id\n" -" The id to wait on.\n" -" options\n" -" Constructed from the ORing of one or more of WEXITED, WSTOPPED\n" -" or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n" -"\n" -"Returns either waitid_result or None if WNOHANG is specified and there are\n" -"no children in a waitable state."); - -#define OS_WAITID_METHODDEF \ - {"waitid", (PyCFunction)os_waitid, METH_VARARGS, os_waitid__doc__}, - -static PyObject * -os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options); - -static PyObject * -os_waitid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_waitid__doc__, +"waitid(idtype, id, options) -> waitid_result\n\n\ +Wait for the completion of one or more child processes.\n\n\ +idtype can be P_PID, P_PGID or P_ALL.\n\ +id specifies the pid to wait on.\n\ +options is constructed from the ORing of one or more of WEXITED, WSTOPPED\n\ +or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n\ +Returns either waitid_result or None if WNOHANG is specified and there are\n\ +no children in a waitable state."); + +static PyObject * +posix_waitid(PyObject *self, PyObject *args) +{ + PyObject *result; idtype_t idtype; id_t id; - int options; - - if (!PyArg_ParseTuple(args, - "i" _Py_PARSE_PID "i:waitid", - &idtype, &id, &options)) - goto exit; - return_value = os_waitid_impl(module, idtype, id, options); - -exit: - return return_value; -} - -static PyObject * -os_waitid_impl(PyModuleDef *module, idtype_t idtype, id_t id, int options) -/*[clinic end generated code: output=fb44bf97f01021b2 input=d8e7f76e052b7920]*/ -{ - PyObject *result; - int res; + int options, res; siginfo_t si; si.si_pid = 0; - + if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID "i:waitid", &idtype, &id, &options)) + return NULL; Py_BEGIN_ALLOW_THREADS res = waitid(idtype, id, &si, options); Py_END_ALLOW_THREADS @@ -9737,65 +6976,23 @@ return result; } -#endif /* defined(HAVE_WAITID) && !defined(__APPLE__) */ - - -#if defined(HAVE_WAITPID) -/*[clinic input] -os.waitpid - pid: pid_t - options: int - / - -Wait for completion of a given child process. - -Returns a tuple of information regarding the child process: - (pid, status) - -The options argument is ignored on Windows. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_waitpid__doc__, -"waitpid($module, pid, options, /)\n" -"--\n" -"\n" -"Wait for completion of a given child process.\n" -"\n" -"Returns a tuple of information regarding the child process:\n" -" (pid, status)\n" -"\n" -"The options argument is ignored on Windows."); - -#define OS_WAITPID_METHODDEF \ - {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, - -static PyObject * -os_waitpid_impl(PyModuleDef *module, pid_t pid, int options); - -static PyObject * -os_waitpid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +#endif + +#ifdef HAVE_WAITPID +PyDoc_STRVAR(posix_waitpid__doc__, +"waitpid(pid, options) -> (pid, status)\n\n\ +Wait for completion of a given child process."); + +static PyObject * +posix_waitpid(PyObject *self, PyObject *args) +{ pid_t pid; int options; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "i:waitpid", - &pid, &options)) - goto exit; - return_value = os_waitpid_impl(module, pid, options); - -exit: - return return_value; -} - -static PyObject * -os_waitpid_impl(PyModuleDef *module, pid_t pid, int options) -/*[clinic end generated code: output=095a6b00af70b7ac input=0bf1666b8758fda3]*/ -{ WAIT_TYPE status; WAIT_STATUS_INT(status) = 0; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:waitpid", &pid, &options)) + return NULL; Py_BEGIN_ALLOW_THREADS pid = waitpid(pid, &status, options); Py_END_ALLOW_THREADS @@ -9804,62 +7001,22 @@ return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status)); } + #elif defined(HAVE_CWAIT) + /* MS C has a variant of waitpid() that's usable for most purposes. */ -/*[clinic input] -os.waitpid - pid: Py_intptr_t - options: int - / - -Wait for completion of a given process. - -Returns a tuple of information regarding the process: - (pid, status << 8) - -The options argument is ignored on Windows. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_waitpid__doc__, -"waitpid($module, pid, options, /)\n" -"--\n" -"\n" -"Wait for completion of a given process.\n" -"\n" -"Returns a tuple of information regarding the process:\n" -" (pid, status << 8)\n" -"\n" -"The options argument is ignored on Windows."); - -#define OS_WAITPID_METHODDEF \ - {"waitpid", (PyCFunction)os_waitpid, METH_VARARGS, os_waitpid__doc__}, - -static PyObject * -os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options); - -static PyObject * -os_waitpid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_waitpid__doc__, +"waitpid(pid, options) -> (pid, status << 8)\n\n" +"Wait for completion of a given process. options is ignored on Windows."); + +static PyObject * +posix_waitpid(PyObject *self, PyObject *args) +{ Py_intptr_t pid; - int options; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_INTPTR "i:waitpid", - &pid, &options)) - goto exit; - return_value = os_waitpid_impl(module, pid, options); - -exit: - return return_value; -} - -static PyObject * -os_waitpid_impl(PyModuleDef *module, Py_intptr_t pid, int options) -/*[clinic end generated code: output=c20b95b15ad44a3a input=444c8f51cca5b862]*/ -{ - int status; - + int status, options; + + if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:waitpid", &pid, &options)) + return NULL; Py_BEGIN_ALLOW_THREADS pid = _cwait(&status, pid, options); Py_END_ALLOW_THREADS @@ -9869,43 +7026,15 @@ /* shift the status left a byte so this is more like the POSIX waitpid */ return Py_BuildValue(_Py_PARSE_INTPTR "i", pid, status << 8); } -#endif - +#endif /* HAVE_WAITPID || HAVE_CWAIT */ #ifdef HAVE_WAIT -/*[clinic input] -os.wait - -Wait for completion of a child process. - -Returns a tuple of information about the child process: - (pid, status) -[clinic start generated code]*/ - -PyDoc_STRVAR(os_wait__doc__, -"wait($module, /)\n" -"--\n" -"\n" -"Wait for completion of a child process.\n" -"\n" -"Returns a tuple of information about the child process:\n" -" (pid, status)"); - -#define OS_WAIT_METHODDEF \ - {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__}, - -static PyObject * -os_wait_impl(PyModuleDef *module); - -static PyObject * -os_wait(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_wait_impl(module); -} - -static PyObject * -os_wait_impl(PyModuleDef *module) -/*[clinic end generated code: output=2a83a9d164e7e6a8 input=03b0182d4a4700ce]*/ +PyDoc_STRVAR(posix_wait__doc__, +"wait() -> (pid, status)\n\n\ +Wait for completion of a child process."); + +static PyObject * +posix_wait(PyObject *self, PyObject *noargs) { pid_t pid; WAIT_TYPE status; @@ -9919,7 +7048,7 @@ return Py_BuildValue("Ni", PyLong_FromPid(pid), WAIT_STATUS_INT(status)); } -#endif /* HAVE_WAIT */ +#endif #if defined(HAVE_READLINK) || defined(MS_WINDOWS) @@ -9935,7 +7064,6 @@ #ifdef HAVE_READLINK -/* AC 3.5: merge win32 and not together */ static PyObject * posix_readlink(PyObject *self, PyObject *args, PyObject *kwargs) { @@ -9950,7 +7078,12 @@ path.function_name = "readlink"; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|$O&:readlink", keywords, path_converter, &path, - READLINKAT_DIR_FD_CONVERTER, &dir_fd)) +#ifdef HAVE_READLINKAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) return NULL; Py_BEGIN_ALLOW_THREADS @@ -9976,8 +7109,277 @@ return return_value; } + #endif /* HAVE_READLINK */ + +#ifdef HAVE_SYMLINK +PyDoc_STRVAR(posix_symlink__doc__, +"symlink(src, dst, target_is_directory=False, *, dir_fd=None)\n\n\ +Create a symbolic link pointing to src named dst.\n\n\ +target_is_directory is required on Windows if the target is to be\n\ + interpreted as a directory. (On Windows, symlink requires\n\ + Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n\ + target_is_directory is ignored on non-Windows platforms.\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +#if defined(MS_WINDOWS) + +/* Grab CreateSymbolicLinkW dynamically from kernel32 */ +static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD) = NULL; +static DWORD (CALLBACK *Py_CreateSymbolicLinkA)(LPSTR, LPSTR, DWORD) = NULL; + +static int +check_CreateSymbolicLink(void) +{ + HINSTANCE hKernel32; + /* only recheck */ + if (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA) + return 1; + hKernel32 = GetModuleHandleW(L"KERNEL32"); + *(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32, + "CreateSymbolicLinkW"); + *(FARPROC*)&Py_CreateSymbolicLinkA = GetProcAddress(hKernel32, + "CreateSymbolicLinkA"); + return (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA); +} + +/* Remove the last portion of the path */ +static void +_dirnameW(WCHAR *path) +{ + WCHAR *ptr; + + /* walk the path from the end until a backslash is encountered */ + for(ptr = path + wcslen(path); ptr != path; ptr--) { + if (*ptr == L'\\' || *ptr == L'/') + break; + } + *ptr = 0; +} + +/* Remove the last portion of the path */ +static void +_dirnameA(char *path) +{ + char *ptr; + + /* walk the path from the end until a backslash is encountered */ + for(ptr = path + strlen(path); ptr != path; ptr--) { + if (*ptr == '\\' || *ptr == '/') + break; + } + *ptr = 0; +} + +/* Is this path absolute? */ +static int +_is_absW(const WCHAR *path) +{ + return path[0] == L'\\' || path[0] == L'/' || path[1] == L':'; + +} + +/* Is this path absolute? */ +static int +_is_absA(const char *path) +{ + return path[0] == '\\' || path[0] == '/' || path[1] == ':'; + +} + +/* join root and rest with a backslash */ +static void +_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest) +{ + size_t root_len; + + if (_is_absW(rest)) { + wcscpy(dest_path, rest); + return; + } + + root_len = wcslen(root); + + wcscpy(dest_path, root); + if(root_len) { + dest_path[root_len] = L'\\'; + root_len++; + } + wcscpy(dest_path+root_len, rest); +} + +/* join root and rest with a backslash */ +static void +_joinA(char *dest_path, const char *root, const char *rest) +{ + size_t root_len; + + if (_is_absA(rest)) { + strcpy(dest_path, rest); + return; + } + + root_len = strlen(root); + + strcpy(dest_path, root); + if(root_len) { + dest_path[root_len] = '\\'; + root_len++; + } + strcpy(dest_path+root_len, rest); +} + +/* Return True if the path at src relative to dest is a directory */ +static int +_check_dirW(WCHAR *src, WCHAR *dest) +{ + WIN32_FILE_ATTRIBUTE_DATA src_info; + WCHAR dest_parent[MAX_PATH]; + WCHAR src_resolved[MAX_PATH] = L""; + + /* dest_parent = os.path.dirname(dest) */ + wcscpy(dest_parent, dest); + _dirnameW(dest_parent); + /* src_resolved = os.path.join(dest_parent, src) */ + _joinW(src_resolved, dest_parent, src); + return ( + GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info) + && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY + ); +} + +/* Return True if the path at src relative to dest is a directory */ +static int +_check_dirA(char *src, char *dest) +{ + WIN32_FILE_ATTRIBUTE_DATA src_info; + char dest_parent[MAX_PATH]; + char src_resolved[MAX_PATH] = ""; + + /* dest_parent = os.path.dirname(dest) */ + strcpy(dest_parent, dest); + _dirnameA(dest_parent); + /* src_resolved = os.path.join(dest_parent, src) */ + _joinA(src_resolved, dest_parent, src); + return ( + GetFileAttributesExA(src_resolved, GetFileExInfoStandard, &src_info) + && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY + ); +} + +#endif + +static PyObject * +posix_symlink(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t src; + path_t dst; + int dir_fd = DEFAULT_DIR_FD; + int target_is_directory = 0; + static char *keywords[] = {"src", "dst", "target_is_directory", + "dir_fd", NULL}; + PyObject *return_value; +#ifdef MS_WINDOWS + DWORD result; +#else + int result; +#endif + + memset(&src, 0, sizeof(src)); + src.function_name = "symlink"; + src.argument_name = "src"; + memset(&dst, 0, sizeof(dst)); + dst.function_name = "symlink"; + dst.argument_name = "dst"; + +#ifdef MS_WINDOWS + if (!check_CreateSymbolicLink()) { + PyErr_SetString(PyExc_NotImplementedError, + "CreateSymbolicLink functions not found"); + return NULL; + } + if (!win32_can_symlink) { + PyErr_SetString(PyExc_OSError, "symbolic link privilege not held"); + return NULL; + } +#endif + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|i$O&:symlink", + keywords, + path_converter, &src, + path_converter, &dst, + &target_is_directory, +#ifdef HAVE_SYMLINKAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; + + if ((src.narrow && dst.wide) || (src.wide && dst.narrow)) { + PyErr_SetString(PyExc_ValueError, + "symlink: src and dst must be the same type"); + return_value = NULL; + goto exit; + } + +#ifdef MS_WINDOWS + + Py_BEGIN_ALLOW_THREADS + if (dst.wide) { + /* if src is a directory, ensure target_is_directory==1 */ + target_is_directory |= _check_dirW(src.wide, dst.wide); + result = Py_CreateSymbolicLinkW(dst.wide, src.wide, + target_is_directory); + } + else { + /* if src is a directory, ensure target_is_directory==1 */ + target_is_directory |= _check_dirA(src.narrow, dst.narrow); + result = Py_CreateSymbolicLinkA(dst.narrow, src.narrow, + target_is_directory); + } + Py_END_ALLOW_THREADS + + if (!result) { + return_value = path_error2(&src, &dst); + goto exit; + } + +#else + + Py_BEGIN_ALLOW_THREADS +#if HAVE_SYMLINKAT + if (dir_fd != DEFAULT_DIR_FD) + result = symlinkat(src.narrow, dir_fd, dst.narrow); + else +#endif + result = symlink(src.narrow, dst.narrow); + Py_END_ALLOW_THREADS + + if (result) { + return_value = path_error2(&src, &dst); + goto exit; + } +#endif + + return_value = Py_None; + Py_INCREF(Py_None); + goto exit; /* silence "unused label" warning */ +exit: + path_cleanup(&src); + path_cleanup(&dst); + return return_value; +} + +#endif /* HAVE_SYMLINK */ + + #if !defined(HAVE_READLINK) && defined(MS_WINDOWS) static PyObject * @@ -10054,297 +7456,6 @@ #endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */ - -#ifdef HAVE_SYMLINK - -#if defined(MS_WINDOWS) - -/* Grab CreateSymbolicLinkW dynamically from kernel32 */ -static DWORD (CALLBACK *Py_CreateSymbolicLinkW)(LPWSTR, LPWSTR, DWORD) = NULL; -static DWORD (CALLBACK *Py_CreateSymbolicLinkA)(LPSTR, LPSTR, DWORD) = NULL; - -static int -check_CreateSymbolicLink(void) -{ - HINSTANCE hKernel32; - /* only recheck */ - if (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA) - return 1; - hKernel32 = GetModuleHandleW(L"KERNEL32"); - *(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32, - "CreateSymbolicLinkW"); - *(FARPROC*)&Py_CreateSymbolicLinkA = GetProcAddress(hKernel32, - "CreateSymbolicLinkA"); - return (Py_CreateSymbolicLinkW && Py_CreateSymbolicLinkA); -} - -/* Remove the last portion of the path */ -static void -_dirnameW(WCHAR *path) -{ - WCHAR *ptr; - - /* walk the path from the end until a backslash is encountered */ - for(ptr = path + wcslen(path); ptr != path; ptr--) { - if (*ptr == L'\\' || *ptr == L'/') - break; - } - *ptr = 0; -} - -/* Remove the last portion of the path */ -static void -_dirnameA(char *path) -{ - char *ptr; - - /* walk the path from the end until a backslash is encountered */ - for(ptr = path + strlen(path); ptr != path; ptr--) { - if (*ptr == '\\' || *ptr == '/') - break; - } - *ptr = 0; -} - -/* Is this path absolute? */ -static int -_is_absW(const WCHAR *path) -{ - return path[0] == L'\\' || path[0] == L'/' || path[1] == L':'; - -} - -/* Is this path absolute? */ -static int -_is_absA(const char *path) -{ - return path[0] == '\\' || path[0] == '/' || path[1] == ':'; - -} - -/* join root and rest with a backslash */ -static void -_joinW(WCHAR *dest_path, const WCHAR *root, const WCHAR *rest) -{ - size_t root_len; - - if (_is_absW(rest)) { - wcscpy(dest_path, rest); - return; - } - - root_len = wcslen(root); - - wcscpy(dest_path, root); - if(root_len) { - dest_path[root_len] = L'\\'; - root_len++; - } - wcscpy(dest_path+root_len, rest); -} - -/* join root and rest with a backslash */ -static void -_joinA(char *dest_path, const char *root, const char *rest) -{ - size_t root_len; - - if (_is_absA(rest)) { - strcpy(dest_path, rest); - return; - } - - root_len = strlen(root); - - strcpy(dest_path, root); - if(root_len) { - dest_path[root_len] = '\\'; - root_len++; - } - strcpy(dest_path+root_len, rest); -} - -/* Return True if the path at src relative to dest is a directory */ -static int -_check_dirW(WCHAR *src, WCHAR *dest) -{ - WIN32_FILE_ATTRIBUTE_DATA src_info; - WCHAR dest_parent[MAX_PATH]; - WCHAR src_resolved[MAX_PATH] = L""; - - /* dest_parent = os.path.dirname(dest) */ - wcscpy(dest_parent, dest); - _dirnameW(dest_parent); - /* src_resolved = os.path.join(dest_parent, src) */ - _joinW(src_resolved, dest_parent, src); - return ( - GetFileAttributesExW(src_resolved, GetFileExInfoStandard, &src_info) - && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ); -} - -/* Return True if the path at src relative to dest is a directory */ -static int -_check_dirA(char *src, char *dest) -{ - WIN32_FILE_ATTRIBUTE_DATA src_info; - char dest_parent[MAX_PATH]; - char src_resolved[MAX_PATH] = ""; - - /* dest_parent = os.path.dirname(dest) */ - strcpy(dest_parent, dest); - _dirnameA(dest_parent); - /* src_resolved = os.path.join(dest_parent, src) */ - _joinA(src_resolved, dest_parent, src); - return ( - GetFileAttributesExA(src_resolved, GetFileExInfoStandard, &src_info) - && src_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ); -} -#endif - - -/*[clinic input] -os.symlink - src: path_t - dst: path_t - target_is_directory: bool = False - * - dir_fd: dir_fd(requires='symlinkat')=None - -# "symlink(src, dst, target_is_directory=False, *, dir_fd=None)\n\n\ - -Create a symbolic link pointing to src named dst. - -target_is_directory is required on Windows if the target is to be - interpreted as a directory. (On Windows, symlink requires - Windows 6.0 or greater, and raises a NotImplementedError otherwise.) - target_is_directory is ignored on non-Windows platforms. - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_symlink__doc__, -"symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n" -"--\n" -"\n" -"Create a symbolic link pointing to src named dst.\n" -"\n" -"target_is_directory is required on Windows if the target is to be\n" -" interpreted as a directory. (On Windows, symlink requires\n" -" Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n" -" target_is_directory is ignored on non-Windows platforms.\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_SYMLINK_METHODDEF \ - {"symlink", (PyCFunction)os_symlink, METH_VARARGS|METH_KEYWORDS, os_symlink__doc__}, - -static PyObject * -os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst, int target_is_directory, int dir_fd); - -static PyObject * -os_symlink(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL}; - path_t src = PATH_T_INITIALIZE("symlink", "src", 0, 0); - path_t dst = PATH_T_INITIALIZE("symlink", "dst", 0, 0); - int target_is_directory = 0; - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|p$O&:symlink", _keywords, - path_converter, &src, path_converter, &dst, &target_is_directory, SYMLINKAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd); - -exit: - /* Cleanup for src */ - path_cleanup(&src); - /* Cleanup for dst */ - path_cleanup(&dst); - - return return_value; -} - -static PyObject * -os_symlink_impl(PyModuleDef *module, path_t *src, path_t *dst, int target_is_directory, int dir_fd) -/*[clinic end generated code: output=1a31e6d88aafe9b6 input=e820ec4472547bc3]*/ -{ -#ifdef MS_WINDOWS - DWORD result; -#else - int result; -#endif - -#ifdef MS_WINDOWS - if (!check_CreateSymbolicLink()) { - PyErr_SetString(PyExc_NotImplementedError, - "CreateSymbolicLink functions not found"); - return NULL; - } - if (!win32_can_symlink) { - PyErr_SetString(PyExc_OSError, "symbolic link privilege not held"); - return NULL; - } -#endif - - if ((src->narrow && dst->wide) || (src->wide && dst->narrow)) { - PyErr_SetString(PyExc_ValueError, - "symlink: src and dst must be the same type"); - return NULL; - } - -#ifdef MS_WINDOWS - - Py_BEGIN_ALLOW_THREADS - if (dst->wide) { - /* if src is a directory, ensure target_is_directory==1 */ - target_is_directory |= _check_dirW(src->wide, dst->wide); - result = Py_CreateSymbolicLinkW(dst->wide, src->wide, - target_is_directory); - } - else { - /* if src is a directory, ensure target_is_directory==1 */ - target_is_directory |= _check_dirA(src->narrow, dst->narrow); - result = Py_CreateSymbolicLinkA(dst->narrow, src->narrow, - target_is_directory); - } - Py_END_ALLOW_THREADS - - if (!result) - return path_error2(src, dst); - -#else - - Py_BEGIN_ALLOW_THREADS -#if HAVE_SYMLINKAT - if (dir_fd != DEFAULT_DIR_FD) - result = symlinkat(src->narrow, dir_fd, dst->narrow); - else -#endif - result = symlink(src->narrow, dst->narrow); - Py_END_ALLOW_THREADS - - if (result) - return path_error2(src, dst); -#endif - - Py_RETURN_NONE; -} -#endif /* HAVE_SYMLINK */ - - - - static PyStructSequence_Field times_result_fields[] = { {"user", "user time"}, {"system", "system time"}, @@ -10408,48 +7519,15 @@ return value; } - -#ifndef MS_WINDOWS -#define NEED_TICKS_PER_SECOND -static long ticks_per_second = -1; -#endif /* MS_WINDOWS */ - -/*[clinic input] -os.times - -Return a collection containing process timing information. - -The object returned behaves like a named tuple with these fields: - (utime, stime, cutime, cstime, elapsed_time) -All fields are floating point numbers. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_times__doc__, -"times($module, /)\n" -"--\n" -"\n" -"Return a collection containing process timing information.\n" -"\n" -"The object returned behaves like a named tuple with these fields:\n" -" (utime, stime, cutime, cstime, elapsed_time)\n" -"All fields are floating point numbers."); - -#define OS_TIMES_METHODDEF \ - {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__}, - -static PyObject * -os_times_impl(PyModuleDef *module); - -static PyObject * -os_times(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_times_impl(module); -} - -static PyObject * -os_times_impl(PyModuleDef *module) -/*[clinic end generated code: output=b86896d031a9b768 input=2bf9df3d6ab2e48b]*/ -#ifdef MS_WINDOWS +PyDoc_STRVAR(posix_times__doc__, +"times() -> times_result\n\n\ +Return an object containing floating point numbers indicating process\n\ +times. The object behaves like a named tuple with these fields:\n\ + (utime, stime, cutime, cstime, elapsed_time)"); + +#if defined(MS_WINDOWS) +static PyObject * +posix_times(PyObject *self, PyObject *noargs) { FILETIME create, exit, kernel, user; HANDLE hProc; @@ -10469,10 +7547,12 @@ (double)0, (double)0); } -#else /* MS_WINDOWS */ -{ - - +#else /* Not Windows */ +#define NEED_TICKS_PER_SECOND +static long ticks_per_second = -1; +static PyObject * +posix_times(PyObject *self, PyObject *noargs) +{ struct tms t; clock_t c; errno = 0; @@ -10486,53 +7566,23 @@ (double)t.tms_cstime / ticks_per_second, (double)c / ticks_per_second); } -#endif /* MS_WINDOWS */ +#endif + #endif /* HAVE_TIMES */ #ifdef HAVE_GETSID -/*[clinic input] -os.getsid - - pid: pid_t - / - -Call the system call getsid(pid) and return the result. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getsid__doc__, -"getsid($module, pid, /)\n" -"--\n" -"\n" -"Call the system call getsid(pid) and return the result."); - -#define OS_GETSID_METHODDEF \ - {"getsid", (PyCFunction)os_getsid, METH_VARARGS, os_getsid__doc__}, - -static PyObject * -os_getsid_impl(PyModuleDef *module, pid_t pid); - -static PyObject * -os_getsid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_getsid__doc__, +"getsid(pid) -> sid\n\n\ +Call the system call getsid()."); + +static PyObject * +posix_getsid(PyObject *self, PyObject *args) +{ pid_t pid; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID ":getsid", - &pid)) - goto exit; - return_value = os_getsid_impl(module, pid); - -exit: - return return_value; -} - -static PyObject * -os_getsid_impl(PyModuleDef *module, pid_t pid) -/*[clinic end generated code: output=ea8390f395f4e0e1 input=eeb2b923a30ce04e]*/ -{ int sid; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID ":getsid", &pid)) + return NULL; sid = getsid(pid); if (sid < 0) return posix_error(); @@ -10542,189 +7592,76 @@ #ifdef HAVE_SETSID -/*[clinic input] -os.setsid - -Call the system call setsid(). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setsid__doc__, -"setsid($module, /)\n" -"--\n" -"\n" -"Call the system call setsid()."); - -#define OS_SETSID_METHODDEF \ - {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__}, - -static PyObject * -os_setsid_impl(PyModuleDef *module); - -static PyObject * -os_setsid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_setsid_impl(module); -} - -static PyObject * -os_setsid_impl(PyModuleDef *module) -/*[clinic end generated code: output=2a9a1435d8d764d5 input=5fff45858e2f0776]*/ +PyDoc_STRVAR(posix_setsid__doc__, +"setsid()\n\n\ +Call the system call setsid()."); + +static PyObject * +posix_setsid(PyObject *self, PyObject *noargs) { if (setsid() < 0) return posix_error(); - Py_RETURN_NONE; + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_SETSID */ - #ifdef HAVE_SETPGID -/*[clinic input] -os.setpgid - - pid: pid_t - pgrp: pid_t - / - -Call the system call setpgid(pid, pgrp). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setpgid__doc__, -"setpgid($module, pid, pgrp, /)\n" -"--\n" -"\n" -"Call the system call setpgid(pid, pgrp)."); - -#define OS_SETPGID_METHODDEF \ - {"setpgid", (PyCFunction)os_setpgid, METH_VARARGS, os_setpgid__doc__}, - -static PyObject * -os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp); - -static PyObject * -os_setpgid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_setpgid__doc__, +"setpgid(pid, pgrp)\n\n\ +Call the system call setpgid()."); + +static PyObject * +posix_setpgid(PyObject *self, PyObject *args) +{ pid_t pid; - pid_t pgrp; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid", - &pid, &pgrp)) - goto exit; - return_value = os_setpgid_impl(module, pid, pgrp); - -exit: - return return_value; -} - -static PyObject * -os_setpgid_impl(PyModuleDef *module, pid_t pid, pid_t pgrp) -/*[clinic end generated code: output=7ad79b725f890e1f input=fceb395eca572e1a]*/ -{ + int pgrp; + if (!PyArg_ParseTuple(args, _Py_PARSE_PID "i:setpgid", &pid, &pgrp)) + return NULL; if (setpgid(pid, pgrp) < 0) return posix_error(); - Py_RETURN_NONE; + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_SETPGID */ #ifdef HAVE_TCGETPGRP -/*[clinic input] -os.tcgetpgrp - - fd: int - / - -Return the process group associated with the terminal specified by fd. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_tcgetpgrp__doc__, -"tcgetpgrp($module, fd, /)\n" -"--\n" -"\n" -"Return the process group associated with the terminal specified by fd."); - -#define OS_TCGETPGRP_METHODDEF \ - {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_VARARGS, os_tcgetpgrp__doc__}, - -static PyObject * -os_tcgetpgrp_impl(PyModuleDef *module, int fd); - -static PyObject * -os_tcgetpgrp(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - - if (!PyArg_ParseTuple(args, - "i:tcgetpgrp", - &fd)) - goto exit; - return_value = os_tcgetpgrp_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_tcgetpgrp_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=abcf52ed4c8d22cb input=7f6c18eac10ada86]*/ -{ - pid_t pgid = tcgetpgrp(fd); - if (pgid < 0) - return posix_error(); - return PyLong_FromPid(pgid); -} -#endif /* HAVE_TCGETPGRP */ - - -#ifdef HAVE_TCSETPGRP -/*[clinic input] -os.tcsetpgrp - - fd: int - pgid: pid_t - / - -Set the process group associated with the terminal specified by fd. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_tcsetpgrp__doc__, -"tcsetpgrp($module, fd, pgid, /)\n" -"--\n" -"\n" -"Set the process group associated with the terminal specified by fd."); - -#define OS_TCSETPGRP_METHODDEF \ - {"tcsetpgrp", (PyCFunction)os_tcsetpgrp, METH_VARARGS, os_tcsetpgrp__doc__}, - -static PyObject * -os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid); - -static PyObject * -os_tcsetpgrp(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_tcgetpgrp__doc__, +"tcgetpgrp(fd) -> pgid\n\n\ +Return the process group associated with the terminal given by a fd."); + +static PyObject * +posix_tcgetpgrp(PyObject *self, PyObject *args) +{ int fd; pid_t pgid; - - if (!PyArg_ParseTuple(args, - "i" _Py_PARSE_PID ":tcsetpgrp", - &fd, &pgid)) - goto exit; - return_value = os_tcsetpgrp_impl(module, fd, pgid); - -exit: - return return_value; -} - -static PyObject * -os_tcsetpgrp_impl(PyModuleDef *module, int fd, pid_t pgid) -/*[clinic end generated code: output=76f9bb8fd00f20f5 input=5bdc997c6a619020]*/ -{ + if (!PyArg_ParseTuple(args, "i:tcgetpgrp", &fd)) + return NULL; + pgid = tcgetpgrp(fd); + if (pgid < 0) + return posix_error(); + return PyLong_FromPid(pgid); +} +#endif /* HAVE_TCGETPGRP */ + + +#ifdef HAVE_TCSETPGRP +PyDoc_STRVAR(posix_tcsetpgrp__doc__, +"tcsetpgrp(fd, pgid)\n\n\ +Set the process group associated with the terminal given by a fd."); + +static PyObject * +posix_tcsetpgrp(PyObject *self, PyObject *args) +{ + int fd; + pid_t pgid; + if (!PyArg_ParseTuple(args, "i" _Py_PARSE_PID ":tcsetpgrp", &fd, &pgid)) + return NULL; if (tcsetpgrp(fd, pgid) < 0) return posix_error(); - Py_RETURN_NONE; + Py_INCREF(Py_None); + return Py_None; } #endif /* HAVE_TCSETPGRP */ @@ -10734,81 +7671,44 @@ extern int _Py_open_cloexec_works; #endif - -/*[clinic input] -os.open -> int - path: path_t - flags: int - mode: int = 0o777 - * - dir_fd: dir_fd(requires='openat') = None - -# "open(path, flags, mode=0o777, *, dir_fd=None)\n\n\ - -Open a file for low level IO. Returns a file descriptor (integer). - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_open__doc__, -"open($module, /, path, flags, mode=511, *, dir_fd=None)\n" -"--\n" -"\n" -"Open a file for low level IO. Returns a file descriptor (integer).\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_OPEN_METHODDEF \ - {"open", (PyCFunction)os_open, METH_VARARGS|METH_KEYWORDS, os_open__doc__}, - -static int -os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd); - -static PyObject * -os_open(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ +PyDoc_STRVAR(posix_open__doc__, +"open(path, flags, mode=0o777, *, dir_fd=None)\n\n\ +Open a file for low level IO. Returns a file handle (integer).\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +static PyObject * +posix_open(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int flags; + int mode = 0777; + int dir_fd = DEFAULT_DIR_FD; + int fd; PyObject *return_value = NULL; - static char *_keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("open", "path", 0, 0); - int flags; - int mode = 511; - int dir_fd = DEFAULT_DIR_FD; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&i|i$O&:open", _keywords, - path_converter, &path, &flags, &mode, OPENAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - _return_value = os_open_impl(module, &path, flags, mode, dir_fd); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong((long)_return_value); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static int -os_open_impl(PyModuleDef *module, path_t *path, int flags, int mode, int dir_fd) -/*[clinic end generated code: output=05b68fc4ed5e29c9 input=ad8623b29acd2934]*/ -{ - int fd; - + static char *keywords[] = {"path", "flags", "mode", "dir_fd", NULL}; #ifdef O_CLOEXEC int *atomic_flag_works = &_Py_open_cloexec_works; #elif !defined(MS_WINDOWS) int *atomic_flag_works = NULL; #endif + memset(&path, 0, sizeof(path)); + path.function_name = "open"; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&i|i$O&:open", keywords, + path_converter, &path, + &flags, &mode, +#ifdef HAVE_OPENAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; + #ifdef MS_WINDOWS flags |= O_NOINHERIT; #elif defined(O_CLOEXEC) @@ -10817,76 +7717,51 @@ Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - if (path->wide) - fd = _wopen(path->wide, flags, mode); + if (path.wide) + fd = _wopen(path.wide, flags, mode); else #endif #ifdef HAVE_OPENAT if (dir_fd != DEFAULT_DIR_FD) - fd = openat(dir_fd, path->narrow, flags, mode); + fd = openat(dir_fd, path.narrow, flags, mode); else #endif - fd = open(path->narrow, flags, mode); + fd = open(path.narrow, flags, mode); Py_END_ALLOW_THREADS if (fd == -1) { - PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path->object); - return -1; + PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path.object); + goto exit; } #ifndef MS_WINDOWS if (_Py_set_inheritable(fd, 0, atomic_flag_works) < 0) { close(fd); - return -1; - } -#endif - - return fd; -} - - -/*[clinic input] -os.close - - fd: int - -Close a file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_close__doc__, -"close($module, /, fd)\n" -"--\n" -"\n" -"Close a file descriptor."); - -#define OS_CLOSE_METHODDEF \ - {"close", (PyCFunction)os_close, METH_VARARGS|METH_KEYWORDS, os_close__doc__}, - -static PyObject * -os_close_impl(PyModuleDef *module, int fd); - -static PyObject * -os_close(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; - int fd; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:close", _keywords, - &fd)) goto exit; - return_value = os_close_impl(module, fd); + } +#endif + + return_value = PyLong_FromLong((long)fd); exit: + path_cleanup(&path); return return_value; } -static PyObject * -os_close_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=927004e29ad55808 input=2bc42451ca5c3223]*/ -{ - int res; +PyDoc_STRVAR(posix_close__doc__, +"close(fd)\n\n\ +Close a file descriptor (for low level IO)."); + +/* +The underscore at end of function name avoids a name clash with the libc +function posix_close. +*/ +static PyObject * +posix_close_(PyObject *self, PyObject *args) +{ + int fd, res; + if (!PyArg_ParseTuple(args, "i:close", &fd)) + return NULL; if (!_PyVerify_fd(fd)) return posix_error(); Py_BEGIN_ALLOW_THREADS @@ -10894,56 +7769,23 @@ Py_END_ALLOW_THREADS if (res < 0) return posix_error(); - Py_RETURN_NONE; -} - - -/*[clinic input] -os.closerange - - fd_low: int - fd_high: int - / - -Closes all file descriptors in [fd_low, fd_high), ignoring errors. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_closerange__doc__, -"closerange($module, fd_low, fd_high, /)\n" -"--\n" -"\n" -"Closes all file descriptors in [fd_low, fd_high), ignoring errors."); - -#define OS_CLOSERANGE_METHODDEF \ - {"closerange", (PyCFunction)os_closerange, METH_VARARGS, os_closerange__doc__}, - -static PyObject * -os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high); - -static PyObject * -os_closerange(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd_low; - int fd_high; - - if (!PyArg_ParseTuple(args, - "ii:closerange", - &fd_low, &fd_high)) - goto exit; - return_value = os_closerange_impl(module, fd_low, fd_high); - -exit: - return return_value; -} - -static PyObject * -os_closerange_impl(PyModuleDef *module, int fd_low, int fd_high) -/*[clinic end generated code: output=0a929ece386811c3 input=5855a3d053ebd4ec]*/ -{ - int i; + Py_INCREF(Py_None); + return Py_None; +} + + +PyDoc_STRVAR(posix_closerange__doc__, +"closerange(fd_low, fd_high)\n\n\ +Closes all file descriptors in [fd_low, fd_high), ignoring errors."); + +static PyObject * +posix_closerange(PyObject *self, PyObject *args) +{ + int fd_from, fd_to, i; + if (!PyArg_ParseTuple(args, "ii:closerange", &fd_from, &fd_to)) + return NULL; Py_BEGIN_ALLOW_THREADS - for (i = fd_low; i < fd_high; i++) + for (i = fd_from; i < fd_to; i++) if (_PyVerify_fd(i)) close(i); Py_END_ALLOW_THREADS @@ -10951,99 +7793,36 @@ } -/*[clinic input] -os.dup -> int - - fd: int - / - -Return a duplicate of a file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_dup__doc__, -"dup($module, fd, /)\n" -"--\n" -"\n" -"Return a duplicate of a file descriptor."); - -#define OS_DUP_METHODDEF \ - {"dup", (PyCFunction)os_dup, METH_VARARGS, os_dup__doc__}, - -static int -os_dup_impl(PyModuleDef *module, int fd); - -static PyObject * -os_dup(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_dup__doc__, +"dup(fd) -> fd2\n\n\ +Return a duplicate of a file descriptor."); + +static PyObject * +posix_dup(PyObject *self, PyObject *args) +{ int fd; - int _return_value; - - if (!PyArg_ParseTuple(args, - "i:dup", - &fd)) - goto exit; - _return_value = os_dup_impl(module, fd); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_dup_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=75943e057b25e1bd input=6f10f7ea97f7852a]*/ -{ - return _Py_dup(fd); -} - - -/*[clinic input] -os.dup2 - fd: int - fd2: int - inheritable: bool=True - -Duplicate file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_dup2__doc__, -"dup2($module, /, fd, fd2, inheritable=True)\n" -"--\n" -"\n" -"Duplicate file descriptor."); - -#define OS_DUP2_METHODDEF \ - {"dup2", (PyCFunction)os_dup2, METH_VARARGS|METH_KEYWORDS, os_dup2__doc__}, - -static PyObject * -os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable); - -static PyObject * -os_dup2(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", "fd2", "inheritable", NULL}; - int fd; - int fd2; + + if (!PyArg_ParseTuple(args, "i:dup", &fd)) + return NULL; + + fd = _Py_dup(fd); + if (fd == -1) + return NULL; + + return PyLong_FromLong((long)fd); +} + + +PyDoc_STRVAR(posix_dup2__doc__, +"dup2(old_fd, new_fd)\n\n\ +Duplicate file descriptor."); + +static PyObject * +posix_dup2(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"fd", "fd2", "inheritable", NULL}; + int fd, fd2; int inheritable = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "ii|p:dup2", _keywords, - &fd, &fd2, &inheritable)) - goto exit; - return_value = os_dup2_impl(module, fd, fd2, inheritable); - -exit: - return return_value; -} - -static PyObject * -os_dup2_impl(PyModuleDef *module, int fd, int fd2, int inheritable) -/*[clinic end generated code: output=531e482dd11a99a0 input=76e96f511be0352f]*/ -{ int res; #if defined(HAVE_DUP3) && \ !(defined(HAVE_FCNTL_H) && defined(F_DUP2FD_CLOEXEC)) @@ -11051,6 +7830,10 @@ int dup3_works = -1; #endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|i:dup2", keywords, + &fd, &fd2, &inheritable)) + return NULL; + if (!_PyVerify_fd_dup2(fd, fd2)) return posix_error(); @@ -11111,247 +7894,133 @@ #endif + Py_INCREF(Py_None); + return Py_None; +} + +#ifdef HAVE_LOCKF +PyDoc_STRVAR(posix_lockf__doc__, +"lockf(fd, cmd, len)\n\n\ +Apply, test or remove a POSIX lock on an open file descriptor.\n\n\ +fd is an open file descriptor.\n\ +cmd specifies the command to use - one of F_LOCK, F_TLOCK, F_ULOCK or\n\ +F_TEST.\n\ +len specifies the section of the file to lock."); + +static PyObject * +posix_lockf(PyObject *self, PyObject *args) +{ + int fd, cmd, res; + off_t len; + if (!PyArg_ParseTuple(args, "iiO&:lockf", + &fd, &cmd, _parse_off_t, &len)) + return NULL; + + Py_BEGIN_ALLOW_THREADS + res = lockf(fd, cmd, len); + Py_END_ALLOW_THREADS + + if (res < 0) + return posix_error(); + Py_RETURN_NONE; } - - -#ifdef HAVE_LOCKF -/*[clinic input] -os.lockf - - fd: int - An open file descriptor. - command: int - One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST. - length: Py_off_t - The number of bytes to lock, starting at the current position. - / - -Apply, test or remove a POSIX lock on an open file descriptor. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lockf__doc__, -"lockf($module, fd, command, length, /)\n" -"--\n" -"\n" -"Apply, test or remove a POSIX lock on an open file descriptor.\n" -"\n" -" fd\n" -" An open file descriptor.\n" -" command\n" -" One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n" -" length\n" -" The number of bytes to lock, starting at the current position."); - -#define OS_LOCKF_METHODDEF \ - {"lockf", (PyCFunction)os_lockf, METH_VARARGS, os_lockf__doc__}, - -static PyObject * -os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length); - -static PyObject * -os_lockf(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - int command; - Py_off_t length; - - if (!PyArg_ParseTuple(args, - "iiO&:lockf", - &fd, &command, Py_off_t_converter, &length)) - goto exit; - return_value = os_lockf_impl(module, fd, command, length); - -exit: - return return_value; -} - -static PyObject * -os_lockf_impl(PyModuleDef *module, int fd, int command, Py_off_t length) -/*[clinic end generated code: output=1b28346ac7335c0f input=65da41d2106e9b79]*/ -{ - int res; - - Py_BEGIN_ALLOW_THREADS - res = lockf(fd, command, length); - Py_END_ALLOW_THREADS - - if (res < 0) - return posix_error(); - - Py_RETURN_NONE; -} -#endif /* HAVE_LOCKF */ - - -/*[clinic input] -os.lseek -> Py_off_t - - fd: int - position: Py_off_t - how: int - / - -Set the position of a file descriptor. Return the new position. - -Return the new cursor position in number of bytes -relative to the beginning of the file. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_lseek__doc__, -"lseek($module, fd, position, how, /)\n" -"--\n" -"\n" -"Set the position of a file descriptor. Return the new position.\n" -"\n" -"Return the new cursor position in number of bytes\n" -"relative to the beginning of the file."); - -#define OS_LSEEK_METHODDEF \ - {"lseek", (PyCFunction)os_lseek, METH_VARARGS, os_lseek__doc__}, - -static Py_off_t -os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how); - -static PyObject * -os_lseek(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - Py_off_t position; - int how; - Py_off_t _return_value; - - if (!PyArg_ParseTuple(args, - "iO&i:lseek", - &fd, Py_off_t_converter, &position, &how)) - goto exit; - _return_value = os_lseek_impl(module, fd, position, how); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromPy_off_t(_return_value); - -exit: - return return_value; -} - -static Py_off_t -os_lseek_impl(PyModuleDef *module, int fd, Py_off_t position, int how) -/*[clinic end generated code: output=88cfc146f55667af input=902654ad3f96a6d3]*/ -{ - Py_off_t result; - - if (!_PyVerify_fd(fd)) { - posix_error(); - return -1; - } +#endif + + +PyDoc_STRVAR(posix_lseek__doc__, +"lseek(fd, pos, how) -> newpos\n\n\ +Set the current position of a file descriptor.\n\ +Return the new cursor position in bytes, starting from the beginning."); + +static PyObject * +posix_lseek(PyObject *self, PyObject *args) +{ + int fd, how; +#ifdef MS_WINDOWS + PY_LONG_LONG pos, res; +#else + off_t pos, res; +#endif + PyObject *posobj; + if (!PyArg_ParseTuple(args, "iOi:lseek", &fd, &posobj, &how)) + return NULL; #ifdef SEEK_SET /* Turn 0, 1, 2 into SEEK_{SET,CUR,END} */ switch (how) { - case 0: how = SEEK_SET; break; - case 1: how = SEEK_CUR; break; - case 2: how = SEEK_END; break; + case 0: how = SEEK_SET; break; + case 1: how = SEEK_CUR; break; + case 2: how = SEEK_END; break; } #endif /* SEEK_END */ +#if !defined(HAVE_LARGEFILE_SUPPORT) + pos = PyLong_AsLong(posobj); +#else + pos = PyLong_AsLongLong(posobj); +#endif if (PyErr_Occurred()) - return -1; - - if (!_PyVerify_fd(fd)) { - posix_error(); - return -1; - } + return NULL; + + if (!_PyVerify_fd(fd)) + return posix_error(); Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - result = _lseeki64(fd, position, how); -#else - result = lseek(fd, position, how); + res = _lseeki64(fd, pos, how); +#else + res = lseek(fd, pos, how); #endif Py_END_ALLOW_THREADS - if (result < 0) - posix_error(); - - return result; -} - - -/*[clinic input] -os.read - fd: int - length: Py_ssize_t - / - -Read from a file descriptor. Returns a bytes object. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_read__doc__, -"read($module, fd, length, /)\n" -"--\n" -"\n" -"Read from a file descriptor. Returns a bytes object."); - -#define OS_READ_METHODDEF \ - {"read", (PyCFunction)os_read, METH_VARARGS, os_read__doc__}, - -static PyObject * -os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length); - -static PyObject * -os_read(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + if (res < 0) + return posix_error(); + +#if !defined(HAVE_LARGEFILE_SUPPORT) + return PyLong_FromLong(res); +#else + return PyLong_FromLongLong(res); +#endif +} + + +PyDoc_STRVAR(posix_read__doc__, +"read(fd, buffersize) -> bytes\n\n\ +Read a file descriptor."); + +static PyObject * +posix_read(PyObject *self, PyObject *args) +{ int fd; - Py_ssize_t length; - - if (!PyArg_ParseTuple(args, - "in:read", - &fd, &length)) - goto exit; - return_value = os_read_impl(module, fd, length); - -exit: - return return_value; -} - -static PyObject * -os_read_impl(PyModuleDef *module, int fd, Py_ssize_t length) -/*[clinic end generated code: output=1f3bc27260a24968 input=1df2eaa27c0bf1d3]*/ -{ + Py_ssize_t size; Py_ssize_t n; PyObject *buffer; - - if (length < 0) { + if (!PyArg_ParseTuple(args, "in:read", &fd, &size)) + return NULL; + if (!_PyVerify_fd(fd)) + return posix_error(); +#ifdef MS_WINDOWS + if (size > INT_MAX) + size = INT_MAX; +#endif + if (size < 0) { errno = EINVAL; return posix_error(); } - if (!_PyVerify_fd(fd)) - return posix_error(); - + buffer = PyBytes_FromStringAndSize((char *)NULL, size); + if (buffer == NULL) + return NULL; + Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS - #define READ_CAST (int) - if (length > INT_MAX) - length = INT_MAX; -#else - #define READ_CAST -#endif - - buffer = PyBytes_FromStringAndSize((char *)NULL, length); - if (buffer == NULL) - return NULL; - Py_BEGIN_ALLOW_THREADS - n = read(fd, PyBytes_AS_STRING(buffer), READ_CAST length); + n = read(fd, PyBytes_AS_STRING(buffer), (int)size); +#else + n = read(fd, PyBytes_AS_STRING(buffer), size); +#endif Py_END_ALLOW_THREADS - if (n < 0) { Py_DECREF(buffer); return posix_error(); } - - if (n != length) + if (n != size) _PyBytes_Resize(&buffer, n); - return buffer; } @@ -11413,163 +8082,70 @@ } #endif - #ifdef HAVE_READV -/*[clinic input] -os.readv -> Py_ssize_t - - fd: int - buffers: object - / - -Read from a file descriptor fd into an iterable of buffers. - -The buffers should be mutable buffers accepting bytes. -readv will transfer data into each buffer until it is full -and then move on to the next buffer in the sequence to hold -the rest of the data. - -readv returns the total number of bytes read, -which may be less than the total capacity of all the buffers. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_readv__doc__, -"readv($module, fd, buffers, /)\n" -"--\n" -"\n" -"Read from a file descriptor fd into an iterable of buffers.\n" -"\n" -"The buffers should be mutable buffers accepting bytes.\n" -"readv will transfer data into each buffer until it is full\n" -"and then move on to the next buffer in the sequence to hold\n" -"the rest of the data.\n" -"\n" -"readv returns the total number of bytes read,\n" -"which may be less than the total capacity of all the buffers."); - -#define OS_READV_METHODDEF \ - {"readv", (PyCFunction)os_readv, METH_VARARGS, os_readv__doc__}, - -static Py_ssize_t -os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers); - -static PyObject * -os_readv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - PyObject *buffers; - Py_ssize_t _return_value; - - if (!PyArg_ParseTuple(args, - "iO:readv", - &fd, &buffers)) - goto exit; - _return_value = os_readv_impl(module, fd, buffers); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - return return_value; -} - -static Py_ssize_t -os_readv_impl(PyModuleDef *module, int fd, PyObject *buffers) -/*[clinic end generated code: output=72748b1c32a6e2a1 input=e679eb5dbfa0357d]*/ -{ - int cnt; +PyDoc_STRVAR(posix_readv__doc__, +"readv(fd, buffers) -> bytesread\n\n\ +Read from a file descriptor fd into a number of mutable, bytes-like\n\ +objects (\"buffers\"). readv will transfer data into each buffer\n\ +until it is full and then move on to the next buffer in the sequence\n\ +to hold the rest of the data.\n\n\ +readv returns the total number of bytes read (which may be less than\n\ +the total capacity of all the buffers."); + +static PyObject * +posix_readv(PyObject *self, PyObject *args) +{ + int fd, cnt; Py_ssize_t n; + PyObject *seq; struct iovec *iov; Py_buffer *buf; - if (!PySequence_Check(buffers)) { + if (!PyArg_ParseTuple(args, "iO:readv", &fd, &seq)) + return NULL; + if (!PySequence_Check(seq)) { PyErr_SetString(PyExc_TypeError, "readv() arg 2 must be a sequence"); - return -1; - } - - cnt = PySequence_Size(buffers); - - if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_WRITABLE) < 0) - return -1; + return NULL; + } + cnt = PySequence_Size(seq); + + if (iov_setup(&iov, &buf, seq, cnt, PyBUF_WRITABLE) < 0) + return NULL; Py_BEGIN_ALLOW_THREADS n = readv(fd, iov, cnt); Py_END_ALLOW_THREADS iov_cleanup(iov, buf, cnt); - if (n < 0) { - posix_error(); - return -1; - } - - return n; -} -#endif /* HAVE_READV */ - + if (n < 0) + return posix_error(); + + return PyLong_FromSsize_t(n); +} +#endif #ifdef HAVE_PREAD -/*[clinic input] -# TODO length should be size_t! but Python doesn't support parsing size_t yet. -os.pread - - fd: int - length: int - offset: Py_off_t - / - -Read a number of bytes from a file descriptor starting at a particular offset. - -Read length bytes from file descriptor fd, starting at offset bytes from -the beginning of the file. The file offset remains unchanged. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_pread__doc__, -"pread($module, fd, length, offset, /)\n" -"--\n" -"\n" -"Read a number of bytes from a file descriptor starting at a particular offset.\n" -"\n" -"Read length bytes from file descriptor fd, starting at offset bytes from\n" -"the beginning of the file. The file offset remains unchanged."); - -#define OS_PREAD_METHODDEF \ - {"pread", (PyCFunction)os_pread, METH_VARARGS, os_pread__doc__}, - -static PyObject * -os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset); - -static PyObject * -os_pread(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - int length; - Py_off_t offset; - - if (!PyArg_ParseTuple(args, - "iiO&:pread", - &fd, &length, Py_off_t_converter, &offset)) - goto exit; - return_value = os_pread_impl(module, fd, length, offset); - -exit: - return return_value; -} - -static PyObject * -os_pread_impl(PyModuleDef *module, int fd, int length, Py_off_t offset) -/*[clinic end generated code: output=7b62bf6c06e20ae8 input=084948dcbaa35d4c]*/ -{ +PyDoc_STRVAR(posix_pread__doc__, +"pread(fd, buffersize, offset) -> string\n\n\ +Read from a file descriptor, fd, at a position of offset. It will read up\n\ +to buffersize number of bytes. The file offset remains unchanged."); + +static PyObject * +posix_pread(PyObject *self, PyObject *args) +{ + int fd, size; + off_t offset; Py_ssize_t n; PyObject *buffer; - - if (length < 0) { + if (!PyArg_ParseTuple(args, "iiO&:pread", &fd, &size, _parse_off_t, &offset)) + return NULL; + + if (size < 0) { errno = EINVAL; return posix_error(); } - buffer = PyBytes_FromStringAndSize((char *)NULL, length); + buffer = PyBytes_FromStringAndSize((char *)NULL, size); if (buffer == NULL) return NULL; if (!_PyVerify_fd(fd)) { @@ -11577,92 +8153,49 @@ return posix_error(); } Py_BEGIN_ALLOW_THREADS - n = pread(fd, PyBytes_AS_STRING(buffer), length, offset); + n = pread(fd, PyBytes_AS_STRING(buffer), size, offset); Py_END_ALLOW_THREADS if (n < 0) { Py_DECREF(buffer); return posix_error(); } - if (n != length) + if (n != size) _PyBytes_Resize(&buffer, n); return buffer; } -#endif /* HAVE_PREAD */ - - -/*[clinic input] -os.write -> Py_ssize_t - - fd: int - data: Py_buffer - / - -Write a bytes object to a file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_write__doc__, -"write($module, fd, data, /)\n" -"--\n" -"\n" -"Write a bytes object to a file descriptor."); - -#define OS_WRITE_METHODDEF \ - {"write", (PyCFunction)os_write, METH_VARARGS, os_write__doc__}, - -static Py_ssize_t -os_write_impl(PyModuleDef *module, int fd, Py_buffer *data); - -static PyObject * -os_write(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +#endif + +PyDoc_STRVAR(posix_write__doc__, +"write(fd, data) -> byteswritten\n\n\ +Write bytes to a file descriptor."); + +static PyObject * +posix_write(PyObject *self, PyObject *args) +{ + Py_buffer pbuf; int fd; - Py_buffer data = {NULL, NULL}; - Py_ssize_t _return_value; - - if (!PyArg_ParseTuple(args, - "iy*:write", - &fd, &data)) - goto exit; - _return_value = os_write_impl(module, fd, &data); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - /* Cleanup for data */ - if (data.obj) - PyBuffer_Release(&data); - - return return_value; -} - -static Py_ssize_t -os_write_impl(PyModuleDef *module, int fd, Py_buffer *data) -/*[clinic end generated code: output=aeb96acfdd4d5112 input=3207e28963234f3c]*/ -{ - Py_ssize_t size; - Py_ssize_t len = data->len; - + Py_ssize_t size, len; + + if (!PyArg_ParseTuple(args, "iy*:write", &fd, &pbuf)) + return NULL; if (!_PyVerify_fd(fd)) { - posix_error(); - return -1; - } - + PyBuffer_Release(&pbuf); + return posix_error(); + } + len = pbuf.len; Py_BEGIN_ALLOW_THREADS #ifdef MS_WINDOWS if (len > INT_MAX) len = INT_MAX; - size = write(fd, data->buf, (int)len); -#else - size = write(fd, data->buf, len); + size = write(fd, pbuf.buf, (int)len); +#else + size = write(fd, pbuf.buf, len); #endif Py_END_ALLOW_THREADS - if (size < 0) { - posix_error(); - return -1; - } - return size; + PyBuffer_Release(&pbuf); + if (size < 0) + return posix_error(); + return PyLong_FromSsize_t(size); } #ifdef HAVE_SENDFILE @@ -11672,7 +8205,6 @@ -> byteswritten\n\ Copy nbytes bytes from file descriptor in to file descriptor out."); -/* AC 3.5: don't bother converting, has optional group*/ static PyObject * posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict) { @@ -11698,10 +8230,10 @@ #ifdef __APPLE__ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&O&|OOi:sendfile", - keywords, &out, &in, Py_off_t_converter, &offset, Py_off_t_converter, &sbytes, + keywords, &out, &in, _parse_off_t, &offset, _parse_off_t, &sbytes, #else if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO&n|OOi:sendfile", - keywords, &out, &in, Py_off_t_converter, &offset, &len, + keywords, &out, &in, _parse_off_t, &offset, &len, #endif &headers, &trailers, &flags)) return NULL; @@ -11794,7 +8326,7 @@ return Py_BuildValue("n", ret); } #endif - if (!Py_off_t_converter(offobj, &offset)) + if (!_parse_off_t(offobj, &offset)) return NULL; Py_BEGIN_ALLOW_THREADS ret = sendfile(out, in, &offset, count); @@ -11804,59 +8336,21 @@ return Py_BuildValue("n", ret); #endif } -#endif /* HAVE_SENDFILE */ - - -/*[clinic input] -os.fstat - - fd : int - -Perform a stat system call on the given file descriptor. - -Like stat(), but for an open file descriptor. -Equivalent to os.stat(fd). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fstat__doc__, -"fstat($module, /, fd)\n" -"--\n" -"\n" -"Perform a stat system call on the given file descriptor.\n" -"\n" -"Like stat(), but for an open file descriptor.\n" -"Equivalent to os.stat(fd)."); - -#define OS_FSTAT_METHODDEF \ - {"fstat", (PyCFunction)os_fstat, METH_VARARGS|METH_KEYWORDS, os_fstat__doc__}, - -static PyObject * -os_fstat_impl(PyModuleDef *module, int fd); - -static PyObject * -os_fstat(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; +#endif + +PyDoc_STRVAR(posix_fstat__doc__, +"fstat(fd) -> stat result\n\n\ +Like stat(), but for an open file descriptor.\n\ +Equivalent to stat(fd=fd)."); + +static PyObject * +posix_fstat(PyObject *self, PyObject *args) +{ int fd; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:fstat", _keywords, - &fd)) - goto exit; - return_value = os_fstat_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_fstat_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=dae4a9678c7bd881 input=27e0e0ebbe5600c9]*/ -{ STRUCT_STAT st; int res; - + if (!PyArg_ParseTuple(args, "i:fstat", &fd)) + return NULL; Py_BEGIN_ALLOW_THREADS res = FSTAT(fd, &st); Py_END_ALLOW_THREADS @@ -11871,97 +8365,29 @@ return _pystat_fromstructstat(&st); } - -/*[clinic input] -os.isatty -> bool - fd: int - / - -Return True if the fd is connected to a terminal. - -Return True if the file descriptor is an open file descriptor -connected to the slave end of a terminal. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_isatty__doc__, -"isatty($module, fd, /)\n" -"--\n" -"\n" -"Return True if the fd is connected to a terminal.\n" -"\n" -"Return True if the file descriptor is an open file descriptor\n" -"connected to the slave end of a terminal."); - -#define OS_ISATTY_METHODDEF \ - {"isatty", (PyCFunction)os_isatty, METH_VARARGS, os_isatty__doc__}, - -static int -os_isatty_impl(PyModuleDef *module, int fd); - -static PyObject * -os_isatty(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_isatty__doc__, +"isatty(fd) -> bool\n\n\ +Return True if the file descriptor 'fd' is an open file descriptor\n\ +connected to the slave end of a terminal."); + +static PyObject * +posix_isatty(PyObject *self, PyObject *args) +{ int fd; - int _return_value; - - if (!PyArg_ParseTuple(args, - "i:isatty", - &fd)) - goto exit; - _return_value = os_isatty_impl(module, fd); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_isatty_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=4bfadbfe22715097 input=08ce94aa1eaf7b5e]*/ -{ + if (!PyArg_ParseTuple(args, "i:isatty", &fd)) + return NULL; if (!_PyVerify_fd(fd)) - return 0; - return isatty(fd); -} - + return PyBool_FromLong(0); + return PyBool_FromLong(isatty(fd)); +} #ifdef HAVE_PIPE -/*[clinic input] -os.pipe - -Create a pipe. - -Returns a tuple of two file descriptors: - (read_fd, write_fd) -[clinic start generated code]*/ - -PyDoc_STRVAR(os_pipe__doc__, -"pipe($module, /)\n" -"--\n" -"\n" -"Create a pipe.\n" -"\n" -"Returns a tuple of two file descriptors:\n" -" (read_fd, write_fd)"); - -#define OS_PIPE_METHODDEF \ - {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__}, - -static PyObject * -os_pipe_impl(PyModuleDef *module); - -static PyObject * -os_pipe(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_pipe_impl(module); -} - -static PyObject * -os_pipe_impl(PyModuleDef *module) -/*[clinic end generated code: output=0da2479f2266e774 input=02535e8c8fa6c4d4]*/ +PyDoc_STRVAR(posix_pipe__doc__, +"pipe() -> (read_end, write_end)\n\n\ +Create a pipe."); + +static PyObject * +posix_pipe(PyObject *self, PyObject *noargs) { int fds[2]; #ifdef MS_WINDOWS @@ -12029,64 +8455,25 @@ } #endif /* HAVE_PIPE */ - #ifdef HAVE_PIPE2 -/*[clinic input] -os.pipe2 - - flags: int - / - -Create a pipe with flags set atomically. - -Returns a tuple of two file descriptors: - (read_fd, write_fd) - -flags can be constructed by ORing together one or more of these values: -O_NONBLOCK, O_CLOEXEC. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_pipe2__doc__, -"pipe2($module, flags, /)\n" -"--\n" -"\n" -"Create a pipe with flags set atomically.\n" -"\n" -"Returns a tuple of two file descriptors:\n" -" (read_fd, write_fd)\n" -"\n" -"flags can be constructed by ORing together one or more of these values:\n" -"O_NONBLOCK, O_CLOEXEC."); - -#define OS_PIPE2_METHODDEF \ - {"pipe2", (PyCFunction)os_pipe2, METH_VARARGS, os_pipe2__doc__}, - -static PyObject * -os_pipe2_impl(PyModuleDef *module, int flags); - -static PyObject * -os_pipe2(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_pipe2__doc__, +"pipe2(flags) -> (read_end, write_end)\n\n\ +Create a pipe with flags set atomically.\n\ +flags can be constructed by ORing together one or more of these values:\n\ +O_NONBLOCK, O_CLOEXEC.\n\ +"); + +static PyObject * +posix_pipe2(PyObject *self, PyObject *arg) +{ int flags; - - if (!PyArg_ParseTuple(args, - "i:pipe2", - &flags)) - goto exit; - return_value = os_pipe2_impl(module, flags); - -exit: - return return_value; -} - -static PyObject * -os_pipe2_impl(PyModuleDef *module, int flags) -/*[clinic end generated code: output=9e27c799ce19220b input=f261b6e7e63c6817]*/ -{ int fds[2]; int res; + flags = _PyLong_AsInt(arg); + if (flags == -1 && PyErr_Occurred()) + return NULL; + res = pipe2(fds, flags); if (res != 0) return posix_error(); @@ -12094,984 +8481,487 @@ } #endif /* HAVE_PIPE2 */ - #ifdef HAVE_WRITEV -/*[clinic input] -os.writev -> Py_ssize_t - fd: int - buffers: object - / - -Iterate over buffers, and write the contents of each to a file descriptor. - -Returns the total number of bytes written. -buffers must be a sequence of bytes-like objects. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_writev__doc__, -"writev($module, fd, buffers, /)\n" -"--\n" -"\n" -"Iterate over buffers, and write the contents of each to a file descriptor.\n" -"\n" -"Returns the total number of bytes written.\n" -"buffers must be a sequence of bytes-like objects."); - -#define OS_WRITEV_METHODDEF \ - {"writev", (PyCFunction)os_writev, METH_VARARGS, os_writev__doc__}, - -static Py_ssize_t -os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers); - -static PyObject * -os_writev(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - PyObject *buffers; - Py_ssize_t _return_value; - - if (!PyArg_ParseTuple(args, - "iO:writev", - &fd, &buffers)) - goto exit; - _return_value = os_writev_impl(module, fd, buffers); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - return return_value; -} - -static Py_ssize_t -os_writev_impl(PyModuleDef *module, int fd, PyObject *buffers) -/*[clinic end generated code: output=591c662dccbe4951 input=5b8d17fe4189d2fe]*/ -{ - int cnt; - Py_ssize_t result; +PyDoc_STRVAR(posix_writev__doc__, +"writev(fd, buffers) -> byteswritten\n\n\ +Write the contents of *buffers* to file descriptor *fd*. *buffers*\n\ +must be a sequence of bytes-like objects.\n\n\ +writev writes the contents of each object to the file descriptor\n\ +and returns the total number of bytes written."); + +static PyObject * +posix_writev(PyObject *self, PyObject *args) +{ + int fd, cnt; + Py_ssize_t res; + PyObject *seq; struct iovec *iov; Py_buffer *buf; - - if (!PySequence_Check(buffers)) { + if (!PyArg_ParseTuple(args, "iO:writev", &fd, &seq)) + return NULL; + if (!PySequence_Check(seq)) { PyErr_SetString(PyExc_TypeError, "writev() arg 2 must be a sequence"); - return -1; - } - cnt = PySequence_Size(buffers); - - if (iov_setup(&iov, &buf, buffers, cnt, PyBUF_SIMPLE) < 0) { - return -1; + return NULL; + } + cnt = PySequence_Size(seq); + + if (iov_setup(&iov, &buf, seq, cnt, PyBUF_SIMPLE) < 0) { + return NULL; } Py_BEGIN_ALLOW_THREADS - result = writev(fd, iov, cnt); + res = writev(fd, iov, cnt); Py_END_ALLOW_THREADS iov_cleanup(iov, buf, cnt); - if (result < 0) - posix_error(); - - return result; -} -#endif /* HAVE_WRITEV */ - + if (res < 0) + return posix_error(); + + return PyLong_FromSsize_t(res); +} +#endif #ifdef HAVE_PWRITE -/*[clinic input] -os.pwrite -> Py_ssize_t - - fd: int - buffer: Py_buffer - offset: Py_off_t - / - -Write bytes to a file descriptor starting at a particular offset. - -Write buffer to fd, starting at offset bytes from the beginning of -the file. Returns the number of bytes writte. Does not change the -current file offset. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_pwrite__doc__, -"pwrite($module, fd, buffer, offset, /)\n" -"--\n" -"\n" -"Write bytes to a file descriptor starting at a particular offset.\n" -"\n" -"Write buffer to fd, starting at offset bytes from the beginning of\n" -"the file. Returns the number of bytes writte. Does not change the\n" -"current file offset."); - -#define OS_PWRITE_METHODDEF \ - {"pwrite", (PyCFunction)os_pwrite, METH_VARARGS, os_pwrite__doc__}, - -static Py_ssize_t -os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset); - -static PyObject * -os_pwrite(PyModuleDef *module, PyObject *args) -{ +PyDoc_STRVAR(posix_pwrite__doc__, +"pwrite(fd, string, offset) -> byteswritten\n\n\ +Write string to a file descriptor, fd, from offset, leaving the file\n\ +offset unchanged."); + +static PyObject * +posix_pwrite(PyObject *self, PyObject *args) +{ + Py_buffer pbuf; + int fd; + off_t offset; + Py_ssize_t size; + + if (!PyArg_ParseTuple(args, "iy*O&:pwrite", &fd, &pbuf, _parse_off_t, &offset)) + return NULL; + + if (!_PyVerify_fd(fd)) { + PyBuffer_Release(&pbuf); + return posix_error(); + } + Py_BEGIN_ALLOW_THREADS + size = pwrite(fd, pbuf.buf, (size_t)pbuf.len, offset); + Py_END_ALLOW_THREADS + PyBuffer_Release(&pbuf); + if (size < 0) + return posix_error(); + return PyLong_FromSsize_t(size); +} +#endif + +#ifdef HAVE_MKFIFO +PyDoc_STRVAR(posix_mkfifo__doc__, +"mkfifo(path, mode=0o666, *, dir_fd=None)\n\n\ +Create a FIFO (a POSIX named pipe).\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + +static PyObject * +posix_mkfifo(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int mode = 0666; + int dir_fd = DEFAULT_DIR_FD; + int result; PyObject *return_value = NULL; - int fd; - Py_buffer buffer = {NULL, NULL}; - Py_off_t offset; - Py_ssize_t _return_value; - - if (!PyArg_ParseTuple(args, - "iy*O&:pwrite", - &fd, &buffer, Py_off_t_converter, &offset)) - goto exit; - _return_value = os_pwrite_impl(module, fd, &buffer, offset); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromSsize_t(_return_value); - -exit: - /* Cleanup for buffer */ - if (buffer.obj) - PyBuffer_Release(&buffer); - - return return_value; -} - -static Py_ssize_t -os_pwrite_impl(PyModuleDef *module, int fd, Py_buffer *buffer, Py_off_t offset) -/*[clinic end generated code: output=ec9cc5b2238e96a7 input=19903f1b3dd26377]*/ -{ - Py_ssize_t size; - - if (!_PyVerify_fd(fd)) { - posix_error(); - return -1; - } - - Py_BEGIN_ALLOW_THREADS - size = pwrite(fd, buffer->buf, (size_t)buffer->len, offset); - Py_END_ALLOW_THREADS - - if (size < 0) - posix_error(); - return size; -} -#endif /* HAVE_PWRITE */ - - -#ifdef HAVE_MKFIFO -/*[clinic input] -os.mkfifo - - path: path_t - mode: int=0o666 - * - dir_fd: dir_fd(requires='mkfifoat')=None - -Create a "fifo" (a POSIX named pipe). - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_mkfifo__doc__, -"mkfifo($module, /, path, mode=438, *, dir_fd=None)\n" -"--\n" -"\n" -"Create a \"fifo\" (a POSIX named pipe).\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_MKFIFO_METHODDEF \ - {"mkfifo", (PyCFunction)os_mkfifo, METH_VARARGS|METH_KEYWORDS, os_mkfifo__doc__}, - -static PyObject * -os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd); - -static PyObject * -os_mkfifo(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "mode", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("mkfifo", "path", 0, 0); - int mode = 438; - int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|i$O&:mkfifo", _keywords, - path_converter, &path, &mode, MKFIFOAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_mkfifo_impl(module, &path, mode, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_mkfifo_impl(PyModuleDef *module, path_t *path, int mode, int dir_fd) -/*[clinic end generated code: output=b3321927546893d0 input=73032e98a36e0e19]*/ -{ - int result; + static char *keywords[] = {"path", "mode", "dir_fd", NULL}; + + memset(&path, 0, sizeof(path)); + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|i$O&:mkfifo", keywords, + path_converter, &path, + &mode, +#ifdef HAVE_MKFIFOAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef HAVE_MKFIFOAT if (dir_fd != DEFAULT_DIR_FD) - result = mkfifoat(dir_fd, path->narrow, mode); + result = mkfifoat(dir_fd, path.narrow, mode); else #endif - result = mkfifo(path->narrow, mode); + result = mkfifo(path.narrow, mode); Py_END_ALLOW_THREADS - if (result < 0) - return posix_error(); - - Py_RETURN_NONE; -} -#endif /* HAVE_MKFIFO */ - + if (result < 0) { + return_value = posix_error(); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; +} +#endif #if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) -/*[clinic input] -os.mknod - - path: path_t - mode: int=0o600 - device: int=0 - * - dir_fd: dir_fd(requires='mknodat')=None - -Create a node in the file system. - -Create a node in the file system (file, device special file or named pipe) -at path. mode specifies both the permissions to use and the -type of node to be created, being combined (bitwise OR) with one of -S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode, -device defines the newly created device special file (probably using -os.makedev()). Otherwise device is ignored. - -If dir_fd is not None, it should be a file descriptor open to a directory, - and path should be relative; path will then be relative to that directory. -dir_fd may not be implemented on your platform. - If it is unavailable, using it will raise a NotImplementedError. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_mknod__doc__, -"mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n" -"--\n" -"\n" -"Create a node in the file system.\n" -"\n" -"Create a node in the file system (file, device special file or named pipe)\n" -"at path. mode specifies both the permissions to use and the\n" -"type of node to be created, being combined (bitwise OR) with one of\n" -"S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n" -"device defines the newly created device special file (probably using\n" -"os.makedev()). Otherwise device is ignored.\n" -"\n" -"If dir_fd is not None, it should be a file descriptor open to a directory,\n" -" and path should be relative; path will then be relative to that directory.\n" -"dir_fd may not be implemented on your platform.\n" -" If it is unavailable, using it will raise a NotImplementedError."); - -#define OS_MKNOD_METHODDEF \ - {"mknod", (PyCFunction)os_mknod, METH_VARARGS|METH_KEYWORDS, os_mknod__doc__}, - -static PyObject * -os_mknod_impl(PyModuleDef *module, path_t *path, int mode, int device, int dir_fd); - -static PyObject * -os_mknod(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "mode", "device", "dir_fd", NULL}; - path_t path = PATH_T_INITIALIZE("mknod", "path", 0, 0); - int mode = 384; +PyDoc_STRVAR(posix_mknod__doc__, +"mknod(filename, mode=0o600, device=0, *, dir_fd=None)\n\n\ +Create a filesystem node (file, device special file or named pipe)\n\ +named filename. mode specifies both the permissions to use and the\n\ +type of node to be created, being combined (bitwise OR) with one of\n\ +S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. For S_IFCHR and S_IFBLK,\n\ +device defines the newly created device special file (probably using\n\ +os.makedev()), otherwise it is ignored.\n\ +\n\ +If dir_fd is not None, it should be a file descriptor open to a directory,\n\ + and path should be relative; path will then be relative to that directory.\n\ +dir_fd may not be implemented on your platform.\n\ + If it is unavailable, using it will raise a NotImplementedError."); + + +static PyObject * +posix_mknod(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + int mode = 0666; int device = 0; int dir_fd = DEFAULT_DIR_FD; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&|ii$O&:mknod", _keywords, - path_converter, &path, &mode, &device, MKNODAT_DIR_FD_CONVERTER, &dir_fd)) - goto exit; - return_value = os_mknod_impl(module, &path, mode, device, dir_fd); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_mknod_impl(PyModuleDef *module, path_t *path, int mode, int device, int dir_fd) -/*[clinic end generated code: output=c688739c15ca7bbb input=30e02126aba9732e]*/ -{ int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "mode", "device", "dir_fd", NULL}; + + memset(&path, 0, sizeof(path)); + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|ii$O&:mknod", keywords, + path_converter, &path, + &mode, &device, +#ifdef HAVE_MKNODAT + dir_fd_converter, &dir_fd +#else + dir_fd_unavailable, &dir_fd +#endif + )) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef HAVE_MKNODAT if (dir_fd != DEFAULT_DIR_FD) - result = mknodat(dir_fd, path->narrow, mode, device); + result = mknodat(dir_fd, path.narrow, mode, device); else #endif - result = mknod(path->narrow, mode, device); + result = mknod(path.narrow, mode, device); Py_END_ALLOW_THREADS - if (result < 0) - return posix_error(); - - Py_RETURN_NONE; -} -#endif /* defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) */ - + if (result < 0) { + return_value = posix_error(); + goto exit; + } + + return_value = Py_None; + Py_INCREF(Py_None); + +exit: + path_cleanup(&path); + return return_value; +} +#endif #ifdef HAVE_DEVICE_MACROS -/*[clinic input] -os.major -> unsigned_int - - device: int - / - -Extracts a device major number from a raw device number. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_major__doc__, -"major($module, device, /)\n" -"--\n" -"\n" -"Extracts a device major number from a raw device number."); - -#define OS_MAJOR_METHODDEF \ - {"major", (PyCFunction)os_major, METH_VARARGS, os_major__doc__}, - -static unsigned int -os_major_impl(PyModuleDef *module, int device); - -static PyObject * -os_major(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_major__doc__, +"major(device) -> major number\n\ +Extracts a device major number from a raw device number."); + +static PyObject * +posix_major(PyObject *self, PyObject *args) +{ int device; - unsigned int _return_value; - - if (!PyArg_ParseTuple(args, - "i:major", - &device)) - goto exit; - _return_value = os_major_impl(module, device); - if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); - -exit: - return return_value; -} - -static unsigned int -os_major_impl(PyModuleDef *module, int device) -/*[clinic end generated code: output=52e6743300dcf4ad input=ea48820b7e10d310]*/ -{ - return major(device); -} - - -/*[clinic input] -os.minor -> unsigned_int - - device: int - / - -Extracts a device minor number from a raw device number. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_minor__doc__, -"minor($module, device, /)\n" -"--\n" -"\n" -"Extracts a device minor number from a raw device number."); - -#define OS_MINOR_METHODDEF \ - {"minor", (PyCFunction)os_minor, METH_VARARGS, os_minor__doc__}, - -static unsigned int -os_minor_impl(PyModuleDef *module, int device); - -static PyObject * -os_minor(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + if (!PyArg_ParseTuple(args, "i:major", &device)) + return NULL; + return PyLong_FromLong((long)major(device)); +} + +PyDoc_STRVAR(posix_minor__doc__, +"minor(device) -> minor number\n\ +Extracts a device minor number from a raw device number."); + +static PyObject * +posix_minor(PyObject *self, PyObject *args) +{ int device; - unsigned int _return_value; - - if (!PyArg_ParseTuple(args, - "i:minor", - &device)) - goto exit; - _return_value = os_minor_impl(module, device); - if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); - -exit: - return return_value; -} - -static unsigned int -os_minor_impl(PyModuleDef *module, int device) -/*[clinic end generated code: output=aebe4bd7f455b755 input=089733ebbf9754e8]*/ -{ - return minor(device); -} - - -/*[clinic input] -os.makedev -> unsigned_int - - major: int - minor: int - / - -Composes a raw device number from the major and minor device numbers. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_makedev__doc__, -"makedev($module, major, minor, /)\n" -"--\n" -"\n" -"Composes a raw device number from the major and minor device numbers."); - -#define OS_MAKEDEV_METHODDEF \ - {"makedev", (PyCFunction)os_makedev, METH_VARARGS, os_makedev__doc__}, - -static unsigned int -os_makedev_impl(PyModuleDef *module, int major, int minor); - -static PyObject * -os_makedev(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int major; - int minor; - unsigned int _return_value; - - if (!PyArg_ParseTuple(args, - "ii:makedev", - &major, &minor)) - goto exit; - _return_value = os_makedev_impl(module, major, minor); - if ((_return_value == (unsigned int)-1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); - -exit: - return return_value; -} - -static unsigned int -os_makedev_impl(PyModuleDef *module, int major, int minor) -/*[clinic end generated code: output=5cb79d9c9eac58b0 input=f55bf7cffb028a08]*/ -{ - return makedev(major, minor); -} -#endif /* HAVE_DEVICE_MACROS */ + if (!PyArg_ParseTuple(args, "i:minor", &device)) + return NULL; + return PyLong_FromLong((long)minor(device)); +} + +PyDoc_STRVAR(posix_makedev__doc__, +"makedev(major, minor) -> device number\n\ +Composes a raw device number from the major and minor device numbers."); + +static PyObject * +posix_makedev(PyObject *self, PyObject *args) +{ + int major, minor; + if (!PyArg_ParseTuple(args, "ii:makedev", &major, &minor)) + return NULL; + return PyLong_FromLong((long)makedev(major, minor)); +} +#endif /* device macros */ #ifdef HAVE_FTRUNCATE -/*[clinic input] -os.ftruncate - - fd: int - length: Py_off_t - / - -Truncate a file, specified by file descriptor, to a specific length. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_ftruncate__doc__, -"ftruncate($module, fd, length, /)\n" -"--\n" -"\n" -"Truncate a file, specified by file descriptor, to a specific length."); - -#define OS_FTRUNCATE_METHODDEF \ - {"ftruncate", (PyCFunction)os_ftruncate, METH_VARARGS, os_ftruncate__doc__}, - -static PyObject * -os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length); - -static PyObject * -os_ftruncate(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_ftruncate__doc__, +"ftruncate(fd, length)\n\n\ +Truncate a file to a specified length."); + +static PyObject * +posix_ftruncate(PyObject *self, PyObject *args) +{ int fd; - Py_off_t length; - - if (!PyArg_ParseTuple(args, - "iO&:ftruncate", - &fd, Py_off_t_converter, &length)) - goto exit; - return_value = os_ftruncate_impl(module, fd, length); - -exit: - return return_value; -} - -static PyObject * -os_ftruncate_impl(PyModuleDef *module, int fd, Py_off_t length) -/*[clinic end generated code: output=62326766cb9b76bf input=63b43641e52818f2]*/ -{ - int result; + off_t length; + int res; + + if (!PyArg_ParseTuple(args, "iO&:ftruncate", &fd, _parse_off_t, &length)) + return NULL; Py_BEGIN_ALLOW_THREADS - result = ftruncate(fd, length); + res = ftruncate(fd, length); Py_END_ALLOW_THREADS - if (result < 0) - return posix_error(); - Py_RETURN_NONE; -} -#endif /* HAVE_FTRUNCATE */ - + if (res < 0) + return posix_error(); + Py_INCREF(Py_None); + return Py_None; +} +#endif #ifdef HAVE_TRUNCATE -/*[clinic input] -os.truncate - path: path_t(allow_fd='PATH_HAVE_FTRUNCATE') - length: Py_off_t - -Truncate a file, specified by path, to a specific length. - -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_truncate__doc__, -"truncate($module, /, path, length)\n" -"--\n" -"\n" -"Truncate a file, specified by path, to a specific length.\n" -"\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception."); - -#define OS_TRUNCATE_METHODDEF \ - {"truncate", (PyCFunction)os_truncate, METH_VARARGS|METH_KEYWORDS, os_truncate__doc__}, - -static PyObject * -os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length); - -static PyObject * -os_truncate(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "length", NULL}; - path_t path = PATH_T_INITIALIZE("truncate", "path", 0, PATH_HAVE_FTRUNCATE); - Py_off_t length; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&:truncate", _keywords, - path_converter, &path, Py_off_t_converter, &length)) - goto exit; - return_value = os_truncate_impl(module, &path, length); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_truncate_impl(PyModuleDef *module, path_t *path, Py_off_t length) -/*[clinic end generated code: output=6bd76262d2e027c6 input=77229cf0b50a9b77]*/ -{ - int result; +PyDoc_STRVAR(posix_truncate__doc__, +"truncate(path, length)\n\n\ +Truncate the file given by path to length bytes.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception."); + +static PyObject * +posix_truncate(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + off_t length; + int res; + PyObject *result = NULL; + static char *keywords[] = {"path", "length", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "truncate"; +#ifdef HAVE_FTRUNCATE + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:truncate", keywords, + path_converter, &path, + _parse_off_t, &length)) + return NULL; Py_BEGIN_ALLOW_THREADS #ifdef HAVE_FTRUNCATE - if (path->fd != -1) - result = ftruncate(path->fd, length); + if (path.fd != -1) + res = ftruncate(path.fd, length); else #endif - result = truncate(path->narrow, length); + res = truncate(path.narrow, length); Py_END_ALLOW_THREADS - if (result < 0) - return path_error(path); - + if (res < 0) + result = path_error(&path); + else { + Py_INCREF(Py_None); + result = Py_None; + } + path_cleanup(&path); + return result; +} +#endif + +#ifdef HAVE_POSIX_FALLOCATE +PyDoc_STRVAR(posix_posix_fallocate__doc__, +"posix_fallocate(fd, offset, len)\n\n\ +Ensures that enough disk space is allocated for the file specified by fd\n\ +starting from offset and continuing for len bytes."); + +static PyObject * +posix_posix_fallocate(PyObject *self, PyObject *args) +{ + off_t len, offset; + int res, fd; + + if (!PyArg_ParseTuple(args, "iO&O&:posix_fallocate", + &fd, _parse_off_t, &offset, _parse_off_t, &len)) + return NULL; + + Py_BEGIN_ALLOW_THREADS + res = posix_fallocate(fd, offset, len); + Py_END_ALLOW_THREADS + if (res != 0) { + errno = res; + return posix_error(); + } Py_RETURN_NONE; } -#endif /* HAVE_TRUNCATE */ - - -#ifdef HAVE_POSIX_FALLOCATE -/*[clinic input] -os.posix_fallocate - - fd: int - offset: Py_off_t - length: Py_off_t - / - -Ensure a file has allocated at least a particular number of bytes on disk. - -Ensure that the file specified by fd encompasses a range of bytes -starting at offset bytes from the beginning and continuing for length bytes. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_posix_fallocate__doc__, -"posix_fallocate($module, fd, offset, length, /)\n" -"--\n" -"\n" -"Ensure a file has allocated at least a particular number of bytes on disk.\n" -"\n" -"Ensure that the file specified by fd encompasses a range of bytes\n" -"starting at offset bytes from the beginning and continuing for length bytes."); - -#define OS_POSIX_FALLOCATE_METHODDEF \ - {"posix_fallocate", (PyCFunction)os_posix_fallocate, METH_VARARGS, os_posix_fallocate__doc__}, - -static PyObject * -os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length); - -static PyObject * -os_posix_fallocate(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - Py_off_t offset; - Py_off_t length; - - if (!PyArg_ParseTuple(args, - "iO&O&:posix_fallocate", - &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length)) - goto exit; - return_value = os_posix_fallocate_impl(module, fd, offset, length); - -exit: - return return_value; -} - -static PyObject * -os_posix_fallocate_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length) -/*[clinic end generated code: output=0cd702d2065c79db input=d7a2ef0ab2ca52fb]*/ -{ - int result; +#endif + +#ifdef HAVE_POSIX_FADVISE +PyDoc_STRVAR(posix_posix_fadvise__doc__, +"posix_fadvise(fd, offset, len, advice)\n\n\ +Announces an intention to access data in a specific pattern thus allowing\n\ +the kernel to make optimizations.\n\ +The advice applies to the region of the file specified by fd starting at\n\ +offset and continuing for len bytes.\n\ +advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n\ +POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or\n\ +POSIX_FADV_DONTNEED."); + +static PyObject * +posix_posix_fadvise(PyObject *self, PyObject *args) +{ + off_t len, offset; + int res, fd, advice; + + if (!PyArg_ParseTuple(args, "iO&O&i:posix_fadvise", + &fd, _parse_off_t, &offset, _parse_off_t, &len, &advice)) + return NULL; Py_BEGIN_ALLOW_THREADS - result = posix_fallocate(fd, offset, length); + res = posix_fadvise(fd, offset, len, advice); Py_END_ALLOW_THREADS - if (result != 0) { - errno = result; + if (res != 0) { + errno = res; return posix_error(); } Py_RETURN_NONE; } -#endif /* HAVE_POSIX_FALLOCATE */ - - -#ifdef HAVE_POSIX_FADVISE -/*[clinic input] -os.posix_fadvise - - fd: int - offset: Py_off_t - length: Py_off_t - advice: int - / - -Announce an intention to access data in a specific pattern. - -Announce an intention to access data in a specific pattern, thus allowing -the kernel to make optimizations. -The advice applies to the region of the file specified by fd starting at -offset and continuing for length bytes. -advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, -POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or -POSIX_FADV_DONTNEED. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_posix_fadvise__doc__, -"posix_fadvise($module, fd, offset, length, advice, /)\n" -"--\n" -"\n" -"Announce an intention to access data in a specific pattern.\n" -"\n" -"Announce an intention to access data in a specific pattern, thus allowing\n" -"the kernel to make optimizations.\n" -"The advice applies to the region of the file specified by fd starting at\n" -"offset and continuing for length bytes.\n" -"advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n" -"POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n" -"POSIX_FADV_DONTNEED."); - -#define OS_POSIX_FADVISE_METHODDEF \ - {"posix_fadvise", (PyCFunction)os_posix_fadvise, METH_VARARGS, os_posix_fadvise__doc__}, - -static PyObject * -os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice); - -static PyObject * -os_posix_fadvise(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - Py_off_t offset; - Py_off_t length; - int advice; - - if (!PyArg_ParseTuple(args, - "iO&O&i:posix_fadvise", - &fd, Py_off_t_converter, &offset, Py_off_t_converter, &length, &advice)) - goto exit; - return_value = os_posix_fadvise_impl(module, fd, offset, length, advice); - -exit: - return return_value; -} - -static PyObject * -os_posix_fadvise_impl(PyModuleDef *module, int fd, Py_off_t offset, Py_off_t length, int advice) -/*[clinic end generated code: output=dad93f32c04dd4f7 input=0fbe554edc2f04b5]*/ -{ - int result; - - Py_BEGIN_ALLOW_THREADS - result = posix_fadvise(fd, offset, length, advice); - Py_END_ALLOW_THREADS - if (result != 0) { - errno = result; - return posix_error(); - } - Py_RETURN_NONE; -} -#endif /* HAVE_POSIX_FADVISE */ +#endif #ifdef HAVE_PUTENV +PyDoc_STRVAR(posix_putenv__doc__, +"putenv(key, value)\n\n\ +Change or add an environment variable."); /* Save putenv() parameters as values here, so we can collect them when they * get re-set with another call for the same key. */ static PyObject *posix_putenv_garbage; -static void -posix_putenv_garbage_setitem(PyObject *name, PyObject *value) -{ +static PyObject * +posix_putenv(PyObject *self, PyObject *args) +{ + PyObject *newstr = NULL; +#ifdef MS_WINDOWS + PyObject *os1, *os2; + wchar_t *newenv; + + if (!PyArg_ParseTuple(args, + "UU:putenv", + &os1, &os2)) + return NULL; + + newstr = PyUnicode_FromFormat("%U=%U", os1, os2); + if (newstr == NULL) { + PyErr_NoMemory(); + goto error; + } + if (_MAX_ENV < PyUnicode_GET_LENGTH(newstr)) { + PyErr_Format(PyExc_ValueError, + "the environment variable is longer than %u characters", + _MAX_ENV); + goto error; + } + + newenv = PyUnicode_AsUnicode(newstr); + if (newenv == NULL) + goto error; + if (_wputenv(newenv)) { + posix_error(); + goto error; + } +#else + PyObject *os1, *os2; + char *s1, *s2; + char *newenv; + + if (!PyArg_ParseTuple(args, + "O&O&:putenv", + PyUnicode_FSConverter, &os1, + PyUnicode_FSConverter, &os2)) + return NULL; + s1 = PyBytes_AsString(os1); + s2 = PyBytes_AsString(os2); + + newstr = PyBytes_FromFormat("%s=%s", s1, s2); + if (newstr == NULL) { + PyErr_NoMemory(); + goto error; + } + + newenv = PyBytes_AS_STRING(newstr); + if (putenv(newenv)) { + posix_error(); + goto error; + } +#endif + /* Install the first arg and newstr in posix_putenv_garbage; * this will cause previous value to be collected. This has to * happen after the real putenv() call because the old value * was still accessible until then. */ - if (PyDict_SetItem(posix_putenv_garbage, name, value)) + if (PyDict_SetItem(posix_putenv_garbage, os1, newstr)) { /* really not much we can do; just leak */ PyErr_Clear(); - else - Py_DECREF(value); -} - - -#ifdef MS_WINDOWS -/*[clinic input] -os.putenv - - name: unicode - value: unicode - / - -Change or add an environment variable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_putenv__doc__, -"putenv($module, name, value, /)\n" -"--\n" -"\n" -"Change or add an environment variable."); - -#define OS_PUTENV_METHODDEF \ - {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, - -static PyObject * -os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value); - -static PyObject * -os_putenv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + } + else { + Py_DECREF(newstr); + } + +#ifndef MS_WINDOWS + Py_DECREF(os1); + Py_DECREF(os2); +#endif + Py_RETURN_NONE; + +error: +#ifndef MS_WINDOWS + Py_DECREF(os1); + Py_DECREF(os2); +#endif + Py_XDECREF(newstr); + return NULL; +} +#endif /* putenv */ + +#ifdef HAVE_UNSETENV +PyDoc_STRVAR(posix_unsetenv__doc__, +"unsetenv(key)\n\n\ +Delete an environment variable."); + +static PyObject * +posix_unsetenv(PyObject *self, PyObject *args) +{ PyObject *name; - PyObject *value; - - if (!PyArg_ParseTuple(args, - "UU:putenv", - &name, &value)) - goto exit; - return_value = os_putenv_impl(module, name, value); - -exit: - return return_value; -} - -static PyObject * -os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value) -/*[clinic end generated code: output=5ce9ef9b15606e7e input=ba586581c2e6105f]*/ -{ - wchar_t *env; - - PyObject *unicode = PyUnicode_FromFormat("%U=%U", name, value); - if (unicode == NULL) { - PyErr_NoMemory(); - return NULL; - } - if (_MAX_ENV < PyUnicode_GET_LENGTH(unicode)) { - PyErr_Format(PyExc_ValueError, - "the environment variable is longer than %u characters", - _MAX_ENV); - goto error; - } - - env = PyUnicode_AsUnicode(unicode); - if (env == NULL) - goto error; - if (_wputenv(env)) { - posix_error(); - goto error; - } - - posix_putenv_garbage_setitem(name, unicode); - Py_RETURN_NONE; - -error: - Py_DECREF(unicode); - return NULL; -} -#else /* MS_WINDOWS */ -/*[clinic input] -os.putenv - - name: FSConverter - value: FSConverter - / - -Change or add an environment variable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_putenv__doc__, -"putenv($module, name, value, /)\n" -"--\n" -"\n" -"Change or add an environment variable."); - -#define OS_PUTENV_METHODDEF \ - {"putenv", (PyCFunction)os_putenv, METH_VARARGS, os_putenv__doc__}, - -static PyObject * -os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value); - -static PyObject * -os_putenv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *name = NULL; - PyObject *value = NULL; - - if (!PyArg_ParseTuple(args, - "O&O&:putenv", - PyUnicode_FSConverter, &name, PyUnicode_FSConverter, &value)) - goto exit; - return_value = os_putenv_impl(module, name, value); - -exit: - /* Cleanup for name */ - Py_XDECREF(name); - /* Cleanup for value */ - Py_XDECREF(value); - - return return_value; -} - -static PyObject * -os_putenv_impl(PyModuleDef *module, PyObject *name, PyObject *value) -/*[clinic end generated code: output=85ab223393dc7afd input=a97bc6152f688d31]*/ -{ - PyObject *bytes = NULL; - char *env; - char *name_string = PyBytes_AsString(name); - char *value_string = PyBytes_AsString(value); - - bytes = PyBytes_FromFormat("%s=%s", name_string, value_string); - if (bytes == NULL) { - PyErr_NoMemory(); - return NULL; - } - - env = PyBytes_AS_STRING(bytes); - if (putenv(env)) { - Py_DECREF(bytes); - return posix_error(); - } - - posix_putenv_garbage_setitem(name, bytes); - Py_RETURN_NONE; -} -#endif /* MS_WINDOWS */ -#endif /* HAVE_PUTENV */ - - -#ifdef HAVE_UNSETENV -/*[clinic input] -os.unsetenv - name: FSConverter - / - -Delete an environment variable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_unsetenv__doc__, -"unsetenv($module, name, /)\n" -"--\n" -"\n" -"Delete an environment variable."); - -#define OS_UNSETENV_METHODDEF \ - {"unsetenv", (PyCFunction)os_unsetenv, METH_VARARGS, os_unsetenv__doc__}, - -static PyObject * -os_unsetenv_impl(PyModuleDef *module, PyObject *name); - -static PyObject * -os_unsetenv(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - PyObject *name = NULL; - - if (!PyArg_ParseTuple(args, - "O&:unsetenv", - PyUnicode_FSConverter, &name)) - goto exit; - return_value = os_unsetenv_impl(module, name); - -exit: - /* Cleanup for name */ - Py_XDECREF(name); - - return return_value; -} - -static PyObject * -os_unsetenv_impl(PyModuleDef *module, PyObject *name) -/*[clinic end generated code: output=91318c995f9a0767 input=2bb5288a599c7107]*/ -{ #ifndef HAVE_BROKEN_UNSETENV int err; #endif + if (!PyArg_ParseTuple(args, "O&:unsetenv", + + PyUnicode_FSConverter, &name)) + return NULL; + #ifdef HAVE_BROKEN_UNSETENV unsetenv(PyBytes_AS_STRING(name)); #else err = unsetenv(PyBytes_AS_STRING(name)); - if (err) - return posix_error(); + if (err) { + Py_DECREF(name); + return posix_error(); + } #endif /* Remove the key from posix_putenv_garbage; @@ -13083,53 +8973,23 @@ /* really not much we can do; just leak */ PyErr_Clear(); } + Py_DECREF(name); Py_RETURN_NONE; } -#endif /* HAVE_UNSETENV */ - - -/*[clinic input] -os.strerror - - code: int - / - -Translate an error code to a message string. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_strerror__doc__, -"strerror($module, code, /)\n" -"--\n" -"\n" -"Translate an error code to a message string."); - -#define OS_STRERROR_METHODDEF \ - {"strerror", (PyCFunction)os_strerror, METH_VARARGS, os_strerror__doc__}, - -static PyObject * -os_strerror_impl(PyModuleDef *module, int code); - -static PyObject * -os_strerror(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +#endif /* unsetenv */ + +PyDoc_STRVAR(posix_strerror__doc__, +"strerror(code) -> string\n\n\ +Translate an error code to a message string."); + +static PyObject * +posix_strerror(PyObject *self, PyObject *args) +{ int code; - - if (!PyArg_ParseTuple(args, - "i:strerror", - &code)) - goto exit; - return_value = os_strerror_impl(module, code); - -exit: - return return_value; -} - -static PyObject * -os_strerror_impl(PyModuleDef *module, int code) -/*[clinic end generated code: output=8665c70bb2ca4720 input=75a8673d97915a91]*/ -{ - char *message = strerror(code); + char *message; + if (!PyArg_ParseTuple(args, "i:strerror", &code)) + return NULL; + message = strerror(code); if (message == NULL) { PyErr_SetString(PyExc_ValueError, "strerror() argument out of range"); @@ -13140,470 +9000,158 @@ #ifdef HAVE_SYS_WAIT_H + #ifdef WCOREDUMP -/*[clinic input] -os.WCOREDUMP -> bool - - status: int - / - -Return True if the process returning status was dumped to a core file. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WCOREDUMP__doc__, -"WCOREDUMP($module, status, /)\n" -"--\n" -"\n" -"Return True if the process returning status was dumped to a core file."); - -#define OS_WCOREDUMP_METHODDEF \ - {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_VARARGS, os_WCOREDUMP__doc__}, - -static int -os_WCOREDUMP_impl(PyModuleDef *module, int status); - -static PyObject * -os_WCOREDUMP(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int status; - int _return_value; - - if (!PyArg_ParseTuple(args, - "i:WCOREDUMP", - &status)) - goto exit; - _return_value = os_WCOREDUMP_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WCOREDUMP_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=e04d55c09c299828 input=8b05e7ab38528d04]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WCOREDUMP(wait_status); +PyDoc_STRVAR(posix_WCOREDUMP__doc__, +"WCOREDUMP(status) -> bool\n\n\ +Return True if the process returning 'status' was dumped to a core file."); + +static PyObject * +posix_WCOREDUMP(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WCOREDUMP", &WAIT_STATUS_INT(status))) + return NULL; + + return PyBool_FromLong(WCOREDUMP(status)); } #endif /* WCOREDUMP */ - #ifdef WIFCONTINUED -/*[clinic input] -os.WIFCONTINUED -> bool - - status: int - -Return True if a particular process was continued from a job control stop. - -Return True if the process returning status was continued from a -job control stop. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WIFCONTINUED__doc__, -"WIFCONTINUED($module, /, status)\n" -"--\n" -"\n" -"Return True if a particular process was continued from a job control stop.\n" -"\n" -"Return True if the process returning status was continued from a\n" -"job control stop."); - -#define OS_WIFCONTINUED_METHODDEF \ - {"WIFCONTINUED", (PyCFunction)os_WIFCONTINUED, METH_VARARGS|METH_KEYWORDS, os_WIFCONTINUED__doc__}, - -static int -os_WIFCONTINUED_impl(PyModuleDef *module, int status); - -static PyObject * -os_WIFCONTINUED(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WIFCONTINUED", _keywords, - &status)) - goto exit; - _return_value = os_WIFCONTINUED_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WIFCONTINUED_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=9c4e6105a4520ab5 input=e777e7d38eb25bd9]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WIFCONTINUED(wait_status); +PyDoc_STRVAR(posix_WIFCONTINUED__doc__, +"WIFCONTINUED(status) -> bool\n\n\ +Return True if the process returning 'status' was continued from a\n\ +job control stop."); + +static PyObject * +posix_WIFCONTINUED(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WCONTINUED", &WAIT_STATUS_INT(status))) + return NULL; + + return PyBool_FromLong(WIFCONTINUED(status)); } #endif /* WIFCONTINUED */ - #ifdef WIFSTOPPED -/*[clinic input] -os.WIFSTOPPED -> bool - - status: int - -Return True if the process returning status was stopped. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WIFSTOPPED__doc__, -"WIFSTOPPED($module, /, status)\n" -"--\n" -"\n" -"Return True if the process returning status was stopped."); - -#define OS_WIFSTOPPED_METHODDEF \ - {"WIFSTOPPED", (PyCFunction)os_WIFSTOPPED, METH_VARARGS|METH_KEYWORDS, os_WIFSTOPPED__doc__}, - -static int -os_WIFSTOPPED_impl(PyModuleDef *module, int status); - -static PyObject * -os_WIFSTOPPED(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WIFSTOPPED", _keywords, - &status)) - goto exit; - _return_value = os_WIFSTOPPED_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WIFSTOPPED_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=e0de2da8ec9593ff input=043cb7f1289ef904]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WIFSTOPPED(wait_status); +PyDoc_STRVAR(posix_WIFSTOPPED__doc__, +"WIFSTOPPED(status) -> bool\n\n\ +Return True if the process returning 'status' was stopped."); + +static PyObject * +posix_WIFSTOPPED(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WIFSTOPPED", &WAIT_STATUS_INT(status))) + return NULL; + + return PyBool_FromLong(WIFSTOPPED(status)); } #endif /* WIFSTOPPED */ - #ifdef WIFSIGNALED -/*[clinic input] -os.WIFSIGNALED -> bool - - status: int - -Return True if the process returning status was terminated by a signal. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WIFSIGNALED__doc__, -"WIFSIGNALED($module, /, status)\n" -"--\n" -"\n" -"Return True if the process returning status was terminated by a signal."); - -#define OS_WIFSIGNALED_METHODDEF \ - {"WIFSIGNALED", (PyCFunction)os_WIFSIGNALED, METH_VARARGS|METH_KEYWORDS, os_WIFSIGNALED__doc__}, - -static int -os_WIFSIGNALED_impl(PyModuleDef *module, int status); - -static PyObject * -os_WIFSIGNALED(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WIFSIGNALED", _keywords, - &status)) - goto exit; - _return_value = os_WIFSIGNALED_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WIFSIGNALED_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=f14d106558f406be input=d55ba7cc9ce5dc43]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WIFSIGNALED(wait_status); +PyDoc_STRVAR(posix_WIFSIGNALED__doc__, +"WIFSIGNALED(status) -> bool\n\n\ +Return True if the process returning 'status' was terminated by a signal."); + +static PyObject * +posix_WIFSIGNALED(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WIFSIGNALED", &WAIT_STATUS_INT(status))) + return NULL; + + return PyBool_FromLong(WIFSIGNALED(status)); } #endif /* WIFSIGNALED */ - #ifdef WIFEXITED -/*[clinic input] -os.WIFEXITED -> bool - - status: int - -Return True if the process returning status exited via the exit() system call. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WIFEXITED__doc__, -"WIFEXITED($module, /, status)\n" -"--\n" -"\n" -"Return True if the process returning status exited via the exit() system call."); - -#define OS_WIFEXITED_METHODDEF \ - {"WIFEXITED", (PyCFunction)os_WIFEXITED, METH_VARARGS|METH_KEYWORDS, os_WIFEXITED__doc__}, - -static int -os_WIFEXITED_impl(PyModuleDef *module, int status); - -static PyObject * -os_WIFEXITED(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WIFEXITED", _keywords, - &status)) - goto exit; - _return_value = os_WIFEXITED_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WIFEXITED_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=2f76087d53721255 input=d63775a6791586c0]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WIFEXITED(wait_status); +PyDoc_STRVAR(posix_WIFEXITED__doc__, +"WIFEXITED(status) -> bool\n\n\ +Return true if the process returning 'status' exited using the exit()\n\ +system call."); + +static PyObject * +posix_WIFEXITED(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WIFEXITED", &WAIT_STATUS_INT(status))) + return NULL; + + return PyBool_FromLong(WIFEXITED(status)); } #endif /* WIFEXITED */ - #ifdef WEXITSTATUS -/*[clinic input] -os.WEXITSTATUS -> int - - status: int - -Return the process return code from status. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WEXITSTATUS__doc__, -"WEXITSTATUS($module, /, status)\n" -"--\n" -"\n" -"Return the process return code from status."); - -#define OS_WEXITSTATUS_METHODDEF \ - {"WEXITSTATUS", (PyCFunction)os_WEXITSTATUS, METH_VARARGS|METH_KEYWORDS, os_WEXITSTATUS__doc__}, - -static int -os_WEXITSTATUS_impl(PyModuleDef *module, int status); - -static PyObject * -os_WEXITSTATUS(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WEXITSTATUS", _keywords, - &status)) - goto exit; - _return_value = os_WEXITSTATUS_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WEXITSTATUS_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=13b6c270e2a326b1 input=e1fb4944e377585b]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WEXITSTATUS(wait_status); +PyDoc_STRVAR(posix_WEXITSTATUS__doc__, +"WEXITSTATUS(status) -> integer\n\n\ +Return the process return code from 'status'."); + +static PyObject * +posix_WEXITSTATUS(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WEXITSTATUS", &WAIT_STATUS_INT(status))) + return NULL; + + return Py_BuildValue("i", WEXITSTATUS(status)); } #endif /* WEXITSTATUS */ - #ifdef WTERMSIG -/*[clinic input] -os.WTERMSIG -> int - - status: int - -Return the signal that terminated the process that provided the status value. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WTERMSIG__doc__, -"WTERMSIG($module, /, status)\n" -"--\n" -"\n" -"Return the signal that terminated the process that provided the status value."); - -#define OS_WTERMSIG_METHODDEF \ - {"WTERMSIG", (PyCFunction)os_WTERMSIG, METH_VARARGS|METH_KEYWORDS, os_WTERMSIG__doc__}, - -static int -os_WTERMSIG_impl(PyModuleDef *module, int status); - -static PyObject * -os_WTERMSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WTERMSIG", _keywords, - &status)) - goto exit; - _return_value = os_WTERMSIG_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WTERMSIG_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=bf1fd4b002d0a9ed input=727fd7f84ec3f243]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WTERMSIG(wait_status); +PyDoc_STRVAR(posix_WTERMSIG__doc__, +"WTERMSIG(status) -> integer\n\n\ +Return the signal that terminated the process that provided the 'status'\n\ +value."); + +static PyObject * +posix_WTERMSIG(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WTERMSIG", &WAIT_STATUS_INT(status))) + return NULL; + + return Py_BuildValue("i", WTERMSIG(status)); } #endif /* WTERMSIG */ - #ifdef WSTOPSIG -/*[clinic input] -os.WSTOPSIG -> int - - status: int - -Return the signal that stopped the process that provided the status value. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_WSTOPSIG__doc__, -"WSTOPSIG($module, /, status)\n" -"--\n" -"\n" -"Return the signal that stopped the process that provided the status value."); - -#define OS_WSTOPSIG_METHODDEF \ - {"WSTOPSIG", (PyCFunction)os_WSTOPSIG, METH_VARARGS|METH_KEYWORDS, os_WSTOPSIG__doc__}, - -static int -os_WSTOPSIG_impl(PyModuleDef *module, int status); - -static PyObject * -os_WSTOPSIG(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"status", NULL}; - int status; - int _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:WSTOPSIG", _keywords, - &status)) - goto exit; - _return_value = os_WSTOPSIG_impl(module, status); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_WSTOPSIG_impl(PyModuleDef *module, int status) -/*[clinic end generated code: output=92e1647d29ee0549 input=46ebf1d1b293c5c1]*/ -{ - WAIT_TYPE wait_status; - WAIT_STATUS_INT(wait_status) = status; - return WSTOPSIG(wait_status); +PyDoc_STRVAR(posix_WSTOPSIG__doc__, +"WSTOPSIG(status) -> integer\n\n\ +Return the signal that stopped the process that provided\n\ +the 'status' value."); + +static PyObject * +posix_WSTOPSIG(PyObject *self, PyObject *args) +{ + WAIT_TYPE status; + WAIT_STATUS_INT(status) = 0; + + if (!PyArg_ParseTuple(args, "i:WSTOPSIG", &WAIT_STATUS_INT(status))) + return NULL; + + return Py_BuildValue("i", WSTOPSIG(status)); } #endif /* WSTOPSIG */ + #endif /* HAVE_SYS_WAIT_H */ -#ifndef OS_WCOREDUMP_METHODDEF -#define OS_WCOREDUMP_METHODDEF -#endif /* OS_WCOREDUMP_METHODDEF */ - -#ifndef OS_WIFCONTINUED_METHODDEF -#define OS_WIFCONTINUED_METHODDEF -#endif /* OS_WIFCONTINUED_METHODDEF */ - -#ifndef OS_WIFSTOPPED_METHODDEF -#define OS_WIFSTOPPED_METHODDEF -#endif /* OS_WIFSTOPPED_METHODDEF */ - -#ifndef OS_WIFSIGNALED_METHODDEF -#define OS_WIFSIGNALED_METHODDEF -#endif /* OS_WIFSIGNALED_METHODDEF */ - -#ifndef OS_WIFEXITED_METHODDEF -#define OS_WIFEXITED_METHODDEF -#endif /* OS_WIFEXITED_METHODDEF */ - -#ifndef OS_WEXITSTATUS_METHODDEF -#define OS_WEXITSTATUS_METHODDEF -#endif /* OS_WEXITSTATUS_METHODDEF */ - -#ifndef OS_WTERMSIG_METHODDEF -#define OS_WTERMSIG_METHODDEF -#endif /* OS_WTERMSIG_METHODDEF */ - -#ifndef OS_WSTOPSIG_METHODDEF -#define OS_WSTOPSIG_METHODDEF -#endif /* OS_WSTOPSIG_METHODDEF */ - - #if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) #ifdef _SCO_DS /* SCO OpenServer 5.0 and later requires _SVID3 before it reveals the @@ -13655,192 +9203,104 @@ return v; } - -/*[clinic input] -os.fstatvfs - fd: int - / - -Perform an fstatvfs system call on the given fd. - -Equivalent to statvfs(fd). -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fstatvfs__doc__, -"fstatvfs($module, fd, /)\n" -"--\n" -"\n" -"Perform an fstatvfs system call on the given fd.\n" -"\n" -"Equivalent to statvfs(fd)."); - -#define OS_FSTATVFS_METHODDEF \ - {"fstatvfs", (PyCFunction)os_fstatvfs, METH_VARARGS, os_fstatvfs__doc__}, - -static PyObject * -os_fstatvfs_impl(PyModuleDef *module, int fd); - -static PyObject * -os_fstatvfs(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - - if (!PyArg_ParseTuple(args, - "i:fstatvfs", - &fd)) - goto exit; - return_value = os_fstatvfs_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_fstatvfs_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=0e32bf07f946ec0d input=d8122243ac50975e]*/ -{ - int result; +PyDoc_STRVAR(posix_fstatvfs__doc__, +"fstatvfs(fd) -> statvfs result\n\n\ +Perform an fstatvfs system call on the given fd.\n\ +Equivalent to statvfs(fd)."); + +static PyObject * +posix_fstatvfs(PyObject *self, PyObject *args) +{ + int fd, res; struct statvfs st; + if (!PyArg_ParseTuple(args, "i:fstatvfs", &fd)) + return NULL; Py_BEGIN_ALLOW_THREADS - result = fstatvfs(fd, &st); + res = fstatvfs(fd, &st); Py_END_ALLOW_THREADS - if (result != 0) + if (res != 0) return posix_error(); return _pystatvfs_fromstructstatvfs(st); } -#endif /* defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) */ +#endif /* HAVE_FSTATVFS && HAVE_SYS_STATVFS_H */ #if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) #include -/*[clinic input] -os.statvfs - - path: path_t(allow_fd='PATH_HAVE_FSTATVFS') - -Perform a statvfs system call on the given path. - -path may always be specified as a string. -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_statvfs__doc__, -"statvfs($module, /, path)\n" -"--\n" -"\n" -"Perform a statvfs system call on the given path.\n" -"\n" -"path may always be specified as a string.\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception."); - -#define OS_STATVFS_METHODDEF \ - {"statvfs", (PyCFunction)os_statvfs, METH_VARARGS|METH_KEYWORDS, os_statvfs__doc__}, - -static PyObject * -os_statvfs_impl(PyModuleDef *module, path_t *path); - -static PyObject * -os_statvfs(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ + +PyDoc_STRVAR(posix_statvfs__doc__, +"statvfs(path)\n\n\ +Perform a statvfs system call on the given path.\n\ +\n\ +path may always be specified as a string.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception."); + +static PyObject * +posix_statvfs(PyObject *self, PyObject *args, PyObject *kwargs) +{ + static char *keywords[] = {"path", NULL}; + path_t path; + int result; PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - path_t path = PATH_T_INITIALIZE("statvfs", "path", 0, PATH_HAVE_FSTATVFS); - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&:statvfs", _keywords, - path_converter, &path)) - goto exit; - return_value = os_statvfs_impl(module, &path); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_statvfs_impl(PyModuleDef *module, path_t *path) -/*[clinic end generated code: output=00ff54983360b446 input=3f5c35791c669bd9]*/ -{ - int result; struct statvfs st; + memset(&path, 0, sizeof(path)); + path.function_name = "statvfs"; +#ifdef HAVE_FSTATVFS + path.allow_fd = 1; +#endif + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:statvfs", keywords, + path_converter, &path + )) + return NULL; + Py_BEGIN_ALLOW_THREADS #ifdef HAVE_FSTATVFS - if (path->fd != -1) { + if (path.fd != -1) { #ifdef __APPLE__ /* handle weak-linking on Mac OS X 10.3 */ if (fstatvfs == NULL) { - fd_specified("statvfs", path->fd); - return NULL; - } -#endif - result = fstatvfs(path->fd, &st); + fd_specified("statvfs", path.fd); + goto exit; + } +#endif + result = fstatvfs(path.fd, &st); } else #endif - result = statvfs(path->narrow, &st); + result = statvfs(path.narrow, &st); Py_END_ALLOW_THREADS if (result) { - return path_error(path); - } - - return _pystatvfs_fromstructstatvfs(st); -} -#endif /* defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) */ - + return_value = path_error(&path); + goto exit; + } + + return_value = _pystatvfs_fromstructstatvfs(st); + +exit: + path_cleanup(&path); + return return_value; +} +#endif /* HAVE_STATVFS */ #ifdef MS_WINDOWS -/*[clinic input] -os._getdiskusage - - path: Py_UNICODE - -Return disk usage statistics about the given path as a (total, free) tuple. -[clinic start generated code]*/ - -PyDoc_STRVAR(os__getdiskusage__doc__, -"_getdiskusage($module, /, path)\n" -"--\n" -"\n" -"Return disk usage statistics about the given path as a (total, free) tuple."); - -#define OS__GETDISKUSAGE_METHODDEF \ - {"_getdiskusage", (PyCFunction)os__getdiskusage, METH_VARARGS|METH_KEYWORDS, os__getdiskusage__doc__}, - -static PyObject * -os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path); - -static PyObject * -os__getdiskusage(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", NULL}; - Py_UNICODE *path; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "u:_getdiskusage", _keywords, - &path)) - goto exit; - return_value = os__getdiskusage_impl(module, path); - -exit: - return return_value; -} - -static PyObject * -os__getdiskusage_impl(PyModuleDef *module, Py_UNICODE *path) -/*[clinic end generated code: output=054c972179b13708 input=6458133aed893c78]*/ +PyDoc_STRVAR(win32__getdiskusage__doc__, +"_getdiskusage(path) -> (total, free)\n\n\ +Return disk usage statistics about the given path as (total, free) tuple."); + +static PyObject * +win32__getdiskusage(PyObject *self, PyObject *args) { BOOL retval; ULARGE_INTEGER _, total, free; + const wchar_t *path; + + if (! PyArg_ParseTuple(args, "u", &path)) + return NULL; Py_BEGIN_ALLOW_THREADS retval = GetDiskFreeSpaceExW(path, &_, &total, &free); @@ -13850,7 +9310,7 @@ return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart); } -#endif /* MS_WINDOWS */ +#endif /* This is used for fpathconf(), pathconf(), confstr() and sysconf(). @@ -14007,149 +9467,81 @@ } #endif - #ifdef HAVE_FPATHCONF -/*[clinic input] -os.fpathconf -> long - - fd: int - name: path_confname - / - -Return the configuration limit name for the file descriptor fd. - -If there is no limit, return -1. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_fpathconf__doc__, -"fpathconf($module, fd, name, /)\n" -"--\n" -"\n" -"Return the configuration limit name for the file descriptor fd.\n" -"\n" -"If there is no limit, return -1."); - -#define OS_FPATHCONF_METHODDEF \ - {"fpathconf", (PyCFunction)os_fpathconf, METH_VARARGS, os_fpathconf__doc__}, - -static long -os_fpathconf_impl(PyModuleDef *module, int fd, int name); - -static PyObject * -os_fpathconf(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; +PyDoc_STRVAR(posix_fpathconf__doc__, +"fpathconf(fd, name) -> integer\n\n\ +Return the configuration limit name for the file descriptor fd.\n\ +If there is no limit, return -1."); + +static PyObject * +posix_fpathconf(PyObject *self, PyObject *args) +{ + PyObject *result = NULL; + int name, fd; + + if (PyArg_ParseTuple(args, "iO&:fpathconf", &fd, + conv_path_confname, &name)) { + long limit; + + errno = 0; + limit = fpathconf(fd, name); + if (limit == -1 && errno != 0) + posix_error(); + else + result = PyLong_FromLong(limit); + } + return result; +} +#endif + + +#ifdef HAVE_PATHCONF +PyDoc_STRVAR(posix_pathconf__doc__, +"pathconf(path, name) -> integer\n\n\ +Return the configuration limit name for the file or directory path.\n\ +If there is no limit, return -1.\n\ +On some platforms, path may also be specified as an open file descriptor.\n\ + If this functionality is unavailable, using it raises an exception."); + +static PyObject * +posix_pathconf(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + PyObject *result = NULL; int name; - long _return_value; - - if (!PyArg_ParseTuple(args, - "iO&:fpathconf", - &fd, conv_path_confname, &name)) - goto exit; - _return_value = os_fpathconf_impl(module, fd, name); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong(_return_value); - -exit: - return return_value; -} - -static long -os_fpathconf_impl(PyModuleDef *module, int fd, int name) -/*[clinic end generated code: output=3bf04b40e0523a8c input=5942a024d3777810]*/ -{ - long limit; - - errno = 0; - limit = fpathconf(fd, name); - if (limit == -1 && errno != 0) - posix_error(); - - return limit; -} -#endif /* HAVE_FPATHCONF */ - - -#ifdef HAVE_PATHCONF -/*[clinic input] -os.pathconf -> long - path: path_t(allow_fd='PATH_HAVE_FPATHCONF') - name: path_confname - -Return the configuration limit name for the file or directory path. - -If there is no limit, return -1. -On some platforms, path may also be specified as an open file descriptor. - If this functionality is unavailable, using it raises an exception. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_pathconf__doc__, -"pathconf($module, /, path, name)\n" -"--\n" -"\n" -"Return the configuration limit name for the file or directory path.\n" -"\n" -"If there is no limit, return -1.\n" -"On some platforms, path may also be specified as an open file descriptor.\n" -" If this functionality is unavailable, using it raises an exception."); - -#define OS_PATHCONF_METHODDEF \ - {"pathconf", (PyCFunction)os_pathconf, METH_VARARGS|METH_KEYWORDS, os_pathconf__doc__}, - -static long -os_pathconf_impl(PyModuleDef *module, path_t *path, int name); - -static PyObject * -os_pathconf(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "name", NULL}; - path_t path = PATH_T_INITIALIZE("pathconf", "path", 0, PATH_HAVE_FPATHCONF); - int name; - long _return_value; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&:pathconf", _keywords, - path_converter, &path, conv_path_confname, &name)) - goto exit; - _return_value = os_pathconf_impl(module, &path, name); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong(_return_value); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static long -os_pathconf_impl(PyModuleDef *module, path_t *path, int name) -/*[clinic end generated code: output=1a53e125b6cf63e4 input=bc3e2a985af27e5e]*/ -{ + static char *keywords[] = {"path", "name", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "pathconf"; +#ifdef HAVE_FPATHCONF + path.allow_fd = 1; +#endif + if (PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&:pathconf", keywords, + path_converter, &path, + conv_path_confname, &name)) { long limit; errno = 0; #ifdef HAVE_FPATHCONF - if (path->fd != -1) - limit = fpathconf(path->fd, name); + if (path.fd != -1) + limit = fpathconf(path.fd, name); else #endif - limit = pathconf(path->narrow, name); + limit = pathconf(path.narrow, name); if (limit == -1 && errno != 0) { if (errno == EINVAL) /* could be a path or name problem */ posix_error(); else - path_error(path); - } - - return limit; -} -#endif /* HAVE_PATHCONF */ + result = path_error(&path); + } + else + result = PyLong_FromLong(limit); + } + path_cleanup(&path); + return result; +} +#endif #ifdef HAVE_CONFSTR static struct constdef posix_constants_confstr[] = { @@ -14313,52 +9705,21 @@ / sizeof(struct constdef)); } - -/*[clinic input] -os.confstr - - name: confstr_confname - / - -Return a string-valued system configuration variable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_confstr__doc__, -"confstr($module, name, /)\n" -"--\n" -"\n" -"Return a string-valued system configuration variable."); - -#define OS_CONFSTR_METHODDEF \ - {"confstr", (PyCFunction)os_confstr, METH_VARARGS, os_confstr__doc__}, - -static PyObject * -os_confstr_impl(PyModuleDef *module, int name); - -static PyObject * -os_confstr(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_confstr__doc__, +"confstr(name) -> string\n\n\ +Return a string-valued system configuration variable."); + +static PyObject * +posix_confstr(PyObject *self, PyObject *args) +{ + PyObject *result = NULL; int name; - - if (!PyArg_ParseTuple(args, - "O&:confstr", - conv_confstr_confname, &name)) - goto exit; - return_value = os_confstr_impl(module, name); - -exit: - return return_value; -} - -static PyObject * -os_confstr_impl(PyModuleDef *module, int name) -/*[clinic end generated code: output=3f5e8aba9f8e3174 input=18fb4d0567242e65]*/ -{ - PyObject *result = NULL; char buffer[255]; size_t len; + if (!PyArg_ParseTuple(args, "O&:confstr", conv_confstr_confname, &name)) + return NULL; + errno = 0; len = confstr(name, buffer, sizeof(buffer)); if (len == 0) { @@ -14383,7 +9744,7 @@ result = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1); return result; } -#endif /* HAVE_CONFSTR */ +#endif #ifdef HAVE_SYSCONF @@ -14890,60 +10251,29 @@ / sizeof(struct constdef)); } - -/*[clinic input] -os.sysconf -> long - name: sysconf_confname - / - -Return an integer-valued system configuration variable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_sysconf__doc__, -"sysconf($module, name, /)\n" -"--\n" -"\n" -"Return an integer-valued system configuration variable."); - -#define OS_SYSCONF_METHODDEF \ - {"sysconf", (PyCFunction)os_sysconf, METH_VARARGS, os_sysconf__doc__}, - -static long -os_sysconf_impl(PyModuleDef *module, int name); - -static PyObject * -os_sysconf(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_sysconf__doc__, +"sysconf(name) -> integer\n\n\ +Return an integer-valued system configuration variable."); + +static PyObject * +posix_sysconf(PyObject *self, PyObject *args) +{ + PyObject *result = NULL; int name; - long _return_value; - - if (!PyArg_ParseTuple(args, - "O&:sysconf", - conv_sysconf_confname, &name)) - goto exit; - _return_value = os_sysconf_impl(module, name); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyLong_FromLong(_return_value); - -exit: - return return_value; -} - -static long -os_sysconf_impl(PyModuleDef *module, int name) -/*[clinic end generated code: output=7b06dfdc472431e4 input=279e3430a33f29e4]*/ -{ - long value; - - errno = 0; - value = sysconf(name); - if (value == -1 && errno != 0) - posix_error(); - return value; -} -#endif /* HAVE_SYSCONF */ + + if (PyArg_ParseTuple(args, "O&:sysconf", conv_sysconf_confname, &name)) { + long value; + + errno = 0; + value = sysconf(name); + if (value == -1 && errno != 0) + posix_error(); + else + result = PyLong_FromLong(value); + } + return result; +} +#endif /* This code is used to ensure that the tables of configuration value names @@ -15020,39 +10350,13 @@ } -/*[clinic input] -os.abort - -Abort the interpreter immediately. - -This function 'dumps core' or otherwise fails in the hardest way possible -on the hosting operating system. This function never returns. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_abort__doc__, -"abort($module, /)\n" -"--\n" -"\n" -"Abort the interpreter immediately.\n" -"\n" -"This function \'dumps core\' or otherwise fails in the hardest way possible\n" -"on the hosting operating system. This function never returns."); - -#define OS_ABORT_METHODDEF \ - {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__}, - -static PyObject * -os_abort_impl(PyModuleDef *module); - -static PyObject * -os_abort(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_abort_impl(module); -} - -static PyObject * -os_abort_impl(PyModuleDef *module) -/*[clinic end generated code: output=cded2cc8c5453d3a input=cf2c7d98bc504047]*/ +PyDoc_STRVAR(posix_abort__doc__, +"abort() -> does not return!\n\n\ +Abort the interpreter immediately. This 'dumps core' or otherwise fails\n\ +in the hardest way possible on the hosting operating system."); + +static PyObject * +posix_abort(PyObject *self, PyObject *noargs) { abort(); /*NOTREACHED*/ @@ -15061,11 +10365,9 @@ } #ifdef MS_WINDOWS -/* AC 3.5: change to path_t? but that might change exceptions */ PyDoc_STRVAR(win32_startfile__doc__, -"startfile(filepath [, operation])\n\ -\n\ -Start a file with its associated application.\n\ +"startfile(filepath [, operation]) - Start a file with its associated\n\ +application.\n\ \n\ When \"operation\" is not specified or \"open\", this acts like\n\ double-clicking the file in Explorer, or giving the file name as an\n\ @@ -15155,45 +10457,17 @@ Py_INCREF(Py_None); return Py_None; } -#endif /* MS_WINDOWS */ - +#endif #ifdef HAVE_GETLOADAVG -/*[clinic input] -os.getloadavg - -Return average recent system load information. - -Return the number of processes in the system run queue averaged over -the last 1, 5, and 15 minutes as a tuple of three floats. -Raises OSError if the load average was unobtainable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getloadavg__doc__, -"getloadavg($module, /)\n" -"--\n" -"\n" -"Return average recent system load information.\n" -"\n" -"Return the number of processes in the system run queue averaged over\n" -"the last 1, 5, and 15 minutes as a tuple of three floats.\n" -"Raises OSError if the load average was unobtainable."); - -#define OS_GETLOADAVG_METHODDEF \ - {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__}, - -static PyObject * -os_getloadavg_impl(PyModuleDef *module); - -static PyObject * -os_getloadavg(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getloadavg_impl(module); -} - -static PyObject * -os_getloadavg_impl(PyModuleDef *module) -/*[clinic end generated code: output=67593a92457d55af input=3d6d826b76d8a34e]*/ +PyDoc_STRVAR(posix_getloadavg__doc__, +"getloadavg() -> (float, float, float)\n\n\ +Return the number of processes in the system run queue averaged over\n\ +the last 1, 5, and 15 minutes or raises OSError if the load average\n\ +was unobtainable"); + +static PyObject * +posix_getloadavg(PyObject *self, PyObject *noargs) { double loadavg[3]; if (getloadavg(loadavg, 3)!=3) { @@ -15202,193 +10476,72 @@ } else return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]); } -#endif /* HAVE_GETLOADAVG */ - - -/*[clinic input] -os.device_encoding - fd: int - -Return a string describing the encoding of a terminal's file descriptor. - -The file descriptor must be attached to a terminal. -If the device is not a terminal, return None. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_device_encoding__doc__, -"device_encoding($module, /, fd)\n" -"--\n" -"\n" -"Return a string describing the encoding of a terminal\'s file descriptor.\n" -"\n" -"The file descriptor must be attached to a terminal.\n" -"If the device is not a terminal, return None."); - -#define OS_DEVICE_ENCODING_METHODDEF \ - {"device_encoding", (PyCFunction)os_device_encoding, METH_VARARGS|METH_KEYWORDS, os_device_encoding__doc__}, - -static PyObject * -os_device_encoding_impl(PyModuleDef *module, int fd); - -static PyObject * -os_device_encoding(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"fd", NULL}; +#endif + +PyDoc_STRVAR(device_encoding__doc__, +"device_encoding(fd) -> str\n\n\ +Return a string describing the encoding of the device\n\ +if the output is a terminal; else return None."); + +static PyObject * +device_encoding(PyObject *self, PyObject *args) +{ int fd; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i:device_encoding", _keywords, - &fd)) - goto exit; - return_value = os_device_encoding_impl(module, fd); - -exit: - return return_value; -} - -static PyObject * -os_device_encoding_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=e9f8274d42f5cce3 input=9e1d4a42b66df312]*/ -{ + if (!PyArg_ParseTuple(args, "i:device_encoding", &fd)) + return NULL; + return _Py_device_encoding(fd); } - #ifdef HAVE_SETRESUID -/*[clinic input] -os.setresuid - - ruid: uid_t - euid: uid_t - suid: uid_t - / - -Set the current process's real, effective, and saved user ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setresuid__doc__, -"setresuid($module, ruid, euid, suid, /)\n" -"--\n" -"\n" -"Set the current process\'s real, effective, and saved user ids."); - -#define OS_SETRESUID_METHODDEF \ - {"setresuid", (PyCFunction)os_setresuid, METH_VARARGS, os_setresuid__doc__}, - -static PyObject * -os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid); - -static PyObject * -os_setresuid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - uid_t ruid; - uid_t euid; - uid_t suid; - - if (!PyArg_ParseTuple(args, - "O&O&O&:setresuid", - _Py_Uid_Converter, &ruid, _Py_Uid_Converter, &euid, _Py_Uid_Converter, &suid)) - goto exit; - return_value = os_setresuid_impl(module, ruid, euid, suid); - -exit: - return return_value; -} - -static PyObject * -os_setresuid_impl(PyModuleDef *module, uid_t ruid, uid_t euid, uid_t suid) -/*[clinic end generated code: output=2e3457cfe7cd1f94 input=9e33cb79a82792f3]*/ -{ +PyDoc_STRVAR(posix_setresuid__doc__, +"setresuid(ruid, euid, suid)\n\n\ +Set the current process's real, effective, and saved user ids."); + +static PyObject* +posix_setresuid (PyObject *self, PyObject *args) +{ + /* We assume uid_t is no larger than a long. */ + uid_t ruid, euid, suid; + if (!PyArg_ParseTuple(args, "O&O&O&:setresuid", + _Py_Uid_Converter, &ruid, + _Py_Uid_Converter, &euid, + _Py_Uid_Converter, &suid)) + return NULL; if (setresuid(ruid, euid, suid) < 0) return posix_error(); Py_RETURN_NONE; } -#endif /* HAVE_SETRESUID */ - +#endif #ifdef HAVE_SETRESGID -/*[clinic input] -os.setresgid - - rgid: gid_t - egid: gid_t - sgid: gid_t - / - -Set the current process's real, effective, and saved group ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setresgid__doc__, -"setresgid($module, rgid, egid, sgid, /)\n" -"--\n" -"\n" -"Set the current process\'s real, effective, and saved group ids."); - -#define OS_SETRESGID_METHODDEF \ - {"setresgid", (PyCFunction)os_setresgid, METH_VARARGS, os_setresgid__doc__}, - -static PyObject * -os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid); - -static PyObject * -os_setresgid(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - gid_t rgid; - gid_t egid; - gid_t sgid; - - if (!PyArg_ParseTuple(args, - "O&O&O&:setresgid", - _Py_Gid_Converter, &rgid, _Py_Gid_Converter, &egid, _Py_Gid_Converter, &sgid)) - goto exit; - return_value = os_setresgid_impl(module, rgid, egid, sgid); - -exit: - return return_value; -} - -static PyObject * -os_setresgid_impl(PyModuleDef *module, gid_t rgid, gid_t egid, gid_t sgid) -/*[clinic end generated code: output=8a7ee6c1f2482362 input=33e9e0785ef426b1]*/ -{ +PyDoc_STRVAR(posix_setresgid__doc__, +"setresgid(rgid, egid, sgid)\n\n\ +Set the current process's real, effective, and saved group ids."); + +static PyObject* +posix_setresgid (PyObject *self, PyObject *args) +{ + gid_t rgid, egid, sgid; + if (!PyArg_ParseTuple(args, "O&O&O&:setresgid", + _Py_Gid_Converter, &rgid, + _Py_Gid_Converter, &egid, + _Py_Gid_Converter, &sgid)) + return NULL; if (setresgid(rgid, egid, sgid) < 0) return posix_error(); Py_RETURN_NONE; } -#endif /* HAVE_SETRESGID */ - +#endif #ifdef HAVE_GETRESUID -/*[clinic input] -os.getresuid - -Return a tuple of the current process's real, effective, and saved user ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getresuid__doc__, -"getresuid($module, /)\n" -"--\n" -"\n" -"Return a tuple of the current process\'s real, effective, and saved user ids."); - -#define OS_GETRESUID_METHODDEF \ - {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__}, - -static PyObject * -os_getresuid_impl(PyModuleDef *module); - -static PyObject * -os_getresuid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getresuid_impl(module); -} - -static PyObject * -os_getresuid_impl(PyModuleDef *module) -/*[clinic end generated code: output=d0786686a6ef1320 input=41ccfa8e1f6517ad]*/ +PyDoc_STRVAR(posix_getresuid__doc__, +"getresuid() -> (ruid, euid, suid)\n\n\ +Get tuple of the current process's real, effective, and saved user ids."); + +static PyObject* +posix_getresuid (PyObject *self, PyObject *noargs) { uid_t ruid, euid, suid; if (getresuid(&ruid, &euid, &suid) < 0) @@ -15397,116 +10550,59 @@ _PyLong_FromUid(euid), _PyLong_FromUid(suid)); } -#endif /* HAVE_GETRESUID */ - +#endif #ifdef HAVE_GETRESGID -/*[clinic input] -os.getresgid - -Return a tuple of the current process's real, effective, and saved group ids. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getresgid__doc__, -"getresgid($module, /)\n" -"--\n" -"\n" -"Return a tuple of the current process\'s real, effective, and saved group ids."); - -#define OS_GETRESGID_METHODDEF \ - {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__}, - -static PyObject * -os_getresgid_impl(PyModuleDef *module); - -static PyObject * -os_getresgid(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_getresgid_impl(module); -} - -static PyObject * -os_getresgid_impl(PyModuleDef *module) -/*[clinic end generated code: output=05249ac795fa759f input=517e68db9ca32df6]*/ -{ - gid_t rgid, egid, sgid; +PyDoc_STRVAR(posix_getresgid__doc__, +"getresgid() -> (rgid, egid, sgid)\n\n\ +Get tuple of the current process's real, effective, and saved group ids."); + +static PyObject* +posix_getresgid (PyObject *self, PyObject *noargs) +{ + uid_t rgid, egid, sgid; if (getresgid(&rgid, &egid, &sgid) < 0) return posix_error(); return Py_BuildValue("(NNN)", _PyLong_FromGid(rgid), _PyLong_FromGid(egid), _PyLong_FromGid(sgid)); } -#endif /* HAVE_GETRESGID */ - +#endif #ifdef USE_XATTRS -/*[clinic input] -os.getxattr - - path: path_t(allow_fd=True) - attribute: path_t - * - follow_symlinks: bool = True - -Return the value of extended attribute attribute on path. - -path may be either a string or an open file descriptor. -If follow_symlinks is False, and the last element of the path is a symbolic - link, getxattr will examine the symbolic link itself instead of the file - the link points to. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_getxattr__doc__, -"getxattr($module, /, path, attribute, *, follow_symlinks=True)\n" -"--\n" -"\n" -"Return the value of extended attribute attribute on path.\n" -"\n" -"path may be either a string or an open file descriptor.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, getxattr will examine the symbolic link itself instead of the file\n" -" the link points to."); - -#define OS_GETXATTR_METHODDEF \ - {"getxattr", (PyCFunction)os_getxattr, METH_VARARGS|METH_KEYWORDS, os_getxattr__doc__}, - -static PyObject * -os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks); - -static PyObject * -os_getxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("getxattr", "path", 0, 1); - path_t attribute = PATH_T_INITIALIZE("getxattr", "attribute", 0, 0); + +PyDoc_STRVAR(posix_getxattr__doc__, +"getxattr(path, attribute, *, follow_symlinks=True) -> value\n\n\ +Return the value of extended attribute attribute on path.\n\ +\n\ +path may be either a string or an open file descriptor.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, getxattr will examine the symbolic link itself instead of the file\n\ + the link points to."); + +static PyObject * +posix_getxattr(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + path_t attribute; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|$p:getxattr", _keywords, - path_converter, &path, path_converter, &attribute, &follow_symlinks)) + PyObject *buffer = NULL; + int i; + static char *keywords[] = {"path", "attribute", "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + memset(&attribute, 0, sizeof(attribute)); + path.function_name = "getxattr"; + attribute.function_name = "getxattr"; + path.allow_fd = 1; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:getxattr", keywords, + path_converter, &path, + path_converter, &attribute, + &follow_symlinks)) + return NULL; + + if (fd_and_follow_symlinks_invalid("getxattr", path.fd, follow_symlinks)) goto exit; - return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - /* Cleanup for attribute */ - path_cleanup(&attribute); - - return return_value; -} - -static PyObject * -os_getxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks) -/*[clinic end generated code: output=bbc9454fe2b9ea86 input=8c8ea3bab78d89c2]*/ -{ - Py_ssize_t i; - PyObject *buffer = NULL; - - if (fd_and_follow_symlinks_invalid("getxattr", path->fd, follow_symlinks)) - return NULL; for (i = 0; ; i++) { void *ptr; @@ -15514,29 +10610,30 @@ static Py_ssize_t buffer_sizes[] = {128, XATTR_SIZE_MAX, 0}; Py_ssize_t buffer_size = buffer_sizes[i]; if (!buffer_size) { - path_error(path); - return NULL; + path_error(&path); + goto exit; } buffer = PyBytes_FromStringAndSize(NULL, buffer_size); if (!buffer) - return NULL; + goto exit; ptr = PyBytes_AS_STRING(buffer); Py_BEGIN_ALLOW_THREADS; - if (path->fd >= 0) - result = fgetxattr(path->fd, attribute->narrow, ptr, buffer_size); + if (path.fd >= 0) + result = fgetxattr(path.fd, attribute.narrow, ptr, buffer_size); else if (follow_symlinks) - result = getxattr(path->narrow, attribute->narrow, ptr, buffer_size); + result = getxattr(path.narrow, attribute.narrow, ptr, buffer_size); else - result = lgetxattr(path->narrow, attribute->narrow, ptr, buffer_size); + result = lgetxattr(path.narrow, attribute.narrow, ptr, buffer_size); Py_END_ALLOW_THREADS; if (result < 0) { Py_DECREF(buffer); + buffer = NULL; if (errno == ERANGE) continue; - path_error(path); - return NULL; + path_error(&path); + goto exit; } if (result != buffer_size) { @@ -15546,259 +10643,168 @@ break; } +exit: + path_cleanup(&path); + path_cleanup(&attribute); return buffer; } - -/*[clinic input] -os.setxattr - - path: path_t(allow_fd=True) - attribute: path_t - value: Py_buffer - flags: int = 0 - * - follow_symlinks: bool = True - -Set extended attribute attribute on path to value. - -path may be either a string or an open file descriptor. -If follow_symlinks is False, and the last element of the path is a symbolic - link, setxattr will modify the symbolic link itself instead of the file - the link points to. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_setxattr__doc__, -"setxattr($module, /, path, attribute, value, flags=0, *,\n" -" follow_symlinks=True)\n" -"--\n" -"\n" -"Set extended attribute attribute on path to value.\n" -"\n" -"path may be either a string or an open file descriptor.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, setxattr will modify the symbolic link itself instead of the file\n" -" the link points to."); - -#define OS_SETXATTR_METHODDEF \ - {"setxattr", (PyCFunction)os_setxattr, METH_VARARGS|METH_KEYWORDS, os_setxattr__doc__}, - -static PyObject * -os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, Py_buffer *value, int flags, int follow_symlinks); - -static PyObject * -os_setxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("setxattr", "path", 0, 1); - path_t attribute = PATH_T_INITIALIZE("setxattr", "attribute", 0, 0); - Py_buffer value = {NULL, NULL}; +PyDoc_STRVAR(posix_setxattr__doc__, +"setxattr(path, attribute, value, flags=0, *, follow_symlinks=True)\n\n\ +Set extended attribute attribute on path to value.\n\ +path may be either a string or an open file descriptor.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, setxattr will modify the symbolic link itself instead of the file\n\ + the link points to."); + +static PyObject * +posix_setxattr(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + path_t attribute; + Py_buffer value; int flags = 0; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&y*|i$p:setxattr", _keywords, - path_converter, &path, path_converter, &attribute, &value, &flags, &follow_symlinks)) + int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "attribute", "value", + "flags", "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "setxattr"; + path.allow_fd = 1; + memset(&attribute, 0, sizeof(attribute)); + memset(&value, 0, sizeof(value)); + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&y*|i$p:setxattr", + keywords, + path_converter, &path, + path_converter, &attribute, + &value, &flags, + &follow_symlinks)) + return NULL; + + if (fd_and_follow_symlinks_invalid("setxattr", path.fd, follow_symlinks)) goto exit; - return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks); + + Py_BEGIN_ALLOW_THREADS; + if (path.fd > -1) + result = fsetxattr(path.fd, attribute.narrow, + value.buf, value.len, flags); + else if (follow_symlinks) + result = setxattr(path.narrow, attribute.narrow, + value.buf, value.len, flags); + else + result = lsetxattr(path.narrow, attribute.narrow, + value.buf, value.len, flags); + Py_END_ALLOW_THREADS; + + if (result) { + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(return_value); exit: - /* Cleanup for path */ path_cleanup(&path); - /* Cleanup for attribute */ path_cleanup(&attribute); - /* Cleanup for value */ - if (value.obj) - PyBuffer_Release(&value); + PyBuffer_Release(&value); return return_value; } -static PyObject * -os_setxattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, Py_buffer *value, int flags, int follow_symlinks) -/*[clinic end generated code: output=2ff845d8e024b218 input=f0d26833992015c2]*/ -{ - ssize_t result; - - if (fd_and_follow_symlinks_invalid("setxattr", path->fd, follow_symlinks)) - return NULL; +PyDoc_STRVAR(posix_removexattr__doc__, +"removexattr(path, attribute, *, follow_symlinks=True)\n\n\ +Remove extended attribute attribute on path.\n\ +path may be either a string or an open file descriptor.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, removexattr will modify the symbolic link itself instead of the file\n\ + the link points to."); + +static PyObject * +posix_removexattr(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; + path_t attribute; + int follow_symlinks = 1; + int result; + PyObject *return_value = NULL; + static char *keywords[] = {"path", "attribute", "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "removexattr"; + memset(&attribute, 0, sizeof(attribute)); + attribute.function_name = "removexattr"; + path.allow_fd = 1; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&O&|$p:removexattr", + keywords, + path_converter, &path, + path_converter, &attribute, + &follow_symlinks)) + return NULL; + + if (fd_and_follow_symlinks_invalid("removexattr", path.fd, follow_symlinks)) + goto exit; Py_BEGIN_ALLOW_THREADS; - if (path->fd > -1) - result = fsetxattr(path->fd, attribute->narrow, - value->buf, value->len, flags); + if (path.fd > -1) + result = fremovexattr(path.fd, attribute.narrow); else if (follow_symlinks) - result = setxattr(path->narrow, attribute->narrow, - value->buf, value->len, flags); + result = removexattr(path.narrow, attribute.narrow); else - result = lsetxattr(path->narrow, attribute->narrow, - value->buf, value->len, flags); + result = lremovexattr(path.narrow, attribute.narrow); Py_END_ALLOW_THREADS; if (result) { - path_error(path); - return NULL; - } - - Py_RETURN_NONE; -} - - -/*[clinic input] -os.removexattr - - path: path_t(allow_fd=True) - attribute: path_t - * - follow_symlinks: bool = True - -Remove extended attribute attribute on path. - -path may be either a string or an open file descriptor. -If follow_symlinks is False, and the last element of the path is a symbolic - link, removexattr will modify the symbolic link itself instead of the file - the link points to. - -[clinic start generated code]*/ - -PyDoc_STRVAR(os_removexattr__doc__, -"removexattr($module, /, path, attribute, *, follow_symlinks=True)\n" -"--\n" -"\n" -"Remove extended attribute attribute on path.\n" -"\n" -"path may be either a string or an open file descriptor.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, removexattr will modify the symbolic link itself instead of the file\n" -" the link points to."); - -#define OS_REMOVEXATTR_METHODDEF \ - {"removexattr", (PyCFunction)os_removexattr, METH_VARARGS|METH_KEYWORDS, os_removexattr__doc__}, - -static PyObject * -os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks); - -static PyObject * -os_removexattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "attribute", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("removexattr", "path", 0, 1); - path_t attribute = PATH_T_INITIALIZE("removexattr", "attribute", 0, 0); + return_value = path_error(&path); + goto exit; + } + + return_value = Py_None; + Py_INCREF(return_value); + +exit: + path_cleanup(&path); + path_cleanup(&attribute); + + return return_value; +} + +PyDoc_STRVAR(posix_listxattr__doc__, +"listxattr(path='.', *, follow_symlinks=True)\n\n\ +Return a list of extended attributes on path.\n\ +\n\ +path may be either None, a string, or an open file descriptor.\n\ +if path is None, listxattr will examine the current directory.\n\ +If follow_symlinks is False, and the last element of the path is a symbolic\n\ + link, listxattr will examine the symbolic link itself instead of the file\n\ + the link points to."); + +static PyObject * +posix_listxattr(PyObject *self, PyObject *args, PyObject *kwargs) +{ + path_t path; int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "O&O&|$p:removexattr", _keywords, - path_converter, &path, path_converter, &attribute, &follow_symlinks)) - goto exit; - return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - /* Cleanup for attribute */ - path_cleanup(&attribute); - - return return_value; -} - -static PyObject * -os_removexattr_impl(PyModuleDef *module, path_t *path, path_t *attribute, int follow_symlinks) -/*[clinic end generated code: output=8dfc715bf607c4cf input=cdb54834161e3329]*/ -{ - ssize_t result; - - if (fd_and_follow_symlinks_invalid("removexattr", path->fd, follow_symlinks)) - return NULL; - - Py_BEGIN_ALLOW_THREADS; - if (path->fd > -1) - result = fremovexattr(path->fd, attribute->narrow); - else if (follow_symlinks) - result = removexattr(path->narrow, attribute->narrow); - else - result = lremovexattr(path->narrow, attribute->narrow); - Py_END_ALLOW_THREADS; - - if (result) { - return path_error(path); - } - - Py_RETURN_NONE; -} - - -/*[clinic input] -os.listxattr - - path: path_t(allow_fd=True, nullable=True) = None - * - follow_symlinks: bool = True - -Return a list of extended attributes on path. - -path may be either None, a string, or an open file descriptor. -if path is None, listxattr will examine the current directory. -If follow_symlinks is False, and the last element of the path is a symbolic - link, listxattr will examine the symbolic link itself instead of the file - the link points to. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_listxattr__doc__, -"listxattr($module, /, path=None, *, follow_symlinks=True)\n" -"--\n" -"\n" -"Return a list of extended attributes on path.\n" -"\n" -"path may be either None, a string, or an open file descriptor.\n" -"if path is None, listxattr will examine the current directory.\n" -"If follow_symlinks is False, and the last element of the path is a symbolic\n" -" link, listxattr will examine the symbolic link itself instead of the file\n" -" the link points to."); - -#define OS_LISTXATTR_METHODDEF \ - {"listxattr", (PyCFunction)os_listxattr, METH_VARARGS|METH_KEYWORDS, os_listxattr__doc__}, - -static PyObject * -os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks); - -static PyObject * -os_listxattr(PyModuleDef *module, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"path", "follow_symlinks", NULL}; - path_t path = PATH_T_INITIALIZE("listxattr", "path", 1, 1); - int follow_symlinks = 1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O&$p:listxattr", _keywords, - path_converter, &path, &follow_symlinks)) - goto exit; - return_value = os_listxattr_impl(module, &path, follow_symlinks); - -exit: - /* Cleanup for path */ - path_cleanup(&path); - - return return_value; -} - -static PyObject * -os_listxattr_impl(PyModuleDef *module, path_t *path, int follow_symlinks) -/*[clinic end generated code: output=3104cafda1a3d887 input=08cca53ac0b07c13]*/ -{ Py_ssize_t i; PyObject *result = NULL; - const char *name; char *buffer = NULL; - - if (fd_and_follow_symlinks_invalid("listxattr", path->fd, follow_symlinks)) + char *name; + static char *keywords[] = {"path", "follow_symlinks", NULL}; + + memset(&path, 0, sizeof(path)); + path.function_name = "listxattr"; + path.allow_fd = 1; + path.fd = -1; + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O&$p:listxattr", keywords, + path_converter, &path, + &follow_symlinks)) + return NULL; + + if (fd_and_follow_symlinks_invalid("listxattr", path.fd, follow_symlinks)) goto exit; - name = path->narrow ? path->narrow : "."; - + name = path.narrow ? path.narrow : "."; for (i = 0; ; i++) { char *start, *trace, *end; ssize_t length; @@ -15806,7 +10812,7 @@ Py_ssize_t buffer_size = buffer_sizes[i]; if (!buffer_size) { /* ERANGE */ - path_error(path); + path_error(&path); break; } buffer = PyMem_MALLOC(buffer_size); @@ -15816,8 +10822,8 @@ } Py_BEGIN_ALLOW_THREADS; - if (path->fd > -1) - length = flistxattr(path->fd, buffer, buffer_size); + if (path.fd > -1) + length = flistxattr(path.fd, buffer, buffer_size); else if (follow_symlinks) length = listxattr(name, buffer, buffer_size); else @@ -15830,7 +10836,7 @@ buffer = NULL; continue; } - path_error(path); + path_error(&path); break; } @@ -15863,71 +10869,43 @@ break; } exit: + path_cleanup(&path); if (buffer) PyMem_FREE(buffer); return result; } + #endif /* USE_XATTRS */ -/*[clinic input] -os.urandom - - size: Py_ssize_t - / - -Return a bytes object containing random bytes suitable for cryptographic use. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_urandom__doc__, -"urandom($module, size, /)\n" -"--\n" -"\n" -"Return a bytes object containing random bytes suitable for cryptographic use."); - -#define OS_URANDOM_METHODDEF \ - {"urandom", (PyCFunction)os_urandom, METH_VARARGS, os_urandom__doc__}, - -static PyObject * -os_urandom_impl(PyModuleDef *module, Py_ssize_t size); - -static PyObject * -os_urandom(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(posix_urandom__doc__, +"urandom(n) -> str\n\n\ +Return n random bytes suitable for cryptographic use."); + +static PyObject * +posix_urandom(PyObject *self, PyObject *args) +{ Py_ssize_t size; - - if (!PyArg_ParseTuple(args, - "n:urandom", - &size)) - goto exit; - return_value = os_urandom_impl(module, size); - -exit: - return return_value; -} - -static PyObject * -os_urandom_impl(PyModuleDef *module, Py_ssize_t size) -/*[clinic end generated code: output=5dbff582cab94cb9 input=4067cdb1b6776c29]*/ -{ - PyObject *bytes; - int result; - + PyObject *result; + int ret; + + /* Read arguments */ + if (!PyArg_ParseTuple(args, "n:urandom", &size)) + return NULL; if (size < 0) return PyErr_Format(PyExc_ValueError, "negative argument not allowed"); - bytes = PyBytes_FromStringAndSize(NULL, size); - if (bytes == NULL) - return NULL; - - result = _PyOS_URandom(PyBytes_AS_STRING(bytes), - PyBytes_GET_SIZE(bytes)); - if (result == -1) { - Py_DECREF(bytes); - return NULL; - } - return bytes; + result = PyBytes_FromStringAndSize(NULL, size); + if (result == NULL) + return NULL; + + ret = _PyOS_URandom(PyBytes_AS_STRING(result), + PyBytes_GET_SIZE(result)); + if (ret == -1) { + Py_DECREF(result); + return NULL; + } + return result; } /* Terminal size querying */ @@ -15951,7 +10929,6 @@ }; #if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) -/* AC 3.5: fd should accept None */ PyDoc_STRVAR(termsize__doc__, "Return the size of the terminal window as (columns, lines).\n" \ "\n" \ @@ -16037,34 +11014,13 @@ } #endif /* defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) */ - -/*[clinic input] -os.cpu_count - -Return the number of CPUs in the system; return None if indeterminable. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_cpu_count__doc__, -"cpu_count($module, /)\n" -"--\n" -"\n" -"Return the number of CPUs in the system; return None if indeterminable."); - -#define OS_CPU_COUNT_METHODDEF \ - {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__}, - -static PyObject * -os_cpu_count_impl(PyModuleDef *module); - -static PyObject * -os_cpu_count(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) -{ - return os_cpu_count_impl(module); -} - -static PyObject * -os_cpu_count_impl(PyModuleDef *module) -/*[clinic end generated code: output=92e2a4a729eb7740 input=d55e2f8f3823a628]*/ +PyDoc_STRVAR(posix_cpu_count__doc__, +"cpu_count() -> integer\n\n\ +Return the number of CPUs in the system, or None if this value cannot be\n\ +established."); + +static PyObject * +posix_cpu_count(PyObject *self) { int ncpu = 0; #ifdef MS_WINDOWS @@ -16093,106 +11049,45 @@ Py_RETURN_NONE; } - -/*[clinic input] -os.get_inheritable -> bool - - fd: int - / - -Get the close-on-exe flag of the specified file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_get_inheritable__doc__, -"get_inheritable($module, fd, /)\n" -"--\n" -"\n" -"Get the close-on-exe flag of the specified file descriptor."); - -#define OS_GET_INHERITABLE_METHODDEF \ - {"get_inheritable", (PyCFunction)os_get_inheritable, METH_VARARGS, os_get_inheritable__doc__}, - -static int -os_get_inheritable_impl(PyModuleDef *module, int fd); - -static PyObject * -os_get_inheritable(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; - int fd; - int _return_value; - - if (!PyArg_ParseTuple(args, - "i:get_inheritable", - &fd)) - goto exit; - _return_value = os_get_inheritable_impl(module, fd); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_get_inheritable_impl(PyModuleDef *module, int fd) -/*[clinic end generated code: output=261d1dd2b0dbdc35 input=89ac008dc9ab6b95]*/ -{ - if (!_PyVerify_fd(fd)){ - posix_error(); - return -1; - } - - return _Py_get_inheritable(fd); -} - - -/*[clinic input] -os.set_inheritable - fd: int - inheritable: int - / - -Set the inheritable flag of the specified file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_set_inheritable__doc__, -"set_inheritable($module, fd, inheritable, /)\n" -"--\n" -"\n" -"Set the inheritable flag of the specified file descriptor."); - -#define OS_SET_INHERITABLE_METHODDEF \ - {"set_inheritable", (PyCFunction)os_set_inheritable, METH_VARARGS, os_set_inheritable__doc__}, - -static PyObject * -os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable); - -static PyObject * -os_set_inheritable(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(get_inheritable__doc__, + "get_inheritable(fd) -> bool\n" \ + "\n" \ + "Get the close-on-exe flag of the specified file descriptor."); + +static PyObject* +posix_get_inheritable(PyObject *self, PyObject *args) +{ int fd; int inheritable; - if (!PyArg_ParseTuple(args, - "ii:set_inheritable", - &fd, &inheritable)) - goto exit; - return_value = os_set_inheritable_impl(module, fd, inheritable); - -exit: - return return_value; -} - -static PyObject * -os_set_inheritable_impl(PyModuleDef *module, int fd, int inheritable) -/*[clinic end generated code: output=64dfe5e15c906539 input=9ceaead87a1e2402]*/ -{ + if (!PyArg_ParseTuple(args, "i:get_inheritable", &fd)) + return NULL; + if (!_PyVerify_fd(fd)) return posix_error(); + inheritable = _Py_get_inheritable(fd); + if (inheritable < 0) + return NULL; + return PyBool_FromLong(inheritable); +} + +PyDoc_STRVAR(set_inheritable__doc__, + "set_inheritable(fd, inheritable)\n" \ + "\n" \ + "Set the inheritable flag of the specified file descriptor."); + +static PyObject* +posix_set_inheritable(PyObject *self, PyObject *args) +{ + int fd, inheritable; + + if (!PyArg_ParseTuple(args, "ii:set_inheritable", &fd, &inheritable)) + return NULL; + + if (!_PyVerify_fd(fd)) + return posix_error(); + if (_Py_set_inheritable(fd, inheritable, NULL) < 0) return NULL; Py_RETURN_NONE; @@ -16200,160 +11095,55 @@ #ifdef MS_WINDOWS -/*[clinic input] -os.get_handle_inheritable -> bool - handle: Py_intptr_t - / - -Get the close-on-exe flag of the specified file descriptor. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_get_handle_inheritable__doc__, -"get_handle_inheritable($module, handle, /)\n" -"--\n" -"\n" -"Get the close-on-exe flag of the specified file descriptor."); - -#define OS_GET_HANDLE_INHERITABLE_METHODDEF \ - {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_VARARGS, os_get_handle_inheritable__doc__}, - -static int -os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle); - -static PyObject * -os_get_handle_inheritable(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; +PyDoc_STRVAR(get_handle_inheritable__doc__, + "get_handle_inheritable(fd) -> bool\n" \ + "\n" \ + "Get the close-on-exe flag of the specified file descriptor."); + +static PyObject* +posix_get_handle_inheritable(PyObject *self, PyObject *args) +{ Py_intptr_t handle; - int _return_value; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_INTPTR ":get_handle_inheritable", - &handle)) - goto exit; - _return_value = os_get_handle_inheritable_impl(module, handle); - if ((_return_value == -1) && PyErr_Occurred()) - goto exit; - return_value = PyBool_FromLong((long)_return_value); - -exit: - return return_value; -} - -static int -os_get_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle) -/*[clinic end generated code: output=d5bf9d86900bf457 input=5f7759443aae3dc5]*/ -{ DWORD flags; + if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) + return NULL; + if (!GetHandleInformation((HANDLE)handle, &flags)) { PyErr_SetFromWindowsErr(0); - return -1; - } - - return flags & HANDLE_FLAG_INHERIT; -} - - -/*[clinic input] -os.set_handle_inheritable - handle: Py_intptr_t - inheritable: bool - / - -Set the inheritable flag of the specified handle. -[clinic start generated code]*/ - -PyDoc_STRVAR(os_set_handle_inheritable__doc__, -"set_handle_inheritable($module, handle, inheritable, /)\n" -"--\n" -"\n" -"Set the inheritable flag of the specified handle."); - -#define OS_SET_HANDLE_INHERITABLE_METHODDEF \ - {"set_handle_inheritable", (PyCFunction)os_set_handle_inheritable, METH_VARARGS, os_set_handle_inheritable__doc__}, - -static PyObject * -os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle, int inheritable); - -static PyObject * -os_set_handle_inheritable(PyModuleDef *module, PyObject *args) -{ - PyObject *return_value = NULL; + return NULL; + } + + return PyBool_FromLong(flags & HANDLE_FLAG_INHERIT); +} + +PyDoc_STRVAR(set_handle_inheritable__doc__, + "set_handle_inheritable(fd, inheritable)\n" \ + "\n" \ + "Set the inheritable flag of the specified handle."); + +static PyObject* +posix_set_handle_inheritable(PyObject *self, PyObject *args) +{ + int inheritable = 1; Py_intptr_t handle; - int inheritable; - - if (!PyArg_ParseTuple(args, - "" _Py_PARSE_INTPTR "p:set_handle_inheritable", - &handle, &inheritable)) - goto exit; - return_value = os_set_handle_inheritable_impl(module, handle, inheritable); - -exit: - return return_value; -} - -static PyObject * -os_set_handle_inheritable_impl(PyModuleDef *module, Py_intptr_t handle, int inheritable) -/*[clinic end generated code: output=ee5fcc6d9f0d4f8b input=e64b2b2730469def]*/ -{ - DWORD flags = inheritable ? HANDLE_FLAG_INHERIT : 0; + DWORD flags; + + if (!PyArg_ParseTuple(args, _Py_PARSE_INTPTR "i:set_handle_inheritable", + &handle, &inheritable)) + return NULL; + + if (inheritable) + flags = HANDLE_FLAG_INHERIT; + else + flags = 0; if (!SetHandleInformation((HANDLE)handle, HANDLE_FLAG_INHERIT, flags)) { PyErr_SetFromWindowsErr(0); return NULL; } Py_RETURN_NONE; } -#endif /* MS_WINDOWS */ - -#ifndef MS_WINDOWS -PyDoc_STRVAR(get_blocking__doc__, - "get_blocking(fd) -> bool\n" \ - "\n" \ - "Get the blocking mode of the file descriptor:\n" \ - "False if the O_NONBLOCK flag is set, True if the flag is cleared."); - -static PyObject* -posix_get_blocking(PyObject *self, PyObject *args) -{ - int fd; - int blocking; - - if (!PyArg_ParseTuple(args, "i:get_blocking", &fd)) - return NULL; - - if (!_PyVerify_fd(fd)) - return posix_error(); - - blocking = _Py_get_blocking(fd); - if (blocking < 0) - return NULL; - return PyBool_FromLong(blocking); -} - -PyDoc_STRVAR(set_blocking__doc__, - "set_blocking(fd, blocking)\n" \ - "\n" \ - "Set the blocking mode of the specified file descriptor.\n" \ - "Set the O_NONBLOCK flag if blocking is False,\n" \ - "clear the O_NONBLOCK flag otherwise."); - -static PyObject* -posix_set_blocking(PyObject *self, PyObject *args) -{ - int fd, blocking; - - if (!PyArg_ParseTuple(args, "ii:set_blocking", &fd, &blocking)) - return NULL; - - if (!_PyVerify_fd(fd)) - return posix_error(); - - if (_Py_set_blocking(fd, blocking) < 0) - return NULL; - Py_RETURN_NONE; -} -#endif /* !MS_WINDOWS */ +#endif /* MS_WINDOWS */ /*[clinic input] @@ -16363,479 +11153,7 @@ #ifndef OS_TTYNAME_METHODDEF #define OS_TTYNAME_METHODDEF #endif /* !defined(OS_TTYNAME_METHODDEF) */ - -#ifndef OS_CTERMID_METHODDEF - #define OS_CTERMID_METHODDEF -#endif /* !defined(OS_CTERMID_METHODDEF) */ - -#ifndef OS_FCHDIR_METHODDEF - #define OS_FCHDIR_METHODDEF -#endif /* !defined(OS_FCHDIR_METHODDEF) */ - -#ifndef OS_FCHMOD_METHODDEF - #define OS_FCHMOD_METHODDEF -#endif /* !defined(OS_FCHMOD_METHODDEF) */ - -#ifndef OS_LCHMOD_METHODDEF - #define OS_LCHMOD_METHODDEF -#endif /* !defined(OS_LCHMOD_METHODDEF) */ - -#ifndef OS_CHFLAGS_METHODDEF - #define OS_CHFLAGS_METHODDEF -#endif /* !defined(OS_CHFLAGS_METHODDEF) */ - -#ifndef OS_LCHFLAGS_METHODDEF - #define OS_LCHFLAGS_METHODDEF -#endif /* !defined(OS_LCHFLAGS_METHODDEF) */ - -#ifndef OS_CHROOT_METHODDEF - #define OS_CHROOT_METHODDEF -#endif /* !defined(OS_CHROOT_METHODDEF) */ - -#ifndef OS_FSYNC_METHODDEF - #define OS_FSYNC_METHODDEF -#endif /* !defined(OS_FSYNC_METHODDEF) */ - -#ifndef OS_SYNC_METHODDEF - #define OS_SYNC_METHODDEF -#endif /* !defined(OS_SYNC_METHODDEF) */ - -#ifndef OS_FDATASYNC_METHODDEF - #define OS_FDATASYNC_METHODDEF -#endif /* !defined(OS_FDATASYNC_METHODDEF) */ - -#ifndef OS_CHOWN_METHODDEF - #define OS_CHOWN_METHODDEF -#endif /* !defined(OS_CHOWN_METHODDEF) */ - -#ifndef OS_FCHOWN_METHODDEF - #define OS_FCHOWN_METHODDEF -#endif /* !defined(OS_FCHOWN_METHODDEF) */ - -#ifndef OS_LCHOWN_METHODDEF - #define OS_LCHOWN_METHODDEF -#endif /* !defined(OS_LCHOWN_METHODDEF) */ - -#ifndef OS_LINK_METHODDEF - #define OS_LINK_METHODDEF -#endif /* !defined(OS_LINK_METHODDEF) */ - -#ifndef OS__GETFINALPATHNAME_METHODDEF - #define OS__GETFINALPATHNAME_METHODDEF -#endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */ - -#ifndef OS__GETVOLUMEPATHNAME_METHODDEF - #define OS__GETVOLUMEPATHNAME_METHODDEF -#endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */ - -#ifndef OS_NICE_METHODDEF - #define OS_NICE_METHODDEF -#endif /* !defined(OS_NICE_METHODDEF) */ - -#ifndef OS_GETPRIORITY_METHODDEF - #define OS_GETPRIORITY_METHODDEF -#endif /* !defined(OS_GETPRIORITY_METHODDEF) */ - -#ifndef OS_SETPRIORITY_METHODDEF - #define OS_SETPRIORITY_METHODDEF -#endif /* !defined(OS_SETPRIORITY_METHODDEF) */ - -#ifndef OS_SYSTEM_METHODDEF - #define OS_SYSTEM_METHODDEF -#endif /* !defined(OS_SYSTEM_METHODDEF) */ - -#ifndef OS_SYSTEM_METHODDEF - #define OS_SYSTEM_METHODDEF -#endif /* !defined(OS_SYSTEM_METHODDEF) */ - -#ifndef OS_UNAME_METHODDEF - #define OS_UNAME_METHODDEF -#endif /* !defined(OS_UNAME_METHODDEF) */ - -#ifndef OS_EXECV_METHODDEF - #define OS_EXECV_METHODDEF -#endif /* !defined(OS_EXECV_METHODDEF) */ - -#ifndef OS_EXECVE_METHODDEF - #define OS_EXECVE_METHODDEF -#endif /* !defined(OS_EXECVE_METHODDEF) */ - -#ifndef OS_SPAWNV_METHODDEF - #define OS_SPAWNV_METHODDEF -#endif /* !defined(OS_SPAWNV_METHODDEF) */ - -#ifndef OS_SPAWNVE_METHODDEF - #define OS_SPAWNVE_METHODDEF -#endif /* !defined(OS_SPAWNVE_METHODDEF) */ - -#ifndef OS_FORK1_METHODDEF - #define OS_FORK1_METHODDEF -#endif /* !defined(OS_FORK1_METHODDEF) */ - -#ifndef OS_FORK_METHODDEF - #define OS_FORK_METHODDEF -#endif /* !defined(OS_FORK_METHODDEF) */ - -#ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF - #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF -#endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */ - -#ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF - #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF -#endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */ - -#ifndef OS_SCHED_GETSCHEDULER_METHODDEF - #define OS_SCHED_GETSCHEDULER_METHODDEF -#endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */ - -#ifndef OS_SCHED_SETSCHEDULER_METHODDEF - #define OS_SCHED_SETSCHEDULER_METHODDEF -#endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */ - -#ifndef OS_SCHED_GETPARAM_METHODDEF - #define OS_SCHED_GETPARAM_METHODDEF -#endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */ - -#ifndef OS_SCHED_SETPARAM_METHODDEF - #define OS_SCHED_SETPARAM_METHODDEF -#endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */ - -#ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF - #define OS_SCHED_RR_GET_INTERVAL_METHODDEF -#endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */ - -#ifndef OS_SCHED_YIELD_METHODDEF - #define OS_SCHED_YIELD_METHODDEF -#endif /* !defined(OS_SCHED_YIELD_METHODDEF) */ - -#ifndef OS_SCHED_SETAFFINITY_METHODDEF - #define OS_SCHED_SETAFFINITY_METHODDEF -#endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */ - -#ifndef OS_SCHED_GETAFFINITY_METHODDEF - #define OS_SCHED_GETAFFINITY_METHODDEF -#endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */ - -#ifndef OS_OPENPTY_METHODDEF - #define OS_OPENPTY_METHODDEF -#endif /* !defined(OS_OPENPTY_METHODDEF) */ - -#ifndef OS_FORKPTY_METHODDEF - #define OS_FORKPTY_METHODDEF -#endif /* !defined(OS_FORKPTY_METHODDEF) */ - -#ifndef OS_GETEGID_METHODDEF - #define OS_GETEGID_METHODDEF -#endif /* !defined(OS_GETEGID_METHODDEF) */ - -#ifndef OS_GETEUID_METHODDEF - #define OS_GETEUID_METHODDEF -#endif /* !defined(OS_GETEUID_METHODDEF) */ - -#ifndef OS_GETGID_METHODDEF - #define OS_GETGID_METHODDEF -#endif /* !defined(OS_GETGID_METHODDEF) */ - -#ifndef OS_GETGROUPS_METHODDEF - #define OS_GETGROUPS_METHODDEF -#endif /* !defined(OS_GETGROUPS_METHODDEF) */ - -#ifndef OS_GETPGID_METHODDEF - #define OS_GETPGID_METHODDEF -#endif /* !defined(OS_GETPGID_METHODDEF) */ - -#ifndef OS_GETPGRP_METHODDEF - #define OS_GETPGRP_METHODDEF -#endif /* !defined(OS_GETPGRP_METHODDEF) */ - -#ifndef OS_SETPGRP_METHODDEF - #define OS_SETPGRP_METHODDEF -#endif /* !defined(OS_SETPGRP_METHODDEF) */ - -#ifndef OS_GETPPID_METHODDEF - #define OS_GETPPID_METHODDEF -#endif /* !defined(OS_GETPPID_METHODDEF) */ - -#ifndef OS_GETLOGIN_METHODDEF - #define OS_GETLOGIN_METHODDEF -#endif /* !defined(OS_GETLOGIN_METHODDEF) */ - -#ifndef OS_GETUID_METHODDEF - #define OS_GETUID_METHODDEF -#endif /* !defined(OS_GETUID_METHODDEF) */ - -#ifndef OS_KILL_METHODDEF - #define OS_KILL_METHODDEF -#endif /* !defined(OS_KILL_METHODDEF) */ - -#ifndef OS_KILLPG_METHODDEF - #define OS_KILLPG_METHODDEF -#endif /* !defined(OS_KILLPG_METHODDEF) */ - -#ifndef OS_PLOCK_METHODDEF - #define OS_PLOCK_METHODDEF -#endif /* !defined(OS_PLOCK_METHODDEF) */ - -#ifndef OS_SETUID_METHODDEF - #define OS_SETUID_METHODDEF -#endif /* !defined(OS_SETUID_METHODDEF) */ - -#ifndef OS_SETEUID_METHODDEF - #define OS_SETEUID_METHODDEF -#endif /* !defined(OS_SETEUID_METHODDEF) */ - -#ifndef OS_SETEGID_METHODDEF - #define OS_SETEGID_METHODDEF -#endif /* !defined(OS_SETEGID_METHODDEF) */ - -#ifndef OS_SETREUID_METHODDEF - #define OS_SETREUID_METHODDEF -#endif /* !defined(OS_SETREUID_METHODDEF) */ - -#ifndef OS_SETREGID_METHODDEF - #define OS_SETREGID_METHODDEF -#endif /* !defined(OS_SETREGID_METHODDEF) */ - -#ifndef OS_SETGID_METHODDEF - #define OS_SETGID_METHODDEF -#endif /* !defined(OS_SETGID_METHODDEF) */ - -#ifndef OS_SETGROUPS_METHODDEF - #define OS_SETGROUPS_METHODDEF -#endif /* !defined(OS_SETGROUPS_METHODDEF) */ - -#ifndef OS_WAIT3_METHODDEF - #define OS_WAIT3_METHODDEF -#endif /* !defined(OS_WAIT3_METHODDEF) */ - -#ifndef OS_WAIT4_METHODDEF - #define OS_WAIT4_METHODDEF -#endif /* !defined(OS_WAIT4_METHODDEF) */ - -#ifndef OS_WAITID_METHODDEF - #define OS_WAITID_METHODDEF -#endif /* !defined(OS_WAITID_METHODDEF) */ - -#ifndef OS_WAITPID_METHODDEF - #define OS_WAITPID_METHODDEF -#endif /* !defined(OS_WAITPID_METHODDEF) */ - -#ifndef OS_WAITPID_METHODDEF - #define OS_WAITPID_METHODDEF -#endif /* !defined(OS_WAITPID_METHODDEF) */ - -#ifndef OS_WAIT_METHODDEF - #define OS_WAIT_METHODDEF -#endif /* !defined(OS_WAIT_METHODDEF) */ - -#ifndef OS_SYMLINK_METHODDEF - #define OS_SYMLINK_METHODDEF -#endif /* !defined(OS_SYMLINK_METHODDEF) */ - -#ifndef OS_TIMES_METHODDEF - #define OS_TIMES_METHODDEF -#endif /* !defined(OS_TIMES_METHODDEF) */ - -#ifndef OS_GETSID_METHODDEF - #define OS_GETSID_METHODDEF -#endif /* !defined(OS_GETSID_METHODDEF) */ - -#ifndef OS_SETSID_METHODDEF - #define OS_SETSID_METHODDEF -#endif /* !defined(OS_SETSID_METHODDEF) */ - -#ifndef OS_SETPGID_METHODDEF - #define OS_SETPGID_METHODDEF -#endif /* !defined(OS_SETPGID_METHODDEF) */ - -#ifndef OS_TCGETPGRP_METHODDEF - #define OS_TCGETPGRP_METHODDEF -#endif /* !defined(OS_TCGETPGRP_METHODDEF) */ - -#ifndef OS_TCSETPGRP_METHODDEF - #define OS_TCSETPGRP_METHODDEF -#endif /* !defined(OS_TCSETPGRP_METHODDEF) */ - -#ifndef OS_LOCKF_METHODDEF - #define OS_LOCKF_METHODDEF -#endif /* !defined(OS_LOCKF_METHODDEF) */ - -#ifndef OS_READV_METHODDEF - #define OS_READV_METHODDEF -#endif /* !defined(OS_READV_METHODDEF) */ - -#ifndef OS_PREAD_METHODDEF - #define OS_PREAD_METHODDEF -#endif /* !defined(OS_PREAD_METHODDEF) */ - -#ifndef OS_PIPE_METHODDEF - #define OS_PIPE_METHODDEF -#endif /* !defined(OS_PIPE_METHODDEF) */ - -#ifndef OS_PIPE2_METHODDEF - #define OS_PIPE2_METHODDEF -#endif /* !defined(OS_PIPE2_METHODDEF) */ - -#ifndef OS_WRITEV_METHODDEF - #define OS_WRITEV_METHODDEF -#endif /* !defined(OS_WRITEV_METHODDEF) */ - -#ifndef OS_PWRITE_METHODDEF - #define OS_PWRITE_METHODDEF -#endif /* !defined(OS_PWRITE_METHODDEF) */ - -#ifndef OS_MKFIFO_METHODDEF - #define OS_MKFIFO_METHODDEF -#endif /* !defined(OS_MKFIFO_METHODDEF) */ - -#ifndef OS_MKNOD_METHODDEF - #define OS_MKNOD_METHODDEF -#endif /* !defined(OS_MKNOD_METHODDEF) */ - -#ifndef OS_MAJOR_METHODDEF - #define OS_MAJOR_METHODDEF -#endif /* !defined(OS_MAJOR_METHODDEF) */ - -#ifndef OS_MINOR_METHODDEF - #define OS_MINOR_METHODDEF -#endif /* !defined(OS_MINOR_METHODDEF) */ - -#ifndef OS_MAKEDEV_METHODDEF - #define OS_MAKEDEV_METHODDEF -#endif /* !defined(OS_MAKEDEV_METHODDEF) */ - -#ifndef OS_FTRUNCATE_METHODDEF - #define OS_FTRUNCATE_METHODDEF -#endif /* !defined(OS_FTRUNCATE_METHODDEF) */ - -#ifndef OS_TRUNCATE_METHODDEF - #define OS_TRUNCATE_METHODDEF -#endif /* !defined(OS_TRUNCATE_METHODDEF) */ - -#ifndef OS_POSIX_FALLOCATE_METHODDEF - #define OS_POSIX_FALLOCATE_METHODDEF -#endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */ - -#ifndef OS_POSIX_FADVISE_METHODDEF - #define OS_POSIX_FADVISE_METHODDEF -#endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */ - -#ifndef OS_PUTENV_METHODDEF - #define OS_PUTENV_METHODDEF -#endif /* !defined(OS_PUTENV_METHODDEF) */ - -#ifndef OS_PUTENV_METHODDEF - #define OS_PUTENV_METHODDEF -#endif /* !defined(OS_PUTENV_METHODDEF) */ - -#ifndef OS_UNSETENV_METHODDEF - #define OS_UNSETENV_METHODDEF -#endif /* !defined(OS_UNSETENV_METHODDEF) */ - -#ifndef OS_WCOREDUMP_METHODDEF - #define OS_WCOREDUMP_METHODDEF -#endif /* !defined(OS_WCOREDUMP_METHODDEF) */ - -#ifndef OS_WIFCONTINUED_METHODDEF - #define OS_WIFCONTINUED_METHODDEF -#endif /* !defined(OS_WIFCONTINUED_METHODDEF) */ - -#ifndef OS_WIFSTOPPED_METHODDEF - #define OS_WIFSTOPPED_METHODDEF -#endif /* !defined(OS_WIFSTOPPED_METHODDEF) */ - -#ifndef OS_WIFSIGNALED_METHODDEF - #define OS_WIFSIGNALED_METHODDEF -#endif /* !defined(OS_WIFSIGNALED_METHODDEF) */ - -#ifndef OS_WIFEXITED_METHODDEF - #define OS_WIFEXITED_METHODDEF -#endif /* !defined(OS_WIFEXITED_METHODDEF) */ - -#ifndef OS_WEXITSTATUS_METHODDEF - #define OS_WEXITSTATUS_METHODDEF -#endif /* !defined(OS_WEXITSTATUS_METHODDEF) */ - -#ifndef OS_WTERMSIG_METHODDEF - #define OS_WTERMSIG_METHODDEF -#endif /* !defined(OS_WTERMSIG_METHODDEF) */ - -#ifndef OS_WSTOPSIG_METHODDEF - #define OS_WSTOPSIG_METHODDEF -#endif /* !defined(OS_WSTOPSIG_METHODDEF) */ - -#ifndef OS_FSTATVFS_METHODDEF - #define OS_FSTATVFS_METHODDEF -#endif /* !defined(OS_FSTATVFS_METHODDEF) */ - -#ifndef OS_STATVFS_METHODDEF - #define OS_STATVFS_METHODDEF -#endif /* !defined(OS_STATVFS_METHODDEF) */ - -#ifndef OS__GETDISKUSAGE_METHODDEF - #define OS__GETDISKUSAGE_METHODDEF -#endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */ - -#ifndef OS_FPATHCONF_METHODDEF - #define OS_FPATHCONF_METHODDEF -#endif /* !defined(OS_FPATHCONF_METHODDEF) */ - -#ifndef OS_PATHCONF_METHODDEF - #define OS_PATHCONF_METHODDEF -#endif /* !defined(OS_PATHCONF_METHODDEF) */ - -#ifndef OS_CONFSTR_METHODDEF - #define OS_CONFSTR_METHODDEF -#endif /* !defined(OS_CONFSTR_METHODDEF) */ - -#ifndef OS_SYSCONF_METHODDEF - #define OS_SYSCONF_METHODDEF -#endif /* !defined(OS_SYSCONF_METHODDEF) */ - -#ifndef OS_GETLOADAVG_METHODDEF - #define OS_GETLOADAVG_METHODDEF -#endif /* !defined(OS_GETLOADAVG_METHODDEF) */ - -#ifndef OS_SETRESUID_METHODDEF - #define OS_SETRESUID_METHODDEF -#endif /* !defined(OS_SETRESUID_METHODDEF) */ - -#ifndef OS_SETRESGID_METHODDEF - #define OS_SETRESGID_METHODDEF -#endif /* !defined(OS_SETRESGID_METHODDEF) */ - -#ifndef OS_GETRESUID_METHODDEF - #define OS_GETRESUID_METHODDEF -#endif /* !defined(OS_GETRESUID_METHODDEF) */ - -#ifndef OS_GETRESGID_METHODDEF - #define OS_GETRESGID_METHODDEF -#endif /* !defined(OS_GETRESGID_METHODDEF) */ - -#ifndef OS_GETXATTR_METHODDEF - #define OS_GETXATTR_METHODDEF -#endif /* !defined(OS_GETXATTR_METHODDEF) */ - -#ifndef OS_SETXATTR_METHODDEF - #define OS_SETXATTR_METHODDEF -#endif /* !defined(OS_SETXATTR_METHODDEF) */ - -#ifndef OS_REMOVEXATTR_METHODDEF - #define OS_REMOVEXATTR_METHODDEF -#endif /* !defined(OS_REMOVEXATTR_METHODDEF) */ - -#ifndef OS_LISTXATTR_METHODDEF - #define OS_LISTXATTR_METHODDEF -#endif /* !defined(OS_LISTXATTR_METHODDEF) */ - -#ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF - #define OS_GET_HANDLE_INHERITABLE_METHODDEF -#endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */ - -#ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF - #define OS_SET_HANDLE_INHERITABLE_METHODDEF -#endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */ -/*[clinic end generated code: output=52a6140b0b052ce6 input=524ce2e021e4eba6]*/ +/*[clinic end generated code: output=5d071bbc8f49ea12 input=524ce2e021e4eba6]*/ static PyMethodDef posix_methods[] = { @@ -16843,26 +11161,71 @@ OS_STAT_METHODDEF OS_ACCESS_METHODDEF OS_TTYNAME_METHODDEF - OS_CHDIR_METHODDEF - OS_CHFLAGS_METHODDEF - OS_CHMOD_METHODDEF - OS_FCHMOD_METHODDEF - OS_LCHMOD_METHODDEF - OS_CHOWN_METHODDEF - OS_FCHOWN_METHODDEF - OS_LCHOWN_METHODDEF - OS_LCHFLAGS_METHODDEF - OS_CHROOT_METHODDEF - OS_CTERMID_METHODDEF - OS_GETCWD_METHODDEF - OS_GETCWDB_METHODDEF - OS_LINK_METHODDEF - OS_LISTDIR_METHODDEF - OS_LSTAT_METHODDEF - OS_MKDIR_METHODDEF - OS_NICE_METHODDEF - OS_GETPRIORITY_METHODDEF - OS_SETPRIORITY_METHODDEF + + {"chdir", (PyCFunction)posix_chdir, + METH_VARARGS | METH_KEYWORDS, + posix_chdir__doc__}, +#ifdef HAVE_CHFLAGS + {"chflags", (PyCFunction)posix_chflags, + METH_VARARGS | METH_KEYWORDS, + posix_chflags__doc__}, +#endif /* HAVE_CHFLAGS */ + {"chmod", (PyCFunction)posix_chmod, + METH_VARARGS | METH_KEYWORDS, + posix_chmod__doc__}, +#ifdef HAVE_FCHMOD + {"fchmod", posix_fchmod, METH_VARARGS, posix_fchmod__doc__}, +#endif /* HAVE_FCHMOD */ +#ifdef HAVE_CHOWN + {"chown", (PyCFunction)posix_chown, + METH_VARARGS | METH_KEYWORDS, + posix_chown__doc__}, +#endif /* HAVE_CHOWN */ +#ifdef HAVE_LCHMOD + {"lchmod", posix_lchmod, METH_VARARGS, posix_lchmod__doc__}, +#endif /* HAVE_LCHMOD */ +#ifdef HAVE_FCHOWN + {"fchown", posix_fchown, METH_VARARGS, posix_fchown__doc__}, +#endif /* HAVE_FCHOWN */ +#ifdef HAVE_LCHFLAGS + {"lchflags", posix_lchflags, METH_VARARGS, posix_lchflags__doc__}, +#endif /* HAVE_LCHFLAGS */ +#ifdef HAVE_LCHOWN + {"lchown", posix_lchown, METH_VARARGS, posix_lchown__doc__}, +#endif /* HAVE_LCHOWN */ +#ifdef HAVE_CHROOT + {"chroot", posix_chroot, METH_VARARGS, posix_chroot__doc__}, +#endif +#ifdef HAVE_CTERMID + {"ctermid", posix_ctermid, METH_NOARGS, posix_ctermid__doc__}, +#endif + {"getcwd", (PyCFunction)posix_getcwd_unicode, + METH_NOARGS, posix_getcwd__doc__}, + {"getcwdb", (PyCFunction)posix_getcwd_bytes, + METH_NOARGS, posix_getcwdb__doc__}, +#if defined(HAVE_LINK) || defined(MS_WINDOWS) + {"link", (PyCFunction)posix_link, + METH_VARARGS | METH_KEYWORDS, + posix_link__doc__}, +#endif /* HAVE_LINK */ + {"listdir", (PyCFunction)posix_listdir, + METH_VARARGS | METH_KEYWORDS, + posix_listdir__doc__}, + {"lstat", (PyCFunction)posix_lstat, + METH_VARARGS | METH_KEYWORDS, + posix_lstat__doc__}, + {"mkdir", (PyCFunction)posix_mkdir, + METH_VARARGS | METH_KEYWORDS, + posix_mkdir__doc__}, +#ifdef HAVE_NICE + {"nice", posix_nice, METH_VARARGS, posix_nice__doc__}, +#endif /* HAVE_NICE */ +#ifdef HAVE_GETPRIORITY + {"getpriority", posix_getpriority, METH_VARARGS, posix_getpriority__doc__}, +#endif /* HAVE_GETPRIORITY */ +#ifdef HAVE_SETPRIORITY + {"setpriority", posix_setpriority, METH_VARARGS, posix_setpriority__doc__}, +#endif /* HAVE_SETPRIORITY */ #ifdef HAVE_READLINK {"readlink", (PyCFunction)posix_readlink, METH_VARARGS | METH_KEYWORDS, @@ -16873,160 +11236,375 @@ METH_VARARGS | METH_KEYWORDS, readlink__doc__}, #endif /* !defined(HAVE_READLINK) && defined(MS_WINDOWS) */ - OS_RENAME_METHODDEF - OS_REPLACE_METHODDEF - OS_RMDIR_METHODDEF + {"rename", (PyCFunction)posix_rename, + METH_VARARGS | METH_KEYWORDS, + posix_rename__doc__}, + {"replace", (PyCFunction)posix_replace, + METH_VARARGS | METH_KEYWORDS, + posix_replace__doc__}, + {"rmdir", (PyCFunction)posix_rmdir, + METH_VARARGS | METH_KEYWORDS, + posix_rmdir__doc__}, {"stat_float_times", stat_float_times, METH_VARARGS, stat_float_times__doc__}, - OS_SYMLINK_METHODDEF - OS_SYSTEM_METHODDEF - OS_UMASK_METHODDEF - OS_UNAME_METHODDEF - OS_UNLINK_METHODDEF - OS_REMOVE_METHODDEF - OS_UTIME_METHODDEF - OS_TIMES_METHODDEF - OS__EXIT_METHODDEF - OS_EXECV_METHODDEF - OS_EXECVE_METHODDEF - OS_SPAWNV_METHODDEF - OS_SPAWNVE_METHODDEF - OS_FORK1_METHODDEF - OS_FORK_METHODDEF - OS_SCHED_GET_PRIORITY_MAX_METHODDEF - OS_SCHED_GET_PRIORITY_MIN_METHODDEF - OS_SCHED_GETPARAM_METHODDEF - OS_SCHED_GETSCHEDULER_METHODDEF - OS_SCHED_RR_GET_INTERVAL_METHODDEF - OS_SCHED_SETPARAM_METHODDEF - OS_SCHED_SETSCHEDULER_METHODDEF - OS_SCHED_YIELD_METHODDEF - OS_SCHED_SETAFFINITY_METHODDEF - OS_SCHED_GETAFFINITY_METHODDEF - OS_OPENPTY_METHODDEF - OS_FORKPTY_METHODDEF - OS_GETEGID_METHODDEF - OS_GETEUID_METHODDEF - OS_GETGID_METHODDEF +#if defined(HAVE_SYMLINK) + {"symlink", (PyCFunction)posix_symlink, + METH_VARARGS | METH_KEYWORDS, + posix_symlink__doc__}, +#endif /* HAVE_SYMLINK */ +#ifdef HAVE_SYSTEM + {"system", posix_system, METH_VARARGS, posix_system__doc__}, +#endif + {"umask", posix_umask, METH_VARARGS, posix_umask__doc__}, +#ifdef HAVE_UNAME + {"uname", posix_uname, METH_NOARGS, posix_uname__doc__}, +#endif /* HAVE_UNAME */ + {"unlink", (PyCFunction)posix_unlink, + METH_VARARGS | METH_KEYWORDS, + posix_unlink__doc__}, + {"remove", (PyCFunction)posix_unlink, + METH_VARARGS | METH_KEYWORDS, + posix_remove__doc__}, + {"utime", (PyCFunction)posix_utime, + METH_VARARGS | METH_KEYWORDS, posix_utime__doc__}, +#ifdef HAVE_TIMES + {"times", posix_times, METH_NOARGS, posix_times__doc__}, +#endif /* HAVE_TIMES */ + {"_exit", posix__exit, METH_VARARGS, posix__exit__doc__}, +#ifdef HAVE_EXECV + {"execv", posix_execv, METH_VARARGS, posix_execv__doc__}, + {"execve", (PyCFunction)posix_execve, + METH_VARARGS | METH_KEYWORDS, + posix_execve__doc__}, +#endif /* HAVE_EXECV */ +#ifdef HAVE_SPAWNV + {"spawnv", posix_spawnv, METH_VARARGS, posix_spawnv__doc__}, + {"spawnve", posix_spawnve, METH_VARARGS, posix_spawnve__doc__}, +#endif /* HAVE_SPAWNV */ +#ifdef HAVE_FORK1 + {"fork1", posix_fork1, METH_NOARGS, posix_fork1__doc__}, +#endif /* HAVE_FORK1 */ +#ifdef HAVE_FORK + {"fork", posix_fork, METH_NOARGS, posix_fork__doc__}, +#endif /* HAVE_FORK */ +#ifdef HAVE_SCHED_H +#ifdef HAVE_SCHED_GET_PRIORITY_MAX + {"sched_get_priority_max", posix_sched_get_priority_max, METH_VARARGS, posix_sched_get_priority_max__doc__}, + {"sched_get_priority_min", posix_sched_get_priority_min, METH_VARARGS, posix_sched_get_priority_min__doc__}, +#endif +#ifdef HAVE_SCHED_SETPARAM + {"sched_getparam", posix_sched_getparam, METH_VARARGS, posix_sched_getparam__doc__}, +#endif +#ifdef HAVE_SCHED_SETSCHEDULER + {"sched_getscheduler", posix_sched_getscheduler, METH_VARARGS, posix_sched_getscheduler__doc__}, +#endif +#ifdef HAVE_SCHED_RR_GET_INTERVAL + {"sched_rr_get_interval", posix_sched_rr_get_interval, METH_VARARGS, posix_sched_rr_get_interval__doc__}, +#endif +#ifdef HAVE_SCHED_SETPARAM + {"sched_setparam", posix_sched_setparam, METH_VARARGS, posix_sched_setparam__doc__}, +#endif +#ifdef HAVE_SCHED_SETSCHEDULER + {"sched_setscheduler", posix_sched_setscheduler, METH_VARARGS, posix_sched_setscheduler__doc__}, +#endif + {"sched_yield", posix_sched_yield, METH_NOARGS, posix_sched_yield__doc__}, +#ifdef HAVE_SCHED_SETAFFINITY + {"sched_setaffinity", posix_sched_setaffinity, METH_VARARGS, posix_sched_setaffinity__doc__}, + {"sched_getaffinity", posix_sched_getaffinity, METH_VARARGS, posix_sched_getaffinity__doc__}, +#endif +#endif /* HAVE_SCHED_H */ +#if defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX) + {"openpty", posix_openpty, METH_NOARGS, posix_openpty__doc__}, +#endif /* HAVE_OPENPTY || HAVE__GETPTY || HAVE_DEV_PTMX */ +#ifdef HAVE_FORKPTY + {"forkpty", posix_forkpty, METH_NOARGS, posix_forkpty__doc__}, +#endif /* HAVE_FORKPTY */ +#ifdef HAVE_GETEGID + {"getegid", posix_getegid, METH_NOARGS, posix_getegid__doc__}, +#endif /* HAVE_GETEGID */ +#ifdef HAVE_GETEUID + {"geteuid", posix_geteuid, METH_NOARGS, posix_geteuid__doc__}, +#endif /* HAVE_GETEUID */ +#ifdef HAVE_GETGID + {"getgid", posix_getgid, METH_NOARGS, posix_getgid__doc__}, +#endif /* HAVE_GETGID */ #ifdef HAVE_GETGROUPLIST {"getgrouplist", posix_getgrouplist, METH_VARARGS, posix_getgrouplist__doc__}, #endif - OS_GETGROUPS_METHODDEF - OS_GETPID_METHODDEF - OS_GETPGRP_METHODDEF - OS_GETPPID_METHODDEF - OS_GETUID_METHODDEF - OS_GETLOGIN_METHODDEF - OS_KILL_METHODDEF - OS_KILLPG_METHODDEF - OS_PLOCK_METHODDEF +#ifdef HAVE_GETGROUPS + {"getgroups", posix_getgroups, METH_NOARGS, posix_getgroups__doc__}, +#endif + {"getpid", posix_getpid, METH_NOARGS, posix_getpid__doc__}, +#ifdef HAVE_GETPGRP + {"getpgrp", posix_getpgrp, METH_NOARGS, posix_getpgrp__doc__}, +#endif /* HAVE_GETPGRP */ +#ifdef HAVE_GETPPID + {"getppid", posix_getppid, METH_NOARGS, posix_getppid__doc__}, +#endif /* HAVE_GETPPID */ +#ifdef HAVE_GETUID + {"getuid", posix_getuid, METH_NOARGS, posix_getuid__doc__}, +#endif /* HAVE_GETUID */ +#ifdef HAVE_GETLOGIN + {"getlogin", posix_getlogin, METH_NOARGS, posix_getlogin__doc__}, +#endif +#ifdef HAVE_KILL + {"kill", posix_kill, METH_VARARGS, posix_kill__doc__}, +#endif /* HAVE_KILL */ +#ifdef HAVE_KILLPG + {"killpg", posix_killpg, METH_VARARGS, posix_killpg__doc__}, +#endif /* HAVE_KILLPG */ +#ifdef HAVE_PLOCK + {"plock", posix_plock, METH_VARARGS, posix_plock__doc__}, +#endif /* HAVE_PLOCK */ #ifdef MS_WINDOWS {"startfile", win32_startfile, METH_VARARGS, win32_startfile__doc__}, -#endif - OS_SETUID_METHODDEF - OS_SETEUID_METHODDEF - OS_SETREUID_METHODDEF - OS_SETGID_METHODDEF - OS_SETEGID_METHODDEF - OS_SETREGID_METHODDEF - OS_SETGROUPS_METHODDEF + {"kill", win32_kill, METH_VARARGS, win32_kill__doc__}, +#endif +#ifdef HAVE_SETUID + {"setuid", posix_setuid, METH_VARARGS, posix_setuid__doc__}, +#endif /* HAVE_SETUID */ +#ifdef HAVE_SETEUID + {"seteuid", posix_seteuid, METH_VARARGS, posix_seteuid__doc__}, +#endif /* HAVE_SETEUID */ +#ifdef HAVE_SETEGID + {"setegid", posix_setegid, METH_VARARGS, posix_setegid__doc__}, +#endif /* HAVE_SETEGID */ +#ifdef HAVE_SETREUID + {"setreuid", posix_setreuid, METH_VARARGS, posix_setreuid__doc__}, +#endif /* HAVE_SETREUID */ +#ifdef HAVE_SETREGID + {"setregid", posix_setregid, METH_VARARGS, posix_setregid__doc__}, +#endif /* HAVE_SETREGID */ +#ifdef HAVE_SETGID + {"setgid", posix_setgid, METH_VARARGS, posix_setgid__doc__}, +#endif /* HAVE_SETGID */ +#ifdef HAVE_SETGROUPS + {"setgroups", posix_setgroups, METH_O, posix_setgroups__doc__}, +#endif /* HAVE_SETGROUPS */ #ifdef HAVE_INITGROUPS {"initgroups", posix_initgroups, METH_VARARGS, posix_initgroups__doc__}, #endif /* HAVE_INITGROUPS */ - OS_GETPGID_METHODDEF - OS_SETPGRP_METHODDEF - OS_WAIT_METHODDEF - OS_WAIT3_METHODDEF - OS_WAIT4_METHODDEF - OS_WAITID_METHODDEF - OS_WAITPID_METHODDEF - OS_GETSID_METHODDEF - OS_SETSID_METHODDEF - OS_SETPGID_METHODDEF - OS_TCGETPGRP_METHODDEF - OS_TCSETPGRP_METHODDEF - OS_OPEN_METHODDEF - OS_CLOSE_METHODDEF - OS_CLOSERANGE_METHODDEF - OS_DEVICE_ENCODING_METHODDEF - OS_DUP_METHODDEF - OS_DUP2_METHODDEF - OS_LOCKF_METHODDEF - OS_LSEEK_METHODDEF - OS_READ_METHODDEF - OS_READV_METHODDEF - OS_PREAD_METHODDEF - OS_WRITE_METHODDEF - OS_WRITEV_METHODDEF - OS_PWRITE_METHODDEF +#ifdef HAVE_GETPGID + {"getpgid", posix_getpgid, METH_VARARGS, posix_getpgid__doc__}, +#endif /* HAVE_GETPGID */ +#ifdef HAVE_SETPGRP + {"setpgrp", posix_setpgrp, METH_NOARGS, posix_setpgrp__doc__}, +#endif /* HAVE_SETPGRP */ +#ifdef HAVE_WAIT + {"wait", posix_wait, METH_NOARGS, posix_wait__doc__}, +#endif /* HAVE_WAIT */ +#ifdef HAVE_WAIT3 + {"wait3", posix_wait3, METH_VARARGS, posix_wait3__doc__}, +#endif /* HAVE_WAIT3 */ +#ifdef HAVE_WAIT4 + {"wait4", posix_wait4, METH_VARARGS, posix_wait4__doc__}, +#endif /* HAVE_WAIT4 */ +#if defined(HAVE_WAITID) && !defined(__APPLE__) + {"waitid", posix_waitid, METH_VARARGS, posix_waitid__doc__}, +#endif +#if defined(HAVE_WAITPID) || defined(HAVE_CWAIT) + {"waitpid", posix_waitpid, METH_VARARGS, posix_waitpid__doc__}, +#endif /* HAVE_WAITPID */ +#ifdef HAVE_GETSID + {"getsid", posix_getsid, METH_VARARGS, posix_getsid__doc__}, +#endif /* HAVE_GETSID */ +#ifdef HAVE_SETSID + {"setsid", posix_setsid, METH_NOARGS, posix_setsid__doc__}, +#endif /* HAVE_SETSID */ +#ifdef HAVE_SETPGID + {"setpgid", posix_setpgid, METH_VARARGS, posix_setpgid__doc__}, +#endif /* HAVE_SETPGID */ +#ifdef HAVE_TCGETPGRP + {"tcgetpgrp", posix_tcgetpgrp, METH_VARARGS, posix_tcgetpgrp__doc__}, +#endif /* HAVE_TCGETPGRP */ +#ifdef HAVE_TCSETPGRP + {"tcsetpgrp", posix_tcsetpgrp, METH_VARARGS, posix_tcsetpgrp__doc__}, +#endif /* HAVE_TCSETPGRP */ + {"open", (PyCFunction)posix_open,\ + METH_VARARGS | METH_KEYWORDS, + posix_open__doc__}, + {"close", posix_close_, METH_VARARGS, posix_close__doc__}, + {"closerange", posix_closerange, METH_VARARGS, posix_closerange__doc__}, + {"device_encoding", device_encoding, METH_VARARGS, device_encoding__doc__}, + {"dup", posix_dup, METH_VARARGS, posix_dup__doc__}, + {"dup2", (PyCFunction)posix_dup2, + METH_VARARGS | METH_KEYWORDS, posix_dup2__doc__}, +#ifdef HAVE_LOCKF + {"lockf", posix_lockf, METH_VARARGS, posix_lockf__doc__}, +#endif + {"lseek", posix_lseek, METH_VARARGS, posix_lseek__doc__}, + {"read", posix_read, METH_VARARGS, posix_read__doc__}, +#ifdef HAVE_READV + {"readv", posix_readv, METH_VARARGS, posix_readv__doc__}, +#endif +#ifdef HAVE_PREAD + {"pread", posix_pread, METH_VARARGS, posix_pread__doc__}, +#endif + {"write", posix_write, METH_VARARGS, posix_write__doc__}, +#ifdef HAVE_WRITEV + {"writev", posix_writev, METH_VARARGS, posix_writev__doc__}, +#endif +#ifdef HAVE_PWRITE + {"pwrite", posix_pwrite, METH_VARARGS, posix_pwrite__doc__}, +#endif #ifdef HAVE_SENDFILE {"sendfile", (PyCFunction)posix_sendfile, METH_VARARGS | METH_KEYWORDS, posix_sendfile__doc__}, #endif - OS_FSTAT_METHODDEF - OS_ISATTY_METHODDEF - OS_PIPE_METHODDEF - OS_PIPE2_METHODDEF - OS_MKFIFO_METHODDEF - OS_MKNOD_METHODDEF - OS_MAJOR_METHODDEF - OS_MINOR_METHODDEF - OS_MAKEDEV_METHODDEF - OS_FTRUNCATE_METHODDEF - OS_TRUNCATE_METHODDEF - OS_POSIX_FALLOCATE_METHODDEF - OS_POSIX_FADVISE_METHODDEF - OS_PUTENV_METHODDEF - OS_UNSETENV_METHODDEF - OS_STRERROR_METHODDEF - OS_FCHDIR_METHODDEF - OS_FSYNC_METHODDEF - OS_SYNC_METHODDEF - OS_FDATASYNC_METHODDEF - OS_WCOREDUMP_METHODDEF - OS_WIFCONTINUED_METHODDEF - OS_WIFSTOPPED_METHODDEF - OS_WIFSIGNALED_METHODDEF - OS_WIFEXITED_METHODDEF - OS_WEXITSTATUS_METHODDEF - OS_WTERMSIG_METHODDEF - OS_WSTOPSIG_METHODDEF - OS_FSTATVFS_METHODDEF - OS_STATVFS_METHODDEF - OS_CONFSTR_METHODDEF - OS_SYSCONF_METHODDEF - OS_FPATHCONF_METHODDEF - OS_PATHCONF_METHODDEF - OS_ABORT_METHODDEF + {"fstat", posix_fstat, METH_VARARGS, posix_fstat__doc__}, + {"isatty", posix_isatty, METH_VARARGS, posix_isatty__doc__}, +#ifdef HAVE_PIPE + {"pipe", posix_pipe, METH_NOARGS, posix_pipe__doc__}, +#endif +#ifdef HAVE_PIPE2 + {"pipe2", posix_pipe2, METH_O, posix_pipe2__doc__}, +#endif +#ifdef HAVE_MKFIFO + {"mkfifo", (PyCFunction)posix_mkfifo, + METH_VARARGS | METH_KEYWORDS, + posix_mkfifo__doc__}, +#endif +#if defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV) + {"mknod", (PyCFunction)posix_mknod, + METH_VARARGS | METH_KEYWORDS, + posix_mknod__doc__}, +#endif +#ifdef HAVE_DEVICE_MACROS + {"major", posix_major, METH_VARARGS, posix_major__doc__}, + {"minor", posix_minor, METH_VARARGS, posix_minor__doc__}, + {"makedev", posix_makedev, METH_VARARGS, posix_makedev__doc__}, +#endif +#ifdef HAVE_FTRUNCATE + {"ftruncate", posix_ftruncate, METH_VARARGS, posix_ftruncate__doc__}, +#endif +#ifdef HAVE_TRUNCATE + {"truncate", (PyCFunction)posix_truncate, + METH_VARARGS | METH_KEYWORDS, + posix_truncate__doc__}, +#endif +#ifdef HAVE_POSIX_FALLOCATE + {"posix_fallocate", posix_posix_fallocate, METH_VARARGS, posix_posix_fallocate__doc__}, +#endif +#ifdef HAVE_POSIX_FADVISE + {"posix_fadvise", posix_posix_fadvise, METH_VARARGS, posix_posix_fadvise__doc__}, +#endif +#ifdef HAVE_PUTENV + {"putenv", posix_putenv, METH_VARARGS, posix_putenv__doc__}, +#endif +#ifdef HAVE_UNSETENV + {"unsetenv", posix_unsetenv, METH_VARARGS, posix_unsetenv__doc__}, +#endif + {"strerror", posix_strerror, METH_VARARGS, posix_strerror__doc__}, +#ifdef HAVE_FCHDIR + {"fchdir", posix_fchdir, METH_O, posix_fchdir__doc__}, +#endif +#ifdef HAVE_FSYNC + {"fsync", posix_fsync, METH_O, posix_fsync__doc__}, +#endif +#ifdef HAVE_SYNC + {"sync", posix_sync, METH_NOARGS, posix_sync__doc__}, +#endif +#ifdef HAVE_FDATASYNC + {"fdatasync", posix_fdatasync, METH_O, posix_fdatasync__doc__}, +#endif +#ifdef HAVE_SYS_WAIT_H +#ifdef WCOREDUMP + {"WCOREDUMP", posix_WCOREDUMP, METH_VARARGS, posix_WCOREDUMP__doc__}, +#endif /* WCOREDUMP */ +#ifdef WIFCONTINUED + {"WIFCONTINUED",posix_WIFCONTINUED, METH_VARARGS, posix_WIFCONTINUED__doc__}, +#endif /* WIFCONTINUED */ +#ifdef WIFSTOPPED + {"WIFSTOPPED", posix_WIFSTOPPED, METH_VARARGS, posix_WIFSTOPPED__doc__}, +#endif /* WIFSTOPPED */ +#ifdef WIFSIGNALED + {"WIFSIGNALED", posix_WIFSIGNALED, METH_VARARGS, posix_WIFSIGNALED__doc__}, +#endif /* WIFSIGNALED */ +#ifdef WIFEXITED + {"WIFEXITED", posix_WIFEXITED, METH_VARARGS, posix_WIFEXITED__doc__}, +#endif /* WIFEXITED */ +#ifdef WEXITSTATUS + {"WEXITSTATUS", posix_WEXITSTATUS, METH_VARARGS, posix_WEXITSTATUS__doc__}, +#endif /* WEXITSTATUS */ +#ifdef WTERMSIG + {"WTERMSIG", posix_WTERMSIG, METH_VARARGS, posix_WTERMSIG__doc__}, +#endif /* WTERMSIG */ +#ifdef WSTOPSIG + {"WSTOPSIG", posix_WSTOPSIG, METH_VARARGS, posix_WSTOPSIG__doc__}, +#endif /* WSTOPSIG */ +#endif /* HAVE_SYS_WAIT_H */ +#if defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H) + {"fstatvfs", posix_fstatvfs, METH_VARARGS, posix_fstatvfs__doc__}, +#endif +#if defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H) + {"statvfs", (PyCFunction)posix_statvfs, + METH_VARARGS | METH_KEYWORDS, + posix_statvfs__doc__}, +#endif +#ifdef HAVE_CONFSTR + {"confstr", posix_confstr, METH_VARARGS, posix_confstr__doc__}, +#endif +#ifdef HAVE_SYSCONF + {"sysconf", posix_sysconf, METH_VARARGS, posix_sysconf__doc__}, +#endif +#ifdef HAVE_FPATHCONF + {"fpathconf", posix_fpathconf, METH_VARARGS, posix_fpathconf__doc__}, +#endif +#ifdef HAVE_PATHCONF + {"pathconf", (PyCFunction)posix_pathconf, + METH_VARARGS | METH_KEYWORDS, + posix_pathconf__doc__}, +#endif + {"abort", posix_abort, METH_NOARGS, posix_abort__doc__}, #ifdef MS_WINDOWS {"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL}, + {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, -#endif - OS__GETDISKUSAGE_METHODDEF - OS__GETFINALPATHNAME_METHODDEF - OS__GETVOLUMEPATHNAME_METHODDEF - OS_GETLOADAVG_METHODDEF - OS_URANDOM_METHODDEF - OS_SETRESUID_METHODDEF - OS_SETRESGID_METHODDEF - OS_GETRESUID_METHODDEF - OS_GETRESGID_METHODDEF - - OS_GETXATTR_METHODDEF - OS_SETXATTR_METHODDEF - OS_REMOVEXATTR_METHODDEF - OS_LISTXATTR_METHODDEF - + {"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__}, + {"_getvolumepathname", posix__getvolumepathname, METH_VARARGS, posix__getvolumepathname__doc__}, +#endif +#ifdef HAVE_GETLOADAVG + {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, +#endif + {"urandom", posix_urandom, METH_VARARGS, posix_urandom__doc__}, +#ifdef HAVE_SETRESUID + {"setresuid", posix_setresuid, METH_VARARGS, posix_setresuid__doc__}, +#endif +#ifdef HAVE_SETRESGID + {"setresgid", posix_setresgid, METH_VARARGS, posix_setresgid__doc__}, +#endif +#ifdef HAVE_GETRESUID + {"getresuid", posix_getresuid, METH_NOARGS, posix_getresuid__doc__}, +#endif +#ifdef HAVE_GETRESGID + {"getresgid", posix_getresgid, METH_NOARGS, posix_getresgid__doc__}, +#endif + +#ifdef USE_XATTRS + {"setxattr", (PyCFunction)posix_setxattr, + METH_VARARGS | METH_KEYWORDS, + posix_setxattr__doc__}, + {"getxattr", (PyCFunction)posix_getxattr, + METH_VARARGS | METH_KEYWORDS, + posix_getxattr__doc__}, + {"removexattr", (PyCFunction)posix_removexattr, + METH_VARARGS | METH_KEYWORDS, + posix_removexattr__doc__}, + {"listxattr", (PyCFunction)posix_listxattr, + METH_VARARGS | METH_KEYWORDS, + posix_listxattr__doc__}, +#endif #if defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL) {"get_terminal_size", get_terminal_size, METH_VARARGS, termsize__doc__}, #endif - OS_CPU_COUNT_METHODDEF - OS_GET_INHERITABLE_METHODDEF - OS_SET_INHERITABLE_METHODDEF - OS_GET_HANDLE_INHERITABLE_METHODDEF - OS_SET_HANDLE_INHERITABLE_METHODDEF -#ifndef MS_WINDOWS - {"get_blocking", posix_get_blocking, METH_VARARGS, get_blocking__doc__}, - {"set_blocking", posix_set_blocking, METH_VARARGS, set_blocking__doc__}, + {"cpu_count", (PyCFunction)posix_cpu_count, + METH_NOARGS, posix_cpu_count__doc__}, + {"get_inheritable", posix_get_inheritable, METH_VARARGS, get_inheritable__doc__}, + {"set_inheritable", posix_set_inheritable, METH_VARARGS, set_inheritable__doc__}, +#ifdef MS_WINDOWS + {"get_handle_inheritable", posix_get_handle_inheritable, + METH_VARARGS, get_handle_inheritable__doc__}, + {"set_handle_inheritable", posix_set_handle_inheritable, + METH_VARARGS, set_handle_inheritable__doc__}, #endif {NULL, NULL} /* Sentinel */ }; @@ -17692,7 +12270,7 @@ sched_param_desc.name = MODNAME ".sched_param"; if (PyStructSequence_InitType2(&SchedParamType, &sched_param_desc) < 0) return NULL; - SchedParamType.tp_new = os_sched_param; + SchedParamType.tp_new = sched_param_new; #endif /* initialize TerminalSize_info */ diff -r 79e469ae13b7 -r 01438f18ee18 Modules/sha1module.c --- a/Modules/sha1module.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/sha1module.c Fri Jul 25 11:39:11 2014 -0400 @@ -19,11 +19,6 @@ #include "Python.h" #include "hashlib.h" -/*[clinic input] -module _sha1 -class SHA1Type "SHA1object *" "&PyType_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=3dc9a20d1becb759]*/ /* Some useful types */ @@ -314,33 +309,10 @@ /* External methods for a hash object */ -/*[clinic input] -SHA1Type.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA1Type_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define SHA1TYPE_COPY_METHODDEF \ - {"copy", (PyCFunction)SHA1Type_copy, METH_NOARGS, SHA1Type_copy__doc__}, +PyDoc_STRVAR(SHA1_copy__doc__, "Return a copy of the hash object."); static PyObject * -SHA1Type_copy_impl(SHA1object *self); - -static PyObject * -SHA1Type_copy(SHA1object *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA1Type_copy_impl(self); -} - -static PyObject * -SHA1Type_copy_impl(SHA1object *self) -/*[clinic end generated code: output=1a320e75a7444098 input=b7eae10df6f89b36]*/ +SHA1_copy(SHA1object *self, PyObject *unused) { SHA1object *newobj; @@ -351,33 +323,11 @@ return (PyObject *)newobj; } -/*[clinic input] -SHA1Type.digest - -Return the digest value as a string of binary data. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA1Type_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA1_digest__doc__, "Return the digest value as a string of binary data."); -#define SHA1TYPE_DIGEST_METHODDEF \ - {"digest", (PyCFunction)SHA1Type_digest, METH_NOARGS, SHA1Type_digest__doc__}, - static PyObject * -SHA1Type_digest_impl(SHA1object *self); - -static PyObject * -SHA1Type_digest(SHA1object *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA1Type_digest_impl(self); -} - -static PyObject * -SHA1Type_digest_impl(SHA1object *self) -/*[clinic end generated code: output=c4920f75228bfbfd input=205d47e1927fd009]*/ +SHA1_digest(SHA1object *self, PyObject *unused) { unsigned char digest[SHA1_DIGESTSIZE]; struct sha1_state temp; @@ -387,33 +337,11 @@ return PyBytes_FromStringAndSize((const char *)digest, SHA1_DIGESTSIZE); } -/*[clinic input] -SHA1Type.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA1Type_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA1_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); -#define SHA1TYPE_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)SHA1Type_hexdigest, METH_NOARGS, SHA1Type_hexdigest__doc__}, - static PyObject * -SHA1Type_hexdigest_impl(SHA1object *self); - -static PyObject * -SHA1Type_hexdigest(SHA1object *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA1Type_hexdigest_impl(self); -} - -static PyObject * -SHA1Type_hexdigest_impl(SHA1object *self) -/*[clinic end generated code: output=6e345aac201887b2 input=97691055c0c74ab0]*/ +SHA1_hexdigest(SHA1object *self, PyObject *unused) { unsigned char digest[SHA1_DIGESTSIZE]; struct sha1_state temp; @@ -445,30 +373,18 @@ return retval; } -/*[clinic input] -SHA1Type.update - - obj: object - / - -Update this hash object's state with the provided string. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA1Type_update__doc__, -"update($self, obj, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided string."); - -#define SHA1TYPE_UPDATE_METHODDEF \ - {"update", (PyCFunction)SHA1Type_update, METH_O, SHA1Type_update__doc__}, +PyDoc_STRVAR(SHA1_update__doc__, +"Update this hash object's state with the provided string."); static PyObject * -SHA1Type_update(SHA1object *self, PyObject *obj) -/*[clinic end generated code: output=ab20a86a25e7d255 input=aad8e07812edbba3]*/ +SHA1_update(SHA1object *self, PyObject *args) { + PyObject *obj; Py_buffer buf; + if (!PyArg_ParseTuple(args, "O:update", &obj)) + return NULL; + GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); sha1_process(&self->hash_state, buf.buf, buf.len); @@ -479,10 +395,10 @@ } static PyMethodDef SHA1_methods[] = { - SHA1TYPE_COPY_METHODDEF - SHA1TYPE_DIGEST_METHODDEF - SHA1TYPE_HEXDIGEST_METHODDEF - SHA1TYPE_UPDATE_METHODDEF + {"copy", (PyCFunction)SHA1_copy, METH_NOARGS, SHA1_copy__doc__}, + {"digest", (PyCFunction)SHA1_digest, METH_NOARGS, SHA1_digest__doc__}, + {"hexdigest", (PyCFunction)SHA1_hexdigest, METH_NOARGS, SHA1_hexdigest__doc__}, + {"update", (PyCFunction)SHA1_update, METH_VARARGS, SHA1_update__doc__}, {NULL, NULL} /* sentinel */ }; @@ -558,55 +474,27 @@ /* The single module-level function: new() */ -/*[clinic input] -_sha1.sha1 - - string: object(c_default="NULL") = b'' - -Return a new SHA1 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha1_sha1__doc__, -"sha1($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA1_new__doc__, "Return a new SHA1 hash object; optionally initialized with a string."); -#define _SHA1_SHA1_METHODDEF \ - {"sha1", (PyCFunction)_sha1_sha1, METH_VARARGS|METH_KEYWORDS, _sha1_sha1__doc__}, - static PyObject * -_sha1_sha1_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_sha1_sha1(PyModuleDef *module, PyObject *args, PyObject *kwargs) +SHA1_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:sha1", _keywords, - &string)) - goto exit; - return_value = _sha1_sha1_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_sha1_sha1_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=c9068552f07b8954 input=27ea54281d995ec2]*/ -{ + static char *kwlist[] = {"string", NULL}; SHA1object *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newSHA1object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -615,11 +503,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { sha1_process(&new->hash_state, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -631,7 +519,7 @@ /* List of functions exported by this module */ static struct PyMethodDef SHA1_functions[] = { - _SHA1_SHA1_METHODDEF + {"sha1",(PyCFunction)SHA1_new, METH_VARARGS|METH_KEYWORDS,SHA1_new__doc__}, {NULL, NULL} /* Sentinel */ }; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/sha256module.c --- a/Modules/sha256module.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/sha256module.c Fri Jul 25 11:39:11 2014 -0400 @@ -20,11 +20,6 @@ #include "structmember.h" #include "hashlib.h" -/*[clinic input] -module _sha256 -class SHA256Type "SHAobject *" "&PyType_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=71a39174d4f0a744]*/ /* Some useful types */ @@ -398,33 +393,10 @@ /* External methods for a hash object */ -/*[clinic input] -SHA256Type.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA256Type_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define SHA256TYPE_COPY_METHODDEF \ - {"copy", (PyCFunction)SHA256Type_copy, METH_NOARGS, SHA256Type_copy__doc__}, +PyDoc_STRVAR(SHA256_copy__doc__, "Return a copy of the hash object."); static PyObject * -SHA256Type_copy_impl(SHAobject *self); - -static PyObject * -SHA256Type_copy(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA256Type_copy_impl(self); -} - -static PyObject * -SHA256Type_copy_impl(SHAobject *self) -/*[clinic end generated code: output=f716c39d3f81c27c input=f58840a618d4f2a7]*/ +SHA256_copy(SHAobject *self, PyObject *unused) { SHAobject *newobj; @@ -440,33 +412,11 @@ return (PyObject *)newobj; } -/*[clinic input] -SHA256Type.digest - -Return the digest value as a string of binary data. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA256Type_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA256_digest__doc__, "Return the digest value as a string of binary data."); -#define SHA256TYPE_DIGEST_METHODDEF \ - {"digest", (PyCFunction)SHA256Type_digest, METH_NOARGS, SHA256Type_digest__doc__}, - static PyObject * -SHA256Type_digest_impl(SHAobject *self); - -static PyObject * -SHA256Type_digest(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA256Type_digest_impl(self); -} - -static PyObject * -SHA256Type_digest_impl(SHAobject *self) -/*[clinic end generated code: output=72d34723d7bb694c input=1fb752e58954157d]*/ +SHA256_digest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -476,33 +426,11 @@ return PyBytes_FromStringAndSize((const char *)digest, self->digestsize); } -/*[clinic input] -SHA256Type.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA256Type_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA256_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); -#define SHA256TYPE_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)SHA256Type_hexdigest, METH_NOARGS, SHA256Type_hexdigest__doc__}, - static PyObject * -SHA256Type_hexdigest_impl(SHAobject *self); - -static PyObject * -SHA256Type_hexdigest(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA256Type_hexdigest_impl(self); -} - -static PyObject * -SHA256Type_hexdigest_impl(SHAobject *self) -/*[clinic end generated code: output=3687aa6183c7d27f input=0cc4c714693010d1]*/ +SHA256_hexdigest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -534,30 +462,18 @@ return retval; } -/*[clinic input] -SHA256Type.update - - obj: object - / - -Update this hash object's state with the provided string. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA256Type_update__doc__, -"update($self, obj, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided string."); - -#define SHA256TYPE_UPDATE_METHODDEF \ - {"update", (PyCFunction)SHA256Type_update, METH_O, SHA256Type_update__doc__}, +PyDoc_STRVAR(SHA256_update__doc__, +"Update this hash object's state with the provided string."); static PyObject * -SHA256Type_update(SHAobject *self, PyObject *obj) -/*[clinic end generated code: output=b47f53d7cbeabee4 input=b2d449d5b30f0f5a]*/ +SHA256_update(SHAobject *self, PyObject *args) { + PyObject *obj; Py_buffer buf; + if (!PyArg_ParseTuple(args, "O:update", &obj)) + return NULL; + GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); sha_update(self, buf.buf, buf.len); @@ -568,10 +484,10 @@ } static PyMethodDef SHA_methods[] = { - SHA256TYPE_COPY_METHODDEF - SHA256TYPE_DIGEST_METHODDEF - SHA256TYPE_HEXDIGEST_METHODDEF - SHA256TYPE_UPDATE_METHODDEF + {"copy", (PyCFunction)SHA256_copy, METH_NOARGS, SHA256_copy__doc__}, + {"digest", (PyCFunction)SHA256_digest, METH_NOARGS, SHA256_digest__doc__}, + {"hexdigest", (PyCFunction)SHA256_hexdigest, METH_NOARGS, SHA256_hexdigest__doc__}, + {"update", (PyCFunction)SHA256_update, METH_VARARGS, SHA256_update__doc__}, {NULL, NULL} /* sentinel */ }; @@ -678,55 +594,27 @@ /* The single module-level function: new() */ -/*[clinic input] -_sha256.sha256 - - string: object(c_default="NULL") = b'' - -Return a new SHA-256 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha256_sha256__doc__, -"sha256($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA256_new__doc__, "Return a new SHA-256 hash object; optionally initialized with a string."); -#define _SHA256_SHA256_METHODDEF \ - {"sha256", (PyCFunction)_sha256_sha256, METH_VARARGS|METH_KEYWORDS, _sha256_sha256__doc__}, - static PyObject * -_sha256_sha256_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_sha256_sha256(PyModuleDef *module, PyObject *args, PyObject *kwargs) +SHA256_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:sha256", _keywords, - &string)) - goto exit; - return_value = _sha256_sha256_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_sha256_sha256_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=4b1263d1e2fcdb98 input=09cce3fb855056b2]*/ -{ + static char *kwlist[] = {"string", NULL}; SHAobject *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newSHA256object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -735,11 +623,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { sha_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -747,55 +635,27 @@ return (PyObject *)new; } -/*[clinic input] -_sha256.sha224 - - string: object(c_default="NULL") = b'' - -Return a new SHA-224 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha256_sha224__doc__, -"sha224($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA224_new__doc__, "Return a new SHA-224 hash object; optionally initialized with a string."); -#define _SHA256_SHA224_METHODDEF \ - {"sha224", (PyCFunction)_sha256_sha224, METH_VARARGS|METH_KEYWORDS, _sha256_sha224__doc__}, - static PyObject * -_sha256_sha224_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_sha256_sha224(PyModuleDef *module, PyObject *args, PyObject *kwargs) +SHA224_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:sha224", _keywords, - &string)) - goto exit; - return_value = _sha256_sha224_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_sha256_sha224_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=4dde0eb1cdaebc06 input=27a04ba24c353a73]*/ -{ + static char *kwlist[] = {"string", NULL}; SHAobject *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newSHA224object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -804,11 +664,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { sha_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -820,8 +680,8 @@ /* List of functions exported by this module */ static struct PyMethodDef SHA_functions[] = { - _SHA256_SHA256_METHODDEF - _SHA256_SHA224_METHODDEF + {"sha256", (PyCFunction)SHA256_new, METH_VARARGS|METH_KEYWORDS, SHA256_new__doc__}, + {"sha224", (PyCFunction)SHA224_new, METH_VARARGS|METH_KEYWORDS, SHA224_new__doc__}, {NULL, NULL} /* Sentinel */ }; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/sha512module.c --- a/Modules/sha512module.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/sha512module.c Fri Jul 25 11:39:11 2014 -0400 @@ -20,12 +20,6 @@ #include "structmember.h" #include "hashlib.h" -/*[clinic input] -module _sha512 -class SHA512Type "SHAobject *" "&PyType_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81a3ccde92bcfe8d]*/ - #ifdef PY_LONG_LONG /* If no PY_LONG_LONG, don't compile anything! */ /* Some useful types */ @@ -465,33 +459,10 @@ /* External methods for a hash object */ -/*[clinic input] -SHA512Type.copy - -Return a copy of the hash object. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA512Type_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of the hash object."); - -#define SHA512TYPE_COPY_METHODDEF \ - {"copy", (PyCFunction)SHA512Type_copy, METH_NOARGS, SHA512Type_copy__doc__}, +PyDoc_STRVAR(SHA512_copy__doc__, "Return a copy of the hash object."); static PyObject * -SHA512Type_copy_impl(SHAobject *self); - -static PyObject * -SHA512Type_copy(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA512Type_copy_impl(self); -} - -static PyObject * -SHA512Type_copy_impl(SHAobject *self) -/*[clinic end generated code: output=14f8e6ce9c61ece0 input=9f5f31e6c457776a]*/ +SHA512_copy(SHAobject *self, PyObject *unused) { SHAobject *newobj; @@ -507,33 +478,11 @@ return (PyObject *)newobj; } -/*[clinic input] -SHA512Type.digest - -Return the digest value as a string of binary data. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA512Type_digest__doc__, -"digest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA512_digest__doc__, "Return the digest value as a string of binary data."); -#define SHA512TYPE_DIGEST_METHODDEF \ - {"digest", (PyCFunction)SHA512Type_digest, METH_NOARGS, SHA512Type_digest__doc__}, - static PyObject * -SHA512Type_digest_impl(SHAobject *self); - -static PyObject * -SHA512Type_digest(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA512Type_digest_impl(self); -} - -static PyObject * -SHA512Type_digest_impl(SHAobject *self) -/*[clinic end generated code: output=be8de024b232977e input=60c2cede9e023018]*/ +SHA512_digest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -543,33 +492,11 @@ return PyBytes_FromStringAndSize((const char *)digest, self->digestsize); } -/*[clinic input] -SHA512Type.hexdigest - -Return the digest value as a string of hexadecimal digits. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA512Type_hexdigest__doc__, -"hexdigest($self, /)\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA512_hexdigest__doc__, "Return the digest value as a string of hexadecimal digits."); -#define SHA512TYPE_HEXDIGEST_METHODDEF \ - {"hexdigest", (PyCFunction)SHA512Type_hexdigest, METH_NOARGS, SHA512Type_hexdigest__doc__}, - static PyObject * -SHA512Type_hexdigest_impl(SHAobject *self); - -static PyObject * -SHA512Type_hexdigest(SHAobject *self, PyObject *Py_UNUSED(ignored)) -{ - return SHA512Type_hexdigest_impl(self); -} - -static PyObject * -SHA512Type_hexdigest_impl(SHAobject *self) -/*[clinic end generated code: output=28a4ab2f9a1781b8 input=498b877b25cbe0a2]*/ +SHA512_hexdigest(SHAobject *self, PyObject *unused) { unsigned char digest[SHA_DIGESTSIZE]; SHAobject temp; @@ -601,30 +528,18 @@ return retval; } -/*[clinic input] -SHA512Type.update - - obj: object - / - -Update this hash object's state with the provided string. -[clinic start generated code]*/ - -PyDoc_STRVAR(SHA512Type_update__doc__, -"update($self, obj, /)\n" -"--\n" -"\n" -"Update this hash object\'s state with the provided string."); - -#define SHA512TYPE_UPDATE_METHODDEF \ - {"update", (PyCFunction)SHA512Type_update, METH_O, SHA512Type_update__doc__}, +PyDoc_STRVAR(SHA512_update__doc__, +"Update this hash object's state with the provided string."); static PyObject * -SHA512Type_update(SHAobject *self, PyObject *obj) -/*[clinic end generated code: output=6be574cdc3a9c52d input=ded2b46656566283]*/ +SHA512_update(SHAobject *self, PyObject *args) { + PyObject *obj; Py_buffer buf; + if (!PyArg_ParseTuple(args, "O:update", &obj)) + return NULL; + GET_BUFFER_VIEW_OR_ERROUT(obj, &buf); sha512_update(self, buf.buf, buf.len); @@ -633,32 +548,12 @@ Py_INCREF(Py_None); return Py_None; } -/*[clinic input] -dump buffer -[clinic start generated code]*/ - -#ifndef SHA512TYPE_COPY_METHODDEF - #define SHA512TYPE_COPY_METHODDEF -#endif /* !defined(SHA512TYPE_COPY_METHODDEF) */ - -#ifndef SHA512TYPE_DIGEST_METHODDEF - #define SHA512TYPE_DIGEST_METHODDEF -#endif /* !defined(SHA512TYPE_DIGEST_METHODDEF) */ - -#ifndef SHA512TYPE_HEXDIGEST_METHODDEF - #define SHA512TYPE_HEXDIGEST_METHODDEF -#endif /* !defined(SHA512TYPE_HEXDIGEST_METHODDEF) */ - -#ifndef SHA512TYPE_UPDATE_METHODDEF - #define SHA512TYPE_UPDATE_METHODDEF -#endif /* !defined(SHA512TYPE_UPDATE_METHODDEF) */ -/*[clinic end generated code: output=de713947d31130e9 input=524ce2e021e4eba6]*/ static PyMethodDef SHA_methods[] = { - SHA512TYPE_COPY_METHODDEF - SHA512TYPE_DIGEST_METHODDEF - SHA512TYPE_HEXDIGEST_METHODDEF - SHA512TYPE_UPDATE_METHODDEF + {"copy", (PyCFunction)SHA512_copy, METH_NOARGS, SHA512_copy__doc__}, + {"digest", (PyCFunction)SHA512_digest, METH_NOARGS, SHA512_digest__doc__}, + {"hexdigest", (PyCFunction)SHA512_hexdigest, METH_NOARGS, SHA512_hexdigest__doc__}, + {"update", (PyCFunction)SHA512_update, METH_VARARGS, SHA512_update__doc__}, {NULL, NULL} /* sentinel */ }; @@ -765,55 +660,27 @@ /* The single module-level function: new() */ -/*[clinic input] -_sha512.sha512 - - string: object(c_default="NULL") = b'' - -Return a new SHA-512 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha512_sha512__doc__, -"sha512($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA512_new__doc__, "Return a new SHA-512 hash object; optionally initialized with a string."); -#define _SHA512_SHA512_METHODDEF \ - {"sha512", (PyCFunction)_sha512_sha512, METH_VARARGS|METH_KEYWORDS, _sha512_sha512__doc__}, - static PyObject * -_sha512_sha512_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_sha512_sha512(PyModuleDef *module, PyObject *args, PyObject *kwargs) +SHA512_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:sha512", _keywords, - &string)) - goto exit; - return_value = _sha512_sha512_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_sha512_sha512_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=9e39b11115f36878 input=e69bad9ae9b6a308]*/ -{ + static char *kwlist[] = {"string", NULL}; SHAobject *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newSHA512object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -822,11 +689,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { sha512_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -834,55 +701,27 @@ return (PyObject *)new; } -/*[clinic input] -_sha512.sha384 - - string: object(c_default="NULL") = b'' - -Return a new SHA-384 hash object; optionally initialized with a string. -[clinic start generated code]*/ - -PyDoc_STRVAR(_sha512_sha384__doc__, -"sha384($module, /, string=b\'\')\n" -"--\n" -"\n" +PyDoc_STRVAR(SHA384_new__doc__, "Return a new SHA-384 hash object; optionally initialized with a string."); -#define _SHA512_SHA384_METHODDEF \ - {"sha384", (PyCFunction)_sha512_sha384, METH_VARARGS|METH_KEYWORDS, _sha512_sha384__doc__}, - static PyObject * -_sha512_sha384_impl(PyModuleDef *module, PyObject *string); - -static PyObject * -_sha512_sha384(PyModuleDef *module, PyObject *args, PyObject *kwargs) +SHA384_new(PyObject *self, PyObject *args, PyObject *kwdict) { - PyObject *return_value = NULL; - static char *_keywords[] = {"string", NULL}; - PyObject *string = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|O:sha384", _keywords, - &string)) - goto exit; - return_value = _sha512_sha384_impl(module, string); - -exit: - return return_value; -} - -static PyObject * -_sha512_sha384_impl(PyModuleDef *module, PyObject *string) -/*[clinic end generated code: output=397c6fba3525b93a input=c9327788d4ea4545]*/ -{ + static char *kwlist[] = {"string", NULL}; SHAobject *new; + PyObject *data_obj = NULL; Py_buffer buf; - if (string) - GET_BUFFER_VIEW_OR_ERROUT(string, &buf); + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "|O:new", kwlist, + &data_obj)) { + return NULL; + } + + if (data_obj) + GET_BUFFER_VIEW_OR_ERROUT(data_obj, &buf); if ((new = newSHA384object()) == NULL) { - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } @@ -891,11 +730,11 @@ if (PyErr_Occurred()) { Py_DECREF(new); - if (string) + if (data_obj) PyBuffer_Release(&buf); return NULL; } - if (string) { + if (data_obj) { sha512_update(new, buf.buf, buf.len); PyBuffer_Release(&buf); } @@ -904,24 +743,11 @@ } -/*[clinic input] -dump buffer -[clinic start generated code]*/ - -#ifndef _SHA512_SHA512_METHODDEF - #define _SHA512_SHA512_METHODDEF -#endif /* !defined(_SHA512_SHA512_METHODDEF) */ - -#ifndef _SHA512_SHA384_METHODDEF - #define _SHA512_SHA384_METHODDEF -#endif /* !defined(_SHA512_SHA384_METHODDEF) */ -/*[clinic end generated code: output=69d84aa9445b01d8 input=524ce2e021e4eba6]*/ - /* List of functions exported by this module */ static struct PyMethodDef SHA_functions[] = { - _SHA512_SHA512_METHODDEF - _SHA512_SHA384_METHODDEF + {"sha512", (PyCFunction)SHA512_new, METH_VARARGS|METH_KEYWORDS, SHA512_new__doc__}, + {"sha384", (PyCFunction)SHA384_new, METH_VARARGS|METH_KEYWORDS, SHA384_new__doc__}, {NULL, NULL} /* Sentinel */ }; diff -r 79e469ae13b7 -r 01438f18ee18 Modules/signalmodule.c --- a/Modules/signalmodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/signalmodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -7,9 +7,6 @@ #ifndef MS_WINDOWS #include "posixmodule.h" #endif -#ifdef MS_WINDOWS -#include "socketmodule.h" /* needed for SOCKET_T */ -#endif #ifdef MS_WINDOWS #include @@ -90,20 +87,7 @@ PyObject *func; } Handlers[NSIG]; -#ifdef MS_WINDOWS -#define INVALID_FD ((SOCKET_T)-1) - -static volatile struct { - SOCKET_T fd; - int use_send; - int send_err_set; - int send_errno; - int send_win_error; -} wakeup = {INVALID_FD, 0, 0}; -#else -#define INVALID_FD (-1) static volatile sig_atomic_t wakeup_fd = -1; -#endif /* Speed up sigcheck() when none tripped */ static volatile sig_atomic_t is_tripped = 0; @@ -188,7 +172,7 @@ } static int -report_wakeup_write_error(void *data) +report_wakeup_error(void *data) { int save_errno = errno; errno = (int) (Py_intptr_t) data; @@ -200,86 +184,25 @@ return 0; } -#ifdef MS_WINDOWS -static int -report_wakeup_send_error(void* Py_UNUSED(data)) -{ - PyObject *res; - - if (wakeup.send_win_error) { - /* PyErr_SetExcFromWindowsErr() invokes FormatMessage() which - recognizes the error codes used by both GetLastError() and - WSAGetLastError */ - res = PyErr_SetExcFromWindowsErr(PyExc_OSError, wakeup.send_win_error); - } - else { - errno = wakeup.send_errno; - res = PyErr_SetFromErrno(PyExc_OSError); - } - - assert(res == NULL); - wakeup.send_err_set = 0; - - PySys_WriteStderr("Exception ignored when trying to send to the " - "signal wakeup fd:\n"); - PyErr_WriteUnraisable(NULL); - - return 0; -} -#endif /* MS_WINDOWS */ - static void trip_signal(int sig_num) { unsigned char byte; - int fd; - Py_ssize_t rc; + int rc = 0; Handlers[sig_num].tripped = 1; - -#ifdef MS_WINDOWS - fd = Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int); -#else - fd = wakeup_fd; -#endif - - if (fd != INVALID_FD) { + if (wakeup_fd != -1) { byte = (unsigned char)sig_num; -#ifdef MS_WINDOWS - if (wakeup.use_send) { - do { - rc = send(fd, &byte, 1, 0); - } while (rc < 0 && errno == EINTR); - - /* we only have a storage for one error in the wakeup structure */ - if (rc < 0 && !wakeup.send_err_set) { - wakeup.send_err_set = 1; - wakeup.send_errno = errno; - wakeup.send_win_error = GetLastError(); - Py_AddPendingCall(report_wakeup_send_error, NULL); - } - } - else -#endif - { - byte = (unsigned char)sig_num; - do { - rc = write(fd, &byte, 1); - } while (rc < 0 && errno == EINTR); - - if (rc < 0) { - Py_AddPendingCall(report_wakeup_write_error, - (void *)(Py_intptr_t)errno); - } - } + while ((rc = write(wakeup_fd, &byte, 1)) == -1 && errno == EINTR); + if (rc == -1) + Py_AddPendingCall(report_wakeup_error, (void *) (Py_intptr_t) errno); } - - if (!is_tripped) { - /* Set is_tripped after setting .tripped, as it gets - cleared in PyErr_CheckSignals() before .tripped. */ - is_tripped = 1; - Py_AddPendingCall(checksignals_witharg, NULL); - } + if (is_tripped) + return; + /* Set is_tripped after setting .tripped, as it gets + cleared in PyErr_CheckSignals() before .tripped. */ + is_tripped = 1; + Py_AddPendingCall(checksignals_witharg, NULL); } static void @@ -503,29 +426,10 @@ static PyObject * signal_set_wakeup_fd(PyObject *self, PyObject *args) { -#ifdef MS_WINDOWS - PyObject *fdobj; - SOCKET_T fd, old_fd; - int res; - int res_size = sizeof res; - PyObject *mod; - struct stat st; - int is_socket; - - if (!PyArg_ParseTuple(args, "O:set_wakeup_fd", &fdobj)) - return NULL; - - fd = PyLong_AsSocket_t(fdobj); - if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) - return NULL; -#else + struct stat buf; int fd, old_fd; - struct stat st; - if (!PyArg_ParseTuple(args, "i:set_wakeup_fd", &fd)) return NULL; -#endif - #ifdef WITH_THREAD if (PyThread_get_thread_ident() != main_thread) { PyErr_SetString(PyExc_ValueError, @@ -534,72 +438,28 @@ } #endif -#ifdef MS_WINDOWS - is_socket = 0; - if (fd != INVALID_FD) { - /* Import the _socket module to call WSAStartup() */ - mod = PyImport_ImportModuleNoBlock("_socket"); - if (mod == NULL) - return NULL; - Py_DECREF(mod); - - /* test the socket */ - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, - (char *)&res, &res_size) != 0) { - int err = WSAGetLastError(); - if (err != WSAENOTSOCK) { - PyErr_SetExcFromWindowsErr(PyExc_OSError, err); - return NULL; - } - - if (!_PyVerify_fd(fd)) { - PyErr_SetString(PyExc_ValueError, "invalid fd"); - return NULL; - } - - if (fstat(fd, &st) != 0) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } - } - else - is_socket = 1; - } - - old_fd = wakeup.fd; - wakeup.fd = fd; - wakeup.use_send = is_socket; - - if (old_fd != INVALID_FD) - return PyLong_FromSocket_t(old_fd); - else - return PyLong_FromLong(-1); -#else if (fd != -1) { if (!_PyVerify_fd(fd)) { PyErr_SetString(PyExc_ValueError, "invalid fd"); return NULL; } - if (fstat(fd, &st) != 0) { - PyErr_SetFromErrno(PyExc_OSError); - return NULL; - } + if (fstat(fd, &buf) != 0) + return PyErr_SetFromErrno(PyExc_OSError); } old_fd = wakeup_fd; wakeup_fd = fd; return PyLong_FromLong(old_fd); -#endif } PyDoc_STRVAR(set_wakeup_fd_doc, "set_wakeup_fd(fd) -> fd\n\ \n\ -Sets the fd to be written to (with the signal number) when a signal\n\ +Sets the fd to be written to (with '\\0') when a signal\n\ comes in. A library can use this to wakeup select or poll.\n\ -The previous fd or -1 is returned.\n\ +The previous fd is returned.\n\ \n\ The fd must be non-blocking."); @@ -607,17 +467,10 @@ int PySignal_SetWakeupFd(int fd) { - int old_fd; + int old_fd = wakeup_fd; if (fd < 0) fd = -1; - -#ifdef MS_WINDOWS - old_fd = Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int); - wakeup.fd = fd; -#else - old_fd = wakeup_fd; wakeup_fd = fd; -#endif return old_fd; } diff -r 79e469ae13b7 -r 01438f18ee18 Modules/socketmodule.c --- a/Modules/socketmodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/socketmodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -1213,71 +1213,6 @@ } } -/* Helper for getsockaddrarg: bypass IDNA for ASCII-only host names - (in particular, numeric IP addresses). */ -struct maybe_idna { - PyObject *obj; - char *buf; -}; - -static void -idna_cleanup(struct maybe_idna *data) -{ - Py_CLEAR(data->obj); -} - -static int -idna_converter(PyObject *obj, struct maybe_idna *data) -{ - size_t len; - PyObject *obj2, *obj3; - if (obj == NULL) { - idna_cleanup(data); - return 1; - } - data->obj = NULL; - len = -1; - if (PyBytes_Check(obj)) { - data->buf = PyBytes_AsString(obj); - len = PyBytes_Size(obj); - } - else if (PyByteArray_Check(obj)) { - data->buf = PyByteArray_AsString(obj); - len = PyByteArray_Size(obj); - } - else if (PyUnicode_Check(obj) && PyUnicode_READY(obj) == 0 && PyUnicode_IS_COMPACT_ASCII(obj)) { - data->buf = PyUnicode_DATA(obj); - len = PyUnicode_GET_LENGTH(obj); - } - else { - obj2 = PyUnicode_FromObject(obj); - if (!obj2) { - PyErr_Format(PyExc_TypeError, "string or unicode text buffer expected, not %s", - obj->ob_type->tp_name); - return 0; - } - obj3 = PyUnicode_AsEncodedString(obj2, "idna", NULL); - Py_DECREF(obj2); - if (!obj3) { - PyErr_SetString(PyExc_TypeError, "encoding of hostname failed"); - return 0; - } - if (!PyBytes_Check(obj3)) { - Py_DECREF(obj3); - PyErr_SetString(PyExc_TypeError, "encoding of hostname failed to return bytes"); - return 0; - } - data->obj = obj3; - data->buf = PyBytes_AS_STRING(obj3); - len = PyBytes_GET_SIZE(obj3); - } - if (strlen(data->buf) != len) { - Py_CLEAR(data->obj); - PyErr_SetString(PyExc_TypeError, "host name must not contain NUL character"); - return 0; - } - return Py_CLEANUP_SUPPORTED; -} /* Parse a socket address argument according to the socket object's address family. Return 1 if the address was in the proper format, @@ -1372,7 +1307,7 @@ case AF_INET: { struct sockaddr_in* addr; - struct maybe_idna host = {NULL, NULL}; + char *host; int port, result; if (!PyTuple_Check(args)) { PyErr_Format( @@ -1382,13 +1317,13 @@ Py_TYPE(args)->tp_name); return 0; } - if (!PyArg_ParseTuple(args, "O&i:getsockaddrarg", - idna_converter, &host, &port)) + if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", + "idna", &host, &port)) return 0; addr=(struct sockaddr_in*)addr_ret; - result = setipaddr(host.buf, (struct sockaddr *)addr, + result = setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET); - idna_cleanup(&host); + PyMem_Free(host); if (result < 0) return 0; if (port < 0 || port > 0xffff) { @@ -1407,7 +1342,7 @@ case AF_INET6: { struct sockaddr_in6* addr; - struct maybe_idna host = {NULL, NULL}; + char *host; int port, result; unsigned int flowinfo, scope_id; flowinfo = scope_id = 0; @@ -1419,15 +1354,15 @@ Py_TYPE(args)->tp_name); return 0; } - if (!PyArg_ParseTuple(args, "O&i|II", - idna_converter, &host, &port, &flowinfo, + if (!PyArg_ParseTuple(args, "eti|II", + "idna", &host, &port, &flowinfo, &scope_id)) { return 0; } addr = (struct sockaddr_in6*)addr_ret; - result = setipaddr(host.buf, (struct sockaddr *)addr, + result = setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET6); - idna_cleanup(&host); + PyMem_Free(host); if (result < 0) return 0; if (port < 0 || port > 0xffff) { @@ -3934,13 +3869,8 @@ static PyObject * sock_repr(PySocketSockObject *s) { - long sock_fd; - /* On Windows, this test is needed because SOCKET_T is unsigned */ - if (s->sock_fd == INVALID_SOCKET) { - sock_fd = -1; - } #if SIZEOF_SOCKET_T > SIZEOF_LONG - else if (s->sock_fd > LONG_MAX) { + if (s->sock_fd > LONG_MAX) { /* this can occur on Win64, and actually there is a special ugly printf formatter for decimal pointer length integer printing, only bother if necessary*/ @@ -3950,11 +3880,9 @@ return NULL; } #endif - else - sock_fd = (long)s->sock_fd; return PyUnicode_FromFormat( "", - sock_fd, s->sock_family, + (long)s->sock_fd, s->sock_family, s->sock_type, s->sock_proto); } diff -r 79e469ae13b7 -r 01438f18ee18 Modules/timemodule.c --- a/Modules/timemodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Modules/timemodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -169,7 +169,7 @@ ret = clock_gettime((clockid_t)clk_id, &tp); if (ret != 0) { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromErrno(PyExc_IOError); return NULL; } return PyFloat_FromDouble(tp.tv_sec + tp.tv_nsec * 1e-9); @@ -200,7 +200,7 @@ ret = clock_settime((clockid_t)clk_id, &tp); if (ret != 0) { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromErrno(PyExc_IOError); return NULL; } Py_RETURN_NONE; @@ -223,7 +223,7 @@ ret = clock_getres((clockid_t)clk_id, &tp); if (ret != 0) { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromErrno(PyExc_IOError); return NULL; } @@ -1591,7 +1591,7 @@ else #endif { - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromErrno(PyExc_IOError); return -1; } } @@ -1625,7 +1625,7 @@ if (rc == WAIT_OBJECT_0) { Py_BLOCK_THREADS errno = EINTR; - PyErr_SetFromErrno(PyExc_OSError); + PyErr_SetFromErrno(PyExc_IOError); return -1; } } diff -r 79e469ae13b7 -r 01438f18ee18 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/bytearrayobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -5,11 +5,6 @@ #include "structmember.h" #include "bytes_methods.h" -/*[clinic input] -class bytearray "PyByteArrayObject *" "&PyByteArray_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=5535b77c37a119e0]*/ - char _PyByteArray_empty_string[] = ""; void @@ -445,9 +440,7 @@ } } else { - PyErr_Format(PyExc_TypeError, - "bytearray indices must be integers or slices, not %.200s", - Py_TYPE(index)->tp_name); + PyErr_SetString(PyExc_TypeError, "bytearray indices must be integers"); return NULL; } } @@ -652,9 +645,7 @@ } } else { - PyErr_Format(PyExc_TypeError, - "bytearray indices must be integers or slices, not %.200s", - Py_TYPE(index)->tp_name); + PyErr_SetString(PyExc_TypeError, "bytearray indices must be integer"); return -1; } @@ -1228,70 +1219,26 @@ return count_obj; } -/*[clinic input] -bytearray.clear - - self: self(type="PyByteArrayObject *") - -Remove all items from the bytearray. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_clear__doc__, -"clear($self, /)\n" -"--\n" -"\n" -"Remove all items from the bytearray."); - -#define BYTEARRAY_CLEAR_METHODDEF \ - {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, bytearray_clear__doc__}, +PyDoc_STRVAR(clear__doc__, +"B.clear() -> None\n\ +\n\ +Remove all items from B."); static PyObject * -bytearray_clear_impl(PyByteArrayObject *self); - -static PyObject * -bytearray_clear(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytearray_clear_impl(self); -} - -static PyObject * -bytearray_clear_impl(PyByteArrayObject *self) -/*[clinic end generated code: output=5344093031e2f36c input=e524fd330abcdc18]*/ +bytearray_clear(PyByteArrayObject *self) { if (PyByteArray_Resize((PyObject *)self, 0) < 0) return NULL; Py_RETURN_NONE; } -/*[clinic input] -bytearray.copy - - self: self(type="PyByteArrayObject *") - -Return a copy of B. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_copy__doc__, -"copy($self, /)\n" -"--\n" -"\n" -"Return a copy of B."); - -#define BYTEARRAY_COPY_METHODDEF \ - {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, bytearray_copy__doc__}, +PyDoc_STRVAR(copy__doc__, +"B.copy() -> bytearray\n\ +\n\ +Return a copy of B."); static PyObject * -bytearray_copy_impl(PyByteArrayObject *self); - -static PyObject * -bytearray_copy(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytearray_copy_impl(self); -} - -static PyObject * -bytearray_copy_impl(PyByteArrayObject *self) -/*[clinic end generated code: output=8788ed299f7f2214 input=6d5d2975aa0f33f3]*/ +bytearray_copy(PyByteArrayObject *self) { return PyByteArray_FromStringAndSize(PyByteArray_AS_STRING((PyObject *)self), PyByteArray_GET_SIZE(self)); @@ -1510,85 +1457,36 @@ } -/*[clinic input] -bytearray.translate - - self: self(type="PyByteArrayObject *") - table: object - Translation table, which must be a bytes object of length 256. - [ - deletechars: object - ] - / - -Return a copy with each character mapped by the given translation table. - -All characters occurring in the optional argument deletechars are removed. -The remaining characters are mapped through the given translation table. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_translate__doc__, -"translate(table, [deletechars])\n" -"Return a copy with each character mapped by the given translation table.\n" -"\n" -" table\n" -" Translation table, which must be a bytes object of length 256.\n" -"\n" -"All characters occurring in the optional argument deletechars are removed.\n" -"The remaining characters are mapped through the given translation table."); - -#define BYTEARRAY_TRANSLATE_METHODDEF \ - {"translate", (PyCFunction)bytearray_translate, METH_VARARGS, bytearray_translate__doc__}, - -static PyObject * -bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, int group_right_1, PyObject *deletechars); +PyDoc_STRVAR(translate__doc__, +"B.translate(table[, deletechars]) -> bytearray\n\ +\n\ +Return a copy of B, where all characters occurring in the\n\ +optional argument deletechars are removed, and the remaining\n\ +characters have been mapped through the given translation\n\ +table, which must be a bytes object of length 256."); static PyObject * bytearray_translate(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *table; - int group_right_1 = 0; - PyObject *deletechars = NULL; - - switch (PyTuple_GET_SIZE(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O:translate", &table)) - goto exit; - break; - case 2: - if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) - goto exit; - group_right_1 = 1; - break; - default: - PyErr_SetString(PyExc_TypeError, "bytearray.translate requires 1 to 2 arguments"); - goto exit; - } - return_value = bytearray_translate_impl(self, table, group_right_1, deletechars); - -exit: - return return_value; -} - -static PyObject * -bytearray_translate_impl(PyByteArrayObject *self, PyObject *table, int group_right_1, PyObject *deletechars) -/*[clinic end generated code: output=a709df81d41db4b7 input=b749ad85f4860824]*/ -{ char *input, *output; - const char *table_chars; + const char *table; Py_ssize_t i, c; PyObject *input_obj = (PyObject*)self; const char *output_start; Py_ssize_t inlen; PyObject *result = NULL; int trans_table[256]; + PyObject *tableobj = NULL, *delobj = NULL; Py_buffer vtable, vdel; - if (table == Py_None) { - table_chars = NULL; + if (!PyArg_UnpackTuple(args, "translate", 1, 2, + &tableobj, &delobj)) + return NULL; + + if (tableobj == Py_None) { table = NULL; - } else if (_getbuffer(table, &vtable) < 0) { + tableobj = NULL; + } else if (_getbuffer(tableobj, &vtable) < 0) { return NULL; } else { if (vtable.len != 256) { @@ -1597,12 +1495,12 @@ PyBuffer_Release(&vtable); return NULL; } - table_chars = (const char*)vtable.buf; + table = (const char*)vtable.buf; } - if (deletechars != NULL) { - if (_getbuffer(deletechars, &vdel) < 0) { - if (table != NULL) + if (delobj != NULL) { + if (_getbuffer(delobj, &vdel) < 0) { + if (tableobj != NULL) PyBuffer_Release(&vtable); return NULL; } @@ -1619,21 +1517,21 @@ output_start = output = PyByteArray_AsString(result); input = PyByteArray_AS_STRING(input_obj); - if (vdel.len == 0 && table_chars != NULL) { + if (vdel.len == 0 && table != NULL) { /* If no deletions are required, use faster code */ for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); - *output++ = table_chars[c]; + *output++ = table[c]; } goto done; } - if (table_chars == NULL) { + if (table == NULL) { for (i = 0; i < 256; i++) trans_table[i] = Py_CHARMASK(i); } else { for (i = 0; i < 256; i++) - trans_table[i] = Py_CHARMASK(table_chars[i]); + trans_table[i] = Py_CHARMASK(table[i]); } for (i = 0; i < vdel.len; i++) @@ -1653,70 +1551,18 @@ } done: - if (table != NULL) + if (tableobj != NULL) PyBuffer_Release(&vtable); - if (deletechars != NULL) + if (delobj != NULL) PyBuffer_Release(&vdel); return result; } -/*[clinic input] - -@staticmethod -bytearray.maketrans - - frm: object - to: object - / - -Return a translation table useable for the bytes or bytearray translate method. - -The returned table will be one where each byte in frm is mapped to the byte at -the same position in to. - -The bytes objects frm and to must be of the same length. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_maketrans__doc__, -"maketrans(frm, to, /)\n" -"--\n" -"\n" -"Return a translation table useable for the bytes or bytearray translate method.\n" -"\n" -"The returned table will be one where each byte in frm is mapped to the byte at\n" -"the same position in to.\n" -"\n" -"The bytes objects frm and to must be of the same length."); - -#define BYTEARRAY_MAKETRANS_METHODDEF \ - {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, bytearray_maketrans__doc__}, - static PyObject * -bytearray_maketrans_impl(PyObject *frm, PyObject *to); - -static PyObject * -bytearray_maketrans(void *null, PyObject *args) +bytearray_maketrans(PyObject *null, PyObject *args) { - PyObject *return_value = NULL; - PyObject *frm; - PyObject *to; - - if (!PyArg_UnpackTuple(args, "maketrans", - 2, 2, - &frm, &to)) - goto exit; - return_value = bytearray_maketrans_impl(frm, to); - -exit: - return return_value; -} - -static PyObject * -bytearray_maketrans_impl(PyObject *frm, PyObject *to) -/*[clinic end generated code: output=307752019d9b25b5 input=ea9bdc6b328c15e2]*/ -{ - return _Py_bytes_maketrans(frm, to); + return _Py_bytes_maketrans(args); } @@ -2207,150 +2053,67 @@ } -/*[clinic input] -bytearray.replace - - old: object - new: object - count: Py_ssize_t = -1 - Maximum number of occurrences to replace. - -1 (the default value) means replace all occurrences. - / - -Return a copy with all occurrences of substring old replaced by new. - -If the optional argument count is given, only the first count occurrences are -replaced. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_replace__doc__, -"replace($self, old, new, count=-1, /)\n" -"--\n" -"\n" -"Return a copy with all occurrences of substring old replaced by new.\n" -"\n" -" count\n" -" Maximum number of occurrences to replace.\n" -" -1 (the default value) means replace all occurrences.\n" -"\n" -"If the optional argument count is given, only the first count occurrences are\n" -"replaced."); - -#define BYTEARRAY_REPLACE_METHODDEF \ - {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, bytearray_replace__doc__}, - -static PyObject * -bytearray_replace_impl(PyByteArrayObject *self, PyObject *old, PyObject *new, Py_ssize_t count); +PyDoc_STRVAR(replace__doc__, +"B.replace(old, new[, count]) -> bytearray\n\ +\n\ +Return a copy of B with all occurrences of subsection\n\ +old replaced by new. If the optional argument count is\n\ +given, only the first count occurrences are replaced."); static PyObject * bytearray_replace(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *old; - PyObject *new; Py_ssize_t count = -1; - - if (!PyArg_ParseTuple(args, - "OO|n:replace", - &old, &new, &count)) - goto exit; - return_value = bytearray_replace_impl(self, old, new, count); - -exit: - return return_value; -} - -static PyObject * -bytearray_replace_impl(PyByteArrayObject *self, PyObject *old, PyObject *new, Py_ssize_t count) -/*[clinic end generated code: output=4d2e3c9130da0f96 input=9aaaa123608dfc1f]*/ -{ - PyObject *res; - Py_buffer vold, vnew; - - if (_getbuffer(old, &vold) < 0) + PyObject *from, *to, *res; + Py_buffer vfrom, vto; + + if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count)) return NULL; - if (_getbuffer(new, &vnew) < 0) { - PyBuffer_Release(&vold); + + if (_getbuffer(from, &vfrom) < 0) + return NULL; + if (_getbuffer(to, &vto) < 0) { + PyBuffer_Release(&vfrom); return NULL; } res = (PyObject *)replace((PyByteArrayObject *) self, - vold.buf, vold.len, - vnew.buf, vnew.len, count); - - PyBuffer_Release(&vold); - PyBuffer_Release(&vnew); + vfrom.buf, vfrom.len, + vto.buf, vto.len, count); + + PyBuffer_Release(&vfrom); + PyBuffer_Release(&vto); return res; } -/*[clinic input] -bytearray.split - - sep: object = None - The delimiter according which to split the bytearray. - None (the default value) means split on ASCII whitespace characters - (space, tab, return, newline, formfeed, vertical tab). - maxsplit: Py_ssize_t = -1 - Maximum number of splits to do. - -1 (the default value) means no limit. - -Return a list of the sections in the bytearray, using sep as the delimiter. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_split__doc__, -"split($self, /, sep=None, maxsplit=-1)\n" -"--\n" -"\n" -"Return a list of the sections in the bytearray, using sep as the delimiter.\n" -"\n" -" sep\n" -" The delimiter according which to split the bytearray.\n" -" None (the default value) means split on ASCII whitespace characters\n" -" (space, tab, return, newline, formfeed, vertical tab).\n" -" maxsplit\n" -" Maximum number of splits to do.\n" -" -1 (the default value) means no limit."); - -#define BYTEARRAY_SPLIT_METHODDEF \ - {"split", (PyCFunction)bytearray_split, METH_VARARGS|METH_KEYWORDS, bytearray_split__doc__}, +PyDoc_STRVAR(split__doc__, +"B.split(sep=None, maxsplit=-1) -> list of bytearrays\n\ +\n\ +Return a list of the sections in B, using sep as the delimiter.\n\ +If sep is not given, B is split on ASCII whitespace characters\n\ +(space, tab, return, newline, formfeed, vertical tab).\n\ +If maxsplit is given, at most maxsplit splits are done."); static PyObject * -bytearray_split_impl(PyByteArrayObject *self, PyObject *sep, Py_ssize_t maxsplit); - -static PyObject * -bytearray_split(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) +bytearray_split(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - PyObject *return_value = NULL; - static char *_keywords[] = {"sep", "maxsplit", NULL}; - PyObject *sep = Py_None; + static char *kwlist[] = {"sep", "maxsplit", 0}; + Py_ssize_t len = PyByteArray_GET_SIZE(self), n; Py_ssize_t maxsplit = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|On:split", _keywords, - &sep, &maxsplit)) - goto exit; - return_value = bytearray_split_impl(self, sep, maxsplit); - -exit: - return return_value; -} - -static PyObject * -bytearray_split_impl(PyByteArrayObject *self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=062a3d87d6f918fa input=24f82669f41bf523]*/ -{ - Py_ssize_t len = PyByteArray_GET_SIZE(self), n; const char *s = PyByteArray_AS_STRING(self), *sub; - PyObject *list; + PyObject *list, *subobj = Py_None; Py_buffer vsub; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:split", + kwlist, &subobj, &maxsplit)) + return NULL; if (maxsplit < 0) maxsplit = PY_SSIZE_T_MAX; - if (sep == Py_None) + if (subobj == Py_None) return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit); - if (_getbuffer(sep, &vsub) < 0) + if (_getbuffer(subobj, &vsub) < 0) return NULL; sub = vsub.buf; n = vsub.len; @@ -2362,46 +2125,19 @@ return list; } -/*[clinic input] -bytearray.partition - - self: self(type="PyByteArrayObject *") - sep: object - / - -Partition the bytearray into three parts using the given separator. - -This will search for the separator sep in the bytearray. If the separator is -found, returns a 3-tuple containing the part before the separator, the -separator itself, and the part after it. - -If the separator is not found, returns a 3-tuple containing the original -bytearray object and two empty bytearray objects. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_partition__doc__, -"partition($self, sep, /)\n" -"--\n" -"\n" -"Partition the bytearray into three parts using the given separator.\n" -"\n" -"This will search for the separator sep in the bytearray. If the separator is\n" -"found, returns a 3-tuple containing the part before the separator, the\n" -"separator itself, and the part after it.\n" -"\n" -"If the separator is not found, returns a 3-tuple containing the original\n" -"bytearray object and two empty bytearray objects."); - -#define BYTEARRAY_PARTITION_METHODDEF \ - {"partition", (PyCFunction)bytearray_partition, METH_O, bytearray_partition__doc__}, +PyDoc_STRVAR(partition__doc__, +"B.partition(sep) -> (head, sep, tail)\n\ +\n\ +Search for the separator sep in B, and return the part before it,\n\ +the separator itself, and the part after it. If the separator is not\n\ +found, returns B and two empty bytearray objects."); static PyObject * -bytearray_partition(PyByteArrayObject *self, PyObject *sep) -/*[clinic end generated code: output=2645138221fe6f4d input=7d7fe37b1696d506]*/ +bytearray_partition(PyByteArrayObject *self, PyObject *sep_obj) { PyObject *bytesep, *result; - bytesep = PyByteArray_FromObject(sep); + bytesep = PyByteArray_FromObject(sep_obj); if (! bytesep) return NULL; @@ -2416,46 +2152,20 @@ return result; } -/*[clinic input] -bytearray.rpartition - - self: self(type="PyByteArrayObject *") - sep: object - / - -Partition the bytes into three parts using the given separator. - -This will search for the separator sep in the bytearray, starting and the end. -If the separator is found, returns a 3-tuple containing the part before the -separator, the separator itself, and the part after it. - -If the separator is not found, returns a 3-tuple containing two empty bytearray -objects and the original bytearray object. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_rpartition__doc__, -"rpartition($self, sep, /)\n" -"--\n" -"\n" -"Partition the bytes into three parts using the given separator.\n" -"\n" -"This will search for the separator sep in the bytearray, starting and the end.\n" -"If the separator is found, returns a 3-tuple containing the part before the\n" -"separator, the separator itself, and the part after it.\n" -"\n" -"If the separator is not found, returns a 3-tuple containing two empty bytearray\n" -"objects and the original bytearray object."); - -#define BYTEARRAY_RPARTITION_METHODDEF \ - {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, bytearray_rpartition__doc__}, +PyDoc_STRVAR(rpartition__doc__, +"B.rpartition(sep) -> (head, sep, tail)\n\ +\n\ +Search for the separator sep in B, starting at the end of B,\n\ +and return the part before it, the separator itself, and the\n\ +part after it. If the separator is not found, returns two empty\n\ +bytearray objects and B."); static PyObject * -bytearray_rpartition(PyByteArrayObject *self, PyObject *sep) -/*[clinic end generated code: output=ed13e54605d007de input=9b8cd540c1b75853]*/ +bytearray_rpartition(PyByteArrayObject *self, PyObject *sep_obj) { PyObject *bytesep, *result; - bytesep = PyByteArray_FromObject(sep); + bytesep = PyByteArray_FromObject(sep_obj); if (! bytesep) return NULL; @@ -2470,70 +2180,35 @@ return result; } -/*[clinic input] -bytearray.rsplit = bytearray.split - -Return a list of the sections in the bytearray, using sep as the delimiter. - -Splitting is done starting at the end of the bytearray and working to the front. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_rsplit__doc__, -"rsplit($self, /, sep=None, maxsplit=-1)\n" -"--\n" -"\n" -"Return a list of the sections in the bytearray, using sep as the delimiter.\n" -"\n" -" sep\n" -" The delimiter according which to split the bytearray.\n" -" None (the default value) means split on ASCII whitespace characters\n" -" (space, tab, return, newline, formfeed, vertical tab).\n" -" maxsplit\n" -" Maximum number of splits to do.\n" -" -1 (the default value) means no limit.\n" -"\n" -"Splitting is done starting at the end of the bytearray and working to the front."); - -#define BYTEARRAY_RSPLIT_METHODDEF \ - {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS|METH_KEYWORDS, bytearray_rsplit__doc__}, +PyDoc_STRVAR(rsplit__doc__, +"B.rsplit(sep=None, maxsplit=-1) -> list of bytearrays\n\ +\n\ +Return a list of the sections in B, using sep as the delimiter,\n\ +starting at the end of B and working to the front.\n\ +If sep is not given, B is split on ASCII whitespace characters\n\ +(space, tab, return, newline, formfeed, vertical tab).\n\ +If maxsplit is given, at most maxsplit splits are done."); static PyObject * -bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep, Py_ssize_t maxsplit); - -static PyObject * -bytearray_rsplit(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) +bytearray_rsplit(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - PyObject *return_value = NULL; - static char *_keywords[] = {"sep", "maxsplit", NULL}; - PyObject *sep = Py_None; + static char *kwlist[] = {"sep", "maxsplit", 0}; + Py_ssize_t len = PyByteArray_GET_SIZE(self), n; Py_ssize_t maxsplit = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|On:rsplit", _keywords, - &sep, &maxsplit)) - goto exit; - return_value = bytearray_rsplit_impl(self, sep, maxsplit); - -exit: - return return_value; -} - -static PyObject * -bytearray_rsplit_impl(PyByteArrayObject *self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=affaf9fc2aae8d41 input=a68286e4dd692ffe]*/ -{ - Py_ssize_t len = PyByteArray_GET_SIZE(self), n; const char *s = PyByteArray_AS_STRING(self), *sub; - PyObject *list; + PyObject *list, *subobj = Py_None; Py_buffer vsub; + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:rsplit", + kwlist, &subobj, &maxsplit)) + return NULL; if (maxsplit < 0) maxsplit = PY_SSIZE_T_MAX; - if (sep == Py_None) + if (subobj == Py_None) return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit); - if (_getbuffer(sep, &vsub) < 0) + if (_getbuffer(subobj, &vsub) < 0) return NULL; sub = vsub.buf; n = vsub.len; @@ -2545,35 +2220,12 @@ return list; } -/*[clinic input] -bytearray.reverse - - self: self(type="PyByteArrayObject *") - -Reverse the order of the values in B in place. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_reverse__doc__, -"reverse($self, /)\n" -"--\n" -"\n" -"Reverse the order of the values in B in place."); - -#define BYTEARRAY_REVERSE_METHODDEF \ - {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, bytearray_reverse__doc__}, - +PyDoc_STRVAR(reverse__doc__, +"B.reverse() -> None\n\ +\n\ +Reverse the order of the values in B in place."); static PyObject * -bytearray_reverse_impl(PyByteArrayObject *self); - -static PyObject * -bytearray_reverse(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytearray_reverse_impl(self); -} - -static PyObject * -bytearray_reverse_impl(PyByteArrayObject *self) -/*[clinic end generated code: output=5d5e5f0bfc67f476 input=7933a499b8597bd1]*/ +bytearray_reverse(PyByteArrayObject *self, PyObject *unused) { char swap, *head, *tail; Py_ssize_t i, j, n = Py_SIZE(self); @@ -2590,69 +2242,57 @@ Py_RETURN_NONE; } - -/*[python input] -class bytesvalue_converter(CConverter): - type = 'int' - converter = '_getbytevalue' -[python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=29c2e7c26c212812]*/ - - -/*[clinic input] -bytearray.insert - - self: self(type="PyByteArrayObject *") - index: Py_ssize_t - The index where the value is to be inserted. - item: bytesvalue - The item to be inserted. - / - -Insert a single item into the bytearray before the given index. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_insert__doc__, -"insert($self, index, item, /)\n" -"--\n" -"\n" -"Insert a single item into the bytearray before the given index.\n" -"\n" -" index\n" -" The index where the value is to be inserted.\n" -" item\n" -" The item to be inserted."); - -#define BYTEARRAY_INSERT_METHODDEF \ - {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, bytearray_insert__doc__}, - -static PyObject * -bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item); - +PyDoc_STRVAR(insert__doc__, +"B.insert(index, int) -> None\n\ +\n\ +Insert a single item into the bytearray before the given index."); static PyObject * bytearray_insert(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - Py_ssize_t index; - int item; - - if (!PyArg_ParseTuple(args, - "nO&:insert", - &index, _getbytevalue, &item)) - goto exit; - return_value = bytearray_insert_impl(self, index, item); - -exit: - return return_value; + PyObject *value; + int ival; + Py_ssize_t where, n = Py_SIZE(self); + char *buf; + + if (!PyArg_ParseTuple(args, "nO:insert", &where, &value)) + return NULL; + + if (n == PY_SSIZE_T_MAX) { + PyErr_SetString(PyExc_OverflowError, + "cannot add more objects to bytearray"); + return NULL; + } + if (!_getbytevalue(value, &ival)) + return NULL; + if (PyByteArray_Resize((PyObject *)self, n + 1) < 0) + return NULL; + buf = PyByteArray_AS_STRING(self); + + if (where < 0) { + where += n; + if (where < 0) + where = 0; + } + if (where > n) + where = n; + memmove(buf + where + 1, buf + where, n - where); + buf[where] = ival; + + Py_RETURN_NONE; } +PyDoc_STRVAR(append__doc__, +"B.append(int) -> None\n\ +\n\ +Append a single item to the end of B."); static PyObject * -bytearray_insert_impl(PyByteArrayObject *self, Py_ssize_t index, int item) -/*[clinic end generated code: output=5ec9340d4ad19080 input=833766836ba30e1e]*/ +bytearray_append(PyByteArrayObject *self, PyObject *arg) { + int value; Py_ssize_t n = Py_SIZE(self); - char *buf; - + + if (! _getbytevalue(arg, &value)) + return NULL; if (n == PY_SSIZE_T_MAX) { PyErr_SetString(PyExc_OverflowError, "cannot add more objects to bytearray"); @@ -2660,108 +2300,19 @@ } if (PyByteArray_Resize((PyObject *)self, n + 1) < 0) return NULL; - buf = PyByteArray_AS_STRING(self); - - if (index < 0) { - index += n; - if (index < 0) - index = 0; - } - if (index > n) - index = n; - memmove(buf + index + 1, buf + index, n - index); - buf[index] = item; + + PyByteArray_AS_STRING(self)[n] = value; Py_RETURN_NONE; } -/*[clinic input] -bytearray.append - - self: self(type="PyByteArrayObject *") - item: bytesvalue - The item to be appended. - / - -Append a single item to the end of the bytearray. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_append__doc__, -"append($self, item, /)\n" -"--\n" -"\n" -"Append a single item to the end of the bytearray.\n" -"\n" -" item\n" -" The item to be appended."); - -#define BYTEARRAY_APPEND_METHODDEF \ - {"append", (PyCFunction)bytearray_append, METH_VARARGS, bytearray_append__doc__}, - +PyDoc_STRVAR(extend__doc__, +"B.extend(iterable_of_ints) -> None\n\ +\n\ +Append all the elements from the iterator or sequence to the\n\ +end of B."); static PyObject * -bytearray_append_impl(PyByteArrayObject *self, int item); - -static PyObject * -bytearray_append(PyByteArrayObject *self, PyObject *args) -{ - PyObject *return_value = NULL; - int item; - - if (!PyArg_ParseTuple(args, - "O&:append", - _getbytevalue, &item)) - goto exit; - return_value = bytearray_append_impl(self, item); - -exit: - return return_value; -} - -static PyObject * -bytearray_append_impl(PyByteArrayObject *self, int item) -/*[clinic end generated code: output=b5b3325bb3bbaf85 input=ae56ea87380407cc]*/ -{ - Py_ssize_t n = Py_SIZE(self); - - if (n == PY_SSIZE_T_MAX) { - PyErr_SetString(PyExc_OverflowError, - "cannot add more objects to bytearray"); - return NULL; - } - if (PyByteArray_Resize((PyObject *)self, n + 1) < 0) - return NULL; - - PyByteArray_AS_STRING(self)[n] = item; - - Py_RETURN_NONE; -} - -/*[clinic input] -bytearray.extend - - self: self(type="PyByteArrayObject *") - iterable_of_ints: object - The iterable of items to append. - / - -Append all the items from the iterator or sequence to the end of the bytearray. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_extend__doc__, -"extend($self, iterable_of_ints, /)\n" -"--\n" -"\n" -"Append all the items from the iterator or sequence to the end of the bytearray.\n" -"\n" -" iterable_of_ints\n" -" The iterable of items to append."); - -#define BYTEARRAY_EXTEND_METHODDEF \ - {"extend", (PyCFunction)bytearray_extend, METH_O, bytearray_extend__doc__}, - -static PyObject * -bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints) -/*[clinic end generated code: output=13b0c13ad5110dfb input=ce83a5d75b70d850]*/ +bytearray_extend(PyByteArrayObject *self, PyObject *arg) { PyObject *it, *item, *bytearray_obj; Py_ssize_t buf_size = 0, len = 0; @@ -2769,19 +2320,19 @@ char *buf; /* bytearray_setslice code only accepts something supporting PEP 3118. */ - if (PyObject_CheckBuffer(iterable_of_ints)) { - if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), iterable_of_ints) == -1) + if (PyObject_CheckBuffer(arg)) { + if (bytearray_setslice(self, Py_SIZE(self), Py_SIZE(self), arg) == -1) return NULL; Py_RETURN_NONE; } - it = PyObject_GetIter(iterable_of_ints); + it = PyObject_GetIter(arg); if (it == NULL) return NULL; /* Try to determine the length of the argument. 32 is arbitrary. */ - buf_size = PyObject_LengthHint(iterable_of_ints, 32); + buf_size = PyObject_LengthHint(arg, 32); if (buf_size == -1) { Py_DECREF(it); return NULL; @@ -2833,70 +2384,29 @@ Py_RETURN_NONE; } -/*[clinic input] -bytearray.pop - - self: self(type="PyByteArrayObject *") - index: Py_ssize_t = -1 - The index from where to remove the item. - -1 (the default value) means remove the last item. - / - -Remove and return a single item from B. - -If no index argument is given, will pop the last item. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_pop__doc__, -"pop($self, index=-1, /)\n" -"--\n" -"\n" -"Remove and return a single item from B.\n" -"\n" -" index\n" -" The index from where to remove the item.\n" -" -1 (the default value) means remove the last item.\n" -"\n" -"If no index argument is given, will pop the last item."); - -#define BYTEARRAY_POP_METHODDEF \ - {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, bytearray_pop__doc__}, - -static PyObject * -bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index); - +PyDoc_STRVAR(pop__doc__, +"B.pop([index]) -> int\n\ +\n\ +Remove and return a single item from B. If no index\n\ +argument is given, will pop the last value."); static PyObject * bytearray_pop(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - Py_ssize_t index = -1; - - if (!PyArg_ParseTuple(args, - "|n:pop", - &index)) - goto exit; - return_value = bytearray_pop_impl(self, index); - -exit: - return return_value; -} - -static PyObject * -bytearray_pop_impl(PyByteArrayObject *self, Py_ssize_t index) -/*[clinic end generated code: output=3b763e548e79af96 input=0797e6c0ca9d5a85]*/ -{ int value; - Py_ssize_t n = Py_SIZE(self); + Py_ssize_t where = -1, n = Py_SIZE(self); char *buf; + if (!PyArg_ParseTuple(args, "|n:pop", &where)) + return NULL; + if (n == 0) { PyErr_SetString(PyExc_IndexError, "pop from empty bytearray"); return NULL; } - if (index < 0) - index += Py_SIZE(self); - if (index < 0 || index >= Py_SIZE(self)) { + if (where < 0) + where += Py_SIZE(self); + if (where < 0 || where >= Py_SIZE(self)) { PyErr_SetString(PyExc_IndexError, "pop index out of range"); return NULL; } @@ -2904,63 +2414,28 @@ return NULL; buf = PyByteArray_AS_STRING(self); - value = buf[index]; - memmove(buf + index, buf + index + 1, n - index); + value = buf[where]; + memmove(buf + where, buf + where + 1, n - where); if (PyByteArray_Resize((PyObject *)self, n - 1) < 0) return NULL; return PyLong_FromLong((unsigned char)value); } -/*[clinic input] -bytearray.remove - - self: self(type="PyByteArrayObject *") - value: bytesvalue - The value to remove. - / - -Remove the first occurrence of a value in the bytearray. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_remove__doc__, -"remove($self, value, /)\n" -"--\n" -"\n" -"Remove the first occurrence of a value in the bytearray.\n" -"\n" -" value\n" -" The value to remove."); - -#define BYTEARRAY_REMOVE_METHODDEF \ - {"remove", (PyCFunction)bytearray_remove, METH_VARARGS, bytearray_remove__doc__}, - +PyDoc_STRVAR(remove__doc__, +"B.remove(int) -> None\n\ +\n\ +Remove the first occurrence of a value in B."); static PyObject * -bytearray_remove_impl(PyByteArrayObject *self, int value); - -static PyObject * -bytearray_remove(PyByteArrayObject *self, PyObject *args) +bytearray_remove(PyByteArrayObject *self, PyObject *arg) { - PyObject *return_value = NULL; int value; - - if (!PyArg_ParseTuple(args, - "O&:remove", - _getbytevalue, &value)) - goto exit; - return_value = bytearray_remove_impl(self, value); - -exit: - return return_value; -} - -static PyObject * -bytearray_remove_impl(PyByteArrayObject *self, int value) -/*[clinic end generated code: output=c71c8bcf4703abfc input=47560b11fd856c24]*/ -{ Py_ssize_t where, n = Py_SIZE(self); char *buf = PyByteArray_AS_STRING(self); + if (! _getbytevalue(arg, &value)) + return NULL; + for (where = 0; where < n; where++) { if (buf[where] == value) break; @@ -3001,273 +2476,132 @@ return i + 1; } -/*[clinic input] -bytearray.strip - - bytes: object = None - / - -Strip leading and trailing bytes contained in the argument. - -If the argument is omitted or None, strip leading and trailing ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_strip__doc__, -"strip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip leading and trailing bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip leading and trailing ASCII whitespace."); - -#define BYTEARRAY_STRIP_METHODDEF \ - {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, bytearray_strip__doc__}, - -static PyObject * -bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes); - +PyDoc_STRVAR(strip__doc__, +"B.strip([bytes]) -> bytearray\n\ +\n\ +Strip leading and trailing bytes contained in the argument\n\ +and return the result as a new bytearray.\n\ +If the argument is omitted, strip ASCII whitespace."); static PyObject * bytearray_strip(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "strip", - 0, 1, - &bytes)) - goto exit; - return_value = bytearray_strip_impl(self, bytes); - -exit: - return return_value; -} - -static PyObject * -bytearray_strip_impl(PyByteArrayObject *self, PyObject *bytes) -/*[clinic end generated code: output=2e3d3358acc4c235 input=ef7bb59b09c21d62]*/ -{ - Py_ssize_t left, right, mysize, byteslen; - char *myptr, *bytesptr; - Py_buffer vbytes; - - if (bytes == Py_None) { - bytesptr = "\t\n\r\f\v "; - byteslen = 6; + Py_ssize_t left, right, mysize, argsize; + char *myptr, *argptr; + PyObject *arg = Py_None; + Py_buffer varg; + if (!PyArg_ParseTuple(args, "|O:strip", &arg)) + return NULL; + if (arg == Py_None) { + argptr = "\t\n\r\f\v "; + argsize = 6; } else { - if (_getbuffer(bytes, &vbytes) < 0) + if (_getbuffer(arg, &varg) < 0) return NULL; - bytesptr = (char *) vbytes.buf; - byteslen = vbytes.len; + argptr = (char *) varg.buf; + argsize = varg.len; } myptr = PyByteArray_AS_STRING(self); mysize = Py_SIZE(self); - left = lstrip_helper(myptr, mysize, bytesptr, byteslen); + left = lstrip_helper(myptr, mysize, argptr, argsize); if (left == mysize) right = left; else - right = rstrip_helper(myptr, mysize, bytesptr, byteslen); - if (bytes != Py_None) - PyBuffer_Release(&vbytes); + right = rstrip_helper(myptr, mysize, argptr, argsize); + if (arg != Py_None) + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(myptr + left, right - left); } -/*[clinic input] -bytearray.lstrip - - bytes: object = None - / - -Strip leading bytes contained in the argument. - -If the argument is omitted or None, strip leading ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_lstrip__doc__, -"lstrip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip leading bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip leading ASCII whitespace."); - -#define BYTEARRAY_LSTRIP_METHODDEF \ - {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, bytearray_lstrip__doc__}, - -static PyObject * -bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes); - +PyDoc_STRVAR(lstrip__doc__, +"B.lstrip([bytes]) -> bytearray\n\ +\n\ +Strip leading bytes contained in the argument\n\ +and return the result as a new bytearray.\n\ +If the argument is omitted, strip leading ASCII whitespace."); static PyObject * bytearray_lstrip(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "lstrip", - 0, 1, - &bytes)) - goto exit; - return_value = bytearray_lstrip_impl(self, bytes); - -exit: - return return_value; -} - -static PyObject * -bytearray_lstrip_impl(PyByteArrayObject *self, PyObject *bytes) -/*[clinic end generated code: output=2599309808a9ec02 input=80843f975dd7c480]*/ -{ - Py_ssize_t left, right, mysize, byteslen; - char *myptr, *bytesptr; - Py_buffer vbytes; - - if (bytes == Py_None) { - bytesptr = "\t\n\r\f\v "; - byteslen = 6; + Py_ssize_t left, right, mysize, argsize; + char *myptr, *argptr; + PyObject *arg = Py_None; + Py_buffer varg; + if (!PyArg_ParseTuple(args, "|O:lstrip", &arg)) + return NULL; + if (arg == Py_None) { + argptr = "\t\n\r\f\v "; + argsize = 6; } else { - if (_getbuffer(bytes, &vbytes) < 0) + if (_getbuffer(arg, &varg) < 0) return NULL; - bytesptr = (char *) vbytes.buf; - byteslen = vbytes.len; + argptr = (char *) varg.buf; + argsize = varg.len; } myptr = PyByteArray_AS_STRING(self); mysize = Py_SIZE(self); - left = lstrip_helper(myptr, mysize, bytesptr, byteslen); + left = lstrip_helper(myptr, mysize, argptr, argsize); right = mysize; - if (bytes != Py_None) - PyBuffer_Release(&vbytes); + if (arg != Py_None) + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(myptr + left, right - left); } -/*[clinic input] -bytearray.rstrip - - bytes: object = None - / - -Strip trailing bytes contained in the argument. - -If the argument is omitted or None, strip trailing ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_rstrip__doc__, -"rstrip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip trailing bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip trailing ASCII whitespace."); - -#define BYTEARRAY_RSTRIP_METHODDEF \ - {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, bytearray_rstrip__doc__}, - -static PyObject * -bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes); - +PyDoc_STRVAR(rstrip__doc__, +"B.rstrip([bytes]) -> bytearray\n\ +\n\ +Strip trailing bytes contained in the argument\n\ +and return the result as a new bytearray.\n\ +If the argument is omitted, strip trailing ASCII whitespace."); static PyObject * bytearray_rstrip(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "rstrip", - 0, 1, - &bytes)) - goto exit; - return_value = bytearray_rstrip_impl(self, bytes); - -exit: - return return_value; -} - -static PyObject * -bytearray_rstrip_impl(PyByteArrayObject *self, PyObject *bytes) -/*[clinic end generated code: output=b5ca6259f4f4f2a3 input=e728b994954cfd91]*/ -{ - Py_ssize_t right, mysize, byteslen; - char *myptr, *bytesptr; - Py_buffer vbytes; - - if (bytes == Py_None) { - bytesptr = "\t\n\r\f\v "; - byteslen = 6; + Py_ssize_t right, mysize, argsize; + char *myptr, *argptr; + PyObject *arg = Py_None; + Py_buffer varg; + if (!PyArg_ParseTuple(args, "|O:rstrip", &arg)) + return NULL; + if (arg == Py_None) { + argptr = "\t\n\r\f\v "; + argsize = 6; } else { - if (_getbuffer(bytes, &vbytes) < 0) + if (_getbuffer(arg, &varg) < 0) return NULL; - bytesptr = (char *) vbytes.buf; - byteslen = vbytes.len; + argptr = (char *) varg.buf; + argsize = varg.len; } myptr = PyByteArray_AS_STRING(self); mysize = Py_SIZE(self); - right = rstrip_helper(myptr, mysize, bytesptr, byteslen); - if (bytes != Py_None) - PyBuffer_Release(&vbytes); + right = rstrip_helper(myptr, mysize, argptr, argsize); + if (arg != Py_None) + PyBuffer_Release(&varg); return PyByteArray_FromStringAndSize(myptr, right); } -/*[clinic input] -bytearray.decode - - encoding: str(c_default="NULL") = 'utf-8' - The encoding with which to decode the bytearray. - errors: str(c_default="NULL") = 'strict' - The error handling scheme to use for the handling of decoding errors. - The default is 'strict' meaning that decoding errors raise a - UnicodeDecodeError. Other possible values are 'ignore' and 'replace' - as well as any other name registered with codecs.register_error that - can handle UnicodeDecodeErrors. - -Decode the bytearray using the codec registered for encoding. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_decode__doc__, -"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" -"--\n" -"\n" -"Decode the bytearray using the codec registered for encoding.\n" -"\n" -" encoding\n" -" The encoding with which to decode the bytearray.\n" -" errors\n" -" The error handling scheme to use for the handling of decoding errors.\n" -" The default is \'strict\' meaning that decoding errors raise a\n" -" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" -" as well as any other name registered with codecs.register_error that\n" -" can handle UnicodeDecodeErrors."); - -#define BYTEARRAY_DECODE_METHODDEF \ - {"decode", (PyCFunction)bytearray_decode, METH_VARARGS|METH_KEYWORDS, bytearray_decode__doc__}, +PyDoc_STRVAR(decode_doc, +"B.decode(encoding='utf-8', errors='strict') -> str\n\ +\n\ +Decode B using the codec registered for encoding. Default encoding\n\ +is 'utf-8'. errors may be given to set a different error\n\ +handling scheme. Default is 'strict' meaning that encoding errors raise\n\ +a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\ +as well as any other name registered with codecs.register_error that is\n\ +able to handle UnicodeDecodeErrors."); static PyObject * -bytearray_decode_impl(PyByteArrayObject *self, const char *encoding, const char *errors); - -static PyObject * -bytearray_decode(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) +bytearray_decode(PyObject *self, PyObject *args, PyObject *kwargs) { - PyObject *return_value = NULL; - static char *_keywords[] = {"encoding", "errors", NULL}; const char *encoding = NULL; const char *errors = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|ss:decode", _keywords, - &encoding, &errors)) - goto exit; - return_value = bytearray_decode_impl(self, encoding, errors); - -exit: - return return_value; -} - -static PyObject * -bytearray_decode_impl(PyByteArrayObject *self, const char *encoding, const char *errors) -/*[clinic end generated code: output=38b83681f1e38a6c input=f28d8f903020257b]*/ -{ + static char *kwlist[] = {"encoding", "errors", 0}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors)) + return NULL; if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); - return PyUnicode_FromEncodedObject((PyObject*)self, encoding, errors); + return PyUnicode_FromEncodedObject(self, encoding, errors); } PyDoc_STRVAR(alloc_doc, @@ -3281,92 +2615,48 @@ return PyLong_FromSsize_t(self->ob_alloc); } -/*[clinic input] -bytearray.join - - iterable_of_bytes: object - / - -Concatenate any number of bytes/bytearray objects. - -The bytearray whose method is called is inserted in between each pair. - -The result is returned as a new bytearray object. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_join__doc__, -"join($self, iterable_of_bytes, /)\n" -"--\n" -"\n" -"Concatenate any number of bytes/bytearray objects.\n" -"\n" -"The bytearray whose method is called is inserted in between each pair.\n" -"\n" -"The result is returned as a new bytearray object."); - -#define BYTEARRAY_JOIN_METHODDEF \ - {"join", (PyCFunction)bytearray_join, METH_O, bytearray_join__doc__}, +PyDoc_STRVAR(join_doc, +"B.join(iterable_of_bytes) -> bytearray\n\ +\n\ +Concatenate any number of bytes/bytearray objects, with B\n\ +in between each pair, and return the result as a new bytearray."); static PyObject * -bytearray_join(PyByteArrayObject *self, PyObject *iterable_of_bytes) -/*[clinic end generated code: output=544e7430032dfdf4 input=aba6b1f9b30fcb8e]*/ +bytearray_join(PyObject *self, PyObject *iterable) { - return stringlib_bytes_join((PyObject*)self, iterable_of_bytes); + return stringlib_bytes_join(self, iterable); } -/*[clinic input] -bytearray.splitlines - - keepends: int(py_default="False") = 0 - -Return a list of the lines in the bytearray, breaking at line boundaries. - -Line breaks are not included in the resulting list unless keepends is given and -true. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_splitlines__doc__, -"splitlines($self, /, keepends=False)\n" -"--\n" -"\n" -"Return a list of the lines in the bytearray, breaking at line boundaries.\n" -"\n" -"Line breaks are not included in the resulting list unless keepends is given and\n" -"true."); - -#define BYTEARRAY_SPLITLINES_METHODDEF \ - {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS|METH_KEYWORDS, bytearray_splitlines__doc__}, - -static PyObject * -bytearray_splitlines_impl(PyByteArrayObject *self, int keepends); - -static PyObject * -bytearray_splitlines(PyByteArrayObject *self, PyObject *args, PyObject *kwargs) +PyDoc_STRVAR(splitlines__doc__, +"B.splitlines([keepends]) -> list of lines\n\ +\n\ +Return a list of the lines in B, breaking at line boundaries.\n\ +Line breaks are not included in the resulting list unless keepends\n\ +is given and true."); + +static PyObject* +bytearray_splitlines(PyObject *self, PyObject *args, PyObject *kwds) { - PyObject *return_value = NULL; - static char *_keywords[] = {"keepends", NULL}; + static char *kwlist[] = {"keepends", 0}; int keepends = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|i:splitlines", _keywords, - &keepends)) - goto exit; - return_value = bytearray_splitlines_impl(self, keepends); - -exit: - return return_value; -} - -static PyObject * -bytearray_splitlines_impl(PyByteArrayObject *self, int keepends) -/*[clinic end generated code: output=a837fd0512ad46ff input=36f0b25bc792f6c0]*/ -{ + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines", + kwlist, &keepends)) + return NULL; + return stringlib_splitlines( (PyObject*) self, PyByteArray_AS_STRING(self), PyByteArray_GET_SIZE(self), keepends ); } +PyDoc_STRVAR(fromhex_doc, +"bytearray.fromhex(string) -> bytearray (static method)\n\ +\n\ +Create a bytearray object from a string of hexadecimal numbers.\n\ +Spaces between two numbers are accepted.\n\ +Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef')."); + static int hex_digit_to_int(Py_UCS4 c) { @@ -3383,68 +2673,24 @@ return -1; } -/*[clinic input] -@classmethod -bytearray.fromhex - - cls: self(type="PyObject*") - string: unicode - / - -Create a bytearray object from a string of hexadecimal numbers. - -Spaces between two numbers are accepted. -Example: bytearray.fromhex('B9 01EF') -> bytearray(b'\\xb9\\x01\\xef') -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_fromhex__doc__, -"fromhex($type, string, /)\n" -"--\n" -"\n" -"Create a bytearray object from a string of hexadecimal numbers.\n" -"\n" -"Spaces between two numbers are accepted.\n" -"Example: bytearray.fromhex(\'B9 01EF\') -> bytearray(b\'\\\\xb9\\\\x01\\\\xef\')"); - -#define BYTEARRAY_FROMHEX_METHODDEF \ - {"fromhex", (PyCFunction)bytearray_fromhex, METH_VARARGS|METH_CLASS, bytearray_fromhex__doc__}, - static PyObject * -bytearray_fromhex_impl(PyObject*cls, PyObject *string); - -static PyObject * -bytearray_fromhex(PyTypeObject *cls, PyObject *args) +bytearray_fromhex(PyObject *cls, PyObject *args) { - PyObject *return_value = NULL; - PyObject *string; - - if (!PyArg_ParseTuple(args, - "U:fromhex", - &string)) - goto exit; - return_value = bytearray_fromhex_impl((PyObject*)cls, string); - -exit: - return return_value; -} - -static PyObject * -bytearray_fromhex_impl(PyObject*cls, PyObject *string) -/*[clinic end generated code: output=adc3c804a74e56d4 input=907bbd2d34d9367a]*/ -{ - PyObject *newbytes; + PyObject *newbytes, *hexobj; char *buf; Py_ssize_t hexlen, byteslen, i, j; int top, bot; void *data; unsigned int kind; - assert(PyUnicode_Check(string)); - if (PyUnicode_READY(string)) + if (!PyArg_ParseTuple(args, "U:fromhex", &hexobj)) return NULL; - kind = PyUnicode_KIND(string); - data = PyUnicode_DATA(string); - hexlen = PyUnicode_GET_LENGTH(string); + assert(PyUnicode_Check(hexobj)); + if (PyUnicode_READY(hexobj)) + return NULL; + kind = PyUnicode_KIND(hexobj); + data = PyUnicode_DATA(hexobj); + hexlen = PyUnicode_GET_LENGTH(hexobj); byteslen = hexlen/2; /* This overestimates if there are spaces */ newbytes = PyByteArray_FromStringAndSize(NULL, byteslen); @@ -3512,113 +2758,33 @@ } } -/*[clinic input] -bytearray.__reduce__ as bytearray_reduce - - self: self(type="PyByteArrayObject *") - -Return state information for pickling. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_reduce__doc__, -"__reduce__($self, /)\n" -"--\n" -"\n" -"Return state information for pickling."); - -#define BYTEARRAY_REDUCE_METHODDEF \ - {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, bytearray_reduce__doc__}, +PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); static PyObject * -bytearray_reduce_impl(PyByteArrayObject *self); - -static PyObject * -bytearray_reduce(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytearray_reduce_impl(self); -} - -static PyObject * -bytearray_reduce_impl(PyByteArrayObject *self) -/*[clinic end generated code: output=b1b56fe87bf30fb0 input=fbb07de4d102a03a]*/ +bytearray_reduce(PyByteArrayObject *self) { return _common_reduce(self, 2); } -/*[clinic input] -bytearray.__reduce_ex__ as bytearray_reduce_ex - - self: self(type="PyByteArrayObject *") - proto: int = 0 - / - -Return state information for pickling. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_reduce_ex__doc__, -"__reduce_ex__($self, proto=0, /)\n" -"--\n" -"\n" -"Return state information for pickling."); - -#define BYTEARRAY_REDUCE_EX_METHODDEF \ - {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, bytearray_reduce_ex__doc__}, - -static PyObject * -bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto); +PyDoc_STRVAR(reduce_ex_doc, "Return state information for pickling."); static PyObject * bytearray_reduce_ex(PyByteArrayObject *self, PyObject *args) { - PyObject *return_value = NULL; int proto = 0; - if (!PyArg_ParseTuple(args, - "|i:__reduce_ex__", - &proto)) - goto exit; - return_value = bytearray_reduce_ex_impl(self, proto); - -exit: - return return_value; -} - -static PyObject * -bytearray_reduce_ex_impl(PyByteArrayObject *self, int proto) -/*[clinic end generated code: output=bbd9afb2f5953dc1 input=0e091a42ca6dbd91]*/ -{ + if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto)) + return NULL; + return _common_reduce(self, proto); } -/*[clinic input] -bytearray.__sizeof__ as bytearray_sizeof - - self: self(type="PyByteArrayObject *") - -Returns the size of the bytearray object in memory, in bytes. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytearray_sizeof__doc__, -"__sizeof__($self, /)\n" -"--\n" -"\n" -"Returns the size of the bytearray object in memory, in bytes."); - -#define BYTEARRAY_SIZEOF_METHODDEF \ - {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, bytearray_sizeof__doc__}, - +PyDoc_STRVAR(sizeof_doc, +"B.__sizeof__() -> int\n\ + \n\ +Returns the size of B in memory, in bytes"); static PyObject * -bytearray_sizeof_impl(PyByteArrayObject *self); - -static PyObject * -bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytearray_sizeof_impl(self); -} - -static PyObject * -bytearray_sizeof_impl(PyByteArrayObject *self) -/*[clinic end generated code: output=4a2254b0a85630c6 input=6b23d305362b462b]*/ +bytearray_sizeof(PyByteArrayObject *self) { Py_ssize_t res; @@ -3653,25 +2819,26 @@ static PyMethodDef bytearray_methods[] = { {"__alloc__", (PyCFunction)bytearray_alloc, METH_NOARGS, alloc_doc}, - BYTEARRAY_REDUCE_METHODDEF - BYTEARRAY_REDUCE_EX_METHODDEF - BYTEARRAY_SIZEOF_METHODDEF - BYTEARRAY_APPEND_METHODDEF + {"__reduce__", (PyCFunction)bytearray_reduce, METH_NOARGS, reduce_doc}, + {"__reduce_ex__", (PyCFunction)bytearray_reduce_ex, METH_VARARGS, reduce_ex_doc}, + {"__sizeof__", (PyCFunction)bytearray_sizeof, METH_NOARGS, sizeof_doc}, + {"append", (PyCFunction)bytearray_append, METH_O, append__doc__}, {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, - BYTEARRAY_CLEAR_METHODDEF - BYTEARRAY_COPY_METHODDEF + {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, clear__doc__}, + {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, copy__doc__}, {"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__}, - BYTEARRAY_DECODE_METHODDEF + {"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc}, {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS, expandtabs__doc__}, - BYTEARRAY_EXTEND_METHODDEF + {"extend", (PyCFunction)bytearray_extend, METH_O, extend__doc__}, {"find", (PyCFunction)bytearray_find, METH_VARARGS, find__doc__}, - BYTEARRAY_FROMHEX_METHODDEF + {"fromhex", (PyCFunction)bytearray_fromhex, METH_VARARGS|METH_CLASS, + fromhex_doc}, {"index", (PyCFunction)bytearray_index, METH_VARARGS, index__doc__}, - BYTEARRAY_INSERT_METHODDEF + {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, insert__doc__}, {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, @@ -3686,31 +2853,34 @@ _Py_istitle__doc__}, {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, - BYTEARRAY_JOIN_METHODDEF + {"join", (PyCFunction)bytearray_join, METH_O, join_doc}, {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__}, {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, - BYTEARRAY_LSTRIP_METHODDEF - BYTEARRAY_MAKETRANS_METHODDEF - BYTEARRAY_PARTITION_METHODDEF - BYTEARRAY_POP_METHODDEF - BYTEARRAY_REMOVE_METHODDEF - BYTEARRAY_REPLACE_METHODDEF - BYTEARRAY_REVERSE_METHODDEF + {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, lstrip__doc__}, + {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, + _Py_maketrans__doc__}, + {"partition", (PyCFunction)bytearray_partition, METH_O, partition__doc__}, + {"pop", (PyCFunction)bytearray_pop, METH_VARARGS, pop__doc__}, + {"remove", (PyCFunction)bytearray_remove, METH_O, remove__doc__}, + {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, replace__doc__}, + {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, reverse__doc__}, {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, rfind__doc__}, {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, rindex__doc__}, {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, - BYTEARRAY_RPARTITION_METHODDEF - BYTEARRAY_RSPLIT_METHODDEF - BYTEARRAY_RSTRIP_METHODDEF - BYTEARRAY_SPLIT_METHODDEF - BYTEARRAY_SPLITLINES_METHODDEF + {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, rpartition__doc__}, + {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__}, + {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__}, + {"split", (PyCFunction)bytearray_split, METH_VARARGS | METH_KEYWORDS, split__doc__}, + {"splitlines", (PyCFunction)bytearray_splitlines, + METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS , startswith__doc__}, - BYTEARRAY_STRIP_METHODDEF + {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, strip__doc__}, {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__}, - BYTEARRAY_TRANSLATE_METHODDEF + {"translate", (PyCFunction)bytearray_translate, METH_VARARGS, + translate__doc__}, {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__}, {NULL} @@ -3871,7 +3041,7 @@ {"__length_hint__", (PyCFunction)bytearrayiter_length_hint, METH_NOARGS, length_hint_doc}, {"__reduce__", (PyCFunction)bytearrayiter_reduce, METH_NOARGS, - bytearray_reduce__doc__}, + reduce_doc}, {"__setstate__", (PyCFunction)bytearrayiter_setstate, METH_O, setstate_doc}, {NULL, NULL} /* sentinel */ diff -r 79e469ae13b7 -r 01438f18ee18 Objects/bytes_methods.c --- a/Objects/bytes_methods.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/bytes_methods.c Fri Jul 25 11:39:11 2014 -0400 @@ -382,9 +382,9 @@ } PyObject * -_Py_bytes_maketrans(PyObject *frm, PyObject *to) +_Py_bytes_maketrans(PyObject *args) { - PyObject *res = NULL; + PyObject *frm, *to, *res = NULL; Py_buffer bfrm, bto; Py_ssize_t i; char *p; @@ -392,6 +392,8 @@ bfrm.len = -1; bto.len = -1; + if (!PyArg_ParseTuple(args, "OO:maketrans", &frm, &to)) + return NULL; if (_getbuffer(frm, &bfrm) < 0) return NULL; if (_getbuffer(to, &bto) < 0) diff -r 79e469ae13b7 -r 01438f18ee18 Objects/bytesobject.c --- a/Objects/bytesobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/bytesobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -7,11 +7,6 @@ #include "bytes_methods.h" #include -/*[clinic input] -class bytes "PyBytesObject*" "&PyBytes_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=1a1d9102afc1b00c]*/ - static Py_ssize_t _getbuffer(PyObject *obj, Py_buffer *view) { @@ -999,7 +994,7 @@ } else { PyErr_Format(PyExc_TypeError, - "byte indices must be integers or slices, not %.200s", + "byte indices must be integers, not %.200s", Py_TYPE(item)->tp_name); return NULL; } @@ -1039,72 +1034,37 @@ #define RIGHTSTRIP 1 #define BOTHSTRIP 2 -/*[clinic input] -bytes.split - - sep: object = None - The delimiter according which to split the bytes. - None (the default value) means split on ASCII whitespace characters - (space, tab, return, newline, formfeed, vertical tab). - maxsplit: Py_ssize_t = -1 - Maximum number of splits to do. - -1 (the default value) means no limit. - -Return a list of the sections in the bytes, using sep as the delimiter. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_split__doc__, -"split($self, /, sep=None, maxsplit=-1)\n" -"--\n" -"\n" -"Return a list of the sections in the bytes, using sep as the delimiter.\n" -"\n" -" sep\n" -" The delimiter according which to split the bytes.\n" -" None (the default value) means split on ASCII whitespace characters\n" -" (space, tab, return, newline, formfeed, vertical tab).\n" -" maxsplit\n" -" Maximum number of splits to do.\n" -" -1 (the default value) means no limit."); - -#define BYTES_SPLIT_METHODDEF \ - {"split", (PyCFunction)bytes_split, METH_VARARGS|METH_KEYWORDS, bytes_split__doc__}, +/* Arrays indexed by above */ +static const char *stripformat[] = {"|O:lstrip", "|O:rstrip", "|O:strip"}; + +#define STRIPNAME(i) (stripformat[i]+3) + +PyDoc_STRVAR(split__doc__, +"B.split(sep=None, maxsplit=-1) -> list of bytes\n\ +\n\ +Return a list of the sections in B, using sep as the delimiter.\n\ +If sep is not specified or is None, B is split on ASCII whitespace\n\ +characters (space, tab, return, newline, formfeed, vertical tab).\n\ +If maxsplit is given, at most maxsplit splits are done."); static PyObject * -bytes_split_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit); - -static PyObject * -bytes_split(PyBytesObject*self, PyObject *args, PyObject *kwargs) +bytes_split(PyBytesObject *self, PyObject *args, PyObject *kwds) { - PyObject *return_value = NULL; - static char *_keywords[] = {"sep", "maxsplit", NULL}; - PyObject *sep = Py_None; + static char *kwlist[] = {"sep", "maxsplit", 0}; + Py_ssize_t len = PyBytes_GET_SIZE(self), n; Py_ssize_t maxsplit = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|On:split", _keywords, - &sep, &maxsplit)) - goto exit; - return_value = bytes_split_impl(self, sep, maxsplit); - -exit: - return return_value; -} - -static PyObject * -bytes_split_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=c80a47afdd505975 input=8b809b39074abbfa]*/ -{ - Py_ssize_t len = PyBytes_GET_SIZE(self), n; const char *s = PyBytes_AS_STRING(self), *sub; Py_buffer vsub; - PyObject *list; - + PyObject *list, *subobj = Py_None; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:split", + kwlist, &subobj, &maxsplit)) + return NULL; if (maxsplit < 0) maxsplit = PY_SSIZE_T_MAX; - if (sep == Py_None) + if (subobj == Py_None) return stringlib_split_whitespace((PyObject*) self, s, len, maxsplit); - if (_getbuffer(sep, &vsub) < 0) + if (_getbuffer(subobj, &vsub) < 0) return NULL; sub = vsub.buf; n = vsub.len; @@ -1114,176 +1074,89 @@ return list; } -/*[clinic input] -bytes.partition - - self: self(type="PyBytesObject *") - sep: object - / - -Partition the bytes into three parts using the given separator. - -This will search for the separator sep in the bytes. If the separator is found, -returns a 3-tuple containing the part before the separator, the separator -itself, and the part after it. - -If the separator is not found, returns a 3-tuple containing the original bytes -object and two empty bytes objects. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_partition__doc__, -"partition($self, sep, /)\n" -"--\n" -"\n" -"Partition the bytes into three parts using the given separator.\n" -"\n" -"This will search for the separator sep in the bytes. If the separator is found,\n" -"returns a 3-tuple containing the part before the separator, the separator\n" -"itself, and the part after it.\n" -"\n" -"If the separator is not found, returns a 3-tuple containing the original bytes\n" -"object and two empty bytes objects."); - -#define BYTES_PARTITION_METHODDEF \ - {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__}, +PyDoc_STRVAR(partition__doc__, +"B.partition(sep) -> (head, sep, tail)\n\ +\n\ +Search for the separator sep in B, and return the part before it,\n\ +the separator itself, and the part after it. If the separator is not\n\ +found, returns B and two empty bytes objects."); static PyObject * -bytes_partition(PyBytesObject *self, PyObject *sep) -/*[clinic end generated code: output=b41e119c873c08bc input=6c5b9dcc5a9fd62e]*/ +bytes_partition(PyBytesObject *self, PyObject *sep_obj) { - const char *sep_chars; + const char *sep; Py_ssize_t sep_len; - if (PyBytes_Check(sep)) { - sep_chars = PyBytes_AS_STRING(sep); - sep_len = PyBytes_GET_SIZE(sep); + if (PyBytes_Check(sep_obj)) { + sep = PyBytes_AS_STRING(sep_obj); + sep_len = PyBytes_GET_SIZE(sep_obj); } - else if (PyObject_AsCharBuffer(sep, &sep_chars, &sep_len)) + else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len)) return NULL; return stringlib_partition( (PyObject*) self, PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), - sep, sep_chars, sep_len + sep_obj, sep, sep_len ); } -/*[clinic input] -bytes.rpartition - - self: self(type="PyBytesObject *") - sep: object - / - -Partition the bytes into three parts using the given separator. - -This will search for the separator sep in the bytes, starting and the end. If -the separator is found, returns a 3-tuple containing the part before the -separator, the separator itself, and the part after it. - -If the separator is not found, returns a 3-tuple containing two empty bytes -objects and the original bytes object. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_rpartition__doc__, -"rpartition($self, sep, /)\n" -"--\n" -"\n" -"Partition the bytes into three parts using the given separator.\n" -"\n" -"This will search for the separator sep in the bytes, starting and the end. If\n" -"the separator is found, returns a 3-tuple containing the part before the\n" -"separator, the separator itself, and the part after it.\n" -"\n" -"If the separator is not found, returns a 3-tuple containing two empty bytes\n" -"objects and the original bytes object."); - -#define BYTES_RPARTITION_METHODDEF \ - {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__}, +PyDoc_STRVAR(rpartition__doc__, +"B.rpartition(sep) -> (head, sep, tail)\n\ +\n\ +Search for the separator sep in B, starting at the end of B,\n\ +and return the part before it, the separator itself, and the\n\ +part after it. If the separator is not found, returns two empty\n\ +bytes objects and B."); static PyObject * -bytes_rpartition(PyBytesObject *self, PyObject *sep) -/*[clinic end generated code: output=3a620803657196ee input=79bc2932e78e5ce0]*/ +bytes_rpartition(PyBytesObject *self, PyObject *sep_obj) { - const char *sep_chars; + const char *sep; Py_ssize_t sep_len; - if (PyBytes_Check(sep)) { - sep_chars = PyBytes_AS_STRING(sep); - sep_len = PyBytes_GET_SIZE(sep); + if (PyBytes_Check(sep_obj)) { + sep = PyBytes_AS_STRING(sep_obj); + sep_len = PyBytes_GET_SIZE(sep_obj); } - else if (PyObject_AsCharBuffer(sep, &sep_chars, &sep_len)) + else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len)) return NULL; return stringlib_rpartition( (PyObject*) self, PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), - sep, sep_chars, sep_len + sep_obj, sep, sep_len ); } -/*[clinic input] -bytes.rsplit = bytes.split - -Return a list of the sections in the bytes, using sep as the delimiter. - -Splitting is done starting at the end of the bytes and working to the front. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_rsplit__doc__, -"rsplit($self, /, sep=None, maxsplit=-1)\n" -"--\n" -"\n" -"Return a list of the sections in the bytes, using sep as the delimiter.\n" -"\n" -" sep\n" -" The delimiter according which to split the bytes.\n" -" None (the default value) means split on ASCII whitespace characters\n" -" (space, tab, return, newline, formfeed, vertical tab).\n" -" maxsplit\n" -" Maximum number of splits to do.\n" -" -1 (the default value) means no limit.\n" -"\n" -"Splitting is done starting at the end of the bytes and working to the front."); - -#define BYTES_RSPLIT_METHODDEF \ - {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS|METH_KEYWORDS, bytes_rsplit__doc__}, +PyDoc_STRVAR(rsplit__doc__, +"B.rsplit(sep=None, maxsplit=-1) -> list of bytes\n\ +\n\ +Return a list of the sections in B, using sep as the delimiter,\n\ +starting at the end of B and working to the front.\n\ +If sep is not given, B is split on ASCII whitespace characters\n\ +(space, tab, return, newline, formfeed, vertical tab).\n\ +If maxsplit is given, at most maxsplit splits are done."); + static PyObject * -bytes_rsplit_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit); - -static PyObject * -bytes_rsplit(PyBytesObject*self, PyObject *args, PyObject *kwargs) +bytes_rsplit(PyBytesObject *self, PyObject *args, PyObject *kwds) { - PyObject *return_value = NULL; - static char *_keywords[] = {"sep", "maxsplit", NULL}; - PyObject *sep = Py_None; + static char *kwlist[] = {"sep", "maxsplit", 0}; + Py_ssize_t len = PyBytes_GET_SIZE(self), n; Py_ssize_t maxsplit = -1; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|On:rsplit", _keywords, - &sep, &maxsplit)) - goto exit; - return_value = bytes_rsplit_impl(self, sep, maxsplit); - -exit: - return return_value; -} - -static PyObject * -bytes_rsplit_impl(PyBytesObject*self, PyObject *sep, Py_ssize_t maxsplit) -/*[clinic end generated code: output=f86feddedbd7b26d input=0f86c9f28f7d7b7b]*/ -{ - Py_ssize_t len = PyBytes_GET_SIZE(self), n; const char *s = PyBytes_AS_STRING(self), *sub; Py_buffer vsub; - PyObject *list; - + PyObject *list, *subobj = Py_None; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|On:rsplit", + kwlist, &subobj, &maxsplit)) + return NULL; if (maxsplit < 0) maxsplit = PY_SSIZE_T_MAX; - if (sep == Py_None) + if (subobj == Py_None) return stringlib_rsplit_whitespace((PyObject*) self, s, len, maxsplit); - if (_getbuffer(sep, &vsub) < 0) + if (_getbuffer(subobj, &vsub) < 0) return NULL; sub = vsub.buf; n = vsub.len; @@ -1294,41 +1167,16 @@ } -/*[clinic input] -bytes.join - - iterable_of_bytes: object - / - -Concatenate any number of bytes objects. - -The bytes whose method is called is inserted in between each pair. - -The result is returned as a new bytes object. - -Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_join__doc__, -"join($self, iterable_of_bytes, /)\n" -"--\n" -"\n" -"Concatenate any number of bytes objects.\n" -"\n" -"The bytes whose method is called is inserted in between each pair.\n" -"\n" -"The result is returned as a new bytes object.\n" -"\n" -"Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'."); - -#define BYTES_JOIN_METHODDEF \ - {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__}, +PyDoc_STRVAR(join__doc__, +"B.join(iterable_of_bytes) -> bytes\n\ +\n\ +Concatenate any number of bytes objects, with B in between each pair.\n\ +Example: b'.'.join([b'ab', b'pq', b'rs']) -> b'ab.pq.rs'."); static PyObject * -bytes_join(PyBytesObject*self, PyObject *iterable_of_bytes) -/*[clinic end generated code: output=e541a14a8da97908 input=7fe377b95bd549d2]*/ +bytes_join(PyObject *self, PyObject *iterable) { - return stringlib_bytes_join((PyObject*)self, iterable_of_bytes); + return stringlib_bytes_join(self, iterable); } PyObject * @@ -1336,7 +1184,7 @@ { assert(sep != NULL && PyBytes_Check(sep)); assert(x != NULL); - return bytes_join((PyBytesObject*)sep, x); + return bytes_join(sep, x); } /* helper macro to fixup start/end slice values */ @@ -1547,159 +1395,62 @@ Py_LOCAL_INLINE(PyObject *) -do_argstrip(PyBytesObject *self, int striptype, PyObject *bytes) +do_argstrip(PyBytesObject *self, int striptype, PyObject *args) { - if (bytes != NULL && bytes != Py_None) { - return do_xstrip(self, striptype, bytes); + PyObject *sep = NULL; + + if (!PyArg_ParseTuple(args, stripformat[striptype], &sep)) + return NULL; + + if (sep != NULL && sep != Py_None) { + return do_xstrip(self, striptype, sep); } return do_strip(self, striptype); } -/*[clinic input] -bytes.strip - - self: self(type="PyBytesObject *") - bytes: object = None - / - -Strip leading and trailing bytes contained in the argument. - -If the argument is omitted or None, strip leading and trailing ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_strip__doc__, -"strip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip leading and trailing bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip leading and trailing ASCII whitespace."); - -#define BYTES_STRIP_METHODDEF \ - {"strip", (PyCFunction)bytes_strip, METH_VARARGS, bytes_strip__doc__}, - -static PyObject * -bytes_strip_impl(PyBytesObject *self, PyObject *bytes); - + +PyDoc_STRVAR(strip__doc__, +"B.strip([bytes]) -> bytes\n\ +\n\ +Strip leading and trailing bytes contained in the argument.\n\ +If the argument is omitted, strip leading and trailing ASCII whitespace."); static PyObject * bytes_strip(PyBytesObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "strip", - 0, 1, - &bytes)) - goto exit; - return_value = bytes_strip_impl(self, bytes); - -exit: - return return_value; + if (PyTuple_GET_SIZE(args) == 0) + return do_strip(self, BOTHSTRIP); /* Common case */ + else + return do_argstrip(self, BOTHSTRIP, args); } -static PyObject * -bytes_strip_impl(PyBytesObject *self, PyObject *bytes) -/*[clinic end generated code: output=c8234a599ba5ec35 input=37daa5fad1395d95]*/ -{ - return do_argstrip(self, BOTHSTRIP, bytes); -} - -/*[clinic input] -bytes.lstrip - - self: self(type="PyBytesObject *") - bytes: object = None - / - -Strip leading bytes contained in the argument. - -If the argument is omitted or None, strip leading ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_lstrip__doc__, -"lstrip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip leading bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip leading ASCII whitespace."); - -#define BYTES_LSTRIP_METHODDEF \ - {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, bytes_lstrip__doc__}, - -static PyObject * -bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes); - + +PyDoc_STRVAR(lstrip__doc__, +"B.lstrip([bytes]) -> bytes\n\ +\n\ +Strip leading bytes contained in the argument.\n\ +If the argument is omitted, strip leading ASCII whitespace."); static PyObject * bytes_lstrip(PyBytesObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "lstrip", - 0, 1, - &bytes)) - goto exit; - return_value = bytes_lstrip_impl(self, bytes); - -exit: - return return_value; + if (PyTuple_GET_SIZE(args) == 0) + return do_strip(self, LEFTSTRIP); /* Common case */ + else + return do_argstrip(self, LEFTSTRIP, args); } -static PyObject * -bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes) -/*[clinic end generated code: output=529e8511ab6f1115 input=88811b09dfbc2988]*/ -{ - return do_argstrip(self, LEFTSTRIP, bytes); -} - -/*[clinic input] -bytes.rstrip - - self: self(type="PyBytesObject *") - bytes: object = None - / - -Strip trailing bytes contained in the argument. - -If the argument is omitted or None, strip trailing ASCII whitespace. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_rstrip__doc__, -"rstrip($self, bytes=None, /)\n" -"--\n" -"\n" -"Strip trailing bytes contained in the argument.\n" -"\n" -"If the argument is omitted or None, strip trailing ASCII whitespace."); - -#define BYTES_RSTRIP_METHODDEF \ - {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, bytes_rstrip__doc__}, - -static PyObject * -bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes); - + +PyDoc_STRVAR(rstrip__doc__, +"B.rstrip([bytes]) -> bytes\n\ +\n\ +Strip trailing bytes contained in the argument.\n\ +If the argument is omitted, strip trailing ASCII whitespace."); static PyObject * bytes_rstrip(PyBytesObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *bytes = Py_None; - - if (!PyArg_UnpackTuple(args, "rstrip", - 0, 1, - &bytes)) - goto exit; - return_value = bytes_rstrip_impl(self, bytes); - -exit: - return return_value; -} - -static PyObject * -bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes) -/*[clinic end generated code: output=e98730bd133e6593 input=8f93c9cd361f0140]*/ -{ - return do_argstrip(self, RIGHTSTRIP, bytes); + if (PyTuple_GET_SIZE(args) == 0) + return do_strip(self, RIGHTSTRIP); /* Common case */ + else + return do_argstrip(self, RIGHTSTRIP, args); } @@ -1751,89 +1502,40 @@ } -/*[clinic input] -bytes.translate - - self: self(type="PyBytesObject *") - table: object - Translation table, which must be a bytes object of length 256. - [ - deletechars: object - ] - / - -Return a copy with each character mapped by the given translation table. - -All characters occurring in the optional argument deletechars are removed. -The remaining characters are mapped through the given translation table. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_translate__doc__, -"translate(table, [deletechars])\n" -"Return a copy with each character mapped by the given translation table.\n" -"\n" -" table\n" -" Translation table, which must be a bytes object of length 256.\n" -"\n" -"All characters occurring in the optional argument deletechars are removed.\n" -"The remaining characters are mapped through the given translation table."); - -#define BYTES_TRANSLATE_METHODDEF \ - {"translate", (PyCFunction)bytes_translate, METH_VARARGS, bytes_translate__doc__}, - -static PyObject * -bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1, PyObject *deletechars); +PyDoc_STRVAR(translate__doc__, +"B.translate(table[, deletechars]) -> bytes\n\ +\n\ +Return a copy of B, where all characters occurring in the\n\ +optional argument deletechars are removed, and the remaining\n\ +characters have been mapped through the given translation\n\ +table, which must be a bytes object of length 256."); static PyObject * bytes_translate(PyBytesObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *table; - int group_right_1 = 0; - PyObject *deletechars = NULL; - - switch (PyTuple_GET_SIZE(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O:translate", &table)) - goto exit; - break; - case 2: - if (!PyArg_ParseTuple(args, "OO:translate", &table, &deletechars)) - goto exit; - group_right_1 = 1; - break; - default: - PyErr_SetString(PyExc_TypeError, "bytes.translate requires 1 to 2 arguments"); - goto exit; - } - return_value = bytes_translate_impl(self, table, group_right_1, deletechars); - -exit: - return return_value; -} - -static PyObject * -bytes_translate_impl(PyBytesObject *self, PyObject *table, int group_right_1, PyObject *deletechars) -/*[clinic end generated code: output=f0f29a57f41df5d8 input=a90fad893c3c88d7]*/ -{ char *input, *output; - const char *table_chars; + const char *table; Py_ssize_t i, c, changed = 0; PyObject *input_obj = (PyObject*)self; - const char *output_start, *del_table_chars=NULL; + const char *output_start, *del_table=NULL; Py_ssize_t inlen, tablen, dellen = 0; PyObject *result; int trans_table[256]; - - if (PyBytes_Check(table)) { - table_chars = PyBytes_AS_STRING(table); - tablen = PyBytes_GET_SIZE(table); + PyObject *tableobj, *delobj = NULL; + + if (!PyArg_UnpackTuple(args, "translate", 1, 2, + &tableobj, &delobj)) + return NULL; + + if (PyBytes_Check(tableobj)) { + table = PyBytes_AS_STRING(tableobj); + tablen = PyBytes_GET_SIZE(tableobj); } - else if (table == Py_None) { - table_chars = NULL; + else if (tableobj == Py_None) { + table = NULL; tablen = 256; } - else if (PyObject_AsCharBuffer(table, &table_chars, &tablen)) + else if (PyObject_AsCharBuffer(tableobj, &table, &tablen)) return NULL; if (tablen != 256) { @@ -1842,16 +1544,16 @@ return NULL; } - if (deletechars != NULL) { - if (PyBytes_Check(deletechars)) { - del_table_chars = PyBytes_AS_STRING(deletechars); - dellen = PyBytes_GET_SIZE(deletechars); + if (delobj != NULL) { + if (PyBytes_Check(delobj)) { + del_table = PyBytes_AS_STRING(delobj); + dellen = PyBytes_GET_SIZE(delobj); } - else if (PyObject_AsCharBuffer(deletechars, &del_table_chars, &dellen)) + else if (PyObject_AsCharBuffer(delobj, &del_table, &dellen)) return NULL; } else { - del_table_chars = NULL; + del_table = NULL; dellen = 0; } @@ -1862,11 +1564,11 @@ output_start = output = PyBytes_AsString(result); input = PyBytes_AS_STRING(input_obj); - if (dellen == 0 && table_chars != NULL) { + if (dellen == 0 && table != NULL) { /* If no deletions are required, use faster code */ for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); - if (Py_CHARMASK((*output++ = table_chars[c])) != c) + if (Py_CHARMASK((*output++ = table[c])) != c) changed = 1; } if (changed || !PyBytes_CheckExact(input_obj)) @@ -1876,16 +1578,16 @@ return input_obj; } - if (table_chars == NULL) { + if (table == NULL) { for (i = 0; i < 256; i++) trans_table[i] = Py_CHARMASK(i); } else { for (i = 0; i < 256; i++) - trans_table[i] = Py_CHARMASK(table_chars[i]); + trans_table[i] = Py_CHARMASK(table[i]); } for (i = 0; i < dellen; i++) - trans_table[(int) Py_CHARMASK(del_table_chars[i])] = -1; + trans_table[(int) Py_CHARMASK(del_table[i])] = -1; for (i = inlen; --i >= 0; ) { c = Py_CHARMASK(*input++); @@ -1906,62 +1608,10 @@ } -/*[clinic input] - -@staticmethod -bytes.maketrans - - frm: object - to: object - / - -Return a translation table useable for the bytes or bytearray translate method. - -The returned table will be one where each byte in frm is mapped to the byte at -the same position in to. - -The bytes objects frm and to must be of the same length. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_maketrans__doc__, -"maketrans(frm, to, /)\n" -"--\n" -"\n" -"Return a translation table useable for the bytes or bytearray translate method.\n" -"\n" -"The returned table will be one where each byte in frm is mapped to the byte at\n" -"the same position in to.\n" -"\n" -"The bytes objects frm and to must be of the same length."); - -#define BYTES_MAKETRANS_METHODDEF \ - {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, bytes_maketrans__doc__}, - static PyObject * -bytes_maketrans_impl(PyObject *frm, PyObject *to); - -static PyObject * -bytes_maketrans(void *null, PyObject *args) +bytes_maketrans(PyObject *null, PyObject *args) { - PyObject *return_value = NULL; - PyObject *frm; - PyObject *to; - - if (!PyArg_UnpackTuple(args, "maketrans", - 2, 2, - &frm, &to)) - goto exit; - return_value = bytes_maketrans_impl(frm, to); - -exit: - return return_value; -} - -static PyObject * -bytes_maketrans_impl(PyObject *frm, PyObject *to) -/*[clinic end generated code: output=89a3c3556975e466 input=d204f680f85da382]*/ -{ - return _Py_bytes_maketrans(frm, to); + return _Py_bytes_maketrans(args); } /* find and count characters and substrings */ @@ -2456,84 +2106,41 @@ } } - -/*[clinic input] -bytes.replace - - old: object - new: object - count: Py_ssize_t = -1 - Maximum number of occurrences to replace. - -1 (the default value) means replace all occurrences. - / - -Return a copy with all occurrences of substring old replaced by new. - -If the optional argument count is given, only the first count occurrences are -replaced. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_replace__doc__, -"replace($self, old, new, count=-1, /)\n" -"--\n" -"\n" -"Return a copy with all occurrences of substring old replaced by new.\n" -"\n" -" count\n" -" Maximum number of occurrences to replace.\n" -" -1 (the default value) means replace all occurrences.\n" -"\n" -"If the optional argument count is given, only the first count occurrences are\n" -"replaced."); - -#define BYTES_REPLACE_METHODDEF \ - {"replace", (PyCFunction)bytes_replace, METH_VARARGS, bytes_replace__doc__}, +PyDoc_STRVAR(replace__doc__, +"B.replace(old, new[, count]) -> bytes\n\ +\n\ +Return a copy of B with all occurrences of subsection\n\ +old replaced by new. If the optional argument count is\n\ +given, only first count occurances are replaced."); static PyObject * -bytes_replace_impl(PyBytesObject*self, PyObject *old, PyObject *new, Py_ssize_t count); - -static PyObject * -bytes_replace(PyBytesObject*self, PyObject *args) +bytes_replace(PyBytesObject *self, PyObject *args) { - PyObject *return_value = NULL; - PyObject *old; - PyObject *new; Py_ssize_t count = -1; - - if (!PyArg_ParseTuple(args, - "OO|n:replace", - &old, &new, &count)) - goto exit; - return_value = bytes_replace_impl(self, old, new, count); - -exit: - return return_value; -} - -static PyObject * -bytes_replace_impl(PyBytesObject*self, PyObject *old, PyObject *new, Py_ssize_t count) -/*[clinic end generated code: output=14ce72f4f9cb91cf input=d3ac254ea50f4ac1]*/ -{ - const char *old_s, *new_s; - Py_ssize_t old_len, new_len; - - if (PyBytes_Check(old)) { - old_s = PyBytes_AS_STRING(old); - old_len = PyBytes_GET_SIZE(old); + PyObject *from, *to; + const char *from_s, *to_s; + Py_ssize_t from_len, to_len; + + if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count)) + return NULL; + + if (PyBytes_Check(from)) { + from_s = PyBytes_AS_STRING(from); + from_len = PyBytes_GET_SIZE(from); } - else if (PyObject_AsCharBuffer(old, &old_s, &old_len)) + else if (PyObject_AsCharBuffer(from, &from_s, &from_len)) return NULL; - if (PyBytes_Check(new)) { - new_s = PyBytes_AS_STRING(new); - new_len = PyBytes_GET_SIZE(new); + if (PyBytes_Check(to)) { + to_s = PyBytes_AS_STRING(to); + to_len = PyBytes_GET_SIZE(to); } - else if (PyObject_AsCharBuffer(new, &new_s, &new_len)) + else if (PyObject_AsCharBuffer(to, &to_s, &to_len)) return NULL; return (PyObject *)replace((PyBytesObject *) self, - old_s, old_len, - new_s, new_len, count); + from_s, from_len, + to_s, to_len, count); } /** End DALKE **/ @@ -2667,121 +2274,60 @@ } -/*[clinic input] -bytes.decode - - encoding: str(c_default="NULL") = 'utf-8' - The encoding with which to decode the bytes. - errors: str(c_default="NULL") = 'strict' - The error handling scheme to use for the handling of decoding errors. - The default is 'strict' meaning that decoding errors raise a - UnicodeDecodeError. Other possible values are 'ignore' and 'replace' - as well as any other name registered with codecs.register_error that - can handle UnicodeDecodeErrors. - -Decode the bytes using the codec registered for encoding. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_decode__doc__, -"decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n" -"--\n" -"\n" -"Decode the bytes using the codec registered for encoding.\n" -"\n" -" encoding\n" -" The encoding with which to decode the bytes.\n" -" errors\n" -" The error handling scheme to use for the handling of decoding errors.\n" -" The default is \'strict\' meaning that decoding errors raise a\n" -" UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n" -" as well as any other name registered with codecs.register_error that\n" -" can handle UnicodeDecodeErrors."); - -#define BYTES_DECODE_METHODDEF \ - {"decode", (PyCFunction)bytes_decode, METH_VARARGS|METH_KEYWORDS, bytes_decode__doc__}, +PyDoc_STRVAR(decode__doc__, +"B.decode(encoding='utf-8', errors='strict') -> str\n\ +\n\ +Decode B using the codec registered for encoding. Default encoding\n\ +is 'utf-8'. errors may be given to set a different error\n\ +handling scheme. Default is 'strict' meaning that encoding errors raise\n\ +a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\ +as well as any other name registerd with codecs.register_error that is\n\ +able to handle UnicodeDecodeErrors."); static PyObject * -bytes_decode_impl(PyBytesObject*self, const char *encoding, const char *errors); - -static PyObject * -bytes_decode(PyBytesObject*self, PyObject *args, PyObject *kwargs) +bytes_decode(PyObject *self, PyObject *args, PyObject *kwargs) { - PyObject *return_value = NULL; - static char *_keywords[] = {"encoding", "errors", NULL}; const char *encoding = NULL; const char *errors = NULL; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|ss:decode", _keywords, - &encoding, &errors)) - goto exit; - return_value = bytes_decode_impl(self, encoding, errors); - -exit: - return return_value; + static char *kwlist[] = {"encoding", "errors", 0}; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors)) + return NULL; + return PyUnicode_FromEncodedObject(self, encoding, errors); } -static PyObject * -bytes_decode_impl(PyBytesObject*self, const char *encoding, const char *errors) -/*[clinic end generated code: output=61a80290bbfce696 input=958174769d2a40ca]*/ + +PyDoc_STRVAR(splitlines__doc__, +"B.splitlines([keepends]) -> list of lines\n\ +\n\ +Return a list of the lines in B, breaking at line boundaries.\n\ +Line breaks are not included in the resulting list unless keepends\n\ +is given and true."); + +static PyObject* +bytes_splitlines(PyObject *self, PyObject *args, PyObject *kwds) { - return PyUnicode_FromEncodedObject((PyObject*)self, encoding, errors); -} - - -/*[clinic input] -bytes.splitlines - - keepends: int(py_default="False") = 0 - -Return a list of the lines in the bytes, breaking at line boundaries. - -Line breaks are not included in the resulting list unless keepends is given and -true. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_splitlines__doc__, -"splitlines($self, /, keepends=False)\n" -"--\n" -"\n" -"Return a list of the lines in the bytes, breaking at line boundaries.\n" -"\n" -"Line breaks are not included in the resulting list unless keepends is given and\n" -"true."); - -#define BYTES_SPLITLINES_METHODDEF \ - {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS|METH_KEYWORDS, bytes_splitlines__doc__}, - -static PyObject * -bytes_splitlines_impl(PyBytesObject*self, int keepends); - -static PyObject * -bytes_splitlines(PyBytesObject*self, PyObject *args, PyObject *kwargs) -{ - PyObject *return_value = NULL; - static char *_keywords[] = {"keepends", NULL}; + static char *kwlist[] = {"keepends", 0}; int keepends = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|i:splitlines", _keywords, - &keepends)) - goto exit; - return_value = bytes_splitlines_impl(self, keepends); - -exit: - return return_value; -} - -static PyObject * -bytes_splitlines_impl(PyBytesObject*self, int keepends) -/*[clinic end generated code: output=79da057d05d126de input=ddb93e3351080c8c]*/ -{ + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines", + kwlist, &keepends)) + return NULL; + return stringlib_splitlines( (PyObject*) self, PyBytes_AS_STRING(self), PyBytes_GET_SIZE(self), keepends ); } + +PyDoc_STRVAR(fromhex_doc, +"bytes.fromhex(string) -> bytes\n\ +\n\ +Create a bytes object from a string of hexadecimal numbers.\n\ +Spaces between two numbers are accepted.\n\ +Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'."); + static int hex_digit_to_int(Py_UCS4 c) { @@ -2798,67 +2344,24 @@ return -1; } -/*[clinic input] -@classmethod -bytes.fromhex - - string: unicode - / - -Create a bytes object from a string of hexadecimal numbers. - -Spaces between two numbers are accepted. -Example: bytes.fromhex('B9 01EF') -> b'\\xb9\\x01\\xef'. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_fromhex__doc__, -"fromhex($type, string, /)\n" -"--\n" -"\n" -"Create a bytes object from a string of hexadecimal numbers.\n" -"\n" -"Spaces between two numbers are accepted.\n" -"Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'."); - -#define BYTES_FROMHEX_METHODDEF \ - {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS, bytes_fromhex__doc__}, - static PyObject * -bytes_fromhex_impl(PyTypeObject *type, PyObject *string); - -static PyObject * -bytes_fromhex(PyTypeObject *type, PyObject *args) +bytes_fromhex(PyObject *cls, PyObject *args) { - PyObject *return_value = NULL; - PyObject *string; - - if (!PyArg_ParseTuple(args, - "U:fromhex", - &string)) - goto exit; - return_value = bytes_fromhex_impl(type, string); - -exit: - return return_value; -} - -static PyObject * -bytes_fromhex_impl(PyTypeObject *type, PyObject *string) -/*[clinic end generated code: output=09e6cbef56cbbb65 input=bf4d1c361670acd3]*/ -{ - PyObject *newstring; + PyObject *newstring, *hexobj; char *buf; Py_ssize_t hexlen, byteslen, i, j; int top, bot; void *data; unsigned int kind; - assert(PyUnicode_Check(string)); - if (PyUnicode_READY(string)) + if (!PyArg_ParseTuple(args, "U:fromhex", &hexobj)) return NULL; - kind = PyUnicode_KIND(string); - data = PyUnicode_DATA(string); - hexlen = PyUnicode_GET_LENGTH(string); + assert(PyUnicode_Check(hexobj)); + if (PyUnicode_READY(hexobj)) + return NULL; + kind = PyUnicode_KIND(hexobj); + data = PyUnicode_DATA(hexobj); + hexlen = PyUnicode_GET_LENGTH(hexobj); byteslen = hexlen/2; /* This overestimates if there are spaces */ newstring = PyBytes_FromStringAndSize(NULL, byteslen); @@ -2890,38 +2393,14 @@ return NULL; } -/*[clinic input] -bytes.__sizeof__ as bytes_sizeof - - self: self(type="PyBytesObject *") - -Returns the size of the bytes object in memory, in bytes. -[clinic start generated code]*/ - -PyDoc_STRVAR(bytes_sizeof__doc__, -"__sizeof__($self, /)\n" -"--\n" -"\n" -"Returns the size of the bytes object in memory, in bytes."); - -#define BYTES_SIZEOF_METHODDEF \ - {"__sizeof__", (PyCFunction)bytes_sizeof, METH_NOARGS, bytes_sizeof__doc__}, +PyDoc_STRVAR(sizeof__doc__, +"B.__sizeof__() -> size of B in memory, in bytes"); static PyObject * -bytes_sizeof_impl(PyBytesObject *self); - -static PyObject * -bytes_sizeof(PyBytesObject *self, PyObject *Py_UNUSED(ignored)) -{ - return bytes_sizeof_impl(self); -} - -static PyObject * -bytes_sizeof_impl(PyBytesObject *self) -/*[clinic end generated code: output=44933279343f24ae input=bee4c64bb42078ed]*/ +bytes_sizeof(PyBytesObject *v) { Py_ssize_t res; - res = PyBytesObject_SIZE + Py_SIZE(self) * Py_TYPE(self)->tp_itemsize; + res = PyBytesObject_SIZE + Py_SIZE(v) * Py_TYPE(v)->tp_itemsize; return PyLong_FromSsize_t(res); } @@ -2940,13 +2419,14 @@ _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__}, - BYTES_DECODE_METHODDEF + {"decode", (PyCFunction)bytes_decode, METH_VARARGS | METH_KEYWORDS, decode__doc__}, {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS, expandtabs__doc__}, {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__}, - BYTES_FROMHEX_METHODDEF + {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS, + fromhex_doc}, {"index", (PyCFunction)bytes_index, METH_VARARGS, index__doc__}, {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, @@ -2962,31 +2442,36 @@ _Py_istitle__doc__}, {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, - BYTES_JOIN_METHODDEF + {"join", (PyCFunction)bytes_join, METH_O, join__doc__}, {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__}, {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, - BYTES_LSTRIP_METHODDEF - BYTES_MAKETRANS_METHODDEF - BYTES_PARTITION_METHODDEF - BYTES_REPLACE_METHODDEF + {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__}, + {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, + _Py_maketrans__doc__}, + {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__}, + {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__}, {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__}, {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__}, {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, - BYTES_RPARTITION_METHODDEF - BYTES_RSPLIT_METHODDEF - BYTES_RSTRIP_METHODDEF - BYTES_SPLIT_METHODDEF - BYTES_SPLITLINES_METHODDEF + {"rpartition", (PyCFunction)bytes_rpartition, METH_O, + rpartition__doc__}, + {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__}, + {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__}, + {"split", (PyCFunction)bytes_split, METH_VARARGS | METH_KEYWORDS, split__doc__}, + {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS | METH_KEYWORDS, + splitlines__doc__}, {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS, startswith__doc__}, - BYTES_STRIP_METHODDEF + {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__}, {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, _Py_swapcase__doc__}, {"title", (PyCFunction)stringlib_title, METH_NOARGS, _Py_title__doc__}, - BYTES_TRANSLATE_METHODDEF + {"translate", (PyCFunction)bytes_translate, METH_VARARGS, + translate__doc__}, {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__}, - BYTES_SIZEOF_METHODDEF + {"__sizeof__", (PyCFunction)bytes_sizeof, METH_NOARGS, + sizeof__doc__}, {NULL, NULL} /* sentinel */ }; diff -r 79e469ae13b7 -r 01438f18ee18 Objects/descrobject.c --- a/Objects/descrobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/descrobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -1180,19 +1180,28 @@ { wrapperfunc wrapper = wp->descr->d_base->wrapper; PyObject *self = wp->self; + PyObject *result = NULL; + + if (Py_EnterRecursiveCall(" while calling __call__")) + return NULL; if (wp->descr->d_base->flags & PyWrapperFlag_KEYWORDS) { wrapperfunc_kwds wk = (wrapperfunc_kwds)wrapper; - return (*wk)(self, args, wp->descr->d_wrapped, kwds); + result = (*wk)(self, args, wp->descr->d_wrapped, kwds); + Py_LeaveRecursiveCall(); + return result; } if (kwds != NULL && (!PyDict_Check(kwds) || PyDict_Size(kwds) != 0)) { PyErr_Format(PyExc_TypeError, "wrapper %s doesn't take keyword arguments", wp->descr->d_base->name); + Py_LeaveRecursiveCall(); return NULL; } - return (*wrapper)(self, args, wp->descr->d_wrapped); + result = (*wrapper)(self, args, wp->descr->d_wrapped); + Py_LeaveRecursiveCall(); + return result; } static int diff -r 79e469ae13b7 -r 01438f18ee18 Objects/listobject.c --- a/Objects/listobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/listobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -2444,7 +2444,7 @@ } else { PyErr_Format(PyExc_TypeError, - "list indices must be integers or slices, not %.200s", + "list indices must be integers, not %.200s", item->ob_type->tp_name); return NULL; } @@ -2608,7 +2608,7 @@ } else { PyErr_Format(PyExc_TypeError, - "list indices must be integers or slices, not %.200s", + "list indices must be integers, not %.200s", item->ob_type->tp_name); return -1; } diff -r 79e469ae13b7 -r 01438f18ee18 Objects/methodobject.c --- a/Objects/methodobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/methodobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -37,7 +37,6 @@ if (op == NULL) return NULL; } - op->m_weakreflist = NULL; op->m_ml = ml; Py_XINCREF(self); op->m_self = self; @@ -148,9 +147,6 @@ meth_dealloc(PyCFunctionObject *m) { _PyObject_GC_UNTRACK(m); - if (m->m_weakreflist != NULL) { - PyObject_ClearWeakRefs((PyObject*) m); - } Py_XDECREF(m->m_self); Py_XDECREF(m->m_module); if (numfree < PyCFunction_MAXFREELIST) { @@ -356,7 +352,7 @@ (traverseproc)meth_traverse, /* tp_traverse */ 0, /* tp_clear */ meth_richcompare, /* tp_richcompare */ - offsetof(PyCFunctionObject, m_weakreflist), /* tp_weaklistoffset */ + 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ meth_methods, /* tp_methods */ diff -r 79e469ae13b7 -r 01438f18ee18 Objects/tupleobject.c --- a/Objects/tupleobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/tupleobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -746,7 +746,7 @@ } else { PyErr_Format(PyExc_TypeError, - "tuple indices must be integers or slices, not %.200s", + "tuple indices must be integers, not %.200s", Py_TYPE(item)->tp_name); return NULL; } diff -r 79e469ae13b7 -r 01438f18ee18 Objects/typeobject.c --- a/Objects/typeobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/typeobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -54,9 +54,6 @@ static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); -static void -clear_slotdefs(void); - /* * finds the beginning of the docstring's introspection signature. * if present, returns a pointer pointing to the first '('. @@ -180,7 +177,6 @@ _PyType_Fini(void) { PyType_ClearCache(); - clear_slotdefs(); } void @@ -6512,15 +6508,15 @@ return 0; } -static int slotdefs_initialized = 0; /* Initialize the slotdefs table by adding interned string objects for the - names. */ + names and sorting the entries. */ static void init_slotdefs(void) { slotdef *p; - - if (slotdefs_initialized) + static int initialized = 0; + + if (initialized) return; for (p = slotdefs; p->name; p++) { /* Slots must be ordered by their offset in the PyHeapTypeObject. */ @@ -6529,17 +6525,7 @@ if (!p->name_strobj) Py_FatalError("Out of memory interning slotdef names"); } - slotdefs_initialized = 1; -} - -/* Undo init_slotdefs, releasing the interned strings. */ -static void clear_slotdefs(void) -{ - slotdef *p; - for (p = slotdefs; p->name; p++) { - Py_CLEAR(p->name_strobj); - } - slotdefs_initialized = 0; + initialized = 1; } /* Update the slots after assignment to a class (type) attribute. */ diff -r 79e469ae13b7 -r 01438f18ee18 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Objects/unicodeobject.c Fri Jul 25 11:39:11 2014 -0400 @@ -3255,7 +3255,7 @@ /* "surrogateescape" error handler */ char *str; - str = Py_EncodeLocale(wstr, &error_pos); + str = _Py_wchar2char(wstr, &error_pos); if (str == NULL) { if (error_pos == (size_t)-1) { PyErr_NoMemory(); @@ -3308,7 +3308,7 @@ if (errmsg != NULL) { size_t errlen; - wstr = Py_DecodeLocale(errmsg, &errlen); + wstr = _Py_char2wchar(errmsg, &errlen); if (wstr != NULL) { reason = PyUnicode_FromWideChar(wstr, errlen); PyMem_RawFree(wstr); @@ -3526,7 +3526,7 @@ if (surrogateescape) { /* "surrogateescape" error handler */ - wstr = Py_DecodeLocale(str, &wlen); + wstr = _Py_char2wchar(str, &wlen); if (wstr == NULL) { if (wlen == (size_t)-1) PyErr_NoMemory(); @@ -3581,7 +3581,7 @@ error_pos = mbstowcs_errorpos(str, len); if (errmsg != NULL) { size_t errlen; - wstr = Py_DecodeLocale(errmsg, &errlen); + wstr = _Py_char2wchar(errmsg, &errlen); if (wstr != NULL) { reason = PyUnicode_FromWideChar(wstr, errlen); PyMem_RawFree(wstr); diff -r 79e469ae13b7 -r 01438f18ee18 PC/pyconfig.h --- a/PC/pyconfig.h Fri Aug 08 17:24:06 2014 +0300 +++ b/PC/pyconfig.h Fri Jul 25 11:39:11 2014 -0400 @@ -436,11 +436,6 @@ /* Define to 1 if you have the `copysign' function. */ #define HAVE_COPYSIGN 1 -/* Define to 1 if you have the `round' function. */ -#if _MSC_VER >= 1800 -#define HAVE_ROUND 1 -#endif - /* Define to 1 if you have the `isinf' macro. */ #define HAVE_DECL_ISINF 1 diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/build.bat --- a/PCbuild/build.bat Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/build.bat Fri Jul 25 11:39:11 2014 -0400 @@ -16,13 +16,13 @@ set dir=%~dp0 :CheckOpts -if '%1'=='-c' (set conf=%2) & shift & shift & goto CheckOpts -if '%1'=='-p' (set platf=%2) & shift & shift & goto CheckOpts -if '%1'=='-r' (set target=Rebuild) & shift & goto CheckOpts -if '%1'=='-d' (set conf=Debug) & shift & goto CheckOpts -if '%1'=='-e' call "%dir%get_externals.bat" & shift & goto CheckOpts +if "%1"=="-c" (set conf=%2) & shift & shift & goto CheckOpts +if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts +if "%1"=="-r" (set target=Rebuild) & shift & goto CheckOpts +if "%1"=="-d" (set conf=Debug) & shift & goto CheckOpts +if "%1"=="-e" call "%dir%get_externals.bat" & shift & goto CheckOpts -if '%platf%'=='x64' (set vs_platf=x86_amd64) +if "%platf%"=="x64" (set vs_platf=x86_amd64) rem Setup the environment call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %vs_platf% diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/build_pgo.bat --- a/PCbuild/build_pgo.bat Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/build_pgo.bat Fri Jul 25 11:39:11 2014 -0400 @@ -7,15 +7,14 @@ setlocal set platf=Win32 -set dir=%~dp0 rem use the performance testsuite. This is quick and simple -set job1="%dir%..\tools\pybench\pybench.py" -n 1 -C 1 --with-gc -set path1="%dir%..\tools\pybench" +set job1=%~dp0..\tools\pybench\pybench.py -n 1 -C 1 --with-gc +set path1=%~dp0..\tools\pybench rem or the whole testsuite for more thorough testing -set job2="%dir%..\lib\test\regrtest.py" -set path2="%dir%..\lib" +set job2=%~dp0..\lib\test\regrtest.py +set path2=%~dp0..\lib set job=%job1% set clrpath=%path1% @@ -24,25 +23,19 @@ if "%1"=="-p" (set platf=%2) & shift & shift & goto CheckOpts if "%1"=="-2" (set job=%job2%) & (set clrpath=%path2%) & shift & goto CheckOpts -set PGI=%dir%%platf%-pgi -set PGO=%dir%%platf%-pgo +set PGI=%platf%-pgi +set PGO=%platf%-pgo -rem We cannot cross compile PGO builds, as the optimization needs to be run natively -set vs_platf=x86 -if "%platf%"=="x64" (set vs_platf=amd64) -rem Setup the environment -call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" %vs_platf% - +@echo on rem build the instrumented version -msbuild "%dir%pcbuild.sln" /t:Build /p:Configuration=PGInstrument /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9 +call build -p %platf% -c PGInstrument rem remove .pyc files, .pgc files and execute the job -"%PGI%\python.exe" "%dir%rmpyc.py" %clrpath% -del "%PGI%\*.pgc" -"%PGI%\python.exe" %job% +%PGI%\python.exe rmpyc.py "%clrpath%" +del %PGI%\*.pgc +%PGI%\python.exe "%job%" -rem clean -if exist "%PGO%" del /s /q "%PGO%" +rem finally build the optimized version +if exist %PGO% del /s /q %PGO% +call build -p %platf% -c PGUpdate -rem build optimized version -msbuild "%dir%pcbuild.sln" /t:Build /p:Configuration=PGUpdate /p:Platform=%platf% %1 %2 %3 %4 %5 %6 %7 %8 %9 diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/get_externals.bat --- a/PCbuild/get_externals.bat Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/get_externals.bat Fri Jul 25 11:39:11 2014 -0400 @@ -51,7 +51,7 @@ for %%e in ( bzip2-1.0.6 - openssl-1.0.1i + openssl-1.0.1h tcl-8.6.1.0 tk-8.6.1.0 tix-8.4.3.4 diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/pginstrument.props --- a/PCbuild/pginstrument.props Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/pginstrument.props Fri Jul 25 11:39:11 2014 -0400 @@ -1,7 +1,7 @@  - $(SolutionDir)$(Platform)-pgi + $(SolutionDir)$(Platform)-pgi\ <_ProjectFileVersion>10.0.30319.1 diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/prepare_ssl.py --- a/PCbuild/prepare_ssl.py Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/prepare_ssl.py Fri Jul 25 11:39:11 2014 -0400 @@ -81,35 +81,6 @@ fout.write(line) os.unlink(m32) -def create_asms(makefile): - #create a custom makefile out of the provided one - asm_makefile = os.path.splitext(makefile)[0] + '.asm.mak' - with open(makefile) as fin: - with open(asm_makefile, 'w') as fout: - for line in fin: - # Keep everything up to the install target (it's convenient) - if line.startswith('install: all'): - break - else: - fout.write(line) - asms = [] - for line in fin: - if '.asm' in line and line.strip().endswith('.pl'): - asms.append(line.split(':')[0]) - while line.strip(): - fout.write(line) - line = next(fin) - fout.write('\n') - - fout.write('asms: $(TMP_D) ') - fout.write(' '.join(asms)) - fout.write('\n') - - os.system('nmake /f {} PERL=perl asms'.format(asm_makefile)) - os.unlink(asm_makefile) - - - def fix_makefile(makefile): """Fix some stuff in all makefiles """ @@ -193,8 +164,14 @@ else: print(makefile, 'already exists!') - print('creating asms...') - create_asms(makefile) + # If the assembler files don't exist in tmpXX, copy them there + if os.path.exists("asm"+dirsuffix): + if not os.path.exists("tmp"+dirsuffix): + os.mkdir("tmp"+dirsuffix) + for f in os.listdir("asm"+dirsuffix): + if not f.endswith(".asm"): continue + if os.path.isfile(r"tmp%s\%s" % (dirsuffix, f)): continue + shutil.copy(r"asm%s\%s" % (dirsuffix, f), "tmp"+dirsuffix) def main(): if len(sys.argv) == 1: diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/pyproject.props --- a/PCbuild/pyproject.props Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/pyproject.props Fri Jul 25 11:39:11 2014 -0400 @@ -20,7 +20,7 @@ $(externalsDir)\sqlite-3.8.3.1 $(externalsDir)\bzip2-1.0.6 $(externalsDir)\xz-5.0.5 - $(externalsDir)\openssl-1.0.1i + $(externalsDir)\openssl-1.0.1h $(externalsDir)\tcl-8.6.1.0 $(externalsDir)\tk-8.6.1.0 $(externalsDir)\tix-8.4.3.4 diff -r 79e469ae13b7 -r 01438f18ee18 PCbuild/pythoncore.vcxproj --- a/PCbuild/pythoncore.vcxproj Fri Aug 08 17:24:06 2014 +0300 +++ b/PCbuild/pythoncore.vcxproj Fri Jul 25 11:39:11 2014 -0400 @@ -176,7 +176,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) $(OutDir)$(PyDllName).dll libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -212,7 +212,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -247,7 +247,7 @@ "$(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -285,7 +285,7 @@ "$(SolutionDir)make_buildinfo.exe" Debug "$(IntDir)" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -317,7 +317,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) $(OutDir)$(PyDllName).dll libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -353,7 +353,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 MachineX64 @@ -386,7 +386,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) $(OutDir)$(PyDllName).dll libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 @@ -422,7 +422,7 @@ "$(SolutionDir)make_buildinfo.exe" Release "$(IntDir)\" - $(IntDir)getbuildinfo.o;ws2_32.lib;%(AdditionalDependencies) + $(IntDir)getbuildinfo.o;%(AdditionalDependencies) libc;%(IgnoreSpecificDefaultLibraries) 0x1e000000 MachineX64 diff -r 79e469ae13b7 -r 01438f18ee18 Programs/python.c --- a/Programs/python.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Programs/python.c Fri Jul 25 11:39:11 2014 -0400 @@ -52,7 +52,7 @@ setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { - argv_copy[i] = Py_DecodeLocale(argv[i], NULL); + argv_copy[i] = _Py_char2wchar(argv[i], NULL); if (!argv_copy[i]) { PyMem_RawFree(oldloc); fprintf(stderr, "Fatal Python error: " diff -r 79e469ae13b7 -r 01438f18ee18 Python/bltinmodule.c --- a/Python/bltinmodule.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Python/bltinmodule.c Fri Jul 25 11:39:11 2014 -0400 @@ -69,7 +69,7 @@ func = PyTuple_GET_ITEM(args, 0); /* Better be callable */ if (!PyFunction_Check(func)) { PyErr_SetString(PyExc_TypeError, - "__build_class__: func must be a function"); + "__build__class__: func must be a function"); return NULL; } name = PyTuple_GET_ITEM(args, 1); diff -r 79e469ae13b7 -r 01438f18ee18 Python/fileutils.c --- a/Python/fileutils.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Python/fileutils.c Fri Jul 25 11:39:11 2014 -0400 @@ -82,11 +82,11 @@ Values of force_ascii: - 1: the workaround is used: Py_EncodeLocale() uses - encode_ascii_surrogateescape() and Py_DecodeLocale() uses + 1: the workaround is used: _Py_wchar2char() uses + encode_ascii_surrogateescape() and _Py_char2wchar() uses decode_ascii_surrogateescape() - 0: the workaround is not used: Py_EncodeLocale() uses wcstombs() and - Py_DecodeLocale() uses mbstowcs() + 0: the workaround is not used: _Py_wchar2char() uses wcstombs() and + _Py_char2wchar() uses mbstowcs() -1: unknown, need to call check_force_ascii() to get the value */ static int force_ascii = -1; @@ -241,26 +241,24 @@ /* Decode a byte string from the locale encoding with the - surrogateescape error handler: undecodable bytes are decoded as characters - in range U+DC80..U+DCFF. If a byte sequence can be decoded as a surrogate + surrogateescape error handler (undecodable bytes are decoded as characters + in range U+DC80..U+DCFF). If a byte sequence can be decoded as a surrogate character, escape the bytes using the surrogateescape error handler instead of decoding them. - Return a pointer to a newly allocated wide character string, use - PyMem_RawFree() to free the memory. If size is not NULL, write the number of - wide characters excluding the null character into *size + Use _Py_wchar2char() to encode the character string back to a byte string. - Return NULL on decoding error or memory allocation error. If *size* is not - NULL, *size is set to (size_t)-1 on memory error or set to (size_t)-2 on - decoding error. + Return a pointer to a newly allocated wide character string (use + PyMem_RawFree() to free the memory) and write the number of written wide + characters excluding the null character into *size if size is not NULL, or + NULL on error (decoding or memory allocation error). If size is not NULL, + *size is set to (size_t)-1 on memory error and (size_t)-2 on decoding + error. - Decoding errors should never happen, unless there is a bug in the C - library. - - Use the Py_EncodeLocale() function to encode the character string back to a - byte string. */ + Conversion errors should never happen, unless there is a bug in the C + library. */ wchar_t* -Py_DecodeLocale(const char* arg, size_t *size) +_Py_char2wchar(const char* arg, size_t *size) { #ifdef __APPLE__ wchar_t *wstr; @@ -391,20 +389,19 @@ #endif /* __APPLE__ */ } -/* Encode a wide character string to the locale encoding with the - surrogateescape error handler: surrogate characters in the range - U+DC80..U+DCFF are converted to bytes 0x80..0xFF. +/* Encode a (wide) character string to the locale encoding with the + surrogateescape error handler (characters in range U+DC80..U+DCFF are + converted to bytes 0x80..0xFF). - Return a pointer to a newly allocated byte string, use PyMem_Free() to free - the memory. Return NULL on encoding or memory allocation error. + This function is the reverse of _Py_char2wchar(). - If error_pos is not NULL, *error_pos is set to the index of the invalid - character on encoding error, or set to (size_t)-1 otherwise. + Return a pointer to a newly allocated byte string (use PyMem_Free() to free + the memory), or NULL on encoding or memory allocation error. - Use the Py_DecodeLocale() function to decode the bytes string back to a wide - character string. */ + If error_pos is not NULL: *error_pos is the index of the invalid character + on encoding error, or (size_t)-1 otherwise. */ char* -Py_EncodeLocale(const wchar_t *text, size_t *error_pos) +_Py_wchar2char(const wchar_t *text, size_t *error_pos) { #ifdef __APPLE__ Py_ssize_t len; @@ -523,7 +520,7 @@ { int err; char *fname; - fname = Py_EncodeLocale(path, NULL); + fname = _Py_wchar2char(path, NULL); if (fname == NULL) { errno = EINVAL; return -1; @@ -787,7 +784,7 @@ errno = EINVAL; return NULL; } - cpath = Py_EncodeLocale(path, NULL); + cpath = _Py_wchar2char(path, NULL); if (cpath == NULL) return NULL; f = fopen(cpath, cmode); @@ -878,7 +875,7 @@ int res; size_t r1; - cpath = Py_EncodeLocale(path, NULL); + cpath = _Py_wchar2char(path, NULL); if (cpath == NULL) { errno = EINVAL; return -1; @@ -892,7 +889,7 @@ return -1; } cbuf[res] = '\0'; /* buf will be null terminated */ - wbuf = Py_DecodeLocale(cbuf, &r1); + wbuf = _Py_char2wchar(cbuf, &r1); if (wbuf == NULL) { errno = EINVAL; return -1; @@ -923,7 +920,7 @@ wchar_t *wresolved_path; char *res; size_t r; - cpath = Py_EncodeLocale(path, NULL); + cpath = _Py_wchar2char(path, NULL); if (cpath == NULL) { errno = EINVAL; return NULL; @@ -933,7 +930,7 @@ if (res == NULL) return NULL; - wresolved_path = Py_DecodeLocale(cresolved_path, &r); + wresolved_path = _Py_char2wchar(cresolved_path, &r); if (wresolved_path == NULL) { errno = EINVAL; return NULL; @@ -966,7 +963,7 @@ if (getcwd(fname, Py_ARRAY_LENGTH(fname)) == NULL) return NULL; - wname = Py_DecodeLocale(fname, &len); + wname = _Py_char2wchar(fname, &len); if (wname == NULL) return NULL; if (size <= len) { @@ -1048,56 +1045,3 @@ return fd; } -#ifndef MS_WINDOWS -/* Get the blocking mode of the file descriptor. - Return 0 if the O_NONBLOCK flag is set, 1 if the flag is cleared, - raise an exception and return -1 on error. */ -int -_Py_get_blocking(int fd) -{ - int flags = fcntl(fd, F_GETFL, 0); - if (flags < 0) { - PyErr_SetFromErrno(PyExc_OSError); - return -1; - } - - return !(flags & O_NONBLOCK); -} - -/* Set the blocking mode of the specified file descriptor. - - Set the O_NONBLOCK flag if blocking is False, clear the O_NONBLOCK flag - otherwise. - - Return 0 on success, raise an exception and return -1 on error. */ -int -_Py_set_blocking(int fd, int blocking) -{ -#if defined(HAVE_SYS_IOCTL_H) && defined(FIONBIO) - int arg = !blocking; - if (ioctl(fd, FIONBIO, &arg) < 0) - goto error; -#else - int flags, res; - - flags = fcntl(fd, F_GETFL, 0); - if (flags < 0) - goto error; - - if (blocking) - flags = flags & (~O_NONBLOCK); - else - flags = flags | O_NONBLOCK; - - res = fcntl(fd, F_SETFL, flags); - if (res < 0) - goto error; -#endif - return 0; - -error: - PyErr_SetFromErrno(PyExc_OSError); - return -1; -} -#endif - diff -r 79e469ae13b7 -r 01438f18ee18 Python/frozenmain.c --- a/Python/frozenmain.c Fri Aug 08 17:24:06 2014 +0300 +++ b/Python/frozenmain.c Fri Jul 25 11:39:11 2014 -0400 @@ -52,7 +52,7 @@ setlocale(LC_ALL, ""); for (i = 0; i < argc; i++) { - argv_copy[i] = Py_DecodeLocale(argv[i], NULL); + argv_copy[i] = _Py_char2wchar(argv[i], NULL); argv_copy2[i] = argv_copy[i]; if (!argv_copy[i]) { fprintf(stderr, "Unable to decode the command line argument #%i\n", diff -r 79e469ae13b7 -r 01438f18ee18 Tools/clinic/clinic.py --- a/Tools/clinic/clinic.py Fri Aug 08 17:24:06 2014 +0300 +++ b/Tools/clinic/clinic.py Fri Jul 25 11:39:11 2014 -0400 @@ -1252,11 +1252,10 @@ match = self.start_re.match(line.lstrip()) return match.group(1) if match else None - def _line(self, lookahead=False): + def _line(self): self.line_number += 1 line = self.input.pop() - if not lookahead: - self.language.parse_line(line) + self.language.parse_line(line) return line def parse_verbatim_block(self): @@ -1312,7 +1311,7 @@ output_add, output_output = text_accumulator() arguments = None while self.input: - line = self._line(lookahead=True) + line = self._line() match = checksum_re.match(line.lstrip()) arguments = match.group(1) if match else None if arguments: @@ -2865,11 +2864,10 @@ type = 'long' conversion_fn = 'PyLong_FromLong' cast = '' - unsigned_cast = '' def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == {}-1".format(self.unsigned_cast), data) + self.err_occurred_if("_return_value == -1", data) data.return_conversion.append( ''.join(('return_value = ', self.conversion_fn, '(', self.cast, '_return_value);\n'))) @@ -2890,12 +2888,10 @@ class unsigned_long_return_converter(long_return_converter): type = 'unsigned long' conversion_fn = 'PyLong_FromUnsignedLong' - unsigned_cast = '(unsigned long)' class unsigned_int_return_converter(unsigned_long_return_converter): type = 'unsigned int' cast = '(unsigned long)' - unsigned_cast = '(unsigned int)' class Py_ssize_t_return_converter(long_return_converter): type = 'Py_ssize_t' @@ -2904,7 +2900,6 @@ class size_t_return_converter(long_return_converter): type = 'size_t' conversion_fn = 'PyLong_FromSize_t' - unsigned_cast = '(size_t)' class double_return_converter(CReturnConverter): diff -r 79e469ae13b7 -r 01438f18ee18 config.guess --- a/config.guess Fri Aug 08 17:24:06 2014 +0300 +++ b/config.guess Fri Jul 25 11:39:11 2014 -0400 @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2014 Free Software Foundation, Inc. +# Copyright 1992-2013 Free Software Foundation, Inc. -timestamp='2014-03-23' +timestamp='2013-06-10' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -50,7 +50,7 @@ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2014 Free Software Foundation, Inc. +Copyright 1992-2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -149,7 +149,7 @@ LIBC=gnu #endif EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'` ;; esac @@ -826,7 +826,7 @@ *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; - *:MSYS*:*) + i*:MSYS*:*) echo ${UNAME_MACHINE}-pc-msys exit ;; i*:windows32*:*) @@ -969,10 +969,10 @@ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; - openrisc*:Linux:*:*) - echo or1k-unknown-linux-${LIBC} + or1k:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; - or32:Linux:*:* | or1k*:Linux:*:*) + or32:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; padre:Linux:*:*) @@ -1260,26 +1260,16 @@ if test "$UNAME_PROCESSOR" = unknown ; then UNAME_PROCESSOR=powerpc fi - if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_64BIT_ARCH >/dev/null - then - case $UNAME_PROCESSOR in - i386) UNAME_PROCESSOR=x86_64 ;; - powerpc) UNAME_PROCESSOR=powerpc64 ;; - esac - fi + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then + if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ + grep IS_64BIT_ARCH >/dev/null + then + case $UNAME_PROCESSOR in + i386) UNAME_PROCESSOR=x86_64 ;; + powerpc) UNAME_PROCESSOR=powerpc64 ;; + esac fi - elif test "$UNAME_PROCESSOR" = i386 ; then - # Avoid executing cc on OS X 10.9, as it ships with a stub - # that puts up a graphical alert prompting to install - # developer tools. Any system running Mac OS X 10.7 or - # later (Darwin 11 and later) is required to have a 64-bit - # processor. This is not true of the ARM version of Darwin - # that Apple uses in portable devices. - UNAME_PROCESSOR=x86_64 fi echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} exit ;; @@ -1371,6 +1361,154 @@ exit ;; esac +eval $set_cc_for_build +cat >$dummy.c < +# include +#endif +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix\n"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-pc-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + struct utsname un; + + uname(&un); + + if (strncmp(un.version, "V2", 2) == 0) { + printf ("i386-sequent-ptx2\n"); exit (0); + } + if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ + printf ("i386-sequent-ptx1\n"); exit (0); + } + printf ("i386-sequent-ptx\n"); exit (0); + +#endif + +#if defined (vax) +# if !defined (ultrix) +# include +# if defined (BSD) +# if BSD == 43 + printf ("vax-dec-bsd4.3\n"); exit (0); +# else +# if BSD == 199006 + printf ("vax-dec-bsd4.3reno\n"); exit (0); +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# endif +# else + printf ("vax-dec-bsd\n"); exit (0); +# endif +# else + printf ("vax-dec-ultrix\n"); exit (0); +# endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && + { echo "$SYSTEM_NAME"; exit; } + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit ;; + c34*) + echo c34-convex-bsd + exit ;; + c38*) + echo c38-convex-bsd + exit ;; + c4*) + echo c4-convex-bsd + exit ;; + esac +fi + cat >&2 <&5 -$as_echo_n "checking if we can turn on $CC mixed sign comparison warning... " >&6; } - ac_save_cc="$CC" - CC="$CC -Wsign-compare" - save_CFLAGS="$CFLAGS" - if ${ac_cv_enable_sign_compare_warning+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - -int -main () -{ - - ; - return 0; -} - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - ac_cv_enable_sign_compare_warning=yes - -else - - ac_cv_enable_sign_compare_warning=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_enable_sign_compare_warning" >&5 -$as_echo "$ac_cv_enable_sign_compare_warning" >&6; } - - if test $ac_cv_enable_sign_compare_warning = yes - then - BASECFLAGS="$BASECFLAGS -Wsign-compare" - fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can turn on $CC unreachable code warning" >&5 -$as_echo_n "checking if we can turn on $CC unreachable code warning... " >&6; } - ac_save_cc="$CC" - CC="$CC -Wunreachable-code" - save_CFLAGS="$CFLAGS" - if ${ac_cv_enable_unreachable_code_warning+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - - -int -main () -{ - - ; - return 0; -} - -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - - ac_cv_enable_unreachable_code_warning=yes - -else - - ac_cv_enable_unreachable_code_warning=no - -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi - - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_enable_unreachable_code_warning" >&5 -$as_echo "$ac_cv_enable_unreachable_code_warning" >&6; } - - # Don't enable unreachable code warning in debug mode, since it usually - # results in non-standard code paths. - if test $ac_cv_enable_unreachable_code_warning = yes && test "$Py_DEBUG" != "true" - then - BASECFLAGS="$BASECFLAGS -Wunreachable-code" - fi - # if using gcc on alpha, use -mieee to get (near) full IEEE 754 # support. Without this, treatment of subnormals doesn't follow # the standard. @@ -15439,7 +15351,7 @@ done -SRCDIRS="Parser Grammar Objects Python Modules Mac Programs" +SRCDIRS="Parser Grammar Objects Python Modules Mac" { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build directories" >&5 $as_echo_n "checking for build directories... " >&6; } for dir in $SRCDIRS; do diff -r 79e469ae13b7 -r 01438f18ee18 configure.ac --- a/configure.ac Fri Aug 08 17:24:06 2014 +0300 +++ b/configure.ac Fri Jul 25 11:39:11 2014 -0400 @@ -1234,52 +1234,6 @@ BASECFLAGS="$BASECFLAGS -Werror=declaration-after-statement" fi - AC_MSG_CHECKING(if we can turn on $CC mixed sign comparison warning) - ac_save_cc="$CC" - CC="$CC -Wsign-compare" - save_CFLAGS="$CFLAGS" - AC_CACHE_VAL(ac_cv_enable_sign_compare_warning, - AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM([[]], [[]]) - ],[ - ac_cv_enable_sign_compare_warning=yes - ],[ - ac_cv_enable_sign_compare_warning=no - ])) - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - AC_MSG_RESULT($ac_cv_enable_sign_compare_warning) - - if test $ac_cv_enable_sign_compare_warning = yes - then - BASECFLAGS="$BASECFLAGS -Wsign-compare" - fi - - AC_MSG_CHECKING(if we can turn on $CC unreachable code warning) - ac_save_cc="$CC" - CC="$CC -Wunreachable-code" - save_CFLAGS="$CFLAGS" - AC_CACHE_VAL(ac_cv_enable_unreachable_code_warning, - AC_COMPILE_IFELSE( - [ - AC_LANG_PROGRAM([[]], [[]]) - ],[ - ac_cv_enable_unreachable_code_warning=yes - ],[ - ac_cv_enable_unreachable_code_warning=no - ])) - CFLAGS="$save_CFLAGS" - CC="$ac_save_cc" - AC_MSG_RESULT($ac_cv_enable_unreachable_code_warning) - - # Don't enable unreachable code warning in debug mode, since it usually - # results in non-standard code paths. - if test $ac_cv_enable_unreachable_code_warning = yes && test "$Py_DEBUG" != "true" - then - BASECFLAGS="$BASECFLAGS -Wunreachable-code" - fi - # if using gcc on alpha, use -mieee to get (near) full IEEE 754 # support. Without this, treatment of subnormals doesn't follow # the standard. @@ -4780,7 +4734,7 @@ done AC_SUBST(SRCDIRS) -SRCDIRS="Parser Grammar Objects Python Modules Mac Programs" +SRCDIRS="Parser Grammar Objects Python Modules Mac" AC_MSG_CHECKING(for build directories) for dir in $SRCDIRS; do if test ! -d $dir; then