diff -r 95c34bce986c -r 900df5732f93 .bzrignore --- a/.bzrignore Tue Jul 26 09:37:46 2011 +0300 +++ b/.bzrignore Mon Jul 25 09:47:18 2011 -0400 @@ -37,6 +37,3 @@ Lib/lib2to3/Grammar*.pickle Lib/lib2to3/PatternGrammar*.pickle __pycache__ -.coverage -coverage/* -htmlcov/* diff -r 95c34bce986c -r 900df5732f93 .gitignore --- a/.gitignore Tue Jul 26 09:37:46 2011 +0300 +++ b/.gitignore Mon Jul 25 09:47:18 2011 -0400 @@ -42,6 +42,3 @@ python python-gdb.py tags -.coverage -coverage/ -htmlcov/ diff -r 95c34bce986c -r 900df5732f93 .hgignore --- a/.hgignore Tue Jul 26 09:37:46 2011 +0300 +++ b/.hgignore Mon Jul 25 09:47:18 2011 -0400 @@ -70,6 +70,3 @@ PCbuild/x64-temp-* __pycache__ Modules/_testembed -.coverage -coverage/ -htmlcov/ diff -r 95c34bce986c -r 900df5732f93 .hgtags --- a/.hgtags Tue Jul 26 09:37:46 2011 +0300 +++ b/.hgtags Mon Jul 25 09:47:18 2011 -0400 @@ -89,5 +89,3 @@ a222a015e28d8ae9af3899258dc6c15c3d40add0 v3.2 8ffac2337a3323323d02153ac919fd1483176652 v3.2.1b1 cfa9364997c7f2e67b9cbb45c3a5fa3bba4e4999 v3.2.1rc1 -5df549718fb4841ff521fe051f6b54f290fad5d8 v3.2.1rc2 -ac1f7e5c05104d557d5acd922e95625ba5d1fe10 v3.2.1 diff -r 95c34bce986c -r 900df5732f93 Doc/ACKS.txt --- a/Doc/ACKS.txt Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/ACKS.txt Mon Jul 25 09:47:18 2011 -0400 @@ -105,7 +105,6 @@ * Robert Kern * Jim Kerr * Jan Kim - * Kamil Kisiel * Greg Kochanski * Guido Kollerie * Peter A. Koren @@ -143,8 +142,7 @@ * Ross Moore * Sjoerd Mullender * Dale Nagata - * Michal Nowikowski - * Steffen Daode Nurpmeso + * Michal Nowikowski * Ng Pheng Siong * Koray Oner * Tomas Oppelstrup diff -r 95c34bce986c -r 900df5732f93 Doc/Makefile --- a/Doc/Makefile Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/Makefile Mon Jul 25 09:47:18 2011 -0400 @@ -113,7 +113,7 @@ pydoc-topics: BUILDER = pydoc-topics pydoc-topics: build @echo "Building finished; now copy build/pydoc-topics/topics.py" \ - "to ../Lib/pydoc_data/topics.py" + "to Lib/pydoc_data/topics.py" htmlview: html $(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')" diff -r 95c34bce986c -r 900df5732f93 Doc/c-api/exceptions.rst --- a/Doc/c-api/exceptions.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/c-api/exceptions.rst Mon Jul 25 09:47:18 2011 -0400 @@ -354,10 +354,10 @@ .. c:function:: PyObject* PyErr_NewException(char *name, PyObject *base, PyObject *dict) - This utility function creates and returns a new exception class. The *name* + This utility function creates and returns a new exception object. The *name* argument must be the name of the new exception, a C string of the form - ``module.classname``. The *base* and *dict* arguments are normally *NULL*. - This creates a class object derived from :exc:`Exception` (accessible in C as + ``module.class``. The *base* and *dict* arguments are normally *NULL*. This + creates a class object derived from :exc:`Exception` (accessible in C as :c:data:`PyExc_Exception`). The :attr:`__module__` attribute of the new class is set to the first part (up diff -r 95c34bce986c -r 900df5732f93 Doc/c-api/number.rst --- a/Doc/c-api/number.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/c-api/number.rst Mon Jul 25 09:47:18 2011 -0400 @@ -249,9 +249,7 @@ .. c:function:: Py_ssize_t PyNumber_AsSsize_t(PyObject *o, PyObject *exc) Returns *o* converted to a Py_ssize_t value if *o* can be interpreted as an - integer. If the call fails, an exception is raised and -1 is returned. - - If *o* can be converted to a Python int but the attempt to + integer. If *o* can be converted to a Python int but the attempt to convert to a Py_ssize_t value would raise an :exc:`OverflowError`, then the *exc* argument is the type of exception that will be raised (usually :exc:`IndexError` or :exc:`OverflowError`). If *exc* is *NULL*, then the diff -r 95c34bce986c -r 900df5732f93 Doc/distutils/index.rst --- a/Doc/distutils/index.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/distutils/index.rst Mon Jul 25 09:47:18 2011 -0400 @@ -20,6 +20,7 @@ .. toctree:: :maxdepth: 2 + :numbered: introduction.rst setupscript.rst diff -r 95c34bce986c -r 900df5732f93 Doc/distutils/setupscript.rst --- a/Doc/distutils/setupscript.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/distutils/setupscript.rst Mon Jul 25 09:47:18 2011 -0400 @@ -72,7 +72,7 @@ promising that the Distutils will find a file :file:`foo/__init__.py` (which might be spelled differently on your system, but you get the idea) relative to the directory where your setup script lives. If you break this promise, the -Distutils will issue a warning but still process the broken package anyway. +Distutils will issue a warning but still process the broken package anyways. If you use a different convention to lay out your source directory, that's no problem: you just have to supply the :option:`package_dir` option to tell the diff -r 95c34bce986c -r 900df5732f93 Doc/howto/logging-cookbook.rst --- a/Doc/howto/logging-cookbook.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/howto/logging-cookbook.rst Mon Jul 25 09:47:18 2011 -0400 @@ -723,7 +723,7 @@ # The size of the rotated files is made small so you can see the results easily. def listener_configurer(): root = logging.getLogger() - h = logging.handlers.RotatingFileHandler('mptest.log', 'a', 300, 10) + h = logging.handlers.RotatingFileHandler('/tmp/mptest.log', 'a', 300, 10) f = logging.Formatter('%(asctime)s %(processName)-10s %(name)s %(levelname)-8s %(message)s') h.setFormatter(f) root.addHandler(h) diff -r 95c34bce986c -r 900df5732f93 Doc/howto/urllib2.rst --- a/Doc/howto/urllib2.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/howto/urllib2.rst Mon Jul 25 09:47:18 2011 -0400 @@ -140,7 +140,7 @@ name=Somebody+Here&language=Python&location=Northampton >>> url = 'http://www.example.com/example.cgi' >>> full_url = url + '?' + url_values - >>> data = urllib.request.urlopen(full_url) + >>> data = urllib.request.open(full_url) Notice that the full URL is created by adding a ``?`` to the URL, followed by the encoded values. diff -r 95c34bce986c -r 900df5732f93 Doc/install/install.rst --- a/Doc/install/install.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/install/install.rst Mon Jul 25 09:47:18 2011 -0400 @@ -4,7 +4,7 @@ Installing Python projects: overwiew ==================================== -.. _packaging-install-intro: +.. _packaging_packaging-intro: Introduction ============ diff -r 95c34bce986c -r 900df5732f93 Doc/library/ast.rst --- a/Doc/library/ast.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/ast.rst Mon Jul 25 09:47:18 2011 -0400 @@ -96,6 +96,9 @@ Abstract Grammar ---------------- +The module defines a string constant ``__version__`` which is the Mercurial +revision of the file shown below. + The abstract grammar is currently defined as follows: .. literalinclude:: ../../Parser/Python.asdl diff -r 95c34bce986c -r 900df5732f93 Doc/library/cmd.rst --- a/Doc/library/cmd.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/cmd.rst Mon Jul 25 09:47:18 2011 -0400 @@ -50,7 +50,7 @@ the line as argument. The optional argument is a banner or intro string to be issued before the first - prompt (this overrides the :attr:`intro` class attribute). + prompt (this overrides the :attr:`intro` class member). If the :mod:`readline` module is loaded, input will automatically inherit :program:`bash`\ -like history-list editing (e.g. :kbd:`Control-P` scrolls back diff -r 95c34bce986c -r 900df5732f93 Doc/library/collections.rst --- a/Doc/library/collections.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/collections.rst Mon Jul 25 09:47:18 2011 -0400 @@ -900,10 +900,10 @@ >>> d = OrderedDict.fromkeys('abcde') >>> d.move_to_end('b') - >>> ''.join(d.keys()) + >>> ''.join(d.keys) 'acdeb' >>> d.move_to_end('b', last=False) - >>> ''.join(d.keys()) + >>> ''.join(d.keys) 'bacde' .. versionadded:: 3.2 diff -r 95c34bce986c -r 900df5732f93 Doc/library/curses.rst --- a/Doc/library/curses.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/curses.rst Mon Jul 25 09:47:18 2011 -0400 @@ -72,7 +72,7 @@ .. function:: baudrate() - Return the output speed of the terminal in bits per second. On software + Returns the output speed of the terminal in bits per second. On software terminal emulators it will have a fixed high value. Included for historical reasons; in former times, it was used to write output loops for time delays and occasionally to change interfaces depending on the line speed. @@ -85,7 +85,7 @@ .. function:: can_change_color() - Return ``True`` or ``False``, depending on whether the programmer can change the colors + Returns true or false, depending on whether the programmer can change the colors displayed by the terminal. @@ -100,7 +100,7 @@ .. function:: color_content(color_number) - Return the intensity of the red, green, and blue (RGB) components in the color + Returns the intensity of the red, green, and blue (RGB) components in the color *color_number*, which must be between ``0`` and :const:`COLORS`. A 3-tuple is returned, containing the R,G,B values for the given color, which will be between ``0`` (no component) and ``1000`` (maximum amount of component). @@ -108,7 +108,7 @@ .. function:: color_pair(color_number) - Return the attribute value for displaying text in the specified color. This + Returns the attribute value for displaying text in the specified color. This attribute value can be combined with :const:`A_STANDOUT`, :const:`A_REVERSE`, and the other :const:`A_\*` attributes. :func:`pair_number` is the counterpart to this function. @@ -116,7 +116,7 @@ .. function:: curs_set(visibility) - Set the cursor state. *visibility* can be set to 0, 1, or 2, for invisible, + Sets the cursor state. *visibility* can be set to 0, 1, or 2, for invisible, normal, or very visible. If the terminal supports the visibility requested, the previous cursor state is returned; otherwise, an exception is raised. On many terminals, the "visible" mode is an underline cursor and the "very visible" mode @@ -125,7 +125,7 @@ .. function:: def_prog_mode() - Save the current terminal mode as the "program" mode, the mode when the running + Saves the current terminal mode as the "program" mode, the mode when the running program is using curses. (Its counterpart is the "shell" mode, for when the program is not in curses.) Subsequent calls to :func:`reset_prog_mode` will restore this mode. @@ -133,7 +133,7 @@ .. function:: def_shell_mode() - Save the current terminal mode as the "shell" mode, the mode when the running + Saves the current terminal mode as the "shell" mode, the mode when the running program is not using curses. (Its counterpart is the "program" mode, when the program is using curses capabilities.) Subsequent calls to :func:`reset_shell_mode` will restore this mode. @@ -141,7 +141,7 @@ .. function:: delay_output(ms) - Insert an *ms* millisecond pause in output. + Inserts an *ms* millisecond pause in output. .. function:: doupdate() @@ -172,7 +172,7 @@ .. function:: erasechar() - Return the user's current erase character. Under Unix operating systems this + Returns the user's current erase character. Under Unix operating systems this is a property of the controlling tty of the curses program, and is not set by the curses library itself. @@ -180,7 +180,7 @@ .. function:: filter() The :func:`.filter` routine, if used, must be called before :func:`initscr` is - called. The effect is that, during those calls, :envvar:`LINES` is set to 1; the + called. The effect is that, during those calls, LINES is set to 1; the capabilities clear, cup, cud, cud1, cuu1, cuu, vpa are disabled; and the home string is set to the value of cr. The effect is that the cursor is confined to the current line, and so are screen updates. This may be used for enabling @@ -206,7 +206,7 @@ method should be call to retrieve the queued mouse event, represented as a 5-tuple ``(id, x, y, z, bstate)``. *id* is an ID value used to distinguish multiple devices, and *x*, *y*, *z* are the event's coordinates. (*z* is - currently unused.) *bstate* is an integer value whose bits will be set to + currently unused.). *bstate* is an integer value whose bits will be set to indicate the type of event, and will be the bitwise OR of one or more of the following constants, where *n* is the button number from 1 to 4: :const:`BUTTONn_PRESSED`, :const:`BUTTONn_RELEASED`, :const:`BUTTONn_CLICKED`, @@ -216,32 +216,32 @@ .. function:: getsyx() - Return the current coordinates of the virtual screen cursor in y and x. If + Returns the current coordinates of the virtual screen cursor in y and x. If leaveok is currently true, then -1,-1 is returned. .. function:: getwin(file) - Read window related data stored in the file by an earlier :func:`putwin` call. + Reads window related data stored in the file by an earlier :func:`putwin` call. The routine then creates and initializes a new window using that data, returning the new window object. .. function:: has_colors() - Return ``True`` if the terminal can display colors; otherwise, return ``False``. + Returns true if the terminal can display colors; otherwise, it returns false. .. function:: has_ic() - Return ``True`` if the terminal has insert- and delete-character capabilities. + Returns true if the terminal has insert- and delete- character capabilities. This function is included for historical reasons only, as all modern software terminal emulators have such capabilities. .. function:: has_il() - Return ``True`` if the terminal has insert- and delete-line capabilities, or can + Returns true if the terminal has insert- and delete-line capabilities, or can simulate them using scrolling regions. This function is included for historical reasons only, as all modern software terminal emulators have such capabilities. @@ -249,7 +249,7 @@ .. function:: has_key(ch) - Take a key value *ch*, and return ``True`` if the current terminal type recognizes + Takes a key value *ch*, and returns true if the current terminal type recognizes a key with that value. @@ -258,13 +258,13 @@ Used for half-delay mode, which is similar to cbreak mode in that characters typed by the user are immediately available to the program. However, after blocking for *tenths* tenths of seconds, an exception is raised if nothing has - been typed. The value of *tenths* must be a number between ``1`` and ``255``. Use + been typed. The value of *tenths* must be a number between 1 and 255. Use :func:`nocbreak` to leave half-delay mode. .. function:: init_color(color_number, r, g, b) - Change the definition of a color, taking the number of the color to be changed + Changes the definition of a color, taking the number of the color to be changed followed by three RGB values (for the amounts of red, green, and blue components). The value of *color_number* must be between ``0`` and :const:`COLORS`. Each of *r*, *g*, *b*, must be a value between ``0`` and @@ -275,7 +275,7 @@ .. function:: init_pair(pair_number, fg, bg) - Change the definition of a color-pair. It takes three arguments: the number of + Changes the definition of a color-pair. It takes three arguments: the number of the color-pair to be changed, the foreground color number, and the background color number. The value of *pair_number* must be between ``1`` and ``COLOR_PAIRS - 1`` (the ``0`` color pair is wired to white on black and cannot @@ -287,7 +287,7 @@ .. function:: initscr() - Initialize the library. Return a :class:`WindowObject` which represents the + Initialize the library. Returns a :class:`WindowObject` which represents the whole screen. .. note:: @@ -296,15 +296,9 @@ cause the interpreter to exit. -.. function:: is_term_resized(nlines, ncols) - - Return ``True`` if :func:`resize_term` would modify the window structure, - ``False`` otherwise. - - .. function:: isendwin() - Return ``True`` if :func:`endwin` has been called (that is, the curses library has + Returns true if :func:`endwin` has been called (that is, the curses library has been deinitialized). @@ -320,14 +314,14 @@ .. function:: killchar() - Return the user's current line kill character. Under Unix operating systems + Returns the user's current line kill character. Under Unix operating systems this is a property of the controlling tty of the curses program, and is not set by the curses library itself. .. function:: longname() - Return a string containing the terminfo long name field describing the current + Returns a string containing the terminfo long name field describing the current terminal. The maximum length of a verbose description is 128 characters. It is defined only after the call to :func:`initscr`. @@ -340,14 +334,14 @@ .. function:: mouseinterval(interval) - Set the maximum time in milliseconds that can elapse between press and release - events in order for them to be recognized as a click, and return the previous + Sets the maximum time in milliseconds that can elapse between press and release + events in order for them to be recognized as a click, and returns the previous interval value. The default value is 200 msec, or one fifth of a second. .. function:: mousemask(mousemask) - Set the mouse events to be reported, and return a tuple ``(availmask, + Sets the mouse events to be reported, and returns a tuple ``(availmask, oldmask)``. *availmask* indicates which of the specified mouse events can be reported; on complete failure it returns 0. *oldmask* is the previous value of the given window's mouse event mask. If this function is never called, no mouse @@ -361,7 +355,7 @@ .. function:: newpad(nlines, ncols) - Create and return a pointer to a new pad data structure with the given number + Creates and returns a pointer to a new pad data structure with the given number of lines and columns. A pad is returned as a window object. A pad is like a window, except that it is not restricted by the screen size, and @@ -371,9 +365,9 @@ echoing of input) do not occur. The :meth:`refresh` and :meth:`noutrefresh` methods of a pad require 6 arguments to specify the part of the pad to be displayed and the location on the screen to be used for the display. The - arguments are *pminrow*, *pmincol*, *sminrow*, *smincol*, *smaxrow*, *smaxcol*; the *p* + arguments are pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol; the p arguments refer to the upper left corner of the pad region to be displayed and - the *s* arguments define a clipping box on the screen within which the pad region + the s arguments define a clipping box on the screen within which the pad region is to be displayed. @@ -415,7 +409,7 @@ .. function:: noqiflush() - When the :func:`noqiflush` routine is used, normal flush of input and output queues + When the noqiflush routine is used, normal flush of input and output queues associated with the INTR, QUIT and SUSP characters will not be done. You may want to call :func:`noqiflush` in a signal handler if you want output to continue as though the interrupt had not occurred, after the handler exits. @@ -428,27 +422,27 @@ .. function:: pair_content(pair_number) - Return a tuple ``(fg, bg)`` containing the colors for the requested color pair. + Returns a tuple ``(fg, bg)`` containing the colors for the requested color pair. The value of *pair_number* must be between ``1`` and ``COLOR_PAIRS - 1``. .. function:: pair_number(attr) - Return the number of the color-pair set by the attribute value *attr*. + Returns the number of the color-pair set by the attribute value *attr*. :func:`color_pair` is the counterpart to this function. .. function:: putp(string) - Equivalent to ``tputs(str, 1, putchar)``; emit the value of a specified - terminfo capability for the current terminal. Note that the output of :func:`putp` + Equivalent to ``tputs(str, 1, putchar)``; emits the value of a specified + terminfo capability for the current terminal. Note that the output of putp always goes to standard output. .. function:: qiflush( [flag] ) - If *flag* is ``False``, the effect is the same as calling :func:`noqiflush`. If - *flag* is ``True``, or no argument is provided, the queues will be flushed when + If *flag* is false, the effect is the same as calling :func:`noqiflush`. If + *flag* is true, or no argument is provided, the queues will be flushed when these control characters are read. @@ -461,55 +455,26 @@ .. function:: reset_prog_mode() - Restore the terminal to "program" mode, as previously saved by + Restores the terminal to "program" mode, as previously saved by :func:`def_prog_mode`. .. function:: reset_shell_mode() - Restore the terminal to "shell" mode, as previously saved by + Restores the terminal to "shell" mode, as previously saved by :func:`def_shell_mode`. -.. function:: resetty() - - Restore the state of the terminal modes to what it was at the last call to - :func:`savetty`. - - -.. function:: resize_term(nlines, ncols) - - Backend function used by :func:`resizeterm`, performing most of the work; - when resizing the windows, :func:`resize_term` blank-fills the areas that are - extended. The calling application should fill in these areas with - appropriate data. The :func:`resize_term` function attempts to resize all - windows. However, due to the calling convention of pads, it is not possible - to resize these without additional interaction with the application. - - -.. function:: resizeterm(nlines, ncols) - - Resize the standard and current windows to the specified dimensions, and - adjusts other bookkeeping data used by the curses library that record the - window dimensions (in particular the SIGWINCH handler). - - -.. function:: savetty() - - Save the current state of the terminal modes in a buffer, usable by - :func:`resetty`. - - .. function:: setsyx(y, x) - Set the virtual screen cursor to *y*, *x*. If *y* and *x* are both -1, then + Sets the virtual screen cursor to *y*, *x*. If *y* and *x* are both -1, then leaveok is set. .. function:: setupterm([termstr, fd]) - Initialize the terminal. *termstr* is a string giving the terminal name; if - omitted, the value of the :envvar:`TERM` environment variable will be used. *fd* is the + Initializes the terminal. *termstr* is a string giving the terminal name; if + omitted, the value of the TERM environment variable will be used. *fd* is the file descriptor to which any initialization sequences will be sent; if not supplied, the file descriptor for ``sys.stdout`` will be used. @@ -529,19 +494,19 @@ .. function:: termattrs() - Return a logical OR of all video attributes supported by the terminal. This + Returns a logical OR of all video attributes supported by the terminal. This information is useful when a curses program needs complete control over the appearance of the screen. .. function:: termname() - Return the value of the environment variable :envvar:`TERM`, truncated to 14 characters. + Returns the value of the environment variable TERM, truncated to 14 characters. .. function:: tigetflag(capname) - Return the value of the Boolean capability corresponding to the terminfo + Returns the value of the Boolean capability corresponding to the terminfo capability name *capname*. The value ``-1`` is returned if *capname* is not a Boolean capability, or ``0`` if it is canceled or absent from the terminal description. @@ -549,7 +514,7 @@ .. function:: tigetnum(capname) - Return the value of the numeric capability corresponding to the terminfo + Returns the value of the numeric capability corresponding to the terminfo capability name *capname*. The value ``-2`` is returned if *capname* is not a numeric capability, or ``-1`` if it is canceled or absent from the terminal description. @@ -557,22 +522,22 @@ .. function:: tigetstr(capname) - Return the value of the string capability corresponding to the terminfo + Returns the value of the string capability corresponding to the terminfo capability name *capname*. ``None`` is returned if *capname* is not a string capability, or is canceled or absent from the terminal description. .. function:: tparm(str[, ...]) - Instantiate the string *str* with the supplied parameters, where *str* should - be a parameterized string obtained from the terminfo database. E.g. - ``tparm(tigetstr("cup"), 5, 3)`` could result in ``'\033[6;4H'``, the exact + Instantiates the string *str* with the supplied parameters, where *str* should + be a parameterized string obtained from the terminfo database. E.g. + ``tparm(tigetstr("cup"), 5, 3)`` could result in ``'\033[6;4H'``, the exact result depending on terminal type. .. function:: typeahead(fd) - Specify that the file descriptor *fd* be used for typeahead checking. If *fd* + Specifies that the file descriptor *fd* be used for typeahead checking. If *fd* is ``-1``, then no typeahead checking is done. The curses library does "line-breakout optimization" by looking for typeahead @@ -584,7 +549,7 @@ .. function:: unctrl(ch) - Return a string which is a printable representation of the character *ch*. + Returns a string which is a printable representation of the character *ch*. Control characters are displayed as a caret followed by the character, for example as ``^C``. Printing characters are left as they are. @@ -607,7 +572,7 @@ .. function:: use_env(flag) If used, this function should be called before :func:`initscr` or newterm are - called. When *flag* is ``False``, the values of lines and columns specified in the + called. When *flag* is false, the values of lines and columns specified in the terminfo database will be used, even if environment variables :envvar:`LINES` and :envvar:`COLUMNS` (used by default) are set, or if curses is running in a window (in which case default behavior would be to use the window size if @@ -691,7 +656,7 @@ .. method:: window.bkgd(ch[, attr]) - Set the background property of the window to the character *ch*, with + Sets the background property of the window to the character *ch*, with attributes *attr*. The change is then applied to every character position in that window: @@ -704,7 +669,7 @@ .. method:: window.bkgdset(ch[, attr]) - Set the window's background. A window's background consists of a character and + Sets the window's background. A window's background consists of a character and any combination of attributes. The attribute part of the background is combined (OR'ed) with all non-blank characters that are written into the window. Both the character and attribute parts of the background are combined with the blank @@ -749,12 +714,12 @@ .. method:: window.box([vertch, horch]) Similar to :meth:`border`, but both *ls* and *rs* are *vertch* and both *ts* and - *bs* are *horch*. The default corner characters are always used by this function. + bs are *horch*. The default corner characters are always used by this function. .. method:: window.chgat([y, x, ] [num,] attr) - Set the attributes of *num* characters at the current cursor position, or at + Sets the attributes of *num* characters at the current cursor position, or at position ``(y, x)`` if supplied. If no value of *num* is given or *num* = -1, the attribute will be set on all the characters to the end of the line. This function does not move the cursor. The changed line will be touched using the @@ -764,7 +729,7 @@ .. method:: window.clear() - Like :meth:`erase`, but also cause the whole window to be repainted upon next + Like :meth:`erase`, but also causes the whole window to be repainted upon next call to :meth:`refresh`. @@ -787,7 +752,7 @@ .. method:: window.cursyncup() - Update the current cursor position of all the ancestors of the window to + Updates the current cursor position of all the ancestors of the window to reflect the current cursor position of the window. @@ -798,14 +763,14 @@ .. method:: window.deleteln() - Delete the line under the cursor. All following lines are moved up by one line. + Delete the line under the cursor. All following lines are moved up by 1 line. .. method:: window.derwin([nlines, ncols,] begin_y, begin_x) An abbreviation for "derive window", :meth:`derwin` is the same as calling :meth:`subwin`, except that *begin_y* and *begin_x* are relative to the origin - of the window, rather than relative to the entire screen. Return a window + of the window, rather than relative to the entire screen. Returns a window object for the derived window. @@ -817,8 +782,8 @@ .. method:: window.enclose(y, x) - Test whether the given pair of screen-relative character-cell coordinates are - enclosed by the given window, returning ``True`` or ``False``. It is useful for + Tests whether the given pair of screen-relative character-cell coordinates are + enclosed by the given window, returning true or false. It is useful for determining what subset of the screen windows enclose the location of a mouse event. @@ -833,11 +798,6 @@ Return a tuple ``(y, x)`` of co-ordinates of upper-left corner. -.. method:: window.getbkgd() - - Return the given window's current background character/attribute pair. - - .. method:: window.getch([y, x]) Get a character. Note that the integer returned does *not* have to be in ASCII @@ -846,14 +806,6 @@ until a key is pressed. -.. method:: window.get_wch([y, x]) - - Get a wide character. Like :meth:`getch`, but the integer returned is the - Unicode code point for the key pressed, so it can be passed to :func:`chr`. - - .. versionadded:: 3.3 - - .. method:: window.getkey([y, x]) Get a character, returning a string instead of an integer, as :meth:`getch` @@ -868,8 +820,8 @@ .. method:: window.getparyx() - Return the beginning coordinates of this window relative to its parent window - into two integer variables y and x. Return ``-1, -1`` if this window has no + Returns the beginning coordinates of this window relative to its parent window + into two integer variables y and x. Returns ``-1,-1`` if this window has no parent. @@ -892,8 +844,8 @@ .. method:: window.idcok(flag) - If *flag* is ``False``, curses no longer considers using the hardware insert/delete - character feature of the terminal; if *flag* is ``True``, use of character insertion + If *flag* is false, curses no longer considers using the hardware insert/delete + character feature of the terminal; if *flag* is true, use of character insertion and deletion is enabled. When curses is first initialized, use of character insert/delete is enabled by default. @@ -906,7 +858,7 @@ .. method:: window.immedok(flag) - If *flag* is ``True``, any change in the window image automatically causes the + If *flag* is true, any change in the window image automatically causes the window to be refreshed; you no longer have to call :meth:`refresh` yourself. However, it may degrade performance considerably, due to repeated calls to wrefresh. This option is disabled by default. @@ -926,7 +878,7 @@ .. method:: window.insdelln(nlines) - Insert *nlines* lines into the specified window above the current line. The + Inserts *nlines* lines into the specified window above the current line. The *nlines* bottom lines are lost. For negative *nlines*, delete *nlines* lines starting with the one under the cursor, and move the remaining lines up. The bottom *nlines* lines are cleared. The current cursor position remains the @@ -935,7 +887,7 @@ .. method:: window.insertln() - Insert a blank line under the cursor. All following lines are moved down by one + Insert a blank line under the cursor. All following lines are moved down by 1 line. @@ -958,23 +910,23 @@ .. method:: window.instr([y, x] [, n]) - Return a string of characters, extracted from the window starting at the + Returns a string of characters, extracted from the window starting at the current cursor position, or at *y*, *x* if specified. Attributes are stripped - from the characters. If *n* is specified, :meth:`instr` returns a string + from the characters. If *n* is specified, :meth:`instr` returns return a string at most *n* characters long (exclusive of the trailing NUL). .. method:: window.is_linetouched(line) - Return ``True`` if the specified line was modified since the last call to - :meth:`refresh`; otherwise return ``False``. Raise a :exc:`curses.error` + Returns true if the specified line was modified since the last call to + :meth:`refresh`; otherwise returns false. Raises a :exc:`curses.error` exception if *line* is not valid for the given window. .. method:: window.is_wintouched() - Return ``True`` if the specified window was modified since the last call to - :meth:`refresh`; otherwise return ``False``. + Returns true if the specified window was modified since the last call to + :meth:`refresh`; otherwise returns false. .. method:: window.keypad(yes) @@ -1000,7 +952,7 @@ .. method:: window.mvderwin(y, x) - Move the window inside its parent window. The screen-relative parameters of + Moves the window inside its parent window. The screen-relative parameters of the window are not changed. This routine is used to display different parts of the parent window at the same physical position on the screen. @@ -1058,19 +1010,19 @@ .. method:: window.putwin(file) - Write all data associated with the window into the provided file object. This + Writes all data associated with the window into the provided file object. This information can be later retrieved using the :func:`getwin` function. .. method:: window.redrawln(beg, num) - Indicate that the *num* screen lines, starting at line *beg*, are corrupted and + Indicates that the *num* screen lines, starting at line *beg*, are corrupted and should be completely redrawn on the next :meth:`refresh` call. .. method:: window.redrawwin() - Touch the entire window, causing it to be completely redrawn on the next + Touches the entire window, causing it to be completely redrawn on the next :meth:`refresh` call. @@ -1091,14 +1043,6 @@ *sminrow*, or *smincol* are treated as if they were zero. -.. method:: window.resize(nlines, ncols) - - Reallocate storage for a curses window to adjust its dimensions to the - specified values. If either dimension is larger than the current values, the - window's data is filled with blanks that have the current background - rendition (as set by :meth:`bkgdset`) merged into them. - - .. method:: window.scroll([lines=1]) Scroll the screen or scrolling region upward by *lines* lines. @@ -1106,7 +1050,7 @@ .. method:: window.scrollok(flag) - Control what happens when the cursor of a window is moved off the edge of the + Controls what happens when the cursor of a window is moved off the edge of the window or scrolling region, either as a result of a newline action on the bottom line, or typing the last character of the last line. If *flag* is false, the cursor is left on the bottom line. If *flag* is true, the window is scrolled up @@ -1148,26 +1092,26 @@ .. method:: window.syncdown() - Touch each location in the window that has been touched in any of its ancestor + Touches each location in the window that has been touched in any of its ancestor windows. This routine is called by :meth:`refresh`, so it should almost never be necessary to call it manually. .. method:: window.syncok(flag) - If called with *flag* set to ``True``, then :meth:`syncup` is called automatically + If called with *flag* set to true, then :meth:`syncup` is called automatically whenever there is a change in the window. .. method:: window.syncup() - Touch all locations in ancestors of the window that have been changed in the + Touches all locations in ancestors of the window that have been changed in the window. .. method:: window.timeout(delay) - Set blocking or non-blocking read behavior for the window. If *delay* is + Sets blocking or non-blocking read behavior for the window. If *delay* is negative, blocking read is used (which will wait indefinitely for input). If *delay* is zero, then non-blocking read is used, and -1 will be returned by :meth:`getch` if no input is waiting. If *delay* is positive, then @@ -1190,7 +1134,7 @@ .. method:: window.untouchwin() - Mark all lines in the window as unchanged since the last call to + Marks all lines in the window as unchanged since the last call to :meth:`refresh`. @@ -1647,7 +1591,7 @@ each keystroke entered with the keystroke as a parameter; command dispatch is done on the result. This method returns the window contents as a string; whether blanks in the window are included is affected by the - :attr:`stripspaces` attribute. + :attr:`stripspaces` member. .. method:: do_command(ch) @@ -1713,13 +1657,13 @@ .. method:: gather() - Return the window contents as a string; whether blanks in the + This method returns the window contents as a string; whether blanks in the window are included is affected by the :attr:`stripspaces` member. .. attribute:: stripspaces - This attribute is a flag which controls the interpretation of blanks in + This data member is a flag which controls the interpretation of blanks in the window. When it is on, trailing blanks on each line are ignored; any cursor motion that would land the cursor on a trailing blank goes to the end of that line instead, and trailing blanks are stripped when the window diff -r 95c34bce986c -r 900df5732f93 Doc/library/datetime.rst --- a/Doc/library/datetime.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/datetime.rst Mon Jul 25 09:47:18 2011 -0400 @@ -11,7 +11,7 @@ The :mod:`datetime` module supplies classes for manipulating dates and times in both simple and complex ways. While date and time arithmetic is supported, the -focus of the implementation is on efficient attribute extraction for output +focus of the implementation is on efficient member extraction for output formatting and manipulation. For related functionality, see also the :mod:`time` and :mod:`calendar` modules. @@ -25,8 +25,8 @@ work with, at the cost of ignoring some aspects of reality. For applications requiring more, :class:`datetime` and :class:`time` objects -have an optional time zone information attribute, :attr:`tzinfo`, that can be -set to an instance of a subclass of the abstract :class:`tzinfo` class. These +have an optional time zone information member, :attr:`tzinfo`, that can contain +an instance of a subclass of the abstract :class:`tzinfo` class. These :class:`tzinfo` objects capture information about the offset from UTC time, the time zone name, and whether Daylight Saving Time is in effect. Note that only one concrete :class:`tzinfo` class, the :class:`timezone` class, is supplied by the @@ -499,9 +499,9 @@ .. method:: date.replace(year, month, day) - Return a date with the same value, except for those parameters given new - values by whichever keyword arguments are specified. For example, if ``d == - date(2002, 12, 31)``, then ``d.replace(day=26) == date(2002, 12, 26)``. + Return a date with the same value, except for those members given new values by + whichever keyword arguments are specified. For example, if ``d == date(2002, + 12, 31)``, then ``d.replace(day=26) == date(2002, 12, 26)``. .. method:: date.timetuple() @@ -748,13 +748,11 @@ .. classmethod:: datetime.combine(date, time) - Return a new :class:`datetime` object whose date components are equal to the - given :class:`date` object's, and whose time components and :attr:`tzinfo` - attributes are equal to the given :class:`time` object's. For any - :class:`datetime` object *d*, - ``d == datetime.combine(d.date(), d.timetz())``. If date is a - :class:`datetime` object, its time components and :attr:`tzinfo` attributes - are ignored. + Return a new :class:`datetime` object whose date members are equal to the given + :class:`date` object's, and whose time and :attr:`tzinfo` members are equal to + the given :class:`time` object's. For any :class:`datetime` object *d*, ``d == + datetime.combine(d.date(), d.timetz())``. If date is a :class:`datetime` + object, its time and :attr:`tzinfo` members are ignored. .. classmethod:: datetime.strptime(date_string, format) @@ -848,44 +846,43 @@ (1) datetime2 is a duration of timedelta removed from datetime1, moving forward in time if ``timedelta.days`` > 0, or backward if ``timedelta.days`` < 0. The - result has the same :attr:`tzinfo` attribute as the input datetime, and - datetime2 - datetime1 == timedelta after. :exc:`OverflowError` is raised if - datetime2.year would be smaller than :const:`MINYEAR` or larger than - :const:`MAXYEAR`. Note that no time zone adjustments are done even if the - input is an aware object. + result has the same :attr:`tzinfo` member as the input datetime, and datetime2 - + datetime1 == timedelta after. :exc:`OverflowError` is raised if datetime2.year + would be smaller than :const:`MINYEAR` or larger than :const:`MAXYEAR`. Note + that no time zone adjustments are done even if the input is an aware object. (2) Computes the datetime2 such that datetime2 + timedelta == datetime1. As for - addition, the result has the same :attr:`tzinfo` attribute as the input - datetime, and no time zone adjustments are done even if the input is aware. - This isn't quite equivalent to datetime1 + (-timedelta), because -timedelta - in isolation can overflow in cases where datetime1 - timedelta does not. + addition, the result has the same :attr:`tzinfo` member as the input datetime, + and no time zone adjustments are done even if the input is aware. This isn't + quite equivalent to datetime1 + (-timedelta), because -timedelta in isolation + can overflow in cases where datetime1 - timedelta does not. (3) Subtraction of a :class:`datetime` from a :class:`datetime` is defined only if both operands are naive, or if both are aware. If one is aware and the other is naive, :exc:`TypeError` is raised. - If both are naive, or both are aware and have the same :attr:`tzinfo` attribute, - the :attr:`tzinfo` attributes are ignored, and the result is a :class:`timedelta` + If both are naive, or both are aware and have the same :attr:`tzinfo` member, + the :attr:`tzinfo` members are ignored, and the result is a :class:`timedelta` object *t* such that ``datetime2 + t == datetime1``. No time zone adjustments are done in this case. - If both are aware and have different :attr:`tzinfo` attributes, ``a-b`` acts - as if *a* and *b* were first converted to naive UTC datetimes first. The - result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - - b.utcoffset())`` except that the implementation never overflows. + If both are aware and have different :attr:`tzinfo` members, ``a-b`` acts as if + *a* and *b* were first converted to naive UTC datetimes first. The result is + ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None) - + b.utcoffset())`` except that the implementation never overflows. (4) *datetime1* is considered less than *datetime2* when *datetime1* precedes *datetime2* in time. If one comparand is naive and the other is aware, :exc:`TypeError` is raised. - If both comparands are aware, and have the same :attr:`tzinfo` attribute, the - common :attr:`tzinfo` attribute is ignored and the base datetimes are - compared. If both comparands are aware and have different :attr:`tzinfo` - attributes, the comparands are first adjusted by subtracting their UTC - offsets (obtained from ``self.utcoffset()``). + If both comparands are aware, and have the same :attr:`tzinfo` member, the + common :attr:`tzinfo` member is ignored and the base datetimes are compared. If + both comparands are aware and have different :attr:`tzinfo` members, the + comparands are first adjusted by subtracting their UTC offsets (obtained from + ``self.utcoffset()``). .. note:: @@ -918,22 +915,22 @@ .. method:: datetime.timetz() Return :class:`time` object with same hour, minute, second, microsecond, and - tzinfo attributes. See also method :meth:`time`. + tzinfo members. See also method :meth:`time`. .. method:: datetime.replace([year[, month[, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]]]]) - Return a datetime with the same attributes, except for those attributes given - new values by whichever keyword arguments are specified. Note that - ``tzinfo=None`` can be specified to create a naive datetime from an aware - datetime with no conversion of date and time data. + Return a datetime with the same members, except for those members given new + values by whichever keyword arguments are specified. Note that ``tzinfo=None`` + can be specified to create a naive datetime from an aware datetime with no + conversion of date and time members. .. method:: datetime.astimezone(tz) - Return a :class:`datetime` object with new :attr:`tzinfo` attribute *tz*, - adjusting the date and time data so the result is the same UTC time as - *self*, but in *tz*'s local time. + Return a :class:`datetime` object with new :attr:`tzinfo` member *tz*, adjusting + the date and time members so the result is the same UTC time as *self*, but in + *tz*'s local time. *tz* must be an instance of a :class:`tzinfo` subclass, and its :meth:`utcoffset` and :meth:`dst` methods must not return ``None``. *self* must @@ -941,18 +938,18 @@ not return ``None``). If ``self.tzinfo`` is *tz*, ``self.astimezone(tz)`` is equal to *self*: no - adjustment of date or time data is performed. Else the result is local - time in time zone *tz*, representing the same UTC time as *self*: after - ``astz = dt.astimezone(tz)``, ``astz - astz.utcoffset()`` will usually have - the same date and time data as ``dt - dt.utcoffset()``. The discussion - of class :class:`tzinfo` explains the cases at Daylight Saving Time transition - boundaries where this cannot be achieved (an issue only if *tz* models both - standard and daylight time). + adjustment of date or time members is performed. Else the result is local time + in time zone *tz*, representing the same UTC time as *self*: after ``astz = + dt.astimezone(tz)``, ``astz - astz.utcoffset()`` will usually have the same date + and time members as ``dt - dt.utcoffset()``. The discussion of class + :class:`tzinfo` explains the cases at Daylight Saving Time transition boundaries + where this cannot be achieved (an issue only if *tz* models both standard and + daylight time). If you merely want to attach a time zone object *tz* to a datetime *dt* without - adjustment of date and time data, use ``dt.replace(tzinfo=tz)``. If you + adjustment of date and time members, use ``dt.replace(tzinfo=tz)``. If you merely want to remove the time zone object from an aware datetime *dt* without - conversion of date and time data, use ``dt.replace(tzinfo=None)``. + conversion of date and time members, use ``dt.replace(tzinfo=None)``. Note that the default :meth:`tzinfo.fromutc` method can be overridden in a :class:`tzinfo` subclass to affect the result returned by :meth:`astimezone`. @@ -1263,14 +1260,14 @@ * comparison of :class:`time` to :class:`time`, where *a* is considered less than *b* when *a* precedes *b* in time. If one comparand is naive and the other is aware, :exc:`TypeError` is raised. If both comparands are aware, and have - the same :attr:`tzinfo` attribute, the common :attr:`tzinfo` attribute is - ignored and the base times are compared. If both comparands are aware and - have different :attr:`tzinfo` attributes, the comparands are first adjusted by - subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order - to stop mixed-type comparisons from falling back to the default comparison by - object address, when a :class:`time` object is compared to an object of a - different type, :exc:`TypeError` is raised unless the comparison is ``==`` or - ``!=``. The latter cases return :const:`False` or :const:`True`, respectively. + the same :attr:`tzinfo` member, the common :attr:`tzinfo` member is ignored and + the base times are compared. If both comparands are aware and have different + :attr:`tzinfo` members, the comparands are first adjusted by subtracting their + UTC offsets (obtained from ``self.utcoffset()``). In order to stop mixed-type + comparisons from falling back to the default comparison by object address, when + a :class:`time` object is compared to an object of a different type, + :exc:`TypeError` is raised unless the comparison is ``==`` or ``!=``. The + latter cases return :const:`False` or :const:`True`, respectively. * hash, use as dict key @@ -1285,10 +1282,10 @@ .. method:: time.replace([hour[, minute[, second[, microsecond[, tzinfo]]]]]) - Return a :class:`time` with the same value, except for those attributes given - new values by whichever keyword arguments are specified. Note that - ``tzinfo=None`` can be specified to create a naive :class:`time` from an - aware :class:`time`, without conversion of the time data. + Return a :class:`time` with the same value, except for those members given new + values by whichever keyword arguments are specified. Note that ``tzinfo=None`` + can be specified to create a naive :class:`time` from an aware :class:`time`, + without conversion of the time members. .. method:: time.isoformat() @@ -1373,7 +1370,7 @@ An instance of (a concrete subclass of) :class:`tzinfo` can be passed to the constructors for :class:`datetime` and :class:`time` objects. The latter objects -view their attributes as being in local time, and the :class:`tzinfo` object +view their members as being in local time, and the :class:`tzinfo` object supports methods revealing offset of local time from UTC, the name of the time zone, and DST offset, all relative to a date or time object passed to them. @@ -1418,9 +1415,9 @@ already been added to the UTC offset returned by :meth:`utcoffset`, so there's no need to consult :meth:`dst` unless you're interested in obtaining DST info separately. For example, :meth:`datetime.timetuple` calls its :attr:`tzinfo` - attribute's :meth:`dst` method to determine how the :attr:`tm_isdst` flag - should be set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for - DST changes when crossing time zones. + member's :meth:`dst` method to determine how the :attr:`tm_isdst` flag should be + set, and :meth:`tzinfo.fromutc` calls :meth:`dst` to account for DST changes + when crossing time zones. An instance *tz* of a :class:`tzinfo` subclass that models both standard and daylight times must be consistent in this sense: @@ -1495,11 +1492,11 @@ .. method:: tzinfo.fromutc(dt) - This is called from the default :class:`datetime.astimezone()` - implementation. When called from that, ``dt.tzinfo`` is *self*, and *dt*'s - date and time data are to be viewed as expressing a UTC time. The purpose - of :meth:`fromutc` is to adjust the date and time data, returning an - equivalent datetime in *self*'s local time. + This is called from the default :class:`datetime.astimezone()` implementation. + When called from that, ``dt.tzinfo`` is *self*, and *dt*'s date and time members + are to be viewed as expressing a UTC time. The purpose of :meth:`fromutc` is to + adjust the date and time members, returning an equivalent datetime in *self*'s + local time. Most :class:`tzinfo` subclasses should be able to inherit the default :meth:`fromutc` implementation without problems. It's strong enough to handle diff -r 95c34bce986c -r 900df5732f93 Doc/library/decimal.rst --- a/Doc/library/decimal.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/decimal.rst Mon Jul 25 09:47:18 2011 -0400 @@ -654,7 +654,7 @@ Normalize the number by stripping the rightmost trailing zeros and converting any result equal to :const:`Decimal('0')` to - :const:`Decimal('0e0')`. Used for producing canonical values for attributes + :const:`Decimal('0e0')`. Used for producing canonical values for members of an equivalence class. For example, ``Decimal('32.100')`` and ``Decimal('0.321000e+2')`` both normalize to the equivalent value ``Decimal('32.1')``. diff -r 95c34bce986c -r 900df5732f93 Doc/library/dis.rst --- a/Doc/library/dis.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/dis.rst Mon Jul 25 09:47:18 2011 -0400 @@ -171,6 +171,11 @@ **General instructions** +.. opcode:: STOP_CODE + + Indicates end-of-code to the compiler, not used by the interpreter. + + .. opcode:: NOP Do nothing code. Used as a placeholder by the bytecode optimizer. diff -r 95c34bce986c -r 900df5732f93 Doc/library/doctest.rst --- a/Doc/library/doctest.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/doctest.rst Mon Jul 25 09:47:18 2011 -0400 @@ -1127,10 +1127,11 @@ .. class:: DocTest(examples, globs, name, filename, lineno, docstring) A collection of doctest examples that should be run in a single namespace. The - constructor arguments are used to initialize the attributes of the same names. + constructor arguments are used to initialize the member variables of the same + names. - :class:`DocTest` defines the following attributes. They are initialized by + :class:`DocTest` defines the following member variables. They are initialized by the constructor, and should not be modified directly. @@ -1183,11 +1184,11 @@ .. class:: Example(source, want, exc_msg=None, lineno=0, indent=0, options=None) A single interactive example, consisting of a Python statement and its expected - output. The constructor arguments are used to initialize the attributes of - the same names. + output. The constructor arguments are used to initialize the member variables + of the same names. - :class:`Example` defines the following attributes. They are initialized by + :class:`Example` defines the following member variables. They are initialized by the constructor, and should not be modified directly. @@ -1674,9 +1675,9 @@ An exception raised by :class:`DocTestRunner` to signal that a doctest example's actual output did not match its expected output. The constructor arguments are - used to initialize the attributes of the same names. + used to initialize the member variables of the same names. -:exc:`DocTestFailure` defines the following attributes: +:exc:`DocTestFailure` defines the following member variables: .. attribute:: DocTestFailure.test @@ -1698,9 +1699,9 @@ An exception raised by :class:`DocTestRunner` to signal that a doctest example raised an unexpected exception. The constructor arguments are used - to initialize the attributes of the same names. + to initialize the member variables of the same names. -:exc:`UnexpectedException` defines the following attributes: +:exc:`UnexpectedException` defines the following member variables: .. attribute:: UnexpectedException.test diff -r 95c34bce986c -r 900df5732f93 Doc/library/email.util.rst --- a/Doc/library/email.util.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/email.util.rst Mon Jul 25 09:47:18 2011 -0400 @@ -81,20 +81,6 @@ indexes 6, 7, and 8 of the result tuple are not usable. -.. function:: parsedate_to_datetime(date) - - The inverse of :func:`format_datetime`. Performs the same function as - :func:`parsedate`, but on success returns a :mod:`~datetime.datetime`. If - the input date has a timezone of ``-0000``, the ``datetime`` will be a naive - ``datetime``, and if the date is conforming to the RFCs it will represent a - time in UTC but with no indication of the actual source timezone of the - message the date comes from. If the input date has any other valid timezone - offset, the ``datetime`` will be an aware ``datetime`` with the - corresponding a :class:`~datetime.timezone` :class:`~datetime.tzinfo`. - - .. versionadded:: 3.3 - - .. function:: mktime_tz(tuple) Turn a 10-tuple as returned by :func:`parsedate_tz` into a UTC timestamp. It @@ -126,20 +112,6 @@ ``False``. The default is ``False``. -.. function:: format_datetime(dt, usegmt=False) - - Like ``formatdate``, but the input is a :mod:`datetime` instance. If it is - a naive datetime, it is assumed to be "UTC with no information about the - source timezone", and the conventional ``-0000`` is used for the timezone. - If it is an aware ``datetime``, then the numeric timezone offset is used. - If it is an aware timezone with offset zero, then *usegmt* may be set to - ``True``, in which case the string ``GMT`` is used instead of the numeric - timezone offset. This provides a way to generate standards conformant HTTP - date headers. - - .. versionadded:: 3.3 - - .. function:: make_msgid(idstring=None, domain=None) Returns a string suitable for an :rfc:`2822`\ -compliant diff -r 95c34bce986c -r 900df5732f93 Doc/library/faulthandler.rst --- a/Doc/library/faulthandler.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/faulthandler.rst Mon Jul 25 09:47:18 2011 -0400 @@ -92,11 +92,11 @@ Dump the traceback on a user signal ----------------------------------- -.. function:: register(signum, file=sys.stderr, all_threads=True, chain=False) +.. function:: register(signum, file=sys.stderr, all_threads=True) Register a user signal: install a handler for the *signum* signal to dump the traceback of all threads, or of the current thread if *all_threads* is - ``False``, into *file*. Call the previous handler if chain is ``True``. + ``False``, into *file*. Not available on Windows. diff -r 95c34bce986c -r 900df5732f93 Doc/library/ftplib.rst --- a/Doc/library/ftplib.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/ftplib.rst Mon Jul 25 09:47:18 2011 -0400 @@ -426,14 +426,6 @@ Set up secure control connection by using TLS or SSL, depending on what specified in :meth:`ssl_version` attribute. -.. method:: FTP_TLS.ccc() - - Revert control channel back to plaintex. This can be useful to take - advantage of firewalls that know how to handle NAT with non-secure FTP - without opening fixed ports. - - .. versionadded:: 3.3 - .. method:: FTP_TLS.prot_p() Set up secure data connection. diff -r 95c34bce986c -r 900df5732f93 Doc/library/functions.rst --- a/Doc/library/functions.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/functions.rst Mon Jul 25 09:47:18 2011 -0400 @@ -331,13 +331,14 @@ :term:`iterator`, or some other object which supports iteration. The :meth:`__next__` method of the iterator returned by :func:`enumerate` returns a tuple containing a count (from *start* which defaults to 0) and the - values obtained from iterating over *iterable*. + corresponding value obtained from iterating over *iterable*. - >>> seasons = ['Spring', 'Summer', 'Fall', 'Winter'] - >>> list(enumerate(seasons)) - [(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')] - >>> list(enumerate(seasons, start=1)) - [(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')] + >>> for i, season in enumerate('Spring Summer Fall Winter'.split(), start=1): + print(i, season) + 1 Spring + 2 Summer + 3 Fall + 4 Winter Equivalent to:: diff -r 95c34bce986c -r 900df5732f93 Doc/library/gzip.rst --- a/Doc/library/gzip.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/gzip.rst Mon Jul 25 09:47:18 2011 -0400 @@ -61,7 +61,7 @@ time is used. This module ignores the timestamp when decompressing; however, some programs, such as :program:`gunzip`\ , make use of it. The format of the timestamp is the same as that of the return value of - ``time.time()`` and of the ``st_mtime`` attribute of the object returned + ``time.time()`` and of the ``st_mtime`` member of the object returned by ``os.stat()``. Calling a :class:`GzipFile` object's :meth:`close` method does not close diff -r 95c34bce986c -r 900df5732f93 Doc/library/html.entities.rst --- a/Doc/library/html.entities.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/html.entities.rst Mon Jul 25 09:47:18 2011 -0400 @@ -11,7 +11,7 @@ This module defines three dictionaries, ``name2codepoint``, ``codepoint2name``, and ``entitydefs``. ``entitydefs`` is used to provide the :attr:`entitydefs` -attribute of the :class:`html.parser.HTMLParser` class. The definition provided +member of the :class:`html.parser.HTMLParser` class. The definition provided here contains all the entities defined by XHTML 1.0 that can be handled using simple textual substitution in the Latin-1 character set (ISO-8859-1). diff -r 95c34bce986c -r 900df5732f93 Doc/library/http.client.rst --- a/Doc/library/http.client.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/http.client.rst Mon Jul 25 09:47:18 2011 -0400 @@ -592,17 +592,15 @@ Here is an example session that shows how to ``POST`` requests:: >>> import http.client, urllib.parse - >>> params = urllib.parse.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'}) + >>> params = urllib.parse.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> headers = {"Content-type": "application/x-www-form-urlencoded", ... "Accept": "text/plain"} - >>> conn = http.client.HTTPConnection("bugs.python.org") - >>> conn.request("POST", "", params, headers) + >>> conn = http.client.HTTPConnection("musi-cal.mojam.com:80") + >>> conn.request("POST", "/cgi-bin/query", params, headers) >>> response = conn.getresponse() >>> print(response.status, response.reason) - 302 Found + 200 OK >>> data = response.read() - >>> data - b'Redirecting to http://bugs.python.org/issue12524' >>> conn.close() diff -r 95c34bce986c -r 900df5732f93 Doc/library/http.cookies.rst --- a/Doc/library/http.cookies.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/http.cookies.rst Mon Jul 25 09:47:18 2011 -0400 @@ -152,7 +152,7 @@ .. method:: Morsel.set(key, value, coded_value) - Set the *key*, *value* and *coded_value* attributes. + Set the *key*, *value* and *coded_value* members. .. method:: Morsel.isReservedKey(K) diff -r 95c34bce986c -r 900df5732f93 Doc/library/io.rst --- a/Doc/library/io.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/io.rst Mon Jul 25 09:47:18 2011 -0400 @@ -391,8 +391,8 @@ :class:`RawIOBase` implementation, but wrap one, like :class:`BufferedWriter` and :class:`BufferedReader` do. - :class:`BufferedIOBase` provides or overrides these methods and attribute in - addition to those from :class:`IOBase`: + :class:`BufferedIOBase` provides or overrides these members in addition to + those from :class:`IOBase`: .. attribute:: raw @@ -706,8 +706,7 @@ written. -.. class:: TextIOWrapper(buffer, encoding=None, errors=None, newline=None, \ - line_buffering=False, write_through=False) +.. class:: TextIOWrapper(buffer, encoding=None, errors=None, newline=None, line_buffering=False) A buffered text stream over a :class:`BufferedIOBase` binary stream. It inherits :class:`TextIOBase`. @@ -738,13 +737,6 @@ If *line_buffering* is ``True``, :meth:`flush` is implied when a call to write contains a newline character. - If *write_through* is ``True``, calls to :meth:`write` are guaranteed - not to be buffered: any data written on the :class:`TextIOWrapper` - object is immediately handled to its underlying binary *buffer*. - - .. versionchanged:: 3.3 - The *write_through* argument has been added. - :class:`TextIOWrapper` provides one attribute in addition to those of :class:`TextIOBase` and its parents: diff -r 95c34bce986c -r 900df5732f93 Doc/library/logging.handlers.rst --- a/Doc/library/logging.handlers.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/logging.handlers.rst Mon Jul 25 09:47:18 2011 -0400 @@ -452,15 +452,6 @@ behaviour) but can be set to ``False`` on a ``SysLogHandler`` instance in order for that instance to *not* append the NUL terminator. - .. versionchanged:: 3.3 - (See: :issue:`12419`.) In earlier versions, there was no facility for - an "ident" or "tag" prefix to identify the source of the message. This - can now be specified using a class-level attribute, defaulting to - ``""`` to preserve existing behaviour, but which can be overridden on - a ``SysLogHandler`` instance in order for that instance to prepend - the ident to every message handled. Note that the provided ident must - be text, not bytes, and is prepended to the message exactly as is. - .. method:: encodePriority(facility, priority) Encodes the facility and priority into an integer. You can pass in strings diff -r 95c34bce986c -r 900df5732f93 Doc/library/mmap.rst --- a/Doc/library/mmap.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/mmap.rst Mon Jul 25 09:47:18 2011 -0400 @@ -21,12 +21,6 @@ :func:`os.open` function, which returns a file descriptor directly (the file still needs to be closed when done). -.. note:: - If you want to create a memory-mapping for a writable, buffered file, you - should :func:`~io.IOBase.flush` the file first. This is necessary to ensure - that local modifications to the buffers are actually available to the - mapping. - For both the Unix and Windows versions of the constructor, *access* may be specified as an optional keyword parameter. *access* accepts one of three values: :const:`ACCESS_READ`, :const:`ACCESS_WRITE`, or :const:`ACCESS_COPY` diff -r 95c34bce986c -r 900df5732f93 Doc/library/multiprocessing.rst --- a/Doc/library/multiprocessing.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/multiprocessing.rst Mon Jul 25 09:47:18 2011 -0400 @@ -343,9 +343,10 @@ .. method:: join([timeout]) - If the optional argument *timeout* is ``None`` (the default), the method - blocks until the process whose :meth:`join` method is called terminates. - If *timeout* is a positive number, it blocks at most *timeout* seconds. + Block the calling thread until the process whose :meth:`join` method is + called terminates or until the optional timeout occurs. + + If *timeout* is ``None`` then there is no timeout. A process can be joined many times. diff -r 95c34bce986c -r 900df5732f93 Doc/library/nntplib.rst --- a/Doc/library/nntplib.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/nntplib.rst Mon Jul 25 09:47:18 2011 -0400 @@ -75,10 +75,10 @@ connection when done. Here is a sample on how using it: >>> from nntplib import NNTP - >>> with NNTP('news.gmane.org') as n: + >>> with nntplib.NNTP('news.gmane.org') as n: ... n.group('gmane.comp.python.committers') ... - ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers') + ('211 1454 1 1454 gmane.comp.python.committers', '1454', '1', '1454', 'gmane.comp.python.committers') >>> @@ -407,7 +407,7 @@ Send an ``ARTICLE`` command, where *message_spec* has the same meaning as for :meth:`stat`. Return a tuple ``(response, info)`` where *info* - is a :class:`~collections.namedtuple` with three attributes *number*, + is a :class:`~collections.namedtuple` with three members *number*, *message_id* and *lines* (in that order). *number* is the article number in the group (or 0 if the information is not available), *message_id* the message id as a string, and *lines* a list of lines (without terminating diff -r 95c34bce986c -r 900df5732f93 Doc/library/os.path.rst --- a/Doc/library/os.path.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/os.path.rst Mon Jul 25 09:47:18 2011 -0400 @@ -190,11 +190,10 @@ path, all previous components (on Windows, including the previous drive letter, if there was one) are thrown away, and joining continues. The return value is the concatenation of *path1*, and optionally *path2*, etc., with exactly one - directory separator (``os.sep``) following each non-empty part except the last. - (This means that an empty last part will result in a path that ends with a - separator.) Note that on Windows, since there is a current directory for - each drive, ``os.path.join("c:", "foo")`` represents a path relative to the - current directory on drive :file:`C:` (:file:`c:foo`), not :file:`c:\\foo`. + directory separator (``os.sep``) inserted between components, unless *path2* is + empty. Note that on Windows, since there is a current directory for each drive, + ``os.path.join("c:", "foo")`` represents a path relative to the current + directory on drive :file:`C:` (:file:`c:foo`), not :file:`c:\\foo`. .. function:: normcase(path) diff -r 95c34bce986c -r 900df5732f93 Doc/library/os.rst --- a/Doc/library/os.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/os.rst Mon Jul 25 09:47:18 2011 -0400 @@ -61,13 +61,6 @@ names have currently been registered: ``'posix'``, ``'nt'``, ``'mac'``, ``'os2'``, ``'ce'``, ``'java'``. - .. seealso:: - :attr:`sys.platform` has a finer granularity. :func:`os.uname` gives - system-dependent version information. - - The :mod:`platform` module provides detailed checks for the - system's identity. - .. _os-filenames: @@ -1472,8 +1465,6 @@ * :data:`stat.UF_APPEND` * :data:`stat.UF_OPAQUE` * :data:`stat.UF_NOUNLINK` - * :data:`stat.UF_COMPRESSED` - * :data:`stat.UF_HIDDEN` * :data:`stat.SF_ARCHIVED` * :data:`stat.SF_IMMUTABLE` * :data:`stat.SF_APPEND` @@ -1833,12 +1824,11 @@ .. note:: - The exact meaning and resolution of the :attr:`st_atime`, - :attr:`st_mtime`, and :attr:`st_ctime` attributes depend on the operating - system and the file system. For example, on Windows systems using the FAT - or FAT32 file systems, :attr:`st_mtime` has 2-second resolution, and - :attr:`st_atime` has only 1-day resolution. See your operating system - documentation for details. + The exact meaning and resolution of the :attr:`st_atime`, :attr:`st_mtime`, and + :attr:`st_ctime` members depends on the operating system and the file system. + For example, on Windows systems using the FAT or FAT32 file systems, + :attr:`st_mtime` has 2-second resolution, and :attr:`st_atime` has only 1-day + resolution. See your operating system documentation for details. For backward compatibility, the return value of :func:`~os.stat` is also accessible as a tuple of at least 10 integers giving the most important (and portable) @@ -2095,9 +2085,8 @@ Generate a :const:`SIGABRT` signal to the current process. On Unix, the default behavior is to produce a core dump; on Windows, the process immediately returns - an exit code of ``3``. Be aware that calling this function will not call the - Python signal handler registered for :const:`SIGABRT` with - :func:`signal.signal`. + an exit code of ``3``. Be aware that programs which use :func:`signal.signal` + to register a handler for :const:`SIGABRT` will behave differently. Availability: Unix, Windows. @@ -2438,9 +2427,7 @@ os.spawnvpe(os.P_WAIT, 'cp', L, os.environ) Availability: Unix, Windows. :func:`spawnlp`, :func:`spawnlpe`, :func:`spawnvp` - and :func:`spawnvpe` are not available on Windows. :func:`spawnle` and - :func:`spawnve` are not thread-safe on Windows; we advise you to use the - :mod:`subprocess` module instead. + and :func:`spawnvpe` are not available on Windows. .. data:: P_NOWAIT diff -r 95c34bce986c -r 900df5732f93 Doc/library/packaging.compiler.rst --- a/Doc/library/packaging.compiler.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/packaging.compiler.rst Mon Jul 25 09:47:18 2011 -0400 @@ -368,7 +368,7 @@ *sources* must be a list of filenames, most likely C/C++ files, but in reality anything that can be handled by a particular compiler and compiler class (e.g. - an ``'msvc'`` compiler can handle resource files in *sources*). Return a list of + an ``'msvc'`` compiler` can handle resource files in *sources*). Return a list of object filenames, one per source filename in *sources*. Depending on the implementation, not all source files will necessarily be compiled, but all corresponding object filenames will be returned. diff -r 95c34bce986c -r 900df5732f93 Doc/library/packaging.database.rst --- a/Doc/library/packaging.database.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/packaging.database.rst Mon Jul 25 09:47:18 2011 -0400 @@ -33,7 +33,7 @@ .. method:: get_distinfo_file(path, binary=False) Return a read-only file object for a file located at - :file:`{project}-{version}.dist-info/{path}`. *path* should be a + :file:`{project-version}.dist-info/path}`. *path* should be a ``'/'``-separated path relative to the ``.dist-info`` directory or an absolute path; if it is an absolute path and doesn't start with the path to the :file:`.dist-info` directory, a :class:`PackagingError` is raised. @@ -72,7 +72,7 @@ .. attribute:: metadata Instance of :class:`packaging.metadata.Metadata` filled with the contents - of the :file:`{project}-{version}.dist-info/METADATA` file. + of the :file:`{project-version}.dist-info/METADATA` file. .. attribute:: name diff -r 95c34bce986c -r 900df5732f93 Doc/library/packaging.rst --- a/Doc/library/packaging.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/packaging.rst Mon Jul 25 09:47:18 2011 -0400 @@ -23,6 +23,7 @@ .. toctree:: :maxdepth: 2 + :numbered: packaging-misc packaging.version @@ -41,6 +42,7 @@ .. toctree:: :maxdepth: 2 + :numbered: packaging.dist packaging.command @@ -53,6 +55,7 @@ .. toctree:: :maxdepth: 2 + :numbered: packaging.util packaging.tests.pypi_server diff -r 95c34bce986c -r 900df5732f93 Doc/library/platform.rst --- a/Doc/library/platform.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/platform.rst Mon Jul 25 09:47:18 2011 -0400 @@ -232,6 +232,9 @@ Entries which cannot be determined are set to ``''``. All tuple entries are strings. + Documentation for the underlying :c:func:`gestalt` API is available online at + http://www.rgaros.nl/gestalt/. + Unix Platforms -------------- diff -r 95c34bce986c -r 900df5732f93 Doc/library/pyclbr.rst --- a/Doc/library/pyclbr.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/pyclbr.rst Mon Jul 25 09:47:18 2011 -0400 @@ -45,7 +45,7 @@ The :class:`Class` objects used as values in the dictionary returned by :func:`readmodule` and :func:`readmodule_ex` provide the following data -attributes: +members: .. attribute:: Class.module @@ -89,7 +89,7 @@ ---------------- The :class:`Function` objects used as values in the dictionary returned by -:func:`readmodule_ex` provide the following attributes: +:func:`readmodule_ex` provide the following data members: .. attribute:: Function.module diff -r 95c34bce986c -r 900df5732f93 Doc/library/reprlib.rst --- a/Doc/library/reprlib.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/reprlib.rst Mon Jul 25 09:47:18 2011 -0400 @@ -66,7 +66,7 @@ Repr Objects ------------ -:class:`Repr` instances provide several attributes which can be used to provide +:class:`Repr` instances provide several members which can be used to provide size limits for the representations of different object types, and methods which format specific object types. diff -r 95c34bce986c -r 900df5732f93 Doc/library/shlex.rst --- a/Doc/library/shlex.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/shlex.rst Mon Jul 25 09:47:18 2011 -0400 @@ -24,8 +24,8 @@ Split the string *s* using shell-like syntax. If *comments* is :const:`False` (the default), the parsing of comments in the given string will be disabled - (setting the :attr:`commenters` attribute of the :class:`shlex` instance to - the empty string). This function operates in POSIX mode by default, but uses + (setting the :attr:`commenters` member of the :class:`shlex` instance to the + empty string). This function operates in POSIX mode by default, but uses non-POSIX mode if the *posix* argument is false. .. note:: @@ -44,7 +44,7 @@ from. It must be a file-/stream-like object with :meth:`read` and :meth:`readline` methods, or a string. If no argument is given, input will be taken from ``sys.stdin``. The second optional argument is a filename - string, which sets the initial value of the :attr:`infile` attribute. If the + string, which sets the initial value of the :attr:`infile` member. If the *instream* argument is omitted or equal to ``sys.stdin``, this second argument defaults to "stdin". The *posix* argument defines the operational mode: when *posix* is not true (default), the :class:`shlex` instance will @@ -202,8 +202,8 @@ .. attribute:: shlex.source - This attribute is ``None`` by default. If you assign a string to it, that - string will be recognized as a lexical-level inclusion request similar to the + This member is ``None`` by default. If you assign a string to it, that string + will be recognized as a lexical-level inclusion request similar to the ``source`` keyword in various shells. That is, the immediately following token will opened as a filename and input taken from that stream until EOF, at which point the :meth:`close` method of that stream will be called and the input @@ -213,7 +213,7 @@ .. attribute:: shlex.debug - If this attribute is numeric and ``1`` or more, a :class:`shlex` instance will + If this member is numeric and ``1`` or more, a :class:`shlex` instance will print verbose progress output on its behavior. If you need to use this, you can read the module source code to learn the details. diff -r 95c34bce986c -r 900df5732f93 Doc/library/shutil.rst --- a/Doc/library/shutil.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/shutil.rst Mon Jul 25 09:47:18 2011 -0400 @@ -161,19 +161,9 @@ Recursively move a file or directory to another location. - Uses :func:`os.rename` to perform the move. If it fails, for reasons such as - when *src* and *dst* are on different filesystems or in case of windows where - rename is not supported when *dst* exists, fallback to copying *src* (with - :func:`copy2`) to the *dst* and then remove *src*. + If the destination is on the current filesystem, then simply use rename. + Otherwise, copy src (with :func:`copy2`) to the dst and then remove src. -.. function:: disk_usage(path) - - Return disk usage statistics about the given path as a namedtuple including - total, used and free space expressed in bytes. - - .. versionadded:: 3.3 - - Availability: Unix, Windows. .. exception:: Error diff -r 95c34bce986c -r 900df5732f93 Doc/library/signal.rst --- a/Doc/library/signal.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/signal.rst Mon Jul 25 09:47:18 2011 -0400 @@ -179,8 +179,7 @@ will then be called. Returns nothing. Not on Windows. (See the Unix man page :manpage:`signal(2)`.) - See also :func:`sigwait`, :func:`sigwaitinfo`, :func:`sigtimedwait` and - :func:`sigpending`. + See also :func:`sigwait` and :func:`sigpending`. .. function:: pthread_kill(thread_id, signum) @@ -335,47 +334,7 @@ Availability: Unix (see the man page :manpage:`sigwait(3)` for further information). - See also :func:`pause`, :func:`pthread_sigmask`, :func:`sigpending`, - :func:`sigwaitinfo` and :func:`sigtimedwait`. - - .. versionadded:: 3.3 - - -.. function:: sigwaitinfo(sigset) - - Suspend execution of the calling thread until the delivery of one of the - signals specified in the signal set *sigset*. The function accepts the - signal and removes it from the pending list of signals. If one of the - signals in *sigset* is already pending for the calling thread, the function - will return immediately with information about that signal. The signal - handler is not called for the delivered signal. The function raises an - :exc:`OSError` with error number set to :const:`errno.EINTR` if it is - interrupted by a signal that is not in *sigset*. - - The return value is an object representing the data contained in the - :c:type:`siginfo_t` structure, namely: :attr:`si_signo`, :attr:`si_code`, - :attr:`si_errno`, :attr:`si_pid`, :attr:`si_uid`, :attr:`si_status`, - :attr:`si_band`. - - Availability: Unix (see the man page :manpage:`sigwaitinfo(2)` for further - information). - - See also :func:`pause`, :func:`sigwait` and :func:`sigtimedwait`. - - .. versionadded:: 3.3 - - -.. function:: sigtimedwait(sigset, (timeout_sec, timeout_nsec)) - - Like :func:`sigtimedwait`, but takes a tuple of ``(seconds, nanoseconds)`` - as an additional argument specifying a timeout. If both *timeout_sec* and - *timeout_nsec* are specified as :const:`0`, a poll is performed. Returns - :const:`None` if a timeout occurs. - - Availability: Unix (see the man page :manpage:`sigtimedwait(2)` for further - information). - - See also :func:`pause`, :func:`sigwait` and :func:`sigwaitinfo`. + See also :func:`pause`, :func:`pthread_sigmask` and :func:`sigpending`. .. versionadded:: 3.3 diff -r 95c34bce986c -r 900df5732f93 Doc/library/smtplib.rst --- a/Doc/library/smtplib.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/smtplib.rst Mon Jul 25 09:47:18 2011 -0400 @@ -348,32 +348,21 @@ .. versionchanged:: 3.2 *msg* may be a byte string. -.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, \ - mail_options=[], rcpt_options=[]) +.. method:: SMTP.send_message(msg, from_addr=None, to_addrs=None, mail_options=[], rcpt_options=[]) This is a convenience method for calling :meth:`sendmail` with the message represented by an :class:`email.message.Message` object. The arguments have the same meaning as for :meth:`sendmail`, except that *msg* is a ``Message`` object. - If *from_addr* is ``None`` or *to_addrs* is ``None``, ``send_message`` fills - those arguments with addresses extracted from the headers of *msg* as - specified in :rfc:`2822`\: *from_addr* is set to the :mailheader:`Sender` - field if it is present, and otherwise to the :mailheader:`From` field. - *to_adresses* combines the values (if any) of the :mailheader:`To`, - :mailheader:`Cc`, and :mailheader:`Bcc` fields from *msg*. If exactly one - set of :mailheader:`Resent-*` headers appear in the message, the regular - headers are ignored and the :mailheader:`Resent-*` headers are used instead. - If the message contains more than one set of :mailheader:`Resent-*` headers, - a :exc:`ValueError` is raised, since there is no way to unambiguously detect - the most recent set of :mailheader:`Resent-` headers. - - ``send_message`` serializes *msg* using + If *from_addr* is ``None``, ``send_message`` sets its value to the value of + the :mailheader:`From` header from *msg*. If *to_addrs* is ``None``, + ``send_message`` combines the values (if any) of the :mailheader:`To`, + :mailheader:`CC`, and :mailheader:`Bcc` fields from *msg*. Regardless of + the values of *from_addr* and *to_addrs*, ``send_message`` deletes any Bcc + field from *msg*. It then serializes *msg* using :class:`~email.generator.BytesGenerator` with ``\r\n`` as the *linesep*, and - calls :meth:`sendmail` to transmit the resulting message. Regardless of the - values of *from_addr* and *to_addrs*, ``send_message`` does not transmit any - :mailheader:`Bcc` or :mailheader:`Resent-Bcc` headers that may appear - in *msg*. + calls :meth:`sendmail` to transmit the resulting message. .. versionadded:: 3.2 diff -r 95c34bce986c -r 900df5732f93 Doc/library/socketserver.rst --- a/Doc/library/socketserver.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/socketserver.rst Mon Jul 25 09:47:18 2011 -0400 @@ -81,7 +81,7 @@ class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass The mix-in class must come first, since it overrides a method defined in -:class:`UDPServer`. Setting the various attributes also change the +:class:`UDPServer`. Setting the various member variables also changes the behavior of the underlying server mechanism. To implement a service, you must derive a class from :class:`BaseRequestHandler` diff -r 95c34bce986c -r 900df5732f93 Doc/library/sqlite3.rst --- a/Doc/library/sqlite3.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/sqlite3.rst Mon Jul 25 09:47:18 2011 -0400 @@ -615,43 +615,43 @@ Let's assume we initialize a table as in the example given above:: - conn = sqlite3.connect(":memory:") - c = conn.cursor() - c.execute('''create table stocks - (date text, trans text, symbol text, - qty real, price real)''') - c.execute("""insert into stocks - values ('2006-01-05','BUY','RHAT',100,35.14)""") - conn.commit() - c.close() + conn = sqlite3.connect(":memory:") + c = conn.cursor() + c.execute('''create table stocks + (date text, trans text, symbol text, + qty real, price real)''') + c.execute("""insert into stocks + values ('2006-01-05','BUY','RHAT',100,35.14)""") + conn.commit() + c.close() Now we plug :class:`Row` in:: - >>> conn.row_factory = sqlite3.Row - >>> c = conn.cursor() - >>> c.execute('select * from stocks') - - >>> r = c.fetchone() - >>> type(r) - - >>> tuple(r) - ('2006-01-05', 'BUY', 'RHAT', 100.0, 35.14) - >>> len(r) - 5 - >>> r[2] - 'RHAT' - >>> r.keys() - ['date', 'trans', 'symbol', 'qty', 'price'] - >>> r['qty'] - 100.0 - >>> for member in r: - ... print(member) - ... - 2006-01-05 - BUY - RHAT - 100.0 - 35.14 + >>> conn.row_factory = sqlite3.Row + >>> c = conn.cursor() + >>> c.execute('select * from stocks') + + >>> r = c.fetchone() + >>> type(r) + + >>> tuple(r) + ('2006-01-05', 'BUY', 'RHAT', 100.0, 35.14) + >>> len(r) + 5 + >>> r[2] + 'RHAT' + >>> r.keys() + ['date', 'trans', 'symbol', 'qty', 'price'] + >>> r['qty'] + 100.0 + >>> for member in r: + ... print(member) + ... + 2006-01-05 + BUY + RHAT + 100.0 + 35.14 .. _sqlite3-types: @@ -902,7 +902,6 @@ .. rubric:: Footnotes .. [#f1] The sqlite3 module is not built with loadable extension support by - default, because some platforms (notably Mac OS X) have SQLite - libraries which are compiled without this feature. To get loadable - extension support, you must pass --enable-loadable-sqlite-extensions to - configure. + default, because some platforms (notably Mac OS X) have SQLite libraries which + are compiled without this feature. To get loadable extension support, you must + pass --enable-loadable-sqlite-extensions to configure. diff -r 95c34bce986c -r 900df5732f93 Doc/library/ssl.rst --- a/Doc/library/ssl.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/ssl.rst Mon Jul 25 09:47:18 2011 -0400 @@ -386,13 +386,6 @@ .. versionadded:: 3.2 -.. data:: CHANNEL_BINDING_TYPES - - List of supported TLS channel binding types. Strings in this list - can be used as arguments to :meth:`SSLSocket.get_channel_binding`. - - .. versionadded:: 3.3 - .. data:: OPENSSL_VERSION The version string of the OpenSSL library loaded by the interpreter:: @@ -447,16 +440,27 @@ the same limitation) - :meth:`~socket.socket.shutdown()` -However, since the SSL (and TLS) protocol has its own framing atop -of TCP, the SSL sockets abstraction can, in certain respects, diverge from -the specification of normal, OS-level sockets. See especially the -:ref:`notes on non-blocking sockets `. - -SSL sockets also have the following additional methods and attributes: +They also have the following additional methods and attributes: .. method:: SSLSocket.do_handshake() - Perform the SSL setup handshake. + Performs the SSL setup handshake. If the socket is non-blocking, this method + may raise :exc:`SSLError` with the value of the exception instance's + ``args[0]`` being either :const:`SSL_ERROR_WANT_READ` or + :const:`SSL_ERROR_WANT_WRITE`, and should be called again until it stops + raising those exceptions. Here's an example of how to do that:: + + while True: + try: + sock.do_handshake() + break + except ssl.SSLError as err: + if err.args[0] == ssl.SSL_ERROR_WANT_READ: + select.select([sock], [], []) + elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: + select.select([], [sock], []) + else: + raise .. method:: SSLSocket.getpeercert(binary_form=False) @@ -502,18 +506,6 @@ version of the SSL protocol that defines its use, and the number of secret bits being used. If no connection has been established, returns ``None``. -.. method:: SSLSocket.get_channel_binding(cb_type="tls-unique") - - Get channel binding data for current connection, as a bytes object. Returns - ``None`` if not connected or the handshake has not been completed. - - The *cb_type* parameter allow selection of the desired channel binding - type. Valid channel binding types are listed in the - :data:`CHANNEL_BINDING_TYPES` list. Currently only the 'tls-unique' channel - binding, defined by :rfc:`5929`, is supported. :exc:`ValueError` will be - raised if an unsupported channel binding type is requested. - - .. versionadded:: 3.3 .. method:: SSLSocket.unwrap() @@ -957,42 +949,6 @@ the sockets in non-blocking mode and use an event loop). -.. _ssl-nonblocking: - -Notes on non-blocking sockets ------------------------------ - -When working with non-blocking sockets, there are several things you need -to be aware of: - -- Calling :func:`~select.select` tells you that the OS-level socket can be - read from (or written to), but it does not imply that there is sufficient - data at the upper SSL layer. For example, only part of an SSL frame might - have arrived. Therefore, you must be ready to handle :meth:`SSLSocket.recv` - and :meth:`SSLSocket.send` failures, and retry after another call to - :func:`~select.select`. - - (of course, similar provisions apply when using other primitives such as - :func:`~select.poll`) - -- The SSL handshake itself will be non-blocking: the - :meth:`SSLSocket.do_handshake` method has to be retried until it returns - successfully. Here is a synopsis using :func:`~select.select` to wait for - the socket's readiness:: - - while True: - try: - sock.do_handshake() - break - except ssl.SSLError as err: - if err.args[0] == ssl.SSL_ERROR_WANT_READ: - select.select([sock], [], []) - elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: - select.select([], [sock], []) - else: - raise - - .. _ssl-security: Security considerations diff -r 95c34bce986c -r 900df5732f93 Doc/library/stat.rst --- a/Doc/library/stat.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/stat.rst Mon Jul 25 09:47:18 2011 -0400 @@ -309,19 +309,11 @@ .. data:: UF_OPAQUE - The directory is opaque when viewed through a union stack. + The file may not be renamed or deleted. .. data:: UF_NOUNLINK - The file may not be renamed or deleted. - -.. data:: UF_COMPRESSED - - The file is stored compressed (Mac OS X 10.6+). - -.. data:: UF_HIDDEN - - The file should not be displayed in a GUI (Mac OS X 10.5+). + The directory is opaque when viewed through a union stack. .. data:: SF_ARCHIVED diff -r 95c34bce986c -r 900df5732f93 Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/stdtypes.rst Mon Jul 25 09:47:18 2011 -0400 @@ -2578,7 +2578,7 @@ foo`` does not require a module object named *foo* to exist, rather it requires an (external) *definition* for a module named *foo* somewhere.) -A special attribute of every module is :attr:`__dict__`. This is the dictionary +A special member of every module is :attr:`__dict__`. This is the dictionary containing the module's symbol table. Modifying this dictionary will actually change the module's symbol table, but direct assignment to the :attr:`__dict__` attribute is not possible (you can write ``m.__dict__['a'] = 1``, which defines diff -r 95c34bce986c -r 900df5732f93 Doc/library/struct.rst --- a/Doc/library/struct.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/struct.rst Mon Jul 25 09:47:18 2011 -0400 @@ -240,11 +240,10 @@ For the ``'s'`` format character, the count is interpreted as the length of the bytes, not a repeat count like for the other format characters; for example, ``'10s'`` means a single 10-byte string, while ``'10c'`` means 10 characters. -If a count is not given, it defaults to 1. For packing, the string is -truncated or padded with null bytes as appropriate to make it fit. For -unpacking, the resulting bytes object always has exactly the specified number -of bytes. As a special case, ``'0s'`` means a single, empty string (while -``'0c'`` means 0 characters). +For packing, the string is truncated or padded with null bytes as appropriate to +make it fit. For unpacking, the resulting bytes object always has exactly the +specified number of bytes. As a special case, ``'0s'`` means a single, empty +string (while ``'0c'`` means 0 characters). When packing a value ``x`` using one of the integer formats (``'b'``, ``'B'``, ``'h'``, ``'H'``, ``'i'``, ``'I'``, ``'l'``, ``'L'``, diff -r 95c34bce986c -r 900df5732f93 Doc/library/subprocess.rst --- a/Doc/library/subprocess.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/subprocess.rst Mon Jul 25 09:47:18 2011 -0400 @@ -567,39 +567,38 @@ .. attribute:: dwFlags - A bit field that determines whether certain :class:`STARTUPINFO` - attributes are used when the process creates a window. :: + A bit field that determines whether certain :class:`STARTUPINFO` members + are used when the process creates a window. :: si = subprocess.STARTUPINFO() si.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW .. attribute:: hStdInput - If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this attribute - is the standard input handle for the process. If - :data:`STARTF_USESTDHANDLES` is not specified, the default for standard - input is the keyboard buffer. + If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this member is + the standard input handle for the process. If :data:`STARTF_USESTDHANDLES` + is not specified, the default for standard input is the keyboard buffer. .. attribute:: hStdOutput - If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this attribute - is the standard output handle for the process. Otherwise, this attribute - is ignored and the default for standard output is the console window's + If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this member is + the standard output handle for the process. Otherwise, this member is + ignored and the default for standard output is the console window's buffer. .. attribute:: hStdError - If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this attribute - is the standard error handle for the process. Otherwise, this attribute is + If :attr:`dwFlags` specifies :data:`STARTF_USESTDHANDLES`, this member is + the standard error handle for the process. Otherwise, this member is ignored and the default for standard error is the console window's buffer. .. attribute:: wShowWindow - If :attr:`dwFlags` specifies :data:`STARTF_USESHOWWINDOW`, this attribute + If :attr:`dwFlags` specifies :data:`STARTF_USESHOWWINDOW`, this member can be any of the values that can be specified in the ``nCmdShow`` parameter for the `ShowWindow `__ - function, except for ``SW_SHOWDEFAULT``. Otherwise, this attribute is + function, except for ``SW_SHOWDEFAULT``. Otherwise, this member is ignored. :data:`SW_HIDE` is provided for this attribute. It is used when @@ -633,12 +632,12 @@ .. data:: STARTF_USESTDHANDLES Specifies that the :attr:`STARTUPINFO.hStdInput`, - :attr:`STARTUPINFO.hStdOutput`, and :attr:`STARTUPINFO.hStdError` attributes + :attr:`STARTUPINFO.hStdOutput`, and :attr:`STARTUPINFO.hStdError` members contain additional information. .. data:: STARTF_USESHOWWINDOW - Specifies that the :attr:`STARTUPINFO.wShowWindow` attribute contains + Specifies that the :attr:`STARTUPINFO.wShowWindow` member contains additional information. .. data:: CREATE_NEW_CONSOLE diff -r 95c34bce986c -r 900df5732f93 Doc/library/sys.rst --- a/Doc/library/sys.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/sys.rst Mon Jul 25 09:47:18 2011 -0400 @@ -705,12 +705,6 @@ For Unix systems, this is the lowercased OS name as returned by ``uname -s`` with the first part of the version as returned by ``uname -r`` appended, e.g. ``'sunos5'`` or ``'linux2'``, *at the time when Python was built*. - Unless you want to test for a specific system version, it is therefore - recommended to use the following idiom:: - - if sys.platform.startswith('linux'): - # Linux-specific code here... - For other systems, the values are: ================ =========================== @@ -723,12 +717,6 @@ OS/2 EMX ``'os2emx'`` ================ =========================== - .. seealso:: - :attr:`os.name` has a coarser granularity. :func:`os.uname` gives - system-dependent version information. - - The :mod:`platform` module provides detailed checks for the - system's identity. .. data:: prefix diff -r 95c34bce986c -r 900df5732f93 Doc/library/tempfile.rst --- a/Doc/library/tempfile.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/tempfile.rst Mon Jul 25 09:47:18 2011 -0400 @@ -25,7 +25,7 @@ Also, all the user-callable functions now take additional arguments which allow direct control over the location and name of temporary files. It is -no longer necessary to use the global *tempdir* variable. +no longer necessary to use the global *tempdir* and *template* variables. To maintain backward compatibility, the argument order is somewhat odd; it is recommended to use keyword arguments for clarity. @@ -60,7 +60,7 @@ This function operates exactly as :func:`TemporaryFile` does, except that the file is guaranteed to have a visible name in the file system (on Unix, the directory entry is not unlinked). That name can be retrieved - from the :attr:`name` attribute of the file object. Whether the name can be + from the :attr:`name` member of the file object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). If *delete* is true (the default), the file is @@ -96,7 +96,7 @@ of the temporary directory object), the newly created temporary directory and all its contents are removed from the filesystem. - The directory name can be retrieved from the :attr:`name` attribute + The directory name can be retrieved from the :attr:`name` member of the returned object. The directory can be explicitly cleaned up by calling the diff -r 95c34bce986c -r 900df5732f93 Doc/library/urllib.request.rst --- a/Doc/library/urllib.request.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/urllib.request.rst Mon Jul 25 09:47:18 2011 -0400 @@ -105,7 +105,7 @@ can be imported), :class:`HTTPSHandler` will also be added. A :class:`BaseHandler` subclass may also change its :attr:`handler_order` - attribute to modify its position in the handlers list. + member variable to modify its position in the handlers list. .. function:: pathname2url(path) @@ -323,11 +323,6 @@ A catch-all class to handle unknown URLs. -.. class:: HTTPErrorProcessor() - - Process HTTP error responses. - - .. _request-objects: Request Objects @@ -551,7 +546,7 @@ Remove any parents. -The following attribute and methods should only be used by classes derived from +The following members and methods should only be used by classes derived from :class:`BaseHandler`. .. note:: @@ -931,7 +926,7 @@ HTTPErrorProcessor Objects -------------------------- -.. method:: HTTPErrorProcessor.http_response() +.. method:: HTTPErrorProcessor.unknown_open() Process HTTP error responses. @@ -943,13 +938,6 @@ :exc:`HTTPError` if no other handler handles the error. -.. method:: HTTPErrorProcessor.https_response() - - Process HTTPS error responses. - - The behavior is same as :meth:`http_response`. - - .. _urllib-request-examples: Examples diff -r 95c34bce986c -r 900df5732f93 Doc/library/warnings.rst --- a/Doc/library/warnings.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/warnings.rst Mon Jul 25 09:47:18 2011 -0400 @@ -40,10 +40,6 @@ message by calling :func:`formatwarning`, which is also available for use by custom implementations. -.. seealso:: - :func:`logging.captureWarnings` allows you to handle all warnings with - the standard logging infrastructure. - .. _warning-categories: @@ -339,7 +335,8 @@ Write a warning to a file. The default implementation calls ``formatwarning(message, category, filename, lineno, line)`` and writes the resulting string to *file*, which defaults to ``sys.stderr``. You may replace - this function with any callable by assigning to ``warnings.showwarning``. + this function with an alternative implementation by assigning to + ``warnings.showwarning``. *line* is a line of source code to be included in the warning message; if *line* is not supplied, :func:`showwarning` will try to read the line specified by *filename* and *lineno*. diff -r 95c34bce986c -r 900df5732f93 Doc/library/xdrlib.rst --- a/Doc/library/xdrlib.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/xdrlib.rst Mon Jul 25 09:47:18 2011 -0400 @@ -260,7 +260,7 @@ .. exception:: Error - The base exception class. :exc:`Error` has a single public attribute + The base exception class. :exc:`Error` has a single public data member :attr:`msg` containing the description of the error. diff -r 95c34bce986c -r 900df5732f93 Doc/library/xmlrpc.client.rst --- a/Doc/library/xmlrpc.client.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/xmlrpc.client.rst Mon Jul 25 09:47:18 2011 -0400 @@ -136,7 +136,7 @@ :class:`Fault` or :class:`ProtocolError` object indicating an error. Servers that support the XML introspection API support some common methods -grouped under the reserved :attr:`system` attribute: +grouped under the reserved :attr:`system` member: .. method:: ServerProxy.system.listMethods() @@ -310,7 +310,7 @@ ------------- A :class:`Fault` object encapsulates the content of an XML-RPC fault tag. Fault -objects have the following attributes: +objects have the following members: .. attribute:: Fault.faultCode @@ -359,7 +359,7 @@ A :class:`ProtocolError` object describes a protocol error in the underlying transport layer (such as a 404 'not found' error if the server named by the URI -does not exist). It has the following attributes: +does not exist). It has the following members: .. attribute:: ProtocolError.url diff -r 95c34bce986c -r 900df5732f93 Doc/library/zipimport.rst --- a/Doc/library/zipimport.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/library/zipimport.rst Mon Jul 25 09:47:18 2011 -0400 @@ -9,11 +9,11 @@ This module adds the ability to import Python modules (:file:`\*.py`, :file:`\*.py[co]`) and packages from ZIP-format archives. It is usually not needed to use the :mod:`zipimport` module explicitly; it is automatically used -by the built-in :keyword:`import` mechanism for :data:`sys.path` items that are paths +by the built-in :keyword:`import` mechanism for ``sys.path`` items that are paths to ZIP archives. -Typically, :data:`sys.path` is a list of directory names as strings. This module -also allows an item of :data:`sys.path` to be a string naming a ZIP file archive. +Typically, ``sys.path`` is a list of directory names as strings. This module +also allows an item of ``sys.path`` to be a string naming a ZIP file archive. The ZIP archive can contain a subdirectory structure to support package imports, and a path within the archive can be specified to only import from a subdirectory. For example, the path :file:`/tmp/example.zip/lib/` would only diff -r 95c34bce986c -r 900df5732f93 Doc/packaging/builtdist.rst --- a/Doc/packaging/builtdist.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/packaging/builtdist.rst Mon Jul 25 09:47:18 2011 -0400 @@ -283,7 +283,7 @@ Which folders are available depends on the exact Windows version, and probably also the configuration. For details refer to Microsoft's documentation of the - :c:func:`SHGetSpecialFolderPath` function. + c:function:`SHGetSpecialFolderPath` function. .. function:: create_shortcut(target, description, filename[, arguments[, workdir[, iconpath[, iconindex]]]]) diff -r 95c34bce986c -r 900df5732f93 Doc/packaging/commandref.rst --- a/Doc/packaging/commandref.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/packaging/commandref.rst Mon Jul 25 09:47:18 2011 -0400 @@ -57,7 +57,7 @@ .. cmdoption:: --suite=NAME, -s NAME Specify the test suite (or module, class, or method) to be run. The default - for this option can be set by in the project's :file:`setup.cfg` file: + for this option can be set by in the project's :file:`setup.cfg` file:: .. code-block:: cfg diff -r 95c34bce986c -r 900df5732f93 Doc/packaging/setupscript.rst --- a/Doc/packaging/setupscript.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/packaging/setupscript.rst Mon Jul 25 09:47:18 2011 -0400 @@ -70,7 +70,7 @@ promising that the Distutils will find a file :file:`foo/__init__.py` (which might be spelled differently on your system, but you get the idea) relative to the directory where your setup script lives. If you break this promise, the -Distutils will issue a warning but still process the broken package anyway. +Distutils will issue a warning but still process the broken package anyways. If you use a different convention to lay out your source directory, that's no problem: you just have to supply the :option:`package_dir` option to tell the diff -r 95c34bce986c -r 900df5732f93 Doc/reference/compound_stmts.rst --- a/Doc/reference/compound_stmts.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/reference/compound_stmts.rst Mon Jul 25 09:47:18 2011 -0400 @@ -615,9 +615,8 @@ .. rubric:: Footnotes -.. [#] The exception is propagated to the invocation stack unless - there is a :keyword:`finally` clause which happens to raise another - exception. That new exception causes the old one to be lost. +.. [#] The exception is propagated to the invocation stack only if there is no + :keyword:`finally` clause that negates the exception. .. [#] Currently, control "flows off the end" except in the case of an exception or the execution of a :keyword:`return`, :keyword:`continue`, or diff -r 95c34bce986c -r 900df5732f93 Doc/tools/sphinxext/susp-ignored.csv --- a/Doc/tools/sphinxext/susp-ignored.csv Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/tools/sphinxext/susp-ignored.csv Mon Jul 25 09:47:18 2011 -0400 @@ -46,8 +46,8 @@ library/functions,,:stop,a[start:stop:step] library/hotshot,,:lineno,"ncalls tottime percall cumtime percall filename:lineno(function)" library/httplib,,:port,host:port -library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS" -library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS" +library/imaplib,,:MM,"""DD-Mmm-YYYY HH:MM:SS +HHMM""" +library/imaplib,,:SS,"""DD-Mmm-YYYY HH:MM:SS +HHMM""" library/itertools,,:stop,elements from seq[start:stop:step] library/itertools,,:step,elements from seq[start:stop:step] library/linecache,,:sys,"sys:x:3:3:sys:/dev:/bin/sh" @@ -495,26 +495,3 @@ library/pprint,209,::,"'Programming Language :: Python :: 2.7'," library/pprint,209,::,"'Topic :: Software Development :: Libraries'," library/pprint,209,::,"'Topic :: Software Development :: Libraries :: Python Modules']," -library/packaging.dist,,:action,http://pypi.python.org/pypi?:action=list_classifiers -packaging/examples,,`,This is the description of the ``foobar`` project. -packaging/setupcfg,,::,Development Status :: 3 - Alpha -packaging/setupcfg,,::,License :: OSI Approved :: Mozilla Public License 1.1 (MPL 1.1) -packaging/setupscript,,::,"'Development Status :: 4 - Beta'," -packaging/setupscript,,::,"'Environment :: Console'," -packaging/setupscript,,::,"'Environment :: Web Environment'," -packaging/setupscript,,::,"'Intended Audience :: End Users/Desktop'," -packaging/setupscript,,::,"'Intended Audience :: Developers'," -packaging/setupscript,,::,"'Intended Audience :: System Administrators'," -packaging/setupscript,,::,"'License :: OSI Approved :: Python Software Foundation License'," -packaging/setupscript,,::,"'Operating System :: MacOS :: MacOS X'," -packaging/setupscript,,::,"'Operating System :: Microsoft :: Windows'," -packaging/setupscript,,::,"'Operating System :: POSIX'," -packaging/setupscript,,::,"'Programming Language :: Python'," -packaging/setupscript,,::,"'Topic :: Communications :: Email'," -packaging/setupscript,,::,"'Topic :: Office/Business'," -packaging/setupscript,,::,"'Topic :: Software Development :: Bug Tracking'," -packaging/tutorial,,::,1) License :: OSI Approved :: GNU General Public License (GPL) -packaging/tutorial,,::,2) License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) -packaging/tutorial,,::,Type the number of the license you wish to use or ? to try again:: 1 -packaging/tutorial,,::,classifier = Development Status :: 3 - Alpha -packaging/tutorial,,::,License :: OSI Approved :: GNU General Public License (GPL) diff -r 95c34bce986c -r 900df5732f93 Doc/tutorial/classes.rst --- a/Doc/tutorial/classes.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/tutorial/classes.rst Mon Jul 25 09:47:18 2011 -0400 @@ -595,28 +595,6 @@ without regard to the syntactic position of the identifier, as long as it occurs within the definition of a class. -Name mangling is helpful for letting subclasses override methods without -breaking intraclass method calls. For example:: - - class Mapping: - def __init__(self, iterable): - self.items_list = [] - self.__update(iterable) - - def update(self, iterable): - for item in iterable: - self.items_list.append(item) - - __update = update # private copy of original update() method - - class MappingSubclass(Mapping): - - def update(self, keys, values): - # provides new signature for update() - # but does not break __init__() - for item in zip(keys, values): - self.items_list.append(item) - Note that the mangling rules are designed mostly to avoid accidents; it still is possible to access or modify a variable that is considered private. This can even be useful in special circumstances, such as in the debugger. diff -r 95c34bce986c -r 900df5732f93 Doc/whatsnew/2.5.rst --- a/Doc/whatsnew/2.5.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/whatsnew/2.5.rst Mon Jul 25 09:47:18 2011 -0400 @@ -1459,7 +1459,7 @@ On FreeBSD, the :func:`os.stat` function now returns times with nanosecond resolution, and the returned object now has :attr:`st_gen` and - :attr:`st_birthtime`. The :attr:`st_flags` attribute is also available, if the + :attr:`st_birthtime`. The :attr:`st_flags` member is also available, if the platform supports it. (Contributed by Antti Louko and Diego Pettenò.) .. (Patch 1180695, 1212117) diff -r 95c34bce986c -r 900df5732f93 Doc/whatsnew/3.3.rst --- a/Doc/whatsnew/3.3.rst Tue Jul 26 09:37:46 2011 +0300 +++ b/Doc/whatsnew/3.3.rst Mon Jul 25 09:47:18 2011 -0400 @@ -68,37 +68,6 @@ * Stub -codecs ------- - -Multibyte CJK decoders now resynchronize faster. They only ignore the first -byte of an invalid byte sequence. For example, ``b'\xff\n'.decode('gb2312', -'replace')`` now returns a ``\n`` after the replacement character. - -(:issue:`12016`) - -Don't reset incremental encoders of CJK codecs at each call to their encode() -method anymore. For example:: - - $ ./python -q - >>> import codecs - >>> encoder = codecs.getincrementalencoder('hz')('strict') - >>> b''.join(encoder.encode(x) for x in '\u52ff\u65bd\u65bc\u4eba\u3002 Bye.') - b'~{NpJ)l6HK!#~} Bye.' - -This example gives ``b'~{Np~}~{J)~}~{l6~}~{HK~}~{!#~} Bye.'`` with older Python -versions. - -(:issue:`12100`) - -curses ------- - -The :class:`curses.window` class has a new :class:`~curses.window.get_wch` -method to a wide character. Patch by Iñigo Serna. - -(:issue:`6755`) - faulthandler ------------ @@ -125,10 +94,10 @@ connection when done:: >>> from nntplib import NNTP - >>> with NNTP('news.gmane.org') as n: + >>> with nntplib.NNTP('news.gmane.org') as n: ... n.group('gmane.comp.python.committers') ... - ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers') + ('211 1454 1 1454 gmane.comp.python.committers', '1454', '1', '1454', 'gmane.comp.python.committers') >>> (Contributed by Giampaolo Rodolà in :issue:`9795`) @@ -200,10 +169,6 @@ * :func:`~signal.pthread_kill`: send a signal to a thread ; * :func:`~signal.sigpending`: examine pending functions ; * :func:`~signal.sigwait`: wait a signal. - * :func:`~signal.sigwaitinfo`: wait for a signal, returning detailed - information about it. - * :func:`~signal.sigtimedwait`: like :func:`~signal.sigwaitinfo` but with a - timeout. * The signal handler writes the signal number as a single byte instead of a nul byte into the wakeup file descriptor. So it is possible to wait more @@ -223,26 +188,6 @@ * :func:`~ssl.RAND_pseudo_bytes`: generate pseudo-random bytes. -ftplib ------- - -The :class:`~ftplib.FTP_TLS` class now provides a new -:func:`~ftplib.FTP_TLS.ccc` function to revert control channel back to -plaintex. This can be useful to take advantage of firewalls that know how to -handle NAT with non-secure FTP without opening fixed ports. - -(Contributed by Giampaolo Rodolà in :issue:`12139`) - - -shutil ------- - -The :mod:`shutil` module has a new :func:`~shutil.disk_usage` function providing total, -used and free disk space statistics. - -(Contributed by Giampaolo Rodolà in :issue:`12442`) - - Optimizations ============= diff -r 95c34bce986c -r 900df5732f93 Include/Python.h --- a/Include/Python.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Include/Python.h Mon Jul 25 09:47:18 2011 -0400 @@ -151,6 +151,11 @@ #define Py_file_input 257 #define Py_eval_input 258 +#ifdef HAVE_PTH +/* GNU pth user-space thread support */ +#include +#endif + /* Define macros for inline documentation. */ #define PyDoc_VAR(name) static char name[] #define PyDoc_STRVAR(name,str) PyDoc_VAR(name) = PyDoc_STR(str) diff -r 95c34bce986c -r 900df5732f93 Include/code.h --- a/Include/code.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Include/code.h Mon Jul 25 09:47:18 2011 -0400 @@ -22,7 +22,6 @@ PyObject *co_freevars; /* tuple of strings (free variable names) */ PyObject *co_cellvars; /* tuple of strings (cell variable names) */ /* The rest doesn't count for hash or comparisons */ - unsigned char *co_cell2arg; /* Maps cell vars which are arguments. */ PyObject *co_filename; /* unicode (where it was loaded from) */ PyObject *co_name; /* unicode (name, for reference) */ int co_firstlineno; /* first source line number */ @@ -58,11 +57,6 @@ #define CO_FUTURE_BARRY_AS_BDFL 0x40000 -/* This value is found in the co_cell2arg array when the associated cell - variable does not correspond to an argument. The maximum number of - arguments is 255 (indexed up to 254), so 255 work as a special flag.*/ -#define CO_CELL_NOT_AN_ARG 255 - /* This should be defined if a future statement modifies the syntax. For example, when a keyword is added. */ diff -r 95c34bce986c -r 900df5732f93 Include/opcode.h --- a/Include/opcode.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Include/opcode.h Mon Jul 25 09:47:18 2011 -0400 @@ -7,6 +7,7 @@ /* Instruction opcodes for compiled code */ +#define STOP_CODE 0 #define POP_TOP 1 #define ROT_TWO 2 #define ROT_THREE 3 diff -r 95c34bce986c -r 900df5732f93 Include/patchlevel.h --- a/Include/patchlevel.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Include/patchlevel.h Mon Jul 25 09:47:18 2011 -0400 @@ -23,7 +23,7 @@ #define PY_RELEASE_SERIAL 0 /* Version as a string */ -#define PY_VERSION "3.3.0a0" +#define PY_VERSION "3.3a0" /*--end constants--*/ /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2. diff -r 95c34bce986c -r 900df5732f93 Include/unicodeobject.h --- a/Include/unicodeobject.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Include/unicodeobject.h Mon Jul 25 09:47:18 2011 -0400 @@ -109,10 +109,6 @@ # endif #endif -#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) -# define HAVE_MBCS -#endif - #ifdef HAVE_WCHAR_H /* Work around a cosmetic bug in BSDI 4.x wchar.h; thanks to Thomas Wouters */ # ifdef _HAVE_BSDI @@ -1166,7 +1162,7 @@ ); #endif -#ifdef HAVE_MBCS +#ifdef MS_WIN32 /* --- MBCS codecs for Windows -------------------------------------------- */ @@ -1195,7 +1191,7 @@ ); #endif -#endif /* HAVE_MBCS */ +#endif /* MS_WIN32 */ /* --- Decimal Encoder ---------------------------------------------------- */ diff -r 95c34bce986c -r 900df5732f93 Lib/_pyio.py --- a/Lib/_pyio.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/_pyio.py Mon Jul 25 09:47:18 2011 -0400 @@ -1478,7 +1478,7 @@ _CHUNK_SIZE = 2048 def __init__(self, buffer, encoding=None, errors=None, newline=None, - line_buffering=False, write_through=False): + line_buffering=False): if newline is not None and not isinstance(newline, str): raise TypeError("illegal newline type: %r" % (type(newline),)) if newline not in (None, "", "\n", "\r", "\r\n"): @@ -1521,7 +1521,6 @@ self._decoded_chars_used = 0 # offset into _decoded_chars for read() self._snapshot = None # info for reconstructing decoder state self._seekable = self._telling = self.buffer.seekable() - self._has_read1 = hasattr(self.buffer, 'read1') self._b2cratio = 0.0 if self._seekable and self.writable(): @@ -1688,10 +1687,7 @@ # len(dec_buffer) bytes ago with decoder state (b'', dec_flags). # Read a chunk, decode it, and put the result in self._decoded_chars. - if self._has_read1: - input_chunk = self.buffer.read1(self._CHUNK_SIZE) - else: - input_chunk = self.buffer.read(self._CHUNK_SIZE) + input_chunk = self.buffer.read1(self._CHUNK_SIZE) eof = not input_chunk decoded_chars = self._decoder.decode(input_chunk, eof) self._set_decoded_chars(decoded_chars) diff -r 95c34bce986c -r 900df5732f93 Lib/ast.py --- a/Lib/ast.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/ast.py Mon Jul 25 09:47:18 2011 -0400 @@ -25,6 +25,7 @@ :license: Python License. """ from _ast import * +from _ast import __version__ def parse(source, filename='', mode='exec'): diff -r 95c34bce986c -r 900df5732f93 Lib/asyncore.py --- a/Lib/asyncore.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/asyncore.py Mon Jul 25 09:47:18 2011 -0400 @@ -132,8 +132,7 @@ is_w = obj.writable() if is_r: r.append(fd) - # accepting sockets should not be writable - if is_w and not obj.accepting: + if is_w: w.append(fd) if is_r or is_w: e.append(fd) @@ -180,8 +179,7 @@ flags = 0 if obj.readable(): flags |= select.POLLIN | select.POLLPRI - # accepting sockets should not be writable - if obj.writable() and not obj.accepting: + if obj.writable(): flags |= select.POLLOUT if flags: # Only check for exceptions if object was either readable diff -r 95c34bce986c -r 900df5732f93 Lib/binhex.py --- a/Lib/binhex.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/binhex.py Mon Jul 25 09:47:18 2011 -0400 @@ -23,6 +23,7 @@ # import io import os +import sys import struct import binascii diff -r 95c34bce986c -r 900df5732f93 Lib/cgi.py --- a/Lib/cgi.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/cgi.py Mon Jul 25 09:47:18 2011 -0400 @@ -76,7 +76,7 @@ send an error message). """ - global log, logfile, logfp + global logfp, log if logfile and not logfp: try: logfp = open(logfile, "a") @@ -96,15 +96,6 @@ """Dummy function, assigned to log when logging is disabled.""" pass -def closelog(): - """Close the log file.""" - global log, logfile, logfp - logfile = '' - if logfp: - logfp.close() - logfp = None - log = initlog - log = initlog # The current logging function diff -r 95c34bce986c -r 900df5732f93 Lib/cgitb.py --- a/Lib/cgitb.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/cgitb.py Mon Jul 25 09:47:18 2011 -0400 @@ -31,6 +31,7 @@ import time import tokenize import traceback +import types def reset(): """Return a string that resets the CGI and browser to a known state.""" diff -r 95c34bce986c -r 900df5732f93 Lib/concurrent/futures/process.py --- a/Lib/concurrent/futures/process.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/concurrent/futures/process.py Mon Jul 25 09:47:18 2011 -0400 @@ -50,7 +50,7 @@ from concurrent.futures import _base import queue import multiprocessing -from multiprocessing.queues import SimpleQueue, SentinelReady, Full +from multiprocessing.queues import SimpleQueue, SentinelReady import threading import weakref @@ -195,20 +195,15 @@ result_queue: A multiprocessing.Queue of _ResultItems generated by the process workers. """ - executor = None - - def shutting_down(): - return _shutdown or executor is None or executor._shutdown_thread def shutdown_worker(): # This is an upper bound nb_children_alive = sum(p.is_alive() for p in processes.values()) for i in range(0, nb_children_alive): - call_queue.put_nowait(None) - # Release the queue's resources as soon as possible. - call_queue.close() + call_queue.put(None) # If .join() is not called on the created processes then - # some multiprocessing.Queue methods may deadlock on Mac OS X. + # some multiprocessing.Queue methods may deadlock on Mac OS + # X. for p in processes.values(): p.join() @@ -227,7 +222,7 @@ if executor is not None: executor._broken = True executor._shutdown_thread = True - executor = None + del executor # All futures in flight must be marked failed for work_id, work_item in pending_work_items.items(): work_item.future.set_exception( @@ -241,17 +236,13 @@ # locks may be in a dirty state and block forever. for p in processes.values(): p.terminate() - shutdown_worker() + for p in processes.values(): + p.join() return if isinstance(result_item, int): # Clean shutdown of a worker using its PID # (avoids marking the executor broken) - assert shutting_down() - p = processes.pop(result_item) - p.join() - if not processes: - shutdown_worker() - return + del processes[result_item] elif result_item is not None: work_item = pending_work_items.pop(result_item.work_id, None) # work_item can be None if another process terminated (see above) @@ -266,21 +257,16 @@ # - The interpreter is shutting down OR # - The executor that owns this worker has been collected OR # - The executor that owns this worker has been shutdown. - if shutting_down(): - try: - # Since no new work items can be added, it is safe to shutdown - # this thread if there are no pending work items. - if not pending_work_items: - shutdown_worker() - return - else: - # Start shutting down by telling a process it can exit. - call_queue.put_nowait(None) - except Full: - # This is not a problem: we will eventually be woken up (in - # result_queue.get()) and be able to send a sentinel again. - pass - executor = None + if _shutdown or executor is None or executor._shutdown_thread: + # Since no new work items can be added, it is safe to shutdown + # this thread if there are no pending work items. + if not pending_work_items: + shutdown_worker() + return + else: + # Start shutting down by telling a process it can exit. + call_queue.put(None) + del executor _system_limits_checked = False _system_limited = None @@ -336,10 +322,6 @@ # because futures in the call queue cannot be cancelled. self._call_queue = multiprocessing.Queue(self._max_workers + EXTRA_QUEUED_CALLS) - # Killed worker processes can produce spurious "broken pipe" - # tracebacks in the queue's own worker thread. But we detect killed - # processes anyway, so silence the tracebacks. - self._call_queue._ignore_epipe = True self._result_queue = SimpleQueue() self._work_ids = queue.Queue() self._queue_management_thread = None diff -r 95c34bce986c -r 900df5732f93 Lib/contextlib.py --- a/Lib/contextlib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/contextlib.py Mon Jul 25 09:47:18 2011 -0400 @@ -2,6 +2,7 @@ import sys from functools import wraps +from warnings import warn __all__ = ["contextmanager", "closing", "ContextDecorator"] diff -r 95c34bce986c -r 900df5732f93 Lib/copy.py --- a/Lib/copy.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/copy.py Mon Jul 25 09:47:18 2011 -0400 @@ -173,10 +173,8 @@ "un(deep)copyable object of type %s" % cls) y = _reconstruct(x, rv, 1, memo) - # If is its own copy, don't memoize. - if y is not x: - memo[d] = y - _keep_alive(x, memo) # Make sure x lives at least as long as d + memo[d] = y + _keep_alive(x, memo) # Make sure x lives at least as long as d return y _deepcopy_dispatch = d = {} @@ -216,10 +214,9 @@ y = [] for a in x: y.append(deepcopy(a, memo)) - # We're not going to put the tuple in the memo, but it's still important we - # check for it, in case the tuple contains recursive mutable structures. + d = id(x) try: - return memo[id(x)] + return memo[d] except KeyError: pass for i in range(len(x)): @@ -228,6 +225,7 @@ break else: y = x + memo[d] = y return y d[tuple] = _deepcopy_tuple diff -r 95c34bce986c -r 900df5732f93 Lib/ctypes/_endian.py --- a/Lib/ctypes/_endian.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/ctypes/_endian.py Mon Jul 25 09:47:18 2011 -0400 @@ -7,18 +7,14 @@ """Return the type with the 'other' byte order. Simple types like c_int and so on already have __ctype_be__ and __ctype_le__ attributes which contain the types, for more complicated types - arrays and structures are supported. + only arrays are supported. """ - # check _OTHER_ENDIAN attribute (present if typ is primitive type) - if hasattr(typ, _OTHER_ENDIAN): + try: return getattr(typ, _OTHER_ENDIAN) - # if typ is array - if isinstance(typ, _array_type): - return _other_endian(typ._type_) * typ._length_ - # if typ is structure - if issubclass(typ, Structure): - return typ - raise TypeError("This type does not support other endian: %s" % typ) + except AttributeError: + if type(typ) == _array_type: + return _other_endian(typ._type_) * typ._length_ + raise TypeError("This type does not support other endian: %s" % typ) class _swapped_meta(type(Structure)): def __setattr__(self, attrname, value): diff -r 95c34bce986c -r 900df5732f93 Lib/ctypes/test/test_byteswap.py --- a/Lib/ctypes/test/test_byteswap.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/ctypes/test/test_byteswap.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,4 +1,4 @@ -import sys, unittest, struct, math, ctypes +import sys, unittest, struct, math from binascii import hexlify from ctypes import * @@ -185,32 +185,18 @@ self.assertRaises(TypeError, setattr, T, "_fields_", [("x", typ)]) def test_struct_struct(self): - # nested structures with different byteorders + # Nested structures with different byte order not (yet) supported + if sys.byteorder == "little": + base = BigEndianStructure + else: + base = LittleEndianStructure - # create nested structures with given byteorders and set memory to data - - for nested, data in ( - (BigEndianStructure, b'\0\0\0\1\0\0\0\2'), - (LittleEndianStructure, b'\1\0\0\0\2\0\0\0'), - ): - for parent in ( - BigEndianStructure, - LittleEndianStructure, - Structure, - ): - class NestedStructure(nested): - _fields_ = [("x", c_uint32), - ("y", c_uint32)] - - class TestStructure(parent): - _fields_ = [("point", NestedStructure)] - - self.assertEqual(len(data), sizeof(TestStructure)) - ptr = POINTER(TestStructure) - s = cast(data, ptr)[0] - del ctypes._pointer_type_cache[TestStructure] - self.assertEqual(s.point.x, 1) - self.assertEqual(s.point.y, 2) + class T(Structure): + _fields_ = [("a", c_int), + ("b", c_int)] + class S(base): + pass + self.assertRaises(TypeError, setattr, S, "_fields_", [("s", T)]) def test_struct_fields_2(self): # standard packing in struct uses no alignment. diff -r 95c34bce986c -r 900df5732f93 Lib/distutils/core.py --- a/Lib/distutils/core.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/distutils/core.py Mon Jul 25 09:47:18 2011 -0400 @@ -8,8 +8,7 @@ __revision__ = "$Id$" -import os -import sys +import sys, os from distutils.debug import DEBUG from distutils.errors import * @@ -216,8 +215,11 @@ sys.argv[0] = script_name if script_args is not None: sys.argv[1:] = script_args - with open(script_name, 'rb') as f: + f = open(script_name) + try: exec(f.read(), g, l) + finally: + f.close() finally: sys.argv = save_argv _setup_stop_after = None diff -r 95c34bce986c -r 900df5732f93 Lib/distutils/spawn.py --- a/Lib/distutils/spawn.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/distutils/spawn.py Mon Jul 25 09:47:18 2011 -0400 @@ -96,42 +96,15 @@ raise DistutilsExecError( "command '%s' failed with exit status %d" % (cmd[0], rc)) -if sys.platform == 'darwin': - from distutils import sysconfig - _cfg_target = None - _cfg_target_split = None - def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0): log.info(' '.join(cmd)) if dry_run: return exec_fn = search_path and os.execvp or os.execv - exec_args = [cmd[0], cmd] - if sys.platform == 'darwin': - global _cfg_target, _cfg_target_split - if _cfg_target is None: - _cfg_target = sysconfig.get_config_var( - 'MACOSX_DEPLOYMENT_TARGET') or '' - if _cfg_target: - _cfg_target_split = [int(x) for x in _cfg_target.split('.')] - if _cfg_target: - # ensure that the deployment target of build process is not less - # than that used when the interpreter was built. This ensures - # extension modules are built with correct compatibility values - cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target) - if _cfg_target_split > [int(x) for x in cur_target.split('.')]: - my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: ' - 'now "%s" but "%s" during configure' - % (cur_target, _cfg_target)) - raise DistutilsPlatformError(my_msg) - env = dict(os.environ, - MACOSX_DEPLOYMENT_TARGET=cur_target) - exec_fn = search_path and os.execvpe or os.execve - exec_args.append(env) pid = os.fork() if pid == 0: # in the child try: - exec_fn(*exec_args) + exec_fn(cmd[0], cmd) except OSError as e: sys.stderr.write("unable to execute %s: %s\n" % (cmd[0], e.strerror)) diff -r 95c34bce986c -r 900df5732f93 Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/distutils/sysconfig.py Mon Jul 25 09:47:18 2011 -0400 @@ -419,6 +419,21 @@ raise DistutilsPlatformError(my_msg) + # On MacOSX we need to check the setting of the environment variable + # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so + # it needs to be compatible. + # If it isn't set we set it to the configure-time value + if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g: + cfg_target = g['MACOSX_DEPLOYMENT_TARGET'] + cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '') + if cur_target == '': + cur_target = cfg_target + os.environ['MACOSX_DEPLOYMENT_TARGET'] = cfg_target + elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]: + my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' + % (cur_target, cfg_target)) + raise DistutilsPlatformError(my_msg) + # On AIX, there are wrong paths to the linker scripts in the Makefile # -- these paths are relative to the Python source, but when installed # the scripts are in another directory. diff -r 95c34bce986c -r 900df5732f93 Lib/distutils/tests/test_build_ext.py --- a/Lib/distutils/tests/test_build_ext.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/distutils/tests/test_build_ext.py Mon Jul 25 09:47:18 2011 -0400 @@ -11,8 +11,7 @@ from distutils.tests.support import LoggingSilencer from distutils.extension import Extension from distutils.errors import ( - CompileError, DistutilsPlatformError, DistutilsSetupError, - UnknownFileError) + CompileError, DistutilsSetupError, UnknownFileError) import unittest from test import support @@ -23,11 +22,6 @@ ALREADY_TESTED = False def _get_source_filename(): - # use installed copy if available - tests_f = os.path.join(os.path.dirname(__file__), 'xxmodule.c') - if os.path.exists(tests_f): - return tests_f - # otherwise try using copy from build directory srcdir = sysconfig.get_config_var('srcdir') return os.path.join(srcdir, 'Modules', 'xxmodule.c') @@ -432,43 +426,18 @@ @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX') - def test_deployment_target_default(self): - # Issue 9516: Test that, in the absence of the environment variable, - # an extension module is compiled with the same deployment target as - # the interpreter. - self._try_compile_deployment_target('==', None) + def test_deployment_target(self): + self._try_compile_deployment_target() - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX') - def test_deployment_target_too_low(self): - # Issue 9516: Test that an extension module is not allowed to be - # compiled with a deployment target less than that of the interpreter. - self.assertRaises(DistutilsPlatformError, - self._try_compile_deployment_target, '>', '10.1') - - @unittest.skipUnless(sys.platform == 'darwin', 'test only relevant for MacOSX') - def test_deployment_target_higher_ok(self): - # Issue 9516: Test that an extension module can be compiled with a - # deployment target higher than that of the interpreter: the ext - # module may depend on some newer OS feature. - deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') - if deptarget: - # increment the minor version number (i.e. 10.6 -> 10.7) - deptarget = [int(x) for x in deptarget.split('.')] - deptarget[-1] += 1 - deptarget = '.'.join(str(i) for i in deptarget) - self._try_compile_deployment_target('<', deptarget) - - def _try_compile_deployment_target(self, operator, target): orig_environ = os.environ os.environ = orig_environ.copy() self.addCleanup(setattr, os, 'environ', orig_environ) - if target is None: - if os.environ.get('MACOSX_DEPLOYMENT_TARGET'): - del os.environ['MACOSX_DEPLOYMENT_TARGET'] - else: - os.environ['MACOSX_DEPLOYMENT_TARGET'] = target + os.environ['MACOSX_DEPLOYMENT_TARGET']='10.1' + self._try_compile_deployment_target() + + def _try_compile_deployment_target(self): deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c') with open(deptarget_c, 'w') as fp: @@ -477,17 +446,16 @@ int dummy; - #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED - #else + #if TARGET != MAC_OS_X_VERSION_MIN_REQUIRED #error "Unexpected target" #endif - ''' % operator)) + ''')) - # get the deployment target that the interpreter was built with target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') target = tuple(map(int, target.split('.'))) target = '%02d%01d0' % target + deptarget_ext = Extension( 'deptarget', [deptarget_c], diff -r 95c34bce986c -r 900df5732f93 Lib/distutils/tests/test_build_py.py --- a/Lib/distutils/tests/test_build_py.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/distutils/tests/test_build_py.py Mon Jul 25 09:47:18 2011 -0400 @@ -10,7 +10,7 @@ from distutils.errors import DistutilsFileError from distutils.tests import support -from test.support import run_unittest, create_empty_file +from test.support import run_unittest class BuildPyTestCase(support.TempdirManager, @@ -71,11 +71,11 @@ # create the distribution files. sources = self.mkdtemp() - create_empty_file(os.path.join(sources, "__init__.py")) + open(os.path.join(sources, "__init__.py"), "w").close() testdir = os.path.join(sources, "doc") os.mkdir(testdir) - create_empty_file(os.path.join(testdir, "testfile")) + open(os.path.join(testdir, "testfile"), "w").close() os.chdir(sources) old_stdout = sys.stdout diff -r 95c34bce986c -r 900df5732f93 Lib/doctest.py --- a/Lib/doctest.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/doctest.py Mon Jul 25 09:47:18 2011 -0400 @@ -92,15 +92,10 @@ ] import __future__ -import difflib -import inspect -import linecache -import os -import pdb -import re -import sys -import traceback -import unittest + +import sys, traceback, inspect, linecache, os, re +import unittest, difflib, pdb, tempfile +import warnings from io import StringIO from collections import namedtuple @@ -2516,21 +2511,39 @@ "Debug a test script. `src` is the script, as a string." import pdb - if globs: - globs = globs.copy() - else: - globs = {} - - if pm: - try: - exec(src, globs, globs) - except: - print(sys.exc_info()[1]) - p = pdb.Pdb(nosigint=True) - p.reset() - p.interaction(None, sys.exc_info()[2]) - else: - pdb.Pdb(nosigint=True).run("exec(%r)" % src, globs, globs) + # Note that tempfile.NameTemporaryFile() cannot be used. As the + # docs say, a file so created cannot be opened by name a second time + # on modern Windows boxes, and exec() needs to open and read it. + srcfilename = tempfile.mktemp(".py", "doctestdebug") + f = open(srcfilename, 'w') + f.write(src) + f.close() + + try: + if globs: + globs = globs.copy() + else: + globs = {} + + if pm: + try: + with open(srcfilename) as f: + exec(f.read(), globs, globs) + except: + print(sys.exc_info()[1]) + p = pdb.Pdb(nosigint=True) + p.reset() + p.interaction(None, sys.exc_info()[2]) + else: + fp = open(srcfilename) + try: + script = fp.read() + finally: + fp.close() + pdb.Pdb(nosigint=True).run("exec(%r)" % script, globs, globs) + + finally: + os.remove(srcfilename) def debug(module, name, pm=False): """Debug a single doctest docstring. diff -r 95c34bce986c -r 900df5732f93 Lib/email/_parseaddr.py --- a/Lib/email/_parseaddr.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/email/_parseaddr.py Mon Jul 25 09:47:18 2011 -0400 @@ -47,21 +47,6 @@ Accounts for military timezones. """ - res = _parsedate_tz(data) - if res[9] is None: - res[9] = 0 - return tuple(res) - -def _parsedate_tz(data): - """Convert date to extended time tuple. - - The last (additional) element is the time zone offset in seconds, except if - the timezone was specified as -0000. In that case the last element is - None. This indicates a UTC timestamp that explicitly declaims knowledge of - the source timezone, as opposed to a +0000 timestamp that indicates the - source timezone really was UTC. - - """ data = data.split() # The FWS after the comma after the day-of-week is optional, so search and # adjust for this. @@ -153,8 +138,6 @@ tzoffset = int(tz) except ValueError: pass - if tzoffset==0 and tz.startswith('-'): - tzoffset = None # Convert a timezone offset into seconds ; -0500 -> -18000 if tzoffset: if tzoffset < 0: @@ -164,7 +147,7 @@ tzsign = 1 tzoffset = tzsign * ( (tzoffset//100)*3600 + (tzoffset % 100)*60) # Daylight Saving Time flag is set to -1, since DST is unknown. - return [yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset] + return yy, mm, dd, thh, tmm, tss, 0, 1, -1, tzoffset def parsedate(data): diff -r 95c34bce986c -r 900df5732f93 Lib/email/errors.py --- a/Lib/email/errors.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/email/errors.py Mon Jul 25 09:47:18 2011 -0400 @@ -55,6 +55,3 @@ class MultipartInvariantViolationDefect(MessageDefect): """A message claimed to be a multipart but no subparts were found.""" - -class InvalidMultipartContentTransferEncodingDefect(MessageDefect): - """An invalid content transfer encoding was set on the multipart itself.""" diff -r 95c34bce986c -r 900df5732f93 Lib/email/feedparser.py --- a/Lib/email/feedparser.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/email/feedparser.py Mon Jul 25 09:47:18 2011 -0400 @@ -300,11 +300,6 @@ lines.append(line) self._cur.set_payload(EMPTYSTRING.join(lines)) return - # Make sure a valid content type was specified per RFC 2045:6.4. - if (self._cur.get('content-transfer-encoding', '8bit').lower() - not in ('7bit', '8bit', 'binary')): - defect = errors.InvalidMultipartContentTransferEncodingDefect() - self.policy.handle_defect(self._cur, defect) # Create a line match predicate which matches the inter-part # boundary as well as the end-of-multipart boundary. Don't push # this onto the input stream until we've scanned past the diff -r 95c34bce986c -r 900df5732f93 Lib/email/utils.py --- a/Lib/email/utils.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/email/utils.py Mon Jul 25 09:47:18 2011 -0400 @@ -11,14 +11,12 @@ 'encode_rfc2231', 'formataddr', 'formatdate', - 'format_datetime', 'getaddresses', 'make_msgid', 'mktime_tz', 'parseaddr', 'parsedate', 'parsedate_tz', - 'parsedate_to_datetime', 'unquote', ] @@ -28,7 +26,6 @@ import base64 import random import socket -import datetime import urllib.parse import warnings from io import StringIO @@ -40,7 +37,6 @@ # We need wormarounds for bugs in these methods in older Pythons (see below) from email._parseaddr import parsedate as _parsedate from email._parseaddr import parsedate_tz as _parsedate_tz -from email._parseaddr import _parsedate_tz as __parsedate_tz from quopri import decodestring as _qdecode @@ -114,14 +110,6 @@ ''', re.VERBOSE | re.IGNORECASE) -def _format_timetuple_and_zone(timetuple, zone): - return '%s, %02d %s %04d %02d:%02d:%02d %s' % ( - ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][timetuple[6]], - timetuple[2], - ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', - 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][timetuple[1] - 1], - timetuple[0], timetuple[3], timetuple[4], timetuple[5], - zone) def formatdate(timeval=None, localtime=False, usegmt=False): """Returns a date string as specified by RFC 2822, e.g.: @@ -166,25 +154,14 @@ zone = 'GMT' else: zone = '-0000' - return _format_timetuple_and_zone(now, zone) + return '%s, %02d %s %04d %02d:%02d:%02d %s' % ( + ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now[6]], + now[2], + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', + 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now[1] - 1], + now[0], now[3], now[4], now[5], + zone) -def format_datetime(dt, usegmt=False): - """Turn a datetime into a date string as specified in RFC 2822. - - If usegmt is True, dt must be an aware datetime with an offset of zero. In - this case 'GMT' will be rendered instead of the normal +0000 required by - RFC2822. This is to support HTTP headers involving date stamps. - """ - now = dt.timetuple() - if usegmt: - if dt.tzinfo is None or dt.tzinfo != datetime.timezone.utc: - raise ValueError("usegmt option requires a UTC datetime") - zone = 'GMT' - elif dt.tzinfo is None: - zone = '-0000' - else: - zone = dt.strftime("%z") - return _format_timetuple_and_zone(now, zone) def make_msgid(idstring=None, domain=None): @@ -226,15 +203,6 @@ return None return _parsedate_tz(data) -def parsedate_to_datetime(data): - if not data: - return None - *dtuple, tz = __parsedate_tz(data) - if tz is None: - return datetime.datetime(*dtuple[:6]) - return datetime.datetime(*dtuple[:6], - tzinfo=datetime.timezone(datetime.timedelta(seconds=tz))) - def parseaddr(addr): addrs = _AddressList(addr).addresslist diff -r 95c34bce986c -r 900df5732f93 Lib/filecmp.py --- a/Lib/filecmp.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/filecmp.py Mon Jul 25 09:47:18 2011 -0400 @@ -48,12 +48,11 @@ if s1[1] != s2[1]: return False - outcome = _cache.get((f1, f2, s1, s2)) - if outcome is None: - outcome = _do_cmp(f1, f2) - if len(_cache) > 100: # limit the maximum size of the cache - _cache.clear() - _cache[f1, f2, s1, s2] = outcome + result = _cache.get((f1, f2)) + if result and (s1, s2) == result[:2]: + return result[2] + outcome = _do_cmp(f1, f2) + _cache[f1, f2] = s1, s2, outcome return outcome def _sig(st): diff -r 95c34bce986c -r 900df5732f93 Lib/ftplib.py --- a/Lib/ftplib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/ftplib.py Mon Jul 25 09:47:18 2011 -0400 @@ -343,39 +343,33 @@ host, port = self.makepasv() conn = socket.create_connection((host, port), self.timeout, source_address=self.source_address) - try: - if rest is not None: - self.sendcmd("REST %s" % rest) - resp = self.sendcmd(cmd) - # Some servers apparently send a 200 reply to - # a LIST or STOR command, before the 150 reply - # (and way before the 226 reply). This seems to - # be in violation of the protocol (which only allows - # 1xx or error messages for LIST), so we just discard - # this response. - if resp[0] == '2': - resp = self.getresp() - if resp[0] != '1': - raise error_reply(resp) - except: - conn.close() - raise + if rest is not None: + self.sendcmd("REST %s" % rest) + resp = self.sendcmd(cmd) + # Some servers apparently send a 200 reply to + # a LIST or STOR command, before the 150 reply + # (and way before the 226 reply). This seems to + # be in violation of the protocol (which only allows + # 1xx or error messages for LIST), so we just discard + # this response. + if resp[0] == '2': + resp = self.getresp() + if resp[0] != '1': + raise error_reply(resp) else: sock = self.makeport() - try: - if rest is not None: - self.sendcmd("REST %s" % rest) - resp = self.sendcmd(cmd) - # See above. - if resp[0] == '2': - resp = self.getresp() - if resp[0] != '1': - raise error_reply(resp) - conn, sockaddr = sock.accept() - if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT: - conn.settimeout(self.timeout) - finally: - sock.close() + if rest is not None: + self.sendcmd("REST %s" % rest) + resp = self.sendcmd(cmd) + # See above. + if resp[0] == '2': + resp = self.getresp() + if resp[0] != '1': + raise error_reply(resp) + conn, sockaddr = sock.accept() + if self.timeout is not _GLOBAL_DEFAULT_TIMEOUT: + conn.settimeout(self.timeout) + sock.close() if resp[:3] == '150': # this is conditional in case we received a 125 size = parse150(resp) @@ -714,14 +708,6 @@ self.file = self.sock.makefile(mode='r', encoding=self.encoding) return resp - def ccc(self): - '''Switch back to a clear-text control connection.''' - if not isinstance(self.sock, ssl.SSLSocket): - raise ValueError("not using TLS") - resp = self.voidcmd('CCC') - self.sock = self.sock.unwrap() - return resp - def prot_p(self): '''Set up secure data connection.''' # PROT defines whether or not the data channel is to be protected. diff -r 95c34bce986c -r 900df5732f93 Lib/idlelib/PyShell.py --- a/Lib/idlelib/PyShell.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/idlelib/PyShell.py Mon Jul 25 09:47:18 2011 -0400 @@ -59,7 +59,7 @@ file = warning_stream try: file.write(warnings.formatwarning(message, category, filename, - lineno, line=line)) + lineno, file=file, line=line)) except IOError: pass ## file (probably __stderr__) is invalid, warning dropped. warnings.showwarning = idle_showwarning diff -r 95c34bce986c -r 900df5732f93 Lib/importlib/test/source/test_file_loader.py --- a/Lib/importlib/test/source/test_file_loader.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/importlib/test/source/test_file_loader.py Mon Jul 25 09:47:18 2011 -0400 @@ -214,7 +214,7 @@ lambda bc: bc[:8] + b'', del_source=del_source) file_path = mapping['_temp'] if not del_source else bytecode_path - with self.assertRaises(EOFError): + with self.assertRaises(ValueError): self.import_(file_path, '_temp') def _test_bad_magic(self, test, *, del_source=False): diff -r 95c34bce986c -r 900df5732f93 Lib/inspect.py --- a/Lib/inspect.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/inspect.py Mon Jul 25 09:47:18 2011 -0400 @@ -33,6 +33,7 @@ import os import types import itertools +import string import re import imp import tokenize @@ -917,24 +918,10 @@ specs.append(formatvarkw(varkw) + formatvalue(locals[varkw])) return '(' + ', '.join(specs) + ')' -def _missing_arguments(f_name, argnames, pos, values): - names = [repr(name) for name in argnames if name not in values] - missing = len(names) - if missing == 1: - s = names[0] - elif missing == 2: - s = "{} and {}".format(*names) - else: - tail = ", {} and {}".format(names[-2:]) - del names[-2:] - s = ", ".join(names) + tail - raise TypeError("%s() missing %i required %s argument%s: %s" % - (f_name, missing, - "positional" if pos else "keyword-only", - "" if missing == 1 else "s", s)) - -def _too_many(f_name, args, kwonly, varargs, defcount, given, values): +def _positional_error(f_name, args, kwonly, varargs, defcount, given, values): atleast = len(args) - defcount + if given is None: + given = len([arg for arg in args if arg in values]) kwonly_given = len([arg for arg in kwonly if arg in values]) if varargs: plural = atleast != 1 @@ -993,25 +980,22 @@ (f_name, kw)) arg2value[kw] = value if num_pos > num_args and not varargs: - _too_many(f_name, args, kwonlyargs, varargs, num_defaults, - num_pos, arg2value) + _positional_error(f_name, args, kwonlyargs, varargs, num_defaults, + num_pos, arg2value) if num_pos < num_args: - req = args[:num_args - num_defaults] - for arg in req: + for arg in args[:num_args - num_defaults]: if arg not in arg2value: - _missing_arguments(f_name, req, True, arg2value) + _positional_error(f_name, args, kwonlyargs, varargs, + num_defaults, None, arg2value) for i, arg in enumerate(args[num_args - num_defaults:]): if arg not in arg2value: arg2value[arg] = defaults[i] - missing = 0 for kwarg in kwonlyargs: if kwarg not in arg2value: - if kwarg in kwonlydefaults: - arg2value[kwarg] = kwonlydefaults[kwarg] - else: - missing += 1 - if missing: - _missing_arguments(f_name, kwonlyargs, False, arg2value) + if kwarg not in kwonlydefaults: + raise TypeError("%s() requires keyword-only argument %r" % + (f_name, kwarg)) + arg2value[kwarg] = kwonlydefaults[kwarg] return arg2value # -------------------------------------------------- stack frame extraction diff -r 95c34bce986c -r 900df5732f93 Lib/lib2to3/fixer_base.py --- a/Lib/lib2to3/fixer_base.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/lib2to3/fixer_base.py Mon Jul 25 09:47:18 2011 -0400 @@ -27,6 +27,7 @@ pattern_tree = None # Tree representation of the pattern options = None # Options object passed to initializer filename = None # The filename (set by set_filename) + logger = None # A logger (set by set_filename) numbers = itertools.count(1) # For new_name() used_names = set() # A set of all used NAMEs order = "post" # Does the fixer prefer pre- or post-order traversal @@ -69,11 +70,12 @@ with_tree=True) def set_filename(self, filename): - """Set the filename. + """Set the filename, and a logger derived from it. The main refactoring tool should call this. """ self.filename = filename + self.logger = logging.getLogger(filename) def match(self, node): """Returns match for a given parse tree node. diff -r 95c34bce986c -r 900df5732f93 Lib/logging/__init__.py --- a/Lib/logging/__init__.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/logging/__init__.py Mon Jul 25 09:47:18 2011 -0400 @@ -1442,8 +1442,7 @@ c = c.parent if (found == 0): if lastResort: - if record.levelno >= lastResort.level: - lastResort.handle(record) + lastResort.handle(record) elif raiseExceptions and not self.manager.emittedNoHandlerWarning: sys.stderr.write("No handlers could be found for logger" " \"%s\"\n" % self.name) diff -r 95c34bce986c -r 900df5732f93 Lib/logging/handlers.py --- a/Lib/logging/handlers.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/logging/handlers.py Mon Jul 25 09:47:18 2011 -0400 @@ -769,7 +769,6 @@ """ return self.priority_map.get(levelName, "warning") - ident = '' # prepended to all messages append_nul = True # some old syslog daemons expect a NUL terminator def emit(self, record): @@ -780,8 +779,6 @@ exception information is present, it is NOT sent to the server. """ msg = self.format(record) - if self.ident: - msg = self.ident + msg if self.append_nul: msg += '\000' """ diff -r 95c34bce986c -r 900df5732f93 Lib/multiprocessing/connection.py --- a/Lib/multiprocessing/connection.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/multiprocessing/connection.py Mon Jul 25 09:47:18 2011 -0400 @@ -149,8 +149,6 @@ self._readable = readable self._writable = writable - # XXX should we use util.Finalize instead of a __del__? - def __del__(self): if self._handle is not None: self._close() @@ -292,8 +290,8 @@ """ _buffered = b'' - def _close(self, _CloseHandle=win32.CloseHandle): - _CloseHandle(self._handle) + def _close(self): + win32.CloseHandle(self._handle) def _send_bytes(self, buf): overlapped = win32.WriteFile(self._handle, buf, overlapped=True) @@ -378,13 +376,13 @@ """ if win32: - def _close(self, _close=win32.closesocket): - _close(self._handle) + def _close(self): + win32.closesocket(self._handle) _write = win32.send _read = win32.recv else: - def _close(self, _close=os.close): - _close(self._handle) + def _close(self): + os.close(self._handle) _write = os.write _read = os.read diff -r 95c34bce986c -r 900df5732f93 Lib/multiprocessing/heap.py --- a/Lib/multiprocessing/heap.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/multiprocessing/heap.py Mon Jul 25 09:47:18 2011 -0400 @@ -101,8 +101,6 @@ self._stop_to_block = {} self._allocated_blocks = set() self._arenas = [] - # list of pending blocks to free - see free() comment below - self._pending_free_blocks = [] @staticmethod def _roundup(n, alignment): @@ -177,39 +175,15 @@ return start, stop - def _free_pending_blocks(self): - # Free all the blocks in the pending list - called with the lock held. - while True: - try: - block = self._pending_free_blocks.pop() - except IndexError: - break + def free(self, block): + # free a block returned by malloc() + assert os.getpid() == self._lastpid + self._lock.acquire() + try: self._allocated_blocks.remove(block) self._free(block) - - def free(self, block): - # free a block returned by malloc() - # Since free() can be called asynchronously by the GC, it could happen - # that it's called while self._lock is held: in that case, - # self._lock.acquire() would deadlock (issue #12352). To avoid that, a - # trylock is used instead, and if the lock can't be acquired - # immediately, the block is added to a list of blocks to be freed - # synchronously sometimes later from malloc() or free(), by calling - # _free_pending_blocks() (appending and retrieving from a list is not - # strictly thread-safe but under cPython it's atomic thanks to the GIL). - assert os.getpid() == self._lastpid - if not self._lock.acquire(False): - # can't acquire the lock right now, add the block to the list of - # pending blocks to free - self._pending_free_blocks.append(block) - else: - # we hold the lock - try: - self._free_pending_blocks() - self._allocated_blocks.remove(block) - self._free(block) - finally: - self._lock.release() + finally: + self._lock.release() def malloc(self, size): # return a block of right size (possibly rounded up) @@ -217,7 +191,6 @@ if os.getpid() != self._lastpid: self.__init__() # reinitialize after fork self._lock.acquire() - self._free_pending_blocks() try: size = self._roundup(max(size,1), self._alignment) (arena, start, stop) = self._malloc(size) diff -r 95c34bce986c -r 900df5732f93 Lib/multiprocessing/process.py --- a/Lib/multiprocessing/process.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/multiprocessing/process.py Mon Jul 25 09:47:18 2011 -0400 @@ -42,7 +42,6 @@ import sys import signal import itertools -from _weakrefset import WeakSet # # @@ -110,7 +109,6 @@ self._kwargs = dict(kwargs) self._name = name or type(self).__name__ + '-' + \ ':'.join(str(i) for i in self._identity) - _dangling.add(self) def run(self): ''' @@ -346,6 +344,3 @@ for name, signum in list(signal.__dict__.items()): if name[:3]=='SIG' and '_' not in name: _exitcode_to_name[-signum] = name - -# For debug and leak testing -_dangling = WeakSet() diff -r 95c34bce986c -r 900df5732f93 Lib/multiprocessing/queues.py --- a/Lib/multiprocessing/queues.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/multiprocessing/queues.py Mon Jul 25 09:47:18 2011 -0400 @@ -41,7 +41,6 @@ import time import atexit import weakref -import errno from queue import Empty, Full import _multiprocessing @@ -68,8 +67,6 @@ else: self._wlock = Lock() self._sem = BoundedSemaphore(maxsize) - # For use by concurrent.futures - self._ignore_epipe = False self._after_fork() @@ -78,11 +75,11 @@ def __getstate__(self): assert_spawning(self) - return (self._ignore_epipe, self._maxsize, self._reader, self._writer, + return (self._maxsize, self._reader, self._writer, self._rlock, self._wlock, self._sem, self._opid) def __setstate__(self, state): - (self._ignore_epipe, self._maxsize, self._reader, self._writer, + (self._maxsize, self._reader, self._writer, self._rlock, self._wlock, self._sem, self._opid) = state self._after_fork() @@ -181,7 +178,7 @@ self._thread = threading.Thread( target=Queue._feed, args=(self._buffer, self._notempty, self._send, - self._wlock, self._writer.close, self._ignore_epipe), + self._wlock, self._writer.close), name='QueueFeederThread' ) self._thread.daemon = True @@ -232,7 +229,7 @@ notempty.release() @staticmethod - def _feed(buffer, notempty, send, writelock, close, ignore_epipe): + def _feed(buffer, notempty, send, writelock, close): debug('starting thread to feed data to pipe') from .util import is_exiting @@ -274,8 +271,6 @@ except IndexError: pass except Exception as e: - if ignore_epipe and getattr(e, 'errno', 0) == errno.EPIPE: - return # Since this runs in a daemon thread the resources it uses # may be become unusable while the process is cleaning up. # We ignore errors which happen after the process has diff -r 95c34bce986c -r 900df5732f93 Lib/multiprocessing/util.py --- a/Lib/multiprocessing/util.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/multiprocessing/util.py Mon Jul 25 09:47:18 2011 -0400 @@ -188,11 +188,7 @@ _finalizer_registry[self._key] = self - def __call__(self, wr=None, - # Need to bind these locally because the globals can have - # been cleared at shutdown - _finalizer_registry=_finalizer_registry, - sub_debug=sub_debug): + def __call__(self, wr=None): ''' Run the callback unless it has already been called or cancelled ''' diff -r 95c34bce986c -r 900df5732f93 Lib/opcode.py --- a/Lib/opcode.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/opcode.py Mon Jul 25 09:47:18 2011 -0400 @@ -43,6 +43,7 @@ # Instruction opcodes for compiled code # Blank lines correspond to available opcodes +def_op('STOP_CODE', 0) def_op('POP_TOP', 1) def_op('ROT_TWO', 2) def_op('ROT_THREE', 3) diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/command/register.py --- a/Lib/packaging/command/register.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/command/register.py Mon Jul 25 09:47:18 2011 -0400 @@ -10,7 +10,7 @@ from packaging import logger from packaging.util import (read_pypirc, generate_pypirc, DEFAULT_REPOSITORY, - DEFAULT_REALM, get_pypirc_path, encode_multipart) + DEFAULT_REALM, get_pypirc_path) from packaging.command.cmd import Command class register(Command): @@ -231,11 +231,29 @@ if 'name' in data: logger.info('Registering %s to %s', data['name'], self.repository) # Build up the MIME payload for the urllib2 POST data - content_type, body = encode_multipart(data.items(), []) + boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' + sep_boundary = '\n--' + boundary + end_boundary = sep_boundary + '--' + body = io.StringIO() + for key, value in data.items(): + # handle multiple entries for the same name + if not isinstance(value, (tuple, list)): + value = [value] + + for value in value: + body.write(sep_boundary) + body.write('\nContent-Disposition: form-data; name="%s"'%key) + body.write("\n\n") + body.write(value) + if value and value[-1] == '\r': + body.write('\n') # write an extra newline (lurve Macs) + body.write(end_boundary) + body.write("\n") + body = body.getvalue() # build the Request headers = { - 'Content-type': content_type, + 'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary, 'Content-length': str(len(body)) } req = urllib.request.Request(self.repository, body, headers) diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/command/upload.py --- a/Lib/packaging/command/upload.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/command/upload.py Mon Jul 25 09:47:18 2011 -0400 @@ -14,7 +14,7 @@ from packaging import logger from packaging.errors import PackagingOptionError from packaging.util import (spawn, read_pypirc, DEFAULT_REPOSITORY, - DEFAULT_REALM, encode_multipart) + DEFAULT_REALM) from packaging.command.cmd import Command @@ -131,22 +131,54 @@ auth = b"Basic " + standard_b64encode(user_pass) # Build up the MIME payload for the POST data - files = [] - for key in ('content', 'gpg_signature'): - if key in data: - filename_, value = data.pop(key) - files.append((key, filename_, value)) + boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' + sep_boundary = b'\n--' + boundary + end_boundary = sep_boundary + b'--' + body = BytesIO() - content_type, body = encode_multipart(data.items(), files) + file_fields = ('content', 'gpg_signature') + + for key, value in data.items(): + # handle multiple entries for the same name + if not isinstance(value, tuple): + value = [value] + + content_dispo = '\nContent-Disposition: form-data; name="%s"' % key + + if key in file_fields: + filename_, content = value + filename_ = ';filename="%s"' % filename_ + body.write(sep_boundary) + body.write(content_dispo.encode('utf-8')) + body.write(filename_.encode('utf-8')) + body.write(b"\n\n") + body.write(content) + else: + for value in value: + value = str(value).encode('utf-8') + body.write(sep_boundary) + body.write(content_dispo.encode('utf-8')) + body.write(b"\n\n") + body.write(value) + if value and value.endswith(b'\r'): + # write an extra newline (lurve Macs) + body.write(b'\n') + + body.write(end_boundary) + body.write(b"\n") + body = body.getvalue() logger.info("Submitting %s to %s", filename, self.repository) # build the Request - headers = {'Content-type': content_type, + headers = {'Content-type': + 'multipart/form-data; boundary=%s' % + boundary.decode('ascii'), 'Content-length': str(len(body)), 'Authorization': auth} - request = Request(self.repository, body, headers) + request = Request(self.repository, data=body, + headers=headers) # send the data try: result = urlopen(request) diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/command/upload_docs.py --- a/Lib/packaging/command/upload_docs.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/command/upload_docs.py Mon Jul 25 09:47:18 2011 -0400 @@ -10,8 +10,7 @@ from io import BytesIO from packaging import logger -from packaging.util import (read_pypirc, DEFAULT_REPOSITORY, DEFAULT_REALM, - encode_multipart) +from packaging.util import read_pypirc, DEFAULT_REPOSITORY, DEFAULT_REALM from packaging.errors import PackagingFileError from packaging.command.cmd import Command @@ -29,6 +28,49 @@ return destination +# grabbed from +# http://code.activestate.com/recipes/ +# 146306-http-client-to-post-using-multipartform-data/ +# TODO factor this out for use by install and command/upload + +def encode_multipart(fields, files, boundary=None): + """ + *fields* is a sequence of (name: str, value: str) elements for regular + form fields, *files* is a sequence of (name: str, filename: str, value: + bytes) elements for data to be uploaded as files. + + Returns (content_type: bytes, body: bytes) ready for http.client.HTTP. + """ + if boundary is None: + boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' + elif not isinstance(boundary, bytes): + raise TypeError('boundary is not bytes but %r' % type(boundary)) + + l = [] + for key, value in fields: + l.extend(( + b'--' + boundary, + ('Content-Disposition: form-data; name="%s"' % + key).encode('utf-8'), + b'', + value.encode('utf-8'))) + + for key, filename, value in files: + l.extend(( + b'--' + boundary, + ('Content-Disposition: form-data; name="%s"; filename="%s"' % + (key, filename)).encode('utf-8'), + b'', + value)) + l.append(b'--' + boundary + b'--') + l.append(b'') + + body = b'\r\n'.join(l) + + content_type = b'multipart/form-data; boundary=' + boundary + return content_type, body + + class upload_docs(Command): description = "upload HTML documentation to PyPI" diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/database.py --- a/Lib/packaging/database.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/database.py Mon Jul 25 09:47:18 2011 -0400 @@ -61,12 +61,13 @@ def clear_cache(): """ Clears the internal cache. """ - global _cache_generated, _cache_generated_egg + global _cache_name, _cache_name_egg, _cache_path, _cache_path_egg, \ + _cache_generated, _cache_generated_egg - _cache_name.clear() - _cache_name_egg.clear() - _cache_path.clear() - _cache_path_egg.clear() + _cache_name = {} + _cache_name_egg = {} + _cache_path = {} + _cache_path_egg = {} _cache_generated = False _cache_generated_egg = False @@ -157,18 +158,17 @@ self.name, self.version, self.path) def _get_records(self, local=False): - results = [] with self.get_distinfo_file('RECORD') as record: record_reader = csv.reader(record, delimiter=',', lineterminator='\n') + # XXX needs an explaining comment for row in record_reader: - missing = [None for i in range(len(row), 3)] - path, checksum, size = row + missing + path, checksum, size = (row[:] + + [None for i in range(len(row), 3)]) if local: path = path.replace('/', os.sep) path = os.path.join(sys.prefix, path) - results.append((path, checksum, size)) - return results + yield path, checksum, size def get_resource_path(self, relative_path): with self.get_distinfo_file('RESOURCES') as resources_file: @@ -197,8 +197,7 @@ :type local: boolean :returns: iterator of (path, md5, size) """ - for result in self._get_records(local): - yield result + return self._get_records(local) def uses(self, path): """ diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/install.py --- a/Lib/packaging/install.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/install.py Mon Jul 25 09:47:18 2011 -0400 @@ -42,7 +42,10 @@ :param files: a list of files to move. :param destination: the destination directory to put on the files. + if not defined, create a new one, using mkdtemp """ + if not destination: + destination = tempfile.mkdtemp() for old in files: filename = os.path.split(old)[-1] @@ -123,11 +126,8 @@ elif _is_archive_file(path): logger.info('Installing from archive: %s', path) _unpacked_dir = tempfile.mkdtemp() - try: - shutil.unpack_archive(path, _unpacked_dir) - return _run_install_from_archive(_unpacked_dir) - finally: - shutil.rmtree(_unpacked_dir) + shutil.unpack_archive(path, _unpacked_dir) + return _run_install_from_archive(_unpacked_dir) else: logger.warning('No projects to install.') return False @@ -179,6 +179,8 @@ :param path: base path to install distribution in :param paths: list of paths (defaults to sys.path) to look for info """ + if not path: + path = tempfile.mkdtemp() installed_dists = [] for dist in dists: diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/__main__.py --- a/Lib/packaging/tests/__main__.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/__main__.py Mon Jul 25 09:47:18 2011 -0400 @@ -5,18 +5,15 @@ import os import sys import unittest -from test.support import run_unittest, reap_children, reap_threads +from test.support import run_unittest, reap_children -@reap_threads def test_main(): - try: - start_dir = os.path.dirname(__file__) - top_dir = os.path.dirname(os.path.dirname(start_dir)) - test_loader = unittest.TestLoader() - run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir)) - finally: - reap_children() + start_dir = os.path.dirname(__file__) + top_dir = os.path.dirname(os.path.dirname(start_dir)) + test_loader = unittest.TestLoader() + run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir)) + reap_children() if __name__ == '__main__': diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/support.py --- a/Lib/packaging/tests/support.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/support.py Mon Jul 25 09:47:18 2011 -0400 @@ -28,11 +28,13 @@ """ import os +import errno import shutil import logging import weakref import tempfile +from packaging import logger from packaging.dist import Distribution from packaging.tests import unittest from test.support import requires_zlib, unlink @@ -42,10 +44,6 @@ 'skip_unless_symlink', 'requires_zlib'] -logger = logging.getLogger('packaging') -logger2to3 = logging.getLogger('RefactoringTool') - - class _TestHandler(logging.handlers.BufferingHandler): # stolen and adapted from test.support @@ -76,10 +74,9 @@ def setUp(self): super(LoggingCatcher, self).setUp() self.loghandler = handler = _TestHandler() - self._old_levels = logger.level, logger2to3.level + self.old_level = logger.level logger.addHandler(handler) logger.setLevel(logging.DEBUG) # we want all messages - logger2to3.setLevel(logging.CRITICAL) # we don't want 2to3 messages def tearDown(self): handler = self.loghandler @@ -90,8 +87,7 @@ for ref in weakref.getweakrefs(handler): logging._removeHandlerRef(ref) del self.loghandler - logger.setLevel(self._old_levels[0]) - logger2to3.setLevel(self._old_levels[1]) + logger.setLevel(self.old_level) super(LoggingCatcher, self).tearDown() def get_logs(self, *levels): diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/test_command_build_ext.py --- a/Lib/packaging/tests/test_command_build_ext.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/test_command_build_ext.py Mon Jul 25 09:47:18 2011 -0400 @@ -3,11 +3,9 @@ import site import shutil import sysconfig -import textwrap from io import StringIO from packaging.dist import Distribution -from packaging.errors import (UnknownFileError, CompileError, - PackagingPlatformError) +from packaging.errors import UnknownFileError, CompileError from packaging.command.build_ext import build_ext from packaging.compiler.extension import Extension from test.script_helper import assert_python_ok @@ -16,11 +14,6 @@ def _get_source_filename(): - # use installed copy if available - tests_f = os.path.join(os.path.dirname(__file__), 'xxmodule.c') - if os.path.exists(tests_f): - return tests_f - # otherwise try using copy from build directory srcdir = sysconfig.get_config_var('srcdir') return os.path.join(srcdir, 'Modules', 'xxmodule.c') @@ -364,95 +357,6 @@ wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext) self.assertEqual(wanted, path) - @unittest.skipUnless(sys.platform == 'darwin', - 'test only relevant for Mac OS X') - def test_deployment_target_default(self): - # Issue 9516: Test that, in the absence of the environment variable, - # an extension module is compiled with the same deployment target as - # the interpreter. - self._try_compile_deployment_target('==', None) - - @unittest.skipUnless(sys.platform == 'darwin', - 'test only relevant for Mac OS X') - def test_deployment_target_too_low(self): - # Issue 9516: Test that an extension module is not allowed to be - # compiled with a deployment target less than that of the interpreter. - self.assertRaises(PackagingPlatformError, - self._try_compile_deployment_target, '>', '10.1') - - @unittest.skipUnless(sys.platform == 'darwin', - 'test only relevant for Mac OS X') - def test_deployment_target_higher_ok(self): - # Issue 9516: Test that an extension module can be compiled with a - # deployment target higher than that of the interpreter: the ext - # module may depend on some newer OS feature. - deptarget = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') - if deptarget: - # increment the minor version number (i.e. 10.6 -> 10.7) - deptarget = [int(x) for x in deptarget.split('.')] - deptarget[-1] += 1 - deptarget = '.'.join(str(i) for i in deptarget) - self._try_compile_deployment_target('<', deptarget) - - def _try_compile_deployment_target(self, operator, target): - orig_environ = os.environ - os.environ = orig_environ.copy() - self.addCleanup(setattr, os, 'environ', orig_environ) - - if target is None: - if os.environ.get('MACOSX_DEPLOYMENT_TARGET'): - del os.environ['MACOSX_DEPLOYMENT_TARGET'] - else: - os.environ['MACOSX_DEPLOYMENT_TARGET'] = target - - deptarget_c = os.path.join(self.tmp_dir, 'deptargetmodule.c') - - with open(deptarget_c, 'w') as fp: - fp.write(textwrap.dedent('''\ - #include - - int dummy; - - #if TARGET %s MAC_OS_X_VERSION_MIN_REQUIRED - #else - #error "Unexpected target" - #endif - - ''' % operator)) - - # get the deployment target that the interpreter was built with - target = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET') - target = tuple(map(int, target.split('.'))) - target = '%02d%01d0' % target - - deptarget_ext = Extension( - 'deptarget', - [deptarget_c], - extra_compile_args=['-DTARGET=%s' % (target,)], - ) - dist = Distribution({ - 'name': 'deptarget', - 'ext_modules': [deptarget_ext], - }) - dist.package_dir = self.tmp_dir - cmd = build_ext(dist) - cmd.build_lib = self.tmp_dir - cmd.build_temp = self.tmp_dir - - try: - old_stdout = sys.stdout - if not verbose: - # silence compiler output - sys.stdout = StringIO() - try: - cmd.ensure_finalized() - cmd.run() - finally: - sys.stdout = old_stdout - - except CompileError: - self.fail("Wrong deployment target during compilation") - def test_suite(): src = _get_source_filename() diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/test_command_register.py --- a/Lib/packaging/tests/test_command_register.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/test_command_register.py Mon Jul 25 09:47:18 2011 -0400 @@ -152,7 +152,7 @@ req1 = dict(self.conn.reqs[0].headers) req2 = dict(self.conn.reqs[1].headers) self.assertEqual(req2['Content-length'], req1['Content-length']) - self.assertIn(b'xxx', self.conn.reqs[1].data) + self.assertIn('xxx', self.conn.reqs[1].data) def test_password_not_in_file(self): @@ -180,8 +180,8 @@ self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) - self.assertEqual(headers['Content-length'], '628') - self.assertIn(b'tarek', req.data) + self.assertEqual(headers['Content-length'], '608') + self.assertIn('tarek', req.data) def test_password_reset(self): # this test runs choice 3 @@ -195,8 +195,8 @@ self.assertEqual(len(self.conn.reqs), 1) req = self.conn.reqs[0] headers = dict(req.headers) - self.assertEqual(headers['Content-length'], '298') - self.assertIn(b'tarek', req.data) + self.assertEqual(headers['Content-length'], '290') + self.assertIn('tarek', req.data) @unittest.skipUnless(DOCUTILS_SUPPORT, 'needs docutils') def test_strict(self): diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/test_command_upload_docs.py --- a/Lib/packaging/tests/test_command_upload_docs.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/test_command_upload_docs.py Mon Jul 25 09:47:18 2011 -0400 @@ -9,7 +9,8 @@ _ssl = None from packaging.command import upload_docs as upload_docs_mod -from packaging.command.upload_docs import upload_docs, zip_dir +from packaging.command.upload_docs import (upload_docs, zip_dir, + encode_multipart) from packaging.dist import Distribution from packaging.errors import PackagingFileError, PackagingOptionError @@ -22,6 +23,23 @@ PyPIServerTestCase = object +EXPECTED_MULTIPART_OUTPUT = [ + b'---x', + b'Content-Disposition: form-data; name="username"', + b'', + b'wok', + b'---x', + b'Content-Disposition: form-data; name="password"', + b'', + b'secret', + b'---x', + b'Content-Disposition: form-data; name="picture"; filename="wok.png"', + b'', + b'PNG89', + b'---x--', + b'', +] + PYPIRC = """\ [distutils] index-servers = server1 @@ -90,6 +108,13 @@ zip_f = zipfile.ZipFile(compressed) self.assertEqual(zip_f.namelist(), ['index.html', 'docs/index.html']) + def test_encode_multipart(self): + fields = [('username', 'wok'), ('password', 'secret')] + files = [('picture', 'wok.png', b'PNG89')] + content_type, body = encode_multipart(fields, files, b'-x') + self.assertEqual(b'multipart/form-data; boundary=-x', content_type) + self.assertEqual(EXPECTED_MULTIPART_OUTPUT, body.split(b'\r\n')) + def prepare_command(self): self.cmd.upload_dir = self.prepare_sample_dir() self.cmd.ensure_finalized() diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/test_uninstall.py --- a/Lib/packaging/tests/test_uninstall.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/test_uninstall.py Mon Jul 25 09:47:18 2011 -0400 @@ -93,6 +93,7 @@ self.assertRaises(PackagingError, remove, 'Foo', paths=[self.root_dir]) + @unittest.skipIf(sys.platform == 'win32', 'deactivated for now') def test_uninstall(self): dist, install_lib = self.install_dist() self.assertIsFile(install_lib, 'foo', '__init__.py') @@ -102,6 +103,7 @@ self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py') self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD') + @unittest.skipIf(sys.platform == 'win32', 'deactivated for now') def test_remove_issue(self): # makes sure if there are OSErrors (like permission denied) # remove() stops and display a clean error diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/tests/test_util.py --- a/Lib/packaging/tests/test_util.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/tests/test_util.py Mon Jul 25 09:47:18 2011 -0400 @@ -19,7 +19,7 @@ get_compiler_versions, _MAC_OS_X_LD_VERSION, byte_compile, find_packages, spawn, get_pypirc_path, generate_pypirc, read_pypirc, resolve_name, iglob, RICH_GLOB, egginfo_to_distinfo, is_setuptools, is_distutils, is_packaging, - get_install_method, cfg_to_args, encode_multipart) + get_install_method, cfg_to_args) PYPIRC = """\ @@ -54,23 +54,6 @@ password:xxx """ -EXPECTED_MULTIPART_OUTPUT = [ - b'---x', - b'Content-Disposition: form-data; name="username"', - b'', - b'wok', - b'---x', - b'Content-Disposition: form-data; name="password"', - b'', - b'secret', - b'---x', - b'Content-Disposition: form-data; name="picture"; filename="wok.png"', - b'', - b'PNG89', - b'---x--', - b'', -] - class FakePopen: test_class = None @@ -542,13 +525,6 @@ self.assertEqual(args['scripts'], dist.scripts) self.assertEqual(args['py_modules'], dist.py_modules) - def test_encode_multipart(self): - fields = [('username', 'wok'), ('password', 'secret')] - files = [('picture', 'wok.png', b'PNG89')] - content_type, body = encode_multipart(fields, files, b'-x') - self.assertEqual(b'multipart/form-data; boundary=-x', content_type) - self.assertEqual(EXPECTED_MULTIPART_OUTPUT, body.split(b'\r\n')) - class GlobTestCaseBase(support.TempdirManager, support.LoggingCatcher, diff -r 95c34bce986c -r 900df5732f93 Lib/packaging/util.py --- a/Lib/packaging/util.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/packaging/util.py Mon Jul 25 09:47:18 2011 -0400 @@ -757,9 +757,6 @@ else: return path, '' -if sys.platform == 'darwin': - _cfg_target = None - _cfg_target_split = None def spawn(cmd, search_path=True, verbose=0, dry_run=False, env=None): """Run another program specified as a command list 'cmd' in a new process. @@ -784,26 +781,6 @@ if dry_run: logging.debug('dry run, no process actually spawned') return - if sys.platform == 'darwin': - global _cfg_target, _cfg_target_split - if _cfg_target is None: - _cfg_target = sysconfig.get_config_var( - 'MACOSX_DEPLOYMENT_TARGET') or '' - if _cfg_target: - _cfg_target_split = [int(x) for x in _cfg_target.split('.')] - if _cfg_target: - # ensure that the deployment target of build process is not less - # than that used when the interpreter was built. This ensures - # extension modules are built with correct compatibility values - env = env or os.environ - cur_target = env.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target) - if _cfg_target_split > [int(x) for x in cur_target.split('.')]: - my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: ' - 'now "%s" but "%s" during configure' - % (cur_target, _cfg_target)) - raise PackagingPlatformError(my_msg) - env = dict(env, MACOSX_DEPLOYMENT_TARGET=cur_target) - exit_status = subprocess.call(cmd, env=env) if exit_status != 0: msg = "command %r failed with exit status %d" @@ -1487,50 +1464,3 @@ _path_created.add(abs_head) return created_dirs - - -def encode_multipart(fields, files, boundary=None): - """Prepare a multipart HTTP request. - - *fields* is a sequence of (name: str, value: str) elements for regular - form fields, *files* is a sequence of (name: str, filename: str, value: - bytes) elements for data to be uploaded as files. - - Returns (content_type: bytes, body: bytes) ready for http.client.HTTP. - """ - # Taken from - # http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/ - - if boundary is None: - boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' - elif not isinstance(boundary, bytes): - raise TypeError('boundary must be bytes, not %r' % type(boundary)) - - l = [] - for key, values in fields: - # handle multiple entries for the same name - if not isinstance(values, (tuple, list)): - values=[values] - - for value in values: - l.extend(( - b'--' + boundary, - ('Content-Disposition: form-data; name="%s"' % - key).encode('utf-8'), - b'', - value.encode('utf-8'))) - - for key, filename, value in files: - l.extend(( - b'--' + boundary, - ('Content-Disposition: form-data; name="%s"; filename="%s"' % - (key, filename)).encode('utf-8'), - b'', - value)) - - l.append(b'--' + boundary + b'--') - l.append(b'') - - body = b'\r\n'.join(l) - content_type = b'multipart/form-data; boundary=' + boundary - return content_type, body diff -r 95c34bce986c -r 900df5732f93 Lib/plat-linux3/CDROM.py --- a/Lib/plat-linux3/CDROM.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,207 +0,0 @@ -# Generated by h2py from /usr/include/linux/cdrom.h - -CDROMPAUSE = 0x5301 -CDROMRESUME = 0x5302 -CDROMPLAYMSF = 0x5303 -CDROMPLAYTRKIND = 0x5304 -CDROMREADTOCHDR = 0x5305 -CDROMREADTOCENTRY = 0x5306 -CDROMSTOP = 0x5307 -CDROMSTART = 0x5308 -CDROMEJECT = 0x5309 -CDROMVOLCTRL = 0x530a -CDROMSUBCHNL = 0x530b -CDROMREADMODE2 = 0x530c -CDROMREADMODE1 = 0x530d -CDROMREADAUDIO = 0x530e -CDROMEJECT_SW = 0x530f -CDROMMULTISESSION = 0x5310 -CDROM_GET_MCN = 0x5311 -CDROM_GET_UPC = CDROM_GET_MCN -CDROMRESET = 0x5312 -CDROMVOLREAD = 0x5313 -CDROMREADRAW = 0x5314 -CDROMREADCOOKED = 0x5315 -CDROMSEEK = 0x5316 -CDROMPLAYBLK = 0x5317 -CDROMREADALL = 0x5318 -CDROMGETSPINDOWN = 0x531d -CDROMSETSPINDOWN = 0x531e -CDROMCLOSETRAY = 0x5319 -CDROM_SET_OPTIONS = 0x5320 -CDROM_CLEAR_OPTIONS = 0x5321 -CDROM_SELECT_SPEED = 0x5322 -CDROM_SELECT_DISC = 0x5323 -CDROM_MEDIA_CHANGED = 0x5325 -CDROM_DRIVE_STATUS = 0x5326 -CDROM_DISC_STATUS = 0x5327 -CDROM_CHANGER_NSLOTS = 0x5328 -CDROM_LOCKDOOR = 0x5329 -CDROM_DEBUG = 0x5330 -CDROM_GET_CAPABILITY = 0x5331 -CDROMAUDIOBUFSIZ = 0x5382 -DVD_READ_STRUCT = 0x5390 -DVD_WRITE_STRUCT = 0x5391 -DVD_AUTH = 0x5392 -CDROM_SEND_PACKET = 0x5393 -CDROM_NEXT_WRITABLE = 0x5394 -CDROM_LAST_WRITTEN = 0x5395 -CDROM_PACKET_SIZE = 12 -CGC_DATA_UNKNOWN = 0 -CGC_DATA_WRITE = 1 -CGC_DATA_READ = 2 -CGC_DATA_NONE = 3 -CD_MINS = 74 -CD_SECS = 60 -CD_FRAMES = 75 -CD_SYNC_SIZE = 12 -CD_MSF_OFFSET = 150 -CD_CHUNK_SIZE = 24 -CD_NUM_OF_CHUNKS = 98 -CD_FRAMESIZE_SUB = 96 -CD_HEAD_SIZE = 4 -CD_SUBHEAD_SIZE = 8 -CD_EDC_SIZE = 4 -CD_ZERO_SIZE = 8 -CD_ECC_SIZE = 276 -CD_FRAMESIZE = 2048 -CD_FRAMESIZE_RAW = 2352 -CD_FRAMESIZE_RAWER = 2646 -CD_FRAMESIZE_RAW1 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE) -CD_FRAMESIZE_RAW0 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE) -CD_XA_HEAD = (CD_HEAD_SIZE+CD_SUBHEAD_SIZE) -CD_XA_TAIL = (CD_EDC_SIZE+CD_ECC_SIZE) -CD_XA_SYNC_HEAD = (CD_SYNC_SIZE+CD_XA_HEAD) -CDROM_LBA = 0x01 -CDROM_MSF = 0x02 -CDROM_DATA_TRACK = 0x04 -CDROM_LEADOUT = 0xAA -CDROM_AUDIO_INVALID = 0x00 -CDROM_AUDIO_PLAY = 0x11 -CDROM_AUDIO_PAUSED = 0x12 -CDROM_AUDIO_COMPLETED = 0x13 -CDROM_AUDIO_ERROR = 0x14 -CDROM_AUDIO_NO_STATUS = 0x15 -CDC_CLOSE_TRAY = 0x1 -CDC_OPEN_TRAY = 0x2 -CDC_LOCK = 0x4 -CDC_SELECT_SPEED = 0x8 -CDC_SELECT_DISC = 0x10 -CDC_MULTI_SESSION = 0x20 -CDC_MCN = 0x40 -CDC_MEDIA_CHANGED = 0x80 -CDC_PLAY_AUDIO = 0x100 -CDC_RESET = 0x200 -CDC_IOCTLS = 0x400 -CDC_DRIVE_STATUS = 0x800 -CDC_GENERIC_PACKET = 0x1000 -CDC_CD_R = 0x2000 -CDC_CD_RW = 0x4000 -CDC_DVD = 0x8000 -CDC_DVD_R = 0x10000 -CDC_DVD_RAM = 0x20000 -CDS_NO_INFO = 0 -CDS_NO_DISC = 1 -CDS_TRAY_OPEN = 2 -CDS_DRIVE_NOT_READY = 3 -CDS_DISC_OK = 4 -CDS_AUDIO = 100 -CDS_DATA_1 = 101 -CDS_DATA_2 = 102 -CDS_XA_2_1 = 103 -CDS_XA_2_2 = 104 -CDS_MIXED = 105 -CDO_AUTO_CLOSE = 0x1 -CDO_AUTO_EJECT = 0x2 -CDO_USE_FFLAGS = 0x4 -CDO_LOCK = 0x8 -CDO_CHECK_TYPE = 0x10 -CD_PART_MAX = 64 -CD_PART_MASK = (CD_PART_MAX - 1) -GPCMD_BLANK = 0xa1 -GPCMD_CLOSE_TRACK = 0x5b -GPCMD_FLUSH_CACHE = 0x35 -GPCMD_FORMAT_UNIT = 0x04 -GPCMD_GET_CONFIGURATION = 0x46 -GPCMD_GET_EVENT_STATUS_NOTIFICATION = 0x4a -GPCMD_GET_PERFORMANCE = 0xac -GPCMD_INQUIRY = 0x12 -GPCMD_LOAD_UNLOAD = 0xa6 -GPCMD_MECHANISM_STATUS = 0xbd -GPCMD_MODE_SELECT_10 = 0x55 -GPCMD_MODE_SENSE_10 = 0x5a -GPCMD_PAUSE_RESUME = 0x4b -GPCMD_PLAY_AUDIO_10 = 0x45 -GPCMD_PLAY_AUDIO_MSF = 0x47 -GPCMD_PLAY_AUDIO_TI = 0x48 -GPCMD_PLAY_CD = 0xbc -GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e -GPCMD_READ_10 = 0x28 -GPCMD_READ_12 = 0xa8 -GPCMD_READ_CDVD_CAPACITY = 0x25 -GPCMD_READ_CD = 0xbe -GPCMD_READ_CD_MSF = 0xb9 -GPCMD_READ_DISC_INFO = 0x51 -GPCMD_READ_DVD_STRUCTURE = 0xad -GPCMD_READ_FORMAT_CAPACITIES = 0x23 -GPCMD_READ_HEADER = 0x44 -GPCMD_READ_TRACK_RZONE_INFO = 0x52 -GPCMD_READ_SUBCHANNEL = 0x42 -GPCMD_READ_TOC_PMA_ATIP = 0x43 -GPCMD_REPAIR_RZONE_TRACK = 0x58 -GPCMD_REPORT_KEY = 0xa4 -GPCMD_REQUEST_SENSE = 0x03 -GPCMD_RESERVE_RZONE_TRACK = 0x53 -GPCMD_SCAN = 0xba -GPCMD_SEEK = 0x2b -GPCMD_SEND_DVD_STRUCTURE = 0xad -GPCMD_SEND_EVENT = 0xa2 -GPCMD_SEND_KEY = 0xa3 -GPCMD_SEND_OPC = 0x54 -GPCMD_SET_READ_AHEAD = 0xa7 -GPCMD_SET_STREAMING = 0xb6 -GPCMD_START_STOP_UNIT = 0x1b -GPCMD_STOP_PLAY_SCAN = 0x4e -GPCMD_TEST_UNIT_READY = 0x00 -GPCMD_VERIFY_10 = 0x2f -GPCMD_WRITE_10 = 0x2a -GPCMD_WRITE_AND_VERIFY_10 = 0x2e -GPCMD_SET_SPEED = 0xbb -GPCMD_PLAYAUDIO_TI = 0x48 -GPCMD_GET_MEDIA_STATUS = 0xda -GPMODE_R_W_ERROR_PAGE = 0x01 -GPMODE_WRITE_PARMS_PAGE = 0x05 -GPMODE_AUDIO_CTL_PAGE = 0x0e -GPMODE_POWER_PAGE = 0x1a -GPMODE_FAULT_FAIL_PAGE = 0x1c -GPMODE_TO_PROTECT_PAGE = 0x1d -GPMODE_CAPABILITIES_PAGE = 0x2a -GPMODE_ALL_PAGES = 0x3f -GPMODE_CDROM_PAGE = 0x0d -DVD_STRUCT_PHYSICAL = 0x00 -DVD_STRUCT_COPYRIGHT = 0x01 -DVD_STRUCT_DISCKEY = 0x02 -DVD_STRUCT_BCA = 0x03 -DVD_STRUCT_MANUFACT = 0x04 -DVD_LAYERS = 4 -DVD_LU_SEND_AGID = 0 -DVD_HOST_SEND_CHALLENGE = 1 -DVD_LU_SEND_KEY1 = 2 -DVD_LU_SEND_CHALLENGE = 3 -DVD_HOST_SEND_KEY2 = 4 -DVD_AUTH_ESTABLISHED = 5 -DVD_AUTH_FAILURE = 6 -DVD_LU_SEND_TITLE_KEY = 7 -DVD_LU_SEND_ASF = 8 -DVD_INVALIDATE_AGID = 9 -DVD_LU_SEND_RPC_STATE = 10 -DVD_HOST_SEND_RPC_STATE = 11 -DVD_CPM_NO_COPYRIGHT = 0 -DVD_CPM_COPYRIGHTED = 1 -DVD_CP_SEC_NONE = 0 -DVD_CP_SEC_EXIST = 1 -DVD_CGMS_UNRESTRICTED = 0 -DVD_CGMS_SINGLE = 2 -DVD_CGMS_RESTRICTED = 3 - -CDROM_MAX_SLOTS = 256 diff -r 95c34bce986c -r 900df5732f93 Lib/plat-linux3/DLFCN.py --- a/Lib/plat-linux3/DLFCN.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -# Generated by h2py from /usr/include/dlfcn.h -_DLFCN_H = 1 - -# Included from features.h -_FEATURES_H = 1 -__USE_ANSI = 1 -__FAVOR_BSD = 1 -_ISOC99_SOURCE = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 199506 -_XOPEN_SOURCE = 600 -_XOPEN_SOURCE_EXTENDED = 1 -_LARGEFILE64_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -__USE_ISOC99 = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 2 -_POSIX_C_SOURCE = 199506 -__USE_POSIX = 1 -__USE_POSIX2 = 1 -__USE_POSIX199309 = 1 -__USE_POSIX199506 = 1 -__USE_XOPEN = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_UNIX98 = 1 -_LARGEFILE_SOURCE = 1 -__USE_XOPEN2K = 1 -__USE_ISOC99 = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_FILE_OFFSET64 = 1 -__USE_MISC = 1 -__USE_BSD = 1 -__USE_SVID = 1 -__USE_GNU = 1 -__USE_REENTRANT = 1 -__STDC_IEC_559__ = 1 -__STDC_IEC_559_COMPLEX__ = 1 -__STDC_ISO_10646__ = 200009 -__GNU_LIBRARY__ = 6 -__GLIBC__ = 2 -__GLIBC_MINOR__ = 2 - -# Included from sys/cdefs.h -_SYS_CDEFS_H = 1 -def __PMT(args): return args - -def __P(args): return args - -def __PMT(args): return args - -def __STRING(x): return #x - -__flexarr = [] -__flexarr = [0] -__flexarr = [] -__flexarr = [1] -def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) - -def __attribute__(xyz): return - -def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) - -def __attribute_format_arg__(x): return - -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_EXTERN_INLINES = 1 - -# Included from gnu/stubs.h - -# Included from bits/dlfcn.h -RTLD_LAZY = 0x00001 -RTLD_NOW = 0x00002 -RTLD_BINDING_MASK = 0x3 -RTLD_NOLOAD = 0x00004 -RTLD_GLOBAL = 0x00100 -RTLD_LOCAL = 0 -RTLD_NODELETE = 0x01000 diff -r 95c34bce986c -r 900df5732f93 Lib/plat-linux3/IN.py --- a/Lib/plat-linux3/IN.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,615 +0,0 @@ -# Generated by h2py from /usr/include/netinet/in.h -_NETINET_IN_H = 1 - -# Included from features.h -_FEATURES_H = 1 -__USE_ANSI = 1 -__FAVOR_BSD = 1 -_ISOC99_SOURCE = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 199506 -_XOPEN_SOURCE = 600 -_XOPEN_SOURCE_EXTENDED = 1 -_LARGEFILE64_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -__USE_ISOC99 = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 2 -_POSIX_C_SOURCE = 199506 -__USE_POSIX = 1 -__USE_POSIX2 = 1 -__USE_POSIX199309 = 1 -__USE_POSIX199506 = 1 -__USE_XOPEN = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_UNIX98 = 1 -_LARGEFILE_SOURCE = 1 -__USE_XOPEN2K = 1 -__USE_ISOC99 = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_FILE_OFFSET64 = 1 -__USE_MISC = 1 -__USE_BSD = 1 -__USE_SVID = 1 -__USE_GNU = 1 -__USE_REENTRANT = 1 -__STDC_IEC_559__ = 1 -__STDC_IEC_559_COMPLEX__ = 1 -__STDC_ISO_10646__ = 200009 -__GNU_LIBRARY__ = 6 -__GLIBC__ = 2 -__GLIBC_MINOR__ = 2 - -# Included from sys/cdefs.h -_SYS_CDEFS_H = 1 -def __PMT(args): return args - -def __P(args): return args - -def __PMT(args): return args - -def __STRING(x): return #x - -__flexarr = [] -__flexarr = [0] -__flexarr = [] -__flexarr = [1] -def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) - -def __attribute__(xyz): return - -def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) - -def __attribute_format_arg__(x): return - -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_EXTERN_INLINES = 1 - -# Included from gnu/stubs.h - -# Included from stdint.h -_STDINT_H = 1 - -# Included from bits/wchar.h -_BITS_WCHAR_H = 1 -__WCHAR_MIN = (-2147483647 - 1) -__WCHAR_MAX = (2147483647) - -# Included from bits/wordsize.h -__WORDSIZE = 32 -def __INT64_C(c): return c ## L - -def __UINT64_C(c): return c ## UL - -def __INT64_C(c): return c ## LL - -def __UINT64_C(c): return c ## ULL - -INT8_MIN = (-128) -INT16_MIN = (-32767-1) -INT32_MIN = (-2147483647-1) -INT64_MIN = (-__INT64_C(9223372036854775807)-1) -INT8_MAX = (127) -INT16_MAX = (32767) -INT32_MAX = (2147483647) -INT64_MAX = (__INT64_C(9223372036854775807)) -UINT8_MAX = (255) -UINT16_MAX = (65535) -UINT64_MAX = (__UINT64_C(18446744073709551615)) -INT_LEAST8_MIN = (-128) -INT_LEAST16_MIN = (-32767-1) -INT_LEAST32_MIN = (-2147483647-1) -INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1) -INT_LEAST8_MAX = (127) -INT_LEAST16_MAX = (32767) -INT_LEAST32_MAX = (2147483647) -INT_LEAST64_MAX = (__INT64_C(9223372036854775807)) -UINT_LEAST8_MAX = (255) -UINT_LEAST16_MAX = (65535) -UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615)) -INT_FAST8_MIN = (-128) -INT_FAST16_MIN = (-9223372036854775807-1) -INT_FAST32_MIN = (-9223372036854775807-1) -INT_FAST16_MIN = (-2147483647-1) -INT_FAST32_MIN = (-2147483647-1) -INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1) -INT_FAST8_MAX = (127) -INT_FAST16_MAX = (9223372036854775807) -INT_FAST32_MAX = (9223372036854775807) -INT_FAST16_MAX = (2147483647) -INT_FAST32_MAX = (2147483647) -INT_FAST64_MAX = (__INT64_C(9223372036854775807)) -UINT_FAST8_MAX = (255) -UINT_FAST64_MAX = (__UINT64_C(18446744073709551615)) -INTPTR_MIN = (-9223372036854775807-1) -INTPTR_MAX = (9223372036854775807) -INTPTR_MIN = (-2147483647-1) -INTPTR_MAX = (2147483647) -INTMAX_MIN = (-__INT64_C(9223372036854775807)-1) -INTMAX_MAX = (__INT64_C(9223372036854775807)) -UINTMAX_MAX = (__UINT64_C(18446744073709551615)) -PTRDIFF_MIN = (-9223372036854775807-1) -PTRDIFF_MAX = (9223372036854775807) -PTRDIFF_MIN = (-2147483647-1) -PTRDIFF_MAX = (2147483647) -SIG_ATOMIC_MIN = (-2147483647-1) -SIG_ATOMIC_MAX = (2147483647) -WCHAR_MIN = __WCHAR_MIN -WCHAR_MAX = __WCHAR_MAX -def INT8_C(c): return c - -def INT16_C(c): return c - -def INT32_C(c): return c - -def INT64_C(c): return c ## L - -def INT64_C(c): return c ## LL - -def UINT8_C(c): return c ## U - -def UINT16_C(c): return c ## U - -def UINT32_C(c): return c ## U - -def UINT64_C(c): return c ## UL - -def UINT64_C(c): return c ## ULL - -def INTMAX_C(c): return c ## L - -def UINTMAX_C(c): return c ## UL - -def INTMAX_C(c): return c ## LL - -def UINTMAX_C(c): return c ## ULL - - -# Included from bits/types.h -_BITS_TYPES_H = 1 -__FD_SETSIZE = 1024 - -# Included from bits/pthreadtypes.h -_BITS_PTHREADTYPES_H = 1 - -# Included from bits/sched.h -SCHED_OTHER = 0 -SCHED_FIFO = 1 -SCHED_RR = 2 -CSIGNAL = 0x000000ff -CLONE_VM = 0x00000100 -CLONE_FS = 0x00000200 -CLONE_FILES = 0x00000400 -CLONE_SIGHAND = 0x00000800 -CLONE_PID = 0x00001000 -CLONE_PTRACE = 0x00002000 -CLONE_VFORK = 0x00004000 -__defined_schedparam = 1 -def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0) - -IN_CLASSA_NET = (-16777216) -IN_CLASSA_NSHIFT = 24 -IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET) -IN_CLASSA_MAX = 128 -def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648)) - -IN_CLASSB_NET = (-65536) -IN_CLASSB_NSHIFT = 16 -IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET) -IN_CLASSB_MAX = 65536 -def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824)) - -IN_CLASSC_NET = (-256) -IN_CLASSC_NSHIFT = 8 -IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET) -def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912)) - -def IN_MULTICAST(a): return IN_CLASSD(a) - -def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912)) - -def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456)) - -IN_LOOPBACKNET = 127 -INET_ADDRSTRLEN = 16 -INET6_ADDRSTRLEN = 46 - -# Included from bits/socket.h - -# Included from limits.h -_LIBC_LIMITS_H_ = 1 -MB_LEN_MAX = 16 -_LIMITS_H = 1 -CHAR_BIT = 8 -SCHAR_MIN = (-128) -SCHAR_MAX = 127 -UCHAR_MAX = 255 -CHAR_MIN = 0 -CHAR_MAX = UCHAR_MAX -CHAR_MIN = SCHAR_MIN -CHAR_MAX = SCHAR_MAX -SHRT_MIN = (-32768) -SHRT_MAX = 32767 -USHRT_MAX = 65535 -INT_MAX = 2147483647 -LONG_MAX = 9223372036854775807 -LONG_MAX = 2147483647 -LONG_MIN = (-LONG_MAX - 1) - -# Included from bits/posix1_lim.h -_BITS_POSIX1_LIM_H = 1 -_POSIX_AIO_LISTIO_MAX = 2 -_POSIX_AIO_MAX = 1 -_POSIX_ARG_MAX = 4096 -_POSIX_CHILD_MAX = 6 -_POSIX_DELAYTIMER_MAX = 32 -_POSIX_LINK_MAX = 8 -_POSIX_MAX_CANON = 255 -_POSIX_MAX_INPUT = 255 -_POSIX_MQ_OPEN_MAX = 8 -_POSIX_MQ_PRIO_MAX = 32 -_POSIX_NGROUPS_MAX = 0 -_POSIX_OPEN_MAX = 16 -_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX -_POSIX_NAME_MAX = 14 -_POSIX_PATH_MAX = 256 -_POSIX_PIPE_BUF = 512 -_POSIX_RTSIG_MAX = 8 -_POSIX_SEM_NSEMS_MAX = 256 -_POSIX_SEM_VALUE_MAX = 32767 -_POSIX_SIGQUEUE_MAX = 32 -_POSIX_SSIZE_MAX = 32767 -_POSIX_STREAM_MAX = 8 -_POSIX_TZNAME_MAX = 6 -_POSIX_QLIMIT = 1 -_POSIX_HIWAT = _POSIX_PIPE_BUF -_POSIX_UIO_MAXIOV = 16 -_POSIX_TTY_NAME_MAX = 9 -_POSIX_TIMER_MAX = 32 -_POSIX_LOGIN_NAME_MAX = 9 -_POSIX_CLOCKRES_MIN = 20000000 - -# Included from bits/local_lim.h - -# Included from linux/limits.h -NR_OPEN = 1024 -NGROUPS_MAX = 32 -ARG_MAX = 131072 -CHILD_MAX = 999 -OPEN_MAX = 256 -LINK_MAX = 127 -MAX_CANON = 255 -MAX_INPUT = 255 -NAME_MAX = 255 -PATH_MAX = 4096 -PIPE_BUF = 4096 -RTSIG_MAX = 32 -_POSIX_THREAD_KEYS_MAX = 128 -PTHREAD_KEYS_MAX = 1024 -_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4 -PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS -_POSIX_THREAD_THREADS_MAX = 64 -PTHREAD_THREADS_MAX = 1024 -AIO_PRIO_DELTA_MAX = 20 -PTHREAD_STACK_MIN = 16384 -TIMER_MAX = 256 -SSIZE_MAX = LONG_MAX -NGROUPS_MAX = _POSIX_NGROUPS_MAX - -# Included from bits/posix2_lim.h -_BITS_POSIX2_LIM_H = 1 -_POSIX2_BC_BASE_MAX = 99 -_POSIX2_BC_DIM_MAX = 2048 -_POSIX2_BC_SCALE_MAX = 99 -_POSIX2_BC_STRING_MAX = 1000 -_POSIX2_COLL_WEIGHTS_MAX = 2 -_POSIX2_EXPR_NEST_MAX = 32 -_POSIX2_LINE_MAX = 2048 -_POSIX2_RE_DUP_MAX = 255 -_POSIX2_CHARCLASS_NAME_MAX = 14 -BC_BASE_MAX = _POSIX2_BC_BASE_MAX -BC_DIM_MAX = _POSIX2_BC_DIM_MAX -BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX -BC_STRING_MAX = _POSIX2_BC_STRING_MAX -COLL_WEIGHTS_MAX = 255 -EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX -LINE_MAX = _POSIX2_LINE_MAX -CHARCLASS_NAME_MAX = 2048 -RE_DUP_MAX = (0x7fff) - -# Included from bits/xopen_lim.h -_XOPEN_LIM_H = 1 - -# Included from bits/stdio_lim.h -L_tmpnam = 20 -TMP_MAX = 238328 -FILENAME_MAX = 4096 -L_ctermid = 9 -L_cuserid = 9 -FOPEN_MAX = 16 -IOV_MAX = 1024 -_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV -NL_ARGMAX = _POSIX_ARG_MAX -NL_LANGMAX = _POSIX2_LINE_MAX -NL_MSGMAX = INT_MAX -NL_NMAX = INT_MAX -NL_SETMAX = INT_MAX -NL_TEXTMAX = INT_MAX -NZERO = 20 -WORD_BIT = 16 -WORD_BIT = 32 -WORD_BIT = 64 -WORD_BIT = 16 -WORD_BIT = 32 -WORD_BIT = 64 -WORD_BIT = 32 -LONG_BIT = 32 -LONG_BIT = 64 -LONG_BIT = 32 -LONG_BIT = 64 -LONG_BIT = 64 -LONG_BIT = 32 -from TYPES import * -PF_UNSPEC = 0 -PF_LOCAL = 1 -PF_UNIX = PF_LOCAL -PF_FILE = PF_LOCAL -PF_INET = 2 -PF_AX25 = 3 -PF_IPX = 4 -PF_APPLETALK = 5 -PF_NETROM = 6 -PF_BRIDGE = 7 -PF_ATMPVC = 8 -PF_X25 = 9 -PF_INET6 = 10 -PF_ROSE = 11 -PF_DECnet = 12 -PF_NETBEUI = 13 -PF_SECURITY = 14 -PF_KEY = 15 -PF_NETLINK = 16 -PF_ROUTE = PF_NETLINK -PF_PACKET = 17 -PF_ASH = 18 -PF_ECONET = 19 -PF_ATMSVC = 20 -PF_SNA = 22 -PF_IRDA = 23 -PF_PPPOX = 24 -PF_WANPIPE = 25 -PF_BLUETOOTH = 31 -PF_MAX = 32 -AF_UNSPEC = PF_UNSPEC -AF_LOCAL = PF_LOCAL -AF_UNIX = PF_UNIX -AF_FILE = PF_FILE -AF_INET = PF_INET -AF_AX25 = PF_AX25 -AF_IPX = PF_IPX -AF_APPLETALK = PF_APPLETALK -AF_NETROM = PF_NETROM -AF_BRIDGE = PF_BRIDGE -AF_ATMPVC = PF_ATMPVC -AF_X25 = PF_X25 -AF_INET6 = PF_INET6 -AF_ROSE = PF_ROSE -AF_DECnet = PF_DECnet -AF_NETBEUI = PF_NETBEUI -AF_SECURITY = PF_SECURITY -AF_KEY = PF_KEY -AF_NETLINK = PF_NETLINK -AF_ROUTE = PF_ROUTE -AF_PACKET = PF_PACKET -AF_ASH = PF_ASH -AF_ECONET = PF_ECONET -AF_ATMSVC = PF_ATMSVC -AF_SNA = PF_SNA -AF_IRDA = PF_IRDA -AF_PPPOX = PF_PPPOX -AF_WANPIPE = PF_WANPIPE -AF_BLUETOOTH = PF_BLUETOOTH -AF_MAX = PF_MAX -SOL_RAW = 255 -SOL_DECNET = 261 -SOL_X25 = 262 -SOL_PACKET = 263 -SOL_ATM = 264 -SOL_AAL = 265 -SOL_IRDA = 266 -SOMAXCONN = 128 - -# Included from bits/sockaddr.h -_BITS_SOCKADDR_H = 1 -def __SOCKADDR_COMMON(sa_prefix): return \ - -_SS_SIZE = 128 -def CMSG_FIRSTHDR(mhdr): return \ - - -# Included from asm/socket.h - -# Included from asm/sockios.h -FIOSETOWN = 0x8901 -SIOCSPGRP = 0x8902 -FIOGETOWN = 0x8903 -SIOCGPGRP = 0x8904 -SIOCATMARK = 0x8905 -SIOCGSTAMP = 0x8906 -SOL_SOCKET = 1 -SO_DEBUG = 1 -SO_REUSEADDR = 2 -SO_TYPE = 3 -SO_ERROR = 4 -SO_DONTROUTE = 5 -SO_BROADCAST = 6 -SO_SNDBUF = 7 -SO_RCVBUF = 8 -SO_KEEPALIVE = 9 -SO_OOBINLINE = 10 -SO_NO_CHECK = 11 -SO_PRIORITY = 12 -SO_LINGER = 13 -SO_BSDCOMPAT = 14 -SO_PASSCRED = 16 -SO_PEERCRED = 17 -SO_RCVLOWAT = 18 -SO_SNDLOWAT = 19 -SO_RCVTIMEO = 20 -SO_SNDTIMEO = 21 -SO_SECURITY_AUTHENTICATION = 22 -SO_SECURITY_ENCRYPTION_TRANSPORT = 23 -SO_SECURITY_ENCRYPTION_NETWORK = 24 -SO_BINDTODEVICE = 25 -SO_ATTACH_FILTER = 26 -SO_DETACH_FILTER = 27 -SO_PEERNAME = 28 -SO_TIMESTAMP = 29 -SCM_TIMESTAMP = SO_TIMESTAMP -SO_ACCEPTCONN = 30 -SOCK_STREAM = 1 -SOCK_DGRAM = 2 -SOCK_RAW = 3 -SOCK_RDM = 4 -SOCK_SEQPACKET = 5 -SOCK_PACKET = 10 -SOCK_MAX = (SOCK_PACKET+1) - -# Included from bits/in.h -IP_TOS = 1 -IP_TTL = 2 -IP_HDRINCL = 3 -IP_OPTIONS = 4 -IP_ROUTER_ALERT = 5 -IP_RECVOPTS = 6 -IP_RETOPTS = 7 -IP_PKTINFO = 8 -IP_PKTOPTIONS = 9 -IP_PMTUDISC = 10 -IP_MTU_DISCOVER = 10 -IP_RECVERR = 11 -IP_RECVTTL = 12 -IP_RECVTOS = 13 -IP_MULTICAST_IF = 32 -IP_MULTICAST_TTL = 33 -IP_MULTICAST_LOOP = 34 -IP_ADD_MEMBERSHIP = 35 -IP_DROP_MEMBERSHIP = 36 -IP_RECVRETOPTS = IP_RETOPTS -IP_PMTUDISC_DONT = 0 -IP_PMTUDISC_WANT = 1 -IP_PMTUDISC_DO = 2 -SOL_IP = 0 -IP_DEFAULT_MULTICAST_TTL = 1 -IP_DEFAULT_MULTICAST_LOOP = 1 -IP_MAX_MEMBERSHIPS = 20 -IPV6_ADDRFORM = 1 -IPV6_PKTINFO = 2 -IPV6_HOPOPTS = 3 -IPV6_DSTOPTS = 4 -IPV6_RTHDR = 5 -IPV6_PKTOPTIONS = 6 -IPV6_CHECKSUM = 7 -IPV6_HOPLIMIT = 8 -IPV6_NEXTHOP = 9 -IPV6_AUTHHDR = 10 -IPV6_UNICAST_HOPS = 16 -IPV6_MULTICAST_IF = 17 -IPV6_MULTICAST_HOPS = 18 -IPV6_MULTICAST_LOOP = 19 -IPV6_JOIN_GROUP = 20 -IPV6_LEAVE_GROUP = 21 -IPV6_ROUTER_ALERT = 22 -IPV6_MTU_DISCOVER = 23 -IPV6_MTU = 24 -IPV6_RECVERR = 25 -IPV6_RXHOPOPTS = IPV6_HOPOPTS -IPV6_RXDSTOPTS = IPV6_DSTOPTS -IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP -IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP -IPV6_PMTUDISC_DONT = 0 -IPV6_PMTUDISC_WANT = 1 -IPV6_PMTUDISC_DO = 2 -SOL_IPV6 = 41 -SOL_ICMPV6 = 58 -IPV6_RTHDR_LOOSE = 0 -IPV6_RTHDR_STRICT = 1 -IPV6_RTHDR_TYPE_0 = 0 - -# Included from endian.h -_ENDIAN_H = 1 -__LITTLE_ENDIAN = 1234 -__BIG_ENDIAN = 4321 -__PDP_ENDIAN = 3412 - -# Included from bits/endian.h -__BYTE_ORDER = __LITTLE_ENDIAN -__FLOAT_WORD_ORDER = __BYTE_ORDER -LITTLE_ENDIAN = __LITTLE_ENDIAN -BIG_ENDIAN = __BIG_ENDIAN -PDP_ENDIAN = __PDP_ENDIAN -BYTE_ORDER = __BYTE_ORDER - -# Included from bits/byteswap.h -_BITS_BYTESWAP_H = 1 -def __bswap_constant_16(x): return \ - -def __bswap_16(x): return \ - -def __bswap_16(x): return __bswap_constant_16 (x) - -def __bswap_constant_32(x): return \ - -def __bswap_32(x): return \ - -def __bswap_32(x): return \ - -def __bswap_32(x): return __bswap_constant_32 (x) - -def __bswap_constant_64(x): return \ - -def __bswap_64(x): return \ - -def ntohl(x): return (x) - -def ntohs(x): return (x) - -def htonl(x): return (x) - -def htons(x): return (x) - -def ntohl(x): return __bswap_32 (x) - -def ntohs(x): return __bswap_16 (x) - -def htonl(x): return __bswap_32 (x) - -def htons(x): return __bswap_16 (x) - -def IN6_IS_ADDR_UNSPECIFIED(a): return \ - -def IN6_IS_ADDR_LOOPBACK(a): return \ - -def IN6_IS_ADDR_LINKLOCAL(a): return \ - -def IN6_IS_ADDR_SITELOCAL(a): return \ - -def IN6_IS_ADDR_V4MAPPED(a): return \ - -def IN6_IS_ADDR_V4COMPAT(a): return \ - -def IN6_IS_ADDR_MC_NODELOCAL(a): return \ - -def IN6_IS_ADDR_MC_LINKLOCAL(a): return \ - -def IN6_IS_ADDR_MC_SITELOCAL(a): return \ - -def IN6_IS_ADDR_MC_ORGLOCAL(a): return \ - -def IN6_IS_ADDR_MC_GLOBAL(a): return diff -r 95c34bce986c -r 900df5732f93 Lib/plat-linux3/TYPES.py --- a/Lib/plat-linux3/TYPES.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -# Generated by h2py from /usr/include/sys/types.h -_SYS_TYPES_H = 1 - -# Included from features.h -_FEATURES_H = 1 -__USE_ANSI = 1 -__FAVOR_BSD = 1 -_ISOC99_SOURCE = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 199506 -_XOPEN_SOURCE = 600 -_XOPEN_SOURCE_EXTENDED = 1 -_LARGEFILE64_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -_BSD_SOURCE = 1 -_SVID_SOURCE = 1 -__USE_ISOC99 = 1 -_POSIX_SOURCE = 1 -_POSIX_C_SOURCE = 2 -_POSIX_C_SOURCE = 199506 -__USE_POSIX = 1 -__USE_POSIX2 = 1 -__USE_POSIX199309 = 1 -__USE_POSIX199506 = 1 -__USE_XOPEN = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_UNIX98 = 1 -_LARGEFILE_SOURCE = 1 -__USE_XOPEN2K = 1 -__USE_ISOC99 = 1 -__USE_XOPEN_EXTENDED = 1 -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_FILE_OFFSET64 = 1 -__USE_MISC = 1 -__USE_BSD = 1 -__USE_SVID = 1 -__USE_GNU = 1 -__USE_REENTRANT = 1 -__STDC_IEC_559__ = 1 -__STDC_IEC_559_COMPLEX__ = 1 -__STDC_ISO_10646__ = 200009 -__GNU_LIBRARY__ = 6 -__GLIBC__ = 2 -__GLIBC_MINOR__ = 2 - -# Included from sys/cdefs.h -_SYS_CDEFS_H = 1 -def __PMT(args): return args - -def __P(args): return args - -def __PMT(args): return args - -def __STRING(x): return #x - -__flexarr = [] -__flexarr = [0] -__flexarr = [] -__flexarr = [1] -def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) - -def __attribute__(xyz): return - -def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) - -def __attribute_format_arg__(x): return - -__USE_LARGEFILE = 1 -__USE_LARGEFILE64 = 1 -__USE_EXTERN_INLINES = 1 - -# Included from gnu/stubs.h - -# Included from bits/types.h -_BITS_TYPES_H = 1 -__FD_SETSIZE = 1024 - -# Included from bits/pthreadtypes.h -_BITS_PTHREADTYPES_H = 1 - -# Included from bits/sched.h -SCHED_OTHER = 0 -SCHED_FIFO = 1 -SCHED_RR = 2 -CSIGNAL = 0x000000ff -CLONE_VM = 0x00000100 -CLONE_FS = 0x00000200 -CLONE_FILES = 0x00000400 -CLONE_SIGHAND = 0x00000800 -CLONE_PID = 0x00001000 -CLONE_PTRACE = 0x00002000 -CLONE_VFORK = 0x00004000 -__defined_schedparam = 1 - -# Included from time.h -_TIME_H = 1 - -# Included from bits/time.h -_BITS_TIME_H = 1 -CLOCKS_PER_SEC = 1000000 -CLOCK_REALTIME = 0 -CLOCK_PROCESS_CPUTIME_ID = 2 -CLOCK_THREAD_CPUTIME_ID = 3 -TIMER_ABSTIME = 1 -_STRUCT_TIMEVAL = 1 -CLK_TCK = CLOCKS_PER_SEC -__clock_t_defined = 1 -__time_t_defined = 1 -__clockid_t_defined = 1 -__timer_t_defined = 1 -__timespec_defined = 1 -def __isleap(year): return \ - -__BIT_TYPES_DEFINED__ = 1 - -# Included from endian.h -_ENDIAN_H = 1 -__LITTLE_ENDIAN = 1234 -__BIG_ENDIAN = 4321 -__PDP_ENDIAN = 3412 - -# Included from bits/endian.h -__BYTE_ORDER = __LITTLE_ENDIAN -__FLOAT_WORD_ORDER = __BYTE_ORDER -LITTLE_ENDIAN = __LITTLE_ENDIAN -BIG_ENDIAN = __BIG_ENDIAN -PDP_ENDIAN = __PDP_ENDIAN -BYTE_ORDER = __BYTE_ORDER - -# Included from sys/select.h -_SYS_SELECT_H = 1 - -# Included from bits/select.h -def __FD_ZERO(fdsp): return \ - -def __FD_ZERO(set): return \ - - -# Included from bits/sigset.h -_SIGSET_H_types = 1 -_SIGSET_H_fns = 1 -def __sigmask(sig): return \ - -def __sigemptyset(set): return \ - -def __sigfillset(set): return \ - -def __sigisemptyset(set): return \ - -def __FDELT(d): return ((d) / __NFDBITS) - -FD_SETSIZE = __FD_SETSIZE -def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp) - - -# Included from sys/sysmacros.h -_SYS_SYSMACROS_H = 1 -def major(dev): return ((int)(((dev) >> 8) & 0xff)) - -def minor(dev): return ((int)((dev) & 0xff)) - -def major(dev): return (((dev).__val[1] >> 8) & 0xff) - -def minor(dev): return ((dev).__val[1] & 0xff) - -def major(dev): return (((dev).__val[0] >> 8) & 0xff) - -def minor(dev): return ((dev).__val[0] & 0xff) diff -r 95c34bce986c -r 900df5732f93 Lib/plat-linux3/regen --- a/Lib/plat-linux3/regen Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -#! /bin/sh -case `uname` in -Linux*) ;; -*) echo Probably not on a Linux system 1>&2 - exit 1;; -esac -set -v -h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h diff -r 95c34bce986c -r 900df5732f93 Lib/platform.py --- a/Lib/platform.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/platform.py Mon Jul 25 09:47:18 2011 -0400 @@ -679,7 +679,6 @@ 0x2: 'PowerPC', 0xa: 'i386'}.get(sysa,'') - versioninfo=('', '', '') return release,versioninfo,machine def _mac_ver_xml(): diff -r 95c34bce986c -r 900df5732f93 Lib/plistlib.py --- a/Lib/plistlib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/plistlib.py Mon Jul 25 09:47:18 2011 -0400 @@ -266,13 +266,13 @@ raise AttributeError(attr) from warnings import warn warn("Attribute access from plist dicts is deprecated, use d[key] " - "notation instead", DeprecationWarning, 2) + "notation instead", PendingDeprecationWarning, 2) return value def __setattr__(self, attr, value): from warnings import warn warn("Attribute access from plist dicts is deprecated, use d[key] " - "notation instead", DeprecationWarning, 2) + "notation instead", PendingDeprecationWarning, 2) self[attr] = value def __delattr__(self, attr): @@ -282,14 +282,14 @@ raise AttributeError(attr) from warnings import warn warn("Attribute access from plist dicts is deprecated, use d[key] " - "notation instead", DeprecationWarning, 2) + "notation instead", PendingDeprecationWarning, 2) class Dict(_InternalDict): def __init__(self, **kwargs): from warnings import warn warn("The plistlib.Dict class is deprecated, use builtin dict instead", - DeprecationWarning, 2) + PendingDeprecationWarning, 2) super().__init__(**kwargs) @@ -302,7 +302,7 @@ def __init__(self, **kwargs): from warnings import warn warn("The Plist class is deprecated, use the readPlist() and " - "writePlist() functions instead", DeprecationWarning, 2) + "writePlist() functions instead", PendingDeprecationWarning, 2) super().__init__(**kwargs) def fromFile(cls, pathOrFile): diff -r 95c34bce986c -r 900df5732f93 Lib/profile.py --- a/Lib/profile.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/profile.py Mon Jul 25 09:47:18 2011 -0400 @@ -2,26 +2,35 @@ # # Class for profiling python code. rev 1.0 6/2/94 # -# Written by James Roskind # Based on prior profile module by Sjoerd Mullender... # which was hacked somewhat by: Guido van Rossum """Class for profiling Python code.""" -# Copyright Disney Enterprises, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement +# Copyright 1994, by InfoSeek Corporation, all rights reserved. +# Written by James Roskind # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Permission to use, copy, modify, and distribute this Python software +# and its associated documentation for any purpose (subject to the +# restriction in the following sentence) without fee is hereby granted, +# provided that the above copyright notice appears in all copies, and +# that both that copyright notice and this permission notice appear in +# supporting documentation, and that the name of InfoSeek not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. This permission is +# explicitly restricted to the copying and modification of the software +# to remain in Python, compiled Python, or other languages (such as C) +# wherein the modified or derived code is exclusively imported into a +# Python module. # -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -# either express or implied. See the License for the specific language -# governing permissions and limitations under the License. +# INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION BE LIABLE FOR ANY +# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF +# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + import sys diff -r 95c34bce986c -r 900df5732f93 Lib/pstats.py --- a/Lib/pstats.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/pstats.py Mon Jul 25 09:47:18 2011 -0400 @@ -2,26 +2,34 @@ # Class for printing reports on profiled python code. rev 1.0 4/1/94 # -# Written by James Roskind # Based on prior profile module by Sjoerd Mullender... # which was hacked somewhat by: Guido van Rossum +# +# see profile.py for more info. -"""Class for profiling Python code.""" - -# Copyright Disney Enterprises, Inc. All Rights Reserved. -# Licensed to PSF under a Contributor Agreement +# Copyright 1994, by InfoSeek Corporation, all rights reserved. +# Written by James Roskind # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at +# Permission to use, copy, modify, and distribute this Python software +# and its associated documentation for any purpose (subject to the +# restriction in the following sentence) without fee is hereby granted, +# provided that the above copyright notice appears in all copies, and +# that both that copyright notice and this permission notice appear in +# supporting documentation, and that the name of InfoSeek not be used in +# advertising or publicity pertaining to distribution of the software +# without specific, written prior permission. This permission is +# explicitly restricted to the copying and modification of the software +# to remain in Python, compiled Python, or other languages (such as C) +# wherein the modified or derived code is exclusively imported into a +# Python module. # -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -# either express or implied. See the License for the specific language -# governing permissions and limitations under the License. +# INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION BE LIABLE FOR ANY +# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF +# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. import sys diff -r 95c34bce986c -r 900df5732f93 Lib/pydoc.py --- a/Lib/pydoc.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/pydoc.py Mon Jul 25 09:47:18 2011 -0400 @@ -51,17 +51,16 @@ # the current directory is changed with os.chdir(), an incorrect # path will be displayed. +import os +import sys import builtins import imp +import io import inspect -import io -import os import pkgutil import platform import re -import sys import time -import tokenize import warnings from collections import deque from reprlib import Repr @@ -222,7 +221,7 @@ if lastupdate < mtime: info = inspect.getmoduleinfo(filename) try: - file = tokenize.open(filename) + file = open(filename) except IOError: # module can't be opened, so skip it return None @@ -250,18 +249,20 @@ def importfile(path): """Import a Python source file or compiled file given its path.""" magic = imp.get_magic() - with open(path, 'rb') as file: - if file.read(len(magic)) == magic: - kind = imp.PY_COMPILED - else: - kind = imp.PY_SOURCE - file.seek(0) - filename = os.path.basename(path) - name, ext = os.path.splitext(filename) - try: - module = imp.load_module(name, file, path, (ext, 'r', kind)) - except: - raise ErrorDuringImport(path, sys.exc_info()) + file = open(path, 'r') + if file.read(len(magic)) == magic: + kind = imp.PY_COMPILED + else: + kind = imp.PY_SOURCE + file.close() + filename = os.path.basename(path) + name, ext = os.path.splitext(filename) + file = open(path, 'r') + try: + module = imp.load_module(name, file, path, (ext, 'r', kind)) + except: + raise ErrorDuringImport(path, sys.exc_info()) + file.close() return module def safeimport(path, forceload=0, cache={}): @@ -2311,7 +2312,7 @@ def html_getfile(path): """Get and display a source file listing safely.""" path = path.replace('%20', ' ') - with tokenize.open(path) as fp: + with open(path, 'r') as fp: lines = html.escape(fp.read()) body = '
%s
' % lines heading = html.heading( diff -r 95c34bce986c -r 900df5732f93 Lib/random.py --- a/Lib/random.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/random.py Mon Jul 25 09:47:18 2011 -0400 @@ -402,9 +402,11 @@ # lambd: rate lambd = 1/mean # ('lambda' is a Python reserved word) - # we use 1-random() instead of random() to preclude the - # possibility of taking the log of zero. - return -_log(1.0 - self.random())/lambd + random = self.random + u = random() + while u <= 1e-7: + u = random() + return -_log(u)/lambd ## -------------------- von Mises distribution -------------------- diff -r 95c34bce986c -r 900df5732f93 Lib/runpy.py --- a/Lib/runpy.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/runpy.py Mon Jul 25 09:47:18 2011 -0400 @@ -226,7 +226,7 @@ code = read_code(f) if code is None: # That didn't work, so try it as normal source code - with open(fname, "rb") as f: + with open(fname, "r") as f: code = compile(f.read(), fname, 'exec') return code diff -r 95c34bce986c -r 900df5732f93 Lib/shutil.py --- a/Lib/shutil.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/shutil.py Mon Jul 25 09:47:18 2011 -0400 @@ -12,7 +12,6 @@ import collections import errno import tarfile -from collections import namedtuple try: import bz2 @@ -755,21 +754,3 @@ func = _UNPACK_FORMATS[format][1] kwargs = dict(_UNPACK_FORMATS[format][2]) func(filename, extract_dir, **kwargs) - -if hasattr(os, "statvfs") or os.name == 'nt': - _ntuple_diskusage = namedtuple('usage', 'total used free') - - def disk_usage(path): - """Return disk usage statistics about the given path as a namedtuple - including total, used and free space expressed in bytes. - """ - if hasattr(os, "statvfs"): - st = os.statvfs(path) - free = (st.f_bavail * st.f_frsize) - total = (st.f_blocks * st.f_frsize) - used = (st.f_blocks - st.f_bfree) * st.f_frsize - else: - import nt - total, free = nt._getdiskusage(path) - used = total - free - return _ntuple_diskusage(total, used, free) diff -r 95c34bce986c -r 900df5732f93 Lib/smtplib.py --- a/Lib/smtplib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/smtplib.py Mon Jul 25 09:47:18 2011 -0400 @@ -49,7 +49,6 @@ import email.generator import base64 import hmac -import copy from email.base64mime import body_encode as encode_base64 from sys import stderr @@ -133,25 +132,24 @@ combination provided. """ -def quoteaddr(addrstring): +def quoteaddr(addr): """Quote a subset of the email addresses defined by RFC 821. Should be able to handle anything email.utils.parseaddr can handle. """ - displayname, addr = email.utils.parseaddr(addrstring) - if (displayname, addr) == ('', ''): - # parseaddr couldn't parse it, use it as is and hope for the best. - if addrstring.strip().startswith('<'): - return addrstring - return "<%s>" % addrstring - return "<%s>" % addr - -def _addr_only(addrstring): - displayname, addr = email.utils.parseaddr(addrstring) - if (displayname, addr) == ('', ''): - # parseaddr couldn't parse it, so use it as is. - return addrstring - return addr + m = (None, None) + try: + m = email.utils.parseaddr(addr)[1] + except AttributeError: + pass + if m == (None, None): # Indicates parse failure or AttributeError + # something weird here.. punt -ddm + return "<%s>" % addr + elif m is None: + # the sender wants an empty return address + return "<>" + else: + return "<%s>" % m # Legacy method kept for backward compatibility. def quotedata(data): @@ -508,14 +506,14 @@ def verify(self, address): """SMTP 'verify' command -- checks for address validity.""" - self.putcmd("vrfy", _addr_only(address)) + self.putcmd("vrfy", quoteaddr(address)) return self.getreply() # a.k.a. vrfy = verify def expn(self, address): """SMTP 'expn' command -- expands a mailing list.""" - self.putcmd("expn", _addr_only(address)) + self.putcmd("expn", quoteaddr(address)) return self.getreply() # some useful methods @@ -678,7 +676,7 @@ msg may be a string containing characters in the ASCII range, or a byte string. A string is encoded to bytes using the ascii codec, and lone - \\r and \\n characters are converted to \\r\\n characters. + \r and \n characters are converted to \r\n characters. If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. If the server does ESMTP, message size @@ -761,49 +759,24 @@ """Converts message to a bytestring and passes it to sendmail. The arguments are as for sendmail, except that msg is an - email.message.Message object. If from_addr is None or to_addrs is - None, these arguments are taken from the headers of the Message as - described in RFC 2822 (a ValueError is raised if there is more than - one set of 'Resent-' headers). Regardless of the values of from_addr and - to_addr, any Bcc field (or Resent-Bcc field, when the Message is a - resent) of the Message object won't be transmitted. The Message - object is then serialized using email.generator.BytesGenerator and - sendmail is called to transmit the message. - + email.message.Message object. If from_addr is None, the from_addr is + taken from the 'From' header of the Message. If to_addrs is None, its + value is composed from the addresses listed in the 'To', 'CC', and + 'Bcc' fields. Regardless of the values of from_addr and to_addr, any + Bcc field in the Message object is deleted. The Message object is then + serialized using email.generator.BytesGenerator and sendmail is called + to transmit the message. """ - # 'Resent-Date' is a mandatory field if the Message is resent (RFC 2822 - # Section 3.6.6). In such a case, we use the 'Resent-*' fields. However, - # if there is more than one 'Resent-' block there's no way to - # unambiguously determine which one is the most recent in all cases, - # so rather than guess we raise a ValueError in that case. - # - # TODO implement heuristics to guess the correct Resent-* block with an - # option allowing the user to enable the heuristics. (It should be - # possible to guess correctly almost all of the time.) - resent =msg.get_all('Resent-Date') - if resent is None: - header_prefix = '' - elif len(resent) == 1: - header_prefix = 'Resent-' - else: - raise ValueError("message has more than one 'Resent-' header block") if from_addr is None: - # Prefer the sender field per RFC 2822:3.6.2. - from_addr = (msg[header_prefix+'Sender'] - if (header_prefix+'Sender') in msg - else msg[header_prefix+'From']) + from_addr = msg['From'] if to_addrs is None: - addr_fields = [f for f in (msg[header_prefix+'To'], - msg[header_prefix+'Bcc'], - msg[header_prefix+'Cc']) if f is not None] + addr_fields = [f for f in (msg['To'], msg['Bcc'], msg['CC']) + if f is not None] to_addrs = [a[1] for a in email.utils.getaddresses(addr_fields)] - # Make a local copy so we can delete the bcc headers. - msg_copy = copy.copy(msg) - del msg_copy['Bcc'] - del msg_copy['Resent-Bcc'] + del msg['Bcc'] with io.BytesIO() as bytesmsg: g = email.generator.BytesGenerator(bytesmsg) - g.flatten(msg_copy, linesep='\r\n') + g.flatten(msg, linesep='\r\n') flatmsg = bytesmsg.getvalue() return self.sendmail(from_addr, to_addrs, flatmsg, mail_options, rcpt_options) diff -r 95c34bce986c -r 900df5732f93 Lib/ssl.py --- a/Lib/ssl.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/ssl.py Mon Jul 25 09:47:18 2011 -0400 @@ -78,8 +78,6 @@ from _ssl import HAS_SNI from _ssl import (PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1) -from _ssl import _OPENSSL_API_VERSION - _PROTOCOL_NAMES = { PROTOCOL_TLSv1: "TLSv1", PROTOCOL_SSLv23: "SSLv23", @@ -99,10 +97,6 @@ import traceback import errno -if _ssl.HAS_TLS_UNIQUE: - CHANNEL_BINDING_TYPES = ['tls-unique'] -else: - CHANNEL_BINDING_TYPES = [] class CertificateError(ValueError): pass @@ -499,21 +493,6 @@ self.do_handshake_on_connect), addr) - def get_channel_binding(self, cb_type="tls-unique"): - """Get channel binding data for current connection. Raise ValueError - if the requested `cb_type` is not supported. Return bytes of the data - or None if the data is not available (e.g. before the handshake). - """ - if cb_type not in CHANNEL_BINDING_TYPES: - raise ValueError("Unsupported channel binding type") - if cb_type != "tls-unique": - raise NotImplementedError( - "{0} channel binding type not implemented" - .format(cb_type)) - if self._sslobj is None: - return None - return self._sslobj.tls_unique_cb() - def __del__(self): # sys.stderr.write("__del__ on %s\n" % repr(self)) self._real_close() diff -r 95c34bce986c -r 900df5732f93 Lib/stat.py --- a/Lib/stat.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/stat.py Mon Jul 25 09:47:18 2011 -0400 @@ -87,8 +87,6 @@ UF_APPEND = 0x00000004 UF_OPAQUE = 0x00000008 UF_NOUNLINK = 0x00000010 -UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed -UF_HIDDEN = 0x00008000 # OS X: file should not be displayed SF_ARCHIVED = 0x00010000 SF_IMMUTABLE = 0x00020000 SF_APPEND = 0x00040000 diff -r 95c34bce986c -r 900df5732f93 Lib/subprocess.py --- a/Lib/subprocess.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/subprocess.py Mon Jul 25 09:47:18 2011 -0400 @@ -446,7 +446,7 @@ while True: try: return func(*args) - except (OSError, IOError) as e: + except OSError as e: if e.errno == errno.EINTR: continue raise @@ -728,7 +728,7 @@ if p2cwrite != -1: self.stdin = io.open(p2cwrite, 'wb', bufsize) if self.universal_newlines: - self.stdin = io.TextIOWrapper(self.stdin, write_through=True) + self.stdin = io.TextIOWrapper(self.stdin) if c2pread != -1: self.stdout = io.open(c2pread, 'rb', bufsize) if universal_newlines: @@ -820,10 +820,10 @@ raise self.stdin.close() elif self.stdout: - stdout = _eintr_retry_call(self.stdout.read) + stdout = self.stdout.read() self.stdout.close() elif self.stderr: - stderr = _eintr_retry_call(self.stderr.read) + stderr = self.stderr.read() self.stderr.close() self.wait() else: diff -r 95c34bce986c -r 900df5732f93 Lib/tempfile.py --- a/Lib/tempfile.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/tempfile.py Mon Jul 25 09:47:18 2011 -0400 @@ -10,6 +10,8 @@ TMP_MAX - maximum number of names that will be tried before giving up. + template - the default prefix for all temporary names. + You may change this to control the default prefix. tempdir - If this is set to a string before the first use of any routine from this module, it will be considered as another candidate location to store temporary files. @@ -72,8 +74,6 @@ else: TMP_MAX = 10000 -# Although it does not have an underscore for historical reasons, this -# variable is an internal implementation detail (see issue 10354). template = "tmp" # Internal routines. diff -r 95c34bce986c -r 900df5732f93 Lib/test/data/README --- a/Lib/test/data/README Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/data/README Mon Jul 25 09:47:18 2011 -0400 @@ -1,2 +1,2 @@ This empty directory serves as destination for temporary files -created by some tests, in particular, the test_codecmaps_* tests. +created by some tests. diff -r 95c34bce986c -r 900df5732f93 Lib/test/regrtest.py --- a/Lib/test/regrtest.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/regrtest.py Mon Jul 25 09:47:18 2011 -0400 @@ -30,7 +30,7 @@ -v/--verbose -- run tests in verbose mode with output to stdout -w/--verbose2 -- re-run failed tests in verbose mode --W/--verbose3 -- display test output on failure +-W/--verbose3 -- re-run failed tests in verbose mode immediately -d/--debug -- print traceback for failed tests -q/--quiet -- no output unless one or more tests fail -S/--slow -- print the slowest 10 tests @@ -43,7 +43,6 @@ -f/--fromfile -- read names of tests to run from a file (see below) -x/--exclude -- arguments are tests to *exclude* -s/--single -- single step through a set of tests (see below) --G/--failfast -- fail as soon as a test fails (only with -v or -W) -u/--use RES1,RES2,... -- specify which special resource intensive tests to run -M/--memlimit LIMIT @@ -163,34 +162,24 @@ """ import builtins -import errno import faulthandler import getopt -import io import json -import logging import os -import platform import random import re -import signal +import io import sys +import time +import errno +import traceback +import warnings +import unittest +from inspect import isabstract +import tempfile +import platform import sysconfig -import tempfile -import time -import traceback -import unittest -import warnings -from inspect import isabstract - -try: - import threading -except ImportError: - threading = None -try: - import multiprocessing.process -except ImportError: - multiprocessing = None +import logging # Some times __path__ and __file__ are not absolute (e.g. while running from @@ -253,7 +242,7 @@ findleaks=False, use_resources=None, trace=False, coverdir='coverage', runleaks=False, huntrleaks=False, verbose2=False, print_slow=False, random_seed=None, use_mp=None, verbose3=False, forever=False, - header=False, failfast=False): + header=False): """Execute a test suite. This also parses command-line options and modifies its behavior @@ -277,30 +266,20 @@ on the command line. """ - # Display the Python traceback on fatal errors (e.g. segfault) + # Display the Python traceback fatal errors (e.g. segfault) faulthandler.enable(all_threads=True) - # Display the Python traceback on SIGALRM or SIGUSR1 signal - signals = [] - if hasattr(signal, 'SIGALRM'): - signals.append(signal.SIGALRM) - if hasattr(signal, 'SIGUSR1'): - signals.append(signal.SIGUSR1) - for signum in signals: - faulthandler.register(signum, chain=True) - replace_stdout() support.record_original_stdout(sys.stdout) try: - opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:G', + opts, args = getopt.getopt(sys.argv[1:], 'hvqxsSrf:lu:t:TD:NLR:FwWM:nj:', ['help', 'verbose', 'verbose2', 'verbose3', 'quiet', 'exclude', 'single', 'slow', 'random', 'fromfile', 'findleaks', 'use=', 'threshold=', 'trace', 'coverdir=', 'nocoverdir', 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'coverage', 'slaveargs=', 'forever', 'debug', - 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait', - 'failfast']) + 'start=', 'nowindows', 'header', 'testdir=', 'timeout=', 'wait']) except getopt.error as msg: usage(msg) @@ -324,8 +303,6 @@ debug = True elif o in ('-W', '--verbose3'): verbose3 = True - elif o in ('-G', '--failfast'): - failfast = True elif o in ('-q', '--quiet'): quiet = True; verbose = 0 @@ -458,8 +435,6 @@ usage("-T and -j don't go together!") if use_mp and findleaks: usage("-l and -j don't go together!") - if failfast and not (verbose or verbose3): - usage("-G/--failfast needs either -v or -W") good = [] bad = [] @@ -605,8 +580,7 @@ args_tuple = ( (test, verbose, quiet), dict(huntrleaks=huntrleaks, use_resources=use_resources, - debug=debug, output_on_failure=verbose3, - timeout=timeout, failfast=failfast) + debug=debug, rerun_failed=verbose3, timeout=timeout) ) yield (test, args_tuple) pending = tests_and_args() @@ -691,8 +665,7 @@ else: try: result = runtest(test, verbose, quiet, huntrleaks, debug, - output_on_failure=verbose3, - timeout=timeout, failfast=failfast) + rerun_failed=verbose3, timeout=timeout) accumulate_result(test, result) except KeyboardInterrupt: interrupted = True @@ -836,7 +809,7 @@ def runtest(test, verbose, quiet, huntrleaks=False, debug=False, use_resources=None, - output_on_failure=False, failfast=False, timeout=None): + rerun_failed=False, timeout=None): """Run a single test. test -- the name of the test @@ -845,7 +818,7 @@ test_times -- a list of (time, test_name) pairs huntrleaks -- run multiple times to test for leaks; requires a debug build; a triple corresponding to -R's three arguments - output_on_failure -- if true, display test output on failure + rerun_failed -- if true, re-run in verbose mode when failed timeout -- dump the traceback and exit if a test takes more than timeout seconds @@ -858,52 +831,25 @@ PASSED test passed """ + support.verbose = verbose # Tell tests to be moderately quiet if use_resources is not None: support.use_resources = use_resources use_timeout = (timeout is not None) if use_timeout: faulthandler.dump_tracebacks_later(timeout, exit=True) try: - if failfast: - support.failfast = True - if output_on_failure: - support.verbose = True - - # Reuse the same instance to all calls to runtest(). Some - # tests keep a reference to sys.stdout or sys.stderr - # (eg. test_argparse). - if runtest.stringio is None: - stream = io.StringIO() - runtest.stringio = stream - else: - stream = runtest.stringio - stream.seek(0) - stream.truncate() - - orig_stdout = sys.stdout - orig_stderr = sys.stderr - try: - sys.stdout = stream - sys.stderr = stream - result = runtest_inner(test, verbose, quiet, huntrleaks, - debug, display_failure=False) - if result[0] == FAILED: - output = stream.getvalue() - orig_stderr.write(output) - orig_stderr.flush() - finally: - sys.stdout = orig_stdout - sys.stderr = orig_stderr - else: - support.verbose = verbose # Tell tests to be moderately quiet - result = runtest_inner(test, verbose, quiet, huntrleaks, debug, - display_failure=not verbose) + result = runtest_inner(test, verbose, quiet, huntrleaks, debug) + if result[0] == FAILED and rerun_failed: + cleanup_test_droppings(test, verbose) + sys.stdout.flush() + sys.stderr.flush() + print("Re-running test {} in verbose mode".format(test)) + runtest(test, True, quiet, huntrleaks, debug, timeout=timeout) return result finally: if use_timeout: faulthandler.cancel_dump_tracebacks_later() cleanup_test_droppings(test, verbose) -runtest.stringio = None # Unit tests are supposed to leave the execution environment unchanged # once they complete. But sometimes tests have bugs, especially when @@ -948,8 +894,7 @@ 'os.environ', 'sys.path', 'sys.path_hooks', '__import__', 'warnings.filters', 'asyncore.socket_map', 'logging._handlers', 'logging._handlerList', 'sys.gettrace', - 'sys.warnoptions', 'threading._dangling', - 'multiprocessing.process._dangling') + 'sys.warnoptions') def get_sys_argv(self): return id(sys.argv), sys.argv, sys.argv[:] @@ -1042,31 +987,6 @@ sys.warnoptions = saved_options[1] sys.warnoptions[:] = saved_options[2] - # Controlling dangling references to Thread objects can make it easier - # to track reference leaks. - def get_threading__dangling(self): - if not threading: - return None - # This copies the weakrefs without making any strong reference - return threading._dangling.copy() - def restore_threading__dangling(self, saved): - if not threading: - return - threading._dangling.clear() - threading._dangling.update(saved) - - # Same for Process objects - def get_multiprocessing_process__dangling(self): - if not multiprocessing: - return None - # This copies the weakrefs without making any strong reference - return multiprocessing.process._dangling.copy() - def restore_multiprocessing_process__dangling(self, saved): - if not multiprocessing: - return - multiprocessing.process._dangling.clear() - multiprocessing.process._dangling.update(saved) - def resource_info(self): for name in self.resources: method_suffix = name.replace('.', '_') @@ -1100,8 +1020,7 @@ return False -def runtest_inner(test, verbose, quiet, - huntrleaks=False, debug=False, display_failure=True): +def runtest_inner(test, verbose, quiet, huntrleaks=False, debug=False): support.unload(test) test_time = 0.0 @@ -1139,10 +1058,7 @@ except KeyboardInterrupt: raise except support.TestFailed as msg: - if display_failure: - print("test", test, "failed --", msg, file=sys.stderr) - else: - print("test", test, "failed", file=sys.stderr) + print("test", test, "failed --", msg, file=sys.stderr) sys.stderr.flush() return FAILED, test_time except: diff -r 95c34bce986c -r 900df5732f93 Lib/test/support.py --- a/Lib/test/support.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/support.py Mon Jul 25 09:47:18 2011 -0400 @@ -24,15 +24,9 @@ import logging.handlers try: - import _thread, threading + import _thread except ImportError: _thread = None - threading = None -try: - import multiprocessing.process -except ImportError: - multiprocessing = None - try: import zlib @@ -46,7 +40,7 @@ "is_resource_enabled", "requires", "requires_linux_version", "requires_mac_ver", "find_unused_port", "bind_port", "IPV6_ENABLED", "is_jython", "TESTFN", "HOST", "SAVEDCWD", "temp_cwd", - "findfile", "create_empty_file", "sortdict", "check_syntax_error", "open_urlresource", + "findfile", "sortdict", "check_syntax_error", "open_urlresource", "check_warnings", "CleanImport", "EnvironmentVarGuard", "TransientResource", "captured_stdout", "captured_stdin", "captured_stderr", "time_out", "socket_peer_reset", "ioerror_peer_reset", "run_with_locale", 'temp_umask', @@ -55,7 +49,7 @@ "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "swap_item", "swap_attr", "requires_IEEE_754", "TestHandler", "Matcher", "can_symlink", "skip_unless_symlink", - "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE", "failfast", + "import_fresh_module", "requires_zlib", "PIPE_MAX_SIZE" ] class Error(Exception): @@ -170,7 +164,7 @@ attribute = getattr(obj, name) except AttributeError: raise unittest.SkipTest("module %s has no attribute %s" % ( - repr(obj), name)) + obj.__name__, name)) else: return attribute @@ -179,7 +173,6 @@ max_memuse = 0 # Disable bigmem tests (they will still be run with # small sizes, to make sure they work.) real_max_memuse = 0 -failfast = False # _original_stdout is meant to hold stdout at the time regrtest began. # This may be "the real" stdout, or IDLE's emulation of stdout, or whatever. @@ -296,7 +289,7 @@ return if not is_resource_enabled(resource): if msg is None: - msg = "Use of the %r resource not enabled" % resource + msg = "Use of the `%s' resource not enabled" % resource raise ResourceDenied(msg) def requires_linux_version(*min_version): @@ -578,15 +571,14 @@ rmtree(name) -if hasattr(os, "umask"): - @contextlib.contextmanager - def temp_umask(umask): - """Context manager that temporarily sets the process umask.""" - oldmask = os.umask(umask) - try: - yield - finally: - os.umask(oldmask) +@contextlib.contextmanager +def temp_umask(umask): + """Context manager that temporarily sets the process umask.""" + oldmask = os.umask(umask) + try: + yield + finally: + os.umask(oldmask) def findfile(file, here=__file__, subdir=None): @@ -604,11 +596,6 @@ if os.path.exists(fn): return fn return file -def create_empty_file(filename): - """Create an empty file. If the file already exists, truncate it.""" - fd = os.open(filename, os.O_WRONLY | os.O_CREAT | os.O_TRUNC) - os.close(fd) - def sortdict(dict): "Like repr(dict), but in sorted order." items = sorted(dict.items()) @@ -673,7 +660,7 @@ f = check_valid_file(fn) if f is not None: return f - raise TestFailed('invalid resource %r' % fn) + raise TestFailed('invalid resource "%s"' % fn) class WarningsRecorder(object): @@ -917,14 +904,13 @@ ('ETIMEDOUT', 110), ] default_gai_errnos = [ - ('EAI_AGAIN', -3), ('EAI_NONAME', -2), ('EAI_NODATA', -5), # Encountered when trying to resolve IPv6-only hostnames ('WSANO_DATA', 11004), ] - denied = ResourceDenied("Resource %r is not available" % resource_name) + denied = ResourceDenied("Resource '%s' is not available" % resource_name) captured_errnos = errnos gai_errnos = [] if not captured_errnos: @@ -1013,16 +999,6 @@ gc.collect() gc.collect() -@contextlib.contextmanager -def disable_gc(): - have_gc = gc.isenabled() - gc.disable() - try: - yield - finally: - if have_gc: - gc.enable() - def python_is_optimized(): """Find if Python was built with optimizations.""" @@ -1031,7 +1007,7 @@ for opt in cflags.split(): if opt.startswith('-O'): final_opt = opt - return final_opt != '' and final_opt != '-O0' + return final_opt and final_opt != '-O0' #======================================================================= @@ -1271,8 +1247,7 @@ def _run_suite(suite): """Run tests from a unittest.TestSuite-derived class.""" if verbose: - runner = unittest.TextTestRunner(sys.stdout, verbosity=2, - failfast=failfast) + runner = unittest.TextTestRunner(sys.stdout, verbosity=2) else: runner = BasicTestRunner() @@ -1323,9 +1298,16 @@ else: verbosity = None - f, t = doctest.testmod(module, verbose=verbosity) - if f: - raise TestFailed("%d of %d doctests failed" % (f, t)) + # Direct doctest output (normally just errors) to real stdout; doctest + # output shouldn't be compared by regrtest. + save_stdout = sys.stdout + sys.stdout = get_original_stdout() + try: + f, t = doctest.testmod(module, verbose=verbosity) + if f: + raise TestFailed("%d of %d doctests failed" % (f, t)) + finally: + sys.stdout = save_stdout if verbose: print('doctest (%s) ... %d tests with zero failures' % (module.__name__, t)) @@ -1367,20 +1349,19 @@ def threading_setup(): if _thread: - return _thread._count(), threading._dangling.copy() + return _thread._count(), else: - return 1, () + return 1, -def threading_cleanup(*original_values): +def threading_cleanup(nb_threads): if not _thread: return _MAX_COUNT = 10 for count in range(_MAX_COUNT): - values = _thread._count(), threading._dangling - if values == original_values: + n = _thread._count() + if n == nb_threads: break time.sleep(0.1) - gc_collect() # XXX print a warning in case of failure? def reap_threads(func): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_ast.py --- a/Lib/test/test_ast.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_ast.py Mon Jul 25 09:47:18 2011 -0400 @@ -20,24 +20,10 @@ # These tests are compiled through "exec" # There should be atleast one test per statement exec_tests = [ - # None - "None", # FunctionDef "def f(): pass", - # FunctionDef with arg - "def f(a): pass", - # FunctionDef with arg and default value - "def f(a=0): pass", - # FunctionDef with varargs - "def f(*args): pass", - # FunctionDef with kwargs - "def f(**kwargs): pass", - # FunctionDef with all kind of args - "def f(a, b=1, c=None, d=[], e={}, *args, **kwargs): pass", # ClassDef "class C:pass", - # ClassDef, new style class - "class C(object): pass", # Return "def f():return 1", # Delete @@ -81,27 +67,6 @@ "for a,b in c: pass", "[(a,b) for a,b in c]", "((a,b) for a,b in c)", - "((a,b) for (a,b) in c)", - # Multiline generator expression (test for .lineno & .col_offset) - """( - ( - Aa - , - Bb - ) - for - Aa - , - Bb in Cc - )""", - # dictcomp - "{a : b for w in x for m in p if g}", - # dictcomp with naked tuple - "{a : b for v,w in x}", - # setcomp - "{r for l in x if g}", - # setcomp with naked tuple - "{r for l,m in x}", ] # These are compiled through "single" @@ -114,8 +79,6 @@ # These are compiled through "eval" # It should test all expressions eval_tests = [ - # None - "None", # BoolOp "a and b", # BinOp @@ -126,16 +89,6 @@ "lambda:None", # Dict "{ 1:2 }", - # Empty dict - "{}", - # Set - "{None,}", - # Multiline dict (test for .lineno & .col_offset) - """{ - 1 - : - 2 - }""", # ListComp "[a for b in c if d]", # GeneratorExp @@ -158,14 +111,8 @@ "v", # List "[1,2,3]", - # Empty list - "[]", # Tuple "1,2,3", - # Tuple - "(1,2,3)", - # Empty tuple - "()", # Combination "a.b.c.d(a.b[1:2])", @@ -191,23 +138,6 @@ elif value is not None: self._assertTrueorder(value, parent_pos) - def test_AST_objects(self): - x = ast.AST() - self.assertEqual(x._fields, ()) - - with self.assertRaises(AttributeError): - x.vararg - - with self.assertRaises(AttributeError): - x.foobar = 21 - - with self.assertRaises(AttributeError): - ast.AST(lineno=2) - - with self.assertRaises(TypeError): - # "_ast.AST constructor takes 0 positional arguments" - ast.AST(2) - def test_snippets(self): for input, output, kind in ((exec_tests, exec_results, "exec"), (single_tests, single_results, "single"), @@ -235,85 +165,7 @@ self.assertTrue(issubclass(ast.comprehension, ast.AST)) self.assertTrue(issubclass(ast.Gt, ast.AST)) - def test_field_attr_existence(self): - for name, item in ast.__dict__.items(): - if isinstance(item, type) and name != 'AST' and name[0].isupper(): - x = item() - if isinstance(x, ast.AST): - self.assertEqual(type(x._fields), tuple) - - def test_arguments(self): - x = ast.arguments() - self.assertEqual(x._fields, ('args', 'vararg', 'varargannotation', - 'kwonlyargs', 'kwarg', 'kwargannotation', - 'defaults', 'kw_defaults')) - - with self.assertRaises(AttributeError): - x.vararg - - x = ast.arguments(*range(1, 9)) - self.assertEqual(x.vararg, 2) - - def test_field_attr_writable(self): - x = ast.Num() - # We can assign to _fields - x._fields = 666 - self.assertEqual(x._fields, 666) - - def test_classattrs(self): - x = ast.Num() - self.assertEqual(x._fields, ('n',)) - - with self.assertRaises(AttributeError): - x.n - - x = ast.Num(42) - self.assertEqual(x.n, 42) - - with self.assertRaises(AttributeError): - x.lineno - - with self.assertRaises(AttributeError): - x.foobar - - x = ast.Num(lineno=2) - self.assertEqual(x.lineno, 2) - - x = ast.Num(42, lineno=0) - self.assertEqual(x.lineno, 0) - self.assertEqual(x._fields, ('n',)) - self.assertEqual(x.n, 42) - - self.assertRaises(TypeError, ast.Num, 1, 2) - self.assertRaises(TypeError, ast.Num, 1, 2, lineno=0) - - def test_module(self): - body = [ast.Num(42)] - x = ast.Module(body) - self.assertEqual(x.body, body) - def test_nodeclasses(self): - # Zero arguments constructor explicitely allowed - x = ast.BinOp() - self.assertEqual(x._fields, ('left', 'op', 'right')) - - # Random attribute allowed too - x.foobarbaz = 5 - self.assertEqual(x.foobarbaz, 5) - - n1 = ast.Num(1) - n3 = ast.Num(3) - addop = ast.Add() - x = ast.BinOp(n1, addop, n3) - self.assertEqual(x.left, n1) - self.assertEqual(x.op, addop) - self.assertEqual(x.right, n3) - - x = ast.BinOp(1, 2, 3) - self.assertEqual(x.left, 1) - self.assertEqual(x.op, 2) - self.assertEqual(x.right, 3) - x = ast.BinOp(1, 2, 3, lineno=0) self.assertEqual(x.left, 1) self.assertEqual(x.op, 2) @@ -322,12 +174,6 @@ # node raises exception when not given enough arguments self.assertRaises(TypeError, ast.BinOp, 1, 2) - # node raises exception when given too many arguments - self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4) - # node raises exception when not given enough arguments - self.assertRaises(TypeError, ast.BinOp, 1, 2, lineno=0) - # node raises exception when given too many arguments - self.assertRaises(TypeError, ast.BinOp, 1, 2, 3, 4, lineno=0) # can set attributes through kwargs too x = ast.BinOp(left=1, op=2, right=3, lineno=0) @@ -336,14 +182,8 @@ self.assertEqual(x.right, 3) self.assertEqual(x.lineno, 0) - # Random kwargs also allowed - x = ast.BinOp(1, 2, 3, foobarbaz=42) - self.assertEqual(x.foobarbaz, 42) - - def test_no_fields(self): # this used to fail because Sub._fields was None x = ast.Sub() - self.assertEqual(x._fields, ()) def test_pickling(self): import pickle @@ -367,20 +207,6 @@ compile(m, "", "exec") self.assertIn("but got <_ast.expr", str(cm.exception)) - def test_invalid_identitifer(self): - m = ast.Module([ast.Expr(ast.Name(42, ast.Load()))]) - ast.fix_missing_locations(m) - with self.assertRaises(TypeError) as cm: - compile(m, "", "exec") - self.assertIn("identifier must be of type str", str(cm.exception)) - - def test_invalid_string(self): - m = ast.Module([ast.Expr(ast.Str(42))]) - ast.fix_missing_locations(m) - with self.assertRaises(TypeError) as cm: - compile(m, "", "exec") - self.assertIn("string must be of type str", str(cm.exception)) - class ASTHelpers_Test(unittest.TestCase): @@ -509,15 +335,8 @@ #### EVERYTHING BELOW IS GENERATED ##### exec_results = [ -('Module', [('Expr', (1, 0), ('Name', (1, 0), 'None', ('Load',)))]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Pass', (1, 9))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [], []), [('Pass', (1, 10))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None)], None, None, [], None, None, [('Num', (1, 8), 0)], []), [('Pass', (1, 12))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], 'args', None, [], None, None, [], []), [('Pass', (1, 14))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], 'kwargs', None, [], []), [('Pass', (1, 17))], [], None)]), -('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [('arg', 'a', None), ('arg', 'b', None), ('arg', 'c', None), ('arg', 'd', None), ('arg', 'e', None)], 'args', None, [], 'kwargs', None, [('Num', (1, 11), 1), ('Name', (1, 16), 'None', ('Load',)), ('List', (1, 24), [], ('Load',)), ('Dict', (1, 30), [], [])], []), [('Pass', (1, 52))], [], None)]), ('Module', [('ClassDef', (1, 0), 'C', [], [], None, None, [('Pass', (1, 8))], [])]), -('Module', [('ClassDef', (1, 0), 'C', [('Name', (1, 8), 'object', ('Load',))], [], None, None, [('Pass', (1, 17))], [])]), ('Module', [('FunctionDef', (1, 0), 'f', ('arguments', [], None, None, [], None, None, [], []), [('Return', (1, 8), ('Num', (1, 15), 1))], [], None)]), ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), @@ -541,26 +360,16 @@ ('Module', [('For', (1, 0), ('Tuple', (1, 4), [('Name', (1, 4), 'a', ('Store',)), ('Name', (1, 6), 'b', ('Store',))], ('Store',)), ('Name', (1, 11), 'c', ('Load',)), [('Pass', (1, 14))], [])]), ('Module', [('Expr', (1, 0), ('ListComp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), ('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'a', ('Store',)), ('Name', (1, 13), 'b', ('Store',))], ('Store',)), ('Name', (1, 18), 'c', ('Load',)), [])]))]), -('Module', [('Expr', (1, 0), ('GeneratorExp', (1, 1), ('Tuple', (1, 2), [('Name', (1, 2), 'a', ('Load',)), ('Name', (1, 4), 'b', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (1, 12), [('Name', (1, 12), 'a', ('Store',)), ('Name', (1, 14), 'b', ('Store',))], ('Store',)), ('Name', (1, 20), 'c', ('Load',)), [])]))]), -('Module', [('Expr', (1, 0), ('GeneratorExp', (2, 4), ('Tuple', (3, 4), [('Name', (3, 4), 'Aa', ('Load',)), ('Name', (5, 7), 'Bb', ('Load',))], ('Load',)), [('comprehension', ('Tuple', (8, 4), [('Name', (8, 4), 'Aa', ('Store',)), ('Name', (10, 4), 'Bb', ('Store',))], ('Store',)), ('Name', (10, 10), 'Cc', ('Load',)), [])]))]), -('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Name', (1, 11), 'w', ('Store',)), ('Name', (1, 16), 'x', ('Load',)), []), ('comprehension', ('Name', (1, 22), 'm', ('Store',)), ('Name', (1, 27), 'p', ('Load',)), [('Name', (1, 32), 'g', ('Load',))])]))]), -('Module', [('Expr', (1, 0), ('DictComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), ('Name', (1, 5), 'b', ('Load',)), [('comprehension', ('Tuple', (1, 11), [('Name', (1, 11), 'v', ('Store',)), ('Name', (1, 13), 'w', ('Store',))], ('Store',)), ('Name', (1, 18), 'x', ('Load',)), [])]))]), -('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 12), 'x', ('Load',)), [('Name', (1, 17), 'g', ('Load',))])]))]), -('Module', [('Expr', (1, 0), ('SetComp', (1, 1), ('Name', (1, 1), 'r', ('Load',)), [('comprehension', ('Tuple', (1, 7), [('Name', (1, 7), 'l', ('Store',)), ('Name', (1, 9), 'm', ('Store',))], ('Store',)), ('Name', (1, 14), 'x', ('Load',)), [])]))]), ] single_results = [ ('Interactive', [('Expr', (1, 0), ('BinOp', (1, 0), ('Num', (1, 0), 1), ('Add',), ('Num', (1, 2), 2)))]), ] eval_results = [ -('Expression', ('Name', (1, 0), 'None', ('Load',))), ('Expression', ('BoolOp', (1, 0), ('And',), [('Name', (1, 0), 'a', ('Load',)), ('Name', (1, 6), 'b', ('Load',))])), ('Expression', ('BinOp', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Add',), ('Name', (1, 4), 'b', ('Load',)))), ('Expression', ('UnaryOp', (1, 0), ('Not',), ('Name', (1, 4), 'v', ('Load',)))), ('Expression', ('Lambda', (1, 0), ('arguments', [], None, None, [], None, None, [], []), ('Name', (1, 7), 'None', ('Load',)))), ('Expression', ('Dict', (1, 0), [('Num', (1, 2), 1)], [('Num', (1, 4), 2)])), -('Expression', ('Dict', (1, 0), [], [])), -('Expression', ('Set', (1, 0), [('Name', (1, 1), 'None', ('Load',))])), -('Expression', ('Dict', (1, 0), [('Num', (2, 6), 1)], [('Num', (4, 10), 2)])), ('Expression', ('ListComp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('GeneratorExp', (1, 1), ('Name', (1, 1), 'a', ('Load',)), [('comprehension', ('Name', (1, 7), 'b', ('Store',)), ('Name', (1, 12), 'c', ('Load',)), [('Name', (1, 17), 'd', ('Load',))])])), ('Expression', ('Compare', (1, 0), ('Num', (1, 0), 1), [('Lt',), ('Lt',)], [('Num', (1, 4), 2), ('Num', (1, 8), 3)])), @@ -571,10 +380,7 @@ ('Expression', ('Subscript', (1, 0), ('Name', (1, 0), 'a', ('Load',)), ('Slice', ('Name', (1, 2), 'b', ('Load',)), ('Name', (1, 4), 'c', ('Load',)), None), ('Load',))), ('Expression', ('Name', (1, 0), 'v', ('Load',))), ('Expression', ('List', (1, 0), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), -('Expression', ('List', (1, 0), [], ('Load',))), ('Expression', ('Tuple', (1, 0), [('Num', (1, 0), 1), ('Num', (1, 2), 2), ('Num', (1, 4), 3)], ('Load',))), -('Expression', ('Tuple', (1, 1), [('Num', (1, 1), 1), ('Num', (1, 3), 2), ('Num', (1, 5), 3)], ('Load',))), -('Expression', ('Tuple', (1, 0), [], ('Load',))), ('Expression', ('Call', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Attribute', (1, 0), ('Name', (1, 0), 'a', ('Load',)), 'b', ('Load',)), 'c', ('Load',)), 'd', ('Load',)), [('Subscript', (1, 8), ('Attribute', (1, 8), ('Name', (1, 8), 'a', ('Load',)), 'b', ('Load',)), ('Slice', ('Num', (1, 12), 1), ('Num', (1, 14), 2), None), ('Load',))], [], None, None)), ] main() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_bz2.py --- a/Lib/test/test_bz2.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_bz2.py Mon Jul 25 09:47:18 2011 -0400 @@ -340,7 +340,7 @@ def testFileno(self): self.createTempFile() - with open(self.filename, 'rb') as rawf: + with open(self.filename) as rawf: with BZ2File(fileobj=rawf) as bz2f: self.assertEqual(bz2f.fileno(), rawf.fileno()) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_capi.py --- a/Lib/test/test_capi.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_capi.py Mon Jul 25 09:47:18 2011 -0400 @@ -145,9 +145,6 @@ class EmbeddingTest(unittest.TestCase): - @unittest.skipIf( - sys.platform.startswith('win'), - "test doesn't work under Windows") def test_subinterps(self): # XXX only tested under Unix checkouts basepath = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_cgi.py --- a/Lib/test/test_cgi.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_cgi.py Mon Jul 25 09:47:18 2011 -0400 @@ -155,7 +155,7 @@ cgi.logfp = None cgi.logfile = "/dev/null" cgi.initlog("%s", "Testing log 3") - self.addCleanup(cgi.closelog) + self.addCleanup(cgi.logfp.close) cgi.log("Testing log 4") def test_fieldstorage_readline(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_cgitb.py --- a/Lib/test/test_cgitb.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -from test.support import run_unittest -import unittest -import sys -import subprocess -import cgitb - -class TestCgitb(unittest.TestCase): - - def test_fonts(self): - text = "Hello Robbie!" - self.assertEqual(cgitb.small(text), "{}".format(text)) - self.assertEqual(cgitb.strong(text), "{}".format(text)) - self.assertEqual(cgitb.grey(text), - '{}'.format(text)) - - def test_blanks(self): - self.assertEqual(cgitb.small(""), "") - self.assertEqual(cgitb.strong(""), "") - self.assertEqual(cgitb.grey(""), "") - - def test_html(self): - try: - raise ValueError("Hello World") - except ValueError as err: - # If the html was templated we could do a bit more here. - # At least check that we get details on what we just raised. - html = cgitb.html(sys.exc_info()) - self.assertIn("ValueError", html) - self.assertIn(str(err), html) - - def test_text(self): - try: - raise ValueError("Hello World") - except ValueError as err: - text = cgitb.text(sys.exc_info()) - self.assertIn("ValueError", text) - self.assertIn("Hello World", text) - - def test_hook(self): - proc = subprocess.Popen([sys.executable, '-c', - ('import cgitb;' - 'cgitb.enable();' - 'raise ValueError("Hello World")')], - stdout=subprocess.PIPE) - out = proc.stdout.read().decode(sys.getfilesystemencoding()) - self.addCleanup(proc.stdout.close) - self.assertIn("ValueError", out) - self.assertIn("Hello World", out) - - -def test_main(): - run_unittest(TestCgitb) - -if __name__ == "__main__": - test_main() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_cmd_line.py --- a/Lib/test/test_cmd_line.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_cmd_line.py Mon Jul 25 09:47:18 2011 -0400 @@ -259,13 +259,6 @@ "print(repr(input()))", b"'abc'") - def test_unmached_quote(self): - # Issue #10206: python program starting with unmatched quote - # spewed spaces to stdout - rc, out, err = assert_python_failure('-c', "'") - self.assertRegex(err.decode('ascii', 'ignore'), 'SyntaxError') - self.assertEqual(b'', out) - def test_main(): test.support.run_unittest(CmdLineTest) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecencodings_cn.py --- a/Lib/test/test_codecencodings_cn.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecencodings_cn.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,8 +15,8 @@ # invalid bytes (b"abc\x81\x81\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x81\x81\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"), - (b"abc\x81\x81\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"), + (b"abc\x81\x81\xc1\xc4", "replace", "abc\ufffd\u804a"), + (b"abc\x81\x81\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), (b"abc\x81\x81\xc1\xc4", "ignore", "abc\u804a"), (b"\xc1\x64", "strict", None), ) @@ -28,8 +28,8 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u804a"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"), (b"\x83\x34\x83\x31", "strict", None), ("\u30fb", "strict", None), @@ -42,14 +42,11 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u804a"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u804a\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u804a"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u804a\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u804a"), - (b"abc\x84\x39\x84\x39\xc1\xc4", "replace", "abc\ufffd9\ufffd9\u804a"), + (b"abc\x84\x39\x84\x39\xc1\xc4", "replace", "abc\ufffd\u804a"), ("\u30fb", "strict", b"\x819\xa79"), - (b"abc\x84\x32\x80\x80def", "replace", 'abc\ufffd2\ufffd\ufffddef'), - (b"abc\x81\x30\x81\x30def", "strict", 'abc\x80def'), - (b"abc\x86\x30\x81\x30def", "replace", 'abc\ufffd0\ufffd0def'), ) has_iso10646 = True @@ -77,11 +74,9 @@ '\u5df1\u6240\u4e0d\u6b32\uff0c\u52ff\u65bd\u65bc\u4eba\u3002' 'Bye.\n'), # invalid bytes - (b'ab~cd', 'replace', 'ab\uFFFDcd'), + (b'ab~cd', 'replace', 'ab\uFFFDd'), (b'ab\xffcd', 'replace', 'ab\uFFFDcd'), (b'ab~{\x81\x81\x41\x44~}cd', 'replace', 'ab\uFFFD\uFFFD\u804Acd'), - (b'ab~{\x41\x44~}cd', 'replace', 'ab\u804Acd'), - (b"ab~{\x79\x79\x41\x44~}cd", "replace", "ab\ufffd\ufffd\u804acd"), ) def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecencodings_hk.py --- a/Lib/test/test_codecencodings_hk.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecencodings_hk.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,8 +15,8 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u8b10"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u8b10\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u8b10"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u8b10\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u8b10"), ) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecencodings_jp.py --- a/Lib/test/test_codecencodings_jp.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecencodings_jp.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,57 +15,50 @@ # invalid bytes (b"abc\x81\x00\x81\x00\x82\x84", "strict", None), (b"abc\xf8", "strict", None), - (b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\x00\uff44"), - (b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\x00\uff44\ufffd"), - (b"abc\x81\x00\x82\x84", "ignore", "abc\x00\uff44"), - (b"ab\xEBxy", "replace", "ab\uFFFDxy"), - (b"ab\xF0\x39xy", "replace", "ab\uFFFD9xy"), - (b"ab\xEA\xF0xy", "replace", 'ab\ufffd\ue038y'), + (b"abc\x81\x00\x82\x84", "replace", "abc\ufffd\uff44"), + (b"abc\x81\x00\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), + (b"abc\x81\x00\x82\x84", "ignore", "abc\uff44"), # sjis vs cp932 (b"\\\x7e", "replace", "\\\x7e"), (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\uff3c\u2225\uff0d"), ) -euc_commontests = ( - # invalid bytes - (b"abc\x80\x80\xc1\xc4", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u7956"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u7956\ufffd"), - (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), - (b"abc\xc8", "strict", None), - (b"abc\x8f\x83\x83", "replace", "abc\ufffd\ufffd\ufffd"), - (b"\x82\xFCxy", "replace", "\ufffd\ufffdxy"), - (b"\xc1\x64", "strict", None), - (b"\xa1\xc0", "strict", "\uff3c"), - (b"\xa1\xc0\\", "strict", "\uff3c\\"), - (b"\x8eXY", "replace", "\ufffdXY"), -) - -class Test_EUC_JIS_2004(test_multibytecodec_support.TestBase, - unittest.TestCase): - encoding = 'euc_jis_2004' - tstring = test_multibytecodec_support.load_teststring('euc_jisx0213') - codectests = euc_commontests - xmlcharnametest = ( - "\xab\u211c\xbb = \u2329\u1234\u232a", - b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" - ) - class Test_EUC_JISX0213(test_multibytecodec_support.TestBase, unittest.TestCase): encoding = 'euc_jisx0213' tstring = test_multibytecodec_support.load_teststring('euc_jisx0213') - codectests = euc_commontests + codectests = ( + # invalid bytes + (b"abc\x80\x80\xc1\xc4", "strict", None), + (b"abc\xc8", "strict", None), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"), + (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), + (b"abc\x8f\x83\x83", "replace", "abc\ufffd"), + (b"\xc1\x64", "strict", None), + (b"\xa1\xc0", "strict", "\uff3c"), + ) xmlcharnametest = ( "\xab\u211c\xbb = \u2329\u1234\u232a", b"\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩" ) +eucjp_commontests = ( + (b"abc\x80\x80\xc1\xc4", "strict", None), + (b"abc\xc8", "strict", None), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u7956"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u7956\ufffd"), + (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u7956"), + (b"abc\x8f\x83\x83", "replace", "abc\ufffd"), + (b"\xc1\x64", "strict", None), +) + class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase): encoding = 'euc_jp' tstring = test_multibytecodec_support.load_teststring('euc_jp') - codectests = euc_commontests + ( + codectests = eucjp_commontests + ( + (b"\xa1\xc0\\", "strict", "\uff3c\\"), ("\xa5", "strict", b"\x5c"), ("\u203e", "strict", b"\x7e"), ) @@ -73,6 +66,8 @@ shiftjis_commonenctests = ( (b"abc\x80\x80\x82\x84", "strict", None), (b"abc\xf8", "strict", None), + (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"), + (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"), ) @@ -80,41 +75,20 @@ encoding = 'shift_jis' tstring = test_multibytecodec_support.load_teststring('shift_jis') codectests = shiftjis_commonenctests + ( - (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"), - (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"), - (b"\\\x7e", "strict", "\\\x7e"), (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\uff3c\u2016\u2212"), - (b"abc\x81\x39", "replace", "abc\ufffd9"), - (b"abc\xEA\xFC", "replace", "abc\ufffd\ufffd"), - (b"abc\xFF\x58", "replace", "abc\ufffdX"), - ) - -class Test_SJIS_2004(test_multibytecodec_support.TestBase, unittest.TestCase): - encoding = 'shift_jis_2004' - tstring = test_multibytecodec_support.load_teststring('shift_jis') - codectests = shiftjis_commonenctests + ( - (b"\\\x7e", "strict", "\xa5\u203e"), - (b"\x81\x5f\x81\x61\x81\x7c", "strict", "\\\u2016\u2212"), - (b"abc\xEA\xFC", "strict", "abc\u64bf"), - (b"\x81\x39xy", "replace", "\ufffd9xy"), - (b"\xFF\x58xy", "replace", "\ufffdXxy"), - (b"\x80\x80\x82\x84xy", "replace", "\ufffd\ufffd\uff44xy"), - (b"\x80\x80\x82\x84\x88xy", "replace", "\ufffd\ufffd\uff44\u5864y"), - (b"\xFC\xFBxy", "replace", '\ufffd\u95b4y'), - ) - xmlcharnametest = ( - "\xab\u211c\xbb = \u2329\u1234\u232a", - b"\x85Gℜ\x85Q = ⟨ሴ⟩" ) class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase): encoding = 'shift_jisx0213' tstring = test_multibytecodec_support.load_teststring('shift_jisx0213') - codectests = shiftjis_commonenctests + ( - (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\ufffd\uff44"), - (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\ufffd\uff44\ufffd"), - + codectests = ( + # invalid bytes + (b"abc\x80\x80\x82\x84", "strict", None), + (b"abc\xf8", "strict", None), + (b"abc\x80\x80\x82\x84", "replace", "abc\ufffd\uff44"), + (b"abc\x80\x80\x82\x84\x88", "replace", "abc\ufffd\uff44\ufffd"), + (b"abc\x80\x80\x82\x84def", "ignore", "abc\uff44def"), # sjis vs cp932 (b"\\\x7e", "replace", "\xa5\u203e"), (b"\x81\x5f\x81\x61\x81\x7c", "replace", "\x5c\u2016\u2212"), diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecencodings_kr.py --- a/Lib/test/test_codecencodings_kr.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecencodings_kr.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,8 +15,8 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\uc894"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\uc894\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"), ) @@ -27,8 +27,8 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", 'abc\ufffd\ufffd\uc894'), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\uc894\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\uc894"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\uc894\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\uc894"), # composed make-up sequence errors @@ -40,14 +40,13 @@ (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4", "strict", None), (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "strict", "\uc4d4"), (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4x", "strict", "\uc4d4x"), - (b"a\xa4\xd4\xa4\xb6\xa4", "replace", 'a\ufffd'), + (b"a\xa4\xd4\xa4\xb6\xa4", "replace", "a\ufffd"), (b"\xa4\xd4\xa3\xb6\xa4\xd0\xa4\xd4", "strict", None), (b"\xa4\xd4\xa4\xb6\xa3\xd0\xa4\xd4", "strict", None), (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa3\xd4", "strict", None), - (b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", '\ufffd\u6e21\ufffd\u3160\ufffd'), - (b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", '\ufffd\u6e21\ub544\ufffd\ufffd'), - (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", '\ufffd\u6e21\ub544\u572d\ufffd'), - (b"\xa4\xd4\xff\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xd4", "replace", '\ufffd\ufffd\ufffd\uc4d4'), + (b"\xa4\xd4\xa4\xff\xa4\xd0\xa4\xd4", "replace", "\ufffd"), + (b"\xa4\xd4\xa4\xb6\xa4\xff\xa4\xd4", "replace", "\ufffd"), + (b"\xa4\xd4\xa4\xb6\xa4\xd0\xa4\xff", "replace", "\ufffd"), (b"\xc1\xc4", "strict", "\uc894"), ) @@ -58,13 +57,9 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\ucd27"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\ucd27\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ucd27"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ucd27\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\ucd27"), - (b"\xD8abc", "replace", "\uFFFDabc"), - (b"\xD8\xFFabc", "replace", "\uFFFD\uFFFDabc"), - (b"\x84bxy", "replace", "\uFFFDbxy"), - (b"\x8CBxy", "replace", "\uFFFDBxy"), ) def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecencodings_tw.py --- a/Lib/test/test_codecencodings_tw.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecencodings_tw.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,8 +15,8 @@ # invalid bytes (b"abc\x80\x80\xc1\xc4", "strict", None), (b"abc\xc8", "strict", None), - (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\ufffd\u8b10"), - (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\ufffd\u8b10\ufffd"), + (b"abc\x80\x80\xc1\xc4", "replace", "abc\ufffd\u8b10"), + (b"abc\x80\x80\xc1\xc4\xc8", "replace", "abc\ufffd\u8b10\ufffd"), (b"abc\x80\x80\xc1\xc4", "ignore", "abc\u8b10"), ) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecmaps_tw.py --- a/Lib/test/test_codecmaps_tw.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecmaps_tw.py Mon Jul 25 09:47:18 2011 -0400 @@ -23,9 +23,6 @@ (b'\xa2\xcc', '\u5341'), (b'\xa2\xce', '\u5345'), ] - codectests = ( - (b"\xFFxy", "replace", "\ufffdxy"), - ) def test_main(): support.run_unittest(__name__) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_codecs.py --- a/Lib/test/test_codecs.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_codecs.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,7 +1,6 @@ from test import support import unittest import codecs -import locale import sys, _testcapi, io class Queue(object): @@ -1231,19 +1230,6 @@ self.assertRaises(TypeError, codecs.getwriter) self.assertRaises(LookupError, codecs.getwriter, "__spam__") - def test_lookup_issue1813(self): - # Issue #1813: under Turkish locales, lookup of some codecs failed - # because 'I' is lowercased as "ı" (dotless i) - oldlocale = locale.getlocale(locale.LC_CTYPE) - self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) - try: - locale.setlocale(locale.LC_CTYPE, 'tr_TR') - except locale.Error: - # Unsupported locale on this system - self.skipTest('test needs Turkish locale') - c = codecs.lookup('ASCII') - self.assertEqual(c.name, 'ascii') - class StreamReaderTest(unittest.TestCase): def setUp(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_compileall.py --- a/Lib/test/test_compileall.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_compileall.py Mon Jul 25 09:47:18 2011 -0400 @@ -248,7 +248,7 @@ self.assertEqual(b'', quiet) def test_regexp(self): - self.assertRunOK('-q', '-x', r'ba[^\\/]*$', self.pkgdir) + self.assertRunOK('-q', '-x', 'ba[^\/]*$', self.pkgdir) self.assertNotCompiled(self.barfn) self.assertCompiled(self.initfn) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_concurrent_futures.py --- a/Lib/test/test_concurrent_futures.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_concurrent_futures.py Mon Jul 25 09:47:18 2011 -0400 @@ -367,13 +367,6 @@ self.assertEqual([None, None], results) - def test_shutdown_race_issue12456(self): - # Issue #12456: race condition at shutdown where trying to post a - # sentinel in the call queue blocks (the queue is full while processes - # have exited). - self.executor.map(str, [2] * (self.worker_count + 1)) - self.executor.shutdown() - class ThreadPoolExecutorTest(ThreadPoolMixin, ExecutorTest): def test_map_submits_without_iteration(self): @@ -623,21 +616,16 @@ self.assertTrue(isinstance(f1.exception(timeout=5), IOError)) -@test.support.reap_threads def test_main(): - try: - test.support.run_unittest(ProcessPoolExecutorTest, - ThreadPoolExecutorTest, - ProcessPoolWaitTests, - ThreadPoolWaitTests, - ProcessPoolAsCompletedTests, - ThreadPoolAsCompletedTests, - FutureTests, - ProcessPoolShutdownTest, - ThreadPoolShutdownTest, - ) - finally: - test.support.reap_children() + test.support.run_unittest(ProcessPoolExecutorTest, + ThreadPoolExecutorTest, + ProcessPoolWaitTests, + ThreadPoolWaitTests, + ProcessPoolAsCompletedTests, + ThreadPoolAsCompletedTests, + FutureTests, + ProcessPoolShutdownTest, + ThreadPoolShutdownTest) if __name__ == "__main__": test_main() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_copy.py --- a/Lib/test/test_copy.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_copy.py Mon Jul 25 09:47:18 2011 -0400 @@ -321,24 +321,9 @@ def test_deepcopy_keepalive(self): memo = {} - x = [] + x = 42 y = copy.deepcopy(x, memo) - self.assertIs(memo[id(memo)][0], x) - - def test_deepcopy_dont_memo_immutable(self): - memo = {} - x = [1, 2, 3, 4] - y = copy.deepcopy(x, memo) - self.assertEqual(y, x) - # There's the entry for the new list, and the keep alive. - self.assertEqual(len(memo), 2) - - memo = {} - x = [(1, 2)] - y = copy.deepcopy(x, memo) - self.assertEqual(y, x) - # Tuples with immutable contents are immutable for deepcopy. - self.assertEqual(len(memo), 2) + self.assertTrue(memo[id(x)] is x) def test_deepcopy_inst_vanilla(self): class C: diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_cprofile.py --- a/Lib/test/test_cprofile.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_cprofile.py Mon Jul 25 09:47:18 2011 -0400 @@ -18,19 +18,16 @@ def test_bad_counter_during_dealloc(self): import _lsprof # Must use a file as StringIO doesn't trigger the bug. - orig_stderr = sys.stderr - try: - with open(TESTFN, 'w') as file: - sys.stderr = file - try: - obj = _lsprof.Profiler(lambda: int) - obj.enable() - obj = _lsprof.Profiler(1) - obj.disable() - finally: - sys.stderr = orig_stderr - finally: - unlink(TESTFN) + with open(TESTFN, 'w') as file: + sys.stderr = file + try: + obj = _lsprof.Profiler(lambda: int) + obj.enable() + obj = _lsprof.Profiler(1) + obj.disable() + finally: + sys.stderr = sys.__stderr__ + unlink(TESTFN) def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_dbm.py --- a/Lib/test/test_dbm.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_dbm.py Mon Jul 25 09:47:18 2011 -0400 @@ -71,8 +71,8 @@ f.close() def test_anydbm_creation_n_file_exists_with_invalid_contents(self): - # create an empty file - test.support.create_empty_file(_fname) + with open(_fname, "w") as w: + pass # create an empty file f = dbm.open(_fname, 'n') self.addCleanup(f.close) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_descr.py --- a/Lib/test/test_descr.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_descr.py Mon Jul 25 09:47:18 2011 -0400 @@ -4247,14 +4247,6 @@ with self.assertRaises(TypeError): str.__add__(fake_str, "abc") - def test_repr_as_str(self): - # Issue #11603: crash or infinite loop when rebinding __str__ as - # __repr__. - class Foo: - pass - Foo.__repr__ = Foo.__str__ - foo = Foo() - str(foo) class DictProxyTests(unittest.TestCase): def setUp(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_dis.py --- a/Lib/test/test_dis.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_dis.py Mon Jul 25 09:47:18 2011 -0400 @@ -200,7 +200,7 @@ lines))) def test_opmap(self): - self.assertEqual(dis.opmap["NOP"], 9) + self.assertEqual(dis.opmap["STOP_CODE"], 0) self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst) self.assertIn(dis.opmap["STORE_NAME"], dis.hasname) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_email/test_email.py --- a/Lib/test/test_email/test_email.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_email/test_email.py Mon Jul 25 09:47:18 2011 -0400 @@ -1809,51 +1809,6 @@ unless(isinstance(self.get_defects(msg)[1], errors.MultipartInvariantViolationDefect)) - multipart_msg = textwrap.dedent("""\ - Date: Wed, 14 Nov 2007 12:56:23 GMT - From: foo@bar.invalid - To: foo@bar.invalid - Subject: Content-Transfer-Encoding: base64 and multipart - MIME-Version: 1.0 - Content-Type: multipart/mixed; - boundary="===============3344438784458119861=="{} - - --===============3344438784458119861== - Content-Type: text/plain - - Test message - - --===============3344438784458119861== - Content-Type: application/octet-stream - Content-Transfer-Encoding: base64 - - YWJj - - --===============3344438784458119861==-- - """) - - def test_multipart_invalid_cte(self): - msg = email.message_from_string( - self.multipart_msg.format("\nContent-Transfer-Encoding: base64"), - policy = self.policy) - self.assertEqual(len(self.get_defects(msg)), 1) - self.assertIsInstance(self.get_defects(msg)[0], - errors.InvalidMultipartContentTransferEncodingDefect) - - def test_multipart_no_cte_no_defect(self): - msg = email.message_from_string( - self.multipart_msg.format(''), - policy = self.policy) - self.assertEqual(len(self.get_defects(msg)), 0) - - def test_multipart_valid_cte_no_defect(self): - for cte in ('7bit', '8bit', 'BINary'): - msg = email.message_from_string( - self.multipart_msg.format( - "\nContent-Transfer-Encoding: {}".format(cte)), - policy = self.policy) - self.assertEqual(len(self.get_defects(msg)), 0) - def test_invalid_content_type(self): eq = self.assertEqual neq = self.ndiffAssertEqual diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_email/test_utils.py --- a/Lib/test/test_email/test_utils.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -import datetime -from email import utils -import unittest - -class DateTimeTests(unittest.TestCase): - - datestring = 'Sun, 23 Sep 2001 20:10:55' - dateargs = (2001, 9, 23, 20, 10, 55) - offsetstring = ' -0700' - utcoffset = datetime.timedelta(hours=-7) - tz = datetime.timezone(utcoffset) - naive_dt = datetime.datetime(*dateargs) - aware_dt = datetime.datetime(*dateargs, tzinfo=tz) - - def test_naive_datetime(self): - self.assertEqual(utils.format_datetime(self.naive_dt), - self.datestring + ' -0000') - - def test_aware_datetime(self): - self.assertEqual(utils.format_datetime(self.aware_dt), - self.datestring + self.offsetstring) - - def test_usegmt(self): - utc_dt = datetime.datetime(*self.dateargs, - tzinfo=datetime.timezone.utc) - self.assertEqual(utils.format_datetime(utc_dt, usegmt=True), - self.datestring + ' GMT') - - def test_usegmt_with_naive_datetime_raises(self): - with self.assertRaises(ValueError): - utils.format_datetime(self.naive_dt, usegmt=True) - - def test_usegmt_with_non_utc_datetime_raises(self): - with self.assertRaises(ValueError): - utils.format_datetime(self.aware_dt, usegmt=True) - - def test_parsedate_to_datetime(self): - self.assertEqual( - utils.parsedate_to_datetime(self.datestring + self.offsetstring), - self.aware_dt) - - def test_parsedate_to_datetime_naive(self): - self.assertEqual( - utils.parsedate_to_datetime(self.datestring + ' -0000'), - self.naive_dt) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_exceptions.py --- a/Lib/test/test_exceptions.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_exceptions.py Mon Jul 25 09:47:18 2011 -0400 @@ -567,33 +567,6 @@ del g self.assertEqual(sys.exc_info()[0], TypeError) - def test_generator_leaking2(self): - # See issue 12475. - def g(): - yield - try: - raise RuntimeError - except RuntimeError: - it = g() - next(it) - try: - next(it) - except StopIteration: - pass - self.assertEqual(sys.exc_info(), (None, None, None)) - - def test_generator_doesnt_retain_old_exc(self): - def g(): - self.assertIsInstance(sys.exc_info()[1], RuntimeError) - yield - self.assertEqual(sys.exc_info(), (None, None, None)) - it = g() - try: - raise RuntimeError - except RuntimeError: - next(it) - self.assertRaises(StopIteration, next, it) - def test_generator_finalizing_and_exc_info(self): # See #7173 def simple_gen(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_extcall.py --- a/Lib/test/test_extcall.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_extcall.py Mon Jul 25 09:47:18 2011 -0400 @@ -66,17 +66,17 @@ >>> g() Traceback (most recent call last): ... - TypeError: g() missing 1 required positional argument: 'x' + TypeError: g() takes at least 1 positional argument but 0 were given >>> g(*()) Traceback (most recent call last): ... - TypeError: g() missing 1 required positional argument: 'x' + TypeError: g() takes at least 1 positional argument but 0 were given >>> g(*(), **{}) Traceback (most recent call last): ... - TypeError: g() missing 1 required positional argument: 'x' + TypeError: g() takes at least 1 positional argument but 0 were given >>> g(1) 1 () {} @@ -263,80 +263,91 @@ >>> f(**x) 1 2 -Too many arguments: +Some additional tests about positional argument errors: - >>> def f(): pass + >>> def f(a, b): + ... pass + >>> f(b=1) + Traceback (most recent call last): + ... + TypeError: f() takes 2 positional arguments but 1 was given + + >>> def f(a): + ... pass + >>> f(6, a=4, *(1, 2, 3)) + Traceback (most recent call last): + ... + TypeError: f() got multiple values for argument 'a' + >>> def f(a, *, kw): + ... pass + >>> f(6, 4, kw=4) + Traceback (most recent call last): + ... + TypeError: f() takes 1 positional argument but 2 positional arguments (and 1 keyword-only argument) were given + + >>> def f(a): + ... pass + >>> f() + Traceback (most recent call last): + ... + TypeError: f() takes 1 positional argument but 0 were given + + >>> def f(a, b): + ... pass >>> f(1) Traceback (most recent call last): ... - TypeError: f() takes 0 positional arguments but 1 was given - >>> def f(a): pass - >>> f(1, 2) + TypeError: f() takes 2 positional arguments but 1 was given + + >>> def f(a, *b): + ... pass + >>> f() Traceback (most recent call last): ... - TypeError: f() takes 1 positional argument but 2 were given - >>> def f(a, b=1): pass - >>> f(1, 2, 3) + TypeError: f() takes at least 1 positional argument but 0 were given + + >>> def f(a, *, kw=4): + ... pass + >>> f(kw=4) Traceback (most recent call last): ... - TypeError: f() takes from 1 to 2 positional arguments but 3 were given - >>> def f(*, kw): pass - >>> f(1, kw=3) + TypeError: f() takes 1 positional argument but 0 positional arguments (and 1 keyword-only argument) were given + + >>> def f(a, b=2): + ... pass + >>> f() + Traceback (most recent call last): + ... + TypeError: f() takes from 1 to 2 positional arguments but 0 were given + + >>> def f(a, *b): + ... pass + >>> f() + Traceback (most recent call last): + ... + TypeError: f() takes at least 1 positional argument but 0 were given + + >>> def f(*, kw): + ... pass + >>> f(3, kw=4) Traceback (most recent call last): ... TypeError: f() takes 0 positional arguments but 1 positional argument (and 1 keyword-only argument) were given - >>> def f(*, kw, b): pass - >>> f(1, 2, 3, b=3, kw=3) - Traceback (most recent call last): - ... - TypeError: f() takes 0 positional arguments but 3 positional arguments (and 2 keyword-only arguments) were given - >>> def f(a, b=2, *, kw): pass - >>> f(2, 3, 4, kw=4) - Traceback (most recent call last): - ... - TypeError: f() takes from 1 to 2 positional arguments but 3 positional arguments (and 1 keyword-only argument) were given -Too few and missing arguments: - - >>> def f(a): pass + >>> def f(a, c=3, *b, kw): + ... pass >>> f() Traceback (most recent call last): - ... - TypeError: f() missing 1 required positional argument: 'a' - >>> def f(a, b): pass - >>> f() + ... + TypeError: f() takes at least 1 positional argument but 0 were given + >>> f(kw=3) Traceback (most recent call last): - ... - TypeError: f() missing 2 required positional arguments: 'a' and 'b' - >>> def f(a, b, c): pass - >>> f() + ... + TypeError: f() takes at least 1 positional argument but 0 positional arguments (and 1 keyword-only argument) were given + >>> f(kw=3, c=4) Traceback (most recent call last): - ... - TypeError: f() missing 3 required positional arguments: 'a', 'b', and 'c' - >>> def f(a, b, c, d, e): pass - >>> f() - Traceback (most recent call last): - ... - TypeError: f() missing 5 required positional arguments: 'a', 'b', 'c', 'd', and 'e' - >>> def f(a, b=4, c=5, d=5): pass - >>> f(c=12, b=9) - Traceback (most recent call last): - ... - TypeError: f() missing 1 required positional argument: 'a' - -Same with keyword only args: - - >>> def f(*, w): pass - >>> f() - Traceback (most recent call last): - ... - TypeError: f() missing 1 required keyword-only argument: 'w' - >>> def f(*, a, b, c, d, e): pass - >>> f() - Traceback (most recent call last): - ... - TypeError: f() missing 5 required keyword-only arguments: 'a', 'b', 'c', 'd', and 'e' - + ... + TypeError: f() takes at least 1 positional argument but 1 positional argument (and 1 keyword-only argument) were given """ import sys diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_faulthandler.py --- a/Lib/test/test_faulthandler.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_faulthandler.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,7 +1,6 @@ from contextlib import contextmanager import datetime import faulthandler -import os import re import signal import subprocess @@ -231,26 +230,17 @@ self.assertNotEqual(exitcode, 0) def test_is_enabled(self): - orig_stderr = sys.stderr + was_enabled = faulthandler.is_enabled() try: - # regrtest may replace sys.stderr by io.StringIO object, but - # faulthandler.enable() requires that sys.stderr has a fileno() - # method - sys.stderr = sys.__stderr__ - - was_enabled = faulthandler.is_enabled() - try: + faulthandler.enable() + self.assertTrue(faulthandler.is_enabled()) + faulthandler.disable() + self.assertFalse(faulthandler.is_enabled()) + finally: + if was_enabled: faulthandler.enable() - self.assertTrue(faulthandler.is_enabled()) + else: faulthandler.disable() - self.assertFalse(faulthandler.is_enabled()) - finally: - if was_enabled: - faulthandler.enable() - else: - faulthandler.disable() - finally: - sys.stderr = orig_stderr def check_dump_traceback(self, filename): """ @@ -452,13 +442,11 @@ @unittest.skipIf(not hasattr(faulthandler, "register"), "need faulthandler.register") def check_register(self, filename=False, all_threads=False, - unregister=False, chain=False): + unregister=False): """ Register a handler displaying the traceback on a user signal. Raise the signal and check the written traceback. - If chain is True, check that the previous signal handler is called. - Raise an error if the output doesn't match the expected format. """ signum = signal.SIGUSR1 @@ -466,41 +454,22 @@ import faulthandler import os import signal -import sys def func(signum): os.kill(os.getpid(), signum) -def handler(signum, frame): - handler.called = True -handler.called = False - -exitcode = 0 signum = {signum} unregister = {unregister} -chain = {chain} - if {has_filename}: file = open({filename}, "wb") else: file = None -if chain: - signal.signal(signum, handler) -faulthandler.register(signum, file=file, - all_threads={all_threads}, chain={chain}) +faulthandler.register(signum, file=file, all_threads={all_threads}) if unregister: faulthandler.unregister(signum) func(signum) -if chain and not handler.called: - if file is not None: - output = file - else: - output = sys.stderr - print("Error: signal handler not called!", file=output) - exitcode = 1 if file is not None: file.close() -sys.exit(exitcode) """.strip() code = code.format( filename=repr(filename), @@ -508,7 +477,6 @@ all_threads=all_threads, signum=signum, unregister=unregister, - chain=chain, ) trace, exitcode = self.get_output(code, filename) trace = '\n'.join(trace) @@ -517,7 +485,7 @@ regex = 'Current thread XXX:\n' else: regex = 'Traceback \(most recent call first\):\n' - regex = expected_traceback(7, 28, regex) + regex = expected_traceback(6, 17, regex) self.assertRegex(trace, regex) else: self.assertEqual(trace, '') @@ -539,9 +507,6 @@ def test_register_threads(self): self.check_register(all_threads=True) - def test_register_chain(self): - self.check_register(chain=True) - def test_main(): support.run_unittest(FaultHandlerTests) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_fcntl.py --- a/Lib/test/test_fcntl.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_fcntl.py Mon Jul 25 09:47:18 2011 -0400 @@ -62,7 +62,7 @@ def test_fcntl_fileno(self): # the example from the library docs - self.f = open(TESTFN, 'wb') + self.f = open(TESTFN, 'w') rv = fcntl.fcntl(self.f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) if verbose: print('Status from fcntl with O_NONBLOCK: ', rv) @@ -74,7 +74,7 @@ def test_fcntl_file_descriptor(self): # again, but pass the file rather than numeric descriptor - self.f = open(TESTFN, 'wb') + self.f = open(TESTFN, 'w') rv = fcntl.fcntl(self.f, fcntl.F_SETFL, os.O_NONBLOCK) if sys.platform not in ['os2emx']: rv = fcntl.fcntl(self.f, fcntl.F_SETLKW, lockdata) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_ftplib.py --- a/Lib/test/test_ftplib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_ftplib.py Mon Jul 25 09:47:18 2011 -0400 @@ -303,11 +303,11 @@ _ssl_closing = False def secure_connection(self): + self.del_channel() socket = ssl.wrap_socket(self.socket, suppress_ragged_eofs=False, certfile=CERTFILE, server_side=True, do_handshake_on_connect=False, ssl_version=ssl.PROTOCOL_SSLv23) - self.del_channel() self.set_socket(socket) self._ssl_accepting = True @@ -342,10 +342,7 @@ # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html pass self._ssl_closing = False - if getattr(self, '_ccc', False) == False: - super(SSLConnection, self).close() - else: - pass + super(SSLConnection, self).close() def handle_read_event(self): if self._ssl_accepting: @@ -413,18 +410,12 @@ def __init__(self, conn): DummyFTPHandler.__init__(self, conn) self.secure_data_channel = False - self._ccc = False def cmd_auth(self, line): """Set up secure control channel.""" self.push('234 AUTH TLS successful') self.secure_connection() - def cmd_ccc(self, line): - self.push('220 Reverting back to clear-text') - self._ccc = True - self._do_ssl_shutdown() - def cmd_pbsz(self, line): """Negotiate size of buffer for secure data transfer. For TLS/SSL the only valid value for the parameter is '0'. @@ -881,13 +872,6 @@ self.assertIs(sock.context, ctx) self.assertIsInstance(sock, ssl.SSLSocket) - def test_ccc(self): - self.assertRaises(ValueError, self.client.ccc) - self.client.login(secure=True) - self.assertIsInstance(self.client.sock, ssl.SSLSocket) - self.client.ccc() - self.assertRaises(ValueError, self.client.sock.unwrap) - class TestTimeouts(TestCase): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_future5.py --- a/Lib/test/test_future5.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_future5.py Mon Jul 25 09:47:18 2011 -0400 @@ -3,7 +3,7 @@ import sys import unittest -from test import support +from . import support class TestMultipleFeatures(unittest.TestCase): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_glob.py --- a/Lib/test/test_glob.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_glob.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,6 +1,5 @@ import unittest -from test.support import (run_unittest, TESTFN, skip_unless_symlink, - can_symlink, create_empty_file) +from test.support import run_unittest, TESTFN, skip_unless_symlink, can_symlink import glob import os import shutil @@ -15,7 +14,8 @@ base, file = os.path.split(filename) if not os.path.exists(base): os.makedirs(base) - create_empty_file(filename) + f = open(filename, 'w') + f.close() def setUp(self): self.tempdir = TESTFN+"_dir" diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_http_cookiejar.py --- a/Lib/test/test_http_cookiejar.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_http_cookiejar.py Mon Jul 25 09:47:18 2011 -0400 @@ -257,7 +257,7 @@ "filename should not exist") except IOError as exc: # exactly IOError, not LoadError - self.assertIs(exc.__class__, IOError) + self.assertEqual(exc.__class__, IOError) else: self.fail("expected IOError for invalid filename") # Invalid contents of cookies file (eg. bad magic string) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_imp.py --- a/Lib/test/test_imp.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_imp.py Mon Jul 25 09:47:18 2011 -0400 @@ -324,7 +324,8 @@ shutil.rmtree('pep3147') self.addCleanup(cleanup) # Touch the __init__.py file. - support.create_empty_file('pep3147/__init__.py') + with open('pep3147/__init__.py', 'w'): + pass m = __import__('pep3147') # Ensure we load the pyc file. support.forget('pep3147') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_import.py --- a/Lib/test/test_import.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_import.py Mon Jul 25 09:47:18 2011 -0400 @@ -14,7 +14,7 @@ from test.support import ( EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, - unlink, unload, create_empty_file) + unlink, unload) from test import script_helper @@ -103,7 +103,7 @@ sys.path.insert(0, os.curdir) try: fname = TESTFN + os.extsep + "py" - create_empty_file(fname) + open(fname, 'w').close() os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) __import__(TESTFN) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_io.py --- a/Lib/test/test_io.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_io.py Mon Jul 25 09:47:18 2011 -0400 @@ -611,24 +611,7 @@ self.assertEqual(rawio.read(2), b"") class CIOTest(IOTest): - - def test_IOBase_finalize(self): - # Issue #12149: segmentation fault on _PyIOBase_finalize when both a - # class which inherits IOBase and an object of this class are caught - # in a reference cycle and close() is already in the method cache. - class MyIO(self.IOBase): - def close(self): - pass - - # create an instance to populate the method cache - MyIO() - obj = MyIO() - obj.obj = obj - wr = weakref.ref(obj) - del MyIO - del obj - support.gc_collect() - self.assertTrue(wr() is None, wr) + pass class PyIOTest(IOTest): pass @@ -2314,27 +2297,6 @@ with self.assertRaises(AttributeError): txt.buffer = buf - def test_rawio(self): - # Issue #12591: TextIOWrapper must work with raw I/O objects, so - # that subprocess.Popen() can have the required unbuffered - # semantics with universal_newlines=True. - raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n']) - txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n') - # Reads - self.assertEqual(txt.read(4), 'abcd') - self.assertEqual(txt.readline(), 'efghi\n') - self.assertEqual(list(txt), ['jkl\n', 'opq\n']) - - def test_rawio_write_through(self): - # Issue #12591: with write_through=True, writes don't need a flush - raw = self.MockRawIO([b'abc', b'def', b'ghi\njkl\nopq\n']) - txt = self.TextIOWrapper(raw, encoding='ascii', newline='\n', - write_through=True) - txt.write('1') - txt.write('23\n4') - txt.write('5') - self.assertEqual(b''.join(raw._write_stack), b'123\n45') - class CTextIOWrapperTest(TextIOWrapperTest): def test_initialization(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_ioctl.py --- a/Lib/test/test_ioctl.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_ioctl.py Mon Jul 25 09:47:18 2011 -0400 @@ -7,7 +7,7 @@ get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature try: - tty = open("/dev/tty", "rb") + tty = open("/dev/tty", "r") except IOError: raise unittest.SkipTest("Unable to open /dev/tty") else: @@ -30,7 +30,7 @@ # If this process has been put into the background, TIOCGPGRP returns # the session ID instead of the process group id. ids = (os.getpgrp(), os.getsid(0)) - with open("/dev/tty", "rb") as tty: + with open("/dev/tty", "r") as tty: r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") rpgrp = struct.unpack("i", r)[0] self.assertIn(rpgrp, ids) @@ -47,7 +47,7 @@ self.assertEqual(len(buf) * intsize, nbytes) # sanity check else: buf.append(fill) - with open("/dev/tty", "rb") as tty: + with open("/dev/tty", "r") as tty: r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) rpgrp = buf[0] self.assertEqual(r, 0) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_itertools.py --- a/Lib/test/test_itertools.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_itertools.py Mon Jul 25 09:47:18 2011 -0400 @@ -168,8 +168,7 @@ self.assertEqual(result, list(combinations2(values, r))) # matches second pure python version self.assertEqual(result, list(combinations3(values, r))) # matches second pure python version - @support.impl_detail("tuple reuse is specific to CPython") - def test_combinations_tuple_reuse(self): + # Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1) @@ -239,9 +238,7 @@ self.assertEqual(result, list(cwr1(values, r))) # matches first pure python version self.assertEqual(result, list(cwr2(values, r))) # matches second pure python version - @support.impl_detail("tuple reuse is specific to CPython") - def test_combinations_with_replacement_tuple_reuse(self): - cwr = combinations_with_replacement + # Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1) @@ -305,8 +302,7 @@ self.assertEqual(result, list(permutations(values, None))) # test r as None self.assertEqual(result, list(permutations(values))) # test default r - @support.impl_detail("tuple resuse is CPython specific") - def test_permutations_tuple_reuse(self): + # Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1) @@ -570,13 +566,11 @@ self.assertEqual(list(zip()), lzip()) self.assertRaises(TypeError, zip, 3) self.assertRaises(TypeError, zip, range(3), 3) + # Check tuple re-use (implementation detail) self.assertEqual([tuple(list(pair)) for pair in zip('abc', 'def')], lzip('abc', 'def')) self.assertEqual([pair for pair in zip('abc', 'def')], lzip('abc', 'def')) - - @support.impl_detail("tuple reuse is specific to CPython") - def test_zip_tuple_reuse(self): ids = list(map(id, zip('abc', 'def'))) self.assertEqual(min(ids), max(ids)) ids = list(map(id, list(zip('abc', 'def')))) @@ -619,13 +613,11 @@ else: self.fail('Did not raise Type in: ' + stmt) + # Check tuple re-use (implementation detail) self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')], list(zip('abc', 'def'))) self.assertEqual([pair for pair in zip_longest('abc', 'def')], list(zip('abc', 'def'))) - - @support.impl_detail("tuple reuse is specific to CPython") - def test_zip_longest_tuple_reuse(self): ids = list(map(id, zip_longest('abc', 'def'))) self.assertEqual(min(ids), max(ids)) ids = list(map(id, list(zip_longest('abc', 'def')))) @@ -729,8 +721,7 @@ args = map(iter, args) self.assertEqual(len(list(product(*args))), expected_len) - @support.impl_detail("tuple reuse is specific to CPython") - def test_product_tuple_reuse(self): + # Test implementation detail: tuple re-use self.assertEqual(len(set(map(id, product('abc', 'def')))), 1) self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_kqueue.py --- a/Lib/test/test_kqueue.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_kqueue.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,12 +1,11 @@ """ Tests for kqueue wrapper. """ +import socket import errno -import os +import time import select -import socket import sys -import time import unittest from test import support @@ -24,10 +23,7 @@ def test_create_event(self): from operator import lt, le, gt, ge - - fd = os.open(os.devnull, os.O_WRONLY) - self.addCleanup(os.close, fd) - + fd = sys.stderr.fileno() ev = select.kevent(fd) other = select.kevent(1000) self.assertEqual(ev.ident, fd) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_locale.py --- a/Lib/test/test_locale.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_locale.py Mon Jul 25 09:47:18 2011 -0400 @@ -391,19 +391,6 @@ # crasher from bug #7419 self.assertRaises(locale.Error, locale.setlocale, 12345) - def test_getsetlocale_issue1813(self): - # Issue #1813: setting and getting the locale under a Turkish locale - oldlocale = locale.getlocale() - self.addCleanup(locale.setlocale, locale.LC_CTYPE, oldlocale) - try: - locale.setlocale(locale.LC_CTYPE, 'tr_TR') - except locale.Error: - # Unsupported locale on this system - self.skipTest('test needs Turkish locale') - loc = locale.getlocale() - locale.setlocale(locale.LC_CTYPE, loc) - self.assertEqual(loc, locale.getlocale()) - def test_main(): tests = [ diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_logging.py --- a/Lib/test/test_logging.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_logging.py Mon Jul 25 09:47:18 2011 -0400 @@ -1482,11 +1482,6 @@ logger.error("sp\xe4m") self.handled.wait() self.assertEqual(self.log_output, b'<11>\xef\xbb\xbfsp\xc3\xa4m') - self.handled.clear() - self.sl_hdlr.ident = "h\xe4m-" - logger.error("sp\xe4m") - self.handled.wait() - self.assertEqual(self.log_output, b'<11>\xef\xbb\xbfh\xc3\xa4m-sp\xc3\xa4m') @unittest.skipUnless(threading, 'Threading required for this test.') @@ -2923,8 +2918,6 @@ old_raise_exceptions = logging.raiseExceptions try: sys.stderr = sio = io.StringIO() - root.debug('This should not appear') - self.assertEqual(sio.getvalue(), '') root.warning('This is your final chance!') self.assertEqual(sio.getvalue(), 'This is your final chance!\n') #No handlers and no last resort, so 'No handlers' message diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_mailbox.py --- a/Lib/test/test_mailbox.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_mailbox.py Mon Jul 25 09:47:18 2011 -0400 @@ -902,7 +902,8 @@ # Now, write something into cur and remove it. This changes # the mtime and should cause a re-read. filename = os.path.join(self._path, 'cur', 'stray-file') - support.create_empty_file(filename) + f = open(filename, 'w') + f.close() os.unlink(filename) self._box._refresh() self.assertTrue(refreshed()) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_marshal.py --- a/Lib/test/test_marshal.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_marshal.py Mon Jul 25 09:47:18 2011 -0400 @@ -228,30 +228,6 @@ invalid_string = b'l\x02\x00\x00\x00\x00\x00\x00\x00' self.assertRaises(ValueError, marshal.loads, invalid_string) - def test_multiple_dumps_and_loads(self): - # Issue 12291: marshal.load() should be callable multiple times - # with interleaved data written by non-marshal code - # Adapted from a patch by Engelbert Gruber. - data = (1, 'abc', b'def', 1.0, (2, 'a', ['b', b'c'])) - for interleaved in (b'', b'0123'): - ilen = len(interleaved) - positions = [] - try: - with open(support.TESTFN, 'wb') as f: - for d in data: - marshal.dump(d, f) - if ilen: - f.write(interleaved) - positions.append(f.tell()) - with open(support.TESTFN, 'rb') as f: - for i, d in enumerate(data): - self.assertEqual(d, marshal.load(f)) - if ilen: - f.read(ilen) - self.assertEqual(positions[i], f.tell()) - finally: - support.unlink(support.TESTFN) - def test_main(): support.run_unittest(IntTestCase, diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_minidom.py --- a/Lib/test/test_minidom.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_minidom.py Mon Jul 25 09:47:18 2011 -0400 @@ -279,7 +279,6 @@ child.setAttribute("def", "ghi") self.confirm(len(child.attributes) == 1) - self.assertRaises(xml.dom.NotFoundErr, child.removeAttribute, "foo") child.removeAttribute("def") self.confirm(len(child.attributes) == 0) dom.unlink() @@ -291,8 +290,6 @@ child.setAttributeNS("http://www.w3.org", "xmlns:python", "http://www.python.org") child.setAttributeNS("http://www.python.org", "python:abcattr", "foo") - self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNS, - "foo", "http://www.python.org") self.confirm(len(child.attributes) == 2) child.removeAttributeNS("http://www.python.org", "abcattr") self.confirm(len(child.attributes) == 1) @@ -304,23 +301,11 @@ child.setAttribute("spam", "jam") self.confirm(len(child.attributes) == 1) node = child.getAttributeNode("spam") - self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode, - None) child.removeAttributeNode(node) self.confirm(len(child.attributes) == 0 and child.getAttributeNode("spam") is None) - dom2 = Document() - child2 = dom2.appendChild(dom.createElement("foo")) - self.assertRaises(xml.dom.NotFoundErr, child.removeAttributeNode, - node) dom.unlink() - def testHasAttribute(self): - dom = Document() - child = dom.appendChild(dom.createElement("foo")) - child.setAttribute("spam", "jam") - self.confirm(child.hasAttribute("spam")) - def testChangeAttr(self): dom = parseString("") el = dom.documentElement @@ -368,16 +353,7 @@ def testGetAttribute(self): pass - def testGetAttributeNS(self): - dom = Document() - child = dom.appendChild( - dom.createElementNS("http://www.python.org", "python:abc")) - child.setAttributeNS("http://www.w3.org", "xmlns:python", - "http://www.python.org") - self.assertEqual(child.getAttributeNS("http://www.w3.org", "python"), - 'http://www.python.org') - self.assertEqual(child.getAttributeNS("http://www.w3.org", "other"), - '') + def testGetAttributeNS(self): pass def testGetAttributeNode(self): pass @@ -561,13 +537,7 @@ def testFirstChild(self): pass - def testHasChildNodes(self): - dom = parseString("") - doc = dom.documentElement - self.assertTrue(dom.hasChildNodes()) - dom2 = parseString("") - doc2 = dom2.documentElement - self.assertFalse(doc2.hasChildNodes()) + def testHasChildNodes(self): pass def _testCloneElementCopiesAttributes(self, e1, e2, test): attrs1 = e1.attributes @@ -1469,14 +1439,6 @@ doc2 = parseString(doc.toxml()) self.confirm(doc2.namespaceURI == xml.dom.EMPTY_NAMESPACE) - def testDocRemoveChild(self): - doc = parse(tstfile) - title_tag = doc.documentElement.getElementsByTagName("TITLE")[0] - self.assertRaises( xml.dom.NotFoundErr, doc.removeChild, title_tag) - num_children_before = len(doc.childNodes) - doc.removeChild(doc.childNodes[0]) - num_children_after = len(doc.childNodes) - self.assertTrue(num_children_after == num_children_before - 1) def test_main(): run_unittest(MinidomTest) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_mmap.py --- a/Lib/test/test_mmap.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_mmap.py Mon Jul 25 09:47:18 2011 -0400 @@ -108,7 +108,7 @@ # Check that the underlying file is truncated too # (bug #728515) - f = open(TESTFN, 'rb') + f = open(TESTFN) try: f.seek(0, 2) self.assertEqual(f.tell(), 512) @@ -308,7 +308,7 @@ f.write(2**16 * b'a') # Arbitrary character f.close() - f = open(TESTFN, 'rb') + f = open(TESTFN) mf = mmap.mmap(f.fileno(), 2**16, access=mmap.ACCESS_READ) mf.close() mf.close() @@ -530,7 +530,7 @@ self.assertEqual(m[0:3], b'foo') # Check that the underlying file is truncated too - f = open(TESTFN, 'rb') + f = open(TESTFN) f.seek(0, 2) self.assertEqual(f.tell(), halfsize + 512) f.close() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_multiprocessing.py --- a/Lib/test/test_multiprocessing.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_multiprocessing.py Mon Jul 25 09:47:18 2011 -0400 @@ -1721,8 +1721,6 @@ # verify the state of the heap all = [] occupied = 0 - heap._lock.acquire() - self.addCleanup(heap._lock.release) for L in list(heap._len_to_seq.values()): for arena, start, stop in L: all.append((heap._arenas.index(arena), start, stop, @@ -1740,28 +1738,6 @@ self.assertTrue((arena != narena and nstart == 0) or (stop == nstart)) - def test_free_from_gc(self): - # Check that freeing of blocks by the garbage collector doesn't deadlock - # (issue #12352). - # Make sure the GC is enabled, and set lower collection thresholds to - # make collections more frequent (and increase the probability of - # deadlock). - if not gc.isenabled(): - gc.enable() - self.addCleanup(gc.disable) - thresholds = gc.get_threshold() - self.addCleanup(gc.set_threshold, *thresholds) - gc.set_threshold(10) - - # perform numerous block allocations, with cyclic references to make - # sure objects are collected asynchronously by the gc - for i in range(5000): - a = multiprocessing.heap.BufferWrapper(1) - b = multiprocessing.heap.BufferWrapper(1) - # circular references - a.buddy = b - b.buddy = a - # # # diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_optparse.py --- a/Lib/test/test_optparse.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_optparse.py Mon Jul 25 09:47:18 2011 -0400 @@ -1023,7 +1023,7 @@ TYPE_CHECKER["file"] = check_file def test_filetype_ok(self): - support.create_empty_file(support.TESTFN) + open(support.TESTFN, "w").close() self.assertParseOK(["--file", support.TESTFN, "-afoo"], {'file': support.TESTFN, 'a': 'foo'}, []) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_os.py --- a/Lib/test/test_os.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_os.py Mon Jul 25 09:47:18 2011 -0400 @@ -114,20 +114,124 @@ self.write_windows_console(sys.executable, "-c", code) self.write_windows_console(sys.executable, "-u", "-c", code) + +class TemporaryFileTests(unittest.TestCase): + def setUp(self): + self.files = [] + os.mkdir(support.TESTFN) + + def tearDown(self): + for name in self.files: + os.unlink(name) + os.rmdir(support.TESTFN) + + def check_tempfile(self, name): + # make sure it doesn't already exist: + self.assertFalse(os.path.exists(name), + "file already exists for temporary file") + # make sure we can create the file + open(name, "w") + self.files.append(name) + + def test_tempnam(self): + if not hasattr(os, "tempnam"): + return + warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, + r"test_os$") + self.check_tempfile(os.tempnam()) + + name = os.tempnam(support.TESTFN) + self.check_tempfile(name) + + name = os.tempnam(support.TESTFN, "pfx") + self.assertTrue(os.path.basename(name)[:3] == "pfx") + self.check_tempfile(name) + + def test_tmpfile(self): + if not hasattr(os, "tmpfile"): + return + # As with test_tmpnam() below, the Windows implementation of tmpfile() + # attempts to create a file in the root directory of the current drive. + # On Vista and Server 2008, this test will always fail for normal users + # as writing to the root directory requires elevated privileges. With + # XP and below, the semantics of tmpfile() are the same, but the user + # running the test is more likely to have administrative privileges on + # their account already. If that's the case, then os.tmpfile() should + # work. In order to make this test as useful as possible, rather than + # trying to detect Windows versions or whether or not the user has the + # right permissions, just try and create a file in the root directory + # and see if it raises a 'Permission denied' OSError. If it does, then + # test that a subsequent call to os.tmpfile() raises the same error. If + # it doesn't, assume we're on XP or below and the user running the test + # has administrative privileges, and proceed with the test as normal. + if sys.platform == 'win32': + name = '\\python_test_os_test_tmpfile.txt' + if os.path.exists(name): + os.remove(name) + try: + fp = open(name, 'w') + except IOError as first: + # open() failed, assert tmpfile() fails in the same way. + # Although open() raises an IOError and os.tmpfile() raises an + # OSError(), 'args' will be (13, 'Permission denied') in both + # cases. + try: + fp = os.tmpfile() + except OSError as second: + self.assertEqual(first.args, second.args) + else: + self.fail("expected os.tmpfile() to raise OSError") + return + else: + # open() worked, therefore, tmpfile() should work. Close our + # dummy file and proceed with the test as normal. + fp.close() + os.remove(name) + + fp = os.tmpfile() + fp.write("foobar") + fp.seek(0,0) + s = fp.read() + fp.close() + self.assertTrue(s == "foobar") + + def test_tmpnam(self): + if not hasattr(os, "tmpnam"): + return + warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, + r"test_os$") + name = os.tmpnam() + if sys.platform in ("win32",): + # The Windows tmpnam() seems useless. From the MS docs: + # + # The character string that tmpnam creates consists of + # the path prefix, defined by the entry P_tmpdir in the + # file STDIO.H, followed by a sequence consisting of the + # digit characters '0' through '9'; the numerical value + # of this string is in the range 1 - 65,535. Changing the + # definitions of L_tmpnam or P_tmpdir in STDIO.H does not + # change the operation of tmpnam. + # + # The really bizarre part is that, at least under MSVC6, + # P_tmpdir is "\\". That is, the path returned refers to + # the root of the current drive. That's a terrible place to + # put temp files, and, depending on privileges, the user + # may not even be able to open a file in the root directory. + self.assertFalse(os.path.exists(name), + "file already exists for temporary file") + else: + self.check_tempfile(name) + def fdopen_helper(self, *args): fd = os.open(support.TESTFN, os.O_RDONLY) - f = os.fdopen(fd, *args) - f.close() + fp2 = os.fdopen(fd, *args) + fp2.close() def test_fdopen(self): - fd = os.open(support.TESTFN, os.O_CREAT|os.O_RDWR) - os.close(fd) - self.fdopen_helper() self.fdopen_helper('r') self.fdopen_helper('r', 100) - # Test attributes on return values from os.*stat* family. class StatAttributeTests(unittest.TestCase): def setUp(self): @@ -590,11 +694,12 @@ class DevNullTests(unittest.TestCase): def test_devnull(self): - with open(os.devnull, 'wb') as f: - f.write(b'hello') - f.close() - with open(os.devnull, 'rb') as f: - self.assertEqual(f.read(), b'') + f = open(os.devnull, 'w') + f.write('hello') + f.close() + f = open(os.devnull, 'r') + self.assertEqual(f.read(), '') + f.close() class URandomTests(unittest.TestCase): def test_urandom(self): @@ -924,7 +1029,8 @@ os.mkdir(self.dir) try: for fn in bytesfn: - support.create_empty_file(os.path.join(self.bdir, fn)) + f = open(os.path.join(self.bdir, fn), "w") + f.close() fn = os.fsdecode(fn) if fn in self.unicodefn: raise ValueError("duplicate filename") @@ -943,7 +1049,7 @@ def test_open(self): for fn in self.unicodefn: - f = open(os.path.join(self.dir, fn), 'rb') + f = open(os.path.join(self.dir, fn)) f.close() def test_stat(self): @@ -1506,7 +1612,6 @@ raise -@support.reap_threads def test_main(): support.run_unittest( FileTests, diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_pkgimport.py --- a/Lib/test/test_pkgimport.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_pkgimport.py Mon Jul 25 09:47:18 2011 -0400 @@ -7,7 +7,7 @@ import unittest from imp import cache_from_source -from test.support import run_unittest, create_empty_file +from test.support import run_unittest class TestImport(unittest.TestCase): @@ -29,7 +29,7 @@ self.package_dir = os.path.join(self.test_dir, self.package_name) os.mkdir(self.package_dir) - create_empty_file(os.path.join(self.package_dir, '__init__.py')) + open(os.path.join(self.package_dir, '__init__.py'), 'w').close() self.module_path = os.path.join(self.package_dir, 'foo.py') def tearDown(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_platform.py --- a/Lib/test/test_platform.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_platform.py Mon Jul 25 09:47:18 2011 -0400 @@ -191,7 +191,7 @@ self.assertEqual(res[1], ('', '', '')) if sys.byteorder == 'little': - self.assertIn(res[2], ('i386', 'x86_64')) + self.assertEqual(res[2], 'i386') else: self.assertEqual(res[2], 'PowerPC') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_posix.py Mon Jul 25 09:47:18 2011 -0400 @@ -16,7 +16,6 @@ import unittest import warnings -_DUMMY_SYMLINK = '%s/dummy-symlink' % os.getenv('TMPDIR', '/tmp') class PosixTester(unittest.TestCase): @@ -24,15 +23,13 @@ # create empty file fp = open(support.TESTFN, 'w+') fp.close() - self.teardown_files = [ support.TESTFN ] self._warnings_manager = support.check_warnings() self._warnings_manager.__enter__() warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning) def tearDown(self): - for teardown_file in self.teardown_files: - support.unlink(teardown_file) + support.unlink(support.TESTFN) self._warnings_manager.__exit__(None, None, None) def testNoArgFunctions(self): @@ -410,7 +407,7 @@ self.assertRaises(OSError, posix.chown, support.TESTFN, -1, -1) # re-create the file - support.create_empty_file(support.TESTFN) + open(support.TESTFN, 'w').close() self._test_all_chown_common(posix.chown, support.TESTFN) @unittest.skipUnless(hasattr(posix, 'fchown'), "test needs os.fchown()") @@ -429,7 +426,7 @@ def test_lchown(self): os.unlink(support.TESTFN) # create a symlink - os.symlink(_DUMMY_SYMLINK, support.TESTFN) + os.symlink('/tmp/dummy-symlink-target', support.TESTFN) self._test_all_chown_common(posix.lchown, support.TESTFN) def test_chdir(self): @@ -514,49 +511,17 @@ posix.utime(support.TESTFN, (int(now), int(now))) posix.utime(support.TESTFN, (now, now)) - def _test_chflags_regular_file(self, chflags_func, target_file): - st = os.stat(target_file) - self.assertTrue(hasattr(st, 'st_flags')) - chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE) - try: - new_st = os.stat(target_file) - self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags) - try: - fd = open(target_file, 'w+') - except IOError as e: - self.assertEqual(e.errno, errno.EPERM) - finally: - posix.chflags(target_file, st.st_flags) + def test_chflags(self): + if hasattr(posix, 'chflags'): + st = os.stat(support.TESTFN) + if hasattr(st, 'st_flags'): + posix.chflags(support.TESTFN, st.st_flags) - @unittest.skipUnless(hasattr(posix, 'chflags'), 'test needs os.chflags()') - def test_chflags(self): - self._test_chflags_regular_file(posix.chflags, support.TESTFN) - - @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()') - def test_lchflags_regular_file(self): - self._test_chflags_regular_file(posix.lchflags, support.TESTFN) - - @unittest.skipUnless(hasattr(posix, 'lchflags'), 'test needs os.lchflags()') - def test_lchflags_symlink(self): - testfn_st = os.stat(support.TESTFN) - - self.assertTrue(hasattr(testfn_st, 'st_flags')) - - os.symlink(support.TESTFN, _DUMMY_SYMLINK) - self.teardown_files.append(_DUMMY_SYMLINK) - dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) - - posix.lchflags(_DUMMY_SYMLINK, - dummy_symlink_st.st_flags | stat.UF_IMMUTABLE) - try: - new_testfn_st = os.stat(support.TESTFN) - new_dummy_symlink_st = os.lstat(_DUMMY_SYMLINK) - - self.assertEqual(testfn_st.st_flags, new_testfn_st.st_flags) - self.assertEqual(dummy_symlink_st.st_flags | stat.UF_IMMUTABLE, - new_dummy_symlink_st.st_flags) - finally: - posix.lchflags(_DUMMY_SYMLINK, dummy_symlink_st.st_flags) + def test_lchflags(self): + if hasattr(posix, 'lchflags'): + st = os.stat(support.TESTFN) + if hasattr(st, 'st_flags'): + posix.lchflags(support.TESTFN, st.st_flags) def test_environ(self): if os.name == "nt": @@ -661,7 +626,7 @@ @unittest.skipUnless(hasattr(posix, 'fchownat'), "test needs posix.fchownat()") def test_fchownat(self): support.unlink(support.TESTFN) - support.create_empty_file(support.TESTFN) + open(support.TESTFN, 'w').close() f = posix.open(posix.getcwd(), posix.O_RDONLY) try: @@ -766,7 +731,7 @@ @unittest.skipUnless(hasattr(posix, 'renameat'), "test needs posix.renameat()") def test_renameat(self): support.unlink(support.TESTFN) - support.create_empty_file(support.TESTFN + 'ren') + open(support.TESTFN + 'ren', 'w').close() f = posix.open(posix.getcwd(), posix.O_RDONLY) try: posix.renameat(f, support.TESTFN + 'ren', f, support.TESTFN) @@ -791,7 +756,7 @@ @unittest.skipUnless(hasattr(posix, 'unlinkat'), "test needs posix.unlinkat()") def test_unlinkat(self): f = posix.open(posix.getcwd(), posix.O_RDONLY) - support.create_empty_file(support.TESTFN + 'del') + open(support.TESTFN + 'del', 'w').close() posix.stat(support.TESTFN + 'del') # should not throw exception try: posix.unlinkat(f, support.TESTFN + 'del') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_pydoc.py --- a/Lib/test/test_pydoc.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_pydoc.py Mon Jul 25 09:47:18 2011 -0400 @@ -15,12 +15,9 @@ from io import StringIO from collections import namedtuple from contextlib import contextmanager +from test.support import TESTFN, forget, rmtree, EnvironmentVarGuard, \ + reap_children, captured_output, captured_stdout -from test.script_helper import assert_python_ok -from test.support import ( - TESTFN, forget, rmtree, EnvironmentVarGuard, - reap_children, reap_threads, captured_output, captured_stdout, unlink -) from test import pydoc_mod try: @@ -202,14 +199,17 @@ # output pattern for module with bad imports badimport_pattern = "problem in %s - ImportError: No module named %r" -def run_pydoc(module_name, *args, **env): +def run_pydoc(module_name, *args): """ Runs pydoc on the specified module. Returns the stripped output of pydoc. """ - args = args + (module_name,) - rc, out, err = assert_python_ok(pydoc.__file__, *args, **env) - return out.strip() + cmd = [sys.executable, pydoc.__file__, " ".join(args), module_name] + try: + output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] + return output.strip() + finally: + reap_children() def get_pydoc_html(module): "Returns pydoc generated output as html" @@ -312,20 +312,19 @@ def newdirinpath(dir): os.mkdir(dir) sys.path.insert(0, dir) - try: - yield - finally: - sys.path.pop(0) - rmtree(dir) + yield + sys.path.pop(0) + rmtree(dir) - with newdirinpath(TESTFN): + with newdirinpath(TESTFN), EnvironmentVarGuard() as env: + env['PYTHONPATH'] = TESTFN fullmodname = os.path.join(TESTFN, modname) sourcefn = fullmodname + os.extsep + "py" for importstring, expectedinmsg in testpairs: with open(sourcefn, 'w') as f: f.write("import {}\n".format(importstring)) try: - result = run_pydoc(modname, PYTHONPATH=TESTFN).decode("ascii") + result = run_pydoc(modname).decode("ascii") finally: forget(modname) expected = badimport_pattern % (modname, expectedinmsg) @@ -396,17 +395,6 @@ self.assertIn('_replace', helptext) self.assertIn('_asdict', helptext) - def test_synopsis(self): - self.addCleanup(unlink, TESTFN) - for encoding in ('ISO-8859-1', 'UTF-8'): - with open(TESTFN, 'w', encoding=encoding) as script: - if encoding != 'UTF-8': - print('#coding: {}'.format(encoding), file=script) - print('"""line 1: h\xe9', file=script) - print('line 2: hi"""', file=script) - synopsis = pydoc.synopsis(TESTFN, {}) - self.assertEqual(synopsis, 'line 1: h\xe9') - class TestDescriptions(unittest.TestCase): @@ -495,17 +483,13 @@ self.assertEqual(sorted(pydoc.Helper.keywords), sorted(keyword.kwlist)) -@reap_threads def test_main(): - try: - test.support.run_unittest(PydocDocTest, - TestDescriptions, - PydocServerTest, - PydocUrlHandlerTest, - TestHelper, - ) - finally: - reap_children() + test.support.run_unittest(PydocDocTest, + TestDescriptions, + PydocServerTest, + PydocUrlHandlerTest, + TestHelper, + ) if __name__ == "__main__": test_main() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_raise.py --- a/Lib/test/test_raise.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_raise.py Mon Jul 25 09:47:18 2011 -0400 @@ -121,15 +121,6 @@ else: self.fail("No exception raised") - def test_new_returns_invalid_instance(self): - # See issue #11627. - class MyException(Exception): - def __new__(cls, *args): - return object() - - with self.assertRaises(TypeError): - raise MyException - class TestCause(unittest.TestCase): def test_invalid_cause(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_reprlib.py --- a/Lib/test/test_reprlib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_reprlib.py Mon Jul 25 09:47:18 2011 -0400 @@ -8,7 +8,7 @@ import shutil import unittest -from test.support import run_unittest, create_empty_file +from test.support import run_unittest from reprlib import repr as r # Don't shadow builtin repr from reprlib import Repr from reprlib import recursive_repr @@ -193,9 +193,10 @@ r(y) r(z) -def write_file(path, text): - with open(path, 'w', encoding='ASCII') as fp: - fp.write(text) +def touch(path, text=''): + fp = open(path, 'w') + fp.write(text) + fp.close() class LongReprTest(unittest.TestCase): def setUp(self): @@ -205,10 +206,10 @@ # Make the package and subpackage shutil.rmtree(self.pkgname, ignore_errors=True) os.mkdir(self.pkgname) - create_empty_file(os.path.join(self.pkgname, '__init__.py')) + touch(os.path.join(self.pkgname, '__init__.py')) shutil.rmtree(self.subpkgname, ignore_errors=True) os.mkdir(self.subpkgname) - create_empty_file(os.path.join(self.subpkgname, '__init__.py')) + touch(os.path.join(self.subpkgname, '__init__.py')) # Remember where we are self.here = os.getcwd() sys.path.insert(0, self.here) @@ -230,7 +231,7 @@ def test_module(self): eq = self.assertEqual - create_empty_file(os.path.join(self.subpkgname, self.pkgname + '.py')) + touch(os.path.join(self.subpkgname, self.pkgname + '.py')) from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation eq(repr(areallylongpackageandmodulenametotestreprtruncation), "" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__)) @@ -238,7 +239,7 @@ def test_type(self): eq = self.assertEqual - write_file(os.path.join(self.subpkgname, 'foo.py'), '''\ + touch(os.path.join(self.subpkgname, 'foo.py'), '''\ class foo(object): pass ''') @@ -252,7 +253,7 @@ pass def test_class(self): - write_file(os.path.join(self.subpkgname, 'bar.py'), '''\ + touch(os.path.join(self.subpkgname, 'bar.py'), '''\ class bar: pass ''') @@ -261,7 +262,7 @@ self.assertEqual(repr(bar.bar), "" % bar.__name__) def test_instance(self): - write_file(os.path.join(self.subpkgname, 'baz.py'), '''\ + touch(os.path.join(self.subpkgname, 'baz.py'), '''\ class baz: pass ''') @@ -272,7 +273,7 @@ def test_method(self): eq = self.assertEqual - write_file(os.path.join(self.subpkgname, 'qux.py'), '''\ + touch(os.path.join(self.subpkgname, 'qux.py'), '''\ class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: def amethod(self): pass ''') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_robotparser.py --- a/Lib/test/test_robotparser.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_robotparser.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,8 +1,7 @@ import io import unittest import urllib.robotparser -from urllib.error import URLError, HTTPError -from urllib.request import urlopen +from urllib.error import URLError from test import support class RobotTestCase(unittest.TestCase): @@ -238,27 +237,13 @@ support.requires('network') with support.transient_internet('mueblesmoraleda.com'): url = 'http://mueblesmoraleda.com' - robots_url = url + "/robots.txt" - # First check the URL is usable for our purposes, since the - # test site is a bit flaky. - try: - urlopen(robots_url) - except HTTPError as e: - if e.code not in {401, 403}: - self.skipTest( - "%r should return a 401 or 403 HTTP error, not %r" - % (robots_url, e.code)) - else: - self.skipTest( - "%r should return a 401 or 403 HTTP error, not succeed" - % (robots_url)) parser = urllib.robotparser.RobotFileParser() parser.set_url(url) try: parser.read() except URLError: self.skipTest('%s is unavailable' % url) - self.assertEqual(parser.can_fetch("*", robots_url), False) + self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False) def testPythonOrg(self): support.requires('network') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_runpy.py --- a/Lib/test/test_runpy.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_runpy.py Mon Jul 25 09:47:18 2011 -0400 @@ -7,8 +7,7 @@ import tempfile import py_compile from test.support import ( - forget, make_legacy_pyc, run_unittest, unload, verbose, no_tracing, - create_empty_file) + forget, make_legacy_pyc, run_unittest, unload, verbose, no_tracing) from test.script_helper import ( make_pkg, make_script, make_zip_pkg, make_zip_script, temp_dir) @@ -114,7 +113,8 @@ def _add_pkg_dir(self, pkg_dir): os.mkdir(pkg_dir) pkg_fname = os.path.join(pkg_dir, "__init__.py") - create_empty_file(pkg_fname) + pkg_file = open(pkg_fname, "w") + pkg_file.close() return pkg_fname def _make_pkg(self, source, depth, mod_base="runpy_test"): @@ -219,7 +219,8 @@ module_dir = os.path.join(module_dir, pkg_name) # Add sibling module sibling_fname = os.path.join(module_dir, "sibling.py") - create_empty_file(sibling_fname) + sibling_file = open(sibling_fname, "w") + sibling_file.close() if verbose: print(" Added sibling module:", sibling_fname) # Add nephew module uncle_dir = os.path.join(parent_dir, "uncle") @@ -229,7 +230,8 @@ self._add_pkg_dir(cousin_dir) if verbose: print(" Added cousin package:", cousin_dir) nephew_fname = os.path.join(cousin_dir, "nephew.py") - create_empty_file(nephew_fname) + nephew_file = open(nephew_fname, "w") + nephew_file.close() if verbose: print(" Added nephew module:", nephew_fname) def _check_relative_imports(self, depth, run_name=None): @@ -405,16 +407,6 @@ msg = "recursion depth exceeded" self.assertRaisesRegex(RuntimeError, msg, run_path, zip_name) - def test_encoding(self): - with temp_dir() as script_dir: - filename = os.path.join(script_dir, 'script.py') - with open(filename, 'w', encoding='latin1') as f: - f.write(""" -#coding:latin1 -"non-ASCII: h\xe9" -""") - result = run_path(filename) - self.assertEqual(result['__doc__'], "non-ASCII: h\xe9") def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_shutil.py --- a/Lib/test/test_shutil.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_shutil.py Mon Jul 25 09:47:18 2011 -0400 @@ -107,7 +107,8 @@ self.errorState = 0 os.mkdir(TESTFN) self.childpath = os.path.join(TESTFN, 'a') - support.create_empty_file(self.childpath) + f = open(self.childpath, 'w') + f.close() old_dir_mode = os.stat(TESTFN).st_mode old_child_mode = os.stat(self.childpath).st_mode # Make unwritable. @@ -155,7 +156,7 @@ def test_rmtree_dont_delete_file(self): # When called on a file instead of a directory, don't delete it. handle, path = tempfile.mkstemp() - os.close(handle) + os.fdopen(handle).close() self.assertRaises(OSError, shutil.rmtree, path) os.remove(path) @@ -421,7 +422,7 @@ self.assertEqual(os.stat(file1).st_mode, os.stat(file2).st_mode) @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.chmod') - @unittest.skipUnless(hasattr(os, 'utime'), 'requires os.utime') + @unittest.skipUnless(hasattr(os, 'chmod'), 'requires os.utime') def test_copy2(self): # Ensure that the copied file exists and has the same mode and # modification time bits. @@ -728,16 +729,6 @@ unregister_unpack_format('Boo2') self.assertEqual(get_unpack_formats(), formats) - @unittest.skipUnless(hasattr(shutil, 'disk_usage'), - "disk_usage not available on this platform") - def test_disk_usage(self): - usage = shutil.disk_usage(os.getcwd()) - self.assertGreater(usage.total, 0) - self.assertGreater(usage.used, 0) - self.assertGreaterEqual(usage.free, 0) - self.assertGreaterEqual(usage.total, usage.used) - self.assertGreater(usage.total, usage.free) - class TestMove(unittest.TestCase): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_signal.py --- a/Lib/test/test_signal.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_signal.py Mon Jul 25 09:47:18 2011 -0400 @@ -224,120 +224,92 @@ @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class WakeupSignalTests(unittest.TestCase): - def check_wakeup(self, test_body, *signals): - # use a subprocess to have only one thread - code = """if 1: - import fcntl - import os - import signal - import struct + TIMEOUT_FULL = 10 + TIMEOUT_HALF = 5 - signals = {!r} + def handler(self, signum, frame): + pass - def handler(signum, frame): - pass - - def check_signum(signals): - data = os.read(read, len(signals)+1) - raised = struct.unpack('%uB' % len(data), data) - if raised != signals: - raise Exception("%r != %r" % (raised, signals)) - - {} - - signal.signal(signal.SIGALRM, handler) - read, write = os.pipe() - 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() - check_signum(signals) - - os.close(read) - os.close(write) - """.format(signals, test_body) - - assert_python_ok('-c', code) + def check_signum(self, *signals): + data = os.read(self.read, len(signals)+1) + raised = struct.unpack('%uB' % len(data), data) + # We don't care of the signal delivery order (it's not portable or + # reliable) + raised = set(raised) + signals = set(signals) + self.assertEqual(raised, signals) def test_wakeup_fd_early(self): - self.check_wakeup("""def test(): - import select - import time + import select - TIMEOUT_FULL = 10 - TIMEOUT_HALF = 5 - - signal.alarm(1) - before_time = time.time() - # We attempt to get a signal during the sleep, - # before select is called - time.sleep(TIMEOUT_FULL) - mid_time = time.time() - dt = mid_time - before_time - if dt >= TIMEOUT_HALF: - raise Exception("%s >= %s" % (dt, TIMEOUT_HALF)) - select.select([read], [], [], TIMEOUT_FULL) - after_time = time.time() - dt = after_time - mid_time - if dt >= TIMEOUT_HALF: - raise Exception("%s >= %s" % (dt, TIMEOUT_HALF)) - """, signal.SIGALRM) + signal.alarm(1) + before_time = time.time() + # We attempt to get a signal during the sleep, + # before select is called + time.sleep(self.TIMEOUT_FULL) + mid_time = time.time() + self.assertTrue(mid_time - before_time < self.TIMEOUT_HALF) + select.select([self.read], [], [], self.TIMEOUT_FULL) + after_time = time.time() + self.assertTrue(after_time - mid_time < self.TIMEOUT_HALF) + self.check_signum(signal.SIGALRM) def test_wakeup_fd_during(self): - self.check_wakeup("""def test(): - import select - import time + import select - TIMEOUT_FULL = 10 - TIMEOUT_HALF = 5 - - signal.alarm(1) - before_time = time.time() - # We attempt to get a signal during the select call - try: - select.select([read], [], [], TIMEOUT_FULL) - except select.error: - pass - else: - raise Exception("select.error not raised") - after_time = time.time() - dt = after_time - before_time - if dt >= TIMEOUT_HALF: - raise Exception("%s >= %s" % (dt, TIMEOUT_HALF)) - """, signal.SIGALRM) + signal.alarm(1) + before_time = time.time() + # We attempt to get a signal during the select call + self.assertRaises(select.error, select.select, + [self.read], [], [], self.TIMEOUT_FULL) + after_time = time.time() + self.assertTrue(after_time - before_time < self.TIMEOUT_HALF) + self.check_signum(signal.SIGALRM) def test_signum(self): - self.check_wakeup("""def test(): - signal.signal(signal.SIGUSR1, handler) - os.kill(os.getpid(), signal.SIGUSR1) - os.kill(os.getpid(), signal.SIGALRM) - """, signal.SIGUSR1, signal.SIGALRM) + old_handler = signal.signal(signal.SIGUSR1, self.handler) + self.addCleanup(signal.signal, signal.SIGUSR1, old_handler) + os.kill(os.getpid(), signal.SIGUSR1) + os.kill(os.getpid(), signal.SIGALRM) + self.check_signum(signal.SIGUSR1, signal.SIGALRM) @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'), 'need signal.pthread_sigmask()') + @unittest.skipUnless(hasattr(signal, 'pthread_kill'), + 'need signal.pthread_kill()') def test_pending(self): - signals = (signal.SIGUSR1, signal.SIGUSR2) - # when signals are unblocked, pending signal ared delivered in the - # reverse order of their number - signals = tuple(sorted(signals, reverse=True)) + signum1 = signal.SIGUSR1 + signum2 = signal.SIGUSR2 + tid = threading.current_thread().ident - self.check_wakeup("""def test(): - signum1 = signal.SIGUSR1 - signum2 = signal.SIGUSR2 + old_handler = signal.signal(signum1, self.handler) + self.addCleanup(signal.signal, signum1, old_handler) + old_handler = signal.signal(signum2, self.handler) + self.addCleanup(signal.signal, signum2, old_handler) - signal.signal(signum1, handler) - signal.signal(signum2, handler) + signal.pthread_sigmask(signal.SIG_BLOCK, (signum1, signum2)) + signal.pthread_kill(tid, signum1) + signal.pthread_kill(tid, signum2) + # Unblocking the 2 signals calls the C signal handler twice + signal.pthread_sigmask(signal.SIG_UNBLOCK, (signum1, signum2)) - signal.pthread_sigmask(signal.SIG_BLOCK, (signum1, signum2)) - os.kill(os.getpid(), signum1) - os.kill(os.getpid(), signum2) - # Unblocking the 2 signals calls the C signal handler twice - signal.pthread_sigmask(signal.SIG_UNBLOCK, (signum1, signum2)) - """, *signals) + self.check_signum(signum1, signum2) + def setUp(self): + import fcntl + + self.alrm = signal.signal(signal.SIGALRM, self.handler) + self.read, self.write = os.pipe() + flags = fcntl.fcntl(self.write, fcntl.F_GETFL, 0) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(self.write, fcntl.F_SETFL, flags) + self.old_wakeup = signal.set_wakeup_fd(self.write) + + def tearDown(self): + signal.set_wakeup_fd(self.old_wakeup) + os.close(self.read) + os.close(self.write) + signal.signal(signal.SIGALRM, self.alrm) @unittest.skipIf(sys.platform == "win32", "Not valid on Windows") class SiginterruptTest(unittest.TestCase): @@ -365,9 +337,6 @@ if interrupt is not None: signal.siginterrupt(signal.SIGALRM, interrupt) - print("ready") - sys.stdout.flush() - # run the test twice for loop in range(2): # send a SIGALRM in a second (during the read) @@ -384,15 +353,11 @@ """ % (interrupt,) with spawn_python('-c', code) as process: try: - # wait until the child process is loaded and has started - first_line = process.stdout.readline() - - stdout, stderr = process.communicate(timeout=5.0) + stdout, stderr = process.communicate(timeout=3.0) except subprocess.TimeoutExpired: process.kill() return False else: - stdout = first_line + stdout exitcode = process.wait() if exitcode not in (2, 3): raise Exception("Child error (exit code %s): %s" @@ -522,6 +487,60 @@ Test pthread_sigmask(), pthread_kill(), sigpending() and sigwait() functions. """ + def setUp(self): + self.has_pthread_kill = hasattr(signal, 'pthread_kill') + + def handler(self, signum, frame): + 1/0 + + def read_sigmask(self): + return signal.pthread_sigmask(signal.SIG_BLOCK, []) + + def can_test_blocked_signals(self, skip): + """ + Check if a blocked signal can be raised to the main thread without + calling its signal handler. We need pthread_kill() or exactly one + thread (the main thread). + + Return True if it's possible. Otherwise, return False and print a + warning if skip is False, or raise a SkipTest exception if skip is + True. + """ + if self.has_pthread_kill: + return True + + # The fault handler timeout thread masks all signals. If the main + # thread masks also SIGUSR1, all threads mask this signal. In this + # case, if we send SIGUSR1 to the process, the signal is pending in the + # main or the faulthandler timeout thread. Unblock SIGUSR1 in the main + # thread calls the signal handler only if the signal is pending for the + # main thread. Stop the faulthandler timeout thread to workaround this + # problem. + import faulthandler + faulthandler.cancel_dump_tracebacks_later() + + # Issue #11998: The _tkinter module loads the Tcl library which + # creates a thread waiting events in select(). This thread receives + # signals blocked by all other threads. We cannot test blocked + # signals + if '_tkinter' in sys.modules: + message = ("_tkinter is loaded and pthread_kill() is missing, " + "cannot test blocked signals (issue #11998)") + if skip: + self.skipTest(message) + else: + print("WARNING: %s" % message) + return False + return True + + def kill(self, signum): + if self.has_pthread_kill: + tid = threading.get_ident() + signal.pthread_kill(tid, signum) + else: + pid = os.getpid() + os.kill(pid, signum) + @unittest.skipUnless(hasattr(signal, 'sigpending'), 'need signal.sigpending()') def test_sigpending_empty(self): @@ -532,198 +551,75 @@ @unittest.skipUnless(hasattr(signal, 'sigpending'), 'need signal.sigpending()') def test_sigpending(self): - code = """if 1: - import os - import signal + self.can_test_blocked_signals(True) - def handler(signum, frame): - 1/0 + signum = signal.SIGUSR1 + old_handler = signal.signal(signum, self.handler) + self.addCleanup(signal.signal, signum, old_handler) - signum = signal.SIGUSR1 - signal.signal(signum, handler) - - signal.pthread_sigmask(signal.SIG_BLOCK, [signum]) - os.kill(os.getpid(), signum) - pending = signal.sigpending() - if pending != {signum}: - raise Exception('%s != {%s}' % (pending, signum)) - try: - signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) - except ZeroDivisionError: - pass - else: - raise Exception("ZeroDivisionError not raised") - """ - assert_python_ok('-c', code) + signal.pthread_sigmask(signal.SIG_BLOCK, [signum]) + self.kill(signum) + self.assertEqual(signal.sigpending(), {signum}) + with self.assertRaises(ZeroDivisionError): + signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) @unittest.skipUnless(hasattr(signal, 'pthread_kill'), 'need signal.pthread_kill()') def test_pthread_kill(self): - code = """if 1: - import signal - import threading - import sys + signum = signal.SIGUSR1 + current = threading.get_ident() - signum = signal.SIGUSR1 + old_handler = signal.signal(signum, self.handler) + self.addCleanup(signal.signal, signum, old_handler) - def handler(signum, frame): - 1/0 - - signal.signal(signum, handler) - - if sys.platform == 'freebsd6': - # Issue #12392 and #12469: send a signal to the main thread - # doesn't work before the creation of the first thread on - # FreeBSD 6 - def noop(): - pass - thread = threading.Thread(target=noop) - thread.start() - thread.join() - - tid = threading.get_ident() - try: - signal.pthread_kill(tid, signum) - except ZeroDivisionError: - pass - else: - raise Exception("ZeroDivisionError not raised") - """ - assert_python_ok('-c', code) - - @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'), - 'need signal.pthread_sigmask()') - def wait_helper(self, blocked, test): - """ - test: body of the "def test(signum):" function. - blocked: number of the blocked signal - """ - code = '''if 1: - import signal - import sys - - def handler(signum, frame): - 1/0 - - %s - - blocked = %s - signum = signal.SIGALRM - - # child: block and wait the signal - try: - signal.signal(signum, handler) - signal.pthread_sigmask(signal.SIG_BLOCK, [blocked]) - - # Do the tests - test(signum) - - # The handler must not be called on unblock - try: - signal.pthread_sigmask(signal.SIG_UNBLOCK, [blocked]) - except ZeroDivisionError: - print("the signal handler has been called", - file=sys.stderr) - sys.exit(1) - except BaseException as err: - print("error: {}".format(err), file=sys.stderr) - sys.stderr.flush() - sys.exit(1) - ''' % (test.strip(), blocked) - - # sig*wait* must be called with the signal blocked: since the current - # process might have several threads running, use a subprocess to have - # a single thread. - assert_python_ok('-c', code) + with self.assertRaises(ZeroDivisionError): + signal.pthread_kill(current, signum) @unittest.skipUnless(hasattr(signal, 'sigwait'), 'need signal.sigwait()') + @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'), + 'need signal.pthread_sigmask()') + @unittest.skipUnless(hasattr(os, 'fork'), 'need os.fork()') def test_sigwait(self): - self.wait_helper(signal.SIGALRM, ''' def test(signum): signal.alarm(1) received = signal.sigwait([signum]) if received != signum: - raise Exception('received %s, not %s' % (received, signum)) - ''') + print("sigwait() received %s, not %s" + % (received, signum), + file=sys.stderr) + os._exit(1) - @unittest.skipUnless(hasattr(signal, 'sigwaitinfo'), - 'need signal.sigwaitinfo()') - def test_sigwaitinfo(self): - self.wait_helper(signal.SIGALRM, ''' - def test(signum): - signal.alarm(1) - info = signal.sigwaitinfo([signum]) - if info.si_signo != signum: - raise Exception("info.si_signo != %s" % signum) - ''') + signum = signal.SIGALRM - @unittest.skipUnless(hasattr(signal, 'sigtimedwait'), - 'need signal.sigtimedwait()') - def test_sigtimedwait(self): - self.wait_helper(signal.SIGALRM, ''' - def test(signum): - signal.alarm(1) - info = signal.sigtimedwait([signum], (10, 1000)) - if info.si_signo != signum: - raise Exception('info.si_signo != %s' % signum) - ''') + # sigwait must be called with the signal blocked: since the current + # process might have several threads running, we fork() a child process + # to have a single thread. + pid = os.fork() + if pid == 0: + # child: block and wait the signal + try: + signal.signal(signum, self.handler) + signal.pthread_sigmask(signal.SIG_BLOCK, [signum]) - @unittest.skipUnless(hasattr(signal, 'sigtimedwait'), - 'need signal.sigtimedwait()') - def test_sigtimedwait_poll(self): - # check that polling with sigtimedwait works - self.wait_helper(signal.SIGALRM, ''' - def test(signum): - import os - os.kill(os.getpid(), signum) - info = signal.sigtimedwait([signum], (0, 0)) - if info.si_signo != signum: - raise Exception('info.si_signo != %s' % signum) - ''') + # Do the tests + test(signum) - @unittest.skipUnless(hasattr(signal, 'sigtimedwait'), - 'need signal.sigtimedwait()') - def test_sigtimedwait_timeout(self): - self.wait_helper(signal.SIGALRM, ''' - def test(signum): - received = signal.sigtimedwait([signum], (1, 0)) - if received is not None: - raise Exception("received=%r" % (received,)) - ''') - - @unittest.skipUnless(hasattr(signal, 'sigtimedwait'), - 'need signal.sigtimedwait()') - def test_sigtimedwait_negative_timeout(self): - signum = signal.SIGALRM - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (-1, -1)) - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (0, -1)) - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (-1, 0)) - - @unittest.skipUnless(hasattr(signal, 'sigwaitinfo'), - 'need signal.sigwaitinfo()') - def test_sigwaitinfo_interrupted(self): - self.wait_helper(signal.SIGUSR1, ''' - def test(signum): - import errno - - hndl_called = True - def alarm_handler(signum, frame): - hndl_called = False - - signal.signal(signal.SIGALRM, alarm_handler) - signal.alarm(1) - try: - signal.sigwaitinfo([signal.SIGUSR1]) - except OSError as e: - if e.errno == errno.EINTR: - if not hndl_called: - raise Exception("SIGALRM handler not called") - else: - raise Exception("Expected EINTR to be raised by sigwaitinfo") + # The handler must not be called on unblock + try: + signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) + except ZeroDivisionError: + print("the signal handler has been called", + file=sys.stderr) + os._exit(1) + except BaseException as err: + print("error: {}".format(err), file=sys.stderr) + os._exit(1) else: - raise Exception("Expected EINTR to be raised by sigwaitinfo") - ''') + os._exit(0) + else: + # parent: check that the child correcty received the signal + self.assertEqual(os.waitpid(pid, 0), (pid, 0)) @unittest.skipUnless(hasattr(signal, 'sigwait'), 'need signal.sigwait()') @@ -771,98 +667,46 @@ @unittest.skipUnless(hasattr(signal, 'pthread_sigmask'), 'need signal.pthread_sigmask()') def test_pthread_sigmask(self): - code = """if 1: - import signal - import os; import threading - - def handler(signum, frame): - 1/0 - - def kill(signum): - os.kill(os.getpid(), signum) - - def read_sigmask(): - return signal.pthread_sigmask(signal.SIG_BLOCK, []) - + test_blocked_signals = self.can_test_blocked_signals(False) signum = signal.SIGUSR1 # Install our signal handler - old_handler = signal.signal(signum, handler) + old_handler = signal.signal(signum, self.handler) + self.addCleanup(signal.signal, signum, old_handler) # Unblock SIGUSR1 (and copy the old mask) to test our signal handler old_mask = signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) - try: - kill(signum) - except ZeroDivisionError: - pass - else: - raise Exception("ZeroDivisionError not raised") + self.addCleanup(signal.pthread_sigmask, signal.SIG_SETMASK, old_mask) + with self.assertRaises(ZeroDivisionError): + self.kill(signum) # Block and then raise SIGUSR1. The signal is blocked: the signal # handler is not called, and the signal is now pending signal.pthread_sigmask(signal.SIG_BLOCK, [signum]) - kill(signum) + if test_blocked_signals: + self.kill(signum) # Check the new mask - blocked = read_sigmask() - if signum not in blocked: - raise Exception("%s not in %s" % (signum, blocked)) - if old_mask ^ blocked != {signum}: - raise Exception("%s ^ %s != {%s}" % (old_mask, blocked, signum)) + blocked = self.read_sigmask() + self.assertIn(signum, blocked) + self.assertEqual(old_mask ^ blocked, {signum}) # Unblock SIGUSR1 - try: - # unblock the pending signal calls immediatly the signal handler + if test_blocked_signals: + with self.assertRaises(ZeroDivisionError): + # unblock the pending signal calls immediatly the signal handler + signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) + else: signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) - except ZeroDivisionError: - pass - else: - raise Exception("ZeroDivisionError not raised") - try: - kill(signum) - except ZeroDivisionError: - pass - else: - raise Exception("ZeroDivisionError not raised") + with self.assertRaises(ZeroDivisionError): + self.kill(signum) # Check the new mask - unblocked = read_sigmask() - if signum in unblocked: - raise Exception("%s in %s" % (signum, unblocked)) - if blocked ^ unblocked != {signum}: - raise Exception("%s ^ %s != {%s}" % (blocked, unblocked, signum)) - if old_mask != unblocked: - raise Exception("%s != %s" % (old_mask, unblocked)) - """ - assert_python_ok('-c', code) - - @unittest.skipIf(sys.platform == 'freebsd6', - "issue #12392: send a signal to the main thread doesn't work " - "before the creation of the first thread on FreeBSD 6") - @unittest.skipUnless(hasattr(signal, 'pthread_kill'), - 'need signal.pthread_kill()') - def test_pthread_kill_main_thread(self): - # Test that a signal can be sent to the main thread with pthread_kill() - # before any other thread has been created (see issue #12392). - code = """if True: - import threading - import signal - import sys - - def handler(signum, frame): - sys.exit(3) - - signal.signal(signal.SIGUSR1, handler) - signal.pthread_kill(threading.get_ident(), signal.SIGUSR1) - sys.exit(2) - """ - - with spawn_python('-c', code) as process: - stdout, stderr = process.communicate() - exitcode = process.wait() - if exitcode != 3: - raise Exception("Child error (exit code %s): %s" % - (exitcode, stdout)) + unblocked = self.read_sigmask() + self.assertNotIn(signum, unblocked) + self.assertEqual(blocked ^ unblocked, {signum}) + self.assertSequenceEqual(old_mask, unblocked) + # Finally, restore the previous signal handler and the signal mask def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_smtplib.py Mon Jul 25 09:47:18 2011 -0400 @@ -293,23 +293,6 @@ mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END) self.assertEqual(self.output.getvalue(), mexpect) - def testSendNullSender(self): - m = 'A test message' - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - smtp.sendmail('<>', 'Sally', m) - # XXX (see comment in testSend) - time.sleep(0.01) - smtp.quit() - - self.client_evt.set() - self.serv_evt.wait() - self.output.flush() - mexpect = '%s%s\n%s' % (MSG_BEGIN, m, MSG_END) - self.assertEqual(self.output.getvalue(), mexpect) - debugout = smtpd.DEBUGSTREAM.getvalue() - sender = re.compile("^sender: <>$", re.MULTILINE) - self.assertRegex(debugout, sender) - def testSendMessage(self): m = email.mime.text.MIMEText('A test message') smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) @@ -337,16 +320,13 @@ # XXX (see comment in testSend) time.sleep(0.01) smtp.quit() - # make sure the Bcc header is still in the message. - self.assertEqual(m['Bcc'], 'John Root , "Dinsdale" ' - '') self.client_evt.set() self.serv_evt.wait() self.output.flush() # Add the X-Peer header that DebuggingServer adds m['X-Peer'] = socket.gethostbyname('localhost') - # The Bcc header should not be transmitted. + # The Bcc header is deleted before serialization. del m['Bcc'] mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) self.assertEqual(self.output.getvalue(), mexpect) @@ -385,112 +365,6 @@ re.MULTILINE) self.assertRegex(debugout, to_addr) - def testSendMessageWithSpecifiedAddresses(self): - # Make sure addresses specified in call override those in message. - m = email.mime.text.MIMEText('A test message') - m['From'] = 'foo@bar.com' - m['To'] = 'John, Dinsdale' - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - smtp.send_message(m, from_addr='joe@example.com', to_addrs='foo@example.net') - # XXX (see comment in testSend) - time.sleep(0.01) - smtp.quit() - - self.client_evt.set() - self.serv_evt.wait() - self.output.flush() - # Add the X-Peer header that DebuggingServer adds - m['X-Peer'] = socket.gethostbyname('localhost') - mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) - self.assertEqual(self.output.getvalue(), mexpect) - debugout = smtpd.DEBUGSTREAM.getvalue() - sender = re.compile("^sender: joe@example.com$", re.MULTILINE) - self.assertRegex(debugout, sender) - for addr in ('John', 'Dinsdale'): - to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr), - re.MULTILINE) - self.assertNotRegex(debugout, to_addr) - recip = re.compile(r"^recips: .*'foo@example.net'.*$", re.MULTILINE) - self.assertRegex(debugout, recip) - - def testSendMessageWithMultipleFrom(self): - # Sender overrides To - m = email.mime.text.MIMEText('A test message') - m['From'] = 'Bernard, Bianca' - m['Sender'] = 'the_rescuers@Rescue-Aid-Society.com' - m['To'] = 'John, Dinsdale' - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - smtp.send_message(m) - # XXX (see comment in testSend) - time.sleep(0.01) - smtp.quit() - - self.client_evt.set() - self.serv_evt.wait() - self.output.flush() - # Add the X-Peer header that DebuggingServer adds - m['X-Peer'] = socket.gethostbyname('localhost') - mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) - self.assertEqual(self.output.getvalue(), mexpect) - debugout = smtpd.DEBUGSTREAM.getvalue() - sender = re.compile("^sender: the_rescuers@Rescue-Aid-Society.com$", re.MULTILINE) - self.assertRegex(debugout, sender) - for addr in ('John', 'Dinsdale'): - to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr), - re.MULTILINE) - self.assertRegex(debugout, to_addr) - - def testSendMessageResent(self): - m = email.mime.text.MIMEText('A test message') - m['From'] = 'foo@bar.com' - m['To'] = 'John' - m['CC'] = 'Sally, Fred' - m['Bcc'] = 'John Root , "Dinsdale" ' - m['Resent-Date'] = 'Thu, 1 Jan 1970 17:42:00 +0000' - m['Resent-From'] = 'holy@grail.net' - m['Resent-To'] = 'Martha , Jeff' - m['Resent-Bcc'] = 'doe@losthope.net' - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - smtp.send_message(m) - # XXX (see comment in testSend) - time.sleep(0.01) - smtp.quit() - - self.client_evt.set() - self.serv_evt.wait() - self.output.flush() - # The Resent-Bcc headers are deleted before serialization. - del m['Bcc'] - del m['Resent-Bcc'] - # Add the X-Peer header that DebuggingServer adds - m['X-Peer'] = socket.gethostbyname('localhost') - mexpect = '%s%s\n%s' % (MSG_BEGIN, m.as_string(), MSG_END) - self.assertEqual(self.output.getvalue(), mexpect) - debugout = smtpd.DEBUGSTREAM.getvalue() - sender = re.compile("^sender: holy@grail.net$", re.MULTILINE) - self.assertRegex(debugout, sender) - for addr in ('my_mom@great.cooker.com', 'Jeff', 'doe@losthope.net'): - to_addr = re.compile(r"^recips: .*'{}'.*$".format(addr), - re.MULTILINE) - self.assertRegex(debugout, to_addr) - - def testSendMessageMultipleResentRaises(self): - m = email.mime.text.MIMEText('A test message') - m['From'] = 'foo@bar.com' - m['To'] = 'John' - m['CC'] = 'Sally, Fred' - m['Bcc'] = 'John Root , "Dinsdale" ' - m['Resent-Date'] = 'Thu, 1 Jan 1970 17:42:00 +0000' - m['Resent-From'] = 'holy@grail.net' - m['Resent-To'] = 'Martha , Jeff' - m['Resent-Bcc'] = 'doe@losthope.net' - m['Resent-Date'] = 'Thu, 2 Jan 1970 17:42:00 +0000' - m['Resent-To'] = 'holy@grail.net' - m['Resent-From'] = 'Martha , Jeff' - smtp = smtplib.SMTP(HOST, self.port, local_hostname='localhost', timeout=3) - with self.assertRaises(ValueError): - smtp.send_message(m) - smtp.close() class NonConnectingTests(unittest.TestCase): @@ -540,7 +414,7 @@ sim_users = {'Mr.A@somewhere.com':'John A', - 'Ms.B@xn--fo-fka.com':'Sally B', + 'Ms.B@somewhere.com':'Sally B', 'Mrs.C@somewhereesle.com':'Ruth C', } @@ -556,7 +430,7 @@ sim_auth_login_password = 'C29TZXBHC3N3B3JK' sim_lists = {'list-1':['Mr.A@somewhere.com','Mrs.C@somewhereesle.com'], - 'list-2':['Ms.B@xn--fo-fka.com',], + 'list-2':['Ms.B@somewhere.com',], } # Simulated SMTP channel & server @@ -580,14 +454,15 @@ self.push(resp) def smtp_VRFY(self, arg): - # For max compatibility smtplib should be sending the raw address. - if arg in sim_users: - self.push('250 %s %s' % (sim_users[arg], smtplib.quoteaddr(arg))) + raw_addr = email.utils.parseaddr(arg)[1] + quoted_addr = smtplib.quoteaddr(arg) + if raw_addr in sim_users: + self.push('250 %s %s' % (sim_users[raw_addr], quoted_addr)) else: self.push('550 No such user: %s' % arg) def smtp_EXPN(self, arg): - list_name = arg.lower() + list_name = email.utils.parseaddr(arg)[1].lower() if list_name in sim_lists: user_list = sim_lists[list_name] for n, user_email in enumerate(user_list): @@ -719,7 +594,8 @@ self.assertEqual(smtp.vrfy(email), expected_known) u = 'nobody@nowhere.com' - expected_unknown = (550, ('No such user: %s' % u).encode('ascii')) + expected_unknown = (550, ('No such user: %s' + % smtplib.quoteaddr(u)).encode('ascii')) self.assertEqual(smtp.vrfy(u), expected_unknown) smtp.quit() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_socketserver.py --- a/Lib/test/test_socketserver.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_socketserver.py Mon Jul 25 09:47:18 2011 -0400 @@ -66,7 +66,7 @@ """Test all socket servers.""" def setUp(self): - signal_alarm(60) # Kill deadlocks after 60 seconds. + signal_alarm(20) # Kill deadlocks after 20 seconds. self.port_seed = 0 self.test_files = [] @@ -283,3 +283,4 @@ if __name__ == "__main__": test_main() + signal_alarm(3) # Shutdown shouldn't take more than 3 seconds. diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_ssl.py Mon Jul 25 09:47:18 2011 -0400 @@ -60,7 +60,7 @@ def can_clear_options(): # 0.9.8m or higher - return ssl._OPENSSL_API_VERSION >= (0, 9, 8, 13, 15) + return ssl.OPENSSL_VERSION_INFO >= (0, 9, 8, 13, 15) def no_sslv2_implies_sslv3_hello(): # 0.9.7h or higher @@ -321,25 +321,6 @@ self.assertRaises(ValueError, ctx.wrap_socket, sock, True, server_hostname="some.hostname") - def test_unknown_channel_binding(self): - # should raise ValueError for unknown type - s = socket.socket(socket.AF_INET) - ss = ssl.wrap_socket(s) - with self.assertRaises(ValueError): - ss.get_channel_binding("unknown-type") - - @unittest.skipUnless("tls-unique" in ssl.CHANNEL_BINDING_TYPES, - "'tls-unique' channel binding not available") - def test_tls_unique_channel_binding(self): - # unconnected should return None for known type - s = socket.socket(socket.AF_INET) - ss = ssl.wrap_socket(s) - self.assertIsNone(ss.get_channel_binding("tls-unique")) - # the same for server-side - s = socket.socket(socket.AF_INET) - ss = ssl.wrap_socket(s, server_side=True, certfile=CERTFILE) - self.assertIsNone(ss.get_channel_binding("tls-unique")) - class ContextTests(unittest.TestCase): @skip_if_broken_ubuntu_ssl @@ -845,11 +826,6 @@ self.sslconn = None if support.verbose and self.server.connectionchatty: sys.stdout.write(" server: connection is now unencrypted...\n") - elif stripped == b'CB tls-unique': - if support.verbose and self.server.connectionchatty: - sys.stdout.write(" server: read CB tls-unique from client, sending our CB data...\n") - data = self.sslconn.get_channel_binding("tls-unique") - self.write(repr(data).encode("us-ascii") + b"\n") else: if (support.verbose and self.server.connectionchatty): @@ -1649,73 +1625,6 @@ t.join() server.close() - @unittest.skipUnless("tls-unique" in ssl.CHANNEL_BINDING_TYPES, - "'tls-unique' channel binding not available") - def test_tls_unique_channel_binding(self): - """Test tls-unique channel binding.""" - if support.verbose: - sys.stdout.write("\n") - - server = ThreadedEchoServer(CERTFILE, - certreqs=ssl.CERT_NONE, - ssl_version=ssl.PROTOCOL_TLSv1, - cacerts=CERTFILE, - chatty=True, - connectionchatty=False) - flag = threading.Event() - server.start(flag) - # wait for it to start - flag.wait() - # try to connect - s = ssl.wrap_socket(socket.socket(), - server_side=False, - certfile=CERTFILE, - ca_certs=CERTFILE, - cert_reqs=ssl.CERT_NONE, - ssl_version=ssl.PROTOCOL_TLSv1) - s.connect((HOST, server.port)) - try: - # get the data - cb_data = s.get_channel_binding("tls-unique") - if support.verbose: - sys.stdout.write(" got channel binding data: {0!r}\n" - .format(cb_data)) - - # check if it is sane - self.assertIsNotNone(cb_data) - self.assertEqual(len(cb_data), 12) # True for TLSv1 - - # and compare with the peers version - s.write(b"CB tls-unique\n") - peer_data_repr = s.read().strip() - self.assertEqual(peer_data_repr, - repr(cb_data).encode("us-ascii")) - s.close() - - # now, again - s = ssl.wrap_socket(socket.socket(), - server_side=False, - certfile=CERTFILE, - ca_certs=CERTFILE, - cert_reqs=ssl.CERT_NONE, - ssl_version=ssl.PROTOCOL_TLSv1) - s.connect((HOST, server.port)) - new_cb_data = s.get_channel_binding("tls-unique") - if support.verbose: - sys.stdout.write(" got another channel binding data: {0!r}\n" - .format(new_cb_data)) - # is it really unique - self.assertNotEqual(cb_data, new_cb_data) - self.assertIsNotNone(cb_data) - self.assertEqual(len(cb_data), 12) # True for TLSv1 - s.write(b"CB tls-unique\n") - peer_data_repr = s.read().strip() - self.assertEqual(peer_data_repr, - repr(new_cb_data).encode("us-ascii")) - s.close() - finally: - server.stop() - server.join() def test_main(verbose=False): if support.verbose: diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_subprocess.py Mon Jul 25 09:47:18 2011 -0400 @@ -390,11 +390,7 @@ stdout, stderr = p.communicate() self.assertEqual(stdout, b"orange") - # Windows requires at least the SYSTEMROOT environment variable to start - # Python - @unittest.skipIf(sys.platform == 'win32', - 'cannot test an empty env on Windows') - @unittest.skipIf(sysconfig.get_config_var('Py_ENABLE_SHARED') is not None, + @unittest.skipIf(sysconfig.get_config_var('Py_ENABLE_SHARED') == 1, 'the python library cannot be loaded ' 'with an empty environment') def test_empty_env(self): @@ -404,11 +400,7 @@ stdout=subprocess.PIPE, env={}) as p: stdout, stderr = p.communicate() - self.assertIn(stdout.strip(), - (b"[]", - # Mac OS X adds __CF_USER_TEXT_ENCODING variable to an empty - # environment - b"['__CF_USER_TEXT_ENCODING']")) + self.assertEqual(stdout.strip(), b"[]") def test_communicate_stdin(self): p = subprocess.Popen([sys.executable, "-c", @@ -557,75 +549,44 @@ def test_universal_newlines(self): p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + - 'sys.stdout.write(sys.stdin.readline());' + 'sys.stdout.write("line1\\n");' 'sys.stdout.flush();' 'sys.stdout.write("line2\\n");' 'sys.stdout.flush();' - 'sys.stdout.write(sys.stdin.read());' + 'sys.stdout.write("line3\\r\\n");' 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' + 'sys.stdout.write("line4\\r");' 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' + 'sys.stdout.write("\\nline5");' 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], - stdin=subprocess.PIPE, + 'sys.stdout.write("\\nline6");'], stdout=subprocess.PIPE, universal_newlines=1) - p.stdin.write("line1\n") - self.assertEqual(p.stdout.readline(), "line1\n") - p.stdin.write("line3\n") - p.stdin.close() self.addCleanup(p.stdout.close) - self.assertEqual(p.stdout.readline(), - "line2\n") - self.assertEqual(p.stdout.read(6), - "line3\n") - self.assertEqual(p.stdout.read(), - "line4\nline5\nline6\nline7\nline8") + stdout = p.stdout.read() + self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6") def test_universal_newlines_communicate(self): # universal newlines through communicate() p = subprocess.Popen([sys.executable, "-c", 'import sys,os;' + SETBINARY + + 'sys.stdout.write("line1\\n");' + 'sys.stdout.flush();' 'sys.stdout.write("line2\\n");' 'sys.stdout.flush();' - 'sys.stdout.write("line4\\n");' + 'sys.stdout.write("line3\\r\\n");' 'sys.stdout.flush();' - 'sys.stdout.write("line5\\r\\n");' + 'sys.stdout.write("line4\\r");' 'sys.stdout.flush();' - 'sys.stdout.write("line6\\r");' + 'sys.stdout.write("\\nline5");' 'sys.stdout.flush();' - 'sys.stdout.write("\\nline7");' - 'sys.stdout.flush();' - 'sys.stdout.write("\\nline8");'], - stderr=subprocess.PIPE, - stdout=subprocess.PIPE, + 'sys.stdout.write("\\nline6");'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=1) self.addCleanup(p.stdout.close) self.addCleanup(p.stderr.close) - # BUG: can't give a non-empty stdin because it breaks both the - # select- and poll-based communicate() implementations. (stdout, stderr) = p.communicate() - self.assertEqual(stdout, - "line2\nline4\nline5\nline6\nline7\nline8") - - def test_universal_newlines_communicate_stdin(self): - # universal newlines through communicate(), with only stdin - p = subprocess.Popen([sys.executable, "-c", - 'import sys,os;' + SETBINARY + '''\nif True: - s = sys.stdin.readline() - assert s == "line1\\n", repr(s) - s = sys.stdin.read() - assert s == "line3\\n", repr(s) - '''], - stdin=subprocess.PIPE, - universal_newlines=1) - (stdout, stderr) = p.communicate("line1\nline3\n") - self.assertEqual(p.returncode, 0) + self.assertEqual(stdout, "line1\nline2\nline3\nline4\nline5\nline6") def test_no_leaking(self): # Make sure we leak no resources @@ -798,24 +759,6 @@ time.sleep(2) p.communicate(b"x" * 2**20) - @unittest.skipUnless(hasattr(signal, 'SIGALRM'), - "Requires signal.SIGALRM") - def test_communicate_eintr(self): - # Issue #12493: communicate() should handle EINTR - def handler(signum, frame): - pass - old_handler = signal.signal(signal.SIGALRM, handler) - self.addCleanup(signal.signal, signal.SIGALRM, old_handler) - - # the process is running for 2 seconds - args = [sys.executable, "-c", 'import time; time.sleep(2)'] - for stream in ('stdout', 'stderr'): - kw = {stream: subprocess.PIPE} - with subprocess.Popen(args, **kw) as process: - signal.alarm(1) - # communicate() will be interrupted by SIGALRM - process.communicate() - # context manager class _SuppressCoreFiles(object): @@ -1689,8 +1632,7 @@ ProcessTestCaseNoPoll, HelperFunctionTests, CommandsWithSpaces, - ContextManagerTests, - ) + ContextManagerTests) support.run_unittest(*unit_tests) support.reap_children() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_support.py --- a/Lib/test/test_support.py Tue Jul 26 09:37:46 2011 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,178 +0,0 @@ -#!/usr/bin/env python - -import sys -import os -import unittest -import socket -import tempfile -import errno -from test import support - -TESTFN = support.TESTFN -TESTDIRN = os.path.basename(tempfile.mkdtemp(dir='.')) - - -class TestSupport(unittest.TestCase): - def setUp(self): - support.unlink(TESTFN) - support.rmtree(TESTDIRN) - tearDown = setUp - - def test_import_module(self): - support.import_module("ftplib") - self.assertRaises(unittest.SkipTest, support.import_module, "foo") - - def test_import_fresh_module(self): - support.import_fresh_module("ftplib") - - def test_get_attribute(self): - self.assertEqual(support.get_attribute(self, "test_get_attribute"), - self.test_get_attribute) - self.assertRaises(unittest.SkipTest, support.get_attribute, self, "foo") - - @unittest.skip("failing buildbots") - def test_get_original_stdout(self): - self.assertEqual(support.get_original_stdout(), sys.stdout) - - def test_unload(self): - import sched - self.assertIn("sched", sys.modules) - support.unload("sched") - self.assertNotIn("sched", sys.modules) - - def test_unlink(self): - with open(TESTFN, "w") as f: - pass - support.unlink(TESTFN) - self.assertFalse(os.path.exists(TESTFN)) - support.unlink(TESTFN) - - def test_rmtree(self): - os.mkdir(TESTDIRN) - os.mkdir(os.path.join(TESTDIRN, TESTDIRN)) - support.rmtree(TESTDIRN) - self.assertFalse(os.path.exists(TESTDIRN)) - support.rmtree(TESTDIRN) - - def test_forget(self): - import smtplib - support.forget("smtplib") - self.assertNotIn("smtplib", sys.modules) - - def test_HOST(self): - s = socket.socket() - s.bind((support.HOST, 0)) - s.close() - - def test_find_unused_port(self): - port = support.find_unused_port() - s = socket.socket() - s.bind((support.HOST, port)) - s.close() - - def test_bind_port(self): - s = socket.socket() - support.bind_port(s) - s.listen(1) - s.close() - - def test_temp_cwd(self): - here = os.getcwd() - with support.temp_cwd(name=TESTFN): - self.assertEqual(os.path.basename(os.getcwd()), TESTFN) - self.assertFalse(os.path.exists(TESTFN)) - self.assertTrue(os.path.basename(os.getcwd()), here) - - def test_sortdict(self): - self.assertEqual(support.sortdict({3:3, 2:2, 1:1}), "{1: 1, 2: 2, 3: 3}") - - def test_make_bad_fd(self): - fd = support.make_bad_fd() - with self.assertRaises(OSError) as cm: - os.write(fd, b"foo") - self.assertEqual(cm.exception.errno, errno.EBADF) - - def test_check_syntax_error(self): - support.check_syntax_error(self, "def class") - self.assertRaises(AssertionError, support.check_syntax_error, self, "1") - - def test_CleanImport(self): - import importlib - with support.CleanImport("asyncore"): - importlib.import_module("asyncore") - - def test_DirsOnSysPath(self): - with support.DirsOnSysPath('foo', 'bar'): - self.assertIn("foo", sys.path) - self.assertIn("bar", sys.path) - self.assertNotIn("foo", sys.path) - self.assertNotIn("bar", sys.path) - - def test_captured_stdout(self): - with support.captured_stdout() as s: - print("hello") - self.assertEqual(s.getvalue(), "hello\n") - - def test_captured_stderr(self): - with support.captured_stderr() as s: - print("hello", file=sys.stderr) - self.assertEqual(s.getvalue(), "hello\n") - - def test_captured_stdin(self): - with support.captured_stdin() as s: - print("hello", file=sys.stdin) - self.assertEqual(s.getvalue(), "hello\n") - - def test_gc_collect(self): - support.gc_collect() - - def test_python_is_optimized(self): - self.assertIsInstance(support.python_is_optimized(), bool) - - def test_swap_attr(self): - class Obj: - x = 1 - obj = Obj() - with support.swap_attr(obj, "x", 5): - self.assertEqual(obj.x, 5) - self.assertEqual(obj.x, 1) - - def test_swap_item(self): - D = {"item":1} - with support.swap_item(D, "item", 5): - self.assertEqual(D["item"], 5) - self.assertEqual(D["item"], 1) - - # XXX -follows a list of untested API - # make_legacy_pyc - # is_resource_enabled - # requires - # fcmp - # umaks - # findfile - # check_warnings - # EnvironmentVarGuard - # TransientResource - # transient_internet - # run_with_locale - # set_memlimit - # bigmemtest - # precisionbigmemtest - # bigaddrspacetest - # requires_resource - # run_doctest - # threading_cleanup - # reap_threads - # reap_children - # strip_python_stderr - # args_from_interpreter_flags - # can_symlink - # skip_unless_symlink - - -def test_main(): - tests = [TestSupport] - support.run_unittest(*tests) - -if __name__ == '__main__': - test_main() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_sys.py --- a/Lib/test/test_sys.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_sys.py Mon Jul 25 09:47:18 2011 -0400 @@ -665,7 +665,7 @@ return inner check(get_cell().__closure__[0], size(h + 'P')) # code - check(get_cell().__code__, size(h + '5i9Pi3P')) + check(get_cell().__code__, size(h + '5i8Pi3P')) # complex check(complex(0,1), size(h + '2d')) # method_descriptor (descriptor object) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_tarfile.py --- a/Lib/test/test_tarfile.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_tarfile.py Mon Jul 25 09:47:18 2011 -0400 @@ -893,7 +893,7 @@ try: for name in ("foo", "bar", "baz"): name = os.path.join(tempdir, name) - support.create_empty_file(name) + open(name, "wb").close() exclude = os.path.isfile @@ -920,7 +920,7 @@ try: for name in ("foo", "bar", "baz"): name = os.path.join(tempdir, name) - support.create_empty_file(name) + open(name, "wb").close() def filter(tarinfo): if os.path.basename(tarinfo.name) == "bar": @@ -959,7 +959,7 @@ # and compare the stored name with the original. foo = os.path.join(TEMPDIR, "foo") if not dir: - support.create_empty_file(foo) + open(foo, "w").close() else: os.mkdir(foo) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_threaded_import.py Mon Jul 25 09:47:18 2011 -0400 @@ -11,8 +11,8 @@ import time import shutil import unittest -from test.support import ( - verbose, import_module, run_unittest, TESTFN, reap_threads) +from test.support import verbose, import_module, run_unittest, TESTFN +thread = import_module('_thread') threading = import_module('threading') def task(N, done, done_tasks, errors): @@ -62,7 +62,7 @@ def __init__(self): self.numcalls = 0 self.x = 0 - self.lock = threading.Lock() + self.lock = thread.allocate_lock() def find_module(self, name, path=None): # Simulate some thread-unsafe behaviour. If calls to find_module() @@ -113,9 +113,7 @@ done_tasks = [] done.clear() for i in range(N): - t = threading.Thread(target=task, - args=(N, done, done_tasks, errors,)) - t.start() + thread.start_new_thread(task, (N, done, done_tasks, errors,)) done.wait(60) self.assertFalse(errors) if verbose: @@ -205,7 +203,6 @@ self.assertEqual(set(results), {'a', 'b'}) -@reap_threads def test_main(): run_unittest(ThreadedImportTests) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_threading.py --- a/Lib/test/test_threading.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_threading.py Mon Jul 25 09:47:18 2011 -0400 @@ -418,13 +418,6 @@ class ThreadJoinOnShutdown(BaseTestCase): - # Between fork() and exec(), only async-safe functions are allowed (issues - # #12316 and #11870), and fork() from a worker thread is known to trigger - # problems with some operating systems (issue #3863): skip problematic tests - # on platforms known to behave badly. - platforms_to_skip = ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5', - 'os2emx') - def _run_and_join(self, script): script = """if 1: import sys, os, time, threading @@ -455,7 +448,6 @@ self._run_and_join(script) @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") - @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") def test_2_join_in_forked_process(self): # Like the test above, but from a forked interpreter script = """if 1: @@ -472,11 +464,15 @@ self._run_and_join(script) @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") - @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") def test_3_join_in_forked_from_thread(self): # Like the test above, but fork() was called from a worker thread # In the forked process, the main Thread object must be marked as stopped. + # Skip platforms with known problems forking from a worker thread. + # See http://bugs.python.org/issue3863. + if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'netbsd5', + 'os2emx'): + raise unittest.SkipTest('due to known OS bugs on ' + sys.platform) script = """if 1: main_thread = threading.current_thread() def worker(): @@ -502,11 +498,15 @@ self.assertEqual(data, expected_output) @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") - @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") def test_4_joining_across_fork_in_worker_thread(self): # There used to be a possible deadlock when forking from a child # thread. See http://bugs.python.org/issue6643. + # Skip platforms with known problems forking from a worker thread. + # See http://bugs.python.org/issue3863. + if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'): + raise unittest.SkipTest('due to known OS bugs on ' + sys.platform) + # The script takes the following steps: # - The main thread in the parent process starts a new thread and then # tries to join it. @@ -575,7 +575,6 @@ self.assertScriptHasOutput(script, "end of main\n") @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()") - @unittest.skipIf(sys.platform in platforms_to_skip, "due to known OS bug") def test_5_clear_waiter_locks_to_avoid_crash(self): # Check that a spawned thread that forks doesn't segfault on certain # platforms, namely OS X. This used to happen if there was a waiter @@ -588,6 +587,10 @@ # lock will be acquired, we can't know if the internal mutex will be # acquired at the time of the fork. + # Skip platforms with known problems forking from a worker thread. + # See http://bugs.python.org/issue3863. + if sys.platform in ('freebsd4', 'freebsd5', 'freebsd6', 'os2emx'): + raise unittest.SkipTest('due to known OS bugs on ' + sys.platform) script = """if True: import os, time, threading @@ -647,10 +650,11 @@ def random_io(): '''Loop for a while sleeping random tiny amounts and doing some I/O.''' + blank = b'x' * 200 while True: - in_f = open(os.__file__, 'rb') + in_f = open(os.__file__, 'r') stuff = in_f.read(200) - null_f = open(os.devnull, 'wb') + null_f = open(os.devnull, 'w') null_f.write(stuff) time.sleep(random.random() / 1995) null_f.close() diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_time.py --- a/Lib/test/test_time.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_time.py Mon Jul 25 09:47:18 2011 -0400 @@ -27,8 +27,6 @@ int(self.t)) def test_sleep(self): - self.assertRaises(ValueError, time.sleep, -2) - self.assertRaises(ValueError, time.sleep, -1) time.sleep(1.2) def test_strftime(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_tk.py --- a/Lib/test/test_tk.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_tk.py Mon Jul 25 09:47:18 2011 -0400 @@ -2,11 +2,15 @@ # Skip test if _tkinter wasn't built. support.import_module('_tkinter') -# Skip test if tk cannot be initialized. -from tkinter.test.support import check_tk_availability -check_tk_availability() +import tkinter +from tkinter.test import runtktests +import unittest -from tkinter.test import runtktests +try: + tkinter.Button() +except tkinter.TclError as msg: + # assuming tk is not available + raise unittest.SkipTest("tk not available: %s" % msg) def test_main(enable_gui=False): if enable_gui: diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_tokenize.py --- a/Lib/test/test_tokenize.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_tokenize.py Mon Jul 25 09:47:18 2011 -0400 @@ -649,7 +649,7 @@ return roundtrip(open(path, 'rb')) def test_utf8_coding_cookie_and_no_utf8_bom(self): - f = 'tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt' + f = 'tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt' self.assertTrue(self._testFile(f)) def test_latin1_coding_cookie_and_utf8_bom(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_ttk_guionly.py --- a/Lib/test/test_ttk_guionly.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_ttk_guionly.py Mon Jul 25 09:47:18 2011 -0400 @@ -5,10 +5,6 @@ # Skip this test if _tkinter wasn't built. support.import_module('_tkinter') -# Skip test if tk cannot be initialized. -from tkinter.test.support import check_tk_availability -check_tk_availability() - from _tkinter import TclError from tkinter import ttk from tkinter.test import runtktests diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_unicode.py --- a/Lib/test/test_unicode.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_unicode.py Mon Jul 25 09:47:18 2011 -0400 @@ -736,11 +736,6 @@ self.assertRaises(TypeError, '{a'.format_map) self.assertRaises(TypeError, '}a'.format_map) - # issue #12579: can't supply positional params to format_map - self.assertRaises(ValueError, '{}'.format_map, {'a' : 2}) - self.assertRaises(ValueError, '{}'.format_map, 'a') - self.assertRaises(ValueError, '{a} {}'.format_map, {"a" : 2, "b" : 1}) - def test_format_auto_numbering(self): class C: def __init__(self, x=100): @@ -793,7 +788,6 @@ self.assertEqual('%c' % '\U00021483', '\U00021483') self.assertRaises(TypeError, "%c".__mod__, "aa") self.assertRaises(ValueError, "%.1\u1032f".__mod__, (1.0/3)) - self.assertRaises(TypeError, "%i".__mod__, "aa") # formatting jobs delegated from the string implementation: self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_unicode_file.py --- a/Lib/test/test_unicode_file.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_unicode_file.py Mon Jul 25 09:47:18 2011 -0400 @@ -6,7 +6,7 @@ import unittest from test.support import (run_unittest, rmtree, - TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE, create_empty_file) + TESTFN_ENCODING, TESTFN_UNICODE, TESTFN_UNENCODABLE) if not os.path.supports_unicode_filenames: try: @@ -99,7 +99,8 @@ # top-level 'test' functions would be if they could take params def _test_single(self, filename): remove_if_exists(filename) - create_empty_file(filename) + f = open(filename, "w") + f.close() try: self._do_single(filename) finally: diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_urllib.py --- a/Lib/test/test_urllib.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_urllib.py Mon Jul 25 09:47:18 2011 -0400 @@ -110,9 +110,8 @@ # Test iterator # Don't need to count number of iterations since test would fail the # instant it returned anything beyond the first line from the - # comparison. - # Use the iterator in the usual implicit way to test for ticket #4608. - for line in self.returned_obj: + # comparison + for line in self.returned_obj.__iter__(): self.assertEqual(line, self.text) class ProxyTests(unittest.TestCase): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_urllib2.py --- a/Lib/test/test_urllib2.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_urllib2.py Mon Jul 25 09:47:18 2011 -0400 @@ -623,7 +623,6 @@ def retrfile(self, filename, filetype): self.filename, self.filetype = filename, filetype return io.StringIO(self.data), len(self.data) - def close(self): pass class NullFTPHandler(urllib.request.FTPHandler): def __init__(self, data): self.data = data diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_urllib2net.py --- a/Lib/test/test_urllib2net.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_urllib2net.py Mon Jul 25 09:47:18 2011 -0400 @@ -222,7 +222,6 @@ handlers = [] cfh = urllib.request.CacheFTPHandler() - self.addCleanup(cfh.clear_cache) cfh.setTimeout(1) handlers.append(cfh) diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_urllibnet.py --- a/Lib/test/test_urllibnet.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_urllibnet.py Mon Jul 25 09:47:18 2011 -0400 @@ -113,14 +113,6 @@ def test_bad_address(self): # Make sure proper exception is raised when connecting to a bogus # address. - bogus_domain = "sadflkjsasf.i.nvali.d" - try: - socket.gethostbyname(bogus_domain) - except socket.gaierror: - pass - else: - # This happens with some overzealous DNS providers such as OpenDNS - self.skipTest("%r should not resolve for test to work" % bogus_domain) self.assertRaises(IOError, # SF patch 809915: In Sep 2003, VeriSign started # highjacking invalid .com and .net addresses to diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_urlparse.py Mon Jul 25 09:47:18 2011 -0400 @@ -93,11 +93,8 @@ def test_qsl(self): for orig, expect in parse_qsl_test_cases: result = urllib.parse.parse_qsl(orig, keep_blank_values=True) - self.assertEqual(result, expect, "Error parsing %r" % orig) - expect_without_blanks = [v for v in expect if len(v[1])] - result = urllib.parse.parse_qsl(orig, keep_blank_values=False) - self.assertEqual(result, expect_without_blanks, - "Error parsing %r" % orig) + self.assertEqual(result, expect, "Error parsing %s" % repr(orig)) + def test_roundtrips(self): str_cases = [ @@ -368,9 +365,6 @@ self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y') self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y') self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x') - self.checkJoin('http:///', '..','http:///') - self.checkJoin('', 'http://a/b/c/g?y/./x','http://a/b/c/g?y/./x') - self.checkJoin('', 'http://a/./g', 'http://a/./g') def test_RFC2732(self): str_cases = [ @@ -725,74 +719,6 @@ errors="ignore") self.assertEqual(result, [('key', '\u0141-')]) - def test_splitnport(self): - # Normal cases are exercised by other tests; ensure that we also - # catch cases with no port specified. (testcase ensuring coverage) - result = urllib.parse.splitnport('parrot:88') - self.assertEqual(result, ('parrot', 88)) - result = urllib.parse.splitnport('parrot') - self.assertEqual(result, ('parrot', -1)) - result = urllib.parse.splitnport('parrot', 55) - self.assertEqual(result, ('parrot', 55)) - result = urllib.parse.splitnport('parrot:') - self.assertEqual(result, ('parrot', None)) - - def test_splitquery(self): - # Normal cases are exercised by other tests; ensure that we also - # catch cases with no port specified (testcase ensuring coverage) - result = urllib.parse.splitquery('http://python.org/fake?foo=bar') - self.assertEqual(result, ('http://python.org/fake', 'foo=bar')) - result = urllib.parse.splitquery('http://python.org/fake?foo=bar?') - self.assertEqual(result, ('http://python.org/fake?foo=bar', '')) - result = urllib.parse.splitquery('http://python.org/fake') - self.assertEqual(result, ('http://python.org/fake', None)) - - def test_splitvalue(self): - # Normal cases are exercised by other tests; test pathological cases - # with no key/value pairs. (testcase ensuring coverage) - result = urllib.parse.splitvalue('foo=bar') - self.assertEqual(result, ('foo', 'bar')) - result = urllib.parse.splitvalue('foo=') - self.assertEqual(result, ('foo', '')) - result = urllib.parse.splitvalue('foobar') - self.assertEqual(result, ('foobar', None)) - - def test_to_bytes(self): - result = urllib.parse.to_bytes('http://www.python.org') - self.assertEqual(result, 'http://www.python.org') - self.assertRaises(UnicodeError, urllib.parse.to_bytes, - 'http://www.python.org/medi\u00e6val') - - def test_urlencode_sequences(self): - # Other tests incidentally urlencode things; test non-covered cases: - # Sequence and object values. - result = urllib.parse.urlencode({'a': [1, 2], 'b': (3, 4, 5)}, True) - self.assertEqual(result, 'a=1&a=2&b=3&b=4&b=5') - - class Trivial: - def __str__(self): - return 'trivial' - - result = urllib.parse.urlencode({'a': Trivial()}, True) - self.assertEqual(result, 'a=trivial') - - def test_quote_from_bytes(self): - self.assertRaises(TypeError, urllib.parse.quote_from_bytes, 'foo') - result = urllib.parse.quote_from_bytes(b'archaeological arcana') - self.assertEqual(result, 'archaeological%20arcana') - result = urllib.parse.quote_from_bytes(b'') - self.assertEqual(result, '') - - def test_unquote_to_bytes(self): - result = urllib.parse.unquote_to_bytes('abc%20def') - self.assertEqual(result, b'abc def') - result = urllib.parse.unquote_to_bytes('') - self.assertEqual(result, b'') - - def test_quote_errors(self): - self.assertRaises(TypeError, urllib.parse.quote, b'foo', - encoding='utf-8') - self.assertRaises(TypeError, urllib.parse.quote, b'foo', errors='strict') def test_main(): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_warnings.py Mon Jul 25 09:47:18 2011 -0400 @@ -512,11 +512,12 @@ def test_showwarning_not_callable(self): with original_warnings.catch_warnings(module=self.module): self.module.filterwarnings("always", category=UserWarning) - self.module.showwarning = print - with support.captured_output('stdout'): - self.module.warn('Warning!') + old_showwarning = self.module.showwarning self.module.showwarning = 23 - self.assertRaises(TypeError, self.module.warn, "Warning!") + try: + self.assertRaises(TypeError, self.module.warn, "Warning!") + finally: + self.module.showwarning = old_showwarning def test_show_warning_output(self): # With showarning() missing, make sure that output is okay. @@ -541,21 +542,6 @@ assert expected_line self.assertEqual(second_line, expected_line) - def test_filename_none(self): - # issue #12467: race condition if a warning is emitted at shutdown - globals_dict = globals() - oldfile = globals_dict['__file__'] - try: - catch = original_warnings.catch_warnings(record=True, - module=self.module) - with catch as w: - self.module.filterwarnings("always", category=UserWarning) - globals_dict['__file__'] = None - original_warnings.warn('test', UserWarning) - self.assertTrue(len(w)) - finally: - globals_dict['__file__'] = oldfile - class WarningsDisplayTests(unittest.TestCase): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_zipimport.py --- a/Lib/test/test_zipimport.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_zipimport.py Mon Jul 25 09:47:18 2011 -0400 @@ -411,7 +411,7 @@ def testEmptyFile(self): support.unlink(TESTMOD) - support.create_empty_file(TESTMOD) + open(TESTMOD, 'w+').close() self.assertZipFailure(TESTMOD) def testFileUnreadable(self): diff -r 95c34bce986c -r 900df5732f93 Lib/test/test_zipimport_support.py --- a/Lib/test/test_zipimport_support.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/test_zipimport_support.py Mon Jul 25 09:47:18 2011 -0400 @@ -33,19 +33,26 @@ def _run_object_doctest(obj, module): - finder = doctest.DocTestFinder(verbose=verbose, recurse=False) - runner = doctest.DocTestRunner(verbose=verbose) - # Use the object's fully qualified name if it has one - # Otherwise, use the module's name + # Direct doctest output (normally just errors) to real stdout; doctest + # output shouldn't be compared by regrtest. + save_stdout = sys.stdout + sys.stdout = test.support.get_original_stdout() try: - name = "%s.%s" % (obj.__module__, obj.__name__) - except AttributeError: - name = module.__name__ - for example in finder.find(obj, name, module): - runner.run(example) - f, t = runner.failures, runner.tries - if f: - raise test.support.TestFailed("%d of %d doctests failed" % (f, t)) + finder = doctest.DocTestFinder(verbose=verbose, recurse=False) + runner = doctest.DocTestRunner(verbose=verbose) + # Use the object's fully qualified name if it has one + # Otherwise, use the module's name + try: + name = "%s.%s" % (obj.__module__, obj.__name__) + except AttributeError: + name = module.__name__ + for example in finder.find(obj, name, module): + runner.run(example) + f, t = runner.failures, runner.tries + if f: + raise test.support.TestFailed("%d of %d doctests failed" % (f, t)) + finally: + sys.stdout = save_stdout if verbose: print ('doctest (%s) ... %d tests with zero failures' % (module.__name__, t)) return f, t diff -r 95c34bce986c -r 900df5732f93 Lib/test/threaded_import_hangers.py --- a/Lib/test/threaded_import_hangers.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/threaded_import_hangers.py Mon Jul 25 09:47:18 2011 -0400 @@ -35,11 +35,8 @@ ("os.path.abspath", os.path.abspath, ('.',)), ]: - try: - t = Worker(func, args) - t.start() - t.join(TIMEOUT) - if t.is_alive(): - errors.append("%s appeared to hang" % name) - finally: - del t + t = Worker(func, args) + t.start() + t.join(TIMEOUT) + if t.is_alive(): + errors.append("%s appeared to hang" % name) diff -r 95c34bce986c -r 900df5732f93 Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt --- a/Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt Mon Jul 25 09:47:18 2011 -0400 @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- # IMPORTANT: unlike the other test_tokenize-*.txt files, this file # does NOT have the utf-8 BOM signature '\xef\xbb\xbf' at the start # of it. Make sure this is not added inadvertently by your editor diff -r 95c34bce986c -r 900df5732f93 Lib/textwrap.py --- a/Lib/textwrap.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/textwrap.py Mon Jul 25 09:47:18 2011 -0400 @@ -7,7 +7,7 @@ __revision__ = "$Id$" -import re +import string, re __all__ = ['TextWrapper', 'wrap', 'fill', 'dedent'] diff -r 95c34bce986c -r 900df5732f93 Lib/threading.py --- a/Lib/threading.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/threading.py Mon Jul 25 09:47:18 2011 -0400 @@ -6,7 +6,6 @@ from time import time as _time, sleep as _sleep from traceback import format_exc as _format_exc from collections import deque -from _weakrefset import WeakSet # Note regarding PEP 8 compliant names # This threading model was originally inspired by Java, and inherited @@ -609,8 +608,6 @@ _active = {} # maps thread id to Thread object _limbo = {} -# For debug and leak testing -_dangling = WeakSet() # Main class for threads @@ -648,7 +645,6 @@ # sys.stderr is not stored in the class like # sys.exc_info since it can be changed between instances self._stderr = _sys.stderr - _dangling.add(self) def _reset_internal_locks(self): # private! Called by _after_fork() to reset our internal locks as diff -r 95c34bce986c -r 900df5732f93 Lib/tkinter/test/support.py --- a/Lib/tkinter/test/support.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/tkinter/test/support.py Mon Jul 25 09:47:18 2011 -0400 @@ -1,52 +1,6 @@ -import sys import tkinter -import unittest - -_tk_unavailable = None - -def check_tk_availability(): - """Check that Tk is installed and available.""" - global _tk_unavailable - - if _tk_unavailable is None: - _tk_unavailable = False - if sys.platform == 'darwin': - # The Aqua Tk implementations on OS X can abort the process if - # being called in an environment where a window server connection - # cannot be made, for instance when invoked by a buildbot or ssh - # process not running under the same user id as the current console - # user. To avoid that, raise an exception if the window manager - # connection is not available. - from ctypes import cdll, c_int, pointer, Structure - from ctypes.util import find_library - - app_services = cdll.LoadLibrary(find_library("ApplicationServices")) - - if app_services.CGMainDisplayID() == 0: - _tk_unavailable = "cannot run without OS X window manager" - else: - class ProcessSerialNumber(Structure): - _fields_ = [("highLongOfPSN", c_int), - ("lowLongOfPSN", c_int)] - psn = ProcessSerialNumber() - psn_p = pointer(psn) - if ( (app_services.GetCurrentProcess(psn_p) < 0) or - (app_services.SetFrontProcess(psn_p) < 0) ): - _tk_unavailable = "cannot run without OS X gui process" - else: # not OS X - import tkinter - try: - tkinter.Button() - except tkinter.TclError as msg: - # assuming tk is not available - _tk_unavailable = "tk not available: %s" % msg - - if _tk_unavailable: - raise unittest.SkipTest(_tk_unavailable) - return def get_tk_root(): - check_tk_availability() # raise exception if tk unavailable try: root = tkinter._default_root except AttributeError: diff -r 95c34bce986c -r 900df5732f93 Lib/tkinter/test/test_ttk/test_widgets.py --- a/Lib/tkinter/test/test_ttk/test_widgets.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/tkinter/test/test_ttk/test_widgets.py Mon Jul 25 09:47:18 2011 -0400 @@ -3,7 +3,6 @@ import os from tkinter import ttk from test.support import requires, run_unittest -import sys import tkinter.test.support as support from tkinter.test.test_ttk.test_functions import MockTclObj, MockStateSpec @@ -562,19 +561,11 @@ self.nb.pack() self.nb.wait_visibility() - if sys.platform == 'darwin': - tb_idx = "@20,5" - else: - tb_idx = "@5,5" - self.assertEqual(self.nb.tab(tb_idx), self.nb.tab('current')) + self.assertEqual(self.nb.tab('@5,5'), self.nb.tab('current')) for i in range(5, 100, 5): - try: - if self.nb.tab('@%d, 5' % i, text=None) == 'a': - break - except tkinter.TclError: - pass - + if self.nb.tab('@%d, 5' % i, text=None) == 'a': + break else: self.fail("Tab with text 'a' not found") @@ -731,10 +722,7 @@ self.nb.enable_traversal() self.nb.focus_force() support.simulate_mouse_click(self.nb, 5, 5) - if sys.platform == 'darwin': - self.nb.event_generate('') - else: - self.nb.event_generate('') + self.nb.event_generate('') self.assertEqual(self.nb.select(), str(self.child1)) diff -r 95c34bce986c -r 900df5732f93 Lib/turtle.py --- a/Lib/turtle.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/turtle.py Mon Jul 25 09:47:18 2011 -0400 @@ -108,6 +108,7 @@ import types import math import time +import os import inspect from os.path import isfile, split, join diff -r 95c34bce986c -r 900df5732f93 Lib/unittest/case.py --- a/Lib/unittest/case.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/unittest/case.py Mon Jul 25 09:47:18 2011 -0400 @@ -218,6 +218,27 @@ self._raiseFailure("{} not triggered".format(exc_name)) +class _TypeEqualityDict(object): + + def __init__(self, testcase): + self.testcase = testcase + self._store = {} + + def __setitem__(self, key, value): + self._store[key] = value + + def __getitem__(self, key): + value = self._store[key] + if isinstance(value, str): + return getattr(self.testcase, value) + return value + + def get(self, key, default=None): + if key in self._store: + return self[key] + return default + + class TestCase(object): """A class whose instances are single test cases. @@ -289,7 +310,7 @@ # Map types to custom assertEqual functions that will compare # instances of said type in more detail to generate a more useful # error message. - self._type_equality_funcs = {} + self._type_equality_funcs = _TypeEqualityDict(self) self.addTypeEqualityFunc(dict, 'assertDictEqual') self.addTypeEqualityFunc(list, 'assertListEqual') self.addTypeEqualityFunc(tuple, 'assertTupleEqual') @@ -622,8 +643,6 @@ if type(first) is type(second): asserter = self._type_equality_funcs.get(type(first)) if asserter is not None: - if isinstance(asserter, str): - asserter = getattr(self, asserter) return asserter return self._baseAssertEqual diff -r 95c34bce986c -r 900df5732f93 Lib/unittest/test/test_case.py --- a/Lib/unittest/test/test_case.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/unittest/test/test_case.py Mon Jul 25 09:47:18 2011 -0400 @@ -4,7 +4,6 @@ import re import sys import warnings -import weakref import inspect from copy import deepcopy @@ -1305,11 +1304,3 @@ klass('test_something').run(result) self.assertEqual(len(result.errors), 1) self.assertEqual(result.testsRun, 1) - - @support.cpython_only - def testNoCycles(self): - case = unittest.TestCase() - wr = weakref.ref(case) - with support.disable_gc(): - del case - self.assertFalse(wr()) diff -r 95c34bce986c -r 900df5732f93 Lib/urllib/request.py --- a/Lib/urllib/request.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/urllib/request.py Mon Jul 25 09:47:18 2011 -0400 @@ -1371,8 +1371,8 @@ raise exc.with_traceback(sys.exc_info()[2]) def connect_ftp(self, user, passwd, host, port, dirs, timeout): - return ftpwrapper(user, passwd, host, port, dirs, timeout, - persistent=False) + fw = ftpwrapper(user, passwd, host, port, dirs, timeout) + return fw class CacheFTPHandler(FTPHandler): # XXX would be nice to have pluggable cache strategies @@ -1421,13 +1421,6 @@ break self.soonest = min(list(self.timeout.values())) - def clear_cache(self): - for conn in self.cache.values(): - conn.close() - self.cache.clear() - self.timeout.clear() - - # Code move from the old urllib module MAXFTPCACHE = 10 # Trim the ftp cache beyond this size @@ -2151,16 +2144,13 @@ class ftpwrapper: """Class used by open_ftp() for cache of open FTP connections.""" - def __init__(self, user, passwd, host, port, dirs, timeout=None, - persistent=True): + def __init__(self, user, passwd, host, port, dirs, timeout=None): self.user = user self.passwd = passwd self.host = host self.port = port self.dirs = dirs self.timeout = timeout - self.refcount = 0 - self.keepalive = persistent self.init() def init(self): @@ -2211,8 +2201,7 @@ conn, retrlen = self.ftp.ntransfercmd(cmd) self.busy = 1 - ftpobj = addclosehook(conn.makefile('rb'), self.file_close) - self.refcount += 1 + ftpobj = addclosehook(conn.makefile('rb'), self.endtransfer) conn.close() # Pass back both a suitably decorated object and a retrieval length return (ftpobj, retrlen) @@ -2227,17 +2216,6 @@ pass def close(self): - self.keepalive = False - if self.refcount <= 0: - self.real_close() - - def file_close(self): - self.endtransfer() - self.refcount -= 1 - if self.refcount <= 0 and not self.keepalive: - self.real_close() - - def real_close(self): self.endtransfer() try: self.ftp.close() diff -r 95c34bce986c -r 900df5732f93 Lib/urllib/response.py --- a/Lib/urllib/response.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/urllib/response.py Mon Jul 25 09:47:18 2011 -0400 @@ -23,14 +23,10 @@ self.fileno = self.fp.fileno else: self.fileno = lambda: None - - def __iter__(self): - # Assigning `__iter__` to the instance doesn't work as intended - # because the iter builtin does something like `cls.__iter__(obj)` - # and thus fails to find the _bound_ method `obj.__iter__`. - # Returning just `self.fp` works for built-in file objects but - # might not work for general file-like objects. - return iter(self.fp) + if hasattr(self.fp, "__iter__"): + self.__iter__ = self.fp.__iter__ + if hasattr(self.fp, "__next__"): + self.__next__ = self.fp.__next__ def __repr__(self): return '<%s at %r whose fp = %r>' % (self.__class__.__name__, diff -r 95c34bce986c -r 900df5732f93 Lib/webbrowser.py --- a/Lib/webbrowser.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/webbrowser.py Mon Jul 25 09:47:18 2011 -0400 @@ -232,7 +232,7 @@ stdout=(self.redirect_stdout and inout or None), stderr=inout, start_new_session=True) if remote: - # wait five seconds. If the subprocess is not finished, the + # wait five secons. If the subprocess is not finished, the # remote invocation has (hopefully) started a new instance. time.sleep(1) rc = p.poll() diff -r 95c34bce986c -r 900df5732f93 Lib/xml/dom/pulldom.py --- a/Lib/xml/dom/pulldom.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/xml/dom/pulldom.py Mon Jul 25 09:47:18 2011 -0400 @@ -326,7 +326,7 @@ if bufsize is None: bufsize = default_bufsize if isinstance(stream_or_string, str): - stream = open(stream_or_string, 'rb') + stream = open(stream_or_string) else: stream = stream_or_string if not parser: diff -r 95c34bce986c -r 900df5732f93 Lib/xml/etree/ElementInclude.py --- a/Lib/xml/etree/ElementInclude.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Lib/xml/etree/ElementInclude.py Mon Jul 25 09:47:18 2011 -0400 @@ -67,7 +67,7 @@ # # @param href Resource reference. # @param parse Parse mode. Either "xml" or "text". -# @param encoding Optional text encoding (UTF-8 by default for "text"). +# @param encoding Optional text encoding. # @return The expanded resource. If the parse mode is "xml", this # is an ElementTree instance. If the parse mode is "text", this # is a Unicode string. If the loader fails, it can return None @@ -75,14 +75,13 @@ # @throws IOError If the loader fails to load the resource. def default_loader(href, parse, encoding=None): + file = open(href) if parse == "xml": - file = open(href, 'rb') data = ElementTree.parse(file).getroot() else: - if not encoding: - encoding = 'UTF-8' - file = open(href, 'r', encoding=encoding) data = file.read() + if encoding: + data = data.decode(encoding) file.close() return data diff -r 95c34bce986c -r 900df5732f93 Makefile.pre.in --- a/Makefile.pre.in Tue Jul 26 09:37:46 2011 +0300 +++ b/Makefile.pre.in Mon Jul 25 09:47:18 2011 -0400 @@ -73,7 +73,7 @@ # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables -PY_CPPFLAGS= -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) +PY_CPPFLAGS= -I. -IInclude $(CONFIGURE_CPPFLAGS) $(CPPFLAGS) PY_LDFLAGS= $(CONFIGURE_LDFLAGS) $(LDFLAGS) NO_AS_NEEDED= @NO_AS_NEEDED@ LDLAST= @LDLAST@ @@ -912,7 +912,6 @@ XMLLIBSUBDIRS= xml xml/dom xml/etree xml/parsers xml/sax LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \ tkinter/test/test_ttk site-packages test \ - test/capath test/data \ test/cjkencodings test/decimaltestdata test/xmltestdata \ test/subprocessdata \ test/tracedmodules test/encoded_modules \ @@ -983,7 +982,7 @@ multiprocessing multiprocessing/dummy \ unittest unittest/test \ curses pydoc_data $(MACHDEPS) -libinstall: build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c +libinstall: build_all $(srcdir)/Lib/$(PLATDIR) @for i in $(SCRIPTDIR) $(LIBDEST); \ do \ if test ! -d $(DESTDIR)$$i; then \ @@ -1039,14 +1038,6 @@ done; \ done $(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt - if test -d $(DESTDIR)$(LIBDEST)/distutils/tests; then \ - $(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \ - $(DESTDIR)$(LIBDEST)/distutils/tests ; \ - fi - if test -d $(DESTDIR)$(LIBDEST)/packaging/tests; then \ - $(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \ - $(DESTDIR)$(LIBDEST)/packaging/tests ; \ - fi -PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \ ./$(BUILDPYTHON) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \ -d $(LIBDEST) -f \ diff -r 95c34bce986c -r 900df5732f93 Misc/ACKS --- a/Misc/ACKS Tue Jul 26 09:37:46 2011 +0300 +++ b/Misc/ACKS Mon Jul 25 09:47:18 2011 -0400 @@ -82,7 +82,6 @@ Andrew Bennetts Andy Bensky Michel Van den Bergh -Julian Berman Eric Beser Steven Bethard Stephen Bevan @@ -130,7 +129,6 @@ Titus Brown Oleg Broytmann Dave Brueck -Francisco Martín Brugué Stan Bubrouski Erik de Bueger Dick Bulterman @@ -176,7 +174,6 @@ Mike Clarkson Andrew Clegg Brad Clements -Robbie Clemons Steve Clift Nick Coghlan Josh Cogliati @@ -193,7 +190,6 @@ Matt Conway David M. Cooke Jason R. Coombs -Garrett Cooper Greg Copeland Aldo Cortesi David Costanzo @@ -264,7 +260,6 @@ Walter Dörwald Hans Eckardt Rodolpho Eckhardt -John Edmonds Grant Edwards John Ehresman Eric Eisner @@ -281,7 +276,6 @@ Andy Eskilsson André Espaze Stefan Esser -Nicolas Estibals Stephen D Evans Carey Evans Tim Everett @@ -330,7 +324,6 @@ Santiago Gala Yitzchak Gale Quentin Gallet-Gilles -Riccardo Attilio Galli Raymund Galvin Nitin Ganatra Fred Gansevles @@ -420,7 +413,6 @@ Gerrit Holl Shane Holloway Rune Holm -Thomas Holmes Philip Homburg Naofumi Honda Jeffrey Honig @@ -516,7 +508,6 @@ Pat Knight Greg Kochanski Damon Kohler -Jacek Konieczny Марк Коренберг Vlad Korolev Joseph Koshy @@ -786,9 +777,7 @@ Armin Rigo Nicholas Riley Jean-Claude Rimbault -Vlad Riscutia Juan M. Bello Rivas -Davide Rizzo Anthony Roach Mark Roberts Jim Robinson @@ -820,7 +809,6 @@ Sam Rushing Mark Russell Nick Russo -Patrick Sabin Sébastien Sablé Hajime Saitou George Sakkis @@ -854,7 +842,6 @@ Yury Selivanov Fred Sells Jiwon Seo -Iñigo Serna Roger D. Serwy Jerry Seutter Denis Severson @@ -886,7 +873,6 @@ Cody Somerville Edoardo Spadolini Clay Spence -Stefan Sperling Per Spilling Joshua Spoerri Noah Spurrier @@ -1033,7 +1019,6 @@ Thomas Wouters Heiko Wundram Doug Wyatt -Robert Xiao Florent Xicluna Hirokazu Yamamoto Ka-Ping Yee diff -r 95c34bce986c -r 900df5732f93 Misc/NEWS --- a/Misc/NEWS Tue Jul 26 09:37:46 2011 +0300 +++ b/Misc/NEWS Mon Jul 25 09:47:18 2011 -0400 @@ -10,47 +10,6 @@ Core and Builtins ----------------- -- Verify the types of AST strings and identifiers provided by the user before - compiling them. - -- Issue #12579: str.format_map() now raises a ValueError if used on a - format string that contains positional fields. Initial patch by - Julian Berman. - -- Issue #10271: Allow warnings.showwarning() be any callable. - -- Issue #11627: Fix segfault when __new__ on a exception returns a - non-exception class. - -- Issue #12149: Update the method cache after a type's dictionnary gets - cleared by the garbage collector. This fixes a segfault when an instance - and its type get caught in a reference cycle, and the instance's - deallocator calls one of the methods on the type (e.g. when subclassing - IOBase). Diagnosis and patch by Davide Rizzo. - -- Issue #9611, #9015: FileIO.read() clamps the length to INT_MAX on Windows. - -- Issue #9642: Uniformize the tests on the availability of the mbcs codec, add - a new HAVE_MBCS define. - -- Issue #9642: Fix filesystem encoding initialization: use the ANSI code page - on Windows if the mbcs codec is not available, and fail with a fatal error if - we cannot get the locale encoding (if nl_langinfo(CODESET) is not available) - instead of using UTF-8. - -- When a generator yields, do not retain the caller's exception state on the - generator. - -- Issue #12475: Prevent generators from leaking their exception state into the - caller's frame as they return for the last time. - -- Issue #12291: You can now load multiple marshalled objects from a stream, - with other data interleaved between marshalled objects. - -- Issue #12356: When required positional or keyword-only arguments are not - given, produce a informative error message which includes the name(s) of the - missing arguments. - - Issue #12370: Fix super with not arguments when __class__ is overriden in the class body. @@ -237,153 +196,6 @@ Library ------- -- Issue #12102: Document that buffered files must be flushed before being used - with mmap. Patch by Steffen Daode Nurpmeso. - -- Issue #12560: Build libpython.so on OpenBSD. Patch by Stefan Sperling. - -- Issue #1813: Fix codec lookup under Turkish locales. - -- Issue #12591: Improve support of "universal newlines" in the subprocess - module: the piped streams can now be properly read from or written to. - -- Issue #12591: Allow io.TextIOWrapper to work with raw IO objects (without - a read1() method), and add a *write_through* parameter to mandate - unbuffered writes. - -- Issue #10883: Fix socket leaks in urllib.request when using FTP. - -- Issue #12592: Make Python build on OpenBSD 5 (and future major releases). - -- Issue #12372: POSIX semaphores are broken on AIX: don't use them. - -- Issue #12551: Provide a get_channel_binding() method on SSL sockets so as - to get channel binding data for the current SSL session (only the - "tls-unique" channel binding is implemented). This allows the implementation - of certain authentication mechanisms such as SCRAM-SHA-1-PLUS. Patch by - Jacek Konieczny. - -- Issue #665194: email.utils now has format_datetime and parsedate_to_datetime - functions, allowing for round tripping of RFC2822 format dates. - -- Issue #12571: Add a plat-linux3 directory mirroring the plat-linux2 - directory, so that "import DLFCN" and other similar imports work on - Linux 3.0. - -- Issue #7484: smtplib no longer puts <> around addresses in VRFY and EXPN - commands; they aren't required and in fact postfix doesn't support that form. - -- Issue #12273: Remove ast.__version__. AST changes can be accounted for by - checking sys.version_info or sys._mercurial. - -- Silence spurious "broken pipe" tracebacks when shutting down a - ProcessPoolExecutor. - -- Fix potential resource leaks in concurrent.futures.ProcessPoolExecutor - by joining all queues and processes when shutdown() is called. - -- Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by - Andreas Stührk. - -- Issue #11321: Fix a crash with multiple imports of the _pickle module when - embedding Python. Patch by Andreas Stührk. - -- Issue #6755: Add get_wch() method to curses.window class. Patch by Iñigo - Serna. - -- Add cgi.closelog() function to close the log file. - -- Issue #12502: asyncore: fix polling loop with AF_UNIX sockets. - -- Issue #4376: ctypes now supports nested structures in a endian different than - the parent structure. Patch by Vlad Riscutia. - -- Raise ValueError when attempting to set the _CHUNK_SIZE attribute of a - TextIOWrapper to a huge value, not TypeError. - -- Issue #12504: Close file handles in a timely manner in packaging.database. - This fixes a bug with the remove (uninstall) feature on Windows. - -- Issues #12169 and #10510: Factor out code used by various packaging commands - to make HTTP POST requests, and make sure it uses CRLF. - -- Issue #12016: Multibyte CJK decoders now resynchronize faster. They only - ignore the first byte of an invalid byte sequence. For example, - b'\xff\n'.decode('gb2312', 'replace') gives '\ufffd\n' instead of '\ufffd'. - -- Issue #12459: time.sleep() now raises a ValueError if the sleep length is - negative, instead of an infinite sleep on Windows or raising an IOError on - Linux for example, to have the same behaviour on all platforms. - -- Issue #12451: pydoc: html_getfile() now uses tokenize.open() to support - Python scripts using a encoding different than UTF-8 (read the coding cookie - of the script). - -- Issue #12493: subprocess: Popen.communicate() now also handles EINTR errors - if the process has only one pipe. - -- Issue #12467: warnings: fix a race condition if a warning is emitted at - shutdown, if globals()['__file__'] is None. - -- Issue #12451: pydoc: importfile() now opens the Python script in binary mode, - instead of text mode using the locale encoding, to avoid encoding issues. - -- Issue #12451: runpy: run_path() now opens the Python script in binary mode, - instead of text mode using the locale encoding, to support other encodings - than UTF-8 (scripts using the coding cookie). - -- Issue #12451: xml.dom.pulldom: parse() now opens files in binary mode instead - of the text mode (using the locale encoding) to avoid encoding issues. - -- Issue #12147: Adjust the new-in-3.2 smtplib.send_message method for better - conformance to the RFCs: correctly handle Sender and Resent- headers. - -- Issue #12352: Fix a deadlock in multiprocessing.Heap when a block is freed by - the garbage collector while the Heap lock is held. - -- Issue #12462: time.sleep() now calls immediatly the (Python) signal handler - if it is interrupted by a signal, instead of having to wait until the next - instruction. - -- Issue #12442: new shutil.disk_usage function, providing total, used and free - disk space statistics. - -- Issue #12451: The XInclude default loader of xml.etree now decodes files from - UTF-8 instead of the locale encoding if the encoding is not specified. It now - also opens XML files for the parser in binary mode instead of the text mode - to avoid encoding issues. - -- Issue #12451: doctest.debug_script() doesn't create a temporary file - anymore to avoid encoding issues. - -- Issue #12451: pydoc.synopsis() now reads the encoding cookie if available, - to read the Python script from the right encoding. - -- Issue #12451: distutils now opens the setup script in binary mode to read the - encoding cookie, instead of opening it in UTF-8. - -- Issue #9516: On Mac OS X, change Distutils to no longer globally attempt to - check or set the MACOSX_DEPLOYMENT_TARGET environment variable for the - interpreter process. This could cause failures in non-Distutils subprocesses - and was unreliable since tests or user programs could modify the interpreter - environment after Distutils set it. Instead, have Distutils set the the - deployment target only in the environment of each build subprocess. It is - still possible to globally override the default by setting - MACOSX_DEPLOYMENT_TARGET before launching the interpreter; its value must be - greater or equal to the default value, the value with which the interpreter - was built. Also, implement the same handling in packaging. - -- Issue #12422: In the copy module, don't store objects that are their own copy - in the memo dict. - -- Issue #12303: Add sigwaitinfo() and sigtimedwait() to the signal module. - -- Issue #12404: Remove C89 incompatible code from mmap module. Patch by Akira - Kitada. - -- Issue #1874: email now detects and reports as a defect the presence of - any CTE other than 7bit, 8bit, or binary on a multipart. - - Issue #12383: Fix subprocess module with env={}: don't copy the environment variables, start with an empty environment. @@ -1030,15 +842,6 @@ Build ----- -- Issue #11863: Remove support for legacy systems deprecated in Python 3.2 - (following PEP 11). These systems are systems using Mach C Threads, - SunOS lightweight processes, GNU pth threads and IRIX threads. - -- Issue #8746: Correct faulty configure checks so that os.chflags() and - os.lchflags() are once again built on systems that support these - functions (*BSD and OS X). Also add new stat file flags for OS X - (UF_HIDDEN and UF_COMPRESSED). - - Issue #10645: Installing Python does no longer create a Python-X.Y.Z-pyX.Y.egg-info file in the lib-dynload directory. @@ -1076,10 +879,6 @@ Extension Modules ----------------- -- Issue #10309: Define _GNU_SOURCE so that mremap() gets the proper - signature. Without this, architectures where sizeof void* != sizeof int are - broken. Patch given by Hallvard B Furuseth. - - Issue #12221: Replace pyexpat.__version__ with the Python version. - Issue #12051: Fix segfault in json.dumps() while encoding highly-nested @@ -1094,67 +893,6 @@ Tests ----- -- Issue #12624: It is now possible to fail after the first failure when - running in verbose mode (``-v`` or ``-W``), by using the ``--failfast`` - (or ``-G``) option to regrtest. This is useful with long test suites - such as test_io or test_subprocess. - -- Issue #12587: Correct faulty test file and reference in test_tokenize. - (Patch by Robert Xiao) - -- Issue #12573: Add resource checks for dangling Thread and Process objects. - -- Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64' - as the processor type on some Mac systems. - -- Skip network tests when getaddrinfo() returns EAI_AGAIN, meaning a temporary - failure in name resolution. - -- Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and - an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder - Web site. - -- Avoid failing in test_urllibnet.test_bad_address when some overzealous - DNS service (e.g. OpenDNS) resolves a non-existent domain name. The test - is now skipped instead. - -- Issue #12440: When testing whether some bits in SSLContext.options can be - reset, check the version of the OpenSSL headers Python was compiled against, - rather than the runtime version of the OpenSSL library. - -- Issue #11512: Add a test suite for the cgitb module. Patch by Robbie Clemons. - -- Issue #12497: Install test/data to prevent failures of the various codecmaps - tests. - -- Issue #12496: Install test/capath directory to prevent test_connect_capath - testcase failure in test_ssl. - -- Issue #12469: Run wakeup and pending signal tests in a subprocess to run the - test in a fresh process with only one thread and to not change signal - handling of the parent process. - -- Issue #8716: Avoid crashes caused by Aqua Tk on OSX when attempting to run - test_tk or test_ttk_guionly under a username that is not currently logged - in to the console windowserver (as may be the case under buildbot or ssh). - -- Issue #12407: Explicitly skip test_capi.EmbeddingTest under Windows. - -- Issue #12400: regrtest -W doesn't rerun the tests twice anymore, but captures - the output and displays it on failure instead. regrtest -v doesn't print the - error twice anymore if there is only one error. - -- Issue #12141: Install copies of template C module file so that - test_build_ext of test_distutils and test_command_build_ext of - test_packaging are no longer silently skipped when - run outside of a build directory. - -- Issue #8746: Add additional tests for os.chflags() and os.lchflags(). - Patch by Garrett Cooper. - -- Issue #10736: Fix test_ttk test_widgets failures with Cocoa Tk 8.5.9 - 2.8 + on Mac OS X. (Patch by Ronald Oussoren) - - Issue #12057: Add tests for ISO 2022 codecs (iso2022_jp, iso2022_jp_2, iso2022_kr). @@ -1470,7 +1208,7 @@ (length bigger than 2^31-1 bytes). - Issue #9015, #9611: FileIO.readinto(), FileIO.write(), os.write() and - stdprinter.write() clamp the length to INT_MAX on Windows. + stdprinter.write() clamp the length to 2^31-1 on Windows. - Issue #8278: On Windows and with a NTFS filesystem, os.stat() and os.utime() can now handle dates after 2038. diff -r 95c34bce986c -r 900df5732f93 Modules/_codecsmodule.c --- a/Modules/_codecsmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_codecsmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -588,7 +588,7 @@ return codec_tuple(unicode, pbuf.len); } -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) static PyObject * mbcs_decode(PyObject *self, @@ -613,7 +613,7 @@ return codec_tuple(decoded, consumed); } -#endif /* HAVE_MBCS */ +#endif /* MS_WINDOWS */ /* --- Encoder ------------------------------------------------------------ */ @@ -989,7 +989,7 @@ return PyUnicode_BuildEncodingMap(map); } -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) static PyObject * mbcs_encode(PyObject *self, @@ -1014,7 +1014,7 @@ return v; } -#endif /* HAVE_MBCS */ +#endif /* MS_WINDOWS */ /* --- Error handler registry --------------------------------------------- */ @@ -1101,7 +1101,7 @@ {"charmap_decode", charmap_decode, METH_VARARGS}, {"charmap_build", charmap_build, METH_VARARGS}, {"readbuffer_encode", readbuffer_encode, METH_VARARGS}, -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) {"mbcs_encode", mbcs_encode, METH_VARARGS}, {"mbcs_decode", mbcs_decode, METH_VARARGS}, #endif diff -r 95c34bce986c -r 900df5732f93 Modules/_ctypes/libffi/src/dlmalloc.c --- a/Modules/_ctypes/libffi/src/dlmalloc.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_ctypes/libffi/src/dlmalloc.c Mon Jul 25 09:47:18 2011 -0400 @@ -457,11 +457,6 @@ #define LACKS_ERRNO_H #define MALLOC_FAILURE_ACTION #define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */ -#elif !defined _GNU_SOURCE -/* mremap() on Linux requires this via sys/mman.h - * See roundup issue 10309 - */ -#define _GNU_SOURCE 1 #endif /* WIN32 */ #if defined(DARWIN) || defined(_DARWIN) diff -r 95c34bce986c -r 900df5732f93 Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_cursesmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -907,38 +907,6 @@ } static PyObject * -PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - int ct; - wint_t rtn; - - switch (PyTuple_Size(args)) { - case 0: - Py_BEGIN_ALLOW_THREADS - ct = wget_wch(self->win,&rtn); - Py_END_ALLOW_THREADS - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - Py_BEGIN_ALLOW_THREADS - ct = mvwget_wch(self->win,y,x,&rtn); - Py_END_ALLOW_THREADS - break; - default: - PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments"); - return NULL; - } - if (ct == ERR) { - /* get_wch() returns ERR in nodelay mode */ - PyErr_SetString(PyCursesError, "no input"); - return NULL; - } - return PyLong_FromLong(rtn); -} - -static PyObject * PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) { int x, y, n; @@ -1636,7 +1604,6 @@ {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, - {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS}, {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, diff -r 95c34bce986c -r 900df5732f93 Modules/_io/fileio.c --- a/Modules/_io/fileio.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_io/fileio.c Mon Jul 25 09:47:18 2011 -0400 @@ -687,10 +687,6 @@ return fileio_readall(self); } -#if defined(MS_WIN64) || defined(MS_WINDOWS) - if (size > INT_MAX) - size = INT_MAX; -#endif bytes = PyBytes_FromStringAndSize(NULL, size); if (bytes == NULL) return NULL; @@ -699,11 +695,7 @@ if (_PyVerify_fd(self->fd)) { Py_BEGIN_ALLOW_THREADS errno = 0; -#if defined(MS_WIN64) || defined(MS_WINDOWS) - n = read(self->fd, ptr, (int)size); -#else n = read(self->fd, ptr, size); -#endif Py_END_ALLOW_THREADS } else n = -1; diff -r 95c34bce986c -r 900df5732f93 Modules/_io/textio.c --- a/Modules/_io/textio.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_io/textio.c Mon Jul 25 09:47:18 2011 -0400 @@ -653,12 +653,10 @@ PyObject *errors; const char *writenl; /* utf-8 encoded, NULL stands for \n */ char line_buffering; - char write_through; char readuniversal; char readtranslate; char writetranslate; char seekable; - char has_read1; char telling; char deallocating; /* Specialized encoding func (see below) */ @@ -815,13 +813,13 @@ textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) { char *kwlist[] = {"buffer", "encoding", "errors", - "newline", "line_buffering", "write_through", + "newline", "line_buffering", NULL}; PyObject *buffer, *raw; char *encoding = NULL; char *errors = NULL; char *newline = NULL; - int line_buffering = 0, write_through = 0; + int line_buffering = 0; _PyIO_State *state = IO_STATE; PyObject *res; @@ -829,9 +827,9 @@ self->ok = 0; self->detached = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|zzzii:fileio", + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|zzzi:fileio", kwlist, &buffer, &encoding, &errors, - &newline, &line_buffering, &write_through)) + &newline, &line_buffering)) return -1; if (newline && newline[0] != '\0' @@ -937,7 +935,6 @@ self->chunk_size = 8192; self->readuniversal = (newline == NULL || newline[0] == '\0'); self->line_buffering = line_buffering; - self->write_through = write_through; self->readtranslate = (newline == NULL); if (newline) { self->readnl = PyUnicode_FromString(newline); @@ -1047,8 +1044,6 @@ self->seekable = self->telling = PyObject_IsTrue(res); Py_DECREF(res); - self->has_read1 = PyObject_HasAttrString(buffer, "read1"); - self->encoding_start_of_stream = 0; if (self->seekable && self->encoder) { PyObject *cookieObj; @@ -1292,9 +1287,7 @@ text = newtext; } - if (self->write_through) - needflush = 1; - else if (self->line_buffering && + if (self->line_buffering && (haslf || findchar(PyUnicode_AS_UNICODE(text), PyUnicode_GET_SIZE(text), '\r'))) @@ -1442,8 +1435,7 @@ if (chunk_size == NULL) goto fail; input_chunk = PyObject_CallMethodObjArgs(self->buffer, - (self->has_read1 ? _PyIO_str_read1: _PyIO_str_read), - chunk_size, NULL); + _PyIO_str_read1, chunk_size, NULL); Py_DECREF(chunk_size); if (input_chunk == NULL) goto fail; @@ -2626,7 +2618,7 @@ { Py_ssize_t n; CHECK_INITIALIZED_INT(self); - n = PyNumber_AsSsize_t(arg, PyExc_ValueError); + n = PyNumber_AsSsize_t(arg, PyExc_TypeError); if (n == -1 && PyErr_Occurred()) return -1; if (n <= 0) { diff -r 95c34bce986c -r 900df5732f93 Modules/_pickle.c --- a/Modules/_pickle.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_pickle.c Mon Jul 25 09:47:18 2011 -0400 @@ -6338,10 +6338,8 @@ if (m == NULL) return NULL; - Py_INCREF(&Pickler_Type); if (PyModule_AddObject(m, "Pickler", (PyObject *)&Pickler_Type) < 0) return NULL; - Py_INCREF(&Unpickler_Type); if (PyModule_AddObject(m, "Unpickler", (PyObject *)&Unpickler_Type) < 0) return NULL; diff -r 95c34bce986c -r 900df5732f93 Modules/_ssl.c --- a/Modules/_ssl.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/_ssl.c Mon Jul 25 09:47:18 2011 -0400 @@ -124,17 +124,6 @@ # undef HAVE_SSL_CTX_CLEAR_OPTIONS #endif -/* In case of 'tls-unique' it will be 12 bytes for TLS, 36 bytes for - * older SSL, but let's be safe */ -#define PySSL_CB_MAXLEN 128 - -/* SSL_get_finished got added to OpenSSL in 0.9.5 */ -#if OPENSSL_VERSION_NUMBER >= 0x0090500fL -# define HAVE_OPENSSL_FINISHED 1 -#else -# define HAVE_OPENSSL_FINISHED 0 -#endif - typedef struct { PyObject_HEAD SSL_CTX *ctx; @@ -146,7 +135,6 @@ SSL *ssl; X509 *peer_cert; int shutdown_seen_zero; - enum py_ssl_server_or_client socket_type; } PySSLSocket; static PyTypeObject PySSLContext_Type; @@ -340,7 +328,6 @@ SSL_set_accept_state(self->ssl); PySSL_END_ALLOW_THREADS - self->socket_type = socket_type; self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL); return self; } @@ -1390,41 +1377,6 @@ Does the SSL shutdown handshake with the remote end, and returns\n\ the underlying socket object."); -#if HAVE_OPENSSL_FINISHED -static PyObject * -PySSL_tls_unique_cb(PySSLSocket *self) -{ - PyObject *retval = NULL; - char buf[PySSL_CB_MAXLEN]; - int len; - - if (SSL_session_reused(self->ssl) ^ !self->socket_type) { - /* if session is resumed XOR we are the client */ - len = SSL_get_finished(self->ssl, buf, PySSL_CB_MAXLEN); - } - else { - /* if a new session XOR we are the server */ - len = SSL_get_peer_finished(self->ssl, buf, PySSL_CB_MAXLEN); - } - - /* It cannot be negative in current OpenSSL version as of July 2011 */ - assert(len >= 0); - if (len == 0) - Py_RETURN_NONE; - - retval = PyBytes_FromStringAndSize(buf, len); - - return retval; -} - -PyDoc_STRVAR(PySSL_tls_unique_cb_doc, -"tls_unique_cb() -> bytes\n\ -\n\ -Returns the 'tls-unique' channel binding data, as defined by RFC 5929.\n\ -\n\ -If the TLS handshake is not yet complete, None is returned"); - -#endif /* HAVE_OPENSSL_FINISHED */ static PyMethodDef PySSLMethods[] = { {"do_handshake", (PyCFunction)PySSL_SSLdo_handshake, METH_NOARGS}, @@ -1439,10 +1391,6 @@ {"cipher", (PyCFunction)PySSL_cipher, METH_NOARGS}, {"shutdown", (PyCFunction)PySSL_SSLshutdown, METH_NOARGS, PySSL_SSLshutdown_doc}, -#if HAVE_OPENSSL_FINISHED - {"tls_unique_cb", (PyCFunction)PySSL_tls_unique_cb, METH_NOARGS, - PySSL_tls_unique_cb_doc}, -#endif {NULL, NULL} }; @@ -2153,24 +2101,6 @@ NULL }; - -static void -parse_openssl_version(unsigned long libver, - unsigned int *major, unsigned int *minor, - unsigned int *fix, unsigned int *patch, - unsigned int *status) -{ - *status = libver & 0xF; - libver >>= 4; - *patch = libver & 0xFF; - libver >>= 8; - *fix = libver & 0xFF; - libver >>= 8; - *minor = libver & 0xFF; - libver >>= 8; - *major = libver & 0xFF; -} - PyMODINIT_FUNC PyInit__ssl(void) { @@ -2273,14 +2203,6 @@ Py_INCREF(r); PyModule_AddObject(m, "HAS_SNI", r); -#if HAVE_OPENSSL_FINISHED - r = Py_True; -#else - r = Py_False; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_TLS_UNIQUE", r); - /* OpenSSL version */ /* SSLeay() gives us the version of the library linked against, which could be different from the headers version. @@ -2291,7 +2213,15 @@ return NULL; if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r)) return NULL; - parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); + status = libver & 0xF; + libver >>= 4; + patch = libver & 0xFF; + libver >>= 8; + fix = libver & 0xFF; + libver >>= 8; + minor = libver & 0xFF; + libver >>= 8; + major = libver & 0xFF; r = Py_BuildValue("IIIII", major, minor, fix, patch, status); if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) return NULL; @@ -2299,11 +2229,5 @@ if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) return NULL; - libver = OPENSSL_VERSION_NUMBER; - parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); - r = Py_BuildValue("IIIII", major, minor, fix, patch, status); - if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r)) - return NULL; - return m; } diff -r 95c34bce986c -r 900df5732f93 Modules/cjkcodecs/_codecs_cn.c --- a/Modules/cjkcodecs/_codecs_cn.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/cjkcodecs/_codecs_cn.c Mon Jul 25 09:47:18 2011 -0400 @@ -85,7 +85,7 @@ TRYMAP_DEC(gb2312, **outbuf, c ^ 0x80, IN2 ^ 0x80) { NEXT(2, 1) } - else return 1; + else return 2; } return 0; @@ -141,7 +141,7 @@ REQUIRE_INBUF(2) GBK_DECODE(c, IN2, **outbuf) - else return 1; + else return 2; NEXT(2, 1) } @@ -267,7 +267,7 @@ c3 = IN3; c4 = IN4; if (c < 0x81 || c3 < 0x81 || c4 < 0x30 || c4 > 0x39) - return 1; + return 4; c -= 0x81; c2 -= 0x30; c3 -= 0x81; c4 -= 0x30; @@ -292,12 +292,12 @@ continue; } } - return 1; + return 4; } GBK_DECODE(c, c2, **outbuf) else TRYMAP_DEC(gb18030ext, **outbuf, c, c2); - else return 1; + else return 2; NEXT(2, 1) } @@ -400,7 +400,7 @@ else if (c2 == '\n') ; /* line-continuation */ else - return 1; + return 2; NEXT(2, 0); continue; } @@ -419,7 +419,7 @@ NEXT(2, 1) } else - return 1; + return 2; } } diff -r 95c34bce986c -r 900df5732f93 Modules/cjkcodecs/_codecs_hk.c --- a/Modules/cjkcodecs/_codecs_hk.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/cjkcodecs/_codecs_hk.c Mon Jul 25 09:47:18 2011 -0400 @@ -161,7 +161,7 @@ case 0x8864: WRITE2(0x00ca, 0x030c); break; case 0x88a3: WRITE2(0x00ea, 0x0304); break; case 0x88a5: WRITE2(0x00ea, 0x030c); break; - default: return 1; + default: return 2; } NEXT(2, 2) /* all decoded codepoints are pairs, above. */ diff -r 95c34bce986c -r 900df5732f93 Modules/cjkcodecs/_codecs_jp.c --- a/Modules/cjkcodecs/_codecs_jp.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/cjkcodecs/_codecs_jp.c Mon Jul 25 09:47:18 2011 -0400 @@ -112,7 +112,7 @@ TRYMAP_DEC(cp932ext, **outbuf, c, c2); else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)){ if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) - return 1; + return 2; c = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); @@ -120,7 +120,7 @@ c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21; TRYMAP_DEC(jisx0208, **outbuf, c, c2); - else return 1; + else return 2; } else if (c >= 0xf0 && c <= 0xf9) { if ((c2 >= 0x40 && c2 <= 0x7e) || @@ -128,10 +128,10 @@ OUT1(0xe000 + 188 * (c - 0xf0) + (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41)) else - return 1; + return 2; } else - return 1; + return 2; NEXT(2, 1) } @@ -256,7 +256,7 @@ NEXT(2, 1) } else - return 1; + return 2; } else if (c == 0x8f) { unsigned char c2, c3; @@ -274,7 +274,7 @@ continue; } else TRYMAP_DEC(jisx0212, **outbuf, c2, c3) ; - else return 1; + else return 3; NEXT(3, 1) } else { @@ -300,7 +300,7 @@ NEXT(2, 2) continue; } - else return 1; + else return 2; NEXT(2, 1) } } @@ -388,7 +388,7 @@ NEXT(2, 1) } else - return 1; + return 2; } else if (c == 0x8f) { unsigned char c2, c3; @@ -401,7 +401,7 @@ NEXT(3, 1) } else - return 1; + return 3; } else { unsigned char c2; @@ -417,7 +417,7 @@ #endif TRYMAP_DEC(jisx0208, **outbuf, c ^ 0x80, c2 ^ 0x80) ; - else return 1; + else return 2; NEXT(2, 1) } } @@ -502,7 +502,7 @@ REQUIRE_INBUF(2) c2 = IN2; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) - return 1; + return 2; c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); @@ -522,10 +522,10 @@ continue; } else - return 1; + return 2; } else - return 1; + return 2; NEXT(1, 1) /* JIS X 0201 */ } @@ -645,7 +645,7 @@ REQUIRE_INBUF(2) c2 = IN2; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) - return 1; + return 2; c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); @@ -671,7 +671,7 @@ NEXT_OUT(2) } else - return 1; + return 2; NEXT_IN(2) } else { /* Plane 2 */ @@ -689,13 +689,13 @@ continue; } else - return 1; + return 2; NEXT(2, 1) } continue; } else - return 1; + return 2; NEXT(1, 1) /* JIS X 0201 */ } diff -r 95c34bce986c -r 900df5732f93 Modules/cjkcodecs/_codecs_kr.c --- a/Modules/cjkcodecs/_codecs_kr.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/cjkcodecs/_codecs_kr.c Mon Jul 25 09:47:18 2011 -0400 @@ -123,7 +123,7 @@ if ((*inbuf)[2] != EUCKR_JAMO_FIRSTBYTE || (*inbuf)[4] != EUCKR_JAMO_FIRSTBYTE || (*inbuf)[6] != EUCKR_JAMO_FIRSTBYTE) - return 1; + return 8; c = (*inbuf)[3]; if (0xa1 <= c && c <= 0xbe) @@ -143,7 +143,7 @@ jong = NONE; if (cho == NONE || jung == NONE || jong == NONE) - return 1; + return 8; OUT1(0xac00 + cho*588 + jung*28 + jong); NEXT(8, 1) @@ -152,7 +152,7 @@ NEXT(2, 1) } else - return 1; + return 2; } return 0; @@ -208,7 +208,7 @@ REQUIRE_INBUF(2) TRYMAP_DEC(ksx1001, **outbuf, c ^ 0x80, IN2 ^ 0x80); else TRYMAP_DEC(cp949ext, **outbuf, c, IN2); - else return 1; + else return 2; NEXT(2, 1) } @@ -375,7 +375,7 @@ i_jong = johabidx_jongseong[c_jong]; if (i_cho == NONE || i_jung == NONE || i_jong == NONE) - return 1; + return 2; /* we don't use U+1100 hangul jamo yet. */ if (i_cho == FILL) { @@ -391,7 +391,7 @@ OUT1(0x3100 | johabjamo_jungseong[c_jung]) else - return 1; + return 2; } } else { if (i_jung == FILL) { @@ -399,7 +399,7 @@ OUT1(0x3100 | johabjamo_choseong[c_cho]) else - return 1; + return 2; } else OUT1(0xac00 + @@ -414,7 +414,7 @@ c2 < 0x31 || (c2 >= 0x80 && c2 < 0x91) || (c2 & 0x7f) == 0x7f || (c == 0xda && (c2 >= 0xa1 && c2 <= 0xd3))) - return 1; + return 2; else { unsigned char t1, t2; @@ -425,7 +425,7 @@ t2 = (t2 < 0x5e ? t2 : t2 - 0x5e) + 0x21; TRYMAP_DEC(ksx1001, **outbuf, t1, t2); - else return 1; + else return 2; NEXT(2, 1) } } diff -r 95c34bce986c -r 900df5732f93 Modules/cjkcodecs/_codecs_tw.c --- a/Modules/cjkcodecs/_codecs_tw.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/cjkcodecs/_codecs_tw.c Mon Jul 25 09:47:18 2011 -0400 @@ -55,7 +55,7 @@ TRYMAP_DEC(big5, **outbuf, c, IN2) { NEXT(2, 1) } - else return 1; + else return 2; } return 0; @@ -109,7 +109,7 @@ TRYMAP_DEC(cp950ext, **outbuf, c, IN2); else TRYMAP_DEC(big5, **outbuf, c, IN2); - else return 1; + else return 2; NEXT(2, 1) } diff -r 95c34bce986c -r 900df5732f93 Modules/faulthandler.c --- a/Modules/faulthandler.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/faulthandler.c Mon Jul 25 09:47:18 2011 -0400 @@ -4,9 +4,6 @@ #include #include #include -#if defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK) -#include -#endif /* Allocate at maximum 100 MB of the stack to raise the stack overflow */ #define STACK_OVERFLOW_MAX_SIZE (100*1024*1024) @@ -71,7 +68,6 @@ PyObject *file; int fd; int all_threads; - int chain; _Py_sighandler_t previous; PyInterpreterState *interp; } user_signal_t; @@ -94,7 +90,6 @@ # endif #endif -static void faulthandler_user(int signum); #endif /* FAULTHANDLER_USER */ @@ -260,9 +255,9 @@ /* restore the previous handler */ #ifdef HAVE_SIGACTION - (void)sigaction(signum, &handler->previous, NULL); + (void)sigaction(handler->signum, &handler->previous, NULL); #else - (void)signal(signum, handler->previous); + (void)signal(handler->signum, handler->previous); #endif handler->enabled = 0; @@ -588,39 +583,6 @@ #endif /* FAULTHANDLER_LATER */ #ifdef FAULTHANDLER_USER -static int -faulthandler_register(int signum, int chain, _Py_sighandler_t *p_previous) -{ -#ifdef HAVE_SIGACTION - struct sigaction action; - action.sa_handler = faulthandler_user; - sigemptyset(&action.sa_mask); - /* if the signal is received while the kernel is executing a system - call, try to restart the system call instead of interrupting it and - return EINTR. */ - action.sa_flags = SA_RESTART; - if (chain) { - /* do not prevent the signal from being received from within its - own signal handler */ - action.sa_flags = SA_NODEFER; - } -#ifdef HAVE_SIGALTSTACK - if (stack.ss_sp != NULL) { - /* Call the signal handler on an alternate signal stack - provided by sigaltstack() */ - action.sa_flags |= SA_ONSTACK; - } -#endif - return sigaction(signum, &action, p_previous); -#else - _Py_sighandler_t previous; - previous = signal(signum, faulthandler_user); - if (p_previous != NULL) - *p_previous = previous; - return (previous == SIG_ERR); -#endif -} - /* Handler of user signals (e.g. SIGUSR1). Dump the traceback of the current thread, or of all threads if @@ -655,19 +617,6 @@ return; _Py_DumpTraceback(user->fd, tstate); } -#ifdef HAVE_SIGACTION - if (user->chain) { - (void)sigaction(signum, &user->previous, NULL); - /* call the previous signal handler */ - raise(signum); - (void)faulthandler_register(signum, user->chain, NULL); - } -#else - if (user->chain) { - /* call the previous signal handler */ - user->previous(signum); - } -#endif errno = save_errno; } @@ -693,23 +642,25 @@ } static PyObject* -faulthandler_register_py(PyObject *self, - PyObject *args, PyObject *kwargs) +faulthandler_register(PyObject *self, + PyObject *args, PyObject *kwargs) { - static char *kwlist[] = {"signum", "file", "all_threads", "chain", NULL}; + static char *kwlist[] = {"signum", "file", "all_threads", NULL}; int signum; PyObject *file = NULL; int all_threads = 1; - int chain = 0; int fd; user_signal_t *user; _Py_sighandler_t previous; +#ifdef HAVE_SIGACTION + struct sigaction action; +#endif PyThreadState *tstate; int err; if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "i|Oii:register", kwlist, - &signum, &file, &all_threads, &chain)) + "i|Oi:register", kwlist, + &signum, &file, &all_threads)) return NULL; if (!check_signum(signum)) @@ -731,7 +682,25 @@ user = &user_signals[signum]; if (!user->enabled) { - err = faulthandler_register(signum, chain, &previous); +#ifdef HAVE_SIGACTION + action.sa_handler = faulthandler_user; + sigemptyset(&action.sa_mask); + /* if the signal is received while the kernel is executing a system + call, try to restart the system call instead of interrupting it and + return EINTR */ + action.sa_flags = SA_RESTART; +#ifdef HAVE_SIGALTSTACK + if (stack.ss_sp != NULL) { + /* Call the signal handler on an alternate signal stack + provided by sigaltstack() */ + action.sa_flags |= SA_ONSTACK; + } +#endif + err = sigaction(signum, &action, &previous); +#else + previous = signal(signum, faulthandler_user); + err = (previous == SIG_ERR); +#endif if (err) { PyErr_SetFromErrno(PyExc_OSError); return NULL; @@ -743,7 +712,6 @@ user->file = file; user->fd = fd; user->all_threads = all_threads; - user->chain = chain; user->previous = previous; user->interp = tstate->interp; user->enabled = 1; @@ -975,8 +943,8 @@ #ifdef FAULTHANDLER_USER {"register", - (PyCFunction)faulthandler_register_py, METH_VARARGS|METH_KEYWORDS, - PyDoc_STR("register(signum, file=sys.stderr, all_threads=True, chain=False): " + (PyCFunction)faulthandler_register, METH_VARARGS|METH_KEYWORDS, + PyDoc_STR("register(signum, file=sys.stderr, all_threads=True): " "register an handler for the signal 'signum': dump the " "traceback of the current thread, or of all threads if " "all_threads is True, into file")}, diff -r 95c34bce986c -r 900df5732f93 Modules/md5module.c --- a/Modules/md5module.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/md5module.c Mon Jul 25 09:47:18 2011 -0400 @@ -243,7 +243,7 @@ in += MD5_BLOCKSIZE; inlen -= MD5_BLOCKSIZE; } else { - n = MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen)); + n = MIN(inlen, (MD5_BLOCKSIZE - md5->curlen)); memcpy(md5->buf + md5->curlen, in, (size_t)n); md5->curlen += n; in += n; diff -r 95c34bce986c -r 900df5732f93 Modules/mmapmodule.c --- a/Modules/mmapmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/mmapmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -1162,13 +1162,12 @@ # endif if (fd != -1 && fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { if (map_size == 0) { - off_t calc_size; if (offset >= st.st_size) { PyErr_SetString(PyExc_ValueError, "mmap offset is greater than file size"); return NULL; } - calc_size = st.st_size - offset; + off_t calc_size = st.st_size - offset; map_size = calc_size; if (map_size != calc_size) { PyErr_SetString(PyExc_ValueError, diff -r 95c34bce986c -r 900df5732f93 Modules/posixmodule.c --- a/Modules/posixmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/posixmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -7451,32 +7451,6 @@ } #endif /* HAVE_STATVFS */ -#ifdef MS_WINDOWS -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; - LPCTSTR path; - - if (! PyArg_ParseTuple(args, "s", &path)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - retval = GetDiskFreeSpaceEx(path, &_, &total, &free); - Py_END_ALLOW_THREADS - if (retval == 0) - return PyErr_SetFromWindowsErr(0); - - return Py_BuildValue("(LL)", total.QuadPart, free.QuadPart); -} -#endif - - /* This is used for fpathconf(), pathconf(), confstr() and sysconf(). * It maps strings representing configuration variable names to * integer values, allowing those functions to be called with the @@ -9742,7 +9716,6 @@ {"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL}, {"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL}, {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__}, - {"_getdiskusage", win32__getdiskusage, METH_VARARGS, win32__getdiskusage__doc__}, #endif #ifdef HAVE_GETLOADAVG {"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__}, diff -r 95c34bce986c -r 900df5732f93 Modules/selectmodule.c --- a/Modules/selectmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/selectmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -921,7 +921,7 @@ PyDoc_STRVAR(pyepoll_register_doc, "register(fd[, eventmask]) -> None\n\ \n\ -Registers a new fd or raises an IOError if the fd is already registered.\n\ +Registers a new fd or modifies an already registered fd.\n\ fd is the target file descriptor of the operation.\n\ events is a bit set composed of the various EPOLL constants; the default\n\ is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\ diff -r 95c34bce986c -r 900df5732f93 Modules/sha1module.c --- a/Modules/sha1module.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/sha1module.c Mon Jul 25 09:47:18 2011 -0400 @@ -218,7 +218,7 @@ in += SHA1_BLOCKSIZE; inlen -= SHA1_BLOCKSIZE; } else { - n = MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen)); + n = MIN(inlen, (SHA1_BLOCKSIZE - sha1->curlen)); memcpy(sha1->buf + sha1->curlen, in, (size_t)n); sha1->curlen += n; in += n; diff -r 95c34bce986c -r 900df5732f93 Modules/signalmodule.c --- a/Modules/signalmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/signalmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -507,8 +507,7 @@ Returns current value of given itimer."); #endif -#if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) || \ - defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT) +#if defined(PYPTHREAD_SIGMASK) || defined(HAVE_SIGWAIT) /* Convert an iterable to a sigset. Return 0 on success, return -1 and raise an exception on error. */ @@ -680,140 +679,6 @@ Wait a signal."); #endif /* #ifdef HAVE_SIGPENDING */ -#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT) -static int initialized; -static PyStructSequence_Field struct_siginfo_fields[] = { - {"si_signo", "signal number"}, - {"si_code", "signal code"}, - {"si_errno", "errno associated with this signal"}, - {"si_pid", "sending process ID"}, - {"si_uid", "real user ID of sending process"}, - {"si_status", "exit value or signal"}, - {"si_band", "band event for SIGPOLL"}, - {0} -}; - -PyDoc_STRVAR(struct_siginfo__doc__, -"struct_siginfo: Result from sigwaitinfo or sigtimedwait.\n\n\ -This object may be accessed either as a tuple of\n\ -(si_signo, si_code, si_errno, si_pid, si_uid, si_status, si_band),\n\ -or via the attributes si_signo, si_code, and so on."); - -static PyStructSequence_Desc struct_siginfo_desc = { - "signal.struct_siginfo", /* name */ - struct_siginfo__doc__, /* doc */ - struct_siginfo_fields, /* fields */ - 7 /* n_in_sequence */ -}; - -static PyTypeObject SiginfoType; - -static PyObject * -fill_siginfo(siginfo_t *si) -{ - PyObject *result = PyStructSequence_New(&SiginfoType); - if (!result) - return NULL; - - PyStructSequence_SET_ITEM(result, 0, PyLong_FromLong((long)(si->si_signo))); - PyStructSequence_SET_ITEM(result, 1, PyLong_FromLong((long)(si->si_code))); - PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si->si_errno))); - PyStructSequence_SET_ITEM(result, 3, PyLong_FromPid(si->si_pid)); - PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si->si_uid))); - PyStructSequence_SET_ITEM(result, 5, - PyLong_FromLong((long)(si->si_status))); - PyStructSequence_SET_ITEM(result, 6, PyLong_FromLong(si->si_band)); - if (PyErr_Occurred()) { - Py_DECREF(result); - return NULL; - } - - return result; -} -#endif - -#ifdef HAVE_SIGWAITINFO -static PyObject * -signal_sigwaitinfo(PyObject *self, PyObject *args) -{ - PyObject *signals; - sigset_t set; - siginfo_t si; - int err; - - if (!PyArg_ParseTuple(args, "O:sigwaitinfo", &signals)) - return NULL; - - if (iterable_to_sigset(signals, &set)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - err = sigwaitinfo(&set, &si); - Py_END_ALLOW_THREADS - if (err == -1) - return PyErr_SetFromErrno(PyExc_OSError); - - return fill_siginfo(&si); -} - -PyDoc_STRVAR(signal_sigwaitinfo_doc, -"sigwaitinfo(sigset) -> struct_siginfo\n\ -\n\ -Wait synchronously for a signal until one of the signals in *sigset* is\n\ -delivered.\n\ -Returns a struct_siginfo containing information about the signal."); -#endif /* #ifdef HAVE_SIGWAITINFO */ - -#ifdef HAVE_SIGTIMEDWAIT -static PyObject * -signal_sigtimedwait(PyObject *self, PyObject *args) -{ - PyObject *signals, *timeout; - struct timespec buf; - sigset_t set; - siginfo_t si; - int err; - - if (!PyArg_ParseTuple(args, "OO:sigtimedwait", &signals, &timeout)) - return NULL; - - if (!PyTuple_Check(timeout) || PyTuple_Size(timeout) != 2) { - PyErr_SetString(PyExc_TypeError, - "sigtimedwait() arg 2 must be a tuple " - "(timeout_sec, timeout_nsec)"); - return NULL; - } else if (!PyArg_ParseTuple(timeout, "ll:sigtimedwait", - &(buf.tv_sec), &(buf.tv_nsec))) - return NULL; - - if (buf.tv_sec < 0 || buf.tv_nsec < 0) { - PyErr_SetString(PyExc_ValueError, "timeout must be non-negative"); - return NULL; - } - - if (iterable_to_sigset(signals, &set)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - err = sigtimedwait(&set, &si, &buf); - Py_END_ALLOW_THREADS - if (err == -1) { - if (errno == EAGAIN) - Py_RETURN_NONE; - else - return PyErr_SetFromErrno(PyExc_OSError); - } - - return fill_siginfo(&si); -} - -PyDoc_STRVAR(signal_sigtimedwait_doc, -"sigtimedwait(sigset, (timeout_sec, timeout_nsec)) -> struct_siginfo\n\ -\n\ -Like sigwaitinfo(), but with a timeout specified as a tuple of (seconds,\n\ -nanoseconds)."); -#endif /* #ifdef HAVE_SIGTIMEDWAIT */ - #if defined(HAVE_PTHREAD_KILL) && defined(WITH_THREAD) static PyObject * @@ -887,14 +752,6 @@ {"sigwait", (PyCFunction)signal_sigwait, METH_VARARGS, signal_sigwait_doc}, #endif -#ifdef HAVE_SIGWAITINFO - {"sigwaitinfo", (PyCFunction)signal_sigwaitinfo, - METH_VARARGS, signal_sigwaitinfo_doc}, -#endif -#ifdef HAVE_SIGTIMEDWAIT - {"sigtimedwait", (PyCFunction)signal_sigtimedwait, - METH_VARARGS, signal_sigtimedwait_doc}, -#endif {NULL, NULL} /* sentinel */ }; @@ -963,15 +820,6 @@ if (m == NULL) return NULL; -#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT) - if (!initialized) - PyStructSequence_InitType(&SiginfoType, &struct_siginfo_desc); - - Py_INCREF((PyObject*) &SiginfoType); - PyModule_AddObject(m, "struct_siginfo", (PyObject*) &SiginfoType); - initialized = 1; -#endif - /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); diff -r 95c34bce986c -r 900df5732f93 Modules/timemodule.c --- a/Modules/timemodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Modules/timemodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -3,6 +3,8 @@ #include "Python.h" #include "_time.h" +#define TZNAME_ENCODING "utf-8" + #include #ifdef HAVE_SYS_TYPES_H @@ -43,11 +45,12 @@ #endif /* MS_WINDOWS */ #endif /* !__WATCOMC__ || __QNX__ */ -#if defined(HAVE_MBCS) -# define TZNAME_ENCODING "mbcs" -#else -# define TZNAME_ENCODING "utf-8" -#endif +#if defined(MS_WINDOWS) && !defined(__BORLANDC__) +/* Win32 has better clock replacement; we have our own version below. */ +#undef HAVE_CLOCK +#undef TZNAME_ENCODING +#define TZNAME_ENCODING "mbcs" +#endif /* MS_WINDOWS && !defined(__BORLANDC__) */ #if defined(PYOS_OS2) #define INCL_DOS @@ -81,9 +84,25 @@ Return the current time in seconds since the Epoch.\n\ Fractions of a second may be present if the system clock provides them."); +#ifdef HAVE_CLOCK + +#ifndef CLOCKS_PER_SEC +#ifdef CLK_TCK +#define CLOCKS_PER_SEC CLK_TCK +#else +#define CLOCKS_PER_SEC 1000000 +#endif +#endif + +static PyObject * +time_clock(PyObject *self, PyObject *unused) +{ + return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); +} +#endif /* HAVE_CLOCK */ + #if defined(MS_WINDOWS) && !defined(__BORLANDC__) -/* Win32 has better clock replacement; we have our own version, due to Mark - Hammond and Tim Peters */ +/* Due to Mark Hammond and Tim Peters */ static PyObject * time_clock(PyObject *self, PyObject *unused) { @@ -108,23 +127,8 @@ return PyFloat_FromDouble(diff / divisor); } -#elif defined(HAVE_CLOCK) - -#ifndef CLOCKS_PER_SEC -#ifdef CLK_TCK -#define CLOCKS_PER_SEC CLK_TCK -#else -#define CLOCKS_PER_SEC 1000000 -#endif -#endif - -static PyObject * -time_clock(PyObject *self, PyObject *unused) -{ - return PyFloat_FromDouble(((double)clock()) / CLOCKS_PER_SEC); -} -#endif /* HAVE_CLOCK */ - +#define HAVE_CLOCK /* So it gets included in the methods */ +#endif /* MS_WINDOWS && !defined(__BORLANDC__) */ #ifdef HAVE_CLOCK PyDoc_STRVAR(clock_doc, @@ -141,11 +145,6 @@ double secs; if (!PyArg_ParseTuple(args, "d:sleep", &secs)) return NULL; - if (secs < 0) { - PyErr_SetString(PyExc_ValueError, - "sleep length must be non-negative"); - return NULL; - } if (floatsleep(secs) != 0) return NULL; Py_INCREF(Py_None); @@ -785,7 +784,7 @@ static PyMethodDef time_methods[] = { {"time", time_time, METH_NOARGS, time_doc}, -#if (defined(MS_WINDOWS) && !defined(__BORLANDC__)) || defined(HAVE_CLOCK) +#ifdef HAVE_CLOCK {"clock", time_clock, METH_NOARGS, clock_doc}, #endif {"sleep", time_sleep, METH_VARARGS, sleep_doc}, @@ -916,28 +915,23 @@ #if defined(HAVE_SELECT) && !defined(__EMX__) struct timeval t; double frac; - int err; - frac = fmod(secs, 1.0); secs = floor(secs); t.tv_sec = (long)secs; t.tv_usec = (long)(frac*1000000.0); Py_BEGIN_ALLOW_THREADS - err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t); - Py_END_ALLOW_THREADS - if (err != 0) { + if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) { #ifdef EINTR - if (errno == EINTR) { - if (PyErr_CheckSignals()) - return -1; - } - else + if (errno != EINTR) { +#else + if (1) { #endif - { + Py_BLOCK_THREADS PyErr_SetFromErrno(PyExc_IOError); return -1; } } + Py_END_ALLOW_THREADS #elif defined(__WATCOMC__) && !defined(__QNX__) /* XXX Can't interrupt this sleep */ Py_BEGIN_ALLOW_THREADS diff -r 95c34bce986c -r 900df5732f93 Objects/bytes_methods.c --- a/Objects/bytes_methods.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/bytes_methods.c Mon Jul 25 09:47:18 2011 -0400 @@ -366,10 +366,10 @@ PyDoc_STRVAR_shared(_Py_maketrans__doc__, "B.maketrans(frm, to) -> translation table\n\ \n\ -Return a translation table (a bytes object of length 256) suitable\n\ -for use in the bytes or bytearray translate method where each byte\n\ -in frm is mapped to the byte at the same position in to.\n\ -The bytes objects frm and to must be of the same length."); +Return a translation table (a bytes object of length 256)\n\ +suitable for use in bytes.translate where each byte in frm is\n\ +mapped to the byte at the same position in to.\n\ +The strings frm and to must be of the same length."); static Py_ssize_t _getbuffer(PyObject *obj, Py_buffer *view) diff -r 95c34bce986c -r 900df5732f93 Objects/codeobject.c --- a/Objects/codeobject.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/codeobject.c Mon Jul 25 09:47:18 2011 -0400 @@ -51,8 +51,7 @@ PyObject *lnotab) { PyCodeObject *co; - unsigned char *cell2arg = NULL; - Py_ssize_t i, n_cellvars; + Py_ssize_t i; /* Check argument types */ if (argcount < 0 || kwonlyargcount < 0 || nlocals < 0 || @@ -69,13 +68,12 @@ PyErr_BadInternalCall(); return NULL; } - n_cellvars = PyTuple_GET_SIZE(cellvars); intern_strings(names); intern_strings(varnames); intern_strings(freevars); intern_strings(cellvars); /* Intern selected string constants */ - for (i = PyTuple_GET_SIZE(consts); --i >= 0; ) { + for (i = PyTuple_Size(consts); --i >= 0; ) { PyObject *v = PyTuple_GetItem(consts, i); if (!PyUnicode_Check(v)) continue; @@ -83,67 +81,35 @@ continue; PyUnicode_InternInPlace(&PyTuple_GET_ITEM(consts, i)); } - /* Create mapping between cells and arguments if needed. */ - if (n_cellvars) { - Py_ssize_t total_args = argcount + kwonlyargcount + - ((flags & CO_VARARGS) != 0) + ((flags & CO_VARKEYWORDS) != 0); - Py_ssize_t alloc_size = sizeof(unsigned char) * n_cellvars; - int used_cell2arg = 0; - cell2arg = PyMem_MALLOC(alloc_size); - if (cell2arg == NULL) - return NULL; - memset(cell2arg, CO_CELL_NOT_AN_ARG, alloc_size); - /* Find cells which are also arguments. */ - for (i = 0; i < n_cellvars; i++) { - Py_ssize_t j; - PyObject *cell = PyTuple_GET_ITEM(cellvars, i); - for (j = 0; j < total_args; j++) { - PyObject *arg = PyTuple_GET_ITEM(varnames, j); - if (!PyUnicode_Compare(cell, arg)) { - cell2arg[i] = j; - used_cell2arg = 1; - break; - } - } - } - if (!used_cell2arg) { - PyMem_FREE(cell2arg); - cell2arg = NULL; - } + co = PyObject_NEW(PyCodeObject, &PyCode_Type); + if (co != NULL) { + co->co_argcount = argcount; + co->co_kwonlyargcount = kwonlyargcount; + co->co_nlocals = nlocals; + co->co_stacksize = stacksize; + co->co_flags = flags; + Py_INCREF(code); + co->co_code = code; + Py_INCREF(consts); + co->co_consts = consts; + Py_INCREF(names); + co->co_names = names; + Py_INCREF(varnames); + co->co_varnames = varnames; + Py_INCREF(freevars); + co->co_freevars = freevars; + Py_INCREF(cellvars); + co->co_cellvars = cellvars; + Py_INCREF(filename); + co->co_filename = filename; + Py_INCREF(name); + co->co_name = name; + co->co_firstlineno = firstlineno; + Py_INCREF(lnotab); + co->co_lnotab = lnotab; + co->co_zombieframe = NULL; + co->co_weakreflist = NULL; } - co = PyObject_NEW(PyCodeObject, &PyCode_Type); - if (co == NULL) { - if (cell2arg) - PyMem_FREE(cell2arg); - return NULL; - } - co->co_argcount = argcount; - co->co_kwonlyargcount = kwonlyargcount; - co->co_nlocals = nlocals; - co->co_stacksize = stacksize; - co->co_flags = flags; - Py_INCREF(code); - co->co_code = code; - Py_INCREF(consts); - co->co_consts = consts; - Py_INCREF(names); - co->co_names = names; - Py_INCREF(varnames); - co->co_varnames = varnames; - Py_INCREF(freevars); - co->co_freevars = freevars; - Py_INCREF(cellvars); - co->co_cellvars = cellvars; - co->co_cell2arg = cell2arg; - Py_INCREF(filename); - co->co_filename = filename; - Py_INCREF(name); - co->co_name = name; - co->co_firstlineno = firstlineno; - Py_INCREF(lnotab); - co->co_lnotab = lnotab; - co->co_zombieframe = NULL; - co->co_weakreflist = NULL; return co; } @@ -364,8 +330,6 @@ Py_XDECREF(co->co_filename); Py_XDECREF(co->co_name); Py_XDECREF(co->co_lnotab); - if (co->co_cell2arg != NULL) - PyMem_FREE(co->co_cell2arg); if (co->co_zombieframe != NULL) PyObject_GC_Del(co->co_zombieframe); if (co->co_weakreflist != NULL) diff -r 95c34bce986c -r 900df5732f93 Objects/genobject.c --- a/Objects/genobject.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/genobject.c Mon Jul 25 09:47:18 2011 -0400 @@ -395,13 +395,15 @@ int i; PyFrameObject *f = gen->gi_frame; - if (f == NULL || f->f_stacktop == NULL) + if (f == NULL || f->f_stacktop == NULL || f->f_iblock <= 0) return 0; /* no frame or empty blockstack == no finalization */ /* Any block type besides a loop requires cleanup. */ - for (i = 0; i < f->f_iblock; i++) + i = f->f_iblock; + while (--i >= 0) { if (f->f_blockstack[i].b_type != SETUP_LOOP) return 1; + } /* No blocks except loops, it's safe to skip finalization. */ return 0; diff -r 95c34bce986c -r 900df5732f93 Objects/stringlib/string_format.h --- a/Objects/stringlib/string_format.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/stringlib/string_format.h Mon Jul 25 09:47:18 2011 -0400 @@ -511,16 +511,6 @@ Py_DECREF(key); } else { - /* If args is NULL, we have a format string with a positional field - with only kwargs to retrieve it from. This can only happen when - used with format_map(), where positional arguments are not - allowed. */ - if (args == NULL) { - PyErr_SetString(PyExc_ValueError, "Format string contains " - "positional fields"); - goto error; - } - /* look up in args */ obj = PySequence_GetItem(args, index); if (obj == NULL) diff -r 95c34bce986c -r 900df5732f93 Objects/typeobject.c --- a/Objects/typeobject.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/typeobject.c Mon Jul 25 09:47:18 2011 -0400 @@ -967,8 +967,6 @@ assert(basedealloc); basedealloc(self); - PyType_Modified(type); - /* Can't reference self beyond this point */ Py_DECREF(type); @@ -2968,7 +2966,7 @@ unaryfunc f; f = Py_TYPE(self)->tp_repr; - if (f == NULL || f == object_str) + if (f == NULL) f = object_repr; return f(self); } diff -r 95c34bce986c -r 900df5732f93 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Objects/unicodeobject.c Mon Jul 25 09:47:18 2011 -0400 @@ -1506,7 +1506,7 @@ (strcmp(lower, "latin1") == 0) || (strcmp(lower, "iso-8859-1") == 0)) return PyUnicode_DecodeLatin1(s, size, errors); -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) else if (strcmp(lower, "mbcs") == 0) return PyUnicode_DecodeMBCS(s, size, errors); #endif @@ -1644,7 +1644,7 @@ PyObject * PyUnicode_EncodeFSDefault(PyObject *unicode) { -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode), NULL); @@ -1746,7 +1746,7 @@ return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode), errors); -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) else if (strcmp(lower, "mbcs") == 0) return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode), PyUnicode_GET_SIZE(unicode), @@ -1848,7 +1848,7 @@ PyObject* PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size) { -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) return PyUnicode_DecodeMBCS(s, size, NULL); #elif defined(__APPLE__) return PyUnicode_DecodeUTF8(s, size, "surrogateescape"); @@ -4942,7 +4942,7 @@ NULL); } -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) /* --- MBCS codecs for Windows -------------------------------------------- */ @@ -5229,7 +5229,7 @@ #undef NEED_RETRY -#endif /* HAVE_MBCS */ +#endif /* MS_WINDOWS */ /* --- Character Mapping Codec -------------------------------------------- */ @@ -9761,6 +9761,8 @@ case 'o': case 'x': case 'X': + if (c == 'i') + c = 'd'; isnumok = 0; if (PyNumber_Check(v)) { PyObject *iobj=NULL; @@ -9775,7 +9777,7 @@ if (iobj!=NULL) { if (PyLong_Check(iobj)) { isnumok = 1; - temp = formatlong(iobj, flags, prec, (c == 'i'? 'd': c)); + temp = formatlong(iobj, flags, prec, c); Py_DECREF(iobj); if (!temp) goto onError; diff -r 95c34bce986c -r 900df5732f93 PC/pyconfig.h --- a/PC/pyconfig.h Tue Jul 26 09:37:46 2011 +0300 +++ b/PC/pyconfig.h Mon Jul 25 09:47:18 2011 -0400 @@ -711,6 +711,9 @@ /* Define if you have the header file. */ /* #define HAVE_SYS_UTSNAME_H 1 */ +/* Define if you have the header file. */ +/* #undef HAVE_THREAD_H */ + /* Define if you have the header file. */ /* #define HAVE_UNISTD_H 1 */ diff -r 95c34bce986c -r 900df5732f93 Parser/Python.asdl --- a/Parser/Python.asdl Tue Jul 26 09:37:46 2011 +0300 +++ b/Parser/Python.asdl Mon Jul 25 09:47:18 2011 -0400 @@ -99,6 +99,7 @@ comprehension = (expr target, expr iter, expr* ifs) + -- not sure what to call the first argument for raise and except excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body) attributes (int lineno, int col_offset) diff -r 95c34bce986c -r 900df5732f93 Parser/asdl_c.py --- a/Parser/asdl_c.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Parser/asdl_c.py Mon Jul 25 09:47:18 2011 -0400 @@ -795,23 +795,8 @@ return 0; } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyUnicode_CheckExact(obj) && obj != Py_None) { - PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); - return 1; - } - return obj2ast_object(obj, out, arena); -} - -static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyUnicode_CheckExact(obj)) { - PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); - return 1; - } - return obj2ast_object(obj, out, arena); -} +#define obj2ast_identifier obj2ast_object +#define obj2ast_string obj2ast_object static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { @@ -915,6 +900,10 @@ self.emit('if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL;', 1) self.emit('if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)', 1) self.emit("return NULL;", 2) + # Value of version: "$Revision$" + self.emit('if (PyModule_AddStringConstant(m, "__version__", "%s") < 0)' + % (mod.version,), 1) + self.emit("return NULL;", 2) for dfn in mod.dfns: self.visit(dfn) self.emit("return m;", 1) @@ -1135,6 +1124,29 @@ common_msg = "/* File automatically generated by %s. */\n\n" +c_file_msg = """ +/* + __version__ %s. + + This module must be committed separately after each AST grammar change; + The __version__ number is set to the revision number of the commit + containing the grammar change. +*/ + +""" + + +def get_file_revision(f): + """Fish out the last change to a file in hg.""" + args = ["hg", "log", "--template", "{node|short}", "--limit", "1", f] + p = subprocess.Popen(args, stdout=subprocess.PIPE) + out = p.communicate()[0] + if p.returncode: + print >> sys.stderr, "error return code from hg" + sys.exit(1) + return out + + def main(srcfile): argv0 = sys.argv[0] components = argv0.split(os.sep) @@ -1143,6 +1155,7 @@ mod = asdl.parse(srcfile) if not asdl.check(mod): sys.exit(1) + mod.version = get_file_revision(srcfile) if INC_DIR: p = "%s/%s-ast.h" % (INC_DIR, mod.name) f = open(p, "w") @@ -1162,6 +1175,7 @@ p = os.path.join(SRC_DIR, str(mod.name) + "-ast.c") f = open(p, "w") f.write(auto_gen_msg) + f.write(c_file_msg % (mod.version,)) f.write('#include "Python.h"\n') f.write('#include "%s-ast.h"\n' % mod.name) f.write('\n') diff -r 95c34bce986c -r 900df5732f93 Python/Python-ast.c --- a/Python/Python-ast.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/Python-ast.c Mon Jul 25 09:47:18 2011 -0400 @@ -1,5 +1,14 @@ /* File automatically generated by Parser/asdl_c.py. */ + +/* + __version__ e0e663132363. + + This module must be committed separately after each AST grammar change; + The __version__ number is set to the revision number of the commit + containing the grammar change. +*/ + #include "Python.h" #include "Python-ast.h" @@ -592,23 +601,8 @@ return 0; } -static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyUnicode_CheckExact(obj) && obj != Py_None) { - PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); - return 1; - } - return obj2ast_object(obj, out, arena); -} - -static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) -{ - if (!PyUnicode_CheckExact(obj)) { - PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); - return 1; - } - return obj2ast_object(obj, out, arena); -} +#define obj2ast_identifier obj2ast_object +#define obj2ast_string obj2ast_object static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { @@ -6756,6 +6750,8 @@ NULL; if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0) return NULL; + if (PyModule_AddStringConstant(m, "__version__", "e0e663132363") < 0) + return NULL; if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) diff -r 95c34bce986c -r 900df5732f93 Python/_warnings.c --- a/Python/_warnings.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/_warnings.c Mon Jul 25 09:47:18 2011 -0400 @@ -409,10 +409,10 @@ else { PyObject *res; - if (!PyCallable_Check(show_fxn)) { + if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) { PyErr_SetString(PyExc_TypeError, "warnings.showwarning() must be set to a " - "callable"); + "function or method"); Py_DECREF(show_fxn); goto cleanup; } @@ -496,7 +496,7 @@ /* Setup filename. */ *filename = PyDict_GetItemString(globals, "__file__"); - if (*filename != NULL && PyUnicode_Check(*filename)) { + if (*filename != NULL) { Py_ssize_t len = PyUnicode_GetSize(*filename); Py_UNICODE *unicode = PyUnicode_AS_UNICODE(*filename); @@ -517,7 +517,6 @@ } else { const char *module_str = _PyUnicode_AsString(*module); - *filename = NULL; if (module_str == NULL) goto handle_error; if (strcmp(module_str, "__main__") == 0) { diff -r 95c34bce986c -r 900df5732f93 Python/bltinmodule.c --- a/Python/bltinmodule.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/bltinmodule.c Mon Jul 25 09:47:18 2011 -0400 @@ -18,15 +18,18 @@ Don't forget to modify PyUnicode_DecodeFSDefault() if you touch any of the values for Py_FileSystemDefaultEncoding! */ -#ifdef HAVE_MBCS +#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) const char *Py_FileSystemDefaultEncoding = "mbcs"; int Py_HasFileSystemDefaultEncoding = 1; #elif defined(__APPLE__) const char *Py_FileSystemDefaultEncoding = "utf-8"; int Py_HasFileSystemDefaultEncoding = 1; -#else +#elif defined(HAVE_LANGINFO_H) && defined(CODESET) const char *Py_FileSystemDefaultEncoding = NULL; /* set by initfsencoding() */ int Py_HasFileSystemDefaultEncoding = 0; +#else +const char *Py_FileSystemDefaultEncoding = "utf-8"; +int Py_HasFileSystemDefaultEncoding = 1; #endif static PyObject * diff -r 95c34bce986c -r 900df5732f93 Python/ceval.c --- a/Python/ceval.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/ceval.c Mon Jul 25 09:47:18 2011 -0400 @@ -491,6 +491,7 @@ } pendingcalls[NPENDINGCALLS]; static int pendingfirst = 0; static int pendinglast = 0; +static char pendingbusy = 0; int Py_AddPendingCall(int (*func)(void *), void *arg) @@ -537,7 +538,6 @@ int Py_MakePendingCalls(void) { - static int busy = 0; int i; int r = 0; @@ -552,9 +552,9 @@ if (main_thread && PyThread_get_thread_ident() != main_thread) return 0; /* don't perform recursive pending calls */ - if (busy) + if (pendingbusy) return 0; - busy = 1; + pendingbusy = 1; /* perform a bounded number of calls, in case of recursion */ for (i=0; iexc_type); \ + Py_XINCREF(tstate->exc_value); \ + Py_XINCREF(tstate->exc_traceback); \ + type = f->f_exc_type; \ + value = f->f_exc_value; \ + traceback = f->f_exc_traceback; \ + f->f_exc_type = tstate->exc_type; \ + f->f_exc_value = tstate->exc_value; \ + f->f_exc_traceback = tstate->exc_traceback; \ + Py_XDECREF(type); \ + Py_XDECREF(value); \ + Py_XDECREF(traceback); \ + } + +#define SWAP_EXC_STATE() \ + { \ + PyObject *tmp; \ + tmp = tstate->exc_type; \ + tstate->exc_type = f->f_exc_type; \ + f->f_exc_type = tmp; \ + tmp = tstate->exc_value; \ + tstate->exc_value = f->f_exc_value; \ + f->f_exc_value = tmp; \ + tmp = tstate->exc_traceback; \ + tstate->exc_traceback = f->f_exc_traceback; \ + f->f_exc_traceback = tmp; \ + } + /* Start of code */ + if (f == NULL) + return NULL; + /* push frame */ if (Py_EnterRecursiveCall("")) return NULL; @@ -1188,10 +1219,11 @@ /* We were in an except handler when we left, restore the exception state which was put aside (see YIELD_VALUE). */ - swap_exc_state(tstate, f); + SWAP_EXC_STATE(); } - else - save_exc_state(tstate, f); + else { + SAVE_EXC_STATE(); + } } #ifdef LLTRACE @@ -1347,6 +1379,8 @@ x to NULL, err to nonzero, or why to anything but WHY_NOT, and that no operation that succeeds does this! */ + /* case STOP_CODE: this is an error! */ + TARGET(NOP) FAST_DISPATCH(); @@ -1831,6 +1865,10 @@ retval = POP(); f->f_stacktop = stack_pointer; why = WHY_YIELD; + /* Put aside the current exception state and restore + that of the calling frame. This only serves when + "yield" is used inside an except handler. */ + SWAP_EXC_STATE(); goto fast_yield; TARGET(POP_EXCEPT) @@ -2967,26 +3005,6 @@ retval = NULL; fast_yield: - if (co->co_flags & CO_GENERATOR && (why == WHY_YIELD || why == WHY_RETURN)) { - /* The purpose of this block is to put aside the generator's exception - state and restore that of the calling frame. If the current - exception state is from the caller, we clear the exception values - on the generator frame, so they are not swapped back in latter. The - origin of the current exception state is determined by checking for - except handler blocks, which we must be in iff a new exception - state came into existence in this frame. (An uncaught exception - would have why == WHY_EXCEPTION, and we wouldn't be here). */ - int i; - for (i = 0; i < f->f_iblock; i++) - if (f->f_blockstack[i].b_type == EXCEPT_HANDLER) - break; - if (i == f->f_iblock) - /* We did not create this exception. */ - restore_and_clear_exc_state(tstate, f); - else - swap_exc_state(tstate, f); - } - if (tstate->use_tracing) { if (tstate->c_tracefunc) { if (why == WHY_RETURN || why == WHY_YIELD) { @@ -3028,118 +3046,28 @@ } static void -format_missing(const char *kind, PyCodeObject *co, PyObject *names) -{ - int err; - Py_ssize_t len = PyList_GET_SIZE(names); - PyObject *name_str, *comma, *tail, *tmp; - - assert(PyList_CheckExact(names)); - assert(len >= 1); - /* Deal with the joys of natural language. */ - switch (len) { - case 1: - name_str = PyList_GET_ITEM(names, 0); - Py_INCREF(name_str); - break; - case 2: - name_str = PyUnicode_FromFormat("%U and %U", - PyList_GET_ITEM(names, len - 2), - PyList_GET_ITEM(names, len - 1)); - break; - default: - tail = PyUnicode_FromFormat(", %U, and %U", - PyList_GET_ITEM(names, len - 2), - PyList_GET_ITEM(names, len - 1)); - /* Chop off the last two objects in the list. This shouldn't actually - fail, but we can't be too careful. */ - err = PyList_SetSlice(names, len - 2, len, NULL); - if (err == -1) { - Py_DECREF(tail); - return; - } - /* Stitch everything up into a nice comma-separated list. */ - comma = PyUnicode_FromString(", "); - if (comma == NULL) { - Py_DECREF(tail); - return; - } - tmp = PyUnicode_Join(comma, names); - Py_DECREF(comma); - if (tmp == NULL) { - Py_DECREF(tail); - return; - } - name_str = PyUnicode_Concat(tmp, tail); - Py_DECREF(tmp); - Py_DECREF(tail); - break; - } - if (name_str == NULL) - return; - PyErr_Format(PyExc_TypeError, - "%U() missing %i required %s argument%s: %U", - co->co_name, - len, - kind, - len == 1 ? "" : "s", - name_str); - Py_DECREF(name_str); -} - -static void -missing_arguments(PyCodeObject *co, int missing, int defcount, - PyObject **fastlocals) -{ - int i, j = 0; - int start, end; - int positional = defcount != -1; - const char *kind = positional ? "positional" : "keyword-only"; - PyObject *missing_names; - - /* Compute the names of the arguments that are missing. */ - missing_names = PyList_New(missing); - if (missing_names == NULL) - return; - if (positional) { - start = 0; - end = co->co_argcount - defcount; - } - else { - start = co->co_argcount; - end = start + co->co_kwonlyargcount; - } - for (i = start; i < end; i++) { - if (GETLOCAL(i) == NULL) { - PyObject *raw = PyTuple_GET_ITEM(co->co_varnames, i); - PyObject *name = PyObject_Repr(raw); - if (name == NULL) { - Py_DECREF(missing_names); - return; - } - PyList_SET_ITEM(missing_names, j++, name); - } - } - assert(j == missing); - format_missing(kind, co, missing_names); - Py_DECREF(missing_names); -} - -static void -too_many_positional(PyCodeObject *co, int given, int defcount, PyObject **fastlocals) +positional_argument_error(PyCodeObject *co, int given, int defcount, PyObject **fastlocals) { int plural; int kwonly_given = 0; + int atleast = co->co_argcount - defcount; int i; PyObject *sig, *kwonly_sig; - assert((co->co_flags & CO_VARARGS) == 0); - /* Count missing keyword-only args. */ + if (given == -1) { + given = 0; + for (i = 0; i < co->co_argcount; i++) + if (GETLOCAL(i)) + given++; + } for (i = co->co_argcount; i < co->co_argcount + co->co_kwonlyargcount; i++) - if (GETLOCAL(i) != NULL) + if (GETLOCAL(i)) kwonly_given++; - if (defcount) { - int atleast = co->co_argcount - defcount; + if (co->co_flags & CO_VARARGS) { + plural = atleast != 1; + sig = PyUnicode_FromFormat("at least %d", atleast); + } + else if (defcount) { plural = 1; sig = PyUnicode_FromFormat("from %d to %d", atleast, co->co_argcount); } @@ -3161,7 +3089,6 @@ else { /* This will not fail. */ kwonly_sig = PyUnicode_FromString(""); - assert(kwonly_sig != NULL); } PyErr_Format(PyExc_TypeError, "%U() takes %U positional argument%s but %d%U %s given", @@ -3290,18 +3217,16 @@ SETLOCAL(j, value); } if (argcount > co->co_argcount && !(co->co_flags & CO_VARARGS)) { - too_many_positional(co, argcount, defcount, fastlocals); + positional_argument_error(co, argcount, defcount, fastlocals); goto fail; } if (argcount < co->co_argcount) { int m = co->co_argcount - defcount; - int missing = 0; - for (i = argcount; i < m; i++) - if (GETLOCAL(i) == NULL) - missing++; - if (missing) { - missing_arguments(co, missing, defcount, fastlocals); - goto fail; + for (i = argcount; i < m; i++) { + if (GETLOCAL(i) == NULL) { + positional_argument_error(co, -1, defcount, fastlocals); + goto fail; + } } if (n > m) i = n - m; @@ -3316,7 +3241,6 @@ } } if (co->co_kwonlyargcount > 0) { - int missing = 0; for (i = co->co_argcount; i < total_args; i++) { PyObject *name; if (GETLOCAL(i) != NULL) @@ -3330,33 +3254,64 @@ continue; } } - missing++; - } - if (missing) { - missing_arguments(co, missing, -1, fastlocals); + PyErr_Format(PyExc_TypeError, + "%U() requires keyword-only argument '%S'", + co->co_name, name); goto fail; } } /* Allocate and initialize storage for cell vars, and copy free - vars into frame. */ - for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { + vars into frame. This isn't too efficient right now. */ + if (PyTuple_GET_SIZE(co->co_cellvars)) { + int i, j, nargs, found; + Py_UNICODE *cellname, *argname; PyObject *c; - int arg; - /* Possibly account for the cell variable being an argument. */ - if (co->co_cell2arg != NULL && - (arg = co->co_cell2arg[i]) != CO_CELL_NOT_AN_ARG) - c = PyCell_New(GETLOCAL(arg)); - else - c = PyCell_New(NULL); - if (c == NULL) - goto fail; - SETLOCAL(co->co_nlocals + i, c); + + nargs = total_args; + if (co->co_flags & CO_VARARGS) + nargs++; + if (co->co_flags & CO_VARKEYWORDS) + nargs++; + + /* Initialize each cell var, taking into account + cell vars that are initialized from arguments. + + Should arrange for the compiler to put cellvars + that are arguments at the beginning of the cellvars + list so that we can march over it more efficiently? + */ + for (i = 0; i < PyTuple_GET_SIZE(co->co_cellvars); ++i) { + cellname = PyUnicode_AS_UNICODE( + PyTuple_GET_ITEM(co->co_cellvars, i)); + found = 0; + for (j = 0; j < nargs; j++) { + argname = PyUnicode_AS_UNICODE( + PyTuple_GET_ITEM(co->co_varnames, j)); + if (Py_UNICODE_strcmp(cellname, argname) == 0) { + c = PyCell_New(GETLOCAL(j)); + if (c == NULL) + goto fail; + GETLOCAL(co->co_nlocals + i) = c; + found = 1; + break; + } + } + if (found == 0) { + c = PyCell_New(NULL); + if (c == NULL) + goto fail; + SETLOCAL(co->co_nlocals + i, c); + } + } } - for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) { - PyObject *o = PyTuple_GET_ITEM(closure, i); - Py_INCREF(o); - freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o; + if (PyTuple_GET_SIZE(co->co_freevars)) { + int i; + for (i = 0; i < PyTuple_GET_SIZE(co->co_freevars); ++i) { + PyObject *o = PyTuple_GET_ITEM(closure, i); + Py_INCREF(o); + freevars[PyTuple_GET_SIZE(co->co_cellvars) + i] = o; + } } if (co->co_flags & CO_GENERATOR) { @@ -3402,60 +3357,6 @@ } -/* These 3 functions deal with the exception state of generators. */ - -static void -save_exc_state(PyThreadState *tstate, PyFrameObject *f) -{ - PyObject *type, *value, *traceback; - Py_XINCREF(tstate->exc_type); - Py_XINCREF(tstate->exc_value); - Py_XINCREF(tstate->exc_traceback); - type = f->f_exc_type; - value = f->f_exc_value; - traceback = f->f_exc_traceback; - f->f_exc_type = tstate->exc_type; - f->f_exc_value = tstate->exc_value; - f->f_exc_traceback = tstate->exc_traceback; - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); -} - -static void -swap_exc_state(PyThreadState *tstate, PyFrameObject *f) -{ - PyObject *tmp; - tmp = tstate->exc_type; - tstate->exc_type = f->f_exc_type; - f->f_exc_type = tmp; - tmp = tstate->exc_value; - tstate->exc_value = f->f_exc_value; - f->f_exc_value = tmp; - tmp = tstate->exc_traceback; - tstate->exc_traceback = f->f_exc_traceback; - f->f_exc_traceback = tmp; -} - -static void -restore_and_clear_exc_state(PyThreadState *tstate, PyFrameObject *f) -{ - PyObject *type, *value, *tb; - type = tstate->exc_type; - value = tstate->exc_value; - tb = tstate->exc_traceback; - tstate->exc_type = f->f_exc_type; - tstate->exc_value = f->f_exc_value; - tstate->exc_traceback = f->f_exc_traceback; - f->f_exc_type = NULL; - f->f_exc_value = NULL; - f->f_exc_traceback = NULL; - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(tb); -} - - /* Logic for the raise statement (too complicated for inlining). This *consumes* a reference count to each of its arguments. */ static enum why_code @@ -3492,13 +3393,6 @@ value = PyObject_CallObject(exc, NULL); if (value == NULL) goto raise_error; - if (!PyExceptionInstance_Check(value)) { - PyErr_Format(PyExc_TypeError, - "calling %R should have returned an instance of " - "BaseException, not %R", - type, Py_TYPE(value)); - goto raise_error; - } } else if (PyExceptionInstance_Check(exc)) { value = exc; diff -r 95c34bce986c -r 900df5732f93 Python/codecs.c --- a/Python/codecs.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/codecs.c Mon Jul 25 09:47:18 2011 -0400 @@ -69,7 +69,7 @@ if (ch == ' ') ch = '-'; else - ch = Py_TOLOWER(Py_CHARMASK(ch)); + ch = tolower(Py_CHARMASK(ch)); p[i] = ch; } p[i] = '\0'; diff -r 95c34bce986c -r 900df5732f93 Python/makeopcodetargets.py --- a/Python/makeopcodetargets.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/makeopcodetargets.py Mon Jul 25 09:47:18 2011 -0400 @@ -23,6 +23,9 @@ opcode = find_module("opcode") targets = ['_unknown_opcode'] * 256 for opname, op in opcode.opmap.items(): + if opname == "STOP_CODE": + # XXX opcode not implemented + continue targets[op] = "TARGET_%s" % opname f.write("static void *opcode_targets[256] = {\n") f.write(",\n".join([" &&%s" % s for s in targets])) diff -r 95c34bce986c -r 900df5732f93 Python/marshal.c --- a/Python/marshal.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/marshal.c Mon Jul 25 09:47:18 2011 -0400 @@ -57,7 +57,6 @@ int error; /* see WFERR_* values */ int depth; /* If fp == NULL, the following are valid: */ - PyObject * readable; /* Stream-like object being read from */ PyObject *str; PyObject *current_filename; char *ptr; @@ -464,75 +463,27 @@ #define rs_byte(p) (((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr++ : EOF) +#define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) + static int r_string(char *s, int n, RFILE *p) { - char * ptr; - int read, left; - - if (!p->readable) { - if (p->fp != NULL) - /* The result fits into int because it must be <=n. */ - read = (int) fread(s, 1, n, p->fp); - else { - left = (int)(p->end - p->ptr); - read = (left < n) ? left : n; - memcpy(s, p->ptr, read); - p->ptr += read; - } - } - else { - PyObject *data = PyObject_CallMethod(p->readable, "read", "i", n); - read = 0; - if (data != NULL) { - if (!PyBytes_Check(data)) { - PyErr_Format(PyExc_TypeError, - "f.read() returned not bytes but %.100s", - data->ob_type->tp_name); - } - else { - read = PyBytes_GET_SIZE(data); - if (read > 0) { - ptr = PyBytes_AS_STRING(data); - memcpy(s, ptr, read); - } - } - Py_DECREF(data); - } - } - if (!PyErr_Occurred() && (read < n)) { - PyErr_SetString(PyExc_EOFError, "EOF read where not expected"); - } - return read; -} - - -static int -r_byte(RFILE *p) -{ - int c = EOF; - unsigned char ch; - int n; - - if (!p->readable) - c = p->fp ? getc(p->fp) : rs_byte(p); - else { - n = r_string((char *) &ch, 1, p); - if (n > 0) - c = ch; - } - return c; + if (p->fp != NULL) + /* The result fits into int because it must be <=n. */ + return (int)fread(s, 1, n, p->fp); + if (p->end - p->ptr < n) + n = (int)(p->end - p->ptr); + memcpy(s, p->ptr, n); + p->ptr += n; + return n; } static int r_short(RFILE *p) { register short x; - unsigned char buffer[2]; - - r_string((char *) buffer, 2, p); - x = buffer[0]; - x |= buffer[1] << 8; + x = r_byte(p); + x |= r_byte(p) << 8; /* Sign-extension, in case short greater than 16 bits */ x |= -(x & 0x8000); return x; @@ -542,13 +493,19 @@ r_long(RFILE *p) { register long x; - unsigned char buffer[4]; - - r_string((char *) buffer, 4, p); - x = buffer[0]; - x |= (long)buffer[1] << 8; - x |= (long)buffer[2] << 16; - x |= (long)buffer[3] << 24; + register FILE *fp = p->fp; + if (fp) { + x = getc(fp); + x |= (long)getc(fp) << 8; + x |= (long)getc(fp) << 16; + x |= (long)getc(fp) << 24; + } + else { + x = rs_byte(p); + x |= (long)rs_byte(p) << 8; + x |= (long)rs_byte(p) << 16; + x |= (long)rs_byte(p) << 24; + } #if SIZEOF_LONG > 4 /* Sign extension for 64-bit machines */ x |= -(x & 0x80000000L); @@ -566,30 +523,25 @@ static PyObject * r_long64(RFILE *p) { - PyObject * result = NULL; long lo4 = r_long(p); long hi4 = r_long(p); - - if (!PyErr_Occurred()) { #if SIZEOF_LONG > 4 - long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL); - result = PyLong_FromLong(x); + long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL); + return PyLong_FromLong(x); #else - unsigned char buf[8]; - int one = 1; - int is_little_endian = (int)*(char*)&one; - if (is_little_endian) { - memcpy(buf, &lo4, 4); - memcpy(buf+4, &hi4, 4); - } - else { - memcpy(buf, &hi4, 4); - memcpy(buf+4, &lo4, 4); - } - result = _PyLong_FromByteArray(buf, 8, is_little_endian, 1); + unsigned char buf[8]; + int one = 1; + int is_little_endian = (int)*(char*)&one; + if (is_little_endian) { + memcpy(buf, &lo4, 4); + memcpy(buf+4, &hi4, 4); + } + else { + memcpy(buf, &hi4, 4); + memcpy(buf+4, &lo4, 4); + } + return _PyLong_FromByteArray(buf, 8, is_little_endian, 1); #endif - } - return result; } static PyObject * @@ -601,8 +553,6 @@ digit d; n = r_long(p); - if (PyErr_Occurred()) - return NULL; if (n == 0) return (PyObject *)_PyLong_New(0); if (n < -INT_MAX || n > INT_MAX) { @@ -622,8 +572,6 @@ d = 0; for (j=0; j < PyLong_MARSHAL_RATIO; j++) { md = r_short(p); - if (PyErr_Occurred()) - break; if (md < 0 || md > PyLong_MARSHAL_BASE) goto bad_digit; d += (digit)md << j*PyLong_MARSHAL_SHIFT; @@ -633,8 +581,6 @@ d = 0; for (j=0; j < shorts_in_top_digit; j++) { md = r_short(p); - if (PyErr_Occurred()) - break; if (md < 0 || md > PyLong_MARSHAL_BASE) goto bad_digit; /* topmost marshal digit should be nonzero */ @@ -646,10 +592,6 @@ } d += (digit)md << j*PyLong_MARSHAL_SHIFT; } - if (PyErr_Occurred()) { - Py_DECREF(ob); - return NULL; - } /* top digit should be nonzero, else the resulting PyLong won't be normalized */ ob->ob_digit[size-1] = d; @@ -718,8 +660,7 @@ break; case TYPE_INT: - n = r_long(p); - retval = PyErr_Occurred() ? NULL : PyLong_FromLong(n); + retval = PyLong_FromLong(r_long(p)); break; case TYPE_INT64: @@ -829,10 +770,6 @@ case TYPE_STRING: n = r_long(p); - if (PyErr_Occurred()) { - retval = NULL; - break; - } if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)"); retval = NULL; @@ -858,10 +795,6 @@ char *buffer; n = r_long(p); - if (PyErr_Occurred()) { - retval = NULL; - break; - } if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)"); retval = NULL; @@ -887,10 +820,6 @@ case TYPE_TUPLE: n = r_long(p); - if (PyErr_Occurred()) { - retval = NULL; - break; - } if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)"); retval = NULL; @@ -918,10 +847,6 @@ case TYPE_LIST: n = r_long(p); - if (PyErr_Occurred()) { - retval = NULL; - break; - } if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)"); retval = NULL; @@ -974,10 +899,6 @@ case TYPE_SET: case TYPE_FROZENSET: n = r_long(p); - if (PyErr_Occurred()) { - retval = NULL; - break; - } if (n < 0 || n > INT_MAX) { PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)"); retval = NULL; @@ -1031,20 +952,10 @@ /* XXX ignore long->int overflows for now */ argcount = (int)r_long(p); - if (PyErr_Occurred()) - goto code_error; kwonlyargcount = (int)r_long(p); - if (PyErr_Occurred()) - goto code_error; nlocals = (int)r_long(p); - if (PyErr_Occurred()) - goto code_error; stacksize = (int)r_long(p); - if (PyErr_Occurred()) - goto code_error; flags = (int)r_long(p); - if (PyErr_Occurred()) - goto code_error; code = r_object(p); if (code == NULL) goto code_error; @@ -1138,7 +1049,6 @@ { RFILE rf; assert(fp); - rf.readable = NULL; rf.fp = fp; rf.current_filename = NULL; rf.end = rf.ptr = NULL; @@ -1150,7 +1060,6 @@ { RFILE rf; rf.fp = fp; - rf.readable = NULL; rf.current_filename = NULL; rf.ptr = rf.end = NULL; return r_long(&rf); @@ -1212,7 +1121,6 @@ RFILE rf; PyObject *result; rf.fp = fp; - rf.readable = NULL; rf.current_filename = NULL; rf.depth = 0; rf.ptr = rf.end = NULL; @@ -1226,7 +1134,6 @@ RFILE rf; PyObject *result; rf.fp = NULL; - rf.readable = NULL; rf.current_filename = NULL; rf.ptr = str; rf.end = str + len; @@ -1242,7 +1149,6 @@ PyObject *res = NULL; wf.fp = NULL; - wf.readable = NULL; wf.str = PyBytes_FromStringAndSize((char *)NULL, 50); if (wf.str == NULL) return NULL; @@ -1318,30 +1224,32 @@ static PyObject * marshal_load(PyObject *self, PyObject *f) { + /* XXX Quick hack -- need to do this differently */ PyObject *data, *result; RFILE rf; - - /* - * Make a call to the read method, but read zero bytes. - * This is to ensure that the object passed in at least - * has a read method which returns bytes. - */ - data = PyObject_CallMethod(f, "read", "i", 0); + data = PyObject_CallMethod(f, "read", ""); if (data == NULL) return NULL; - if (!PyBytes_Check(data)) { - PyErr_Format(PyExc_TypeError, - "f.read() returned not bytes but %.100s", - data->ob_type->tp_name); - result = NULL; + rf.fp = NULL; + rf.current_filename = NULL; + if (PyBytes_Check(data)) { + rf.ptr = PyBytes_AS_STRING(data); + rf.end = rf.ptr + PyBytes_GET_SIZE(data); + } + else if (PyBytes_Check(data)) { + rf.ptr = PyBytes_AS_STRING(data); + rf.end = rf.ptr + PyBytes_GET_SIZE(data); } else { - rf.depth = 0; - rf.fp = NULL; - rf.readable = f; - rf.current_filename = NULL; - result = read_object(&rf); + PyErr_Format(PyExc_TypeError, + "f.read() returned neither string " + "nor bytes but %.100s", + data->ob_type->tp_name); + Py_DECREF(data); + return NULL; } + rf.depth = 0; + result = read_object(&rf); Py_DECREF(data); return result; } @@ -1392,7 +1300,6 @@ s = p.buf; n = p.len; rf.fp = NULL; - rf.readable = NULL; rf.current_filename = NULL; rf.ptr = s; rf.end = s + n; diff -r 95c34bce986c -r 900df5732f93 Python/modsupport.c --- a/Python/modsupport.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/modsupport.c Mon Jul 25 09:47:18 2011 -0400 @@ -292,6 +292,11 @@ case 'C': { int i = va_arg(*p_va, int); + if (i < 0 || i > PyUnicode_GetMax()) { + PyErr_SetString(PyExc_OverflowError, + "%c arg not in range(0x110000)"); + return NULL; + } return PyUnicode_FromOrdinal(i); } diff -r 95c34bce986c -r 900df5732f93 Python/pythonrun.c --- a/Python/pythonrun.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/pythonrun.c Mon Jul 25 09:47:18 2011 -0400 @@ -168,25 +168,18 @@ return NULL; } +#if defined(HAVE_LANGINFO_H) && defined(CODESET) static char* -get_locale_encoding(void) +get_codeset(void) { -#ifdef MS_WINDOWS - char codepage[100]; - PyOS_snprintf(codepage, sizeof(codepage), "cp%d", GetACP()); - return get_codec_name(codepage); -#elif defined(HAVE_LANGINFO_H) && defined(CODESET) char* codeset = nl_langinfo(CODESET); if (!codeset || codeset[0] == '\0') { PyErr_SetString(PyExc_ValueError, "CODESET is not set or empty"); return NULL; } return get_codec_name(codeset); -#else - PyErr_SetNone(PyExc_NotImplementedError); - return NULL; +} #endif -} void Py_InitializeEx(int install_sigs) @@ -753,17 +746,24 @@ initfsencoding(PyInterpreterState *interp) { PyObject *codec; +#if defined(HAVE_LANGINFO_H) && defined(CODESET) + char *codeset = NULL; - if (Py_FileSystemDefaultEncoding == NULL) - { - Py_FileSystemDefaultEncoding = get_locale_encoding(); - if (Py_FileSystemDefaultEncoding == NULL) + if (Py_FileSystemDefaultEncoding == NULL) { + /* On Unix, set the file system encoding according to the + user's preference, if the CODESET names a well-known + Python codec, and Py_FileSystemDefaultEncoding isn't + initialized by other means. */ + codeset = get_codeset(); + if (codeset == NULL) Py_FatalError("Py_Initialize: Unable to get the locale encoding"); + Py_FileSystemDefaultEncoding = codeset; Py_HasFileSystemDefaultEncoding = 0; interp->fscodec_initialized = 1; return 0; } +#endif /* the encoding is mbcs, utf-8 or ascii */ codec = _PyCodec_Lookup(Py_FileSystemDefaultEncoding); diff -r 95c34bce986c -r 900df5732f93 Python/symtable.c --- a/Python/symtable.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/symtable.c Mon Jul 25 09:47:18 2011 -0400 @@ -899,15 +899,18 @@ static int symtable_exit_block(struct symtable *st, void *ast) { - Py_ssize_t size; + Py_ssize_t end; - st->st_cur = NULL; - size = PyList_GET_SIZE(st->st_stack); - if (size) { - if (PyList_SetSlice(st->st_stack, size - 1, size, NULL) < 0) + Py_CLEAR(st->st_cur); + end = PyList_GET_SIZE(st->st_stack) - 1; + if (end >= 0) { + st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, + end); + if (st->st_cur == NULL) return 0; - if (--size) - st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, size - 1); + Py_INCREF(st->st_cur); + if (PySequence_DelItem(st->st_stack, end) < 0) + return 0; } return 1; } @@ -916,23 +919,23 @@ symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block, void *ast, int lineno, int col_offset) { - PySTEntryObject *prev = NULL, *ste; + PySTEntryObject *prev = NULL; - ste = ste_new(st, name, block, ast, lineno, col_offset); - if (ste == NULL) + if (st->st_cur) { + prev = st->st_cur; + if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) { + return 0; + } + Py_DECREF(st->st_cur); + } + st->st_cur = ste_new(st, name, block, ast, lineno, col_offset); + if (st->st_cur == NULL) return 0; - if (PyList_Append(st->st_stack, (PyObject *)ste) < 0) { - Py_DECREF(ste); - return 0; - } - prev = st->st_cur; - /* The entry is owned by the stack. Borrow it for st_cur. */ - Py_DECREF(ste); - st->st_cur = ste; if (block == ModuleBlock) st->st_global = st->st_cur->ste_symbols; if (prev) { - if (PyList_Append(prev->ste_children, (PyObject *)ste) < 0) { + if (PyList_Append(prev->ste_children, + (PyObject *)st->st_cur) < 0) { return 0; } } @@ -1026,6 +1029,12 @@ if (!symtable_visit_ ## TYPE((ST), (V))) \ return 0; +#define VISIT_IN_BLOCK(ST, TYPE, V, S) \ + if (!symtable_visit_ ## TYPE((ST), (V))) { \ + symtable_exit_block((ST), (S)); \ + return 0; \ + } + #define VISIT_SEQ(ST, TYPE, SEQ) { \ int i; \ asdl_seq *seq = (SEQ); /* avoid variable capture */ \ @@ -1036,6 +1045,18 @@ } \ } +#define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \ + int i; \ + asdl_seq *seq = (SEQ); /* avoid variable capture */ \ + for (i = 0; i < asdl_seq_LEN(seq); i++) { \ + TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \ + if (!symtable_visit_ ## TYPE((ST), elt)) { \ + symtable_exit_block((ST), (S)); \ + return 0; \ + } \ + } \ +} + #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \ int i; \ asdl_seq *seq = (SEQ); /* avoid variable capture */ \ @@ -1046,6 +1067,18 @@ } \ } +#define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \ + int i; \ + asdl_seq *seq = (SEQ); /* avoid variable capture */ \ + for (i = (START); i < asdl_seq_LEN(seq); i++) { \ + TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \ + if (!symtable_visit_ ## TYPE((ST), elt)) { \ + symtable_exit_block((ST), (S)); \ + return 0; \ + } \ + } \ +} + #define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \ int i = 0; \ asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \ @@ -1095,8 +1128,8 @@ FunctionBlock, (void *)s, s->lineno, s->col_offset)) return 0; - VISIT(st, arguments, s->v.FunctionDef.args); - VISIT_SEQ(st, stmt, s->v.FunctionDef.body); + VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s); + VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s); if (!symtable_exit_block(st, s)) return 0; break; @@ -1123,7 +1156,7 @@ } tmp = st->st_private; st->st_private = s->v.ClassDef.name; - VISIT_SEQ(st, stmt, s->v.ClassDef.body); + VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s); st->st_private = tmp; if (!symtable_exit_block(st, s)) return 0; @@ -1304,8 +1337,8 @@ FunctionBlock, (void *)e, e->lineno, e->col_offset)) return 0; - VISIT(st, arguments, e->v.Lambda.args); - VISIT(st, expr, e->v.Lambda.body); + VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e); + VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e); if (!symtable_exit_block(st, (void *)e)) return 0; break; @@ -1625,12 +1658,13 @@ symtable_exit_block(st, (void *)e); return 0; } - VISIT(st, expr, outermost->target); - VISIT_SEQ(st, expr, outermost->ifs); - VISIT_SEQ_TAIL(st, comprehension, generators, 1); + VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e); + VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e); + VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension, + generators, 1, (void*)e); if (value) - VISIT(st, expr, value); - VISIT(st, expr, elt); + VISIT_IN_BLOCK(st, expr, value, (void*)e); + VISIT_IN_BLOCK(st, expr, elt, (void*)e); return symtable_exit_block(st, (void *)e); } diff -r 95c34bce986c -r 900df5732f93 Python/thread.c --- a/Python/thread.c Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/thread.c Mon Jul 25 09:47:18 2011 -0400 @@ -26,6 +26,18 @@ #ifndef _POSIX_THREADS +#ifdef __sgi +#define SGI_THREADS +#endif + +#ifdef HAVE_THREAD_H +#define SOLARIS_THREADS +#endif + +#if defined(sun) && !defined(SOLARIS_THREADS) +#define SUN_LWP +#endif + /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then enough of the Posix threads package is implemented to support python threads. @@ -81,11 +93,37 @@ or the size specified by the THREAD_STACK_SIZE macro. */ static size_t _pythread_stacksize = 0; +#ifdef SGI_THREADS +#error SGI Irix threads are now unsupported, and code will be removed in 3.3. +#include "thread_sgi.h" +#endif + +#ifdef SOLARIS_THREADS +#define PYTHREAD_NAME "solaris" +#include "thread_solaris.h" +#endif + +#ifdef SUN_LWP +#error SunOS lightweight processes are now unsupported, and code will be removed in 3.3. +#include "thread_lwp.h" +#endif + +#ifdef HAVE_PTH +#error GNU pth threads are now unsupported, and code will be removed in 3.3. +#include "thread_pth.h" +#undef _POSIX_THREADS +#endif + #ifdef _POSIX_THREADS #define PYTHREAD_NAME "pthread" #include "thread_pthread.h" #endif +#ifdef C_THREADS +#error Mach C Threads are now unsupported, and code will be removed in 3.3. +#include "thread_cthread.h" +#endif + #ifdef NT_THREADS #define PYTHREAD_NAME "nt" #include "thread_nt.h" @@ -96,6 +134,11 @@ #include "thread_os2.h" #endif +#ifdef PLAN9_THREADS +#define PYTHREAD_NAME "plan9" +#include "thread_plan9.h" +#endif + /* #ifdef FOOBAR_THREADS #include "thread_foobar.h" diff -r 95c34bce986c -r 900df5732f93 Python/thread_cthread.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/thread_cthread.h Mon Jul 25 09:47:18 2011 -0400 @@ -0,0 +1,112 @@ + +#ifdef MACH_C_THREADS +#include +#endif + +#ifdef HURD_C_THREADS +#include +#endif + +/* + * Initialization. + */ +static void +PyThread__init_thread(void) +{ +#ifndef HURD_C_THREADS + /* Roland McGrath said this should not be used since this is + done while linking to threads */ + cthread_init(); +#else +/* do nothing */ + ; +#endif +} + +/* + * Thread support. + */ +long +PyThread_start_new_thread(void (*func)(void *), void *arg) +{ + int success = 0; /* init not needed when SOLARIS_THREADS and */ + /* C_THREADS implemented properly */ + + dprintf(("PyThread_start_new_thread called\n")); + if (!initialized) + PyThread_init_thread(); + /* looks like solaris detaches the thread to never rejoin + * so well do it here + */ + cthread_detach(cthread_fork((cthread_fn_t) func, arg)); + return success < 0 ? -1 : 0; +} + +long +PyThread_get_thread_ident(void) +{ + if (!initialized) + PyThread_init_thread(); + return (long) cthread_self(); +} + +void +PyThread_exit_thread(void) +{ + dprintf(("PyThread_exit_thread called\n")); + if (!initialized) + exit(0); + cthread_exit(0); +} + +/* + * Lock support. + */ +PyThread_type_lock +PyThread_allocate_lock(void) +{ + mutex_t lock; + + dprintf(("PyThread_allocate_lock called\n")); + if (!initialized) + PyThread_init_thread(); + + lock = mutex_alloc(); + if (mutex_init(lock)) { + perror("mutex_init"); + free((void *) lock); + lock = 0; + } + dprintf(("PyThread_allocate_lock() -> %p\n", lock)); + return (PyThread_type_lock) lock; +} + +void +PyThread_free_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_free_lock(%p) called\n", lock)); + mutex_free(lock); +} + +int +PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) +{ + int success = FALSE; + + dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); + if (waitflag) { /* blocking */ + mutex_lock((mutex_t)lock); + success = TRUE; + } else { /* non blocking */ + success = mutex_try_lock((mutex_t)lock); + } + dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); + return success; +} + +void +PyThread_release_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_release_lock(%p) called\n", lock)); + mutex_unlock((mutex_t )lock); +} diff -r 95c34bce986c -r 900df5732f93 Python/thread_lwp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/thread_lwp.h Mon Jul 25 09:47:18 2011 -0400 @@ -0,0 +1,113 @@ + +#include +#include +#include + +#define STACKSIZE 1000 /* stacksize for a thread */ +#define NSTACKS 2 /* # stacks to be put in cache initially */ + +struct lock { + int lock_locked; + cv_t lock_condvar; + mon_t lock_monitor; +}; + + +/* + * Initialization. + */ +static void PyThread__init_thread(void) +{ + lwp_setstkcache(STACKSIZE, NSTACKS); +} + +/* + * Thread support. + */ + + +long PyThread_start_new_thread(void (*func)(void *), void *arg) +{ + thread_t tid; + int success; + dprintf(("PyThread_start_new_thread called\n")); + if (!initialized) + PyThread_init_thread(); + success = lwp_create(&tid, func, MINPRIO, 0, lwp_newstk(), 1, arg); + return success < 0 ? -1 : 0; +} + +long PyThread_get_thread_ident(void) +{ + thread_t tid; + if (!initialized) + PyThread_init_thread(); + if (lwp_self(&tid) < 0) + return -1; + return tid.thread_id; +} + +void PyThread_exit_thread(void) +{ + dprintf(("PyThread_exit_thread called\n")); + if (!initialized) + exit(0); + lwp_destroy(SELF); +} + +/* + * Lock support. + */ +PyThread_type_lock PyThread_allocate_lock(void) +{ + struct lock *lock; + extern char *malloc(size_t); + + dprintf(("PyThread_allocate_lock called\n")); + if (!initialized) + PyThread_init_thread(); + + lock = (struct lock *) malloc(sizeof(struct lock)); + lock->lock_locked = 0; + (void) mon_create(&lock->lock_monitor); + (void) cv_create(&lock->lock_condvar, lock->lock_monitor); + dprintf(("PyThread_allocate_lock() -> %p\n", lock)); + return (PyThread_type_lock) lock; +} + +void PyThread_free_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_free_lock(%p) called\n", lock)); + mon_destroy(((struct lock *) lock)->lock_monitor); + free((char *) lock); +} + +int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) +{ + int success; + + dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); + success = 0; + + (void) mon_enter(((struct lock *) lock)->lock_monitor); + if (waitflag) + while (((struct lock *) lock)->lock_locked) + cv_wait(((struct lock *) lock)->lock_condvar); + if (!((struct lock *) lock)->lock_locked) { + success = 1; + ((struct lock *) lock)->lock_locked = 1; + } + cv_broadcast(((struct lock *) lock)->lock_condvar); + mon_exit(((struct lock *) lock)->lock_monitor); + dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); + return success; +} + +void PyThread_release_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_release_lock(%p) called\n", lock)); + (void) mon_enter(((struct lock *) lock)->lock_monitor); + ((struct lock *) lock)->lock_locked = 0; + cv_broadcast(((struct lock *) lock)->lock_condvar); + mon_exit(((struct lock *) lock)->lock_monitor); +} diff -r 95c34bce986c -r 900df5732f93 Python/thread_pthread.h --- a/Python/thread_pthread.h Tue Jul 26 09:37:46 2011 +0300 +++ b/Python/thread_pthread.h Mon Jul 25 09:47:18 2011 -0400 @@ -144,7 +144,7 @@ * Initialization. */ -#if defined(_HAVE_BSDI) +#ifdef _HAVE_BSDI static void _noop(void) { diff -r 95c34bce986c -r 900df5732f93 Python/thread_sgi.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/thread_sgi.h Mon Jul 25 09:47:18 2011 -0400 @@ -0,0 +1,259 @@ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define HDR_SIZE 2680 /* sizeof(ushdr_t) */ +#define MAXPROC 100 /* max # of threads that can be started */ + +static usptr_t *shared_arena; +static ulock_t count_lock; /* protection for some variables */ +static ulock_t wait_lock; /* lock used to wait for other threads */ +static int waiting_for_threads; /* protected by count_lock */ +static int nthreads; /* protected by count_lock */ +static int exit_status; +static int exiting; /* we're already exiting (for maybe_exit) */ +static pid_t my_pid; /* PID of main thread */ +static struct pidlist { + pid_t parent; + pid_t child; +} pidlist[MAXPROC]; /* PIDs of other threads; protected by count_lock */ +static int maxpidindex; /* # of PIDs in pidlist */ +/* + * Initialization. + */ +static void PyThread__init_thread(void) +{ +#ifdef USE_DL + long addr, size; +#endif /* USE_DL */ + + +#ifdef USE_DL + if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0) + perror("usconfig - CONF_INITSIZE (check)"); + if (usconfig(CONF_INITSIZE, size) < 0) + perror("usconfig - CONF_INITSIZE (reset)"); + addr = (long) dl_getrange(size + HDR_SIZE); + dprintf(("trying to use addr %p-%p for shared arena\n", addr, addr+size)); + errno = 0; + if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0) + perror("usconfig - CONF_ATTACHADDR (set)"); +#endif /* USE_DL */ + if (usconfig(CONF_INITUSERS, 16) < 0) + perror("usconfig - CONF_INITUSERS"); + my_pid = getpid(); /* so that we know which is the main thread */ + if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0) + perror("usconfig - CONF_ARENATYPE"); + usconfig(CONF_LOCKTYPE, US_DEBUG); /* XXX */ +#ifdef Py_DEBUG + if (thread_debug & 4) + usconfig(CONF_LOCKTYPE, US_DEBUGPLUS); + else if (thread_debug & 2) + usconfig(CONF_LOCKTYPE, US_DEBUG); +#endif /* Py_DEBUG */ + if ((shared_arena = usinit(tmpnam(0))) == 0) + perror("usinit"); +#ifdef USE_DL + if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */ + perror("usconfig - CONF_ATTACHADDR (reset)"); +#endif /* USE_DL */ + if ((count_lock = usnewlock(shared_arena)) == NULL) + perror("usnewlock (count_lock)"); + (void) usinitlock(count_lock); + if ((wait_lock = usnewlock(shared_arena)) == NULL) + perror("usnewlock (wait_lock)"); + dprintf(("arena start: %p, arena size: %ld\n", shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena))); +} + +/* + * Thread support. + */ + +static void clean_threads(void) +{ + int i, j; + pid_t mypid, pid; + + /* clean up any exited threads */ + mypid = getpid(); + i = 0; + while (i < maxpidindex) { + if (pidlist[i].parent == mypid && (pid = pidlist[i].child) > 0) { + pid = waitpid(pid, 0, WNOHANG); + if (pid > 0) { + /* a thread has exited */ + pidlist[i] = pidlist[--maxpidindex]; + /* remove references to children of dead proc */ + for (j = 0; j < maxpidindex; j++) + if (pidlist[j].parent == pid) + pidlist[j].child = -1; + continue; /* don't increment i */ + } + } + i++; + } + /* clean up the list */ + i = 0; + while (i < maxpidindex) { + if (pidlist[i].child == -1) { + pidlist[i] = pidlist[--maxpidindex]; + continue; /* don't increment i */ + } + i++; + } +} + +long PyThread_start_new_thread(void (*func)(void *), void *arg) +{ +#ifdef USE_DL + long addr, size; + static int local_initialized = 0; +#endif /* USE_DL */ + int success = 0; /* init not needed when SOLARIS_THREADS and */ + /* C_THREADS implemented properly */ + + dprintf(("PyThread_start_new_thread called\n")); + if (!initialized) + PyThread_init_thread(); + switch (ussetlock(count_lock)) { + case 0: return 0; + case -1: perror("ussetlock (count_lock)"); + } + if (maxpidindex >= MAXPROC) + success = -1; + else { +#ifdef USE_DL + if (!local_initialized) { + if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0) + perror("usconfig - CONF_INITSIZE (check)"); + if (usconfig(CONF_INITSIZE, size) < 0) + perror("usconfig - CONF_INITSIZE (reset)"); + addr = (long) dl_getrange(size + HDR_SIZE); + dprintf(("trying to use addr %p-%p for sproc\n", + addr, addr+size)); + errno = 0; + if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && + errno != 0) + perror("usconfig - CONF_ATTACHADDR (set)"); + } +#endif /* USE_DL */ + clean_threads(); + if ((success = sproc(func, PR_SALL, arg)) < 0) + perror("sproc"); +#ifdef USE_DL + if (!local_initialized) { + if (usconfig(CONF_ATTACHADDR, addr) < 0) + /* reset address */ + perror("usconfig - CONF_ATTACHADDR (reset)"); + local_initialized = 1; + } +#endif /* USE_DL */ + if (success >= 0) { + nthreads++; + pidlist[maxpidindex].parent = getpid(); + pidlist[maxpidindex++].child = success; + dprintf(("pidlist[%d] = %d\n", + maxpidindex-1, success)); + } + } + if (usunsetlock(count_lock) < 0) + perror("usunsetlock (count_lock)"); + return success; +} + +long PyThread_get_thread_ident(void) +{ + return getpid(); +} + +void PyThread_exit_thread(void) +{ + dprintf(("PyThread_exit_thread called\n")); + if (!initialized) + exit(0); + if (ussetlock(count_lock) < 0) + perror("ussetlock (count_lock)"); + nthreads--; + if (getpid() == my_pid) { + /* main thread; wait for other threads to exit */ + exiting = 1; + waiting_for_threads = 1; + if (ussetlock(wait_lock) < 0) + perror("ussetlock (wait_lock)"); + for (;;) { + if (nthreads < 0) { + dprintf(("really exit (%d)\n", exit_status)); + exit(exit_status); + } + if (usunsetlock(count_lock) < 0) + perror("usunsetlock (count_lock)"); + dprintf(("waiting for other threads (%d)\n", nthreads)); + if (ussetlock(wait_lock) < 0) + perror("ussetlock (wait_lock)"); + if (ussetlock(count_lock) < 0) + perror("ussetlock (count_lock)"); + } + } + /* not the main thread */ + if (waiting_for_threads) { + dprintf(("main thread is waiting\n")); + if (usunsetlock(wait_lock) < 0) + perror("usunsetlock (wait_lock)"); + } + if (usunsetlock(count_lock) < 0) + perror("usunsetlock (count_lock)"); + _exit(0); +} + +/* + * Lock support. + */ +PyThread_type_lock PyThread_allocate_lock(void) +{ + ulock_t lock; + + dprintf(("PyThread_allocate_lock called\n")); + if (!initialized) + PyThread_init_thread(); + + if ((lock = usnewlock(shared_arena)) == NULL) + perror("usnewlock"); + (void) usinitlock(lock); + dprintf(("PyThread_allocate_lock() -> %p\n", lock)); + return (PyThread_type_lock) lock; +} + +void PyThread_free_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_free_lock(%p) called\n", lock)); + usfreelock((ulock_t) lock, shared_arena); +} + +int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) +{ + int success; + + dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); + errno = 0; /* clear it just in case */ + if (waitflag) + success = ussetlock((ulock_t) lock); + else + success = uscsetlock((ulock_t) lock, 1); /* Try it once */ + if (success < 0) + perror(waitflag ? "ussetlock" : "uscsetlock"); + dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); + return success; +} + +void PyThread_release_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_release_lock(%p) called\n", lock)); + if (usunsetlock((ulock_t) lock) < 0) + perror("usunsetlock"); +} diff -r 95c34bce986c -r 900df5732f93 Python/thread_solaris.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/thread_solaris.h Mon Jul 25 09:47:18 2011 -0400 @@ -0,0 +1,130 @@ + +#include +#include +#include +#include +#undef _POSIX_THREADS + + +/* + * Initialization. + */ +static void PyThread__init_thread(void) +{ +} + +/* + * Thread support. + */ +struct func_arg { + void (*func)(void *); + void *arg; +}; + +static void * +new_func(void *funcarg) +{ + void (*func)(void *); + void *arg; + + func = ((struct func_arg *) funcarg)->func; + arg = ((struct func_arg *) funcarg)->arg; + free(funcarg); + (*func)(arg); + return 0; +} + + +long +PyThread_start_new_thread(void (*func)(void *), void *arg) +{ + thread_t tid; + struct func_arg *funcarg; + + dprintf(("PyThread_start_new_thread called\n")); + if (!initialized) + PyThread_init_thread(); + funcarg = (struct func_arg *) malloc(sizeof(struct func_arg)); + funcarg->func = func; + funcarg->arg = arg; + if (thr_create(0, 0, new_func, funcarg, + THR_DETACHED | THR_NEW_LWP, &tid)) { + perror("thr_create"); + free((void *) funcarg); + return -1; + } + return tid; +} + +long +PyThread_get_thread_ident(void) +{ + if (!initialized) + PyThread_init_thread(); + return thr_self(); +} + +void +PyThread_exit_thread(void) +{ + dprintf(("PyThread_exit_thread called\n")); + if (!initialized) + exit(0); + thr_exit(0); +} + +/* + * Lock support. + */ +PyThread_type_lock +PyThread_allocate_lock(void) +{ + mutex_t *lock; + + dprintf(("PyThread_allocate_lock called\n")); + if (!initialized) + PyThread_init_thread(); + + lock = (mutex_t *) malloc(sizeof(mutex_t)); + if (mutex_init(lock, USYNC_THREAD, 0)) { + perror("mutex_init"); + free((void *) lock); + lock = 0; + } + dprintf(("PyThread_allocate_lock() -> %p\n", lock)); + return (PyThread_type_lock) lock; +} + +void +PyThread_free_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_free_lock(%p) called\n", lock)); + mutex_destroy((mutex_t *) lock); + free((void *) lock); +} + +int +PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) +{ + int success; + + dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); + if (waitflag) + success = mutex_lock((mutex_t *) lock); + else + success = mutex_trylock((mutex_t *) lock); + if (success < 0) + perror(waitflag ? "mutex_lock" : "mutex_trylock"); + else + success = !success; /* solaris does it the other way round */ + dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); + return success; +} + +void +PyThread_release_lock(PyThread_type_lock lock) +{ + dprintf(("PyThread_release_lock(%p) called\n", lock)); + if (mutex_unlock((mutex_t *) lock)) + perror("mutex_unlock"); +} diff -r 95c34bce986c -r 900df5732f93 Python/thread_wince.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Python/thread_wince.h Mon Jul 25 09:47:18 2011 -0400 @@ -0,0 +1,136 @@ + +/* This code implemented by Mark Hammond (MHammond@skippinet.com.au) */ + +#include +#include +#include + +long PyThread_get_thread_ident(void); + +/* + * Change all headers to pure ANSI as no one will use K&R style on an + * NT + */ + +/* + * Initialization of the C package, should not be needed. + */ +static void PyThread__init_thread(void) +{ +} + +/* + * Thread support. + */ +long PyThread_start_new_thread(void (*func)(void *), void *arg) +{ + long rv; + int success = -1; + + dprintf(("%ld: PyThread_start_new_thread called\n", PyThread_get_thread_ident())); + if (!initialized) + PyThread_init_thread(); + + rv = _beginthread(func, 0, arg); /* use default stack size */ + + if (rv != -1) { + success = 0; + dprintf(("%ld: PyThread_start_new_thread succeeded:\n", PyThread_get_thread_ident())); + } + + return success; +} + +/* + * Return the thread Id instead of an handle. The Id is said to uniquely identify the + * thread in the system + */ +long PyThread_get_thread_ident(void) +{ + if (!initialized) + PyThread_init_thread(); + + return GetCurrentThreadId(); +} + +void PyThread_exit_thread(void) +{ + dprintf(("%ld: PyThread_exit_thread called\n", PyThread_get_thread_ident())); + if (!initialized) + exit(0); + _endthread(); +} + +/* + * Lock support. It has to be implemented using Mutexes, as + * CE doesnt support semaphores. Therefore we use some hacks to + * simulate the non reentrant requirements of Python locks + */ +PyThread_type_lock PyThread_allocate_lock(void) +{ + HANDLE aLock; + + dprintf(("PyThread_allocate_lock called\n")); + if (!initialized) + PyThread_init_thread(); + + aLock = CreateEvent(NULL, /* Security attributes */ + 0, /* Manual-Reset */ + 1, /* Is initially signalled */ + NULL); /* Name of event */ + + dprintf(("%ld: PyThread_allocate_lock() -> %p\n", PyThread_get_thread_ident(), aLock)); + + return (PyThread_type_lock) aLock; +} + +void PyThread_free_lock(PyThread_type_lock aLock) +{ + dprintf(("%ld: PyThread_free_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); + + CloseHandle(aLock); +} + +/* + * Return 1 on success if the lock was acquired + * + * and 0 if the lock was not acquired. This means a 0 is returned + * if the lock has already been acquired by this thread! + */ +int PyThread_acquire_lock(PyThread_type_lock aLock, int waitflag) +{ + int success = 1; + DWORD waitResult; + + dprintf(("%ld: PyThread_acquire_lock(%p, %d) called\n", PyThread_get_thread_ident(),aLock, waitflag)); + +#ifndef DEBUG + waitResult = WaitForSingleObject(aLock, (waitflag ? INFINITE : 0)); +#else + /* To aid in debugging, we regularly wake up. This allows us to + break into the debugger */ + while (TRUE) { + waitResult = WaitForSingleObject(aLock, waitflag ? 3000 : 0); + if (waitflag==0 || (waitflag && waitResult == WAIT_OBJECT_0)) + break; + } +#endif + + if (waitResult != WAIT_OBJECT_0) { + success = 0; /* We failed */ + } + + dprintf(("%ld: PyThread_acquire_lock(%p, %d) -> %d\n", PyThread_get_thread_ident(),aLock, waitflag, success)); + + return success; +} + +void PyThread_release_lock(PyThread_type_lock aLock) +{ + dprintf(("%ld: PyThread_release_lock(%p) called\n", PyThread_get_thread_ident(),aLock)); + + if (!SetEvent(aLock)) + dprintf(("%ld: Could not PyThread_release_lock(%p) error: %l\n", PyThread_get_thread_ident(), aLock, GetLastError())); +} + + diff -r 95c34bce986c -r 900df5732f93 Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Tools/gdb/libpython.py Mon Jul 25 09:47:18 2011 -0400 @@ -905,11 +905,7 @@ if self.is_optimized_out(): return '(frame information optimized out)' filename = self.filename() - try: - f = open(os_fsencode(filename), 'r') - except IOError: - return None - with f: + with open(os_fsencode(filename), 'r') as f: all_lines = f.readlines() # Convert from 1-based current_line_num to 0-based list offset: return all_lines[self.current_line_num()-1] @@ -1434,9 +1430,7 @@ if pyop: line = pyop.get_truncated_repr(MAX_OUTPUT_LEN) write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line)) - line = pyop.current_line() - if line is not None: - sys.stdout.write(line) + sys.stdout.write(pyop.current_line()) else: sys.stdout.write('#%i (unable to read python frame information)\n' % self.get_index()) else: @@ -1447,9 +1441,7 @@ pyop = self.get_pyop() if pyop: pyop.print_traceback() - line = pyop.current_line() - if line is not None: - sys.stdout.write(' %s\n' % line.strip()) + sys.stdout.write(' %s\n' % pyop.current_line().strip()) else: sys.stdout.write(' (unable to read python frame information)\n') else: @@ -1509,13 +1501,7 @@ if start<1: start = 1 - try: - f = open(os_fsencode(filename), 'r') - except IOError as err: - sys.stdout.write('Unable to open %s: %s\n' - % (filename, err)) - return - with f: + with open(os_fsencode(filename), 'r') as f: all_lines = f.readlines() # start and end are 1-based, all_lines is 0-based; # so [start-1:end] as a python slice gives us [start, end] as a diff -r 95c34bce986c -r 900df5732f93 Tools/msi/msi.py --- a/Tools/msi/msi.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Tools/msi/msi.py Mon Jul 25 09:47:18 2011 -0400 @@ -119,7 +119,6 @@ "30":"{6953bc3b-6768-4291-8410-7914ce6e2ca8}", "31":"{4afcba0b-13e4-47c3-bebe-477428b46913}", "32":"{3ff95315-1096-4d31-bd86-601d5438ad5e}", - "33":"{f7581ca4-d368-4eea-8f82-d48c64c4f047}", } [major+minor] # Compute the name that Sphinx gives to the docfile @@ -1011,8 +1010,6 @@ lib.remove_pyc() # package READMEs if present lib.glob("README") - if dir=='Lib': - lib.add_file("sysconfig.cfg") if dir=='test' and parent.physical=='Lib': lib.add_file("185test.db") lib.add_file("audiotest.au") @@ -1048,7 +1045,7 @@ if dir=="Icons": lib.glob("*.gif") lib.add_file("idle.icns") - if dir=="command" and parent.physical in ("distutils", "packaging"): + if dir=="command" and parent.physical=="distutils": lib.glob("wininst*.exe") lib.add_file("command_template") if dir=="lib2to3": @@ -1159,8 +1156,6 @@ lib.add_file("README.txt", src="README") if f == 'Scripts': lib.add_file("2to3.py", src="2to3") - lib.add_file("pydoc3.py", src="pydoc3") - lib.add_file("pysetup3.py", src="pysetup3") if have_tcl: lib.start_component("pydocgui.pyw", tcltk, keyfile="pydocgui.pyw") lib.add_file("pydocgui.pyw") diff -r 95c34bce986c -r 900df5732f93 Tools/scripts/patchcheck.py --- a/Tools/scripts/patchcheck.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Tools/scripts/patchcheck.py Mon Jul 25 09:47:18 2011 -0400 @@ -36,14 +36,23 @@ def changed_files(): """Get the list of changed or added files from the VCS.""" if os.path.isdir('.hg'): + vcs = 'hg' cmd = 'hg status --added --modified --no-status' + elif os.path.isdir('.svn'): + vcs = 'svn' + cmd = 'svn status --quiet --non-interactive --ignore-externals' else: sys.exit('need a checkout to get modified files') st = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) try: st.wait() - return [x.decode().rstrip() for x in st.stdout] + if vcs == 'hg': + return [x.decode().rstrip() for x in st.stdout] + else: + output = (x.decode().rstrip().rsplit(None, 1)[-1] + for x in st.stdout if x[0] in b'AM') + return set(path for path in output if os.path.isfile(path)) finally: st.stdout.close() @@ -63,8 +72,10 @@ def normalize_whitespace(file_paths): """Make sure that the whitespace for .py files have been normalized.""" reindent.makebackup = False # No need to create backups. - fixed = [path for path in file_paths if path.endswith('.py') and - reindent.check(path)] + fixed = [] + for path in (x for x in file_paths if x.endswith('.py')): + if reindent.check(path): + fixed.append(path) return fixed diff -r 95c34bce986c -r 900df5732f93 Tools/scripts/reindent.py --- a/Tools/scripts/reindent.py Tue Jul 26 09:37:46 2011 +0300 +++ b/Tools/scripts/reindent.py Mon Jul 25 09:47:18 2011 -0400 @@ -8,6 +8,8 @@ -r (--recurse) Recurse. Search for all .py files in subdirectories too. -n (--nobackup) No backup. Does not make a ".bak" file before reindenting. -v (--verbose) Verbose. Print informative msgs; else no output. + (--newline) Newline. Specify the newline character to use (CRLF, LF). + Default is the same as the original file. -h (--help) Help. Print this usage information and exit. Change Python (.py) files to use 4-space indents and no hard tab characters. @@ -35,7 +37,7 @@ The backup file is a copy of the one that is being reindented. The ".bak" file is generated with shutil.copy(), but some corner cases regarding -user/group and permissions could leave the backup file more readable that +user/group and permissions could leave the backup file more readable than you'd prefer. You can always use the --nobackup option to prevent this. """ @@ -65,10 +67,11 @@ def main(): import getopt - global verbose, recurse, dryrun, makebackup + global verbose, recurse, dryrun, makebackup, spec_newline + spec_newline = None try: opts, args = getopt.getopt(sys.argv[1:], "drnvh", - ["dryrun", "recurse", "nobackup", "verbose", "help"]) + ["dryrun", "recurse", "nobackup", "verbose", "newline=", "help"]) except getopt.error as msg: usage(msg) return @@ -81,6 +84,11 @@ makebackup = False elif o in ('-v', '--verbose'): verbose = True + elif o in ('--newline',): + if not a.upper() in ('CRLF', 'LF'): + usage() + return + spec_newline = dict(CRLF='\r\n', LF='\n')[a.upper()] elif o in ('-h', '--help'): usage() return @@ -109,7 +117,7 @@ if verbose: print("checking", file, "...", end=' ') - with open(file, 'rb') as f: + with open(file, 'rb') as f: encoding, _ = tokenize.detect_encoding(f.readline) try: with open(file, encoding=encoding) as f: @@ -118,6 +126,11 @@ errprint("%s: I/O Error: %s" % (file, str(msg))) return + newline = spec_newline if spec_newline else r.newlines + if isinstance(newline, tuple): + errprint("%s: mixed newlines detected; cannot continue without --newline" % file) + return + if r.run(): if verbose: print("changed.") @@ -129,7 +142,7 @@ shutil.copyfile(file, bak) if verbose: print("backed up", file, "to", bak) - with open(file, "w", encoding=encoding) as f: + with open(file, "w", encoding=encoding, newline=newline) as f: r.write(f) if verbose: print("wrote new", file) @@ -177,6 +190,10 @@ # indeed, they're our headache! self.stats = [] + # Save the newlines found in the file so they can be used to + # create output without mutating the newlines. + self.newlines = f.newlines + def run(self): tokens = tokenize.generate_tokens(self.getline) for _token in tokens: diff -r 95c34bce986c -r 900df5732f93 configure --- a/configure Tue Jul 26 09:37:46 2011 +0300 +++ b/configure Mon Jul 25 09:47:18 2011 -0400 @@ -3066,7 +3066,7 @@ # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. # In addition, Stefan Krah confirms that issue #1244610 exists through # OpenBSD 4.6, but is fixed in 4.7. - OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.[0123456]) + OpenBSD/2.* | OpenBSD/3.[0123456789] | OpenBSD/4.[0123456]) define_xopen_source=no # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE @@ -3075,7 +3075,7 @@ $as_echo "#define _BSD_SOURCE 1" >>confdefs.h ;; - OpenBSD/*) + OpenBSD/4.[789]) # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE # As this has a different meaning on Linux, only define it on OpenBSD @@ -5005,7 +5005,7 @@ PY3LIBRARY=libpython3.so fi ;; - Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*) + Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) LDLIBRARY='libpython$(LDVERSION).so' BLDLIBRARY='-L. -lpython$(LDVERSION)' RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} @@ -6084,7 +6084,7 @@ for ac_header in asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \ fcntl.h grp.h \ ieeefp.h io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \ -shadow.h signal.h stdint.h stropts.h termios.h \ +shadow.h signal.h stdint.h stropts.h termios.h thread.h \ unistd.h utime.h \ sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \ sys/lock.h sys/mkdev.h sys/modem.h \ @@ -8349,6 +8349,7 @@ + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for --with-threads" >&5 $as_echo_n "checking for --with-threads... " >&6; } @@ -8450,6 +8451,31 @@ $as_echo "#define _REENTRANT 1" >>confdefs.h + ac_fn_c_check_header_mongrel "$LINENO" "cthreads.h" "ac_cv_header_cthreads_h" "$ac_includes_default" +if test "x$ac_cv_header_cthreads_h" = x""yes; then : + $as_echo "#define WITH_THREAD 1" >>confdefs.h + + $as_echo "#define C_THREADS 1" >>confdefs.h + + +$as_echo "#define HURD_C_THREADS 1" >>confdefs.h + + LIBS="$LIBS -lthreads" + THREADOBJ="Python/thread.o" +else + + ac_fn_c_check_header_mongrel "$LINENO" "mach/cthreads.h" "ac_cv_header_mach_cthreads_h" "$ac_includes_default" +if test "x$ac_cv_header_mach_cthreads_h" = x""yes; then : + $as_echo "#define WITH_THREAD 1" >>confdefs.h + + $as_echo "#define C_THREADS 1" >>confdefs.h + + +$as_echo "#define MACH_C_THREADS 1" >>confdefs.h + + THREADOBJ="Python/thread.o" +else + # Just looking for pthread_create in libpthread is not enough: # on HP/UX, pthread.h renames pthread_create to a different symbol name. # So we really have to include pthread.h, and then link. @@ -8681,6 +8707,12 @@ fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext +fi + + +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for usconfig in -lmpc" >&5 $as_echo_n "checking for usconfig in -lmpc... " >&6; } @@ -8784,7 +8816,7 @@ # Bug 662787: Using semaphores causes unexplicable hangs on Solaris 8. case $ac_sys_system/$ac_sys_release in - SunOS/5.6) + SunOS/5.6) $as_echo "#define HAVE_PTHREAD_DESTRUCTOR 1" >>confdefs.h ;; @@ -8792,10 +8824,14 @@ $as_echo "#define HAVE_BROKEN_POSIX_SEMAPHORES 1" >>confdefs.h ;; - AIX/*) + AIX/5) $as_echo "#define HAVE_BROKEN_POSIX_SEMAPHORES 1" >>confdefs.h ;; + AIX/6) +$as_echo "#define HAVE_BROKEN_POSIX_SEMAPHORES 1" >>confdefs.h + + ;; esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking if PTHREAD_SCOPE_SYSTEM is supported" >&5 @@ -9331,8 +9367,8 @@ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ - sigaction sigaltstack siginterrupt sigpending sigrelse \ - sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ + sigaction sigaltstack siginterrupt sigpending \ + sigrelse sigwait snprintf strftime strlcpy symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm writev _getpty @@ -9876,7 +9912,7 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +[ #include #include int main(int argc, char*argv[]) @@ -9885,7 +9921,7 @@ return 1; return 0; } - +] _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_have_chflags=yes @@ -9925,7 +9961,7 @@ else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - +[ #include #include int main(int argc, char*argv[]) @@ -9934,7 +9970,7 @@ return 1; return 0; } - +] _ACEOF if ac_fn_c_try_run "$LINENO"; then : ac_cv_have_lchflags=yes diff -r 95c34bce986c -r 900df5732f93 configure.in --- a/configure.in Tue Jul 26 09:37:46 2011 +0300 +++ b/configure.in Mon Jul 25 09:47:18 2011 -0400 @@ -327,14 +327,14 @@ # Reconfirmed for OpenBSD 3.3 by Zachary Hamm, for 3.4 by Jason Ish. # In addition, Stefan Krah confirms that issue #1244610 exists through # OpenBSD 4.6, but is fixed in 4.7. - OpenBSD/2.* | OpenBSD/3.* | OpenBSD/4.@<:@0123456@:>@) + OpenBSD/2.* | OpenBSD/3.@<:@0123456789@:>@ | OpenBSD/4.@<:@0123456@:>@) define_xopen_source=no # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE # As this has a different meaning on Linux, only define it on OpenBSD AC_DEFINE(_BSD_SOURCE, 1, [Define on OpenBSD to activate all library features]) ;; - OpenBSD/*) + OpenBSD/4.@<:@789@:>@) # OpenBSD undoes our definition of __BSD_VISIBLE if _XOPEN_SOURCE is # also defined. This can be overridden by defining _BSD_SOURCE # As this has a different meaning on Linux, only define it on OpenBSD @@ -769,7 +769,7 @@ PY3LIBRARY=libpython3.so fi ;; - Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*) + Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) LDLIBRARY='libpython$(LDVERSION).so' BLDLIBRARY='-L. -lpython$(LDVERSION)' RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} @@ -1301,7 +1301,7 @@ AC_CHECK_HEADERS(asm/types.h conio.h curses.h direct.h dlfcn.h errno.h \ fcntl.h grp.h \ ieeefp.h io.h langinfo.h libintl.h ncurses.h poll.h process.h pthread.h \ -shadow.h signal.h stdint.h stropts.h termios.h \ +shadow.h signal.h stdint.h stropts.h termios.h thread.h \ unistd.h utime.h \ sys/audioio.h sys/bsdtty.h sys/epoll.h sys/event.h sys/file.h sys/loadavg.h \ sys/lock.h sys/mkdev.h sys/modem.h \ @@ -2044,6 +2044,7 @@ # Templates for things AC_DEFINEd more than once. # For a single AC_DEFINE, no template is needed. +AH_TEMPLATE(C_THREADS,[Define if you have the Mach cthreads package]) AH_TEMPLATE(_REENTRANT, [Define to force use of thread-safe errno, h_errno, and other functions]) AH_TEMPLATE(WITH_THREAD, @@ -2125,6 +2126,17 @@ AC_MSG_RESULT($unistd_defines_pthreads) AC_DEFINE(_REENTRANT) + AC_CHECK_HEADER(cthreads.h, [AC_DEFINE(WITH_THREAD) + AC_DEFINE(C_THREADS) + AC_DEFINE(HURD_C_THREADS, 1, + [Define if you are using Mach cthreads directly under /include]) + LIBS="$LIBS -lthreads" + THREADOBJ="Python/thread.o"],[ + AC_CHECK_HEADER(mach/cthreads.h, [AC_DEFINE(WITH_THREAD) + AC_DEFINE(C_THREADS) + AC_DEFINE(MACH_C_THREADS, 1, + [Define if you are using Mach cthreads under mach /]) + THREADOBJ="Python/thread.o"],[ # Just looking for pthread_create in libpthread is not enough: # on HP/UX, pthread.h renames pthread_create to a different symbol name. # So we really have to include pthread.h, and then link. @@ -2160,7 +2172,7 @@ LIBS="$LIBS -lcma" THREADOBJ="Python/thread.o"],[ USE_THREAD_MODULE="#"]) - ])])])])]) + ])])])])])])]) AC_CHECK_LIB(mpc, usconfig, [AC_DEFINE(WITH_THREAD) LIBS="$LIBS -lmpc" @@ -2184,15 +2196,18 @@ # Bug 662787: Using semaphores causes unexplicable hangs on Solaris 8. case $ac_sys_system/$ac_sys_release in - SunOS/5.6) AC_DEFINE(HAVE_PTHREAD_DESTRUCTOR, 1, + SunOS/5.6) AC_DEFINE(HAVE_PTHREAD_DESTRUCTOR, 1, [Defined for Solaris 2.6 bug in pthread header.]) ;; SunOS/5.8) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, [Define if the Posix semaphores do not work on your system]) ;; - AIX/*) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, + AIX/5) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, [Define if the Posix semaphores do not work on your system]) ;; + AIX/6) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, + Define if the Posix semaphores do not work on your system) + ;; esac AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported) @@ -2537,8 +2552,8 @@ select sem_open sem_timedwait sem_getvalue sem_unlink sendfile setegid seteuid \ setgid sethostname \ setlocale setregid setreuid setresuid setresgid setsid setpgid setpgrp setpriority setuid setvbuf \ - sigaction sigaltstack siginterrupt sigpending sigrelse \ - sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ + sigaction sigaltstack siginterrupt sigpending \ + sigrelse sigwait snprintf strftime strlcpy symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm writev _getpty) @@ -2660,7 +2675,7 @@ # On Tru64, chflags seems to be present, but calling it will # exit Python AC_CACHE_CHECK([for chflags], [ac_cv_have_chflags], [dnl -AC_RUN_IFELSE([AC_LANG_SOURCE([[ +AC_RUN_IFELSE([AC_LANG_SOURCE([[[ #include #include int main(int argc, char*argv[]) @@ -2669,7 +2684,7 @@ return 1; return 0; } -]])], +]]])], [ac_cv_have_chflags=yes], [ac_cv_have_chflags=no], [ac_cv_have_chflags=cross]) @@ -2678,11 +2693,11 @@ AC_CHECK_FUNC([chflags], [ac_cv_have_chflags="yes"], [ac_cv_have_chflags="no"]) fi if test "$ac_cv_have_chflags" = yes ; then - AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the 'chflags' function.]) + AC_DEFINE(HAVE_CHFLAGS, 1, [Define to 1 if you have the `chflags' function.]) fi AC_CACHE_CHECK([for lchflags], [ac_cv_have_lchflags], [dnl -AC_RUN_IFELSE([AC_LANG_SOURCE([[ +AC_RUN_IFELSE([AC_LANG_SOURCE([[[ #include #include int main(int argc, char*argv[]) @@ -2691,13 +2706,13 @@ return 1; return 0; } -]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross]) +]]])],[ac_cv_have_lchflags=yes],[ac_cv_have_lchflags=no],[ac_cv_have_lchflags=cross]) ]) if test "$ac_cv_have_lchflags" = cross ; then AC_CHECK_FUNC([lchflags], [ac_cv_have_lchflags="yes"], [ac_cv_have_lchflags="no"]) fi if test "$ac_cv_have_lchflags" = yes ; then - AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.]) + AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the `lchflags' function.]) fi dnl Check if system zlib has *Copy() functions diff -r 95c34bce986c -r 900df5732f93 pyconfig.h.in --- a/pyconfig.h.in Tue Jul 26 09:37:46 2011 +0300 +++ b/pyconfig.h.in Mon Jul 25 09:47:18 2011 -0400 @@ -12,6 +12,9 @@ support for AIX C++ shared extension modules. */ #undef AIX_GENUINE_CPLUSPLUS +/* Define if you have the Mach cthreads package */ +#undef C_THREADS + /* Define if C doubles are 64-bit IEEE 754 binary format, stored in ARM mixed-endian order (byte order 45670123) */ #undef DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754 @@ -98,7 +101,7 @@ /* Define this if you have the type _Bool. */ #undef HAVE_C99_BOOL -/* Define to 1 if you have the 'chflags' function. */ +/* Define to 1 if you have the `chflags' function. */ #undef HAVE_CHFLAGS /* Define to 1 if you have the `chown' function. */ @@ -425,7 +428,7 @@ Solaris and Linux, the necessary defines are already defined.) */ #undef HAVE_LARGEFILE_SUPPORT -/* Define to 1 if you have the 'lchflags' function. */ +/* Define to 1 if you have the `lchflags' function. */ #undef HAVE_LCHFLAGS /* Define to 1 if you have the `lchmod' function. */ @@ -740,15 +743,9 @@ /* Define to 1 if you have the `sigrelse' function. */ #undef HAVE_SIGRELSE -/* Define to 1 if you have the `sigtimedwait' function. */ -#undef HAVE_SIGTIMEDWAIT - /* Define to 1 if you have the `sigwait' function. */ #undef HAVE_SIGWAIT -/* Define to 1 if you have the `sigwaitinfo' function. */ -#undef HAVE_SIGWAITINFO - /* Define to 1 if you have the `snprintf' function. */ #undef HAVE_SNPRINTF @@ -945,6 +942,9 @@ /* Define to 1 if you have the `tgamma' function. */ #undef HAVE_TGAMMA +/* Define to 1 if you have the header file. */ +#undef HAVE_THREAD_H + /* Define to 1 if you have the `timegm' function. */ #undef HAVE_TIMEGM @@ -1043,9 +1043,15 @@ /* Define to 1 if you have the `_getpty' function. */ #undef HAVE__GETPTY +/* Define if you are using Mach cthreads directly under /include */ +#undef HURD_C_THREADS + /* Define if log1p(-0.) is 0. rather than -0. */ #undef LOG1P_DROPS_ZERO_SIGN +/* Define if you are using Mach cthreads under mach / */ +#undef MACH_C_THREADS + /* Define to 1 if `major', `minor', and `makedev' are declared in . */ #undef MAJOR_IN_MKDEV