From 6461e10158db1f1d41dc9449e233551b2889ebb5 Mon Sep 17 00:00:00 2001 From: Alexandre Vassalotti Date: Thu, 15 May 2008 22:09:29 +0000 Subject: Merged revisions 62914-62916,62918-62919,62921-62922,62924-62942,62944-62945,62947-62949 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62914 | skip.montanaro | 2008-05-08 20:45:00 -0400 (Thu, 08 May 2008) | 4 lines Add an example about using NamedTemporaryFile() to replace mktemp(). I'm unclear whether the verbatim text should have been indented or by how much. ........ r62915 | benjamin.peterson | 2008-05-08 20:50:40 -0400 (Thu, 08 May 2008) | 2 lines reindent example ........ r62927 | georg.brandl | 2008-05-09 02:09:25 -0400 (Fri, 09 May 2008) | 2 lines #2788: add .hgignore file. ........ r62928 | georg.brandl | 2008-05-09 02:10:43 -0400 (Fri, 09 May 2008) | 2 lines #2781: fix function name. ........ r62929 | georg.brandl | 2008-05-09 02:18:27 -0400 (Fri, 09 May 2008) | 2 lines Add a sentence to basicConfig() that is in the docstring. ........ r62930 | georg.brandl | 2008-05-09 02:26:54 -0400 (Fri, 09 May 2008) | 2 lines Add another link to colorsys docs. ........ r62931 | georg.brandl | 2008-05-09 02:36:07 -0400 (Fri, 09 May 2008) | 2 lines Add Kodos as a re reference. ........ r62932 | georg.brandl | 2008-05-09 02:39:58 -0400 (Fri, 09 May 2008) | 2 lines Add a note about using reload(). ........ r62933 | andrew.kuchling | 2008-05-09 07:46:05 -0400 (Fri, 09 May 2008) | 3 lines Update planned release date. Uncomment PEP 370 section. Add some module items ........ r62934 | christian.heimes | 2008-05-09 08:19:09 -0400 (Fri, 09 May 2008) | 1 line Add --user option to build_ext ........ r62948 | mark.dickinson | 2008-05-09 13:54:23 -0400 (Fri, 09 May 2008) | 3 lines Issue #2487. math.ldexp(x, n) raised OverflowError when n was large and negative; fix to return an (appropriately signed) zero instead. ........ r62949 | martin.v.loewis | 2008-05-09 14:21:55 -0400 (Fri, 09 May 2008) | 1 line Use the CHM file name that Sphinx assigns. ........ --- .hgignore | 69 +++++++++++++++++++++++++++++++++++ Doc/library/_winreg.rst | 4 +-- Doc/library/colorsys.rst | 9 ++--- Doc/library/re.rst | 3 ++ Doc/library/tempfile.rst | 18 ++++++++++ Doc/tutorial/modules.rst | 7 ++++ Doc/whatsnew/2.6.rst | 74 +++++++++++++++++++++++++++----------- Lib/distutils/command/build_ext.py | 16 ++++++++- Lib/site.py | 2 +- Lib/test/test_math.py | 18 ++++++++++ Misc/NEWS | 5 +++ Modules/mathmodule.c | 66 +++++++++++++++++++++++++++------- Tools/msi/msi.py | 14 +++++--- 13 files changed, 260 insertions(+), 45 deletions(-) create mode 100644 .hgignore diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..a0868fa --- /dev/null +++ b/.hgignore @@ -0,0 +1,69 @@ +.gdb_history +.purify +.svn +BIG5.TXT +BIG5HKSCS-2004.TXT +BIG5HKSCS.TXT +CP932.TXT +CP936.TXT +CP949.TXT +CP950.TXT +EUC-CN.TXT +EUC-JISX0213.TXT +EUC-JP.TXT +EUC-KR.TXT +JOHAB.TXT +Makefile +Makefile.pre +NormalizationTest-3.2.0.txt +NormalizationTest.txt +SHIFTJIS.TXT +SHIFT_JISX0213.TXT +TAGS +autom4te.cache +build +buildno +config.cache +config.log +config.status +config.status.lineno +db_home +gb-18030-2000.xml +platform +pyconfig.h +python +python.exe +reflog.txt +tags +Lib/plat-mac/errors.rsrc.df.rsrc +Doc/tools/sphinx/ +Doc/tools/docutils/ +Doc/tools/jinja/ +Doc/tools/pygments/ +Modules/Setup +Modules/Setup.config +Modules/Setup.local +Modules/config.c +Parser/pgen +core + +syntax: glob +libpython*.a +*.o +*.pyc +*.pyo +*.pyd +*.cover +*.orig +*.rej +*~ +Lib/lib2to3/*.pickle +PCbuild/*.exe +PCbuild/*.dll +PCbuild/*.pdb +PCbuild/*.lib +PCbuild/*.exp +PCbuild/*.o +PCbuild/*.ncb +PCbuild/*.bsc +PCbuild/Win32-temp-* \ No newline at end of file diff --git a/Doc/library/_winreg.rst b/Doc/library/_winreg.rst index a4f3879..ba2994d 100644 --- a/Doc/library/_winreg.rst +++ b/Doc/library/_winreg.rst @@ -146,7 +146,7 @@ This module offers the following functions: *key* is an already open key, or one of the predefined :const:`HKEY_\*` constants. - It is not necessary to call RegFlushKey to change a key. Registry changes are + It is not necessary to call :func:`FlushKey` to change a key. Registry changes are flushed to disk by the registry using its lazy flusher. Registry changes are also flushed to disk at system shutdown. Unlike :func:`CloseKey`, the :func:`FlushKey` method returns only when all the data has been written to the @@ -159,7 +159,7 @@ This module offers the following functions: isn't. -.. function:: RegLoadKey(key, sub_key, file_name) +.. function:: LoadKey(key, sub_key, file_name) Creates a subkey under the specified key and stores registration information from a specified file into that subkey. diff --git a/Doc/library/colorsys.rst b/Doc/library/colorsys.rst index 2e7f3b7..2cbc704 100644 --- a/Doc/library/colorsys.rst +++ b/Doc/library/colorsys.rst @@ -1,4 +1,3 @@ - :mod:`colorsys` --- Conversions between color systems ===================================================== @@ -15,8 +14,11 @@ spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1. -More information about color spaces can be found at -http://www.poynton.com/ColorFAQ.html. +.. seealso:: + + More information about color spaces can be found at + http://www.poynton.com/ColorFAQ.html and + http://www.cambridgeincolour.com/tutorials/color-spaces.htm. The :mod:`colorsys` module defines the following functions: @@ -57,4 +59,3 @@ Example:: (0.25, 0.5, 0.4) >>> colorsys.hsv_to_rgb(0.25, 0.5, 0.4) (0.3, 0.4, 0.2) - diff --git a/Doc/library/re.rst b/Doc/library/re.rst index e3867c0..707eedf 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -43,6 +43,9 @@ fine-tuning parameters. second edition of the book no longer covers Python at all, but the first edition covered writing good regular expression patterns in great detail. + `Kodos `_ + is a graphical regular expression debugger written in Python. + .. _re-syntax: diff --git a/Doc/library/tempfile.rst b/Doc/library/tempfile.rst index 7363940..25d5acb 100644 --- a/Doc/library/tempfile.rst +++ b/Doc/library/tempfile.rst @@ -152,6 +152,24 @@ The module defines the following user-callable functions: Use of this function may introduce a security hole in your program. By the time you get around to doing anything with the file name it returns, someone else may have beaten you to the punch. + :func:`mktemp` usage can be replaced easily with + :func:`NamedTemporaryFile`, passing it the `delete=False` parameter:: + + >>> f = NamedTemporaryFile(delete=False) + >>> print f.name + >>> f.write("Hello World!\n") + >>> f.close() + >>> os.unlink(f.name) + >>> f = NamedTemporaryFile(delete=False) + >>> f + ', mode 'w+b' at 0x384698> + >>> f.name + '/var/folders/5q/5qTPn6xq2RaWqk+1Ytw3-U+++TI/-Tmp-/tmpG7V1Y0' + >>> f.write("Hello World!\n") + >>> f.close() + >>> os.unlink(f.name) + >>> os.path.exists(f.name) + False The module uses two global variables that tell it how to construct a temporary name. They are initialized at the first call to any of the diff --git a/Doc/tutorial/modules.rst b/Doc/tutorial/modules.rst index eee989f..4d06df2 100644 --- a/Doc/tutorial/modules.rst +++ b/Doc/tutorial/modules.rst @@ -106,6 +106,13 @@ In most cases Python programmers do not use this facility since it introduces an unknown set of names into the interpreter, possibly hiding some things you have already defined. +.. note:: + + For efficiency reasons, each module is only imported once per interpreter + session. Therefore, if you change your modules, you must restart the + interpreter -- or, if it's just one module you want to test interactively, + use :func:`reload`, e.g. ``reload('modulename')``. + .. _tut-modulesasscripts: diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst index 1af6f73..9708c67 100644 --- a/Doc/whatsnew/2.6.rst +++ b/Doc/whatsnew/2.6.rst @@ -40,25 +40,26 @@ * Credit the author of a patch or bugfix. Just the name is sufficient; the e-mail address isn't necessary. - * It's helpful to add the bug/patch number in an parenthetical + * It's helpful to add the bug/patch number in a parenthetical comment. XXX Describe the transmogrify() function added to the socket module. (Contributed by P.Y. Developer; :issue:`12345`.) - This saves the maintainer the effort of going through the SVN logs + This saves the maintainer some effort going through the SVN logs when researching a change. -This article explains the new features in Python 2.6. No release date for -Python 2.6 has been set; it will probably be released in mid 2008. +This article explains the new features in Python 2.6. The release +schedule is described in :pep:`361`; currently the final release is +scheduled for September 3 2008. This article doesn't attempt to provide a complete specification of the new features, but instead provides a convenient overview. For full details, you should refer to the documentation for Python 2.6. If -you want to understand the complete implementation and design -rationale, refer to the PEP for a particular new feature. For smaller -changes, this edition of "What's New in Python" links to the bug/patch -item for each change whenever possible. +you want to understand the rationale for the design and +implementation, refer to the PEP for a particular new feature. +Whenever possible, "What's New in Python" links to the bug/patch item +for each change. .. Compare with previous release in 2 - 3 sentences here. add hyperlink when the documentation becomes available online. @@ -481,24 +482,41 @@ can now be used in scripts running from inside a package. .. ====================================================================== -.. :: +.. _pep-0370: - .. _pep-0370: +PEP 370: Per-user ``site-packages`` Directory +===================================================== + +When you run Python, the module search path ``sys.modules`` usually +includes a directory whose path ends in ``"site-packages"``. This +directory is intended to hold locally-installed packages available to +all users on a machine or using a particular site installation. + +Python 2.6 introduces a convention for user-specific site directories. +The directory varies depending on the platform: + +* Unix and MacOS: :file:`~/.local/` +* Windows: :file:`%APPDATA%/Python` - PEP 370: XXX - ===================================================== +Within this directory, there will be version-specific subdirectories, +such as :file:`lib/python2.6/site-packages` on Unix/MacOS and +:file:`Python26/site-packages` on Windows. - When you run Python, the module search page ``sys.modules`` usually - includes a directory whose path ends in ``"site-packages"``. This - directory is intended to hold locally-installed packages available to - all users on a machine or using a particular site installation. +If you don't like the default directory, it can be overridden by an +environment variable. :envvar:`PYTHONUSERBASE` sets the root +directory used for all Python versions supporting this feature. On +Windows, the directory for application-specific data can be changed by +setting the :envvar:`APPDATA` environment variable. You can also +modify the :file:`site.py` file for your Python installation. - Python 2.6 introduces a convention for user-specific site directories. +The feature can be disabled entirely by running Python with the +:option:`-s` option or setting the :envvar:`PYTHONNOUSERSITE` +environment variable. - .. seealso:: +.. seealso:: - :pep:`370` - XXX - PEP written by XXX; implemented by Christian Heimes. + :pep:`370` - Per-user ``site-packages`` Directory + PEP written and implemented by Christian Heimes. .. ====================================================================== @@ -1450,6 +1468,12 @@ fixes. Here's a partial list of the most notable changes, sorted alphabetically by module name. Consult the :file:`Misc/NEWS` file in the source tree for a more complete list of changes, or look through the CVS logs for all the details. +* (3.0-warning mode) The :mod:`audiodev` module is being deprecated, + and has been removed from Python 3.0, so importing it now triggers a + warning. The module hasn't been maintained for several versions, + and is written against an outdated sound interface for SunOS and + IRIX. + * The :mod:`bsddb.dbshelve` module now uses the highest pickling protocol available, instead of restricting itself to protocol 1. (Contributed by W. Barnes; :issue:`1551443`.) @@ -2104,7 +2128,12 @@ complete list of changes, or look through the CVS logs for all the details. (Added by Facundo Batista.) -* The XML-RPC classes :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer` +* The :mod:`warnings` module's :func:`formatwarning` and :func:`showwarning` + gained an optional *line* argument that can be used to supply the + line of source code. (Added as part of :issue:`1631171`, which re-implemented + part of the :mod:`warnings` module in C code.) + +* The XML-RPC :class:`SimpleXMLRPCServer` and :class:`DocXMLRPCServer` classes can now be prevented from immediately opening and binding to their socket by passing True as the ``bind_and_activate`` constructor parameter. This can be used to modify the instance's @@ -2144,6 +2173,9 @@ complete list of changes, or look through the CVS logs for all the details. (Contributed by Alan McIntyre; :issue:`467924`.) + Also, :mod:`zipfile` now supports using Unicode filenames + for archived files. (Contributed by Alexey Borzenkov; :issue:`1734346`.) + .. ====================================================================== .. whole new modules get described in subsections here diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index e011219..73cc00b 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -7,6 +7,7 @@ extensions ASAP).""" __revision__ = "$Id$" import sys, os, re +from site import USER_BASE, USER_SITE from distutils.core import Command from distutils.errors import * from distutils.sysconfig import customize_compiler, get_python_version @@ -90,9 +91,11 @@ class build_ext(Command): "list of SWIG command line options"), ('swig=', None, "path to the SWIG executable"), + ('user', None, + "add user include, library and rpath"), ] - boolean_options = ['inplace', 'debug', 'force', 'swig-cpp'] + boolean_options = ['inplace', 'debug', 'force', 'swig-cpp', 'user'] help_options = [ ('help-compiler', None, @@ -120,6 +123,7 @@ class build_ext(Command): self.swig = None self.swig_cpp = None self.swig_opts = None + self.user = None def finalize_options(self): from distutils import sysconfig @@ -253,6 +257,16 @@ class build_ext(Command): else: self.swig_opts = self.swig_opts.split(' ') + # Finally add the user include and library directories if requested + if self.user: + user_include = os.path.join(USER_BASE, "include") + user_lib = os.path.join(USER_BASE, "lib") + if os.path.isdir(user_include): + self.include_dirs.append(user_include) + if os.path.isdir(user_lib): + self.library_dirs.append(user_lib) + self.rpath.append(user_lib) + def run(self): from distutils.ccompiler import new_compiler diff --git a/Lib/site.py b/Lib/site.py index 54a7e2b..548aa62 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -527,7 +527,7 @@ def _script(): Exit codes with --user-base or --user-site: 0 - user site directory is enabled - 1 - user site diretory is disabled by user + 1 - user site directory is disabled by user 2 - uses site directory is disabled by super user or for security reasons >2 - unknown error diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 379ff89..ff8db7c 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -369,6 +369,24 @@ class MathTests(unittest.TestCase): self.assertEquals(math.ldexp(NINF, -213), NINF) self.assert_(math.isnan(math.ldexp(NAN, 0))) + # large second argument + for n in [10**5, 10**10, 10**20, 10**40]: + self.assertEquals(math.ldexp(INF, -n), INF) + self.assertEquals(math.ldexp(NINF, -n), NINF) + self.assertEquals(math.ldexp(1., -n), 0.) + self.assertEquals(math.ldexp(-1., -n), -0.) + self.assertEquals(math.ldexp(0., -n), 0.) + self.assertEquals(math.ldexp(-0., -n), -0.) + self.assert_(math.isnan(math.ldexp(NAN, -n))) + + self.assertRaises(OverflowError, math.ldexp, 1., n) + self.assertRaises(OverflowError, math.ldexp, -1., n) + self.assertEquals(math.ldexp(0., n), 0.) + self.assertEquals(math.ldexp(-0., n), -0.) + self.assertEquals(math.ldexp(INF, n), INF) + self.assertEquals(math.ldexp(NINF, n), NINF) + self.assert_(math.isnan(math.ldexp(NAN, n))) + def testLog(self): self.assertRaises(TypeError, math.log) self.ftest('log(1/e)', math.log(1/math.e), -1) diff --git a/Misc/NEWS b/Misc/NEWS index 75e8be0..31b2678 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -30,6 +30,11 @@ Library - The ConfigParser module has been renamed to configparser. +- Issue #2487: change the semantics of math.ldexp(x, n) when n is too + large to fit in a C long. ldexp(x, n) now returns a zero (with + suitable sign) if n is large and negative; previously, it raised + OverflowError. + - Issue 2865: webbrowser.open() works again in a KDE environment. - The multifile module has been removed. diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index fffb630..d7aba68 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -425,23 +425,65 @@ static PyObject * math_ldexp(PyObject *self, PyObject *args) { double x, r; - int exp; - if (! PyArg_ParseTuple(args, "di:ldexp", &x, &exp)) + PyObject *oexp; + long exp; + if (! PyArg_ParseTuple(args, "dO:ldexp", &x, &oexp)) return NULL; - errno = 0; - PyFPE_START_PROTECT("in math_ldexp", return 0) - r = ldexp(x, exp); - PyFPE_END_PROTECT(r) - if (Py_IS_FINITE(x) && Py_IS_INFINITY(r)) + + if (PyLong_Check(oexp)) { + /* on overflow, replace exponent with either LONG_MAX + or LONG_MIN, depending on the sign. */ + exp = PyLong_AsLong(oexp); + if (exp == -1 && PyErr_Occurred()) { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) { + if (Py_SIZE(oexp) < 0) { + exp = LONG_MIN; + } + else { + exp = LONG_MAX; + } + PyErr_Clear(); + } + else { + /* propagate any unexpected exception */ + return NULL; + } + } + } + else if (PyLong_Check(oexp)) { + exp = PyLong_AS_LONG(oexp); + } + else { + PyErr_SetString(PyExc_TypeError, + "Expected an int or long as second argument " + "to ldexp."); + return NULL; + } + + if (x == 0. || !Py_IS_FINITE(x)) { + /* NaNs, zeros and infinities are returned unchanged */ + r = x; + errno = 0; + } else if (exp > INT_MAX) { + /* overflow */ + r = copysign(Py_HUGE_VAL, x); errno = ERANGE; - /* Windows MSVC8 sets errno = EDOM on ldexp(NaN, i); - we unset it to avoid raising a ValueError here. */ - if (errno == EDOM) + } else if (exp < INT_MIN) { + /* underflow to +-0 */ + r = copysign(0., x); errno = 0; + } else { + errno = 0; + PyFPE_START_PROTECT("in math_ldexp", return 0); + r = ldexp(x, (int)exp); + PyFPE_END_PROTECT(r); + if (Py_IS_INFINITY(r)) + errno = ERANGE; + } + if (errno && is_error(r)) return NULL; - else - return PyFloat_FromDouble(r); + return PyFloat_FromDouble(r); } PyDoc_STRVAR(math_ldexp_doc, diff --git a/Tools/msi/msi.py b/Tools/msi/msi.py index d2774c8..b48604c 100644 --- a/Tools/msi/msi.py +++ b/Tools/msi/msi.py @@ -112,6 +112,12 @@ pythondll_uuid = { "30":"{6953bc3b-6768-4291-8410-7914ce6e2ca8}", } [major+minor] +# Compute the name that Sphinx gives to the docfile +docfile = "" +if level < 0xf: + docfile = '%x%s' % (level, serial) +docfile = 'python%s%s%s.chm' % (major, minor, docfile) + # Build the mingw import library, libpythonXY.a # This requires 'nm' and 'dlltool' executables on your PATH def build_mingw_lib(lib_file, def_file, dll_file, mingw_lib): @@ -1073,8 +1079,8 @@ def add_files(db): # Add documentation htmlfiles.set_current() lib = PyDirectory(db, cab, root, "Doc", "Doc", "DOC|Doc") - lib.start_component("documentation", keyfile="Python%s%s.chm" % (major,minor)) - lib.add_file("Python%s%s.chm" % (major, minor), src="build/htmlhelp/pydoc.chm") + lib.start_component("documentation", keyfile=docfile) + lib.add_file(docfile, src="build/htmlhelp/"+docfile) cab.commit(db) @@ -1182,7 +1188,7 @@ def add_registry(db): ("PythonPath", -1, prefix+r"\PythonPath", "", r"[TARGETDIR]Lib;[TARGETDIR]DLLs;[TARGETDIR]Lib\lib-tk", "REGISTRY"), ("Documentation", -1, prefix+r"\Help\Main Python Documentation", "", - r"[TARGETDIR]Doc\Python%s%s.chm" % (major, minor), "REGISTRY.doc"), + "[TARGETDIR]Doc\\"+docfile , "REGISTRY.doc"), ("Modules", -1, prefix+r"\Modules", "+", None, "REGISTRY"), ("AppPaths", -1, r"Software\Microsoft\Windows\CurrentVersion\App Paths\Python.exe", "", r"[TARGETDIR]Python.exe", "REGISTRY.def") @@ -1212,7 +1218,7 @@ def add_registry(db): # htmlfiles.id, None, None, None, None, None, None, None), ## Non-advertised shortcuts: must be associated with a registry component ("Manual", "MenuDir", "MANUAL|Python Manuals", "REGISTRY.doc", - "[#Python%s%s.chm]" % (major,minor), None, + "[#%s]" % docfile, None, None, None, None, None, None, None), ("Uninstall", "MenuDir", "UNINST|Uninstall Python", "REGISTRY", SystemFolderName+"msiexec", "/x%s" % product_code, -- cgit v0.12