]> granicus.if.org Git - python/commitdiff
Merged revisions 55817-55961 via svnmerge from
authorGuido van Rossum <guido@python.org>
Wed, 13 Jun 2007 18:07:49 +0000 (18:07 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 13 Jun 2007 18:07:49 +0000 (18:07 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

................
  r55837 | guido.van.rossum | 2007-06-08 16:04:42 -0700 (Fri, 08 Jun 2007) | 2 lines

  PEP 3119 -- the abc module.
................
  r55838 | guido.van.rossum | 2007-06-08 17:38:55 -0700 (Fri, 08 Jun 2007) | 2 lines

  Implement part of PEP 3119 -- One Trick Ponies.
................
  r55847 | guido.van.rossum | 2007-06-09 08:28:06 -0700 (Sat, 09 Jun 2007) | 2 lines

  Different way to do one trick ponies, allowing registration (per PEP strawman).
................
  r55849 | guido.van.rossum | 2007-06-09 18:06:38 -0700 (Sat, 09 Jun 2007) | 3 lines

  Make sure that the magic looking for __hash__ (etc.) doesn't apply to
  real subclasses of Hashable.
................
  r55852 | guido.van.rossum | 2007-06-10 08:29:51 -0700 (Sun, 10 Jun 2007) | 2 lines

  Add some more examples, e.g. generators and dict views.
................
  r55853 | guido.van.rossum | 2007-06-10 08:31:59 -0700 (Sun, 10 Jun 2007) | 2 lines

  keys() and items() *are* containers -- just values() isn't.
................
  r55864 | georg.brandl | 2007-06-10 15:29:40 -0700 (Sun, 10 Jun 2007) | 2 lines

  PEP 3127: new octal literals, binary literals.
................
  r55865 | georg.brandl | 2007-06-10 15:31:37 -0700 (Sun, 10 Jun 2007) | 2 lines

  Some octal literal fixes in Tools.
................
  r55866 | georg.brandl | 2007-06-10 15:37:43 -0700 (Sun, 10 Jun 2007) | 2 lines

  Tokenizer changes for PEP 3127.
................
  r55867 | georg.brandl | 2007-06-10 15:37:55 -0700 (Sun, 10 Jun 2007) | 2 lines

  Some docs for PEP 3127.
................
  r55868 | georg.brandl | 2007-06-10 15:44:39 -0700 (Sun, 10 Jun 2007) | 2 lines

  Missed a place in intobject.c. Is that used anymore anyway?
................
  r55871 | neal.norwitz | 2007-06-10 18:31:49 -0700 (Sun, 10 Jun 2007) | 182 lines

  Merged revisions 55729-55868 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55731 | neal.norwitz | 2007-06-01 00:29:12 -0700 (Fri, 01 Jun 2007) | 7 lines

    SF 1668596/1720897: distutils now copies data files
    even if package_dir is empty.

    This needs to be backported.  I'm too tired tonight.  It would be great
    if someone backports this if the buildbots are ok with it.  Otherwise,
    I will try to get to it tomorrow.
  ........
    r55732 | georg.brandl | 2007-06-01 04:33:33 -0700 (Fri, 01 Jun 2007) | 2 lines

    Bug #1722484: remove docstrings again when running with -OO.
  ........
    r55735 | georg.brandl | 2007-06-01 12:20:27 -0700 (Fri, 01 Jun 2007) | 2 lines

    Fix wrong issue number.
  ........
    r55739 | brett.cannon | 2007-06-01 20:02:29 -0700 (Fri, 01 Jun 2007) | 3 lines

    Have configure raise an error when building on AtheOS.  Code specific to AtheOS
    will be removed in Python 2.7.
  ........
    r55746 | neal.norwitz | 2007-06-02 11:33:53 -0700 (Sat, 02 Jun 2007) | 1 line

    Update expected birthday of 2.6
  ........
    r55751 | neal.norwitz | 2007-06-03 13:32:50 -0700 (Sun, 03 Jun 2007) | 10 lines

    Backout the original 'fix' to 1721309 which had no effect.
    Different versions of Berkeley DB handle this differently.
    The comments and bug report should have the details.  Memory is allocated
    in 4.4 (and presumably earlier), but not in 4.5.  Thus
    4.5 has the free error, but not earlier versions.

    Mostly update comments, plus make the free conditional.

    This fix was already applied to the 2.5 branch.
  ........
    r55752 | brett.cannon | 2007-06-03 16:13:41 -0700 (Sun, 03 Jun 2007) | 6 lines

    Make _strptime.TimeRE().pattern() use ``\s+`` for matching whitespace instead
    of ``\s*``.  This prevents patterns from "stealing" bits from other patterns in
    order to make a match work.

    Closes bug #1730389.  Will be backported.
  ........
    r55766 | hyeshik.chang | 2007-06-05 11:16:52 -0700 (Tue, 05 Jun 2007) | 4 lines

    Fix build on FreeBSD.  Bluetooth HCI API in FreeBSD is quite different
    from Linux's.  Just fix the build for now but the code doesn't
    support the complete capability of HCI on FreeBSD yet.
  ........
    r55770 | hyeshik.chang | 2007-06-05 11:58:51 -0700 (Tue, 05 Jun 2007) | 4 lines

    Bug #1728403: Fix a bug that CJKCodecs StreamReader hangs when it
    reads a file that ends with incomplete sequence and sizehint argument
    for .read() is specified.
  ........
    r55775 | hyeshik.chang | 2007-06-05 12:28:15 -0700 (Tue, 05 Jun 2007) | 2 lines

    Fix for Windows: close a temporary file before trying to delete it.
  ........
    r55783 | guido.van.rossum | 2007-06-05 14:24:47 -0700 (Tue, 05 Jun 2007) | 2 lines

    Patch by Tim Delany (missing DECREF). SF #1731330.
  ........
    r55785 | collin.winter | 2007-06-05 17:17:35 -0700 (Tue, 05 Jun 2007) | 3 lines

    Patch #1731049: make threading.py use a proper "raise" when checking internal state, rather than assert statements (which get stripped out by -O).
  ........
    r55786 | facundo.batista | 2007-06-06 08:13:37 -0700 (Wed, 06 Jun 2007) | 4 lines

    FTP.ntransfercmd method now uses create_connection when passive,
    using the timeout received in connection time.
  ........
    r55792 | facundo.batista | 2007-06-06 10:15:23 -0700 (Wed, 06 Jun 2007) | 7 lines

    Added an optional timeout parameter to function urllib2.urlopen,
    with tests in test_urllib2net.py (must have network resource
    enabled to execute them). Also modified test_urllib2.py because
    testing mock classes must take it into acount. Docs are also
    updated.
  ........
    r55793 | thomas.heller | 2007-06-06 13:19:19 -0700 (Wed, 06 Jun 2007) | 1 line

    Build _ctypes and _ctypes_test in the ReleaseAMD64 configuration.
  ........
    r55802 | georg.brandl | 2007-06-07 06:23:24 -0700 (Thu, 07 Jun 2007) | 3 lines

    Disallow function calls like foo(None=1).
    Backport from py3k rev. 55708 by Guido.
  ........
    r55804 | georg.brandl | 2007-06-07 06:30:24 -0700 (Thu, 07 Jun 2007) | 2 lines

    Make reindent.py executable.
  ........
    r55805 | georg.brandl | 2007-06-07 06:34:10 -0700 (Thu, 07 Jun 2007) | 2 lines

    Patch #1667860: Fix UnboundLocalError in urllib2.
  ........
    r55821 | kristjan.jonsson | 2007-06-07 16:53:49 -0700 (Thu, 07 Jun 2007) | 1 line

    Fixing changes to getbuildinfo.c that broke linux builds
  ........
    r55828 | thomas.heller | 2007-06-08 09:10:27 -0700 (Fri, 08 Jun 2007) | 1 line

    Make this test work with older Python releases where struct has no 't' format character.
  ........
    r55829 | martin.v.loewis | 2007-06-08 10:29:20 -0700 (Fri, 08 Jun 2007) | 3 lines

    Bug #1733488: Fix compilation of bufferobject.c on AIX.
    Will backport to 2.5.
  ........
    r55831 | thomas.heller | 2007-06-08 11:20:09 -0700 (Fri, 08 Jun 2007) | 2 lines

    [ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
    with small modifications.
  ........
    r55832 | thomas.heller | 2007-06-08 12:01:06 -0700 (Fri, 08 Jun 2007) | 1 line

    Fix gcc warnings intruduced by passing Py_ssize_t to PyErr_Format calls.
  ........
    r55833 | thomas.heller | 2007-06-08 12:08:31 -0700 (Fri, 08 Jun 2007) | 2 lines

    Fix wrong documentation, and correct the punktuation.
    Closes [1700455].
  ........
    r55834 | thomas.heller | 2007-06-08 12:14:23 -0700 (Fri, 08 Jun 2007) | 1 line

    Fix warnings by using proper function prototype.
  ........
    r55839 | neal.norwitz | 2007-06-08 20:36:34 -0700 (Fri, 08 Jun 2007) | 7 lines

    Prevent expandtabs() on string and unicode objects from causing a segfault when
    a large width is passed on 32-bit platforms.  Found by Google.

    It would be good for people to review this especially carefully and verify
    I don't have an off by one error and there is no other way to cause overflow.
  ........
    r55841 | neal.norwitz | 2007-06-08 21:48:22 -0700 (Fri, 08 Jun 2007) | 1 line

    Use macro version of GET_SIZE to avoid Coverity warning (#150) about a possible error.
  ........
    r55842 | martin.v.loewis | 2007-06-09 00:42:52 -0700 (Sat, 09 Jun 2007) | 3 lines

    Patch #1733960: Allow T_LONGLONG to accept ints.
    Will backport to 2.5.
  ........
    r55843 | martin.v.loewis | 2007-06-09 00:58:05 -0700 (Sat, 09 Jun 2007) | 2 lines

    Fix Windows build.
  ........
    r55845 | martin.v.loewis | 2007-06-09 03:10:26 -0700 (Sat, 09 Jun 2007) | 2 lines

    Provide LLONG_MAX for S390.
  ........
    r55854 | thomas.heller | 2007-06-10 08:59:17 -0700 (Sun, 10 Jun 2007) | 4 lines

    First version of build scripts for Windows/AMD64 (no external
    components are built yet, and 'kill_python' is disabled).
  ........
    r55855 | thomas.heller | 2007-06-10 10:55:51 -0700 (Sun, 10 Jun 2007) | 3 lines

    For now, disable the _bsddb, _sqlite3, _ssl, _testcapi, _tkinter
    modules in the ReleaseAMD64 configuration because they do not compile.
  ........
    r55856 | thomas.heller | 2007-06-10 11:27:54 -0700 (Sun, 10 Jun 2007) | 1 line

    Need to set the environment variables, otherwise devenv.com is not found.
  ........
    r55860 | thomas.heller | 2007-06-10 14:01:17 -0700 (Sun, 10 Jun 2007) | 1 line

    Revert commit 55855.
  ........
................
  r55880 | neal.norwitz | 2007-06-10 22:07:36 -0700 (Sun, 10 Jun 2007) | 5 lines

  Fix the refleak counter on test_collections.  The ABC metaclass creates
  a registry which must be cleared on each run.  Otherwise, there *seem*
  to be refleaks when there really aren't any.  (The class is held within
  the registry even though it's no longer needed.)
................
  r55884 | neal.norwitz | 2007-06-10 22:46:33 -0700 (Sun, 10 Jun 2007) | 1 line

  These tests have been removed, so they are no longer needed here
................
  r55886 | georg.brandl | 2007-06-11 00:26:37 -0700 (Mon, 11 Jun 2007) | 3 lines

  Optimize access to True and False in the compiler (if True)
  and the peepholer (LOAD_NAME True).
................
  r55905 | georg.brandl | 2007-06-11 10:02:26 -0700 (Mon, 11 Jun 2007) | 5 lines

  Remove __oct__ and __hex__ and use __index__ for converting
  non-ints before formatting in a base.

  Add a bin() builtin.
................
  r55906 | georg.brandl | 2007-06-11 10:04:44 -0700 (Mon, 11 Jun 2007) | 2 lines

  int(x, 0) does not "guess".
................
  r55907 | georg.brandl | 2007-06-11 10:05:47 -0700 (Mon, 11 Jun 2007) | 2 lines

  Add a comment to explain that nb_oct and nb_hex are nonfunctional.
................
  r55908 | guido.van.rossum | 2007-06-11 10:49:18 -0700 (Mon, 11 Jun 2007) | 2 lines

  Get rid of unused imports and comment.
................
  r55910 | guido.van.rossum | 2007-06-11 13:05:17 -0700 (Mon, 11 Jun 2007) | 2 lines

  _Abstract.__new__ now requires either no arguments or __init__ overridden.
................
  r55911 | guido.van.rossum | 2007-06-11 13:07:49 -0700 (Mon, 11 Jun 2007) | 7 lines

  Move the collections ABCs to a separate file, _abcoll.py, in order to avoid
  needing to import _collections.so during the bootstrap (this will become
  apparent in the next submit of os.py).

  Add (plain and mutable) ABCs for Set, Mapping, Sequence.
................
  r55912 | guido.van.rossum | 2007-06-11 13:09:31 -0700 (Mon, 11 Jun 2007) | 2 lines

  Rewrite the _Environ class to use the new collections ABCs.
................
  r55913 | guido.van.rossum | 2007-06-11 13:59:45 -0700 (Mon, 11 Jun 2007) | 72 lines

  Merged revisions 55869-55912 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55869 | neal.norwitz | 2007-06-10 17:42:11 -0700 (Sun, 10 Jun 2007) | 1 line

    Add Atul Varma for patch # 1667860
  ........
    r55870 | neal.norwitz | 2007-06-10 18:22:03 -0700 (Sun, 10 Jun 2007) | 1 line

    Ignore valgrind problems on Ubuntu from ld
  ........
    r55872 | neal.norwitz | 2007-06-10 18:48:46 -0700 (Sun, 10 Jun 2007) | 2 lines

    Ignore config.status.lineno which seems new (new autoconf?)
  ........
    r55873 | neal.norwitz | 2007-06-10 19:14:39 -0700 (Sun, 10 Jun 2007) | 1 line

    Prevent these tests from running on Win64 since they don\'t apply there either
  ........
    r55874 | neal.norwitz | 2007-06-10 19:16:10 -0700 (Sun, 10 Jun 2007) | 5 lines

    Fix a bug when there was a newline in the string expandtabs was called on.
    This also catches another condition that can overflow.

    Will backport.
  ........
    r55879 | neal.norwitz | 2007-06-10 21:52:37 -0700 (Sun, 10 Jun 2007) | 1 line

    Prevent hang if the port cannot be opened.
  ........
    r55881 | neal.norwitz | 2007-06-10 22:28:45 -0700 (Sun, 10 Jun 2007) | 4 lines

    Add all of the distuils modules that don't seem to have explicit tests. :-(
    Move an import in mworkscompiler so that this module can be imported on
    any platform.  Hopefully this works on all platforms.
  ........
    r55882 | neal.norwitz | 2007-06-10 22:35:10 -0700 (Sun, 10 Jun 2007) | 4 lines

    SF #1734732, lower case the module names per PEP 8.

    Will backport.
  ........
    r55885 | neal.norwitz | 2007-06-10 23:16:48 -0700 (Sun, 10 Jun 2007) | 4 lines

    Not sure why this only fails sometimes on Unix machines. Better
    to disable it and only import msvccompiler on Windows since that's
    the only place it can work anyways.
  ........
    r55887 | neal.norwitz | 2007-06-11 00:29:43 -0700 (Mon, 11 Jun 2007) | 4 lines

    Bug #1734723: Fix repr.Repr() so it doesn't ignore the maxtuple attribute.

    Will backport
  ........
    r55889 | neal.norwitz | 2007-06-11 00:36:24 -0700 (Mon, 11 Jun 2007) | 1 line

    Reflow long line
  ........
    r55896 | thomas.heller | 2007-06-11 08:58:33 -0700 (Mon, 11 Jun 2007) | 3 lines

    Use "O&" in calls to PyArg_Parse when we need a 'void*' instead of "k"
    or "K" codes.
  ........
    r55901 | facundo.batista | 2007-06-11 09:27:08 -0700 (Mon, 11 Jun 2007) | 5 lines

    Added versionchanged flag to all the methods which received
    a new optional timeout parameter, and a versionadded flag to
    the socket.create_connection function.
  ........
................
  r55914 | guido.van.rossum | 2007-06-11 14:19:50 -0700 (Mon, 11 Jun 2007) | 3 lines

  New super() implementation, for PEP 3135 (though the PEP is not yet updated
  to this design, and small tweaks may still be made later).
................
  r55923 | guido.van.rossum | 2007-06-11 21:15:24 -0700 (Mon, 11 Jun 2007) | 4 lines

  I'm guessing this module broke when Neal ripped out the types module --
  it used 'list' both as a local variable and as the built-in list type.
  Renamed the local variable since that was easier.
................
  r55924 | guido.van.rossum | 2007-06-11 21:20:05 -0700 (Mon, 11 Jun 2007) | 5 lines

  Change all occurrences of super(<thisclass>, <firstarg>) to super().
  Seems to have worked, all the tests still pass.
  Exception: test_descr and test_descrtut, which have tons of these
  and are there to test the various usages.
................
  r55939 | collin.winter | 2007-06-12 13:57:33 -0700 (Tue, 12 Jun 2007) | 1 line

  Patch #1735485: remove StandardError from the exception hierarchy.
................
  r55954 | neal.norwitz | 2007-06-12 21:56:32 -0700 (Tue, 12 Jun 2007) | 51 lines

  Merged revisions 55913-55950 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r55926 | marc-andre.lemburg | 2007-06-12 02:09:58 -0700 (Tue, 12 Jun 2007) | 3 lines

    Apply patch #1734945 to support TurboLinux as distribution.
  ........
    r55927 | marc-andre.lemburg | 2007-06-12 02:26:49 -0700 (Tue, 12 Jun 2007) | 3 lines

    Add patch #1726668: Windows Vista support.
  ........
    r55929 | thomas.heller | 2007-06-12 08:36:22 -0700 (Tue, 12 Jun 2007) | 1 line

    Checkout, but do not yet try to build, exernal sources.
  ........
    r55930 | thomas.heller | 2007-06-12 09:08:27 -0700 (Tue, 12 Jun 2007) | 6 lines

    Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
    right thing to do?).

    Set the /XP64 /RETAIL build enviroment in the makefile when building
    ReleaseAMD64.
  ........
    r55931 | thomas.heller | 2007-06-12 09:23:19 -0700 (Tue, 12 Jun 2007) | 5 lines

    Revert this change, since it breaks the win32 build:

    Add bufferoverflowU.lib to the libraries needed by _ssl (is this the
    right thing to do?).
  ........
    r55934 | thomas.heller | 2007-06-12 10:28:31 -0700 (Tue, 12 Jun 2007) | 3 lines

    Specify the bufferoverflowU.lib to the makefile on the command line
    (for ReleaseAMD64 builds).
  ........
    r55937 | thomas.heller | 2007-06-12 12:02:59 -0700 (Tue, 12 Jun 2007) | 3 lines

    Add bufferoverflowU.lib to PCBuild\_bsddb.vcproj.
    Build sqlite3.dll and bsddb.
  ........
    r55938 | thomas.heller | 2007-06-12 12:56:12 -0700 (Tue, 12 Jun 2007) | 2 lines

    Don't rebuild Berkeley DB if not needed (this was committed by accident).
  ........
    r55948 | martin.v.loewis | 2007-06-12 20:42:19 -0700 (Tue, 12 Jun 2007) | 3 lines

    Provide PY_LLONG_MAX on all systems having long long.
    Will backport to 2.5.
  ........
................
  r55959 | guido.van.rossum | 2007-06-13 09:22:41 -0700 (Wed, 13 Jun 2007) | 2 lines

  Fix a compilation warning.
................

195 files changed:
Doc/api/exceptions.tex
Doc/lib/libctypes.tex
Doc/lib/libdecimal.tex
Doc/lib/libexcs.tex
Doc/lib/libftplib.tex
Doc/lib/libfuncs.tex
Doc/lib/libhttplib.tex
Doc/lib/libpoplib.tex
Doc/lib/libsmtplib.tex
Doc/lib/libsocket.tex
Doc/lib/libtelnetlib.tex
Doc/lib/libthreading.tex
Doc/lib/liburllib2.tex
Doc/ref/ref2.tex
Doc/ref/ref3.tex
Doc/tut/tut.tex
Doc/whatsnew/whatsnew26.tex
Include/abstract.h
Include/longobject.h
Include/object.h
Include/pyerrors.h
Include/pyport.h
Lib/CGIHTTPServer.py
Lib/_abcoll.py [new file with mode: 0644]
Lib/_strptime.py
Lib/anydbm.py
Lib/bsddb/__init__.py
Lib/bsddb/dbshelve.py
Lib/bsddb/dbtables.py
Lib/bsddb/test/test_1413192.py
Lib/bsddb/test/test_basics.py
Lib/bsddb/test/test_env_close.py
Lib/bsddb/test/test_sequence.py
Lib/collections.py
Lib/ctypes/__init__.py
Lib/ctypes/_endian.py
Lib/ctypes/test/test_init.py
Lib/ctypes/test/test_numbers.py
Lib/dbhash.py
Lib/distutils/ccompiler.py
Lib/distutils/cmd.py
Lib/distutils/command/build_py.py
Lib/distutils/command/build_scripts.py
Lib/distutils/command/install_scripts.py
Lib/distutils/command/register.py
Lib/distutils/dir_util.py
Lib/distutils/mwerkscompiler.py
Lib/distutils/tests/support.py
Lib/distutils/tests/test_build_py.py
Lib/dumbdbm.py
Lib/ftplib.py
Lib/imputil.py
Lib/mailbox.py
Lib/mhlib.py
Lib/os.py
Lib/plat-atheos/IN.py
Lib/plat-mac/aepack.py
Lib/plat-mac/bundlebuilder.py
Lib/plat-mac/macostools.py
Lib/plat-mac/plistlib.py
Lib/plat-sunos5/IN.py
Lib/plat-sunos5/STROPTS.py
Lib/plat-unixware7/IN.py
Lib/plat-unixware7/STROPTS.py
Lib/platform.py
Lib/pty.py
Lib/random.py
Lib/repr.py
Lib/sqlite3/test/dbapi.py
Lib/stat.py
Lib/tarfile.py
Lib/tempfile.py
Lib/test/exception_hierarchy.txt
Lib/test/list_tests.py
Lib/test/output/test_class
Lib/test/output/test_tokenize
Lib/test/regrtest.py
Lib/test/string_tests.py
Lib/test/test_abc.py [new file with mode: 0644]
Lib/test/test_array.py
Lib/test/test_builtin.py
Lib/test/test_bytes.py
Lib/test/test_cgi.py
Lib/test/test_class.py
Lib/test/test_collections.py
Lib/test/test_compile.py
Lib/test/test_descr.py
Lib/test/test_dumbdbm.py
Lib/test/test_format.py
Lib/test/test_grammar.py
Lib/test/test_hexoct.py
Lib/test/test_list.py
Lib/test/test_long.py
Lib/test/test_multibytecodec.py
Lib/test/test_peepholer.py
Lib/test/test_pep352.py
Lib/test/test_repr.py
Lib/test/test_str.py
Lib/test/test_strptime.py
Lib/test/test_structmembers.py
Lib/test/test_subprocess.py
Lib/test/test_sundry.py
Lib/test/test_super.py [new file with mode: 0644]
Lib/test/test_tarfile.py
Lib/test/test_tempfile.py
Lib/test/test_threading.py
Lib/test/test_tuple.py
Lib/test/test_unicode.py
Lib/test/test_unicode_file.py
Lib/test/test_unittest.py
Lib/test/test_urllib2.py
Lib/test/test_urllib2_localnet.py [new file with mode: 0644]
Lib/test/test_urllib2net.py
Lib/test/test_userlist.py
Lib/test/test_uu.py
Lib/test/test_weakref.py
Lib/test/test_xmlrpc.py
Lib/test/test_zipimport.py
Lib/test/tf_inherit_check.py
Lib/test/tokenize_tests.txt
Lib/threading.py
Lib/tokenize.py
Lib/urllib2.py
Lib/uu.py
Lib/weakref.py
Lib/xml/dom/domreg.py
Misc/ACKS
Misc/NEWS
Misc/Vim/python.vim
Misc/build.sh
Misc/cheatsheet
Misc/python-mode.el
Misc/valgrind-python.supp
Modules/_bsddb.c
Modules/_ctypes/_ctypes.c
Modules/_ctypes/callbacks.c
Modules/_ctypes/callproc.c
Modules/_ctypes/cfield.c
Modules/_ctypes/ctypes.h
Modules/_ctypes/libffi/src/x86/ffi.c
Modules/_ctypes/libffi/src/x86/ffi64.c
Modules/_ctypes/stgdict.c
Modules/_sqlite/cache.c
Modules/_sqlite/module.c
Modules/_testcapimodule.c
Modules/cjkcodecs/multibytecodec.c
Modules/getbuildinfo.c
Modules/socketmodule.c
Objects/abstract.c
Objects/bufferobject.c
Objects/exceptions.c
Objects/intobject.c
Objects/longobject.c
Objects/stringobject.c
Objects/typeobject.c
Objects/unicodeobject.c
PC/os2emx/python25.def
PC/os2vacpp/python.def
PC/pyconfig.h
PCbuild/_bsddb.vcproj
PCbuild/_ssl.mak
PCbuild/build_ssl.bat
PCbuild/build_ssl.py
PCbuild/pcbuild.sln
Parser/tokenizer.c
Python/ast.c
Python/bltinmodule.c
Python/compile.c
Python/mystrtoul.c
Python/peephole.c
Python/structmember.c
Python/symtable.c
README
Tools/buildbot/build-amd64.bat [new file with mode: 0644]
Tools/buildbot/clean-amd64.bat [new file with mode: 0644]
Tools/buildbot/external-amd64.bat [new file with mode: 0644]
Tools/buildbot/test-amd64.bat [new file with mode: 0644]
Tools/i18n/msgfmt.py
Tools/pybench/Arithmetic.py
Tools/pybench/CommandLine.py
Tools/pybench/Numbers.py
Tools/pybench/systimes.py
Tools/scripts/classfix.py
Tools/scripts/fixcid.py
Tools/scripts/ftpmirror.py
Tools/scripts/linktree.py
Tools/scripts/methfix.py
Tools/scripts/pathfix.py
Tools/scripts/reindent.py [changed mode: 0644->0755]
Tools/scripts/which.py
Tools/unicode/makeunicodedata.py
Tools/webchecker/websucker.py
configure
configure.in
setup.py

index 46ade49d4e626175fc5ce069baed129b277711cc..01c0aaf6bdac15c55cdc9f38e6a4a21302f4a6d2 100644 (file)
@@ -381,7 +381,6 @@ completeness, here are all the variables:
 \begin{tableiii}{l|l|c}{cdata}{C Name}{Python Name}{Notes}
   \lineiii{PyExc_BaseException\ttindex{PyExc_BaseException}}{\exception{BaseException}}{(1), (4)}
   \lineiii{PyExc_Exception\ttindex{PyExc_Exception}}{\exception{Exception}}{(1)}
-  \lineiii{PyExc_StandardError\ttindex{PyExc_StandardError}}{\exception{StandardError}}{(1)}
   \lineiii{PyExc_ArithmeticError\ttindex{PyExc_ArithmeticError}}{\exception{ArithmeticError}}{(1)}
   \lineiii{PyExc_LookupError\ttindex{PyExc_LookupError}}{\exception{LookupError}}{(1)}
   \lineiii{PyExc_AssertionError\ttindex{PyExc_AssertionError}}{\exception{AssertionError}}{}
index f19507a4fd19d295342e0c010a4f393188ed83f5..346863dbc6c38d25bacc39ba7e1ee40dc92a94d8 100755 (executable)
@@ -437,8 +437,8 @@ You should be careful, however, not to pass them to functions
 expecting pointers to mutable memory. If you need mutable memory
 blocks, ctypes has a \code{create{\_}string{\_}buffer} function which creates
 these in various ways.  The current memory block contents can be
-accessed (or changed) with the \code{raw} property, if you want to access
-it as NUL terminated string, use the \code{string} property:
+accessed (or changed) with the \code{raw} property; if you want to access
+it as NUL terminated string, use the \code{value} property:
 \begin{verbatim}
 >>> from ctypes import *
 >>> p = create_string_buffer(3)      # create a 3 byte buffer, initialized to NUL bytes
index a0a257eb65f71a5d460a700343ef044b12cf3d58..8c665da2942c8a4dcc7aad7ecaeca2526618cb8d 100644 (file)
@@ -845,7 +845,7 @@ exception is raised upon encountering the condition.
 The following table summarizes the hierarchy of signals:
 
 \begin{verbatim}    
-    exceptions.ArithmeticError(exceptions.StandardError)
+    exceptions.ArithmeticError(exceptions.Exception)
         DecimalException
             Clamped
             DivisionByZero(DecimalException, exceptions.ZeroDivisionError)
index 631c798a0e942d7c13f95bd9b8b37daed5eda763..298f04dcfd830a9c1f81ff88b17ac62ae7acd442 100644 (file)
@@ -64,13 +64,6 @@ from this class.
 \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
 \end{excdesc}
 
-\begin{excdesc}{StandardError}
-The base class for all built-in exceptions except
-\exception{StopIteration}, \exception{GeneratorExit},
-\exception{KeyboardInterrupt} and \exception{SystemExit}.
-\exception{StandardError} itself is derived from \exception{Exception}.
-\end{excdesc}
-
 \begin{excdesc}{ArithmeticError}
 The base class for those built-in exceptions that are raised for
 various arithmetic errors: \exception{OverflowError},
@@ -143,9 +136,9 @@ Raised when an \keyword{assert} statement fails.
 
 \begin{excdesc}{GeneratorExit}
   Raise when a generator's \method{close()} method is called.
-  It directly inherits from \exception{Exception} instead of
-  \exception{StandardError} since it is technically not an error.
   \versionadded{2.5}
+  \versionchanged[Changed to inherit from Exception instead of
+  StandardError]{3.0}
 \end{excdesc}
 
 \begin{excdesc}{IOError}
@@ -257,10 +250,9 @@ Raised when an \keyword{assert} statement fails.
 \begin{excdesc}{StopIteration}
   Raised by builtin \function{next()} and an iterator's \method{__next__()}
   method to signal that there are no further values.
-  This is derived from \exception{Exception} rather than
-  \exception{StandardError}, since this is not considered an error in
-  its normal application.
   \versionadded{2.2}
+  \versionchanged[Changed to inherit from Exception instead of
+  StandardError]{3.0}
 \end{excdesc}
 
 
@@ -304,7 +296,7 @@ Raised when an \keyword{assert} statement fails.
   Instances have an attribute \member{code} which is set to the
   proposed exit status or error message (defaulting to \code{None}).
   Also, this exception derives directly from \exception{BaseException} and
-  not \exception{StandardError}, since it is not technically an error.
+  not \exception{Exception}, since it is not technically an error.
 
   A call to \function{sys.exit()} is translated into an exception so that
   clean-up handlers (\keyword{finally} clauses of \keyword{try} statements)
@@ -315,7 +307,7 @@ Raised when an \keyword{assert} statement fails.
   \function{fork()}).
 
   The exception inherits from \exception{BaseException} instead of
-  \exception{StandardError} or \exception{Exception} so that it is not
+  \exception{Exception} so that it is not
   accidentally caught by code that catches \exception{Exception}.  This allows
   the exception to properly propagate up and cause the interpreter to exit.
   \versionchanged[Changed to inherit from \exception{BaseException}]{2.5}
index 98d7e80a4cbb22ae5fc77f95aa4757c83a548f38..1ce5f9bab36a3ba3473957ce9b23c6282625ebb3 100644 (file)
@@ -46,6 +46,7 @@ made.  When \var{user} is given, additionally the method call
 The optional \var{timeout} parameter specifies a timeout in seconds for the
 connection attempt (if is not specified, or passed as None, the global
 default timeout setting will be used).
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{datadesc}{all_errors}
@@ -117,6 +118,8 @@ the connection attempt. If is not specified, or passed as None, the
 object timeout is used (the timeout that you passed when instantiating the
 class); if the object timeout is also None, the global default timeout 
 setting will be used.
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{methoddesc}
 
 \begin{methoddesc}[FTP]{getwelcome}{}
index 4f49e3380c77e80bb9d95a3c17013dced0b73564..3cc06c85216694823ac8792775c9a46e4096f6d3 100644 (file)
@@ -104,6 +104,14 @@ def my_import(name):
   \versionadded{2.3}
 \end{funcdesc}
 
+\begin{funcdesc}{bin}{x}
+  Convert an integer number to a binary string.
+  The result is a valid Python expression.  If \var{x} is not a Python
+  \class{int} object, it has to define an \method{__index__} method
+  that returns an integer.
+  \versionadded{3.0}
+\end{funcdesc}
+
 \begin{funcdesc}{bool}{\optional{x}}
   Convert a value to a Boolean, using the standard truth testing
   procedure.  If \var{x} is false or omitted, this returns
@@ -540,8 +548,10 @@ class C:
 \end{funcdesc}
 
 \begin{funcdesc}{hex}{x}
-  Convert an integer number (of any size) to a hexadecimal string.
-  The result is a valid Python expression.
+  Convert an integer number to a hexadecimal string.
+  The result is a valid Python expression.  If \var{x} is not a Python
+  \class{int} object, it has to define an \method{__index__} method
+  that returns an integer.
   \versionchanged[Formerly only returned an unsigned literal]{2.4}
 \end{funcdesc}
 
@@ -559,8 +569,7 @@ class C:
   representable as a Python integer, possibly embedded in whitespace.
   The \var{radix} parameter gives the base for the
   conversion and may be any integer in the range [2, 36], or zero.  If
-  \var{radix} is zero, the proper radix is guessed based on the
-  contents of string; the interpretation is the same as for integer
+  \var{radix} is zero, the interpretation is the same as for integer
   literals.  If \var{radix} is specified and \var{x} is not a string,
   \exception{TypeError} is raised.
   Otherwise, the argument may be a plain or
@@ -707,8 +716,10 @@ class C:
 \end{funcdesc}
 
 \begin{funcdesc}{oct}{x}
-  Convert an integer number (of any size) to an octal string.  The
-  result is a valid Python expression.
+  Convert an integer number to an octal string.  The
+  result is a valid Python expression.  If \var{x} is not a Python
+  \class{int} object, it has to define an \method{__index__} method
+  that returns an integer.
   \versionchanged[Formerly only returned an unsigned literal]{2.4}
 \end{funcdesc}
 
index 7c9449de174ca2e7d66f15c1e54955c99781ca61..37a442d73ca0facbea37bfee0eabd5bba02fb86f 100644 (file)
@@ -49,6 +49,7 @@ the server at the same host and port:
 >>> h3 = httplib.HTTPConnection('www.cwi.nl', 80, timeout=10)
 \end{verbatim}
 \versionadded{2.0}
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{classdesc}{HTTPSConnection}{host\optional{, port\optional{,
@@ -63,6 +64,7 @@ key. \var{cert_file} is a PEM formatted certificate chain file.
 \warning{This does not do any certificate verification!}
 
 \versionadded{2.0}
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{classdesc}{HTTPResponse}{sock\optional{, debuglevel=0}\optional{, strict=0}}
index 7b2c4a10eb1e3074a0fc0064ad64edef01732f18..9ca5bbd7f2569454aedc7d71e49ec4c279aa587b 100644 (file)
@@ -35,6 +35,8 @@ If \var{port} is omitted, the standard POP3 port (110) is used.
 The optional \var{timeout} parameter specifies a timeout in seconds for the
 connection attempt (if not specified, or passed as None, the global default
 timeout setting will be used).
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{classdesc}{POP3_SSL}{host\optional{, port\optional{, keyfile\optional{, certfile}}}}
index 26293d6780b6abc2eac97b69d5d2b3d5575377f2..1c034e7b0ec85d1f8b3a3881c78d1b4a3e9d4e6d 100644 (file)
@@ -29,6 +29,8 @@ default timeout setting will be used).
 For normal use, you should only require the initialization/connect,
 \method{sendmail()}, and \method{quit()} methods.  An example is
 included below.
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{classdesc}{SMTP_SSL}{\optional{host\optional{, port\optional{,
@@ -45,6 +47,8 @@ certificate chain file for the SSL connection.
 The optional \var{timeout} parameter specifies a timeout in seconds for the
 connection attempt (if not specified, or passed as None, the global
 default timeout setting will be used).
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 \begin{classdesc}{LMTP}{\optional{host\optional{, port\optional{,
index ff0fb87f7d2aa18f8eeba27e0922e9f9fa16a93a..e3fce23c7c0cf889be5db70dc36f3a9066f0b7ce 100644 (file)
@@ -177,6 +177,7 @@ higher-level protocols, it is not normally used directly from
 application-level code.  Passing the optional \var{timeout} parameter
 will set the timeout on the socket instance (if it is not given or
 \code{None}, the global default timeout setting is used).
+\versionadded{2.6}
 \end{funcdesc}
 
 \begin{funcdesc}{getaddrinfo}{host, port\optional{, family\optional{,
index 269ee9b8c481a217a1323c69af4efca377f3c2d6..853788f2a9b5bfd797079f21109b79f924d98602 100644 (file)
@@ -40,6 +40,7 @@ This class has many \method{read_*()} methods.  Note that some of them
 raise \exception{EOFError} when the end of the connection is read,
 because they can return an empty string for other reasons.  See the
 individual descriptions below.
+\versionchanged[\var{timeout} was added]{2.6}
 \end{classdesc}
 
 
@@ -123,6 +124,7 @@ connection attempt (if not specified, or passed as None, the global default
 timeout setting will be used).
 
 Do not try to reopen an already connected instance.
+\versionchanged[\var{timeout} was added]{2.6}
 \end{methoddesc}
 
 \begin{methoddesc}[Telnet]{msg}{msg\optional{, *args}}
index 522ea2f99591fdb36cb59d3e0c0863b22fafce4a..19c496e499d3de85cb258fb044831abf2a706cd2 100644 (file)
@@ -174,11 +174,14 @@ until a call to \method{release()} in another thread changes it to
 unlocked, then the \method{acquire()} call resets it to locked and
 returns.  The \method{release()} method should only be called in the
 locked state; it changes the state to unlocked and returns
-immediately.  When more than one thread is blocked in
-\method{acquire()} waiting for the state to turn to unlocked, only one
-thread proceeds when a \method{release()} call resets the state to
-unlocked; which one of the waiting threads proceeds is not defined,
-and may vary across implementations.
+immediately. If an attempt is made to release an unlocked lock, a
+\exception{RuntimeError} will be raised.
+
+When more than one thread is blocked in \method{acquire()} waiting for
+the state to turn to unlocked, only one thread proceeds when a
+\method{release()} call resets the state to unlocked; which one of the
+waiting threads proceeds is not defined, and may vary across
+implementations.
 
 All methods are executed atomically.
 
@@ -257,8 +260,9 @@ become unlocked, allow exactly one of them to proceed.  If after the
 decrement the recursion level is still nonzero, the lock remains
 locked and owned by the calling thread.
 
-Only call this method when the calling thread owns the lock.
-Do not call this method when the lock is unlocked.
+Only call this method when the calling thread owns the lock. A
+\exception{RuntimeError} is raised if this method is called when the
+lock is unlocked.
 
 There is no return value.
 \end{methoddesc}
@@ -275,7 +279,8 @@ A condition variable has \method{acquire()} and \method{release()}
 methods that call the corresponding methods of the associated lock.
 It also has a \method{wait()} method, and \method{notify()} and
 \method{notifyAll()} methods.  These three must only be called when
-the calling thread has acquired the lock.
+the calling thread has acquired the lock, otherwise a
+\exception{RuntimeError} is raised.
 
 The \method{wait()} method releases the lock, and then blocks until it
 is awakened by a \method{notify()} or \method{notifyAll()} call for
@@ -343,9 +348,9 @@ lock; there is no return value.
 \end{methoddesc}
 
 \begin{methoddesc}{wait}{\optional{timeout}}
-Wait until notified or until a timeout occurs.
-This must only be called when the calling thread has acquired the
-lock.
+Wait until notified or until a timeout occurs. If the calling thread
+has not acquired the lock when this method is called, a
+\exception{RuntimeError} is raised.
 
 This method releases the underlying lock, and then blocks until it is
 awakened by a \method{notify()} or \method{notifyAll()} call for the
@@ -367,9 +372,10 @@ when the lock is reacquired.
 \end{methoddesc}
 
 \begin{methoddesc}{notify}{}
-Wake up a thread waiting on this condition, if any.
-This must only be called when the calling thread has acquired the
-lock.
+Wake up a thread waiting on this condition, if any. Wait until
+notified or until a timeout occurs. If the calling thread has not
+acquired the lock when this method is called, a
+\exception{RuntimeError} is raised.
 
 This method wakes up one of the threads waiting for the condition
 variable, if any are waiting; it is a no-op if no threads are waiting.
@@ -386,7 +392,9 @@ Note: the awakened thread does not actually return from its
 
 \begin{methoddesc}{notifyAll}{}
 Wake up all threads waiting on this condition.  This method acts like
-\method{notify()}, but wakes up all waiting threads instead of one.
+\method{notify()}, but wakes up all waiting threads instead of one. If
+the calling thread has not acquired the lock when this method is
+called, a \exception{RuntimeError} is raised.
 \end{methoddesc}
 
 
@@ -404,8 +412,9 @@ finds that it is zero, it blocks, waiting until some other thread
 calls \method{release()}.
 
 \begin{classdesc}{Semaphore}{\optional{value}}
-The optional argument gives the initial value for the internal
-counter; it defaults to \code{1}.
+The optional argument gives the initial \var{value} for the internal
+counter; it defaults to \code{1}. If the \var{value} given is less
+than 0, \exception{ValueError} is raised.
 \end{classdesc}
 
 \begin{methoddesc}{acquire}{\optional{blocking}}
@@ -586,9 +595,12 @@ before doing anything else to the thread.
 \begin{methoddesc}{start}{}
 Start the thread's activity.
 
-This must be called at most once per thread object.  It
-arranges for the object's \method{run()} method to be invoked in a
-separate thread of control.
+It must be called at most once per thread object.  It arranges for the
+object's \method{run()} method to be invoked in a separate thread of
+control.
+
+This method will raise a \exception{RuntimeException} if called more
+than once on the same thread object.
 \end{methoddesc}
 
 \begin{methoddesc}{run}{}
@@ -618,11 +630,10 @@ operation will block until the thread terminates.
 
 A thread can be \method{join()}ed many times.
 
-A thread cannot join itself because this would cause a
-deadlock.
-
-It is an error to attempt to \method{join()} a thread before it has
-been started.
+\method{join()} may throw a \exception{RuntimeError}, if an attempt is
+made to join the current thread as that would cause a deadlock. It is
+also an error to \method{join()} a thread before it has been started
+and attempts to do so raises same exception.
 \end{methoddesc}
 
 \begin{methoddesc}{getName}{}
@@ -651,7 +662,8 @@ Return the thread's daemon flag.
 
 \begin{methoddesc}{setDaemon}{daemonic}
 Set the thread's daemon flag to the Boolean value \var{daemonic}.
-This must be called before \method{start()} is called.
+This must be called before \method{start()} is called, otherwise
+\exception{RuntimeError} is raised.
 
 The initial value is inherited from the creating thread.
 
index 0df73859ba8360a46d48727dd4b22b5a4dfebcdc..9d2c38279e2b9e2f9adebff887782f3d8970c197 100644 (file)
@@ -14,7 +14,7 @@ authentication, redirections, cookies and more.
 
 The \module{urllib2} module defines the following functions:
 
-\begin{funcdesc}{urlopen}{url\optional{, data}}
+\begin{funcdesc}{urlopen}{url\optional{, data}\optional{, timeout}}
 Open the URL \var{url}, which can be either a string or a \class{Request}
 object.
 
@@ -27,6 +27,11 @@ parameter is provided.  \var{data} should be a buffer in the standard
 \function{urllib.urlencode()} function takes a mapping or sequence of
 2-tuples and returns a string in this format.
 
+The optional \var{timeout} parameter specifies a timeout in seconds for the
+connection attempt (if not specified, or passed as None, the global default
+timeout setting will be used). This actually only work for HTTP, HTTPS, FTP
+and FTPS connections.
+
 This function returns a file-like object with two additional methods:
 
 \begin{itemize}
@@ -40,6 +45,8 @@ Raises \exception{URLError} on errors.
 Note that \code{None} may be returned if no handler handles the
 request (though the default installed global \class{OpenerDirector}
 uses \class{UnknownHandler} to ensure this never happens).
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{funcdesc}
 
 \begin{funcdesc}{install_opener}{opener}
@@ -351,12 +358,18 @@ that HTTP errors are a special case).
 \end{itemize}
 \end{methoddesc}
 
-\begin{methoddesc}[OpenerDirector]{open}{url\optional{, data}}
+\begin{methoddesc}[OpenerDirector]{open}{url\optional{, data}{\optional{, timeout}}}
 Open the given \var{url} (which can be a request object or a string),
 optionally passing the given \var{data}.
 Arguments, return values and exceptions raised are the same as those
 of \function{urlopen()} (which simply calls the \method{open()} method
-on the currently installed global \class{OpenerDirector}).
+on the currently installed global \class{OpenerDirector}).  The optional
+\var{timeout} parameter specifies a timeout in seconds for the connection 
+attempt (if not specified, or passed as None, the global default timeout 
+setting will be used; this actually only work for HTTP, HTTPS, FTP
+and FTPS connections).
+
+\versionchanged[\var{timeout} was added]{2.6}
 \end{methoddesc}
 
 \begin{methoddesc}[OpenerDirector]{error}{proto\optional{,
index 39b75a976e018a8e31faae62a8ff26085ccfa51a..7b70676f622863e58cf2933abe9ebae79a63deda 100644 (file)
@@ -565,6 +565,7 @@ number and an imaginary number).
 \index{floating point literal}
 \index{hexadecimal literal}
 \index{octal literal}
+\index{binary literal}
 \index{decimal literal}
 \index{imaginary literal}
 \index{complex!literal}
@@ -574,35 +575,32 @@ Note that numeric literals do not include a sign; a phrase like
 `\code{-}' and the literal \code{1}.
 
 
-\subsection{Integer and long integer literals\label{integers}}
+\subsection{Integer literals\label{integers}}
 
-Integer and long integer literals are described by the following
+Integer literals are described by the following
 lexical definitions:
 
 \begin{productionlist}
-  \production{longinteger}
-             {\token{integer} ("l" | "L")}
   \production{integer}
              {\token{decimalinteger} | \token{octinteger} | \token{hexinteger}}
   \production{decimalinteger}
-             {\token{nonzerodigit} \token{digit}* | "0"}
+             {\token{nonzerodigit} \token{digit}* | "0"+}
   \production{octinteger}
-             {"0" \token{octdigit}+}
+             {"0" ("o" | "O") \token{octdigit}+}
   \production{hexinteger}
              {"0" ("x" | "X") \token{hexdigit}+}
+  \production{bininteger}
+             {"0" ("b" | "B") \token{bindigit}+}
   \production{nonzerodigit}
              {"1"..."9"}
   \production{octdigit}
              {"0"..."7"}
   \production{hexdigit}
              {\token{digit} | "a"..."f" | "A"..."F"}
+  \production{bindigit}
+             {"0"..."1"}
 \end{productionlist}
 
-Although both lower case \character{l} and upper case \character{L} are
-allowed as suffix for long integers, it is strongly recommended to always
-use \character{L}, since the letter \character{l} looks too much like the
-digit \character{1}.
-
 Plain integer literals that are above the largest representable plain
 integer (e.g., 2147483647 when using 32-bit arithmetic) are accepted
 as if they were long integers instead.\footnote{In versions of Python
@@ -613,13 +611,16 @@ taken as the negative plain integer obtained by subtracting 4294967296
 from their unsigned value.}  There is no limit for long integer
 literals apart from what can be stored in available memory.
 
-Some examples of plain integer literals (first row) and long integer
-literals (second and third rows):
+Note that leading zeros in a non-zero decimal number are not allowed.
+This is for disambiguation with C-style octal literals, which Python
+used before version 3.0.
+
+Some examples of integer literals:
 
 \begin{verbatim}
-7     2147483647                        0177
-3L    79228162514264337593543950336L    0377L   0x100000000L
-      79228162514264337593543950336             0xdeadbeef                                                 
+7     2147483647                        0o177    0b100110111
+3     79228162514264337593543950336     0o377    0x100000000
+      79228162514264337593543950336              0xdeadbeef                                                
 \end{verbatim}
 
 
@@ -644,12 +645,10 @@ definitions:
              {("e" | "E") ["+" | "-"] \token{digit}+}
 \end{productionlist}
 
-Note that the integer and exponent parts of floating point numbers
-can look like octal integers, but are interpreted using radix 10.  For
-example, \samp{077e010} is legal, and denotes the same number
-as \samp{77e10}.
-The allowed range of floating point literals is
-implementation-dependent.
+Note that the integer and exponent parts are always interpreted using
+radix 10.  For example, \samp{077e010} is legal, and denotes the same
+number as \samp{77e10}.
+The allowed range of floating point literals is implementation-dependent.
 Some examples of floating point literals:
 
 \begin{verbatim}
index 66aa27331609ec006e14c0726112f0e0b7b842ab..cced29eda02760ab351852b2c41549794cc0b689 100644 (file)
@@ -2033,17 +2033,11 @@ and \function{float()}\bifuncindex{float}.  Should return a value of
 the appropriate type.
 \end{methoddesc}
 
-\begin{methoddesc}[numeric object]{__oct__}{self}
-\methodline[numeric object]{__hex__}{self}
-Called to implement the built-in functions
-\function{oct()}\bifuncindex{oct} and
-\function{hex()}\bifuncindex{hex}.  Should return a string value.
-\end{methoddesc}
-
 \begin{methoddesc}[numeric object]{__index__}{self}
 Called to implement \function{operator.index()}.  Also called whenever
-Python needs an integer object (such as in slicing).  Must return an
-integer (int or long).
+Python needs an integer object (such as in slicing, or in the built-in
+\function{bin()}, \function{hex()} and \function{oct()} functions).
+Must return an integer (int or long).
 \versionadded{2.5}
 \end{methoddesc}
 
index 4ed1b838a5fc550266074e4578b7dba22560ac0f..53a84a9d49d811266707699da94b1835c78a3557 100644 (file)
@@ -2689,7 +2689,7 @@ standard module \module{__builtin__}\refbimodindex{__builtin__}:
  'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented',
  'NotImplementedError', 'OSError', 'OverflowError', 
  'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError',
- 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError',
+ 'RuntimeWarning', 'StopIteration', 'SyntaxError',
  'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True',
  'TypeError', 'UnboundLocalError', 'UnicodeDecodeError',
  'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError',
@@ -2734,9 +2734,9 @@ possible structure for your package (expressed in terms of a
 hierarchical filesystem):
 
 \begin{verbatim}
-Sound/                          Top-level package
+sound/                          Top-level package
       __init__.py               Initialize the sound package
-      Formats/                  Subpackage for file format conversions
+      formats/                  Subpackage for file format conversions
               __init__.py
               wavread.py
               wavwrite.py
@@ -2745,13 +2745,13 @@ Sound/                          Top-level package
               auread.py
               auwrite.py
               ...
-      Effects/                  Subpackage for sound effects
+      effects/                  Subpackage for sound effects
               __init__.py
               echo.py
               surround.py
               reverse.py
               ...
-      Filters/                  Subpackage for filters
+      filters/                  Subpackage for filters
               __init__.py
               equalizer.py
               vocoder.py
@@ -2774,20 +2774,20 @@ Users of the package can import individual modules from the
 package, for example:
 
 \begin{verbatim}
-import Sound.Effects.echo
+import sound.effects.echo
 \end{verbatim}
 
-This loads the submodule \module{Sound.Effects.echo}.  It must be referenced
+This loads the submodule \module{sound.effects.echo}.  It must be referenced
 with its full name.
 
 \begin{verbatim}
-Sound.Effects.echo.echofilter(input, output, delay=0.7, atten=4)
+sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)
 \end{verbatim}
 
 An alternative way of importing the submodule is:
 
 \begin{verbatim}
-from Sound.Effects import echo
+from sound.effects import echo
 \end{verbatim}
 
 This also loads the submodule \module{echo}, and makes it available without
@@ -2800,7 +2800,7 @@ echo.echofilter(input, output, delay=0.7, atten=4)
 Yet another variation is to import the desired function or variable directly:
 
 \begin{verbatim}
-from Sound.Effects.echo import echofilter
+from sound.effects.echo import echofilter
 \end{verbatim}
 
 Again, this loads the submodule \module{echo}, but this makes its function
@@ -2827,7 +2827,7 @@ class or function or variable defined in the previous item.
 %The \code{__all__} Attribute
 
 \ttindex{__all__}
-Now what happens when the user writes \code{from Sound.Effects import
+Now what happens when the user writes \code{from sound.effects import
 *}?  Ideally, one would hope that this somehow goes out to the
 filesystem, finds which submodules are present in the package, and
 imports them all.  Unfortunately, this operation does not work very
@@ -2849,19 +2849,19 @@ encountered.  It is up to the package author to keep this list
 up-to-date when a new version of the package is released.  Package
 authors may also decide not to support it, if they don't see a use for
 importing * from their package.  For example, the file
-\file{Sounds/Effects/__init__.py} could contain the following code:
+\file{sounds/effects/__init__.py} could contain the following code:
 
 \begin{verbatim}
 __all__ = ["echo", "surround", "reverse"]
 \end{verbatim}
 
-This would mean that \code{from Sound.Effects import *} would
-import the three named submodules of the \module{Sound} package.
+This would mean that \code{from sound.effects import *} would
+import the three named submodules of the \module{sound} package.
 
-If \code{__all__} is not defined, the statement \code{from Sound.Effects
+If \code{__all__} is not defined, the statement \code{from sound.effects
 import *} does \emph{not} import all submodules from the package
-\module{Sound.Effects} into the current namespace; it only ensures that the
-package \module{Sound.Effects} has been imported (possibly running any
+\module{sound.effects} into the current namespace; it only ensures that the
+package \module{sound.effects} has been imported (possibly running any
 initialization code in \file{__init__.py}) and then imports whatever names are
 defined in the package.  This includes any names defined (and
 submodules explicitly loaded) by \file{__init__.py}.  It also includes any
@@ -2869,14 +2869,14 @@ submodules of the package that were explicitly loaded by previous
 import statements.  Consider this code:
 
 \begin{verbatim}
-import Sound.Effects.echo
-import Sound.Effects.surround
-from Sound.Effects import *
+import sound.effects.echo
+import sound.effects.surround
+from sound.effects import *
 \end{verbatim}
 
 In this example, the echo and surround modules are imported in the
 current namespace because they are defined in the
-\module{Sound.Effects} package when the \code{from...import} statement
+\module{sound.effects} package when the \code{from...import} statement
 is executed.  (This also works when \code{__all__} is defined.)
 
 Note that in general the practice of importing \code{*} from a module or
@@ -2904,12 +2904,12 @@ which the current module is a submodule), the \keyword{import}
 statement looks for a top-level module with the given name.
 
 When packages are structured into subpackages (as with the
-\module{Sound} package in the example), there's no shortcut to refer
+\module{sound} package in the example), there's no shortcut to refer
 to submodules of sibling packages - the full name of the subpackage
 must be used.  For example, if the module
-\module{Sound.Filters.vocoder} needs to use the \module{echo} module
-in the \module{Sound.Effects} package, it can use \code{from
-Sound.Effects import echo}.
+\module{sound.filters.vocoder} needs to use the \module{echo} module
+in the \module{sound.effects} package, it can use \code{from
+sound.effects import echo}.
 
 Starting with Python 2.5, in addition to the implicit relative imports
 described above, you can write explicit relative imports with the
@@ -2920,8 +2920,8 @@ module for example, you might use:
 
 \begin{verbatim}
 from . import echo
-from .. import Formats
-from ..Filters import equalizer
+from .. import formats
+from ..filters import equalizer
 \end{verbatim}
 
 Note that both explicit and implicit relative imports are based on the
index a40c10099754bf6ec31cccb31e5d9cc123b337b7..5d2373f79d642cf0c1c8398303072e6c6359dc8c 100644 (file)
@@ -53,7 +53,7 @@
 \tableofcontents
 
 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 late 2007.
+for Python 2.6 has been set; it will probably be released in mid 2008.
 
 % Compare with previous release in 2 - 3 sentences here.
 
index 661c28821c1c40466e410462a0fae05122848af9..23bff6d673b599e0dd753104ca5d0e79d2a362cc 100644 (file)
@@ -851,6 +851,14 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
         expression: o1 |= o2.
        */
 
+     PyAPI_FUNC(PyObject *) PyNumber_ToBase(PyObject *n, int base);
+
+       /*
+        Returns the integer n converted to a string with a base, with a base
+        marker of 0b, 0o or 0x prefixed if applicable.
+        If n is not an int object, it is converted with PyNumber_Index first.
+       */
+
 
 /*  Sequence protocol:*/
 
index 9ec19022804cdd54ce9cef5ba8e2ddfea2083cf2..e8981eb182d3d49bb35a66478c5650e29bc8a210 100644 (file)
@@ -109,6 +109,11 @@ PyAPI_FUNC(int) _PyLong_AsByteArray(PyLongObject* v,
        unsigned char* bytes, size_t n,
        int little_endian, int is_signed);
 
+
+/* _PyLong_Format: Convert the long to a string object with given base,
+   appending a base prefix of 0[box] if base is 2, 8 or 16. */
+PyAPI_FUNC(PyObject *) _PyLong_Format(PyObject *aa, int base);
+
 #ifdef __cplusplus
 }
 #endif
index fbeb91572ab79d00ce401c85e70bd5c7ba77f492..46f4ce6221e85922a746b8e5aa7c3829d103da98 100644 (file)
@@ -171,6 +171,7 @@ typedef struct {
        unaryfunc nb_int;
        unaryfunc nb_long;
        unaryfunc nb_float;
+       /* NB: nb_oct and nb_hex are not used anymore. */
        unaryfunc nb_oct;
        unaryfunc nb_hex;
 
index 1f7b2ca06b5c833b0a3421ee9acb45369052f053..1eacbaff8f02db5949ac214797028d81c3e515eb 100644 (file)
@@ -105,7 +105,6 @@ PyAPI_DATA(PyObject *) PyExc_BaseException;
 PyAPI_DATA(PyObject *) PyExc_Exception;
 PyAPI_DATA(PyObject *) PyExc_StopIteration;
 PyAPI_DATA(PyObject *) PyExc_GeneratorExit;
-PyAPI_DATA(PyObject *) PyExc_StandardError;
 PyAPI_DATA(PyObject *) PyExc_ArithmeticError;
 PyAPI_DATA(PyObject *) PyExc_LookupError;
 
index 92ce3aec5e665618e79c5cd01dd0406491b29c2f..febc21ee5e555bb1a1a5b5fcc6d01fd17d68d84e 100644 (file)
@@ -50,6 +50,22 @@ Used in:  PY_LONG_LONG
 #ifdef HAVE_LONG_LONG
 #ifndef PY_LONG_LONG
 #define PY_LONG_LONG long long
+#if defined(LLONG_MAX)
+/* If LLONG_MAX is defined in limits.h, use that. */
+#define PY_LLONG_MIN LLONG_MIN
+#define PY_LLONG_MAX LLONG_MAX
+#define PY_ULLONG_MAX ULLONG_MAX
+#elif defined(__LONG_LONG_MAX__)
+/* Otherwise, if GCC has a builtin define, use that. */
+#define PY_LLONG_MAX __LONG_LONG_MAX__
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
+#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
+#else
+/* Otherwise, rely on two's complement. */
+#define PY_ULLONG_MAX (~0ULL)
+#define PY_LLONG_MAX  ((long long)(PY_ULLONG_MAX>>1))
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)
+#endif /* LLONG_MAX */
 #endif
 #endif /* HAVE_LONG_LONG */
 
index 5017eec7aa3d14c466cef4e8c6b4e67dcb37e882..a2d809c14c644a5bb08db1bab9a1e08dade4b261 100644 (file)
@@ -353,7 +353,7 @@ def executable(path):
         st = os.stat(path)
     except os.error:
         return False
-    return st.st_mode & 0111 != 0
+    return st.st_mode & 0o111 != 0
 
 
 def test(HandlerClass = CGIHTTPRequestHandler,
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py
new file mode 100644 (file)
index 0000000..cd1c9ce
--- /dev/null
@@ -0,0 +1,535 @@
+# Copyright 2007 Google, Inc. All Rights Reserved.
+# Licensed to PSF under a Contributor Agreement.
+
+"""Abstract Base Classes (ABCs) for collections, according to PEP 3119.
+
+DON'T USE THIS MODULE DIRECTLY!  The classes here should be imported
+via collections; they are defined here only to alleviate ceratin
+bootstrapping issues.  Unit tests are in test_collections.
+"""
+
+from abc import ABCMeta, abstractmethod
+
+__all__ = ["Hashable", "Iterable", "Iterator",
+           "Sized", "Container", "Callable",
+           "Set", "MutableSet",
+           "Mapping", "MutableMapping",
+           "MappingView", "KeysView", "ItemsView", "ValuesView",
+           "Sequence", "MutableSequence",
+           ]
+
+### ONE-TRICK PONIES ###
+
+class Hashable(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __hash__(self):
+        return 0
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Hashable:
+            for B in C.__mro__:
+                if "__hash__" in B.__dict__:
+                    if B.__dict__["__hash__"]:
+                        return True
+                    break
+        return NotImplemented
+
+
+class Iterable(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __iter__(self):
+        while False:
+            yield None
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Iterable:
+            if any("__iter__" in B.__dict__ for B in C.__mro__):
+                return True
+        return NotImplemented
+
+Iterable.register(bytes)
+
+
+class Iterator(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __next__(self):
+        raise StopIteration
+
+    def __iter__(self):
+        return self
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Iterator:
+            if any("__next__" in B.__dict__ for B in C.__mro__):
+                return True
+        return NotImplemented
+
+
+class Sized(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __len__(self):
+        return 0
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Sized:
+            if any("__len__" in B.__dict__ for B in C.__mro__):
+                return True
+        return NotImplemented
+
+
+class Container(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __contains__(self, x):
+        return False
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Container:
+            if any("__contains__" in B.__dict__ for B in C.__mro__):
+                return True
+        return NotImplemented
+
+
+class Callable(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __contains__(self, x):
+        return False
+
+    @classmethod
+    def __subclasshook__(cls, C):
+        if cls is Callable:
+            if any("__call__" in B.__dict__ for B in C.__mro__):
+                return True
+        return NotImplemented
+
+
+### SETS ###
+
+
+class Set(metaclass=ABCMeta):
+
+    """A set is a finite, iterable container.
+
+    This class provides concrete generic implementations of all
+    methods except for __contains__, __iter__ and __len__.
+
+    To override the comparisons (presumably for speed, as the
+    semantics are fixed), all you have to do is redefine __le__ and
+    then the other operations will automatically follow suit.
+    """
+
+    @abstractmethod
+    def __contains__(self, value):
+        return False
+
+    @abstractmethod
+    def __iter__(self):
+        while False:
+            yield None
+
+    @abstractmethod
+    def __len__(self):
+        return 0
+
+    def __le__(self, other):
+        if not isinstance(other, Set):
+            return NotImplemented
+        if len(self) > len(other):
+            return False
+        for elem in self:
+            if elem not in other:
+                return False
+        return True
+
+    def __lt__(self, other):
+        if not isinstance(other, Set):
+            return NotImplemented
+        return len(self) < len(other) and self.__le__(other)
+
+    def __eq__(self, other):
+        if not isinstance(other, Set):
+            return NotImplemented
+        return len(self) == len(other) and self.__le__(other)
+
+    @classmethod
+    def _from_iterable(cls, it):
+        return frozenset(it)
+
+    def __and__(self, other):
+        if not isinstance(other, Iterable):
+            return NotImplemented
+        return self._from_iterable(value for value in other if value in self)
+
+    def __or__(self, other):
+        if not isinstance(other, Iterable):
+            return NotImplemented
+        return self._from_iterable(itertools.chain(self, other))
+
+    def __sub__(self, other):
+        if not isinstance(other, Set):
+            if not isinstance(other, Iterable):
+                return NotImplemented
+            other = self._from_iterable(other)
+        return self._from_iterable(value for value in self
+                                   if value not in other)
+
+    def __xor__(self, other):
+        if not isinstance(other, Set):
+            if not isinstance(other, Iterable):
+                return NotImplemented
+            other = self._from_iterable(other)
+        return (self - other) | (other - self)
+
+    def _hash(self):
+        """Compute the hash value of a set.
+
+        Note that we don't define __hash__: not all sets are hashable.
+        But if you define a hashable set type, its __hash__ should
+        call this function.
+
+        This must be compatible __eq__.
+
+        All sets ought to compare equal if they contain the same
+        elements, regardless of how they are implemented, and
+        regardless of the order of the elements; so there's not much
+        freedom for __eq__ or __hash__.  We match the algorithm used
+        by the built-in frozenset type.
+        """
+        MAX = sys.maxint
+        MASK = 2 * MAX + 1
+        n = len(self)
+        h = 1927868237 * (n + 1)
+        h &= MASK
+        for x in self:
+            hx = hash(x)
+            h ^= (hx ^ (hx << 16) ^ 89869747)  * 3644798167
+            h &= MASK
+        h = h * 69069 + 907133923
+        h &= MASK
+        if h > MAX:
+            h -= MASK + 1
+        if h == -1:
+            h = 590923713
+        return h
+
+Set.register(frozenset)
+
+
+class MutableSet(Set):
+
+    @abstractmethod
+    def add(self, value):
+        """Return True if it was added, False if already there."""
+        raise NotImplementedError
+
+    @abstractmethod
+    def discard(self, value):
+        """Return True if it was deleted, False if not there."""
+        raise NotImplementedError
+
+    def pop(self):
+        """Return the popped value.  Raise KeyError if empty."""
+        it = iter(self)
+        try:
+            value = it.__next__()
+        except StopIteration:
+            raise KeyError
+        self.discard(value)
+        return value
+
+    def toggle(self, value):
+        """Return True if it was added, False if deleted."""
+        # XXX This implementation is not thread-safe
+        if value in self:
+            self.discard(value)
+            return False
+        else:
+            self.add(value)
+            return True
+
+    def clear(self):
+        """This is slow (creates N new iterators!) but effective."""
+        try:
+            while True:
+                self.pop()
+        except KeyError:
+            pass
+
+    def __ior__(self, it: Iterable):
+        for value in it:
+            self.add(value)
+        return self
+
+    def __iand__(self, c: Container):
+        for value in self:
+            if value not in c:
+                self.discard(value)
+        return self
+
+    def __ixor__(self, it: Iterable):
+        # This calls toggle(), so if that is overridded, we call the override
+        for value in it:
+            self.toggle(it)
+        return self
+
+    def __isub__(self, it: Iterable):
+        for value in it:
+            self.discard(value)
+        return self
+
+MutableSet.register(set)
+
+
+### MAPPINGS ###
+
+
+class Mapping(metaclass=ABCMeta):
+
+    @abstractmethod
+    def __getitem__(self, key):
+        raise KeyError
+
+    def get(self, key, default=None):
+        try:
+            return self[key]
+        except KeyError:
+            return default
+
+    def __contains__(self, key):
+        try:
+            self[key]
+        except KeyError:
+            return False
+        else:
+            return True
+
+    @abstractmethod
+    def __len__(self):
+        return 0
+
+    @abstractmethod
+    def __iter__(self):
+        while False:
+            yield None
+
+    def keys(self):
+        return KeysView(self)
+
+    def items(self):
+        return ItemsView(self)
+
+    def values(self):
+        return ValuesView(self)
+
+
+class MappingView(metaclass=ABCMeta):
+
+    def __init__(self, mapping):
+        self._mapping = mapping
+
+    def __len__(self):
+        return len(self._mapping)
+
+
+class KeysView(MappingView, Set):
+
+    def __contains__(self, key):
+        return key in self._mapping
+
+    def __iter__(self):
+        for key in self._mapping:
+            yield key
+
+KeysView.register(type({}.keys()))
+
+
+class ItemsView(MappingView, Set):
+
+    def __contains__(self, item):
+        key, value = item
+        try:
+            v = self._mapping[key]
+        except KeyError:
+            return False
+        else:
+            return v == value
+
+    def __iter__(self):
+        for key in self._mapping:
+            yield (key, self._mapping[key])
+
+ItemsView.register(type({}.items()))
+
+
+class ValuesView(MappingView):
+
+    def __contains__(self, value):
+        for key in self._mapping:
+            if value == self._mapping[key]:
+                return True
+        return False
+
+    def __iter__(self):
+        for key in self._mapping:
+            yield self._mapping[key]
+
+ValuesView.register(type({}.values()))
+
+
+class MutableMapping(Mapping):
+
+    @abstractmethod
+    def __setitem__(self, key, value):
+        raise KeyError
+
+    @abstractmethod
+    def __delitem__(self, key):
+        raise KeyError
+
+    __marker = object()
+
+    def pop(self, key, default=__marker):
+        try:
+            value = self[key]
+        except KeyError:
+            if default is self.__marker:
+                raise
+            return default
+        else:
+            del self[key]
+            return value
+
+    def popitem(self):
+        try:
+            key = next(iter(self))
+        except StopIteration:
+            raise KeyError
+        value = self[key]
+        del self[key]
+        return key, value
+
+    def clear(self):
+        try:
+            while True:
+                self.popitem()
+        except KeyError:
+            pass
+
+    def update(self, other=(), **kwds):
+        if isinstance(other, Mapping):
+            for key in other:
+                self[key] = other[key]
+        elif hasattr(other, "keys"):
+            for key in other.keys():
+                self[key] = other[key]
+        else:
+            for key, value in other:
+                self[key] = value
+        for key, value in kwds.items():
+            self[key] = value
+
+MutableMapping.register(dict)
+
+
+### SEQUENCES ###
+
+
+class Sequence(metaclass=ABCMeta):
+
+    """All the operations on a read-only sequence.
+
+    Concrete subclasses must override __new__ or __init__,
+    __getitem__, and __len__.
+    """
+
+    @abstractmethod
+    def __getitem__(self, index):
+        raise IndexError
+
+    @abstractmethod
+    def __len__(self):
+        return 0
+
+    def __iter__(self):
+        i = 0
+        while True:
+            try:
+                v = self[i]
+            except IndexError:
+                break
+            yield v
+            i += 1
+
+    def __contains__(self, value):
+        for v in self:
+            if v == value:
+                return True
+        return False
+
+    def __reversed__(self):
+        for i in reversed(range(len(self))):
+            yield self[i]
+
+    def index(self, value):
+        for i, v in enumerate(self):
+            if v == value:
+                return i
+        raise ValueError
+
+    def count(self, value):
+        return sum(1 for v in self if v == value)
+
+Sequence.register(tuple)
+Sequence.register(basestring)
+Sequence.register(buffer)
+
+
+class MutableSequence(Sequence):
+
+    @abstractmethod
+    def __setitem__(self, index, value):
+        raise IndexError
+
+    @abstractmethod
+    def __delitem__(self, index):
+        raise IndexError
+
+    @abstractmethod
+    def insert(self, index, value):
+        raise IndexError
+
+    def append(self, value):
+        self.insert(len(self), value)
+
+    def reverse(self):
+        n = len(self)
+        for i in range(n//2):
+            self[i], self[n-i-1] = self[n-i-1], self[i]
+
+    def extend(self, values):
+        for v in values:
+            self.append(v)
+
+    def pop(self, index=-1):
+        v = self[index]
+        del self[index]
+        return v
+
+    def remove(self, value):
+        del self[self.index(value)]
+
+    def __iadd__(self, values):
+        self.extend(values)
+
+MutableSequence.register(list)
+MutableSequence.register(bytes)
index e5d2721ce072741b135976933bb89a7cfee7d47e..28ccac77b94adbc65c59f739d47f13d3937b557a 100644 (file)
@@ -107,7 +107,7 @@ class LocaleTime(object):
         # magical; just happened to have used it everywhere else where a
         # static date was needed.
         am_pm = []
-        for hour in (01,22):
+        for hour in (1, 22):
             time_tuple = time.struct_time((1999,3,17,hour,44,55,2,76,0))
             am_pm.append(time.strftime("%p", time_tuple).lower())
         self.am_pm = am_pm
@@ -186,7 +186,7 @@ class TimeRE(dict):
             self.locale_time = locale_time
         else:
             self.locale_time = LocaleTime()
-        base = super(TimeRE, self)
+        base = super()
         base.__init__({
             # The " \d" part of the regex is to make %c from ANSI C work
             'd': r"(?P<d>3[0-1]|[1-2]\d|0[1-9]|[1-9]| [1-9])",
@@ -250,7 +250,7 @@ class TimeRE(dict):
         regex_chars = re_compile(r"([\\.^$*+?\(\){}\[\]|])")
         format = regex_chars.sub(r"\\\1", format)
         whitespace_replacement = re_compile('\s+')
-        format = whitespace_replacement.sub('\s*', format)
+        format = whitespace_replacement.sub('\s+', format)
         while '%' in format:
             directive_index = format.index('%')+1
             processed_format = "%s%s%s" % (processed_format,
index 8b01ef3ea49113da3e054290c242fca3123e959c..89381841c0119e4fd2abb0eff2c06ec91bef7ce5 100644 (file)
@@ -3,7 +3,7 @@
 Instead of
 
         import dbm
-        d = dbm.open(file, 'w', 0666)
+        d = dbm.open(file, 'w', 0o666)
 
 use
 
@@ -63,7 +63,7 @@ if not _defaultmod:
 
 error = tuple(_errors)
 
-def open(file, flag = 'r', mode = 0666):
+def open(file, flag = 'r', mode = 0o666):
     # guess the type of an existing database
     from whichdb import whichdb
     result=whichdb(file)
index 3099bb305c18b1d5b88c5dc0e8b719b396334542..02df49918fba4d8f25439e43469283ed04c1ed48 100644 (file)
@@ -294,7 +294,7 @@ class _DBWithCursor(_iter_mixin):
 #----------------------------------------------------------------------
 # Compatibility object factory functions
 
-def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
+def hashopen(file, flag='c', mode=0o666, pgsize=None, ffactor=None, nelem=None,
             cachesize=None, lorder=None, hflags=0):
 
     flags = _checkflag(flag, file)
@@ -310,7 +310,7 @@ def hashopen(file, flag='c', mode=0666, pgsize=None, ffactor=None, nelem=None,
 
 #----------------------------------------------------------------------
 
-def btopen(file, flag='c', mode=0666,
+def btopen(file, flag='c', mode=0o666,
             btflags=0, cachesize=None, maxkeypage=None, minkeypage=None,
             pgsize=None, lorder=None):
 
@@ -328,7 +328,7 @@ def btopen(file, flag='c', mode=0666,
 #----------------------------------------------------------------------
 
 
-def rnopen(file, flag='c', mode=0666,
+def rnopen(file, flag='c', mode=0o666,
             rnflags=0, cachesize=None, pgsize=None, lorder=None,
             rlen=None, delim=None, source=None, pad=None):
 
index 8530c9a5b7719713a7197ff9259867d16e06f067..8eb7ed2201078c28b30792ea9fa88b3bb2fd3973 100644 (file)
@@ -40,7 +40,7 @@ from . import db
 #------------------------------------------------------------------------
 
 
-def open(filename, flags=db.DB_CREATE, mode=0660, filetype=db.DB_HASH,
+def open(filename, flags=db.DB_CREATE, mode=0o660, filetype=db.DB_HASH,
          dbenv=None, dbname=None):
     """
     A simple factory function for compatibility with the standard
index efc6062164212600be690820561c7a857a6bf5f6..97ea6a7bf898267159b7023b4b915d97267e2a40 100644 (file)
@@ -38,7 +38,7 @@ except NameError:
     class DBIncompleteError(Exception):
         pass
 
-class TableDBError(StandardError):
+class TableDBError(Exception):
     pass
 class TableAlreadyExists(TableDBError):
     pass
@@ -134,9 +134,9 @@ def contains_metastrings(s) :
 
 
 class bsdTableDB :
-    def __init__(self, filename, dbhome, create=0, truncate=0, mode=0600,
+    def __init__(self, filename, dbhome, create=0, truncate=0, mode=0o600,
                  recover=0, dbflags=0):
-        """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0600)
+        """bsdTableDB(filename, dbhome, create=0, truncate=0, mode=0o600)
 
         Open database name in the dbhome BerkeleyDB directory.
         Use keyword arguments when calling this constructor.
index 436f407867d6a7f517446da9f6da8df6e3b793ce..0a411dd12a86569a6a37c98ef8f6b5cde4d7cff8 100644 (file)
@@ -18,4 +18,4 @@ env.open(env_name, db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_MPOOL)
 the_txn = env.txn_begin()
 
 map = db.DB(env)
-map.open('xxx.db', "p", db.DB_HASH, db.DB_CREATE, 0666, txn=the_txn)
+map.open('xxx.db', "p", db.DB_HASH, db.DB_CREATE, 0o666, txn=the_txn)
index 381e2ffde671a0ada10c72357b8d71e6ad079b27..13f8ded29cf5c9ee97f73b60a91e961889c63149 100644 (file)
@@ -44,7 +44,7 @@ class BasicTestCase(unittest.TestCase):
     dbtype       = db.DB_UNKNOWN  # must be set in derived class
     dbopenflags  = 0
     dbsetflags   = 0
-    dbmode       = 0660
+    dbmode       = 0o660
     dbname       = None
     useEnv       = 0
     envflags     = 0
index 12e103746afbfa2c657010ecd0ae4d3950c165ba..1a6a8041209b6b44a2c5ee3b10ee1dddee977919 100644 (file)
@@ -50,10 +50,10 @@ class DBEnvClosedEarlyCrash(unittest.TestCase):
         dbenv = db.DBEnv()
         dbenv.open(self.homeDir,
                    db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
-                   0666)
+                   0o666)
 
         d = db.DB(dbenv)
-        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
+        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0o666)
 
         try:
             dbenv.close()
@@ -75,10 +75,10 @@ class DBEnvClosedEarlyCrash(unittest.TestCase):
         dbenv = db.DBEnv()
         dbenv.open(self.homeDir,
                    db.DB_INIT_CDB| db.DB_CREATE |db.DB_THREAD|db.DB_INIT_MPOOL,
-                   0666)
+                   0o666)
 
         d = db.DB(dbenv)
-        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0666)
+        d.open(self.filename, db.DB_BTREE, db.DB_CREATE | db.DB_THREAD, 0o666)
 
         try:
             dbenv.close()
index 48631a37e2ef7e607427039f656b51f1d3486286..350d926f6a2c09cd1c61e1256141f54893aad2d7 100644 (file)
@@ -26,9 +26,9 @@ class DBSequenceTest(unittest.TestCase):
         tempfile.tempdir = None
 
         self.dbenv = db.DBEnv()
-        self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0666)
+        self.dbenv.open(self.homeDir, db.DB_CREATE | db.DB_INIT_MPOOL, 0o666)
         self.d = db.DB(self.dbenv)
-        self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 0666)
+        self.d.open(self.filename, db.DB_BTREE, db.DB_CREATE, 0o666)
 
     def tearDown(self):
         if hasattr(self, 'seq'):
index 2cf9fe84c797f967aa1e30d274978ca42210c51c..b2d40d6399e3141bc36cbf0a3dcbc41dd94a10bf 100644 (file)
@@ -4,6 +4,13 @@ from _collections import deque, defaultdict
 from operator import itemgetter as _itemgetter
 import sys as _sys
 
+# For bootstrapping reasons, the collection ABCs are defined in _abcoll.py.
+# They should however be considered an integral part of collections.py.
+from _abcoll import *
+import _abcoll
+__all__ += _abcoll.__all__
+
+
 def NamedTuple(typename, s):
     """Returns a new subclass of tuple with named fields.
 
index b753a6b899fe36a322337a17b66fe0296607c7c7..8c9fe1a64968b8fa6292273390dea40a3b11a5f0 100644 (file)
@@ -149,7 +149,7 @@ class py_object(_SimpleCData):
     _type_ = "O"
     def __repr__(self):
         try:
-            return super(py_object, self).__repr__()
+            return super().__repr__()
         except ValueError:
             return "%s(<NULL>)" % type(self).__name__
 _check_size(py_object, "P")
index 61ac33475b41e814c97204e8d0a6670c2a41b440..138b248788d22215873462aee08bb3071602732d 100644 (file)
@@ -29,7 +29,7 @@ class _swapped_meta(type(Structure)):
                 rest = desc[2:]
                 fields.append((name, _other_endian(typ)) + rest)
             value = fields
-        super(_swapped_meta, self).__setattr__(attrname, value)
+        super().__setattr__(attrname, value)
 
 ################################################################
 
index 3d9dc92109b1dc7728150eca3584866d27082c61..e4dfe36f95c0db74c9e833c727691f851e0fc6a5 100644 (file)
@@ -7,7 +7,7 @@ class X(Structure):
     new_was_called = False
 
     def __new__(cls):
-        result = super(X, cls).__new__(cls)
+        result = super().__new__(cls)
         result.new_was_called = True
         return result
 
index eaabc7c2fb4170cbf3b05ae85ead4a2c694f38c1..2430ac87ceb047493c017478c49801e89cd5d37d 100644 (file)
@@ -117,7 +117,10 @@ class NumberTestCase(unittest.TestCase):
 
     def test_sizes(self):
         for t in signed_types + unsigned_types + float_types + bool_types:
-            size = struct.calcsize(t._type_)
+            try:
+                size = struct.calcsize(t._type_)
+            except struct.error:
+                continue
             # sizeof of the type...
             self.failUnlessEqual(sizeof(t), size)
             # and sizeof of an instance
index 9f8a9c3f28bb27e1d67a8bb8c3253feb31ecb894..3c60812a07b8bf660c7b0e94bd90ce58c5b2b480 100644 (file)
@@ -12,5 +12,5 @@ __all__ = ["error","open"]
 
 error = bsddb.error                     # Exported for anydbm
 
-def open(file, flag = 'r', mode=0666):
+def open(file, flag = 'r', mode=0o666):
     return bsddb.hashopen(file, flag, mode)
index 50905c1d44ca98b1b436c784ffb89a5a4e0d3ec0..d4f4adea19d60a917eb5ddab6c7146ce895964cc 100644 (file)
@@ -1040,7 +1040,7 @@ main (int argc, char **argv) {
     def move_file (self, src, dst):
         return move_file (src, dst, dry_run=self.dry_run)
 
-    def mkpath (self, name, mode=0777):
+    def mkpath (self, name, mode=0o777):
         mkpath (name, mode, self.dry_run)
 
 
index 8d77e7fb2be91cb0d4cd8f5cffaf3c515f6d99ce..b2c952c38c8ac453afed3116fde0ec63d9509d61 100644 (file)
@@ -356,7 +356,7 @@ class Command:
         util.execute(func, args, msg, dry_run=self.dry_run)
 
 
-    def mkpath (self, name, mode=0777):
+    def mkpath (self, name, mode=0o777):
         dir_util.mkpath(name, mode, dry_run=self.dry_run)
 
 
index 52534bdb475c53600fa99ac7be06ea318c0bef32..8f5609084ca5be6243470008e38b2c0266324f60 100644 (file)
@@ -114,7 +114,9 @@ class build_py (Command):
             build_dir = os.path.join(*([self.build_lib] + package.split('.')))
 
             # Length of path to strip from found files
-            plen = len(src_dir)+1
+            plen = 0
+            if src_dir:
+                plen = len(src_dir)+1
 
             # Strip directory from globbed filenames
             filenames = [
index bda4480ca59e0b69d2aae172a2d2a153b4b6c673..511b82f9998a4af01bcf325045755445aeefa879 100644 (file)
@@ -119,8 +119,8 @@ class build_scripts (Command):
                 if self.dry_run:
                     log.info("changing mode of %s", file)
                 else:
-                    oldmode = os.stat(file)[ST_MODE] & 07777
-                    newmode = (oldmode | 0555) & 07777
+                    oldmode = os.stat(file)[ST_MODE] & 0o7777
+                    newmode = (oldmode | 0o555) & 0o7777
                     if newmode != oldmode:
                         log.info("changing mode of %s from %o to %o",
                                  file, oldmode, newmode)
index fe93ef5af2374dcc415c77c063f37321d9eb36d7..da2da358bad2dcb1d3b1ff67cdff5c09dcca7a47 100644 (file)
@@ -53,7 +53,7 @@ class install_scripts (Command):
                 if self.dry_run:
                     log.info("changing mode of %s", file)
                 else:
-                    mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777
+                    mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o7777
                     log.info("changing mode of %s to %o", file, mode)
                     os.chmod(file, mode)
 
index 2ddabadf8810b8e5c4ed160d1a3952ee2f4d4a0a..53f4293e1777f090532b6290f3067ed9b56d881a 100644 (file)
@@ -183,7 +183,7 @@ Your selection [default 1]: ''', end=' ')
                         username, password))
                     f.close()
                     try:
-                        os.chmod(rc, 0600)
+                        os.chmod(rc, 0o600)
                     except:
                         pass
         elif choice == '2':
index c6f014b2609bd7f89297285637c7f929e08a68e8..0cfca2e8ffc5deca2306db3732c95281863ed955 100644 (file)
@@ -18,7 +18,7 @@ _path_created = {}
 # I don't use os.makedirs because a) it's new to Python 1.5.2, and
 # b) it blows up if the directory already exists (I want to silently
 # succeed in that case).
-def mkpath (name, mode=0777, verbose=0, dry_run=0):
+def mkpath (name, mode=0o777, verbose=0, dry_run=0):
     """Create a directory and any missing ancestor directories.  If the
        directory already exists (or if 'name' is the empty string, which
        means the current directory, which of course exists), then do
@@ -85,7 +85,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
 # mkpath ()
 
 
-def create_tree (base_dir, files, mode=0777, verbose=0, dry_run=0):
+def create_tree (base_dir, files, mode=0o777, verbose=0, dry_run=0):
 
     """Create all the empty directories under 'base_dir' needed to
        put 'files' there.  'base_dir' is just the a name of a directory
index 028ea8250d267a27279447f4662fb11683038025..662046ae22345673cc344aa299b40e36f49abf90 100644 (file)
@@ -18,7 +18,6 @@ from distutils.ccompiler import \
 import distutils.util
 import distutils.dir_util
 from distutils import log
-import mkcwproject
 
 class MWerksCompiler (CCompiler) :
     """Concrete class that implements an interface to MetroWerks CodeWarrior,
@@ -188,6 +187,7 @@ class MWerksCompiler (CCompiler) :
         # doesn't have a clue about our working directory.
         xmlfilename = os.path.join(os.getcwd(), os.path.join(build_temp, xmlname))
         log.debug("\tCreate XML file %s", xmlfilename)
+        import mkcwproject
         xmlbuilder = mkcwproject.cwxmlgen.ProjectBuilder(settings)
         xmlbuilder.generate()
         xmldata = settings['tmp_projectxmldata']
index 475ceee598bd76cdc6f13b5bd9257614f235c75d..91e704cfcc2ab61a78d402a8cd8a2ff271217a21 100644 (file)
@@ -9,12 +9,12 @@ from distutils import log
 class LoggingSilencer(object):
 
     def setUp(self):
-        super(LoggingSilencer, self).setUp()
+        super().setUp()
         self.threshold = log.set_threshold(log.FATAL)
 
     def tearDown(self):
         log.set_threshold(self.threshold)
-        super(LoggingSilencer, self).tearDown()
+        super().tearDown()
 
 
 class TempdirManager(object):
@@ -24,11 +24,11 @@ class TempdirManager(object):
     """
 
     def setUp(self):
-        super(TempdirManager, self).setUp()
+        super().setUp()
         self.tempdirs = []
 
     def tearDown(self):
-        super(TempdirManager, self).tearDown()
+        super().tearDown()
         while self.tempdirs:
             d = self.tempdirs.pop()
             shutil.rmtree(d)
index 78e4c55ed4839584137731b9006f29be631af8a4..54a4ed80fd30bc3a20c370ba7c51b7d0cddf1d31 100644 (file)
@@ -1,10 +1,13 @@
 """Tests for distutils.command.build_py."""
 
 import os
+import sys
+import StringIO
 import unittest
 
 from distutils.command.build_py import build_py
 from distutils.core import Distribution
+from distutils.errors import DistutilsFileError
 
 from distutils.tests import support
 
@@ -53,6 +56,38 @@ class BuildPyTestCase(support.TempdirManager,
         self.assert_("__init__.pyc" in files)
         self.assert_("README.txt" in files)
 
+    def test_empty_package_dir (self):
+        # See SF 1668596/1720897.
+        cwd = os.getcwd()
+
+        # create the distribution files.
+        sources = self.mkdtemp()
+        open(os.path.join(sources, "__init__.py"), "w").close()
+
+        testdir = os.path.join(sources, "doc")
+        os.mkdir(testdir)
+        open(os.path.join(testdir, "testfile"), "w").close()
+
+        os.chdir(sources)
+        sys.stdout = StringIO.StringIO()
+
+        try:
+            dist = Distribution({"packages": ["pkg"],
+                                 "package_dir": {"pkg": ""},
+                                 "package_data": {"pkg": ["doc/*"]}})
+            # script_name need not exist, it just need to be initialized
+            dist.script_name = os.path.join(sources, "setup.py")
+            dist.script_args = ["build"]
+            dist.parse_command_line()
+
+            try:
+                dist.run_commands()
+            except DistutilsFileError:
+                self.fail("failed package_data test when package_dir is ''")
+        finally:
+            # Restore state.
+            os.chdir(cwd)
+            sys.stdout = sys.__stdout__
 
 def test_suite():
     return unittest.makeSuite(BuildPyTestCase)
index eb1c613324764e67ffd78fc7b01d7509f7836cb1..aaa16802a59d49ce721513c8a0801030a7e4fc17 100644 (file)
@@ -220,7 +220,7 @@ class _Database(UserDict.DictMixin):
             self._os.chmod(file, self._mode)
 
 
-def open(file, flag=None, mode=0666):
+def open(file, flag=None, mode=0o666):
     """Open the database file, filename, and return corresponding object.
 
     The flag argument, used to control how the database is opened in the
@@ -229,7 +229,7 @@ def open(file, flag=None, mode=0666):
     not exist.
 
     The optional mode argument is the UNIX mode of the file, used only when
-    the database has to be created.  It defaults to octal code 0666 (and
+    the database has to be created.  It defaults to octal code 0o666 (and
     will be modified by the prevailing umask).
 
     """
index cdc893b537540588b7c50c02828d8b7263bb5ab8..4838c15ed345f7268730cd6a81109f8d7f2f8bbd 100644 (file)
@@ -319,9 +319,7 @@ class FTP:
         size = None
         if self.passiveserver:
             host, port = self.makepasv()
-            af, socktype, proto, canon, sa = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0]
-            conn = socket.socket(af, socktype, proto)
-            conn.connect(sa)
+            conn = socket.create_connection((host, port), self.timeout)
             if rest is not None:
                 self.sendcmd("REST %s" % rest)
             resp = self.sendcmd(cmd)
index 6d99ec17b3fe8b9dba3ea40a1128fab693ae291e..a0099a86e86591f537a68fb0a39938b401a63666 100644 (file)
@@ -476,7 +476,7 @@ def _os_path_isdir(pathname):
         s = _os_stat(pathname)
     except OSError:
         return None
-    return (s.st_mode & 0170000) == 0040000
+    return (s.st_mode & 0o170000) == 0o040000
 
 def _timestamp(pathname):
     "Return the file modification time as a Long."
index a3daf01e8acb617e74b748f2053be13975dc1ab7..b9f4497d022dfebd65f5f432d867cb2ae9f62b21 100755 (executable)
@@ -227,10 +227,10 @@ class Maildir(Mailbox):
         Mailbox.__init__(self, dirname, factory, create)
         if not os.path.exists(self._path):
             if create:
-                os.mkdir(self._path, 0700)
-                os.mkdir(os.path.join(self._path, 'tmp'), 0700)
-                os.mkdir(os.path.join(self._path, 'new'), 0700)
-                os.mkdir(os.path.join(self._path, 'cur'), 0700)
+                os.mkdir(self._path, 0o700)
+                os.mkdir(os.path.join(self._path, 'tmp'), 0o700)
+                os.mkdir(os.path.join(self._path, 'new'), 0o700)
+                os.mkdir(os.path.join(self._path, 'cur'), 0o700)
             else:
                 raise NoSuchMailboxError(self._path)
         self._toc = {}
@@ -802,9 +802,9 @@ class MH(Mailbox):
         Mailbox.__init__(self, path, factory, create)
         if not os.path.exists(self._path):
             if create:
-                os.mkdir(self._path, 0700)
+                os.mkdir(self._path, 0o700)
                 os.close(os.open(os.path.join(self._path, '.mh_sequences'),
-                                 os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0600))
+                                 os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600))
             else:
                 raise NoSuchMailboxError(self._path)
         self._locked = False
index eecb447a131abc97709b9ff100a9f6ea9f904511..4b3202091216ce81d32e73406040ca694e298b20 100644 (file)
@@ -67,7 +67,7 @@ s = m.getbodytext(0)    # text of message's body, not decoded
 MH_PROFILE = '~/.mh_profile'
 PATH = '~/Mail'
 MH_SEQUENCES = '.mh_sequences'
-FOLDER_PROTECT = 0700
+FOLDER_PROTECT = 0o700
 
 
 # Imported modules
index d2a305ef7bd6839f2d331e7b8a548e2e8d5c0df6..e47ec99224a72fac9042c2ef88548f092e9ae54f 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -147,8 +147,8 @@ SEEK_END = 2
 # Super directory utilities.
 # (Inspired by Eric Raymond; the doc strings are mostly his)
 
-def makedirs(name, mode=0777):
-    """makedirs(path [, mode=0777])
+def makedirs(name, mode=0o777):
+    """makedirs(path [, mode=0o777])
 
     Super-mkdir; create a leaf directory and all intermediate ones.
     Works like mkdir, except that any intermediate path segment (not
@@ -405,108 +405,63 @@ def _execvpe(file, args, env=None):
         raise error, saved_exc, saved_tb
     raise error, last_exc, tb
 
-# Change environ to automatically call putenv() if it exists
-try:
-    # This will fail if there's no putenv
-    putenv
-except NameError:
-    pass
+
+if name == "riscos":
+    # On RISC OS, all env access goes through getenv and putenv
+    from riscosenviron import _Environ
 else:
-    import UserDict
-
-    # Fake unsetenv() for Windows
-    # not sure about os2 here but
-    # I'm guessing they are the same.
-
-    if name in ('os2', 'nt'):
-        def unsetenv(key):
-            putenv(key, "")
-
-    if name == "riscos":
-        # On RISC OS, all env access goes through getenv and putenv
-        from riscosenviron import _Environ
-    elif name in ('os2', 'nt'):  # Where Env Var Names Must Be UPPERCASE
-        # But we store them as upper case
-        class _Environ(UserDict.IterableUserDict):
-            def __init__(self, environ):
-                UserDict.UserDict.__init__(self)
-                data = self.data
-                for k, v in environ.items():
-                    data[k.upper()] = v
-            def __setitem__(self, key, item):
-                putenv(key, item)
-                self.data[key.upper()] = item
-            def __getitem__(self, key):
-                return self.data[key.upper()]
-            try:
-                unsetenv
-            except NameError:
-                def __delitem__(self, key):
-                    del self.data[key.upper()]
-            else:
-                def __delitem__(self, key):
-                    unsetenv(key)
-                    del self.data[key.upper()]
-            def __contains__(self, key):
-                return key.upper() in self.data
-            def get(self, key, failobj=None):
-                return self.data.get(key.upper(), failobj)
-            def update(self, dict=None, **kwargs):
-                if dict:
-                    try:
-                        keys = dict.keys()
-                    except AttributeError:
-                        # List of (key, value)
-                        for k, v in dict:
-                            self[k] = v
-                    else:
-                        # got keys
-                        # cannot use items(), since mappings
-                        # may not have them.
-                        for k in keys:
-                            self[k] = dict[k]
-                if kwargs:
-                    self.update(kwargs)
-            def copy(self):
-                return dict(self)
+    # Change environ to automatically call putenv(), unsetenv if they exist.
+    from _abcoll import MutableMapping  # Can't use collections (bootstrap)
+
+    class _Environ(MutableMapping):
+        def __init__(self, environ, keymap, putenv, unsetenv):
+            self.keymap = keymap
+            self.putenv = putenv
+            self.unsetenv = unsetenv
+            self.data = data = {}
+            for key, value in environ.items():
+                data[keymap(key)] = value
+        def __getitem__(self, key):
+            return self.data[self.keymap(key)]
+        def __setitem__(self, key, item):
+            self.putenv(key, item)
+            self.data[self.keymap(key)] = item
+        def __delitem__(self, key):
+            self.unsetenv(key)
+            del self.data[self.keymap(key)]
+        def __iter__(self):
+            for key in self.data:
+                yield key
+        def __len__(self):
+            return len(self.data)
+        def copy(self):
+            return dict(self)
+        def setdefault(self, key, value):
+            if key not in self:
+                self[key] = value
+            return self[key]
+
+    try:
+        _putenv = putenv
+    except NameError:
+        _putenv = lambda key, value: None
+    else:
+        __all__.append("putenv")
+
+    try:
+        _unsetenv = unsetenv
+    except NameError:
+        _unsetenv = lambda key: _putenv(key, "")
+    else:
+        __all__.append("unsetenv")
 
+    if name in ('os2', 'nt'): # Where Env Var Names Must Be UPPERCASE
+        _keymap = lambda key: key.upper()
     else:  # Where Env Var Names Can Be Mixed Case
-        class _Environ(UserDict.IterableUserDict):
-            def __init__(self, environ):
-                UserDict.UserDict.__init__(self)
-                self.data = environ
-            def __setitem__(self, key, item):
-                putenv(key, item)
-                self.data[key] = item
-            def update(self,  dict=None, **kwargs):
-                if dict:
-                    try:
-                        keys = dict.keys()
-                    except AttributeError:
-                        # List of (key, value)
-                        for k, v in dict:
-                            self[k] = v
-                    else:
-                        # got keys
-                        # cannot use items(), since mappings
-                        # may not have them.
-                        for k in keys:
-                            self[k] = dict[k]
-                if kwargs:
-                    self.update(kwargs)
-            try:
-                unsetenv
-            except NameError:
-                pass
-            else:
-                def __delitem__(self, key):
-                    unsetenv(key)
-                    del self.data[key]
-            def copy(self):
-                return dict(self)
-
-
-    environ = _Environ(environ)
+        _keymap = lambda key: key
+
+    environ = _Environ(environ, _keymap, _putenv, _unsetenv)
+
 
 def getenv(key, default=None):
     """Get an environment variable, return None if it doesn't exist.
index 4894495cce188104c42da162d9bc6e3df81f82b6..9e77efc75c6e33cc8498048c5a4c801daddebbb9 100644 (file)
@@ -557,7 +557,7 @@ _DIRENT_H = 1
 # Included from bits/dirent.h
 def _D_ALLOC_NAMLEN(d): return (_D_EXACT_NAMLEN (d) + 1)
 
-def IFTODT(mode): return (((mode) & 0170000) >> 12)
+def IFTODT(mode): return (((mode) & 0o170000) >> 12)
 
 def DTTOIF(dirtype): return ((dirtype) << 12)
 
@@ -567,17 +567,17 @@ MAXNAMLEN = NAME_MAX
 MAXNAMLEN = 255
 
 # Included from posix/stat.h
-S_IFMT = 00170000
-S_IFSOCK = 0140000
-S_IFLNK = 0120000
-S_IFREG = 0100000
-S_IFBLK = 0060000
-S_IFDIR = 0040000
-S_IFCHR = 0020000
-S_IFIFO = 0010000
-S_ISUID = 0004000
-S_ISGID = 0002000
-S_ISVTX = 0001000
+S_IFMT = 0o0170000
+S_IFSOCK = 0o140000
+S_IFLNK = 0o120000
+S_IFREG = 0o100000
+S_IFBLK = 0o060000
+S_IFDIR = 0o040000
+S_IFCHR = 0o020000
+S_IFIFO = 0o010000
+S_ISUID = 0o004000
+S_ISGID = 0o002000
+S_ISVTX = 0o001000
 def S_ISLNK(m): return (((m) & S_IFMT) == S_IFLNK)
 
 def S_ISREG(m): return (((m) & S_IFMT) == S_IFREG)
@@ -592,18 +592,18 @@ def S_ISFIFO(m): return (((m) & S_IFMT) == S_IFIFO)
 
 def S_ISSOCK(m): return (((m) & S_IFMT) == S_IFSOCK)
 
-S_IRWXU = 00700
-S_IRUSR = 00400
-S_IWUSR = 00200
-S_IXUSR = 00100
-S_IRWXG = 00070
-S_IRGRP = 00040
-S_IWGRP = 00020
-S_IXGRP = 00010
-S_IRWXO = 00007
-S_IROTH = 00004
-S_IWOTH = 00002
-S_IXOTH = 00001
+S_IRWXU = 0o0700
+S_IRUSR = 0o0400
+S_IWUSR = 0o0200
+S_IXUSR = 0o0100
+S_IRWXG = 0o0070
+S_IRGRP = 0o0040
+S_IWGRP = 0o0020
+S_IXGRP = 0o0010
+S_IRWXO = 0o0007
+S_IROTH = 0o0004
+S_IWOTH = 0o0002
+S_IXOTH = 0o0001
 S_IRWXUGO = (S_IRWXU|S_IRWXG|S_IRWXO)
 S_IALLUGO = (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
 S_IRUGO = (S_IRUSR|S_IRGRP|S_IROTH)
@@ -612,24 +612,24 @@ S_IXUGO = (S_IXUSR|S_IXGRP|S_IXOTH)
 _STAT_VER_KERNEL = 0
 
 # Included from posix/fcntl.h
-O_ACCMODE = 0003
+O_ACCMODE = 0o003
 O_RWMASK = O_ACCMODE
 O_RDONLY = 00
-O_WRONLY = 01
-O_RDWR = 02
-O_CREAT = 0100
-O_EXCL = 0200
-O_NOCTTY = 0400
-O_TRUNC = 01000
-O_APPEND = 02000
-O_NONBLOCK = 04000
+O_WRONLY = 0o1
+O_RDWR = 0o2
+O_CREAT = 0o100
+O_EXCL = 0o200
+O_NOCTTY = 0o400
+O_TRUNC = 0o1000
+O_APPEND = 0o2000
+O_NONBLOCK = 0o4000
 O_NDELAY = O_NONBLOCK
-O_SYNC = 010000
+O_SYNC = 0o10000
 O_FSYNC = O_SYNC
-O_ASYNC = 020000
+O_ASYNC = 0o20000
 FASYNC = O_ASYNC
-O_DIRECTORY = 040000
-O_NOTRAVERSE = 0100000
+O_DIRECTORY = 0o40000
+O_NOTRAVERSE = 0o100000
 O_NOFOLLOW = O_NOTRAVERSE
 F_DUPFD = 0
 F_GETFD = 1
index 7ce8548cd4a0edb672abaf7207bfad644c5465c9..d7cbbce4a7256347a450b0fc58992b4159c3b826 100644 (file)
@@ -100,10 +100,10 @@ def pack(x, forcetype = None):
             data = data[2:]
         return AE.AECreateDesc('utxt', data)
     if isinstance(x, list):
-        list = AE.AECreateList('', 0)
+        lst = AE.AECreateList('', 0)
         for item in x:
-            list.AEPutDesc(0, pack(item))
-        return list
+            lst.AEPutDesc(0, pack(item))
+        return lst
     if isinstance(x, dict):
         record = AE.AECreateList('', 1)
         for key, value in x.items():
index bf11ed9fd5786651b25aac286b4b53ca21a09ff4..e833addb11b31cac10eb07f756c2c9fe0bb28e8d 100755 (executable)
@@ -504,7 +504,7 @@ class AppBuilder(BundleBuilder):
             standalone = self.standalone
             semi_standalone = self.semi_standalone
             open(bootstrappath, "w").write(BOOTSTRAP_SCRIPT % locals())
-            os.chmod(bootstrappath, 0775)
+            os.chmod(bootstrappath, 0o775)
 
         if self.iconfile is not None:
             iconbase = os.path.basename(self.iconfile)
@@ -603,7 +603,7 @@ class AppBuilder(BundleBuilder):
                         walk(path)
                     else:
                         mod = os.stat(path)[stat.ST_MODE]
-                        if not (mod & 0100):
+                        if not (mod & 0o100):
                             continue
                         relpath = path[len(self.bundlepath):]
                         self.message("Stripping %s" % relpath, 2)
index 27d2f83fce18db2c77aee7563ac904ee39054895..67d32e74ce2ca60b3c376984c600dff926cdc366 100644 (file)
@@ -61,7 +61,7 @@ def mkdirs(dst):
     if os.sep == ':' and not ':' in head:
         head = head + ':'
     mkdirs(head)
-    os.mkdir(dst, 0777)
+    os.mkdir(dst, 0o777)
 
 def touched(dst):
     """Tell the finder a file has changed. No-op on MacOSX."""
index 049b50bdc5bc64ba5a09f7f22acac45f3d4a301a..709e8e15fa1978380b911560ac930b9d980d30aa 100644 (file)
@@ -320,7 +320,7 @@ class Dict(_InternalDict):
         from warnings import warn
         warn("The plistlib.Dict class is deprecated, use builtin dict instead",
              PendingDeprecationWarning)
-        super(Dict, self).__init__(**kwargs)
+        super().__init__(**kwargs)
 
 
 class Plist(_InternalDict):
@@ -333,7 +333,7 @@ class Plist(_InternalDict):
         from warnings import warn
         warn("The Plist class is deprecated, use the readPlist() and "
              "writePlist() functions instead", PendingDeprecationWarning)
-        super(Plist, self).__init__(**kwargs)
+        super().__init__(**kwargs)
 
     def fromFile(cls, pathOrFile):
         """Deprecated. Use the readPlist() function instead."""
index 3a4971da12654b8c0937179bf6b71d2d824945c8..9572ead8a2213b815f97893b9e114b3d02e5931a 100755 (executable)
@@ -97,7 +97,7 @@ NGROUPS_MAX_DEFAULT = 16
 NZERO = 20
 NULL = 0
 NULL = 0
-CMASK = 022
+CMASK = 0o22
 CDLIMIT = (1<<11)
 NBPS = 0x20000
 NBPSCTR = 512
@@ -733,13 +733,13 @@ _SPARC_MAXREGWINDOW = 31
 _XRS_ID = 0x78727300
 GETCONTEXT = 0
 SETCONTEXT = 1
-UC_SIGMASK = 001
-UC_STACK = 002
-UC_CPU = 004
-UC_MAU = 010
+UC_SIGMASK = 0o01
+UC_STACK = 0o02
+UC_CPU = 0o04
+UC_MAU = 0o10
 UC_FPU = UC_MAU
-UC_INTR = 020
-UC_ASR = 040
+UC_INTR = 0o20
+UC_ASR = 0o40
 UC_MCONTEXT = (UC_CPU|UC_FPU|UC_ASR)
 UC_ALL = (UC_SIGMASK|UC_STACK|UC_MCONTEXT)
 _SIGQUEUE_MAX = 32
@@ -1021,14 +1021,14 @@ AT_STAT = (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
 AT_TIMES = (AT_ATIME|AT_MTIME|AT_CTIME)
 AT_NOSET = (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
                         AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-VSUID = 04000
-VSGID = 02000
-VSVTX = 01000
-VREAD = 00400
-VWRITE = 00200
-VEXEC = 00100
-MODEMASK = 07777
-PERMMASK = 00777
+VSUID = 0o4000
+VSGID = 0o2000
+VSVTX = 0o1000
+VREAD = 0o0400
+VWRITE = 0o0200
+VEXEC = 0o0100
+MODEMASK = 0o7777
+PERMMASK = 0o0777
 def MANDMODE(mode): return (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
 
 VSA_ACL = 0x0001
index b72f4e69b8fc6e569bbc5a147fa0ca3ea602ea78..8f735c4f846b061a558822e428a27b663f68db5c 100644 (file)
@@ -94,7 +94,7 @@ NGROUPS_MAX_DEFAULT = 16
 NZERO = 20
 NULL = 0
 NULL = 0
-CMASK = 022
+CMASK = 0o22
 CDLIMIT = (1<<11)
 NBPS = 0x20000
 NBPSCTR = 512
@@ -730,13 +730,13 @@ _SPARC_MAXREGWINDOW = 31
 _XRS_ID = 0x78727300
 GETCONTEXT = 0
 SETCONTEXT = 1
-UC_SIGMASK = 001
-UC_STACK = 002
-UC_CPU = 004
-UC_MAU = 010
+UC_SIGMASK = 0o01
+UC_STACK = 0o02
+UC_CPU = 0o04
+UC_MAU = 0o10
 UC_FPU = UC_MAU
-UC_INTR = 020
-UC_ASR = 040
+UC_INTR = 0o20
+UC_ASR = 0o40
 UC_MCONTEXT = (UC_CPU|UC_FPU|UC_ASR)
 UC_ALL = (UC_SIGMASK|UC_STACK|UC_MCONTEXT)
 _SIGQUEUE_MAX = 32
@@ -1400,14 +1400,14 @@ AT_STAT = (AT_MODE|AT_UID|AT_GID|AT_FSID|AT_NODEID|AT_NLINK|\
 AT_TIMES = (AT_ATIME|AT_MTIME|AT_CTIME)
 AT_NOSET = (AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
                         AT_BLKSIZE|AT_NBLOCKS|AT_VCODE)
-VSUID = 04000
-VSGID = 02000
-VSVTX = 01000
-VREAD = 00400
-VWRITE = 00200
-VEXEC = 00100
-MODEMASK = 07777
-PERMMASK = 00777
+VSUID = 0o4000
+VSGID = 0o2000
+VSVTX = 0o1000
+VREAD = 0o0400
+VWRITE = 0o0200
+VEXEC = 0o0100
+MODEMASK = 0o7777
+PERMMASK = 0o0777
 def MANDMODE(mode): return (((mode) & (VSGID|(VEXEC>>3))) == VSGID)
 
 VSA_ACL = 0x0001
index 514456e3936730f83fcf8853d317ccf05edbd0d3..af023b4f2d63a42987d22d8bce1d0f5e7f4a194f 100644 (file)
@@ -187,8 +187,8 @@ NC_TPI_COTS = 2
 NC_TPI_COTS_ORD = 3
 NC_TPI_RAW = 4
 NC_NOFLAG = 00
-NC_VISIBLE = 01
-NC_BROADCAST = 02
+NC_VISIBLE = 0o1
+NC_BROADCAST = 0o2
 NC_NOPROTOFMLY = "-"
 NC_LOOPBACK = "loopback"
 NC_INET = "inet"
index 9850eb4055dd068b4c974653a127f3792ffab7ab..ef50a9cb2b7236d52ee5720aa6bc7fe5392775f4 100644 (file)
@@ -65,41 +65,41 @@ ES_PRVSETS = 6
 ES_MACADTLID = 7
 ES_PRVID = 8
 ES_TPGETMAJOR = 9
-SA_EXEC = 001
-SA_WRITE = 002
-SA_READ = 004
-SA_SUBSIZE = 010
+SA_EXEC = 0o01
+SA_WRITE = 0o02
+SA_READ = 0o04
+SA_SUBSIZE = 0o10
 
 # Included from sys/stropts_f.h
 X_STR = (ord('S')<<8)
-X_I_BASE = (X_STR|0200)
-X_I_NREAD = (X_STR|0201)
-X_I_PUSH = (X_STR|0202)
-X_I_POP = (X_STR|0203)
-X_I_LOOK = (X_STR|0204)
-X_I_FLUSH = (X_STR|0205)
-X_I_SRDOPT = (X_STR|0206)
-X_I_GRDOPT = (X_STR|0207)
-X_I_STR = (X_STR|0210)
-X_I_SETSIG = (X_STR|0211)
-X_I_GETSIG = (X_STR|0212)
-X_I_FIND = (X_STR|0213)
-X_I_LINK = (X_STR|0214)
-X_I_UNLINK = (X_STR|0215)
-X_I_PEEK = (X_STR|0217)
-X_I_FDINSERT = (X_STR|0220)
-X_I_SENDFD = (X_STR|0221)
-X_I_RECVFD = (X_STR|0222)
+X_I_BASE = (X_STR|0o200)
+X_I_NREAD = (X_STR|0o201)
+X_I_PUSH = (X_STR|0o202)
+X_I_POP = (X_STR|0o203)
+X_I_LOOK = (X_STR|0o204)
+X_I_FLUSH = (X_STR|0o205)
+X_I_SRDOPT = (X_STR|0o206)
+X_I_GRDOPT = (X_STR|0o207)
+X_I_STR = (X_STR|0o210)
+X_I_SETSIG = (X_STR|0o211)
+X_I_GETSIG = (X_STR|0o212)
+X_I_FIND = (X_STR|0o213)
+X_I_LINK = (X_STR|0o214)
+X_I_UNLINK = (X_STR|0o215)
+X_I_PEEK = (X_STR|0o217)
+X_I_FDINSERT = (X_STR|0o220)
+X_I_SENDFD = (X_STR|0o221)
+X_I_RECVFD = (X_STR|0o222)
 
 # Included from unistd.h
 
 # Included from sys/unistd.h
-R_OK = 004
-W_OK = 002
-X_OK = 001
+R_OK = 0o04
+W_OK = 0o02
+X_OK = 0o01
 F_OK = 000
-EFF_ONLY_OK = 010
-EX_OK = 020
+EFF_ONLY_OK = 0o10
+EX_OK = 0o20
 SEEK_SET = 0
 SEEK_CUR = 1
 SEEK_END = 2
@@ -289,40 +289,40 @@ MUXID_ALL = (-1)
 ANYMARK = 0x01
 LASTMARK = 0x02
 STR = (ord('S')<<8)
-I_NREAD = (STR|01)
-I_PUSH = (STR|02)
-I_POP = (STR|03)
-I_LOOK = (STR|04)
-I_FLUSH = (STR|05)
-I_SRDOPT = (STR|06)
-I_GRDOPT = (STR|07)
-I_STR = (STR|010)
-I_SETSIG = (STR|011)
-I_GETSIG = (STR|012)
-I_FIND = (STR|013)
-I_LINK = (STR|014)
-I_UNLINK = (STR|015)
-I_PEEK = (STR|017)
-I_FDINSERT = (STR|020)
-I_SENDFD = (STR|021)
-I_RECVFD = (STR|022)
-I_E_RECVFD = (STR|016)
-I_RECVFD = (STR|016)
-I_RECVFD = (STR|022)
-I_SWROPT = (STR|023)
-I_GWROPT = (STR|024)
-I_LIST = (STR|025)
-I_PLINK = (STR|026)
-I_PUNLINK = (STR|027)
-I_FLUSHBAND = (STR|034)
-I_CKBAND = (STR|035)
-I_GETBAND = (STR|036)
-I_ATMARK = (STR|037)
-I_SETCLTIME = (STR|040)
-I_GETCLTIME = (STR|041)
-I_CANPUT = (STR|042)
-I_S_RECVFD = (STR|043)
-I_STATS = (STR|044)
-I_BIGPIPE = (STR|045)
-I_GETTP = (STR|046)
+I_NREAD = (STR|0o1)
+I_PUSH = (STR|0o2)
+I_POP = (STR|0o3)
+I_LOOK = (STR|0o4)
+I_FLUSH = (STR|0o5)
+I_SRDOPT = (STR|0o6)
+I_GRDOPT = (STR|0o7)
+I_STR = (STR|0o10)
+I_SETSIG = (STR|0o11)
+I_GETSIG = (STR|0o12)
+I_FIND = (STR|0o13)
+I_LINK = (STR|0o14)
+I_UNLINK = (STR|0o15)
+I_PEEK = (STR|0o17)
+I_FDINSERT = (STR|0o20)
+I_SENDFD = (STR|0o21)
+I_RECVFD = (STR|0o22)
+I_E_RECVFD = (STR|0o16)
+I_RECVFD = (STR|0o16)
+I_RECVFD = (STR|0o22)
+I_SWROPT = (STR|0o23)
+I_GWROPT = (STR|0o24)
+I_LIST = (STR|0o25)
+I_PLINK = (STR|0o26)
+I_PUNLINK = (STR|0o27)
+I_FLUSHBAND = (STR|0o34)
+I_CKBAND = (STR|0o35)
+I_GETBAND = (STR|0o36)
+I_ATMARK = (STR|0o37)
+I_SETCLTIME = (STR|0o40)
+I_GETCLTIME = (STR|0o41)
+I_CANPUT = (STR|0o42)
+I_S_RECVFD = (STR|0o43)
+I_STATS = (STR|0o44)
+I_BIGPIPE = (STR|0o45)
+I_GETTP = (STR|0o46)
 INFTIM = -1
index bd9efe6f98b5ed502c24fcb74749d76343f03a87..25daadd06caf3f19995fae607ab0c0083d1dba2e 100755 (executable)
@@ -242,7 +242,7 @@ _release_version = re.compile(r'([^0-9]+)'
 
 _supported_dists = ('SuSE', 'debian', 'fedora', 'redhat', 'centos',
                     'mandrake', 'rocks', 'slackware', 'yellowdog',
-                    'gentoo', 'UnitedLinux')
+                    'gentoo', 'UnitedLinux', 'turbolinux')
 
 def _parse_release_file(firstline):
 
@@ -600,6 +600,16 @@ def win32_ver(release='',version='',csd='',ptype=''):
                 release = '2003Server'
             else:
                 release = 'post2003'
+        elif maj == 6:
+            if min == 0:
+                # Per http://msdn2.microsoft.com/en-us/library/ms724429.aspx
+                productType = GetVersionEx(1)[8]
+                if productType == 1: # VER_NT_WORKSTATION
+                    release = 'Vista'
+                else:
+                    release = '2008Server'
+            else:
+                release = 'post2008Server'
     else:
         if not release:
             # E.g. Win3.1 with win32s
@@ -1064,6 +1074,16 @@ def uname():
             # (_syscmd_ver() tends to return the vendor name as well)
             if system == 'Microsoft Windows':
                 system = 'Windows'
+            elif system == 'Microsoft' and release == 'Windows':
+                # Under Windows Vista and Windows Server 2008,
+                # Microsoft changed the output of the ver command. The
+                # release is no longer printed.  This causes the
+                # system and release to be misidentified.
+                system = 'Windows'
+                if '6.0' == version[:3]:
+                    release = 'Vista'
+                else:
+                    release = ''
 
         # In case we still don't know anything useful, we'll try to
         # help ourselves
index 912262476a86109cf8c1a3aa02e63bbd2164f821..5d588e49a31b6a5b5552a17bdae9b077573f0b96 100644 (file)
@@ -55,7 +55,7 @@ def _open_terminal():
         pass
     else:
         try:
-            tty_name, master_fd = sgi._getpty(os.O_RDWR, 0666, 0)
+            tty_name, master_fd = sgi._getpty(os.O_RDWR, 0o666, 0)
         except IOError as msg:
             raise os.error, msg
         return master_fd, tty_name
index 075c3b7926174ccfe6b85a5b9899b4aa7f944c50..8a4717856678c28200b37875e72547899b6dc3f4 100644 (file)
@@ -110,19 +110,19 @@ class Random(_random.Random):
                 import time
                 a = int(time.time() * 256) # use fractional seconds
 
-        super(Random, self).seed(a)
+        super().seed(a)
         self.gauss_next = None
 
     def getstate(self):
         """Return internal state; can be passed to setstate() later."""
-        return self.VERSION, super(Random, self).getstate(), self.gauss_next
+        return self.VERSION, super().getstate(), self.gauss_next
 
     def setstate(self, state):
         """Restore internal state from object returned by getstate()."""
         version = state[0]
         if version == 2:
             version, internalstate, self.gauss_next = state
-            super(Random, self).setstate(internalstate)
+            super().setstate(internalstate)
         else:
             raise ValueError("state with version %s passed to "
                              "Random.setstate() of version %s" %
index c580168d64c18a0da8dfa17e0d7962d7acc4c9f7..84d963d3df8acb08ba37a412e8f07aefd1cc97b6 100644 (file)
@@ -47,7 +47,7 @@ class Repr:
         return '%s%s%s' % (left, s, right)
 
     def repr_tuple(self, x, level):
-        return self._repr_iterable(x, level, '(', ')', self.maxlist, ',')
+        return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',')
 
     def repr_list(self, x, level):
         return self._repr_iterable(x, level, '[', ']', self.maxlist)
index 99ed02b4fddd2b461278fd74c1e9ba310c1bc761..faf31b1edcf04fe11b0023249e29dd06d47caa50 100644 (file)
@@ -40,12 +40,12 @@ class ModuleTests(unittest.TestCase):
                          sqlite.paramstyle)
 
     def CheckWarning(self):
-        self.assert_(issubclass(sqlite.Warning, StandardError),
-                     "Warning is not a subclass of StandardError")
+        self.assert_(issubclass(sqlite.Warning, Exception),
+                     "Warning is not a subclass of Exception")
 
     def CheckError(self):
-        self.failUnless(issubclass(sqlite.Error, StandardError),
-                        "Error is not a subclass of StandardError")
+        self.failUnless(issubclass(sqlite.Error, Exception),
+                        "Error is not a subclass of Exception")
 
     def CheckInterfaceError(self):
         self.failUnless(issubclass(sqlite.InterfaceError, sqlite.Error),
index 5f416879c6c7a893e56441ebea05a5466e5d7409..c054fb8e0a9377748fc6bb21b32ae8dc24f9cd31 100644 (file)
@@ -24,21 +24,21 @@ ST_CTIME = 9
 # Extract bits from the mode
 
 def S_IMODE(mode):
-    return mode & 07777
+    return mode & 0o7777
 
 def S_IFMT(mode):
-    return mode & 0170000
+    return mode & 0o170000
 
 # Constants used as S_IFMT() for various file types
 # (not all are implemented on all systems)
 
-S_IFDIR  = 0040000
-S_IFCHR  = 0020000
-S_IFBLK  = 0060000
-S_IFREG  = 0100000
-S_IFIFO  = 0010000
-S_IFLNK  = 0120000
-S_IFSOCK = 0140000
+S_IFDIR  = 0o040000
+S_IFCHR  = 0o020000
+S_IFBLK  = 0o060000
+S_IFREG  = 0o100000
+S_IFIFO  = 0o010000
+S_IFLNK  = 0o120000
+S_IFSOCK = 0o140000
 
 # Functions to test for each file type
 
@@ -65,25 +65,25 @@ def S_ISSOCK(mode):
 
 # Names for permission bits
 
-S_ISUID = 04000
-S_ISGID = 02000
+S_ISUID = 0o4000
+S_ISGID = 0o2000
 S_ENFMT = S_ISGID
-S_ISVTX = 01000
-S_IREAD = 00400
-S_IWRITE = 00200
-S_IEXEC = 00100
-S_IRWXU = 00700
-S_IRUSR = 00400
-S_IWUSR = 00200
-S_IXUSR = 00100
-S_IRWXG = 00070
-S_IRGRP = 00040
-S_IWGRP = 00020
-S_IXGRP = 00010
-S_IRWXO = 00007
-S_IROTH = 00004
-S_IWOTH = 00002
-S_IXOTH = 00001
+S_ISVTX = 0o1000
+S_IREAD = 0o0400
+S_IWRITE = 0o0200
+S_IEXEC = 0o0100
+S_IRWXU = 0o0700
+S_IRUSR = 0o0400
+S_IWUSR = 0o0200
+S_IXUSR = 0o0100
+S_IRWXG = 0o0070
+S_IRGRP = 0o0040
+S_IWGRP = 0o0020
+S_IXGRP = 0o0010
+S_IRWXO = 0o0007
+S_IROTH = 0o0004
+S_IWOTH = 0o0002
+S_IXOTH = 0o0001
 
 # Names for file flags
 
index 97973fde5053f899b2c802fa5fa4e38654f719bf..94dac98ba87adeb1a9753168d5dfbb85536012be 100644 (file)
@@ -141,26 +141,26 @@ PAX_NUMBER_FIELDS = {
 #---------------------------------------------------------
 # Bits used in the mode field, values in octal.
 #---------------------------------------------------------
-S_IFLNK = 0120000        # symbolic link
-S_IFREG = 0100000        # regular file
-S_IFBLK = 0060000        # block device
-S_IFDIR = 0040000        # directory
-S_IFCHR = 0020000        # character device
-S_IFIFO = 0010000        # fifo
-
-TSUID   = 04000          # set UID on execution
-TSGID   = 02000          # set GID on execution
-TSVTX   = 01000          # reserved
-
-TUREAD  = 0400           # read by owner
-TUWRITE = 0200           # write by owner
-TUEXEC  = 0100           # execute/search by owner
-TGREAD  = 0040           # read by group
-TGWRITE = 0020           # write by group
-TGEXEC  = 0010           # execute/search by group
-TOREAD  = 0004           # read by other
-TOWRITE = 0002           # write by other
-TOEXEC  = 0001           # execute/search by other
+S_IFLNK = 0o120000        # symbolic link
+S_IFREG = 0o100000        # regular file
+S_IFBLK = 0o060000        # block device
+S_IFDIR = 0o040000        # directory
+S_IFCHR = 0o020000        # character device
+S_IFIFO = 0o010000        # fifo
+
+TSUID   = 0o4000          # set UID on execution
+TSGID   = 0o2000          # set GID on execution
+TSVTX   = 0o1000          # reserved
+
+TUREAD  = 0o400           # read by owner
+TUWRITE = 0o200           # write by owner
+TUEXEC  = 0o100           # execute/search by owner
+TGREAD  = 0o040           # read by group
+TGWRITE = 0o020           # write by group
+TGEXEC  = 0o010           # execute/search by group
+TOREAD  = 0o004           # read by other
+TOWRITE = 0o002           # write by other
+TOEXEC  = 0o001           # execute/search by other
 
 #---------------------------------------------------------
 # initialization
@@ -192,7 +192,7 @@ def nti(s):
     """
     # There are two possible encodings for a number field, see
     # itn() below.
-    if s[0] != chr(0200):
+    if s[0] != chr(0o200):
         try:
             n = int(nts(s) or "0", 8)
         except ValueError:
@@ -210,7 +210,7 @@ def itn(n, digits=8, format=DEFAULT_FORMAT):
     # POSIX 1003.1-1988 requires numbers to be encoded as a string of
     # octal digits followed by a null-byte, this allows values up to
     # (8**(digits-1))-1. GNU tar allows storing numbers greater than
-    # that if necessary. A leading 0200 byte indicates this particular
+    # that if necessary. A leading 0o200 byte indicates this particular
     # encoding, the following digits-1 bytes are a big-endian
     # representation. This allows values up to (256**(digits-1))-1.
     if 0 <= n < 8 ** (digits - 1):
@@ -226,9 +226,9 @@ def itn(n, digits=8, format=DEFAULT_FORMAT):
 
         s = ""
         for i in range(digits - 1):
-            s = chr(n & 0377) + s
+            s = chr(n & 0o377) + s
             n >>= 8
-        s = chr(0200) + s
+        s = chr(0o200) + s
     return s
 
 def uts(s, encoding, errors):
@@ -920,7 +920,7 @@ class TarInfo(object):
            of the member.
         """
         self.name = name        # member name
-        self.mode = 0644        # file permissions
+        self.mode = 0o644       # file permissions
         self.uid = 0            # user id
         self.gid = 0            # group id
         self.size = 0           # file size
@@ -960,7 +960,7 @@ class TarInfo(object):
         """
         info = {
             "name":     normpath(self.name),
-            "mode":     self.mode & 07777,
+            "mode":     self.mode & 0o7777,
             "uid":      self.uid,
             "gid":      self.gid,
             "size":     self.size,
@@ -1103,7 +1103,7 @@ class TarInfo(object):
         """
         parts = [
             stn(info.get("name", ""), 100),
-            itn(info.get("mode", 0) & 07777, 8, format),
+            itn(info.get("mode", 0) & 0o7777, 8, format),
             itn(info.get("uid", 0), 8, format),
             itn(info.get("gid", 0), 8, format),
             itn(info.get("size", 0), 12, format),
@@ -2019,7 +2019,7 @@ class TarFile(object):
                 # Extract directory with a safe mode, so that
                 # all files below can be extracted as well.
                 try:
-                    os.makedirs(os.path.join(path, tarinfo.name), 0700)
+                    os.makedirs(os.path.join(path, tarinfo.name), 0o700)
                 except EnvironmentError:
                     pass
                 directories.append(tarinfo)
index 0dd32f3bff9ac1c567060a3542a9139cfda29bef..109dc594bf42c7da39ca79c79f27e2fcc65f177e 100644 (file)
@@ -197,7 +197,7 @@ def _get_default_tempdir():
             name = next(namer)
             filename = _os.path.join(dir, name)
             try:
-                fd = _os.open(filename, flags, 0600)
+                fd = _os.open(filename, flags, 0o600)
                 fp = _os.fdopen(fd, 'w')
                 fp.write('blat')
                 fp.close()
@@ -236,7 +236,7 @@ def _mkstemp_inner(dir, pre, suf, flags):
         name = next(names)
         file = _os.path.join(dir, pre + name + suf)
         try:
-            fd = _os.open(file, flags, 0600)
+            fd = _os.open(file, flags, 0o600)
             _set_cloexec(fd)
             return (fd, _os.path.abspath(file))
         except OSError as e:
@@ -328,7 +328,7 @@ def mkdtemp(suffix="", prefix=template, dir=None):
         name = next(names)
         file = _os.path.join(dir, prefix + name + suffix)
         try:
-            _os.mkdir(file, 0700)
+            _os.mkdir(file, 0o700)
             return file
         except OSError as e:
             if e.errno == _errno.EEXIST:
index a03f7bbd71876130ad6642844813e235614baeb0..079ce2963c308d0ceb127e6fbe1f58ab32125708 100644 (file)
@@ -4,39 +4,38 @@ BaseException
  +-- Exception
       +-- GeneratorExit
       +-- StopIteration
-      +-- StandardError
-      |    +-- ArithmeticError
-      |    |    +-- FloatingPointError
-      |    |    +-- OverflowError
-      |    |    +-- ZeroDivisionError
-      |    +-- AssertionError
-      |    +-- AttributeError
-      |    +-- EnvironmentError
-      |    |    +-- IOError
-      |    |    +-- OSError
-      |    |         +-- WindowsError (Windows)
-      |    |         +-- VMSError (VMS)
-      |    +-- EOFError
-      |    +-- ImportError
-      |    +-- LookupError
-      |    |    +-- IndexError
-      |    |    +-- KeyError
-      |    +-- MemoryError
-      |    +-- NameError
-      |    |    +-- UnboundLocalError
-      |    +-- ReferenceError
-      |    +-- RuntimeError
-      |    |    +-- NotImplementedError
-      |    +-- SyntaxError
-      |    |    +-- IndentationError
-      |    |         +-- TabError
-      |    +-- SystemError
-      |    +-- TypeError
-      |    +-- ValueError
-      |    |    +-- UnicodeError
-      |    |         +-- UnicodeDecodeError
-      |    |         +-- UnicodeEncodeError
-      |    |         +-- UnicodeTranslateError
+      +-- ArithmeticError
+      |    +-- FloatingPointError
+      |    +-- OverflowError
+      |    +-- ZeroDivisionError
+      +-- AssertionError
+      +-- AttributeError
+      +-- EnvironmentError
+      |    +-- IOError
+      |    +-- OSError
+      |         +-- WindowsError (Windows)
+      |         +-- VMSError (VMS)
+      +-- EOFError
+      +-- ImportError
+      +-- LookupError
+      |    +-- IndexError
+      |    +-- KeyError
+      +-- MemoryError
+      +-- NameError
+      |    +-- UnboundLocalError
+      +-- ReferenceError
+      +-- RuntimeError
+      |    +-- NotImplementedError
+      +-- SyntaxError
+      |    +-- IndentationError
+      |         +-- TabError
+      +-- SystemError
+      +-- TypeError
+      +-- ValueError
+      |    +-- UnicodeError
+      |         +-- UnicodeDecodeError
+      |         +-- UnicodeEncodeError
+      |         +-- UnicodeTranslateError
       +-- Warning
            +-- DeprecationWarning
            +-- PendingDeprecationWarning
index 468a1bc418537945c0588130666239f42d601213..0d893f2205deba355484af420f4a799782d7dc38 100644 (file)
@@ -451,7 +451,7 @@ class CommonTest(seq_tests.CommonTest):
         self.assertEqual(u, list("ham"))
 
     def test_iadd(self):
-        super(CommonTest, self).test_iadd()
+        super().test_iadd()
         u = self.type2test([0, 1])
         u2 = u
         u += [2, 3]
index f6ba4757b3f673d68209a3405658ea227042bc84..d0fed75263ffb16e70dd660fe8dfece89c4b5e2e 100644 (file)
@@ -46,8 +46,7 @@ __abs__: ()
 __int__: ()
 __int__: ()
 __float__: ()
-__oct__: ()
-__hex__: ()
+__index__: ()
 __hash__: ()
 __repr__: ()
 __str__: ()
index a46824ddb207083c35060d7870be3d6e5639d820..c3bb8b024c8a5adbfa0f873106375cdbf60ad3b2 100644 (file)
@@ -124,66 +124,80 @@ test_tokenize
 39,5-39,7:     OP      '!='
 39,8-39,11:    NUMBER  '255'
 39,11-39,12:   NEWLINE '\n'
-40,0-40,4:     NUMBER  '0377'
-40,5-40,7:     OP      '!='
-40,8-40,11:    NUMBER  '255'
-40,11-40,12:   NEWLINE '\n'
+40,0-40,5:     NUMBER  '0o377'
+40,6-40,8:     OP      '!='
+40,9-40,12:    NUMBER  '255'
+40,12-40,13:   NEWLINE '\n'
 41,0-41,10:    NUMBER  '2147483647'
 41,13-41,15:   OP      '!='
-41,16-41,28:   NUMBER  '017777777777'
-41,28-41,29:   NEWLINE '\n'
+41,16-41,29:   NUMBER  '0o17777777777'
+41,29-41,30:   NEWLINE '\n'
 42,0-42,1:     OP      '-'
 42,1-42,11:    NUMBER  '2147483647'
 42,11-42,12:   OP      '-'
 42,12-42,13:   NUMBER  '1'
 42,14-42,16:   OP      '!='
-42,17-42,29:   NUMBER  '020000000000'
-42,29-42,30:   NEWLINE '\n'
-43,0-43,12:    NUMBER  '037777777777'
-43,13-43,15:   OP      '!='
-43,16-43,17:   OP      '-'
-43,17-43,18:   NUMBER  '1'
-43,18-43,19:   NEWLINE '\n'
+42,17-42,30:   NUMBER  '0o20000000000'
+42,30-42,31:   NEWLINE '\n'
+43,0-43,13:    NUMBER  '0o37777777777'
+43,14-43,16:   OP      '!='
+43,17-43,18:   OP      '-'
+43,18-43,19:   NUMBER  '1'
+43,19-43,20:   NEWLINE '\n'
 44,0-44,10:    NUMBER  '0xffffffff'
 44,11-44,13:   OP      '!='
 44,14-44,15:   OP      '-'
 44,15-44,16:   NUMBER  '1'
-44,16-44,17:   NEWLINE '\n'
+44,16-44,17:   OP      ';'
+44,18-44,31:   NUMBER  '0o37777777777'
+44,32-44,34:   OP      '!='
+44,35-44,36:   OP      '-'
+44,36-44,37:   NUMBER  '1'
+44,37-44,38:   OP      ';'
+44,39-44,40:   OP      '-'
+44,40-44,49:   NUMBER  '0o1234567'
+44,50-44,52:   OP      '=='
+44,53-44,64:   NUMBER  '0O001234567'
+44,64-44,65:   OP      ';'
+44,66-44,73:   NUMBER  '0b10101'
+44,74-44,76:   OP      '=='
+44,77-44,87:   NUMBER  '0B00010101'
+44,87-44,88:   NEWLINE '\n'
 45,0-45,1:     NL      '\n'
 46,0-46,15:    COMMENT '# Long integers'
 46,15-46,16:   NL      '\n'
 47,0-47,1:     NAME    'x'
 47,2-47,3:     OP      '='
-47,4-47,6:     NUMBER  '0L'
-47,6-47,7:     NEWLINE '\n'
+47,4-47,5:     NUMBER  '0'
+47,5-47,6:     NEWLINE '\n'
 48,0-48,1:     NAME    'x'
 48,2-48,3:     OP      '='
-48,4-48,6:     NUMBER  '0l'
-48,6-48,7:     NEWLINE '\n'
+48,4-48,5:     NUMBER  '0'
+48,5-48,6:     NEWLINE '\n'
 49,0-49,1:     NAME    'x'
 49,2-49,3:     OP      '='
-49,4-49,23:    NUMBER  '0xffffffffffffffffL'
-49,23-49,24:   NEWLINE '\n'
+49,4-49,22:    NUMBER  '0xffffffffffffffff'
+49,22-49,23:   NEWLINE '\n'
 50,0-50,1:     NAME    'x'
 50,2-50,3:     OP      '='
-50,4-50,23:    NUMBER  '0xffffffffffffffffl'
-50,23-50,24:   NEWLINE '\n'
+50,4-50,22:    NUMBER  '0xffffffffffffffff'
+50,22-50,23:   NEWLINE '\n'
 51,0-51,1:     NAME    'x'
 51,2-51,3:     OP      '='
-51,4-51,23:    NUMBER  '077777777777777777L'
+51,4-51,23:    NUMBER  '0o77777777777777777'
 51,23-51,24:   NEWLINE '\n'
 52,0-52,1:     NAME    'x'
 52,2-52,3:     OP      '='
-52,4-52,23:    NUMBER  '077777777777777777l'
+52,4-52,23:    NUMBER  '0B11101010111111111'
 52,23-52,24:   NEWLINE '\n'
 53,0-53,1:     NAME    'x'
 53,2-53,3:     OP      '='
-53,4-53,35:    NUMBER  '123456789012345678901234567890L'
-53,35-53,36:   NEWLINE '\n'
+53,4-53,34:    NUMBER  '123456789012345678901234567890'
+53,34-53,35:   NEWLINE '\n'
 54,0-54,1:     NAME    'x'
 54,2-54,3:     OP      '='
-54,4-54,35:    NUMBER  '123456789012345678901234567890l'
-54,35-54,36:   NEWLINE '\n'
+54,4-54,34:    NUMBER  '123456789012345678901234567890'
+54,34-54,35:   NEWLINE '\n'
 55,0-55,1:     NL      '\n'
 56,0-56,24:    COMMENT '# Floating-point numbers'
 56,24-56,25:   NL      '\n'
index de0b9f0fffb4c0e6c10a9795b0002293bb200bb6..5dfc9d484d2e4d802e1809c0e1f16dfa8ca8b4e1 100755 (executable)
@@ -697,7 +697,7 @@ def dash_R_cleanup(fs, ps, pic):
     import gc, copy_reg
     import _strptime, linecache, dircache
     import urlparse, urllib, urllib2, mimetypes, doctest
-    import struct, filecmp
+    import struct, filecmp, collections
     from distutils.dir_util import _path_created
 
     # Restore some original values.
@@ -707,6 +707,10 @@ def dash_R_cleanup(fs, ps, pic):
     sys.path_importer_cache.clear()
     sys.path_importer_cache.update(pic)
 
+    # Clear ABC registries.
+    for obj in [collections.Hashable, collections.Iterable]:
+        obj._ABCMeta__registry.clear()
+
     # Clear assorted module caches.
     _path_created.clear()
     re.purge()
index 4dfbb1bd6e053ff086218e5b06054ff87b7e5c9d..0ce212ceb2637a53eea22b3de2a2b53f4e06d2df 100644 (file)
@@ -211,6 +211,32 @@ class BaseTest(unittest.TestCase):
         self.checkraises(TypeError, 'hello', 'rindex')
         self.checkraises(TypeError, 'hello', 'rindex', 42)
 
+    def test_lower(self):
+        self.checkequal('hello', 'HeLLo', 'lower')
+        self.checkequal('hello', 'hello', 'lower')
+        self.checkraises(TypeError, 'hello', 'lower', 42)
+
+    def test_upper(self):
+        self.checkequal('HELLO', 'HeLLo', 'upper')
+        self.checkequal('HELLO', 'HELLO', 'upper')
+        self.checkraises(TypeError, 'hello', 'upper', 42)
+
+    def test_expandtabs(self):
+        self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
+        self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
+        self.checkequal('abc\rab  def\ng   hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 4)
+        self.checkequal('abc\r\nab  def\ng   hi', 'abc\r\nab\tdef\ng\thi', 'expandtabs', 4)
+        self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs')
+        self.checkequal('abc\rab      def\ng       hi', 'abc\rab\tdef\ng\thi', 'expandtabs', 8)
+        self.checkequal('abc\r\nab\r\ndef\ng\r\nhi', 'abc\r\nab\r\ndef\ng\r\nhi', 'expandtabs', 4)
+        self.checkequal('  a\n b', ' \ta\n\tb', 'expandtabs', 1)
+
+        self.checkraises(TypeError, 'hello', 'expandtabs', 42, 42)
+        # This test is only valid when sizeof(int) == sizeof(void*) == 4.
+        if sys.maxint < (1 << 32) and struct.calcsize('P') == 4:
+            self.checkraises(OverflowError,
+                             '\ta\n\tb', 'expandtabs', sys.maxint)
+
     def test_split(self):
         # by a char
         self.checkequal(['a', 'b', 'c', 'd'], 'a|b|c|d', 'split', '|')
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
new file mode 100644 (file)
index 0000000..aecb800
--- /dev/null
@@ -0,0 +1,123 @@
+# Copyright 2007 Google, Inc. All Rights Reserved.
+# Licensed to PSF under a Contributor Agreement.
+
+"""Unit tests for abc.py."""
+
+import sys
+import unittest
+from test import test_support
+
+import abc
+
+
+class TestABC(unittest.TestCase):
+
+    def test_abstractmethod_basics(self):
+        @abc.abstractmethod
+        def foo(self): pass
+        self.assertEqual(foo.__isabstractmethod__, True)
+        def bar(self): pass
+        self.assertEqual(hasattr(bar, "__isabstractmethod__"), False)
+
+    def test_abstractmethod_integration(self):
+        class C(metaclass=abc.ABCMeta):
+            @abc.abstractmethod
+            def foo(self): pass  # abstract
+            def bar(self): pass  # concrete
+        self.assertEqual(C.__abstractmethods__, {"foo"})
+        self.assertRaises(TypeError, C)  # because foo is abstract
+        class D(C):
+            def bar(self): pass  # concrete override of concrete
+        self.assertEqual(D.__abstractmethods__, {"foo"})
+        self.assertRaises(TypeError, D)  # because foo is still abstract
+        class E(D):
+            def foo(self): pass
+        self.assertEqual(E.__abstractmethods__, set())
+        E()  # now foo is concrete, too
+        class F(E):
+            @abc.abstractmethod
+            def bar(self): pass  # abstract override of concrete
+        self.assertEqual(F.__abstractmethods__, {"bar"})
+        self.assertRaises(TypeError, F)  # because bar is abstract now
+
+    def test_registration_basics(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        class B:
+            pass
+        b = B()
+        self.assertEqual(issubclass(B, A), False)
+        self.assertEqual(isinstance(b, A), False)
+        A.register(B)
+        self.assertEqual(issubclass(B, A), True)
+        self.assertEqual(isinstance(b, A), True)
+        class C(B):
+            pass
+        c = C()
+        self.assertEqual(issubclass(C, A), True)
+        self.assertEqual(isinstance(c, A), True)
+
+    def test_registration_builtins(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        A.register(int)
+        self.assertEqual(isinstance(42, A), True)
+        self.assertEqual(issubclass(int, A), True)
+        class B(A):
+            pass
+        B.register(basestring)
+        self.assertEqual(isinstance("", A), True)
+        self.assertEqual(issubclass(str, A), True)
+
+    def test_registration_edge_cases(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        A.register(A)  # should pass silently
+        class A1(A):
+            pass
+        self.assertRaises(RuntimeError, A1.register, A)  # cycles not allowed
+        class B:
+            pass
+        A1.register(B)  # ok
+        A1.register(B)  # should pass silently
+        class C(A):
+            pass
+        A.register(C)  # should pass silently
+        self.assertRaises(RuntimeError, C.register, A)  # cycles not allowed
+        C.register(B)  # ok
+
+    def test_registration_transitiveness(self):
+        class A(metaclass=abc.ABCMeta):
+            pass
+        self.failUnless(issubclass(A, A))
+        class B(metaclass=abc.ABCMeta):
+            pass
+        self.failIf(issubclass(A, B))
+        self.failIf(issubclass(B, A))
+        class C(metaclass=abc.ABCMeta):
+            pass
+        A.register(B)
+        class B1(B):
+            pass
+        self.failUnless(issubclass(B1, A))
+        class C1(C):
+            pass
+        B1.register(C1)
+        self.failIf(issubclass(C, B))
+        self.failIf(issubclass(C, B1))
+        self.failUnless(issubclass(C1, A))
+        self.failUnless(issubclass(C1, B))
+        self.failUnless(issubclass(C1, B1))
+        C1.register(int)
+        class MyInt(int):
+            pass
+        self.failUnless(issubclass(MyInt, A))
+        self.failUnless(isinstance(42, A))
+
+
+def test_main():
+    test_support.run_unittest(TestABC)
+
+
+if __name__ == "__main__":
+    unittest.main()
index 2eb64f3c87bddfcf320ab0f7b7a84bc19d0b457a..0d4c219c783b682a76cfa494d8ed542cf9b9fe8b 100755 (executable)
@@ -704,7 +704,7 @@ class BaseTest(unittest.TestCase):
 class StringTest(BaseTest):
 
     def test_setitem(self):
-        super(StringTest, self).test_setitem()
+        super().test_setitem()
         a = array.array(self.typecode, self.example)
         self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2])
 
index 1c1998d1e704fba5db718e284b3101fb1c58d1bd..a2fde023e3120beb53e7896aa822d6be129307c4 100644 (file)
@@ -728,8 +728,27 @@ class BuiltinTest(unittest.TestCase):
 
         self.assertRaises(TypeError, int, 1, 12)
 
-        self.assertEqual(int('0123', 0), 83)
+        # tests with base 0
+        self.assertRaises(ValueError, int, ' 0123  ', 0) # old octal syntax
+        self.assertEqual(int('000', 0), 0)
+        self.assertEqual(int('0o123', 0), 83)
+        self.assertEqual(int('0x123', 0), 291)
+        self.assertEqual(int('0b100', 0), 4)
+        self.assertEqual(int(' 0O123   ', 0), 83)
+        self.assertEqual(int(' 0X123  ', 0), 291)
+        self.assertEqual(int(' 0B100 ', 0), 4)
+
+        # without base still base 10
+        self.assertEqual(int('0123'), 123)
+        self.assertEqual(int('0123', 10), 123)
+
+        # tests with prefix and base != 0
         self.assertEqual(int('0x123', 16), 291)
+        self.assertEqual(int('0o123', 8), 83)
+        self.assertEqual(int('0b100', 2), 4)
+        self.assertEqual(int('0X123', 16), 291)
+        self.assertEqual(int('0O123', 8), 83)
+        self.assertEqual(int('0B100', 2), 4)
 
         # SF bug 1334662: int(string, base) wrong answers
         # Various representations of 2**32 evaluated to 0
@@ -1269,10 +1288,10 @@ class BuiltinTest(unittest.TestCase):
         self.assertEquals(next(it, 42), 42)
 
     def test_oct(self):
-        self.assertEqual(oct(100), '0144')
-        self.assertEqual(oct(100), '0144')
-        self.assertEqual(oct(-100), '-0144')
-        self.assertEqual(oct(-100), '-0144')
+        self.assertEqual(oct(100), '0o144')
+        self.assertEqual(oct(100), '0o144')
+        self.assertEqual(oct(-100), '-0o144')
+        self.assertEqual(oct(-100), '-0o144')
         self.assertRaises(TypeError, oct, ())
 
     def write_testfile(self):
index efb4c98c9bbd71c6f44f250858ac276fd449a6bf..10833217050411b96ae0ebb6240e6713fb530256 100644 (file)
@@ -716,6 +716,12 @@ class BytesAsStringTest(test.string_tests.BaseTest):
         pass
     def test_find(self):
         pass
+    def test_expandtabs(self):
+        pass
+    def test_upper(self):
+        pass
+    def test_lower(self):
+        pass
 
 
 def test_main():
index 260d9b2a85ecb47b8aba311dfeb1af2b3c5f24bd..0bf18a15e44656edb75fd2917b6544c64e84e799 100644 (file)
@@ -50,7 +50,7 @@ def do_test(buf, method):
         raise ValueError, "unknown method: %s" % method
     try:
         return cgi.parse(fp, env, strict_parsing=1)
-    except StandardError as err:
+    except Exception as err:
         return ComparableException(err)
 
 # A list of test cases.  Each test case is a a two-tuple that contains
index ded3f1a8994b44aa7caa94bb4c1ccb7c996aa122..003b4a51e6a92153dd639498b83c227b7328f405 100644 (file)
@@ -80,18 +80,14 @@ class AllTests:
         print("__int__:", args)
         return 1
 
+    def __index__(self, *args):
+        print("__index__:", args)
+        return 1
+
     def __float__(self, *args):
         print("__float__:", args)
         return 1.0
 
-    def __oct__(self, *args):
-        print("__oct__:", args)
-        return '01'
-
-    def __hex__(self, *args):
-        print("__hex__:", args)
-        return '0x1'
-
     def __cmp__(self, *args):
         print("__cmp__:", args)
         return 0
@@ -237,7 +233,6 @@ int(testme)
 int(testme)
 float(testme)
 oct(testme)
-hex(testme)
 
 # And the rest...
 
@@ -287,8 +282,6 @@ class BadTypeClass:
     __float__ = __int__
     __str__ = __int__
     __repr__ = __int__
-    __oct__ = __int__
-    __hex__ = __int__
 
 def check_exc(stmt, exception):
     """Raise TestFailed if executing 'stmt' does not raise 'exception'
index f5dad7d2238f3a7bc36676455ef703f9e51c83fd..13401e94432149349b00bac13249420a757ff307 100644 (file)
@@ -1,6 +1,14 @@
+"""Unit tests for collections.py."""
+
 import unittest
 from test import test_support
 from collections import NamedTuple
+from collections import Hashable, Iterable, Iterator
+from collections import Sized, Container, Callable
+from collections import Set, MutableSet
+from collections import Mapping, MutableMapping
+from collections import Sequence, MutableSequence
+
 
 class TestNamedTuple(unittest.TestCase):
 
@@ -51,11 +59,187 @@ class TestNamedTuple(unittest.TestCase):
         self.assertRaises(AttributeError, eval, 'p.z', locals())
 
 
+class TestOneTrickPonyABCs(unittest.TestCase):
+
+    def test_Hashable(self):
+        # Check some non-hashables
+        non_samples = [bytes(), list(), set(), dict()]
+        for x in non_samples:
+            self.failIf(isinstance(x, Hashable), repr(x))
+            self.failIf(issubclass(type(x), Hashable), repr(type(x)))
+        # Check some hashables
+        samples = [None,
+                   int(), float(), complex(),
+                   str(), unicode(),
+                   tuple(), frozenset(),
+                   int, list, object, type,
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Hashable), repr(x))
+            self.failUnless(issubclass(type(x), Hashable), repr(type(x)))
+        self.assertRaises(TypeError, Hashable)
+        # Check direct subclassing
+        class H(Hashable):
+            def __hash__(self):
+                return super().__hash__()
+        self.assertEqual(hash(H()), 0)
+        self.failIf(issubclass(int, H))
+
+    def test_Iterable(self):
+        # Check some non-iterables
+        non_samples = [None, 42, 3.14, 1j]
+        for x in non_samples:
+            self.failIf(isinstance(x, Iterable), repr(x))
+            self.failIf(issubclass(type(x), Iterable), repr(type(x)))
+        # Check some iterables
+        samples = [bytes(), str(), unicode(),
+                   tuple(), list(), set(), frozenset(), dict(),
+                   dict().keys(), dict().items(), dict().values(),
+                   (lambda: (yield))(),
+                   (x for x in []),
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Iterable), repr(x))
+            self.failUnless(issubclass(type(x), Iterable), repr(type(x)))
+        # Check direct subclassing
+        class I(Iterable):
+            def __iter__(self):
+                return super().__iter__()
+        self.assertEqual(list(I()), [])
+        self.failIf(issubclass(str, I))
+
+    def test_Iterator(self):
+        non_samples = [None, 42, 3.14, 1j, b"", "", u"", (), [], {}, set()]
+        for x in non_samples:
+            self.failIf(isinstance(x, Iterator), repr(x))
+            self.failIf(issubclass(type(x), Iterator), repr(type(x)))
+        samples = [iter(bytes()), iter(str()), iter(unicode()),
+                   iter(tuple()), iter(list()), iter(dict()),
+                   iter(set()), iter(frozenset()),
+                   iter(dict().keys()), iter(dict().items()),
+                   iter(dict().values()),
+                   (lambda: (yield))(),
+                   (x for x in []),
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Iterator), repr(x))
+            self.failUnless(issubclass(type(x), Iterator), repr(type(x)))
+
+    def test_Sized(self):
+        non_samples = [None, 42, 3.14, 1j,
+                       (lambda: (yield))(),
+                       (x for x in []),
+                       ]
+        for x in non_samples:
+            self.failIf(isinstance(x, Sized), repr(x))
+            self.failIf(issubclass(type(x), Sized), repr(type(x)))
+        samples = [bytes(), str(), unicode(),
+                   tuple(), list(), set(), frozenset(), dict(),
+                   dict().keys(), dict().items(), dict().values(),
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Sized), repr(x))
+            self.failUnless(issubclass(type(x), Sized), repr(type(x)))
+
+    def test_Container(self):
+        non_samples = [None, 42, 3.14, 1j,
+                       (lambda: (yield))(),
+                       (x for x in []),
+                       ]
+        for x in non_samples:
+            self.failIf(isinstance(x, Container), repr(x))
+            self.failIf(issubclass(type(x), Container), repr(type(x)))
+        samples = [bytes(), str(), unicode(),
+                   tuple(), list(), set(), frozenset(), dict(),
+                   dict().keys(), dict().items(),
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Container), repr(x))
+            self.failUnless(issubclass(type(x), Container), repr(type(x)))
+
+    def test_Callable(self):
+        non_samples = [None, 42, 3.14, 1j,
+                       "", b"", (), [], {}, set(),
+                       (lambda: (yield))(),
+                       (x for x in []),
+                       ]
+        for x in non_samples:
+            self.failIf(isinstance(x, Callable), repr(x))
+            self.failIf(issubclass(type(x), Callable), repr(type(x)))
+        samples = [lambda: None,
+                   type, int, object,
+                   len,
+                   list.append, [].append,
+                   ]
+        for x in samples:
+            self.failUnless(isinstance(x, Callable), repr(x))
+            self.failUnless(issubclass(type(x), Callable), repr(type(x)))
+
+    def test_direct_subclassing(self):
+        for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
+            class C(B):
+                pass
+            self.failUnless(issubclass(C, B))
+            self.failIf(issubclass(int, C))
+
+    def test_registration(self):
+        for B in Hashable, Iterable, Iterator, Sized, Container, Callable:
+            class C:
+                __hash__ = None  # Make sure it isn't hashable by default
+            self.failIf(issubclass(C, B), B.__name__)
+            B.register(C)
+            self.failUnless(issubclass(C, B))
+
+
+class TestCollectionABCs(unittest.TestCase):
+
+    # XXX For now, we only test some virtual inheritance properties.
+    # We should also test the proper behavior of the collection ABCs
+    # as real base classes or mix-in classes.
+
+    def test_Set(self):
+        for sample in [set, frozenset]:
+            self.failUnless(isinstance(sample(), Set))
+            self.failUnless(issubclass(sample, Set))
+
+    def test_MutableSet(self):
+        self.failUnless(isinstance(set(), MutableSet))
+        self.failUnless(issubclass(set, MutableSet))
+        self.failIf(isinstance(frozenset(), MutableSet))
+        self.failIf(issubclass(frozenset, MutableSet))
+
+    def test_Mapping(self):
+        for sample in [dict]:
+            self.failUnless(isinstance(sample(), Mapping))
+            self.failUnless(issubclass(sample, Mapping))
+
+    def test_MutableMapping(self):
+        for sample in [dict]:
+            self.failUnless(isinstance(sample(), MutableMapping))
+            self.failUnless(issubclass(sample, MutableMapping))
+
+    def test_Sequence(self):
+        for sample in [tuple, list, bytes, str]:
+            self.failUnless(isinstance(sample(), Sequence))
+            self.failUnless(issubclass(sample, Sequence))
+        self.failUnless(issubclass(basestring, Sequence))
+
+    def test_MutableSequence(self):
+        for sample in [tuple, str]:
+            self.failIf(isinstance(sample(), MutableSequence))
+            self.failIf(issubclass(sample, MutableSequence))
+        for sample in [list, bytes]:
+            self.failUnless(isinstance(sample(), MutableSequence))
+            self.failUnless(issubclass(sample, MutableSequence))
+        self.failIf(issubclass(basestring, MutableSequence))
+
+
 def test_main(verbose=None):
     import collections as CollectionsModule
-    test_classes = [TestNamedTuple]
+    test_classes = [TestNamedTuple, TestOneTrickPonyABCs, TestCollectionABCs]
     test_support.run_unittest(*test_classes)
     test_support.run_doctest(CollectionsModule, verbose)
 
+
 if __name__ == "__main__":
     test_main(verbose=True)
index 4e29eab0ef5f7ac0eb233b8fc285ddc26121b7d5..b5949fd4ce7de33a9764f062a9a824bb7b58ebda 100644 (file)
@@ -36,6 +36,9 @@ class TestSpecifics(unittest.TestCase):
     def test_syntax_error(self):
         self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec")
 
+    def test_none_keyword_arg(self):
+        self.assertRaises(SyntaxError, compile, "f(None=1)", "<string>", "exec")
+
     def test_duplicate_global_local(self):
         try:
             exec('def f(a): global a; a = 1')
@@ -158,21 +161,22 @@ if 1:
 
     def test_literals_with_leading_zeroes(self):
         for arg in ["077787", "0xj", "0x.", "0e",  "090000000000000",
-                    "080000000000000", "000000000000009", "000000000000008"]:
+                    "080000000000000", "000000000000009", "000000000000008",
+                    "0b42", "0BADCAFE", "0o123456789", "0b1.1", "0o4.2",
+                    "0b101j2", "0o153j2", "0b100e1", "0o777e1", "0777",
+                    "000777", "000000000000007"]:
             self.assertRaises(SyntaxError, eval, arg)
 
-        self.assertEqual(eval("0777"), 511)
-        self.assertEqual(eval("000777"), 511)
         self.assertEqual(eval("0xff"), 255)
-        self.assertEqual(eval("0XfF"), 255)
         self.assertEqual(eval("0777."), 777)
         self.assertEqual(eval("0777.0"), 777)
         self.assertEqual(eval("000000000000000000000000000000000000000000000000000777e0"), 777)
         self.assertEqual(eval("0777e1"), 7770)
         self.assertEqual(eval("0e0"), 0)
-        self.assertEqual(eval("0000E-012"), 0)
+        self.assertEqual(eval("0000e-012"), 0)
         self.assertEqual(eval("09.5"), 9.5)
         self.assertEqual(eval("0777j"), 777j)
+        self.assertEqual(eval("000"), 0)
         self.assertEqual(eval("00j"), 0j)
         self.assertEqual(eval("00.0"), 0)
         self.assertEqual(eval("0e3"), 0)
@@ -181,9 +185,12 @@ if 1:
         self.assertEqual(eval("090000000000000e0"), 90000000000000.)
         self.assertEqual(eval("090000000000000e-0"), 90000000000000.)
         self.assertEqual(eval("090000000000000j"), 90000000000000j)
-        self.assertEqual(eval("000000000000007"), 7)
         self.assertEqual(eval("000000000000008."), 8.)
         self.assertEqual(eval("000000000000009."), 9.)
+        self.assertEqual(eval("0b101010"), 42)
+        self.assertEqual(eval("-0b000000000010"), -2)
+        self.assertEqual(eval("0o777"), 511)
+        self.assertEqual(eval("-0o0000010"), -8)
 
     def test_unary_minus(self):
         # Verify treatment of unary minus on negative numbers SF bug #660455
index bcbd0964552220de2e4733fefedd564dee087b62..7dc84426482e606815e661cec14f556a855ac9b7 100644 (file)
@@ -2126,17 +2126,14 @@ def inherits():
     class octlong(int):
         __slots__ = []
         def __str__(self):
-            s = oct(self)
-            if s[-1] == 'L':
-                s = s[:-1]
-            return s
+            return oct(self)
         def __add__(self, other):
             return self.__class__(super(octlong, self).__add__(other))
         __radd__ = __add__
-    vereq(str(octlong(3) + 5), "010")
+    vereq(str(octlong(3) + 5), "0o10")
     # (Note that overriding __radd__ here only seems to work
     # because the example uses a short int left argument.)
-    vereq(str(5 + octlong(3000)), "05675")
+    vereq(str(5 + octlong(3000)), "0o5675")
     a = octlong(12345)
     vereq(a, 12345)
     vereq(int(a), 12345)
index c7d29ec008e3feec987716dc1a5927128ec68b0c..d03d861d6ebc17c3cdb89bcdde08de8814812faf 100644 (file)
@@ -45,17 +45,17 @@ class DumbDBMTestCase(unittest.TestCase):
             return
 
         try:
-            old_umask = os.umask(0002)
-            f = dumbdbm.open(_fname, 'c', 0637)
+            old_umask = os.umask(0o002)
+            f = dumbdbm.open(_fname, 'c', 0o637)
             f.close()
         finally:
             os.umask(old_umask)
 
-        expected_mode = 0635
+        expected_mode = 0o635
         if os.name != 'posix':
             # Windows only supports setting the read-only attribute.
             # This shouldn't fail, but doesn't work like Unix either.
-            expected_mode = 0666
+            expected_mode = 0o666
 
         import stat
         st = os.stat(_fname + '.dat')
index ace1f1f3c95886f8a1927ec1135c5dd199fc198a..085768dc15d7b021bde26ceb5d5fac5c98eb7dc8 100644 (file)
@@ -121,7 +121,7 @@ testboth("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
 # same, except no 0 flag
 testboth("%#+27.23X", big, " +0X001234567890ABCDEF12345")
 
-big = 012345670123456701234567012345670  # 32 octal digits
+big = 0o12345670123456701234567012345670  # 32 octal digits
 testboth("%o", big, "12345670123456701234567012345670")
 testboth("%o", -big, "-12345670123456701234567012345670")
 testboth("%5o", -big, "-12345670123456701234567012345670")
@@ -141,33 +141,36 @@ testboth("%.33o", big, "012345670123456701234567012345670")
 testboth("%34.33o", big, " 012345670123456701234567012345670")
 testboth("%-34.33o", big, "012345670123456701234567012345670 ")
 testboth("%o", big, "12345670123456701234567012345670")
-testboth("%#o", big, "012345670123456701234567012345670")
-testboth("%#o", -big, "-012345670123456701234567012345670")
-testboth("%#.34o", -big, "-0012345670123456701234567012345670")
-testboth("%#+.34o", big, "+0012345670123456701234567012345670")
-testboth("%# .34o", big, " 0012345670123456701234567012345670")
-testboth("%#+.34o", big, "+0012345670123456701234567012345670")
-testboth("%#-+.34o", big, "+0012345670123456701234567012345670")
-testboth("%#-+37.34o", big, "+0012345670123456701234567012345670  ")
-testboth("%#+37.34o", big, "  +0012345670123456701234567012345670")
+testboth("%#o", big, "0o12345670123456701234567012345670")
+testboth("%#o", -big, "-0o12345670123456701234567012345670")
+testboth("%#.34o", -big, "-0o0012345670123456701234567012345670")
+testboth("%#+.34o", big, "+0o0012345670123456701234567012345670")
+testboth("%# .34o", big, " 0o0012345670123456701234567012345670")
+testboth("%#-+.34o", big, "+0o0012345670123456701234567012345670")
+testboth("%#-+39.34o", big, "+0o0012345670123456701234567012345670  ")
+testboth("%#+39.34o", big, "  +0o0012345670123456701234567012345670")
 # next one gets one leading zero from precision
 testboth("%.33o", big, "012345670123456701234567012345670")
-# base marker shouldn't change that, since "0" is redundant
-testboth("%#.33o", big, "012345670123456701234567012345670")
-# but reduce precision, and base marker should add a zero
-testboth("%#.32o", big, "012345670123456701234567012345670")
-# one leading zero from precision, and another from "0" flag & width
+# one leading zero from precision
+testboth("%#.33o", big, "0o012345670123456701234567012345670")
+# leading zero vanishes
+testboth("%#.32o", big, "0o12345670123456701234567012345670")
+# one leading zero from precision, and another from '0' flag & width
 testboth("%034.33o", big, "0012345670123456701234567012345670")
-# base marker shouldn't change that
-testboth("%0#34.33o", big, "0012345670123456701234567012345670")
+# max width includes base marker; padding zeroes come after marker
+testboth("%0#38.33o", big, "0o000012345670123456701234567012345670")
+# padding spaces come before marker
+testboth("%#36.33o", big, " 0o012345670123456701234567012345670")
 
 # Some small ints, in both Python int and long flavors).
 testboth("%d", 42, "42")
 testboth("%d", -42, "-42")
 testboth("%#x", 1, "0x1")
 testboth("%#X", 1, "0X1")
-testboth("%#o", 1, "01")
-testboth("%#o", 0, "0")
+testboth("%#o", 1, "0o1")
+testboth("%#o", 1, "0o1")
+testboth("%#o", 0, "0o0")
+testboth("%#o", 0, "0o0")
 testboth("%o", 0, "0")
 testboth("%d", 0, "0")
 testboth("%#x", 0, "0x0")
@@ -176,8 +179,10 @@ testboth("%#X", 0, "0X0")
 testboth("%x", 0x42, "42")
 testboth("%x", -0x42, "-42")
 
-testboth("%o", 042, "42")
-testboth("%o", -042, "-42")
+testboth("%o", 0o42, "42")
+testboth("%o", -0o42, "-42")
+testboth("%o", 0o42, "42")
+testboth("%o", -0o42, "-42")
 
 # Test exception for unknown format characters
 if verbose:
@@ -216,14 +221,6 @@ test_exc('no format', '1', TypeError,
 test_exc('no format', '1', TypeError,
          "not all arguments converted during string formatting")
 
-class Foobar(int):
-    def __oct__(self):
-        # Returning a non-string should not blow up.
-        return self + 1
-
-test_exc('%o', Foobar(), TypeError,
-         "expected string, int found")
-
 if maxsize == 2**31-1:
     # crashes 2.2.1 and earlier:
     try:
index 711d636f0448253329ab12cf6aaf1baaf73795de..8f4538298481fa65cc17ce3b012de7b8228139f6 100644 (file)
@@ -27,26 +27,32 @@ class TokenTests(unittest.TestCase):
         self.assertEquals(x, 0, 'backslash ending comment')
 
     def testPlainIntegers(self):
+        self.assertEquals(type(000), type(0))
         self.assertEquals(0xff, 255)
-        self.assertEquals(0377, 255)
-        self.assertEquals(2147483647, 017777777777)
+        self.assertEquals(0o377, 255)
+        self.assertEquals(2147483647, 0o17777777777)
+        self.assertEquals(0b1001, 9)
         from sys import maxint
         if maxint == 2147483647:
-            self.assertEquals(-2147483647-1, -020000000000)
+            self.assertEquals(-2147483647-1, -0o20000000000)
             # XXX -2147483648
-            self.assert_(037777777777 > 0)
+            self.assert_(0o37777777777 > 0)
             self.assert_(0xffffffff > 0)
-            for s in '2147483648', '040000000000', '0x100000000':
+            self.assert_(0b1111111111111111111111111111111 > 0)
+            for s in ('2147483648', '0o40000000000', '0x100000000',
+                      '0b10000000000000000000000000000000'):
                 try:
                     x = eval(s)
                 except OverflowError:
                     self.fail("OverflowError on huge integer literal %r" % s)
         elif maxint == 9223372036854775807:
-            self.assertEquals(-9223372036854775807-1, -01000000000000000000000)
-            self.assert_(01777777777777777777777 > 0)
+            self.assertEquals(-9223372036854775807-1, -0o1000000000000000000000)
+            self.assert_(0o1777777777777777777777 > 0)
             self.assert_(0xffffffffffffffff > 0)
-            for s in '9223372036854775808', '02000000000000000000000', \
-                     '0x10000000000000000':
+            self.assert_(0b11111111111111111111111111111111111111111111111111111111111111 > 0)
+            for s in '9223372036854775808', '0o2000000000000000000000', \
+                     '0x10000000000000000', \
+                     '0b100000000000000000000000000000000000000000000000000000000000000':
                 try:
                     x = eval(s)
                 except OverflowError:
@@ -56,13 +62,13 @@ class TokenTests(unittest.TestCase):
 
     def testLongIntegers(self):
         x = 0
-        x = 0
-        x = 0xffffffffffffffff
         x = 0xffffffffffffffff
-        x = 077777777777777777
-        x = 077777777777777777
-        x = 123456789012345678901234567890
+        x = 0Xffffffffffffffff
+        x = 0o77777777777777777
+        x = 0O77777777777777777
         x = 123456789012345678901234567890
+        x = 0b100000000000000000000000000000000000000000000000000000000000000000000
+        x = 0B111111111111111111111111111111111111111111111111111111111111111111111
 
     def testFloats(self):
         x = 3.14
index 5e86beabab520137505dc9ef7f0af6b542611fc7..afd696afc5634a7deef860902eee3f401b42042c 100644 (file)
@@ -65,49 +65,49 @@ class TextHexOct(unittest.TestCase):
     def test_oct_baseline(self):
         # Baseline tests
         self.assertEqual(00, 0)
-        self.assertEqual(020, 16)
+        self.assertEqual(0o20, 16)
         if platform_long_is_32_bits:
-            self.assertEqual(017777777777, 2147483647)
+            self.assertEqual(0o17777777777, 2147483647)
         else:
-            self.assertEqual(0777777777777777777777, 9223372036854775807)
+            self.assertEqual(0o777777777777777777777, 9223372036854775807)
         # Ditto with a minus sign and parentheses
         self.assertEqual(-(00), 0)
-        self.assertEqual(-(020), -16)
+        self.assertEqual(-(0o20), -16)
         if platform_long_is_32_bits:
-            self.assertEqual(-(017777777777), -2147483647)
+            self.assertEqual(-(0o17777777777), -2147483647)
         else:
-            self.assertEqual(-(0777777777777777777777), -9223372036854775807)
+            self.assertEqual(-(0o777777777777777777777), -9223372036854775807)
         # Ditto with a minus sign and NO parentheses
         self.assertEqual(-00, 0)
-        self.assertEqual(-020, -16)
+        self.assertEqual(-0o20, -16)
         if platform_long_is_32_bits:
-            self.assertEqual(-017777777777, -2147483647)
+            self.assertEqual(-0o17777777777, -2147483647)
         else:
-            self.assertEqual(-0777777777777777777777, -9223372036854775807)
+            self.assertEqual(-0o777777777777777777777, -9223372036854775807)
 
     def test_oct_unsigned(self):
         if platform_long_is_32_bits:
             # Positive constants
-            self.assertEqual(020000000000, 2147483648)
-            self.assertEqual(037777777777, 4294967295)
+            self.assertEqual(0o20000000000, 2147483648)
+            self.assertEqual(0o37777777777, 4294967295)
             # Ditto with a minus sign and parentheses
-            self.assertEqual(-(020000000000), -2147483648)
-            self.assertEqual(-(037777777777), -4294967295)
+            self.assertEqual(-(0o20000000000), -2147483648)
+            self.assertEqual(-(0o37777777777), -4294967295)
             # Ditto with a minus sign and NO parentheses
             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-020000000000, -2147483648)
-            self.assertEqual(-037777777777, -4294967295)
+            self.assertEqual(-0o20000000000, -2147483648)
+            self.assertEqual(-0o37777777777, -4294967295)
         else:
             # Positive constants
-            self.assertEqual(01000000000000000000000, 9223372036854775808)
-            self.assertEqual(01777777777777777777777, 18446744073709551615)
+            self.assertEqual(0o1000000000000000000000, 9223372036854775808)
+            self.assertEqual(0o1777777777777777777777, 18446744073709551615)
             # Ditto with a minus sign and parentheses
-            self.assertEqual(-(01000000000000000000000), -9223372036854775808)
-            self.assertEqual(-(01777777777777777777777), -18446744073709551615)
+            self.assertEqual(-(0o1000000000000000000000), -9223372036854775808)
+            self.assertEqual(-(0o1777777777777777777777), -18446744073709551615)
             # Ditto with a minus sign and NO parentheses
             # This failed in Python 2.2 through 2.2.2 and in 2.3a1
-            self.assertEqual(-01000000000000000000000, -9223372036854775808)
-            self.assertEqual(-01777777777777777777777, -18446744073709551615)
+            self.assertEqual(-0o1000000000000000000000, -9223372036854775808)
+            self.assertEqual(-0o1777777777777777777777, -18446744073709551615)
 
 def test_main():
     test_support.run_unittest(TextHexOct)
index ea78773f7b9a4d1ca6cfa46ae5f14335a148f603..f7f561ad73be6dee7f0ab8089c57619e67aee441 100644 (file)
@@ -5,7 +5,7 @@ class ListTest(list_tests.CommonTest):
     type2test = list
 
     def test_truth(self):
-        super(ListTest, self).test_truth()
+        super().test_truth()
         self.assert_(not [])
         self.assert_([42])
 
@@ -13,7 +13,7 @@ class ListTest(list_tests.CommonTest):
         self.assert_([] is not [])
 
     def test_len(self):
-        super(ListTest, self).test_len()
+        super().test_len()
         self.assertEqual(len([]), 0)
         self.assertEqual(len([0]), 1)
         self.assertEqual(len([0, 1, 2]), 3)
index c38056da0f87b6b74193b3f3b07d6d72539b1899..9e56d31c8cd0e5468d5ed539fe1c34b213d91849 100644 (file)
@@ -195,9 +195,6 @@ class LongTest(unittest.TestCase):
                 self.check_bitop_identities_3(x, y, self.getran((lenx + leny)//2))
 
     def slow_format(self, x, base):
-        if (x, base) == (0, 8):
-            # this is an oddball!
-            return "0"
         digits = []
         sign = 0
         if x < 0:
@@ -208,7 +205,7 @@ class LongTest(unittest.TestCase):
         digits.reverse()
         digits = digits or [0]
         return '-'[:sign] + \
-               {8: '0', 10: '', 16: '0x'}[base] + \
+               {2: '0b', 8: '0o', 10: '', 16: '0x'}[base] + \
                "".join(map(lambda i: "0123456789abcdef"[i], digits))
 
     def check_format_1(self, x):
index f41ad34caf4fe101b62edf53e8f589ad60b64094..472f6204b47256ff4f6d64d36867c590a54483ae 100644 (file)
@@ -136,6 +136,16 @@ class Test_IncrementalDecoder(unittest.TestCase):
         self.assertRaises(UnicodeDecodeError, decoder.decode, '', True)
         self.assertEqual(decoder.decode('B@$'), '\u4e16')
 
+class Test_StreamReader(unittest.TestCase):
+    def test_bug1728403(self):
+        try:
+            open(TESTFN, 'w').write('\xa1')
+            f = codecs.open(TESTFN, encoding='cp949')
+            self.assertRaises(UnicodeDecodeError, f.read, 2)
+        finally:
+            try: f.close()
+            except: pass
+            os.unlink(TESTFN)
 
 class Test_StreamWriter(unittest.TestCase):
     if len('\U00012345') == 2: # UCS2
index b2901985147cfc4f20c0ad4c826f259ed01ed19c..28ad055641e5176f62ae0cda9ba9beddbaad7c0c 100644 (file)
@@ -39,16 +39,24 @@ class TestTranforms(unittest.TestCase):
             asm = dis_single(line)
             self.assert_(elem in asm)
 
-    def test_none_as_constant(self):
-        # LOAD_GLOBAL None  -->  LOAD_CONST None
+    def test_global_as_constant(self):
+        # LOAD_GLOBAL None/True/False  -->  LOAD_CONST None/True/False
         def f(x):
+            None
             None
             return x
-        asm = disassemble(f)
-        for elem in ('LOAD_GLOBAL',):
-            self.assert_(elem not in asm)
-        for elem in ('LOAD_CONST', '(None)'):
-            self.assert_(elem in asm)
+        def g(x):
+            True
+            return x
+        def h(x):
+            False
+            return x
+        for func, name in ((f, 'None'), (g, 'True'), (h, 'False')):
+            asm = disassemble(func)
+            for elem in ('LOAD_GLOBAL',):
+                self.assert_(elem not in asm)
+            for elem in ('LOAD_CONST', '('+name+')'):
+                self.assert_(elem in asm)
         def f():
             'Adding a docstring made this test fail in Py2.5.0'
             return None
index 90766ba505a29e2c07417ff1ca216ccdf0623525..dc47737feb3a81bfc127e192a44c37828398b65d 100644 (file)
@@ -131,22 +131,22 @@ class UsageTests(unittest.TestCase):
         """Catching 'object_' should raise a TypeError."""
         try:
             try:
-                raise StandardError
+                raise Exception
             except object_:
                 pass
         except TypeError:
             pass
-        except StandardError:
+        except Exception:
             self.fail("TypeError expected when catching %s" % type(object_))
 
         try:
             try:
-                raise StandardError
+                raise Exception
             except (object_,):
                 pass
         except TypeError:
             return
-        except StandardError:
+        except Exception:
             self.fail("TypeError expected when catching %s as specified in a "
                         "tuple" % type(object_))
 
index 5059c08c98847dda123e79ac96f7819e38ebcbfc..d4db894f5fee6d88f3f7dd4f7a4828871520601d 100644 (file)
@@ -10,6 +10,7 @@ import unittest
 
 from test.test_support import run_unittest
 from repr import repr as r # Don't shadow builtin repr
+from repr import Repr
 
 
 def nestedTuple(nesting):
@@ -34,6 +35,18 @@ class ReprTests(unittest.TestCase):
         expected = repr(s)[:13] + "..." + repr(s)[-14:]
         eq(r(s), expected)
 
+    def test_tuple(self):
+        eq = self.assertEquals
+        eq(r((1,)), "(1,)")
+
+        t3 = (1, 2, 3)
+        eq(r(t3), "(1, 2, 3)")
+
+        r2 = Repr()
+        r2.maxtuple = 2
+        expected = repr(t3)[:-2] + "...)"
+        eq(r2.repr(t3), expected)
+
     def test_container(self):
         from array import array
         from collections import deque
index 6fa377966f250b1c2246c8b0ba2de3f607f8085b..2ef01f00dd09442a27eaf31b49dcc14b3afdc088 100644 (file)
@@ -1,4 +1,7 @@
+
 import unittest
+import struct
+import sys
 from test import test_support, string_tests
 
 
@@ -88,6 +91,15 @@ class StrTest(
         self.assertEqual(str8(Foo9("foo")), "string")
         self.assertEqual(str(Foo9("foo")), "not unicode")
 
+    def test_expandtabs_overflows_gracefully(self):
+        # This test only affects 32-bit platforms because expandtabs can only take
+        # an int as the max value, not a 64-bit C long.  If expandtabs is changed
+        # to take a 64-bit long, this test should apply to all platforms.
+        if sys.maxint > (1 << 32) or struct.calcsize('P') != 4:
+            return
+        self.assertRaises(OverflowError, 't\tt\t'.expandtabs, sys.maxint)
+
+
 def test_main():
     test_support.run_unittest(StrTest)
 
index 0e1909eb428442a60ecb7d5b3a4c66624a8f48d6..81f83927ebda9eff110723146166f4ebc8654ffc 100644 (file)
@@ -190,6 +190,15 @@ class TimeRETests(unittest.TestCase):
                         "locale data that contains regex metacharacters is not"
                         " properly escaped")
 
+    def test_whitespace_substitution(self):
+        # When pattern contains whitespace, make sure it is taken into account
+        # so as to not allow to subpatterns to end up next to each other and
+        # "steal" characters from each other.
+        pattern = self.time_re.pattern('%j %H')
+        self.failUnless(not re.match(pattern, "180"))
+        self.failUnless(re.match(pattern, "18 0"))
+
+
 class StrptimeTests(unittest.TestCase):
     """Tests for _strptime.strptime."""
 
@@ -463,8 +472,8 @@ class CalculationTests(unittest.TestCase):
                                         "of the year")
         test_helper((1917, 12, 31), "Dec 31 on Monday with year starting and "
                                         "ending on Monday")
-        test_helper((2007, 01, 07), "First Sunday of 2007")
-        test_helper((2007, 01, 14), "Second Sunday of 2007")
+        test_helper((2007, 1, 7), "First Sunday of 2007")
+        test_helper((2007, 1, 14), "Second Sunday of 2007")
         test_helper((2006, 12, 31), "Last Sunday of 2006")
         test_helper((2006, 12, 24), "Second to last Sunday of 2006")
 
index 599c6fb9cb291df952c24d0a5cf67ee9eafb3c2a..c3d01c876fb7569aa9766b5dd65d512ae9657b3f 100644 (file)
@@ -2,7 +2,8 @@ from _testcapi import test_structmembersType, \
     CHAR_MAX, CHAR_MIN, UCHAR_MAX, \
     SHRT_MAX, SHRT_MIN, USHRT_MAX, \
     INT_MAX, INT_MIN, UINT_MAX, \
-    LONG_MAX, LONG_MIN, ULONG_MAX
+    LONG_MAX, LONG_MIN, ULONG_MAX, \
+    LLONG_MAX, LLONG_MIN, ULLONG_MAX
 
 import warnings, unittest
 from test import test_support
@@ -39,6 +40,23 @@ class ReadWriteTests(unittest.TestCase):
         ts.T_ULONG=ULONG_MAX
         self.assertEquals(ts.T_ULONG, ULONG_MAX)
 
+        ## T_LONGLONG and T_ULONGLONG may not be present on some platforms
+        if hasattr(ts, 'T_LONGLONG'):
+            ts.T_LONGLONG=LLONG_MAX
+            self.assertEquals(ts.T_LONGLONG, LLONG_MAX)
+            ts.T_LONGLONG=LLONG_MIN
+            self.assertEquals(ts.T_LONGLONG, LLONG_MIN)
+
+            ts.T_ULONGLONG=ULLONG_MAX
+            self.assertEquals(ts.T_ULONGLONG, ULLONG_MAX)
+
+            ## make sure these will accept a plain int as well as a long
+            ts.T_LONGLONG=3
+            self.assertEquals(ts.T_LONGLONG, 3)
+            ts.T_ULONGLONG=4
+            self.assertEquals(ts.T_ULONGLONG, 4)
+
+
 class TestWarnings(unittest.TestCase):
     def has_warned(self, w):
         self.assert_(w.category is RuntimeWarning)
index b44e83a57b4dbffdb49e44d0ef71492c52219af9..2421a6b1106deaf50a01f3f627a17d0355fb606d 100644 (file)
@@ -528,7 +528,7 @@ class ProcessTestCase(unittest.TestCase):
             os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" %
                         sys.executable)
             os.close(f)
-            os.chmod(fname, 0700)
+            os.chmod(fname, 0o700)
             p = subprocess.Popen(fname)
             p.wait()
             os.remove(fname)
@@ -570,7 +570,7 @@ class ProcessTestCase(unittest.TestCase):
             os.write(f, "exec %s -c 'import sys; sys.exit(47)'\n" %
                         sys.executable)
             os.close(f)
-            os.chmod(fname, 0700)
+            os.chmod(fname, 0o700)
             rc = subprocess.call(fname)
             os.remove(fname)
             self.assertEqual(rc, 47)
index 3c0346da561964d9ba842a3a06b0da031700de68..28a08c5cd38a27b5c394d48f70712f0125458242 100644 (file)
@@ -1,6 +1,7 @@
 """Do a minimal test of all the modules that aren't otherwise tested."""
 
 from test.test_support import guard_warnings_filter
+import sys
 import warnings
 
 with guard_warnings_filter():
@@ -18,6 +19,53 @@ with guard_warnings_filter():
     import cmd
     import code
     import compileall
+
+    import distutils.archive_util
+    import distutils.bcppcompiler
+    import distutils.ccompiler
+    import distutils.cmd
+    import distutils.core
+    import distutils.cygwinccompiler
+    import distutils.dep_util
+    import distutils.dir_util
+    import distutils.emxccompiler
+    import distutils.errors
+    import distutils.extension
+    import distutils.file_util
+    import distutils.filelist
+    import distutils.log
+    if sys.platform.startswith('win'):
+        import distutils.msvccompiler
+    import distutils.mwerkscompiler
+    import distutils.sysconfig
+    import distutils.text_file
+    import distutils.unixccompiler
+    import distutils.util
+    import distutils.version
+
+    import distutils.command.bdist_dumb
+    if sys.platform.startswith('win'):
+        import distutils.command.bdist_msi
+    import distutils.command.bdist
+    import distutils.command.bdist_rpm
+    import distutils.command.bdist_wininst
+    import distutils.command.build_clib
+    import distutils.command.build_ext
+    import distutils.command.build
+    import distutils.command.build_py
+    import distutils.command.build_scripts
+    import distutils.command.clean
+    import distutils.command.config
+    import distutils.command.install_data
+    import distutils.command.install_egg_info
+    import distutils.command.install_headers
+    import distutils.command.install_lib
+    import distutils.command.install
+    import distutils.command.install_scripts
+    import distutils.command.register
+    import distutils.command.sdist
+    import distutils.command.upload
+
     import encodings
     import formatter
     import ftplib
@@ -37,7 +85,6 @@ with guard_warnings_filter():
     import os2emxpath
     import pdb
     import pipes
-    #import poplib
     import pstats
     import py_compile
     import pydoc
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
new file mode 100644 (file)
index 0000000..fc303ea
--- /dev/null
@@ -0,0 +1,79 @@
+"""Unit tests for new super() implementation."""
+
+import sys
+import unittest
+from test import test_support
+
+
+class A:
+    def f(self):
+        return 'A'
+    @classmethod
+    def cm(cls):
+        return (cls, 'A')
+
+class B(A):
+    def f(self):
+        return super().f() + 'B'
+    @classmethod
+    def cm(cls):
+        return (cls, super().cm(), 'B')
+
+class C(A):
+    def f(self):
+        return super().f() + 'C'
+    @classmethod
+    def cm(cls):
+        return (cls, super().cm(), 'C')
+
+class D(C, B):
+    def f(self):
+        return super().f() + 'D'
+    def cm(cls):
+        return (cls, super().cm(), 'D')
+
+class E(D):
+    pass
+
+class F(E):
+    f = E.f
+
+class G(A):
+    pass
+
+
+class TestSuper(unittest.TestCase):
+
+    def testBasicsWorking(self):
+        self.assertEqual(D().f(), 'ABCD')
+
+    def testClassGetattrWorking(self):
+        self.assertEqual(D.f(D()), 'ABCD')
+
+    def testSubclassNoOverrideWorking(self):
+        self.assertEqual(E().f(), 'ABCD')
+        self.assertEqual(E.f(E()), 'ABCD')
+
+    def testUnboundMethodTransferWorking(self):
+        self.assertEqual(F().f(), 'ABCD')
+        self.assertEqual(F.f(F()), 'ABCD')
+
+    def testClassMethodsStillWorking(self):
+        self.assertEqual(A.cm(), (A, 'A'))
+        self.assertEqual(A().cm(), (A, 'A'))
+        self.assertEqual(G.cm(), (G, 'A'))
+        self.assertEqual(G().cm(), (G, 'A'))
+
+    def testSuperInClassMethodsWorking(self):
+        d = D()
+        self.assertEqual(d.cm(), (d, (D, (D, (D, 'A'), 'B'), 'C'), 'D'))
+        e = E()
+        self.assertEqual(e.cm(), (e, (E, (E, (E, 'A'), 'B'), 'C'), 'D'))
+
+
+def test_main():
+    test_support.run_unittest(TestSuper)
+
+
+if __name__ == "__main__":
+    unittest.main()
index 39504e14523e41e650410b203277032267f98165..50c5bbede7f306b47f74a7e76d747e21c0d77d2a 100644 (file)
@@ -164,7 +164,7 @@ class MiscReadTest(ReadTest):
 
     def test_check_members(self):
         for tarinfo in self.tar:
-            self.assert_(int(tarinfo.mtime) == 07606136617,
+            self.assert_(int(tarinfo.mtime) == 0o7606136617,
                     "wrong mtime for %s" % tarinfo.name)
             if not tarinfo.name.startswith("ustar/"):
                 continue
@@ -299,7 +299,7 @@ class MemberReadTest(ReadTest):
             self.assert_(md5sum(self.tar.extractfile(tarinfo).read()) == chksum,
                     "wrong md5sum for %s" % tarinfo.name)
 
-        kwargs["mtime"] = 07606136617
+        kwargs["mtime"] = 0o7606136617
         kwargs["uid"] = 1000
         kwargs["gid"] = 100
         if "old-v7" not in tarinfo.name:
@@ -978,7 +978,7 @@ class LimitsTest(unittest.TestCase):
 
         # uid > 8 digits
         tarinfo = tarfile.TarInfo("name")
-        tarinfo.uid = 010000000
+        tarinfo.uid = 0o10000000
         self.assertRaises(ValueError, tarinfo.tobuf, tarfile.USTAR_FORMAT)
 
     def test_gnu_limits(self):
@@ -991,7 +991,7 @@ class LimitsTest(unittest.TestCase):
 
         # uid >= 256 ** 7
         tarinfo = tarfile.TarInfo("name")
-        tarinfo.uid = 04000000000000000000
+        tarinfo.uid = 0o4000000000000000000
         self.assertRaises(ValueError, tarinfo.tobuf, tarfile.GNU_FORMAT)
 
     def test_pax_limits(self):
@@ -1003,7 +1003,7 @@ class LimitsTest(unittest.TestCase):
         tarinfo.tobuf(tarfile.PAX_FORMAT)
 
         tarinfo = tarfile.TarInfo("name")
-        tarinfo.uid = 04000000000000000000
+        tarinfo.uid = 0o4000000000000000000
         tarinfo.tobuf(tarfile.PAX_FORMAT)
 
 
index 8c2eb23d20693b9efa3525f66d66dffa2dd71c24..caa8f4e734d8a6d6536f8ebb308e5996d468fafe 100644 (file)
@@ -264,7 +264,7 @@ class test__mkstemp_inner(TC):
 
         file = self.do_create()
         mode = stat.S_IMODE(os.stat(file.name).st_mode)
-        expected = 0600
+        expected = 0o600
         if sys.platform in ('win32', 'os2emx', 'mac'):
             # There's no distinction among 'user', 'group' and 'world';
             # replicate the 'user' bits.
@@ -482,8 +482,8 @@ class test_mkdtemp(TC):
         dir = self.do_create()
         try:
             mode = stat.S_IMODE(os.stat(dir).st_mode)
-            mode &= 0777 # Mask off sticky bits inherited from /tmp
-            expected = 0700
+            mode &= 0o777 # Mask off sticky bits inherited from /tmp
+            expected = 0o700
             if sys.platform in ('win32', 'os2emx', 'mac'):
                 # There's no distinction among 'user', 'group' and 'world';
                 # replicate the 'user' bits.
@@ -517,7 +517,7 @@ class test_mktemp(TC):
             self.name = tempfile.mktemp(dir=dir, prefix=pre, suffix=suf)
             # Create the file.  This will raise an exception if it's
             # mysteriously appeared in the meanwhile.
-            os.close(os.open(self.name, self._bflags, 0600))
+            os.close(os.open(self.name, self._bflags, 0o600))
 
         def __del__(self):
             self._unlink(self.name)
index 95557c0ce16eca3aee8aea4522bb19da6a06385f..b76cea14e0d3962aaaa4404fd94013bc6bab9d60 100644 (file)
@@ -3,6 +3,7 @@
 import test.test_support
 from test.test_support import verbose
 import random
+import sys
 import threading
 import thread
 import time
@@ -201,8 +202,47 @@ class ThreadTests(unittest.TestCase):
             t.join()
         # else the thread is still running, and we have no way to kill it
 
+class ThreadingExceptionTests(unittest.TestCase):
+    # A RuntimeError should be raised if Thread.start() is called
+    # multiple times.
+    def test_start_thread_again(self):
+        thread = threading.Thread()
+        thread.start()
+        self.assertRaises(RuntimeError, thread.start)
+
+    def test_releasing_unacquired_rlock(self):
+        rlock = threading.RLock()
+        self.assertRaises(RuntimeError, rlock.release)
+
+    def test_waiting_on_unacquired_condition(self):
+        cond = threading.Condition()
+        self.assertRaises(RuntimeError, cond.wait)
+
+    def test_notify_on_unacquired_condition(self):
+        cond = threading.Condition()
+        self.assertRaises(RuntimeError, cond.notify)
+
+    def test_semaphore_with_negative_value(self):
+        self.assertRaises(ValueError, threading.Semaphore, value = -1)
+        self.assertRaises(ValueError, threading.Semaphore, value = -sys.maxint)
+
+    def test_joining_current_thread(self):
+        currentThread = threading.currentThread()
+        self.assertRaises(RuntimeError, currentThread.join);
+
+    def test_joining_inactive_thread(self):
+        thread = threading.Thread()
+        self.assertRaises(RuntimeError, thread.join)
+
+    def test_daemonize_active_thread(self):
+        thread = threading.Thread()
+        thread.start()
+        self.assertRaises(RuntimeError, thread.setDaemon, True)
+
+
 def test_main():
-    test.test_support.run_unittest(ThreadTests)
+    test.test_support.run_unittest(ThreadTests,
+                                   ThreadingExceptionTests)
 
 if __name__ == "__main__":
     test_main()
index 00dcd393d71d894d62625569383b5aa1acae71b7..1da0ef35d850d5b8b72eabd6e60e5c8721ebc4db 100644 (file)
@@ -5,30 +5,30 @@ class TupleTest(seq_tests.CommonTest):
     type2test = tuple
 
     def test_constructors(self):
-        super(TupleTest, self).test_len()
+        super().test_len()
         # calling built-in types without argument must return empty
         self.assertEqual(tuple(), ())
 
     def test_truth(self):
-        super(TupleTest, self).test_truth()
+        super().test_truth()
         self.assert_(not ())
         self.assert_((42, ))
 
     def test_len(self):
-        super(TupleTest, self).test_len()
+        super().test_len()
         self.assertEqual(len(()), 0)
         self.assertEqual(len((0,)), 1)
         self.assertEqual(len((0, 1, 2)), 3)
 
     def test_iadd(self):
-        super(TupleTest, self).test_iadd()
+        super().test_iadd()
         u = (0, 1)
         u2 = u
         u += (2, 3)
         self.assert_(u is not u2)
 
     def test_imul(self):
-        super(TupleTest, self).test_imul()
+        super().test_imul()
         u = (0, 1)
         u2 = u
         u *= 3
index 76674d5c71680d830a97ce3b807d5638b434e1b0..fbad9843b883106bb484459f1bfd170196c47db8 100644 (file)
@@ -6,7 +6,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
 
 """#"
-import unittest, sys, codecs, new
+import unittest, sys, struct, codecs, new
 from test import test_support, string_tests
 
 # Error handling (bad decoder return)
@@ -785,8 +785,13 @@ class UnicodeTest(
         self.assertEqual(repr(s1()), '\\n')
         self.assertEqual(repr(s2()), '\\n')
 
-
-
+    def test_expandtabs_overflows_gracefully(self):
+        # This test only affects 32-bit platforms because expandtabs can only take
+        # an int as the max value, not a 64-bit C long.  If expandtabs is changed
+        # to take a 64-bit long, this test should apply to all platforms.
+        if sys.maxint > (1 << 32) or struct.calcsize('P') != 4:
+            return
+        self.assertRaises(OverflowError, u't\tt\t'.expandtabs, sys.maxint)
 
 
 def test_main():
index 2fc64cda0e7449a10cba9a4d4cbbffbcf5894cb9..9cf48df816d096233f63c6b8a7e5bb14b910fe95 100644 (file)
@@ -48,7 +48,7 @@ class TestUnicodeFiles(unittest.TestCase):
         self.failUnless(os.path.exists(os.path.abspath(filename)))
         self.failUnless(os.path.isfile(os.path.abspath(filename)))
         self.failUnless(os.access(os.path.abspath(filename), os.R_OK))
-        os.chmod(filename, 0777)
+        os.chmod(filename, 0o777)
         os.utime(filename, None)
         os.utime(filename, (time.time(), time.time()))
         # Copy/rename etc tests using the same filename
index 327d65fbf3e9b2702d66d1ea1a0a5cc572b80f62..98066e436c2da356273e4ade40fbef74ea9eb1b2 100644 (file)
@@ -16,23 +16,23 @@ from unittest import TestCase
 class LoggingResult(unittest.TestResult):
     def __init__(self, log):
         self._events = log
-        super(LoggingResult, self).__init__()
+        super().__init__()
 
     def startTest(self, test):
         self._events.append('startTest')
-        super(LoggingResult, self).startTest(test)
+        super().startTest(test)
 
     def stopTest(self, test):
         self._events.append('stopTest')
-        super(LoggingResult, self).stopTest(test)
+        super().stopTest(test)
 
     def addFailure(self, *args):
         self._events.append('addFailure')
-        super(LoggingResult, self).addFailure(*args)
+        super().addFailure(*args)
 
     def addError(self, *args):
         self._events.append('addError')
-        super(LoggingResult, self).addError(*args)
+        super().addError(*args)
 
 class TestEquality(object):
     # Check for a valid __eq__ implementation
index 10d8c46dea6bed54508eec3b59e55e814c853272..dbcfe26de3ca518100eb401b947fcbc2a644b54d 100644 (file)
@@ -544,7 +544,7 @@ class HandlerTests(unittest.TestCase):
 
         class NullFTPHandler(urllib2.FTPHandler):
             def __init__(self, data): self.data = data
-            def connect_ftp(self, user, passwd, host, port, dirs):
+            def connect_ftp(self, user, passwd, host, port, dirs, timeout=None):
                 self.user, self.passwd = user, passwd
                 self.host, self.port = host, port
                 self.dirs = dirs
@@ -567,7 +567,9 @@ class HandlerTests(unittest.TestCase):
              "localhost", ftplib.FTP_PORT, "A",
              [], "baz.gif", None),  # XXX really this should guess image/gif
             ]:
-            r = h.ftp_open(Request(url))
+            req = Request(url)
+            req.timeout = None
+            r = h.ftp_open(req)
             # ftp authentication not yet implemented by FTPHandler
             self.assert_(h.user == h.passwd == "")
             self.assertEqual(h.host, socket.gethostbyname(host))
@@ -682,8 +684,9 @@ class HandlerTests(unittest.TestCase):
                 self.req_headers = []
                 self.data = None
                 self.raise_on_endheaders = False
-            def __call__(self, host):
+            def __call__(self, host, timeout=None):
                 self.host = host
+                self.timeout = timeout
                 return self
             def set_debuglevel(self, level):
                 self.level = level
@@ -706,6 +709,7 @@ class HandlerTests(unittest.TestCase):
         url = "http://example.com/"
         for method, data in [("GET", None), ("POST", "blah")]:
             req = Request(url, data, {"Foo": "bar"})
+            req.timeout = None
             req.add_unredirected_header("Spam", "eggs")
             http = MockHTTPClass()
             r = h.do_open(http, req)
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
new file mode 100644 (file)
index 0000000..737ecbd
--- /dev/null
@@ -0,0 +1,310 @@
+#!/usr/bin/env python
+
+import sys
+import threading
+import urlparse
+import urllib2
+import BaseHTTPServer
+import unittest
+import hashlib
+from test import test_support
+
+# Loopback http server infrastructure
+
+class LoopbackHttpServer(BaseHTTPServer.HTTPServer):
+    """HTTP server w/ a few modifications that make it useful for
+    loopback testing purposes.
+    """
+
+    def __init__(self, server_address, RequestHandlerClass):
+        BaseHTTPServer.HTTPServer.__init__(self,
+                                           server_address,
+                                           RequestHandlerClass)
+
+        # Set the timeout of our listening socket really low so
+        # that we can stop the server easily.
+        self.socket.settimeout(1.0)
+
+    def get_request(self):
+        """BaseHTTPServer method, overridden."""
+
+        request, client_address = self.socket.accept()
+
+        # It's a loopback connection, so setting the timeout
+        # really low shouldn't affect anything, but should make
+        # deadlocks less likely to occur.
+        request.settimeout(10.0)
+
+        return (request, client_address)
+
+class LoopbackHttpServerThread(threading.Thread):
+    """Stoppable thread that runs a loopback http server."""
+
+    def __init__(self, port, RequestHandlerClass):
+        threading.Thread.__init__(self)
+        self._RequestHandlerClass = RequestHandlerClass
+        self._stop = False
+        self._port = port
+        self._server_address = ('127.0.0.1', self._port)
+        self.ready = threading.Event()
+        self.error = None
+
+    def stop(self):
+        """Stops the webserver if it's currently running."""
+
+        # Set the stop flag.
+        self._stop = True
+
+        self.join()
+
+    def run(self):
+        protocol = "HTTP/1.0"
+
+        try:
+            self._RequestHandlerClass.protocol_version = protocol
+            httpd = LoopbackHttpServer(self._server_address,
+                                       self._RequestHandlerClass)
+
+            sa = httpd.socket.getsockname()
+            #print "Serving HTTP on", sa[0], "port", sa[1], "..."
+        except:
+            # Fail "gracefully" if we are unable to start.
+            self.ready.set()
+            self.error = sys.exc_info()[1]
+            raise
+
+        self.ready.set()
+        while not self._stop:
+            httpd.handle_request()
+
+# Authentication infrastructure
+
+class DigestAuthHandler:
+    """Handler for performing digest authentication."""
+
+    def __init__(self):
+        self._request_num = 0
+        self._nonces = []
+        self._users = {}
+        self._realm_name = "Test Realm"
+        self._qop = "auth"
+
+    def set_qop(self, qop):
+        self._qop = qop
+
+    def set_users(self, users):
+        assert isinstance(users, dict)
+        self._users = users
+
+    def set_realm(self, realm):
+        self._realm_name = realm
+
+    def _generate_nonce(self):
+        self._request_num += 1
+        nonce = hashlib.md5(str(self._request_num)).hexdigest()
+        self._nonces.append(nonce)
+        return nonce
+
+    def _create_auth_dict(self, auth_str):
+        first_space_index = auth_str.find(" ")
+        auth_str = auth_str[first_space_index+1:]
+
+        parts = auth_str.split(",")
+
+        auth_dict = {}
+        for part in parts:
+            name, value = part.split("=")
+            name = name.strip()
+            if value[0] == '"' and value[-1] == '"':
+                value = value[1:-1]
+            else:
+                value = value.strip()
+            auth_dict[name] = value
+        return auth_dict
+
+    def _validate_auth(self, auth_dict, password, method, uri):
+        final_dict = {}
+        final_dict.update(auth_dict)
+        final_dict["password"] = password
+        final_dict["method"] = method
+        final_dict["uri"] = uri
+        HA1_str = "%(username)s:%(realm)s:%(password)s" % final_dict
+        HA1 = hashlib.md5(HA1_str).hexdigest()
+        HA2_str = "%(method)s:%(uri)s" % final_dict
+        HA2 = hashlib.md5(HA2_str).hexdigest()
+        final_dict["HA1"] = HA1
+        final_dict["HA2"] = HA2
+        response_str = "%(HA1)s:%(nonce)s:%(nc)s:" \
+                       "%(cnonce)s:%(qop)s:%(HA2)s" % final_dict
+        response = hashlib.md5(response_str).hexdigest()
+
+        return response == auth_dict["response"]
+
+    def _return_auth_challenge(self, request_handler):
+        request_handler.send_response(407, "Proxy Authentication Required")
+        request_handler.send_header("Content-Type", "text/html")
+        request_handler.send_header(
+            'Proxy-Authenticate', 'Digest realm="%s", '
+            'qop="%s",'
+            'nonce="%s", ' % \
+            (self._realm_name, self._qop, self._generate_nonce()))
+        # XXX: Not sure if we're supposed to add this next header or
+        # not.
+        #request_handler.send_header('Connection', 'close')
+        request_handler.end_headers()
+        request_handler.wfile.write("Proxy Authentication Required.")
+        return False
+
+    def handle_request(self, request_handler):
+        """Performs digest authentication on the given HTTP request
+        handler.  Returns True if authentication was successful, False
+        otherwise.
+
+        If no users have been set, then digest auth is effectively
+        disabled and this method will always return True.
+        """
+
+        if len(self._users) == 0:
+            return True
+
+        if 'Proxy-Authorization' not in request_handler.headers:
+            return self._return_auth_challenge(request_handler)
+        else:
+            auth_dict = self._create_auth_dict(
+                request_handler.headers['Proxy-Authorization']
+                )
+            if auth_dict["username"] in self._users:
+                password = self._users[ auth_dict["username"] ]
+            else:
+                return self._return_auth_challenge(request_handler)
+            if not auth_dict.get("nonce") in self._nonces:
+                return self._return_auth_challenge(request_handler)
+            else:
+                self._nonces.remove(auth_dict["nonce"])
+
+            auth_validated = False
+
+            # MSIE uses short_path in its validation, but Python's
+            # urllib2 uses the full path, so we're going to see if
+            # either of them works here.
+
+            for path in [request_handler.path, request_handler.short_path]:
+                if self._validate_auth(auth_dict,
+                                       password,
+                                       request_handler.command,
+                                       path):
+                    auth_validated = True
+
+            if not auth_validated:
+                return self._return_auth_challenge(request_handler)
+            return True
+
+# Proxy test infrastructure
+
+class FakeProxyHandler(BaseHTTPServer.BaseHTTPRequestHandler):
+    """This is a 'fake proxy' that makes it look like the entire
+    internet has gone down due to a sudden zombie invasion.  It main
+    utility is in providing us with authentication support for
+    testing.
+    """
+
+    digest_auth_handler = DigestAuthHandler()
+
+    def log_message(self, format, *args):
+        # Uncomment the next line for debugging.
+        #sys.stderr.write(format % args)
+        pass
+
+    def do_GET(self):
+        (scm, netloc, path, params, query, fragment) = urlparse.urlparse(
+            self.path, 'http')
+        self.short_path = path
+        if self.digest_auth_handler.handle_request(self):
+            self.send_response(200, "OK")
+            self.send_header("Content-Type", "text/html")
+            self.end_headers()
+            self.wfile.write("You've reached %s!<BR>" % self.path)
+            self.wfile.write("Our apologies, but our server is down due to "
+                              "a sudden zombie invasion.")
+
+# Test cases
+
+class ProxyAuthTests(unittest.TestCase):
+    URL = "http://www.foo.com"
+
+    PORT = 8080
+    USER = "tester"
+    PASSWD = "test123"
+    REALM = "TestRealm"
+
+    PROXY_URL = "http://127.0.0.1:%d" % PORT
+
+    def setUp(self):
+        FakeProxyHandler.digest_auth_handler.set_users({
+            self.USER : self.PASSWD
+            })
+        FakeProxyHandler.digest_auth_handler.set_realm(self.REALM)
+
+        self.server = LoopbackHttpServerThread(self.PORT, FakeProxyHandler)
+        self.server.start()
+        self.server.ready.wait()
+        if self.server.error:
+            raise self.server.error
+
+        handler = urllib2.ProxyHandler({"http" : self.PROXY_URL})
+        self._digest_auth_handler = urllib2.ProxyDigestAuthHandler()
+        self.opener = urllib2.build_opener(handler, self._digest_auth_handler)
+
+    def tearDown(self):
+        self.server.stop()
+
+    def test_proxy_with_bad_password_raises_httperror(self):
+        self._digest_auth_handler.add_password(self.REALM, self.URL,
+                                               self.USER, self.PASSWD+"bad")
+        FakeProxyHandler.digest_auth_handler.set_qop("auth")
+        self.assertRaises(urllib2.HTTPError,
+                          self.opener.open,
+                          self.URL)
+
+    def test_proxy_with_no_password_raises_httperror(self):
+        FakeProxyHandler.digest_auth_handler.set_qop("auth")
+        self.assertRaises(urllib2.HTTPError,
+                          self.opener.open,
+                          self.URL)
+
+    def test_proxy_qop_auth_works(self):
+        self._digest_auth_handler.add_password(self.REALM, self.URL,
+                                               self.USER, self.PASSWD)
+        FakeProxyHandler.digest_auth_handler.set_qop("auth")
+        result = self.opener.open(self.URL)
+        while result.read():
+            pass
+        result.close()
+
+    def test_proxy_qop_auth_int_works_or_throws_urlerror(self):
+        self._digest_auth_handler.add_password(self.REALM, self.URL,
+                                               self.USER, self.PASSWD)
+        FakeProxyHandler.digest_auth_handler.set_qop("auth-int")
+        try:
+            result = self.opener.open(self.URL)
+        except urllib2.URLError:
+            # It's okay if we don't support auth-int, but we certainly
+            # shouldn't receive any kind of exception here other than
+            # a URLError.
+            result = None
+        if result:
+            while result.read():
+                pass
+            result.close()
+
+def test_main():
+    # We will NOT depend on the network resource flag
+    # (Lib/test/regrtest.py -u network) since all tests here are only
+    # localhost.  However, if this is a bad rationale, then uncomment
+    # the next line.
+    #test_support.requires("network")
+
+    test_support.run_unittest(ProxyAuthTests)
+
+if __name__ == "__main__":
+    test_main()
index 537b738d8096a13517b3c092fe1cac2ba002289a..89ddaa4390aef694e5db8b15a6883f54a20b9dc3 100644 (file)
@@ -267,6 +267,49 @@ class OtherNetworkTests(unittest.TestCase):
 
         return handlers
 
+class TimeoutTest(unittest.TestCase):
+    def test_http_basic(self):
+        u = urllib2.urlopen("http://www.python.org")
+        self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
+
+    def test_http_NoneWithdefault(self):
+        prev = socket.getdefaulttimeout()
+        socket.setdefaulttimeout(60)
+        try:
+            u = urllib2.urlopen("http://www.python.org", timeout=None)
+            self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 60)
+        finally:
+            socket.setdefaulttimeout(prev)
+
+    def test_http_Value(self):
+        u = urllib2.urlopen("http://www.python.org", timeout=120)
+        self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120)
+
+    def test_http_NoneNodefault(self):
+        u = urllib2.urlopen("http://www.python.org", timeout=None)
+        self.assertTrue(u.fp._sock.fp._sock.gettimeout() is None)
+
+    def test_ftp_basic(self):
+        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/")
+        self.assertTrue(u.fp.fp._sock.gettimeout() is None)
+
+    def test_ftp_NoneWithdefault(self):
+        prev = socket.getdefaulttimeout()
+        socket.setdefaulttimeout(60)
+        try:
+            u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=None)
+            self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
+        finally:
+            socket.setdefaulttimeout(prev)
+
+    def test_ftp_NoneNodefault(self):
+        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=None)
+        self.assertTrue(u.fp.fp._sock.gettimeout() is None)
+
+    def test_ftp_Value(self):
+        u = urllib2.urlopen("ftp://ftp.mirror.nl/pub/mirror/gnu/", timeout=60)
+        self.assertEqual(u.fp.fp._sock.gettimeout(), 60)
+
 
 def test_main():
     test_support.requires("network")
@@ -275,6 +318,7 @@ def test_main():
                               AuthTests,
                               OtherNetworkTests,
                               CloseSocketTest,
+                              TimeoutTest,
                               )
 
 if __name__ == "__main__":
index fc9508f8ccc7b04c8bd23da85de741269fbea4fd..32c7733f093e50fe329348263feece1560b5048c 100644 (file)
@@ -8,7 +8,7 @@ class UserListTest(list_tests.CommonTest):
     type2test = UserList
 
     def test_getslice(self):
-        super(UserListTest, self).test_getslice()
+        super().test_getslice()
         l = [0, 1, 2, 3, 4]
         u = self.type2test(l)
         for i in range(-3, 6):
@@ -30,7 +30,7 @@ class UserListTest(list_tests.CommonTest):
         self.assertEqual(u2, list("spameggs"))
 
     def test_iadd(self):
-        super(UserListTest, self).test_iadd()
+        super().test_iadd()
         u = [0, 1]
         u += UserList([0, 1])
         self.assertEqual(u, [0, 1, 0, 1])
index 548cafb401f81f0a559958810641ee326a9cb820..181e361d1759f98197fbe8f9dd39fa1377f77eaf 100644 (file)
@@ -24,21 +24,21 @@ class UUTest(unittest.TestCase):
         inp = cStringIO.StringIO(plaintext)
         out = cStringIO.StringIO()
         uu.encode(inp, out, "t1")
-        self.assertEqual(out.getvalue(), encodedtextwrapped % (0666, "t1"))
+        self.assertEqual(out.getvalue(), encodedtextwrapped % (0o666, "t1"))
         inp = cStringIO.StringIO(plaintext)
         out = cStringIO.StringIO()
-        uu.encode(inp, out, "t1", 0644)
-        self.assertEqual(out.getvalue(), encodedtextwrapped % (0644, "t1"))
+        uu.encode(inp, out, "t1", 0o644)
+        self.assertEqual(out.getvalue(), encodedtextwrapped % (0o644, "t1"))
 
     def test_decode(self):
-        inp = cStringIO.StringIO(encodedtextwrapped % (0666, "t1"))
+        inp = cStringIO.StringIO(encodedtextwrapped % (0o666, "t1"))
         out = cStringIO.StringIO()
         uu.decode(inp, out)
         self.assertEqual(out.getvalue(), plaintext)
         inp = cStringIO.StringIO(
             "UUencoded files may contain many lines,\n" +
             "even some that have 'begin' in them.\n" +
-            encodedtextwrapped % (0666, "t1")
+            encodedtextwrapped % (0o666, "t1")
         )
         out = cStringIO.StringIO()
         uu.decode(inp, out)
@@ -75,14 +75,14 @@ class UUStdIOTest(unittest.TestCase):
     def test_encode(self):
         sys.stdin = cStringIO.StringIO(plaintext)
         sys.stdout = cStringIO.StringIO()
-        uu.encode("-", "-", "t1", 0666)
+        uu.encode("-", "-", "t1", 0o666)
         self.assertEqual(
             sys.stdout.getvalue(),
-            encodedtextwrapped % (0666, "t1")
+            encodedtextwrapped % (0o666, "t1")
         )
 
     def test_decode(self):
-        sys.stdin = cStringIO.StringIO(encodedtextwrapped % (0666, "t1"))
+        sys.stdin = cStringIO.StringIO(encodedtextwrapped % (0o666, "t1"))
         sys.stdout = cStringIO.StringIO()
         uu.decode("-", "-")
         self.assertEqual(sys.stdout.getvalue(), plaintext)
@@ -120,21 +120,21 @@ class UUFileTest(unittest.TestCase):
 
             fin = open(self.tmpin, 'rb')
             fout = open(self.tmpout, 'w')
-            uu.encode(fin, fout, self.tmpin, mode=0644)
+            uu.encode(fin, fout, self.tmpin, mode=0o644)
             fin.close()
             fout.close()
 
             fout = open(self.tmpout, 'r')
             s = fout.read()
             fout.close()
-            self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))
+            self.assertEqual(s, encodedtextwrapped % (0o644, self.tmpin))
 
             # in_file and out_file as filenames
-            uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0644)
+            uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0o644)
             fout = open(self.tmpout, 'r')
             s = fout.read()
             fout.close()
-            self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))
+            self.assertEqual(s, encodedtextwrapped % (0o644, self.tmpin))
 
         finally:
             self._kill(fin)
@@ -143,7 +143,7 @@ class UUFileTest(unittest.TestCase):
     def test_decode(self):
         try:
             f = open(self.tmpin, 'w')
-            f.write(encodedtextwrapped % (0644, self.tmpout))
+            f.write(encodedtextwrapped % (0o644, self.tmpout))
             f.close()
 
             f = open(self.tmpin, 'r')
@@ -161,7 +161,7 @@ class UUFileTest(unittest.TestCase):
     def test_decodetwice(self):
         # Verify that decode() will refuse to overwrite an existing file
         try:
-            f = cStringIO.StringIO(encodedtextwrapped % (0644, self.tmpout))
+            f = cStringIO.StringIO(encodedtextwrapped % (0o644, self.tmpout))
 
             f = open(self.tmpin, 'r')
             uu.decode(f)
index 99a5178a6bdec95aacb4319928001b4cae3462da..92d80318b3035bdc1dc70fbff86d241420eacd47 100644 (file)
@@ -651,10 +651,10 @@ class SubclassableWeakrefTestCase(unittest.TestCase):
         class MyRef(weakref.ref):
             def __init__(self, ob, callback=None, value=42):
                 self.value = value
-                super(MyRef, self).__init__(ob, callback)
+                super().__init__(ob, callback)
             def __call__(self):
                 self.called = True
-                return super(MyRef, self).__call__()
+                return super().__call__()
         o = Object("foo")
         mr = MyRef(o, value=24)
         self.assert_(mr() is o)
@@ -1091,7 +1091,7 @@ None
 >>> import weakref
 >>> class ExtendedRef(weakref.ref):
 ...     def __init__(self, ob, callback=None, **annotations):
-...         super(ExtendedRef, self).__init__(ob, callback)
+...         super().__init__(ob, callback)
 ...         self.__counter = 0
 ...         for k, v in annotations.items():
 ...             setattr(self, k, v)
@@ -1099,7 +1099,7 @@ None
 ...         '''Return a pair containing the referent and the number of
 ...         times the reference has been called.
 ...         '''
-...         ob = super(ExtendedRef, self).__call__()
+...         ob = super().__call__()
 ...         if ob is not None:
 ...             self.__counter += 1
 ...             ob = (ob, self.__counter)
index bc8a7cf27f1ddf0d0d1cbcb317be54c7ec014df3..791cca7666ad98390528f90dcc90e60aa182caeb 100644 (file)
@@ -15,9 +15,9 @@ alist = [{'astring': 'foo@bar.baz.spam',
           'ukey\u4000': 'regular value',
           'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
           'datetime2': xmlrpclib.DateTime(
-                        (2005, 02, 10, 11, 41, 23, 0, 1, -1)),
+                        (2005, 2, 10, 11, 41, 23, 0, 1, -1)),
           'datetime3': xmlrpclib.DateTime(
-                        datetime.datetime(2005, 02, 10, 11, 41, 23)),
+                        datetime.datetime(2005, 2, 10, 11, 41, 23)),
           }]
 
 class XMLRPCTestCase(unittest.TestCase):
@@ -31,7 +31,7 @@ class XMLRPCTestCase(unittest.TestCase):
         # by the marshalling code.  This can't be done via test_dump_load()
         # since with use_datetime set to 1 the unmarshaller would create
         # datetime objects for the 'datetime[123]' keys as well
-        dt = datetime.datetime(2005, 02, 10, 11, 41, 23)
+        dt = datetime.datetime(2005, 2, 10, 11, 41, 23)
         s = xmlrpclib.dumps((dt,))
         (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
         self.assertEquals(newdt, dt)
@@ -44,7 +44,7 @@ class XMLRPCTestCase(unittest.TestCase):
         # This checks that an unwrapped datetime.date object can be handled
         # by the marshalling code.  This can't be done via test_dump_load()
         # since the unmarshaller produces a datetime object
-        d = datetime.datetime(2005, 02, 10, 11, 41, 23).date()
+        d = datetime.datetime(2005, 2, 10, 11, 41, 23).date()
         s = xmlrpclib.dumps((d,))
         (newd,), m = xmlrpclib.loads(s, use_datetime=1)
         self.assertEquals(newd.date(), d)
@@ -58,7 +58,7 @@ class XMLRPCTestCase(unittest.TestCase):
         # This checks that an unwrapped datetime.time object can be handled
         # by the marshalling code.  This can't be done via test_dump_load()
         # since the unmarshaller produces a datetime object
-        t = datetime.datetime(2005, 02, 10, 11, 41, 23).time()
+        t = datetime.datetime(2005, 2, 10, 11, 41, 23).time()
         s = xmlrpclib.dumps((t,))
         (newt,), m = xmlrpclib.loads(s, use_datetime=1)
         today = datetime.datetime.now().date().strftime("%Y%m%d")
index 53c5504170eaeb2e01c1e8b9be2edc26bbe5ed94..8daac4b49921e6450a6a189eac9f183f6ec5ad1c 100644 (file)
@@ -364,7 +364,7 @@ class BadFileZipImportTestCase(unittest.TestCase):
         finally:
             # If we leave "the read-only bit" set on Windows, nothing can
             # delete TESTMOD, and later tests suffer bogus failures.
-            os.chmod(TESTMOD, 0666)
+            os.chmod(TESTMOD, 0o666)
             test_support.unlink(TESTMOD)
 
     def testNotZipFile(self):
index a8b80d2726e26b2d09edb96a7adacd90356feedc..0fd108914ef130140ba42864c839fe0bbdd0d31d 100644 (file)
@@ -19,7 +19,7 @@ try:
             sys.stderr.write("fd %d is open in child" % fd)
         sys.exit(1)
 
-except StandardError:
+except Exception:
     if verbose:
         raise
     sys.exit(1)
index b1aa020bfbd3ea199088533f46da1f86ce28853b..30e7a8d2f04601d8d27b55b9d02dd9da07b4e7e3 100644 (file)
@@ -37,21 +37,21 @@ x = 0
 
 # Ordinary integers
 0xff != 255
-0377 != 255
-2147483647   != 017777777777
--2147483647-1 != 020000000000
-037777777777 != -1
-0xffffffff != -1
+0o377 != 255
+2147483647   != 0o17777777777
+-2147483647-1 != 0o20000000000
+0o37777777777 != -1
+0xffffffff != -1; 0o37777777777 != -1; -0o1234567 == 0O001234567; 0b10101 == 0B00010101
 
 # Long integers
-x = 0L
-x = 0l
-x = 0xffffffffffffffffL
-x = 0xffffffffffffffffl
-x = 077777777777777777L
-x = 077777777777777777l
-x = 123456789012345678901234567890L
-x = 123456789012345678901234567890l
+x = 0
+x = 0
+x = 0xffffffffffffffff
+x = 0xffffffffffffffff
+x = 0o77777777777777777
+x = 0B11101010111111111
+x = 123456789012345678901234567890
+x = 123456789012345678901234567890
 
 # Floating-point numbers
 x = 3.14
index e87a6530f17c8703c39a5a3c308257d323c277b5..489713c68677ec2b5b4bedfa5c71aae0c542e55c 100644 (file)
@@ -111,8 +111,8 @@ class _RLock(_Verbose):
     __enter__ = acquire
 
     def release(self):
-        me = currentThread()
-        assert self.__owner is me, "release() of un-acquire()d lock"
+        if self.__owner is not currentThread():
+            raise RuntimeError("cannot release un-aquired lock")
         self.__count = count = self.__count - 1
         if not count:
             self.__owner = None
@@ -203,7 +203,8 @@ class _Condition(_Verbose):
             return True
 
     def wait(self, timeout=None):
-        assert self._is_owned(), "wait() of un-acquire()d lock"
+        if not self._is_owned():
+            raise RuntimeError("cannot wait on un-aquired lock")
         waiter = _allocate_lock()
         waiter.acquire()
         self.__waiters.append(waiter)
@@ -244,7 +245,8 @@ class _Condition(_Verbose):
             self._acquire_restore(saved_state)
 
     def notify(self, n=1):
-        assert self._is_owned(), "notify() of un-acquire()d lock"
+        if not self._is_owned():
+            raise RuntimeError("cannot notify on un-aquired lock")
         __waiters = self.__waiters
         waiters = __waiters[:n]
         if not waiters:
@@ -272,7 +274,8 @@ class _Semaphore(_Verbose):
     # After Tim Peters' semaphore class, but not quite the same (no maximum)
 
     def __init__(self, value=1, verbose=None):
-        assert value >= 0, "Semaphore initial value must be >= 0"
+        if value < 0:
+            raise ValueError("semaphore initial value must be >= 0")
         _Verbose.__init__(self, verbose)
         self.__cond = Condition(Lock())
         self.__value = value
@@ -423,8 +426,10 @@ class Thread(_Verbose):
         return "<%s(%s, %s)>" % (self.__class__.__name__, self.__name, status)
 
     def start(self):
-        assert self.__initialized, "Thread.__init__() not called"
-        assert not self.__started, "thread already started"
+        if not self.__initialized:
+            raise RuntimeError("thread.__init__() not called")
+        if self.__started:
+            raise RuntimeError("thread already started")
         if __debug__:
             self._note("%s.start(): starting thread", self)
         _active_limbo_lock.acquire()
@@ -544,9 +549,13 @@ class Thread(_Verbose):
             _active_limbo_lock.release()
 
     def join(self, timeout=None):
-        assert self.__initialized, "Thread.__init__() not called"
-        assert self.__started, "cannot join thread before it is started"
-        assert self is not currentThread(), "cannot join current thread"
+        if not self.__initialized:
+            raise RuntimeError("Thread.__init__() not called")
+        if not self.__started:
+            raise RuntimeError("cannot join thread before it is started")
+        if self is currentThread():
+            raise RuntimeError("cannot join current thread")
+
         if __debug__:
             if not self.__stopped:
                 self._note("%s.join(): waiting until thread stops", self)
@@ -589,8 +598,10 @@ class Thread(_Verbose):
         return self.__daemonic
 
     def setDaemon(self, daemonic):
-        assert self.__initialized, "Thread.__init__() not called"
-        assert not self.__started, "cannot set daemon status of active thread"
+        if not self.__initialized:
+            raise RuntimeError("Thread.__init__() not called")
+        if self.__started:
+            raise RuntimeError("cannot set daemon status of active thread");
         self.__daemonic = daemonic
 
 # The timer class was contributed by Itamar Shtull-Trauring
index e94d7b9723e504e4f4a509c67aea74f6a3379e27..9ea57b6b680dc59dc54192d468eb93a497f439b6 100644 (file)
@@ -49,10 +49,11 @@ Comment = r'#[^\r\n]*'
 Ignore = Whitespace + any(r'\\\r?\n' + Whitespace) + maybe(Comment)
 Name = r'[a-zA-Z_]\w*'
 
-Hexnumber = r'0[xX][\da-fA-F]*[lL]?'
-Octnumber = r'0[0-7]*[lL]?'
-Decnumber = r'[1-9]\d*[lL]?'
-Intnumber = group(Hexnumber, Octnumber, Decnumber)
+Hexnumber = r'0[xX][\da-fA-F]*'
+Binnumber = r'0[bB][01]*'
+Octnumber = r'0[oO][0-7]*'
+Decnumber = r'(?:0+|[1-9]\d*)'
+Intnumber = group(Hexnumber, Binnumber, Octnumber, Decnumber)
 Exponent = r'[eE][-+]?\d+'
 Pointfloat = group(r'\d+\.\d*', r'\.\d+') + maybe(Exponent)
 Expfloat = r'\d+' + Exponent
index 4321c366420a12f20eec638c6f267793444cd619..4ae7df4bdf3497fbbe80dd7f30b6cf0f6941d68b 100644 (file)
@@ -114,11 +114,11 @@ from urllib import localhost, url2pathname, getproxies
 __version__ = sys.version[:3]
 
 _opener = None
-def urlopen(url, data=None):
+def urlopen(url, data=None, timeout=None):
     global _opener
     if _opener is None:
         _opener = build_opener()
-    return _opener.open(url, data)
+    return _opener.open(url, data, timeout)
 
 def install_opener(opener):
     global _opener
@@ -352,7 +352,7 @@ class OpenerDirector:
             if result is not None:
                 return result
 
-    def open(self, fullurl, data=None):
+    def open(self, fullurl, data=None, timeout=None):
         # accept a URL or a Request object
         if isinstance(fullurl, basestring):
             req = Request(fullurl, data)
@@ -361,6 +361,7 @@ class OpenerDirector:
             if data is not None:
                 req.add_data(data)
 
+        req.timeout = timeout
         protocol = req.get_type()
 
         # pre-process request
@@ -944,7 +945,7 @@ class AbstractDigestAuthHandler:
             respdig = KD(H(A1), "%s:%s" % (nonce, H(A2)))
         else:
             # XXX handle auth-int.
-            pass
+            raise URLError("qop '%s' is not supported." % qop)
 
         # XXX should the partial digests be encoded too?
 
@@ -1053,7 +1054,7 @@ class AbstractHTTPHandler(BaseHandler):
         if not host:
             raise URLError('no host given')
 
-        h = http_class(host) # will parse host:port
+        h = http_class(host, timeout=req.timeout) # will parse host:port
         h.set_debuglevel(self._debuglevel)
 
         headers = dict(req.headers)
@@ -1263,7 +1264,7 @@ class FTPHandler(BaseHandler):
         if dirs and not dirs[0]:
             dirs = dirs[1:]
         try:
-            fw = self.connect_ftp(user, passwd, host, port, dirs)
+            fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout)
             type = file and 'I' or 'D'
             for attr in attrs:
                 attr, value = splitvalue(attr)
@@ -1283,8 +1284,8 @@ class FTPHandler(BaseHandler):
         except ftplib.all_errors as msg:
             raise IOError, ('ftp error', msg), sys.exc_info()[2]
 
-    def connect_ftp(self, user, passwd, host, port, dirs):
-        fw = ftpwrapper(user, passwd, host, port, dirs)
+    def connect_ftp(self, user, passwd, host, port, dirs, timeout):
+        fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
 ##        fw.ftp.set_debuglevel(1)
         return fw
 
@@ -1304,12 +1305,12 @@ class CacheFTPHandler(FTPHandler):
     def setMaxConns(self, m):
         self.max_conns = m
 
-    def connect_ftp(self, user, passwd, host, port, dirs):
-        key = user, host, port, '/'.join(dirs)
+    def connect_ftp(self, user, passwd, host, port, dirs, timeout):
+        key = user, host, port, '/'.join(dirs), timeout
         if key in self.cache:
             self.timeout[key] = time.time() + self.delay
         else:
-            self.cache[key] = ftpwrapper(user, passwd, host, port, dirs)
+            self.cache[key] = ftpwrapper(user, passwd, host, port, dirs, timeout)
             self.timeout[key] = time.time() + self.delay
         self.check_cache()
         return self.cache[key]
index 4d3cbd603f80c02b3e3bb8869f9271a528a9d35f..ff1ffe44c7c00504bf1b7b7d8ac7b318953decae 100755 (executable)
--- a/Lib/uu.py
+++ b/Lib/uu.py
@@ -68,11 +68,11 @@ def encode(in_file, out_file, name=None, mode=None):
     if name is None:
         name = '-'
     if mode is None:
-        mode = 0666
+        mode = 0o666
     #
     # Write the data
     #
-    out_file.write('begin %o %s\n' % ((mode&0777),name))
+    out_file.write('begin %o %s\n' % ((mode & 0o777),name))
     data = in_file.read(45)
     while len(data) > 0:
         out_file.write(binascii.b2a_uu(data))
index 33896f5f601d43fa7a02b712be5b0d1ab6ed9d59..bdb89fbba4286aa38dbc62fdbe83874821ca712a 100644 (file)
@@ -204,7 +204,7 @@ class KeyedRef(ref):
         return self
 
     def __init__(self, ob, callback, key):
-        super(KeyedRef,  self).__init__(ob, callback)
+        super().__init__(ob, callback)
 
 
 class WeakKeyDictionary(UserDict.UserDict):
index ec3acdf9c1ddf984cba57f6d60d5f8a957fa343b..cfd8231acedc44ac8ff1a89566e6d687ad2ad205 100644 (file)
@@ -72,7 +72,7 @@ def getDOMImplementation(name = None, features = ()):
     for creator in well_known_implementations.keys():
         try:
             dom = getDOMImplementation(name = creator)
-        except StandardError: # typically ImportError, or AttributeError
+        except Exception: # typically ImportError, or AttributeError
             continue
         if _good_enough(dom, features):
             return dom
index d5c509bf3ec037fa8bca05a6e7b98553c693c0f5..2ebe75063671c092f86f9721357764bccf8a0eaf 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -159,6 +159,7 @@ John DeGood
 Vincent Delft
 Erik Demaine
 Roger Dev
+Raghuram Devarakonda
 Toby Dickenson
 Mark Dickinson
 Yves Dionne
@@ -660,6 +661,7 @@ Lionel Ulmer
 Roger Upole
 Michael Urman
 Hector Urtubia
+Atul Varma
 Dmitry Vasiliev
 Frank Vercruesse
 Mike Verdone
index 100897957ad0e78657e1d4b18e60c3dd097b92d9..c789843030c0399bbf02c1ceee77decee533e62c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,13 @@ TO DO
 Core and Builtins
 -----------------
 
+- Removed the __oct__ and __hex__ special methods and added a bin()
+  builtin function.
+
+- PEP 3127: octal literals now start with "0o". Old-style octal literals
+  are invalid. There are binary literals with a prefix of "0b".
+  This also affects int(x, 0).
+
 - None, True, False are now keywords.
 
 - PEP 3119: isinstance() and issubclass() can be overridden.
index 21c375d9db79c061e0c5a48704030136eabbc0f5..38869312eaa16584b271e58a7a710979cc796d12 100644 (file)
@@ -88,7 +88,7 @@ if exists("python_highlight_exceptions")
   syn keyword pythonException    MemoryError NameError NotImplementedError
   syn keyword pythonException    OSError OverflowError PendingDeprecationWarning
   syn keyword pythonException    ReferenceError RuntimeError RuntimeWarning
-  syn keyword pythonException    StandardError StopIteration SyntaxError
+  syn keyword pythonException    StopIteration SyntaxError
   syn keyword pythonException    SyntaxWarning SystemError SystemExit TabError
   syn keyword pythonException    TypeError UnboundLocalError UnicodeDecodeError
   syn keyword pythonException    UnicodeEncodeError UnicodeError
index 4d7bddbba9d7889cc76d45325cda2c02d34b45db..779ba93860c3fdfa3b390cfd6a6b0201cb64bc5a 100755 (executable)
@@ -70,7 +70,7 @@ REFLOG="build/reflog.txt.out"
 LEAKY_TESTS="test_(cmd_line|socket)"
 
 # These tests always fail, so skip them so we don't get false positives.
-_ALWAYS_SKIP="test_compiler test_transformer"
+_ALWAYS_SKIP=""
 ALWAYS_SKIP="-x $_ALWAYS_SKIP"
 
 # Skip these tests altogether when looking for leaks.  These tests
index b1a428b85f4668918c0b7257501caaa578d0ddda..2ef871f0fae51f424434c53847624b211b967158 100644 (file)
@@ -779,8 +779,8 @@ When an error message is printed for an unhandled exception which is a
 class, the class name is printed, then a colon and a space, and
 finally the instance converted to a string using the built-in function
 str().
-All built-in exception classes derives from StandardError, itself
-derived from Exception.
+All built-in exception classes derives from Exception, itself
+derived from BaseException.
 
 Name Space Statements
 
@@ -1051,9 +1051,6 @@ Exception>
          On 'sys.exit()'
     StopIteration
          Signal the end from iterator.__next__()
-    StandardError
-                 Base class for all built-in exceptions; derived from Exception
-    root class.
         ArithmeticError
                  Base class for OverflowError, ZeroDivisionError,
     FloatingPointError
index 6e2741d194151c4ac5146f0749af44e41fbf4529..55ba60246da687b2049e536f7c1026489846b6b7 100644 (file)
@@ -369,7 +369,7 @@ support for features needed by `python-mode'.")
                          "NotImplementedError" "OSError" "OverflowError"
                          "OverflowWarning" "PendingDeprecationWarning"
                          "ReferenceError" "RuntimeError" "RuntimeWarning"
-                         "StandardError" "StopIteration" "SyntaxError"
+                         "StopIteration" "SyntaxError"
                          "SyntaxWarning" "SystemError" "SystemExit"
                          "TabError" "True" "TypeError" "UnboundLocalError"
                          "UnicodeDecodeError" "UnicodeEncodeError"
index 4a6710e74070c557c1fc830eda781346232ea669..a08eaac97b0509170533803077f17a1a1ad0eeac 100644 (file)
 ### use of the libraries.
 ###
 
+{
+   Generic ubuntu ld problems
+   Memcheck:Addr8
+   obj:/lib/ld-2.4.so
+   obj:/lib/ld-2.4.so
+   obj:/lib/ld-2.4.so
+   obj:/lib/ld-2.4.so
+}
+
 {
    Generic gentoo ld problems
    Memcheck:Cond
index ef0c7f33d7e8e67927dad0019db887e8f2c1f005..d569b7dcf948b94218b5769bbb06778558d47f91 100644 (file)
@@ -1713,6 +1713,7 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs)
     PyObject* dataobj;
     PyObject* retval = NULL;
     DBT key, data;
+    void *orig_data;
     DB_TXN *txn = NULL;
     static char* kwnames[] = { "key", "data", "txn", "flags", NULL };
 
@@ -1724,7 +1725,6 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs)
     CHECK_DB_NOT_CLOSED(self);
     if (!make_key_dbt(self, keyobj, &key, NULL))
         return NULL;
-    CLEAR_DBT(data);
     if ( !make_dbt(dataobj, &data) ||
          !checkTxnObj(txnobj, &txn) )
     {
@@ -1733,13 +1733,12 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs)
     }
 
     flags |= DB_GET_BOTH;
+    orig_data = data.data;
 
     if (CHECK_DBFLAG(self, DB_THREAD)) {
         /* Tell BerkeleyDB to malloc the return value (thread safe) */
+        /* XXX(nnorwitz): At least 4.4.20 and 4.5.20 require this flag. */
         data.flags = DB_DBT_MALLOC;
-        /* TODO: Is this flag needed?  We're passing a data object that should
-                 match what's in the DB, so there should be no need to malloc.
-                 We run the risk of freeing something twice!  Check this. */
     }
 
     MYDB_BEGIN_ALLOW_THREADS;
@@ -1753,8 +1752,13 @@ DB_get_both(DBObject* self, PyObject* args, PyObject* kwargs)
         retval = Py_None;
     }
     else if (!err) {
+        /* XXX(nnorwitz): can we do: retval = dataobj; Py_INCREF(retval); */
         retval = PyString_FromStringAndSize((char*)data.data, data.size);
-        FREE_DBT(data); /* Only if retrieval was successful */
+
+        /* Even though the flags require DB_DBT_MALLOC, data is not always
+           allocated.  4.4: allocated, 4.5: *not* allocated. :-( */
+        if (data.data != orig_data)
+            FREE_DBT(data);
     }
 
     FREE_DBT(key);
index 55ef0b7f7e978b67e1a6fe7e405d37daddb8a57c..ab5e895996a38ef24e0c9387ad79d9f369753a4d 100644 (file)
@@ -789,7 +789,7 @@ static int
 CharArray_set_value(CDataObject *self, PyObject *value)
 {
        char *ptr;
-       int size;
+       Py_ssize_t size;
 
        if (PyUnicode_Check(value)) {
                value = PyUnicode_AsEncodedString(value,
@@ -844,7 +844,7 @@ WCharArray_get_value(CDataObject *self)
 static int
 WCharArray_set_value(CDataObject *self, PyObject *value)
 {
-       int result = 0;
+       Py_ssize_t result = 0;
 
        if (PyString_Check(value)) {
                value = PyUnicode_FromEncodedObject(value,
@@ -868,14 +868,12 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
        result = PyUnicode_AsWideChar((PyUnicodeObject *)value,
                                      (wchar_t *)self->b_ptr,
                                      self->b_size/sizeof(wchar_t));
-       if (result >= 0 && (unsigned)result < self->b_size/sizeof(wchar_t))
+       if (result >= 0 && (size_t)result < self->b_size/sizeof(wchar_t))
                ((wchar_t *)self->b_ptr)[result] = (wchar_t)0;
-       if (result > 0)
-               result = 0;
   done:
        Py_DECREF(value);
 
-       return result;
+       return result >= 0 ? 0 : -1;
 }
 
 static PyGetSetDef WCharArray_getsets[] = {
@@ -966,7 +964,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        PyObject *typedict;
        int length;
 
-       int itemsize, itemalign;
+       Py_ssize_t itemsize, itemalign;
 
        typedict = PyTuple_GetItem(args, 2);
        if (!typedict)
@@ -1737,8 +1735,8 @@ static PyObject *
 converters_from_argtypes(PyObject *ob)
 {
        PyObject *converters;
-       int i;
-       int nArgs;
+       Py_ssize_t i;
+       Py_ssize_t nArgs;
 
        ob = PySequence_Tuple(ob); /* new reference */
        if (!ob) {
@@ -1771,7 +1769,12 @@ converters_from_argtypes(PyObject *ob)
        Py_XDECREF(converters);
        Py_DECREF(ob);
        PyErr_Format(PyExc_TypeError,
-                    "item %d in _argtypes_ has no from_param method", i+1);
+#if (PY_VERSION_HEX < 0x02050000)
+                    "item %d in _argtypes_ has no from_param method",
+#else
+                    "item %zd in _argtypes_ has no from_param method",
+#endif
+                    i+1);
        return NULL;
 }
 
@@ -2591,18 +2594,18 @@ static PyGetSetDef CFuncPtr_getsets[] = {
 #ifdef MS_WIN32
 static PPROC FindAddress(void *handle, char *name, PyObject *type)
 {
+#ifdef MS_WIN64
+       /* win64 has no stdcall calling conv, so it should
+          also not have the name mangling of it.
+       */
+       return (PPROC)GetProcAddress(handle, name);
+#else
        PPROC address;
        char *mangled_name;
        int i;
        StgDictObject *dict;
 
        address = (PPROC)GetProcAddress(handle, name);
-#ifdef _WIN64
-       /* win64 has no stdcall calling conv, so it should
-          also not have the name mangling of it.
-       */
-       return address;
-#else
        if (address)
                return address;
        if (((size_t)name & ~0xFFFF) == 0) {
@@ -2634,7 +2637,7 @@ static PPROC FindAddress(void *handle, char *name, PyObject *type)
 
 /* Return 1 if usable, 0 else and exception set. */
 static int
-_check_outarg_type(PyObject *arg, int index)
+_check_outarg_type(PyObject *arg, Py_ssize_t index)
 {
        StgDictObject *dict;
 
@@ -2655,7 +2658,7 @@ _check_outarg_type(PyObject *arg, int index)
 
        PyErr_Format(PyExc_TypeError,
                     "'out' parameter %d must be a pointer type, not %s",
-                    index,
+                    Py_SAFE_DOWNCAST(index, Py_ssize_t, int),
                     PyType_Check(arg) ?
                     ((PyTypeObject *)arg)->tp_name :
                     arg->ob_type->tp_name);
@@ -2666,7 +2669,7 @@ _check_outarg_type(PyObject *arg, int index)
 static int
 _validate_paramflags(PyTypeObject *type, PyObject *paramflags)
 {
-       int i, len;
+       Py_ssize_t i, len;
        StgDictObject *dict;
        PyObject *argtypes;
 
@@ -3051,12 +3054,12 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
        PyObject *paramflags = self->paramflags;
        PyObject *callargs;
        StgDictObject *dict;
-       int i, len;
+       Py_ssize_t i, len;
        int inargs_index = 0;
        /* It's a little bit difficult to determine how many arguments the
        function call requires/accepts.  For simplicity, we count the consumed
        args and compare this to the number of supplied args. */
-       int actual_args;
+       Py_ssize_t actual_args;
 
        *poutmask = 0;
        *pinoutmask = 0;
@@ -3093,7 +3096,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
                /* This way seems to be ~2 us faster than the PyArg_ParseTuple
                   calls below. */
                /* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
-               int tsize = PyTuple_GET_SIZE(item);
+               Py_ssize_t tsize = PyTuple_GET_SIZE(item);
                flag = PyInt_AS_LONG(PyTuple_GET_ITEM(item, 0));
                name = tsize > 1 ? PyString_AS_STRING(PyTuple_GET_ITEM(item, 1)) : NULL;
                defval = tsize > 2 ? PyTuple_GET_ITEM(item, 2) : NULL;
@@ -3193,7 +3196,11 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
                   message is misleading.  See unittests/test_paramflags.py
                 */
                PyErr_Format(PyExc_TypeError,
+#if (PY_VERSION_HEX < 0x02050000)
                             "call takes exactly %d arguments (%d given)",
+#else
+                            "call takes exactly %d arguments (%zd given)",
+#endif
                             inargs_index, actual_args);
                goto error;
        }
@@ -3339,8 +3346,10 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
                return NULL;
 
        if (converters) {
-               int required = PyTuple_GET_SIZE(converters);
-               int actual = PyTuple_GET_SIZE(callargs);
+               int required = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(converters),
+                                               Py_ssize_t, int);
+               int actual = Py_SAFE_DOWNCAST(PyTuple_GET_SIZE(callargs),
+                                             Py_ssize_t, int);
 
                if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) {
                        /* For cdecl functions, we allow more actual arguments
@@ -3679,8 +3688,8 @@ static PyTypeObject Union_Type = {
 static int
 Array_init(CDataObject *self, PyObject *args, PyObject *kw)
 {
-       int i;
-       int n;
+       Py_ssize_t i;
+       Py_ssize_t n;
 
        if (!PyTuple_Check(args)) {
                PyErr_SetString(PyExc_TypeError,
@@ -3701,7 +3710,7 @@ static PyObject *
 Array_item(PyObject *_self, Py_ssize_t index)
 {
        CDataObject *self = (CDataObject *)_self;
-       int offset, size;
+       Py_ssize_t offset, size;
        StgDictObject *stgdict;
 
 
@@ -3773,7 +3782,7 @@ static int
 Array_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
 {
        CDataObject *self = (CDataObject *)_self;
-       int size, offset;
+       Py_ssize_t size, offset;
        StgDictObject *stgdict;
        char *ptr;
 
@@ -3802,7 +3811,7 @@ static int
 Array_ass_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *value)
 {
        CDataObject *self = (CDataObject *)_self;
-       int i, len;
+       Py_ssize_t i, len;
 
        if (value == NULL) {
                PyErr_SetString(PyExc_TypeError,
@@ -4163,7 +4172,7 @@ static PyObject *
 Pointer_item(PyObject *_self, Py_ssize_t index)
 {
        CDataObject *self = (CDataObject *)_self;
-       int size;
+       Py_ssize_t size;
        Py_ssize_t offset;
        StgDictObject *stgdict, *itemdict;
        PyObject *proto;
@@ -4194,7 +4203,7 @@ static int
 Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
 {
        CDataObject *self = (CDataObject *)_self;
-       int size;
+       Py_ssize_t size;
        Py_ssize_t offset;
        StgDictObject *stgdict, *itemdict;
        PyObject *proto;
@@ -4627,9 +4636,10 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
 static PyObject *
 wstring_at(const wchar_t *ptr, int size)
 {
-       if (size == -1)
-               size = wcslen(ptr);
-       return PyUnicode_FromWideChar(ptr, size);
+       Py_ssize_t ssize = size;
+       if (ssize == -1)
+               ssize = wcslen(ptr);
+       return PyUnicode_FromWideChar(ptr, ssize);
 }
 #endif
 
@@ -4829,7 +4839,7 @@ PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
     return (PyObject *)unicode;
 }
 
-int My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
+Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
                            register wchar_t *w,
                            Py_ssize_t size)
 {
index 2ead9272919e5b54458975451d91a92a05ef15f4..497599b8d1107c4c5db0be6023380a0f0fa56de4 100644 (file)
@@ -124,10 +124,10 @@ static void _CallPythonObject(void *mem,
                              PyObject *converters,
                              void **pArgs)
 {
-       int i;
+       Py_ssize_t i;
        PyObject *result;
        PyObject *arglist = NULL;
-       int nArgs;
+       Py_ssize_t nArgs;
 #ifdef WITH_THREAD
        PyGILState_STATE state = PyGILState_Ensure();
 #endif
@@ -265,7 +265,7 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
 {
        int result;
        ffi_info *p;
-       int nArgs, i;
+       Py_ssize_t nArgs, i;
        ffi_abi cc;
 
        nArgs = PySequence_Size(converters);
@@ -308,7 +308,8 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
        if (is_cdecl == 0)
                cc = FFI_STDCALL;
 #endif
-       result = ffi_prep_cif(&p->cif, cc, nArgs,
+       result = ffi_prep_cif(&p->cif, cc,
+                             Py_SAFE_DOWNCAST(nArgs, Py_ssize_t, int),
                              GetType(restype),
                              &p->atypes[0]);
        if (result != FFI_OK) {
index ba1629df33f1be3aa92842a45a6d2cfb2b143dc8..23150b3f5789375d4abb43c02dfaad3e74d6747f 100644 (file)
@@ -361,13 +361,13 @@ PyCArg_repr(PyCArgObject *self)
        case 'z':
        case 'Z':
        case 'P':
-               sprintf(buffer, "<cparam '%c' (%08lx)>",
-                       self->tag, (long)self->value.p);
+               sprintf(buffer, "<cparam '%c' (%p)>",
+                       self->tag, self->value.p);
                break;
 
        default:
-               sprintf(buffer, "<cparam '%c' at %08lx>",
-                       self->tag, (long)self);
+               sprintf(buffer, "<cparam '%c' at %p>",
+                       self->tag, self);
                break;
        }
        return PyUnicode_FromString(buffer);
@@ -464,7 +464,7 @@ struct argument {
 /*
  * Convert a single Python object into a PyCArgObject and return it.
  */
-static int ConvParam(PyObject *obj, int index, struct argument *pa)
+static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
 {
        StgDictObject *dict;
        pa->keep = NULL; /* so we cannot forget it later */
@@ -566,7 +566,8 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa)
                        return result;
                }
                PyErr_Format(PyExc_TypeError,
-                            "Don't know how to convert parameter %d", index);
+                            "Don't know how to convert parameter %d", 
+                            Py_SAFE_DOWNCAST(index, Py_ssize_t, int));
                return -1;
        }
 }
@@ -906,7 +907,7 @@ PyObject *_CallProc(PPROC pProc,
                    PyObject *restype,
                    PyObject *checker)
 {
-       int i, n, argcount, argtype_count;
+       Py_ssize_t i, n, argcount, argtype_count;
        void *resbuf;
        struct argument *args, *pa;
        ffi_type **atypes;
@@ -996,7 +997,10 @@ PyObject *_CallProc(PPROC pProc,
        }
 
        if (-1 == _call_function_pointer(flags, pProc, avalues, atypes,
-                                        rtype, resbuf, argcount))
+                                        rtype, resbuf,
+                                        Py_SAFE_DOWNCAST(argcount,
+                                                         Py_ssize_t,
+                                                         int)))
                goto cleanup;
 
 #ifdef WORDS_BIGENDIAN
@@ -1036,6 +1040,15 @@ PyObject *_CallProc(PPROC pProc,
        return retval;
 }
 
+static int
+_parse_voidp(PyObject *obj, void **address)
+{
+       *address = PyLong_AsVoidPtr(obj);
+       if (*address == NULL)
+               return 0;
+       return 1;
+}
+
 #ifdef MS_WIN32
 
 #ifdef _UNICODE
@@ -1123,7 +1136,7 @@ Free the handle of an executable previously loaded by LoadLibrary.\n";
 static PyObject *free_library(PyObject *self, PyObject *args)
 {
        void *hMod;
-       if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":FreeLibrary", &hMod))
+       if (!PyArg_ParseTuple(args, "O&:FreeLibrary", &_parse_voidp, &hMod))
                return NULL;
        if (!FreeLibrary((HMODULE)hMod))
                return PyErr_SetFromWindowsErr(GetLastError());
@@ -1246,7 +1259,7 @@ static PyObject *py_dl_close(PyObject *self, PyObject *args)
 {
        void *handle;
 
-       if (!PyArg_ParseTuple(args, PY_VOID_P_CODE ":dlclose", &handle))
+       if (!PyArg_ParseTuple(args, "O&:dlclose", &_parse_voidp, &handle))
                return NULL;
        if (dlclose(handle)) {
                PyErr_SetString(PyExc_OSError,
@@ -1263,7 +1276,8 @@ static PyObject *py_dl_sym(PyObject *self, PyObject *args)
        void *handle;
        void *ptr;
 
-       if (!PyArg_ParseTuple(args, PY_VOID_P_CODE "s:dlsym", &handle, &name))
+       if (!PyArg_ParseTuple(args, "O&s:dlsym",
+                             &_parse_voidp, &handle, &name))
                return NULL;
        ptr = ctypes_dlsym((void*)handle, name);
        if (!ptr) {
@@ -1288,8 +1302,8 @@ call_function(PyObject *self, PyObject *args)
        PyObject *result;
 
        if (!PyArg_ParseTuple(args,
-                             PY_VOID_P_CODE "O!",
-                             &func,
+                             "O&O!",
+                             &_parse_voidp, &func,
                              &PyTuple_Type, &arguments))
                return NULL;
 
@@ -1319,8 +1333,8 @@ call_cdeclfunction(PyObject *self, PyObject *args)
        PyObject *result;
 
        if (!PyArg_ParseTuple(args,
-                             PY_VOID_P_CODE "O!",
-                             &func,
+                             "O&O!",
+                             &_parse_voidp, &func,
                              &PyTuple_Type, &arguments))
                return NULL;
 
@@ -1352,10 +1366,10 @@ sizeof_func(PyObject *self, PyObject *obj)
 
        dict = PyType_stgdict(obj);
        if (dict)
-               return PyInt_FromLong(dict->size);
+               return PyInt_FromSsize_t(dict->size);
 
        if (CDataObject_Check(obj))
-               return PyInt_FromLong(((CDataObject *)obj)->b_size);
+               return PyInt_FromSsize_t(((CDataObject *)obj)->b_size);
        PyErr_SetString(PyExc_TypeError,
                        "this type has no size");
        return NULL;
@@ -1373,11 +1387,11 @@ align_func(PyObject *self, PyObject *obj)
 
        dict = PyType_stgdict(obj);
        if (dict)
-               return PyInt_FromLong(dict->align);
+               return PyInt_FromSsize_t(dict->align);
 
        dict = PyObject_stgdict(obj);
        if (dict)
-               return PyInt_FromLong(dict->align);
+               return PyInt_FromSsize_t(dict->align);
 
        PyErr_SetString(PyExc_TypeError,
                        "no alignment info");
index 5874f5282cc8f958db2d47e78e926b91e3e5aca8..1d91edfdcbbabe0d446b677530d6be43568cac1a 100644 (file)
@@ -35,14 +35,14 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  * prev_desc points to the type of the previous bitfield, if any.
  */
 PyObject *
-CField_FromDesc(PyObject *desc, int index,
-               int *pfield_size, int bitsize, int *pbitofs,
-               int *psize, int *poffset, int *palign,
+CField_FromDesc(PyObject *desc, Py_ssize_t index,
+               Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
+               Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
                int pack, int big_endian)
 {
        CFieldObject *self;
        PyObject *proto;
-       int size, align, length;
+       Py_ssize_t size, align, length;
        SETFUNC setfunc = NULL;
        GETFUNC getfunc = NULL;
        StgDictObject *dict;
@@ -147,7 +147,7 @@ CField_FromDesc(PyObject *desc, int index,
                else
                        align = dict->align;
                if (align && *poffset % align) {
-                       int delta = align - (*poffset % align);
+                       Py_ssize_t delta = align - (*poffset % align);
                        *psize += delta;
                        *poffset += delta;
                }
@@ -220,21 +220,13 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
 static PyObject *
 CField_get_offset(PyObject *self, void *data)
 {
-#if (PY_VERSION_HEX < 0x02050000)
-       return PyInt_FromLong(((CFieldObject *)self)->offset);
-#else
        return PyInt_FromSsize_t(((CFieldObject *)self)->offset);
-#endif
 }
 
 static PyObject *
 CField_get_size(PyObject *self, void *data)
 {
-#if (PY_VERSION_HEX < 0x02050000)
-       return PyInt_FromLong(((CFieldObject *)self)->size);
-#else
        return PyInt_FromSsize_t(((CFieldObject *)self)->size);
-#endif
 }
 
 static PyGetSetDef CField_getset[] = {
@@ -268,8 +260,8 @@ static PyObject *
 CField_repr(CFieldObject *self)
 {
        PyObject *result;
-       int bits = self->size >> 16;
-       int size = self->size & 0xFFFF;
+       Py_ssize_t bits = self->size >> 16;
+       Py_ssize_t size = self->size & 0xFFFF;
        const char *name;
 
        name = ((PyTypeObject *)self->proto)->tp_name;
@@ -279,7 +271,7 @@ CField_repr(CFieldObject *self)
 #if (PY_VERSION_HEX < 0x02050000)
                        "<Field type=%s, ofs=%d:%d, bits=%d>",
 #else
-                       "<Field type=%s, ofs=%zd:%d, bits=%d>",
+                       "<Field type=%s, ofs=%zd:%zd, bits=%zd>",
 #endif
                        name, self->offset, size, bits);
        else
@@ -287,7 +279,7 @@ CField_repr(CFieldObject *self)
 #if (PY_VERSION_HEX < 0x02050000)
                        "<Field type=%s, ofs=%d, size=%d>",
 #else
-                       "<Field type=%s, ofs=%zd, size=%d>",
+                       "<Field type=%s, ofs=%zd, size=%zd>",
 #endif
                        name, self->offset, size);
        return result;
@@ -519,7 +511,7 @@ get_ulonglong(PyObject *v, unsigned PY_LONG_LONG *p)
  */
 
 static PyObject *
-b_set(void *ptr, PyObject *value, unsigned size)
+b_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        if (get_long(value, &val) < 0)
@@ -530,7 +522,7 @@ b_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-b_get(void *ptr, unsigned size)
+b_get(void *ptr, Py_ssize_t size)
 {
        signed char val = *(signed char *)ptr;
        GET_BITFIELD(val, size);
@@ -538,7 +530,7 @@ b_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-B_set(void *ptr, PyObject *value, unsigned size)
+B_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        if (get_ulong(value, &val) < 0)
@@ -550,7 +542,7 @@ B_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-B_get(void *ptr, unsigned size)
+B_get(void *ptr, Py_ssize_t size)
 {
        unsigned char val = *(unsigned char *)ptr;
        GET_BITFIELD(val, size);
@@ -558,7 +550,7 @@ B_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-h_set(void *ptr, PyObject *value, unsigned size)
+h_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        short x;
@@ -572,7 +564,7 @@ h_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-h_set_sw(void *ptr, PyObject *value, unsigned size)
+h_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        short field;
@@ -587,7 +579,7 @@ h_set_sw(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-h_get(void *ptr, unsigned size)
+h_get(void *ptr, Py_ssize_t size)
 {
        short val;
        memcpy(&val, ptr, sizeof(val));
@@ -596,7 +588,7 @@ h_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-h_get_sw(void *ptr, unsigned size)
+h_get_sw(void *ptr, Py_ssize_t size)
 {
        short val;
        memcpy(&val, ptr, sizeof(val));
@@ -606,7 +598,7 @@ h_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-H_set(void *ptr, PyObject *value, unsigned size)
+H_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned short x;
@@ -619,7 +611,7 @@ H_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-H_set_sw(void *ptr, PyObject *value, unsigned size)
+H_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned short field;
@@ -635,7 +627,7 @@ H_set_sw(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-H_get(void *ptr, unsigned size)
+H_get(void *ptr, Py_ssize_t size)
 {
        unsigned short val;
        memcpy(&val, ptr, sizeof(val));
@@ -644,7 +636,7 @@ H_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-H_get_sw(void *ptr, unsigned size)
+H_get_sw(void *ptr, Py_ssize_t size)
 {
        unsigned short val;
        memcpy(&val, ptr, sizeof(val));
@@ -654,7 +646,7 @@ H_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-i_set(void *ptr, PyObject *value, unsigned size)
+i_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        int x;
@@ -667,7 +659,7 @@ i_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-i_set_sw(void *ptr, PyObject *value, unsigned size)
+i_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        int field;
@@ -683,7 +675,7 @@ i_set_sw(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-i_get(void *ptr, unsigned size)
+i_get(void *ptr, Py_ssize_t size)
 {
        int val;
        memcpy(&val, ptr, sizeof(val));
@@ -692,7 +684,7 @@ i_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-i_get_sw(void *ptr, unsigned size)
+i_get_sw(void *ptr, Py_ssize_t size)
 {
        int val;
        memcpy(&val, ptr, sizeof(val));
@@ -704,7 +696,7 @@ i_get_sw(void *ptr, unsigned size)
 #ifdef MS_WIN32
 /* short BOOL - VARIANT_BOOL */
 static PyObject *
-vBOOL_set(void *ptr, PyObject *value, unsigned size)
+vBOOL_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        switch (PyObject_IsTrue(value)) {
        case -1:
@@ -719,7 +711,7 @@ vBOOL_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-vBOOL_get(void *ptr, unsigned size)
+vBOOL_get(void *ptr, Py_ssize_t size)
 {
        return PyBool_FromLong((long)*(short int *)ptr);
 }
@@ -734,7 +726,7 @@ vBOOL_get(void *ptr, unsigned size)
 #endif
 
 static PyObject *
-t_set(void *ptr, PyObject *value, unsigned size)
+t_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        switch (PyObject_IsTrue(value)) {
        case -1:
@@ -749,13 +741,13 @@ t_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-t_get(void *ptr, unsigned size)
+t_get(void *ptr, Py_ssize_t size)
 {
        return PyBool_FromLong((long)*(BOOL_TYPE *)ptr);
 }
 
 static PyObject *
-I_set(void *ptr, PyObject *value, unsigned size)
+I_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned int x;
@@ -768,7 +760,7 @@ I_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-I_set_sw(void *ptr, PyObject *value, unsigned size)
+I_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned int field;
@@ -783,7 +775,7 @@ I_set_sw(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-I_get(void *ptr, unsigned size)
+I_get(void *ptr, Py_ssize_t size)
 {
        unsigned int val;
        memcpy(&val, ptr, sizeof(val));
@@ -792,7 +784,7 @@ I_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-I_get_sw(void *ptr, unsigned size)
+I_get_sw(void *ptr, Py_ssize_t size)
 {
        unsigned int val;
        memcpy(&val, ptr, sizeof(val));
@@ -802,7 +794,7 @@ I_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-l_set(void *ptr, PyObject *value, unsigned size)
+l_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        long x;
@@ -815,7 +807,7 @@ l_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-l_set_sw(void *ptr, PyObject *value, unsigned size)
+l_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        long val;
        long field;
@@ -831,7 +823,7 @@ l_set_sw(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-l_get(void *ptr, unsigned size)
+l_get(void *ptr, Py_ssize_t size)
 {
        long val;
        memcpy(&val, ptr, sizeof(val));
@@ -840,7 +832,7 @@ l_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-l_get_sw(void *ptr, unsigned size)
+l_get_sw(void *ptr, Py_ssize_t size)
 {
        long val;
        memcpy(&val, ptr, sizeof(val));
@@ -850,7 +842,7 @@ l_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-L_set(void *ptr, PyObject *value, unsigned size)
+L_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned long x;
@@ -863,7 +855,7 @@ L_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-L_set_sw(void *ptr, PyObject *value, unsigned size)
+L_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned long val;
        unsigned long field;
@@ -879,7 +871,7 @@ L_set_sw(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-L_get(void *ptr, unsigned size)
+L_get(void *ptr, Py_ssize_t size)
 {
        unsigned long val;
        memcpy(&val, ptr, sizeof(val));
@@ -888,7 +880,7 @@ L_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-L_get_sw(void *ptr, unsigned size)
+L_get_sw(void *ptr, Py_ssize_t size)
 {
        unsigned long val;
        memcpy(&val, ptr, sizeof(val));
@@ -899,7 +891,7 @@ L_get_sw(void *ptr, unsigned size)
 
 #ifdef HAVE_LONG_LONG
 static PyObject *
-q_set(void *ptr, PyObject *value, unsigned size)
+q_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        PY_LONG_LONG val;
        PY_LONG_LONG x;
@@ -912,7 +904,7 @@ q_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-q_set_sw(void *ptr, PyObject *value, unsigned size)
+q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        PY_LONG_LONG val;
        PY_LONG_LONG field;
@@ -927,7 +919,7 @@ q_set_sw(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-q_get(void *ptr, unsigned size)
+q_get(void *ptr, Py_ssize_t size)
 {
        PY_LONG_LONG val;
        memcpy(&val, ptr, sizeof(val));
@@ -936,7 +928,7 @@ q_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-q_get_sw(void *ptr, unsigned size)
+q_get_sw(void *ptr, Py_ssize_t size)
 {
        PY_LONG_LONG val;
        memcpy(&val, ptr, sizeof(val));
@@ -946,7 +938,7 @@ q_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-Q_set(void *ptr, PyObject *value, unsigned size)
+Q_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned PY_LONG_LONG val;
        unsigned PY_LONG_LONG x;
@@ -959,7 +951,7 @@ Q_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-Q_set_sw(void *ptr, PyObject *value, unsigned size)
+Q_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        unsigned PY_LONG_LONG val;
        unsigned PY_LONG_LONG field;
@@ -974,7 +966,7 @@ Q_set_sw(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-Q_get(void *ptr, unsigned size)
+Q_get(void *ptr, Py_ssize_t size)
 {
        unsigned PY_LONG_LONG val;
        memcpy(&val, ptr, sizeof(val));
@@ -983,7 +975,7 @@ Q_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-Q_get_sw(void *ptr, unsigned size)
+Q_get_sw(void *ptr, Py_ssize_t size)
 {
        unsigned PY_LONG_LONG val;
        memcpy(&val, ptr, sizeof(val));
@@ -1000,7 +992,7 @@ Q_get_sw(void *ptr, unsigned size)
 
 
 static PyObject *
-d_set(void *ptr, PyObject *value, unsigned size)
+d_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        double x;
 
@@ -1016,7 +1008,7 @@ d_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-d_get(void *ptr, unsigned size)
+d_get(void *ptr, Py_ssize_t size)
 {
        double val;
        memcpy(&val, ptr, sizeof(val));
@@ -1024,7 +1016,7 @@ d_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-d_set_sw(void *ptr, PyObject *value, unsigned size)
+d_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        double x;
 
@@ -1046,7 +1038,7 @@ d_set_sw(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-d_get_sw(void *ptr, unsigned size)
+d_get_sw(void *ptr, Py_ssize_t size)
 {
 #ifdef WORDS_BIGENDIAN
        return PyFloat_FromDouble(_PyFloat_Unpack8(ptr, 1));
@@ -1056,7 +1048,7 @@ d_get_sw(void *ptr, unsigned size)
 }
 
 static PyObject *
-f_set(void *ptr, PyObject *value, unsigned size)
+f_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        float x;
 
@@ -1072,7 +1064,7 @@ f_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-f_get(void *ptr, unsigned size)
+f_get(void *ptr, Py_ssize_t size)
 {
        float val;
        memcpy(&val, ptr, sizeof(val));
@@ -1080,7 +1072,7 @@ f_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-f_set_sw(void *ptr, PyObject *value, unsigned size)
+f_set_sw(void *ptr, PyObject *value, Py_ssize_t size)
 {
        float x;
 
@@ -1102,7 +1094,7 @@ f_set_sw(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-f_get_sw(void *ptr, unsigned size)
+f_get_sw(void *ptr, Py_ssize_t size)
 {
 #ifdef WORDS_BIGENDIAN
        return PyFloat_FromDouble(_PyFloat_Unpack4(ptr, 1));
@@ -1122,7 +1114,7 @@ f_get_sw(void *ptr, unsigned size)
   Py_DECREF on destruction.  Maybe only when b_needsfree is non-zero.
 */
 static PyObject *
-O_get(void *ptr, unsigned size)
+O_get(void *ptr, Py_ssize_t size)
 {
        PyObject *ob = *(PyObject **)ptr;
        if (ob == NULL) {
@@ -1137,7 +1129,7 @@ O_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-O_set(void *ptr, PyObject *value, unsigned size)
+O_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        /* Hm, does the memory block need it's own refcount or not? */
        *(PyObject **)ptr = value;
@@ -1147,7 +1139,7 @@ O_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-c_set(void *ptr, PyObject *value, unsigned size)
+c_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        if (!PyString_Check(value) || (1 != PyString_Size(value))) {
                PyErr_Format(PyExc_TypeError,
@@ -1160,7 +1152,7 @@ c_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-c_get(void *ptr, unsigned size)
+c_get(void *ptr, Py_ssize_t size)
 {
        return PyString_FromStringAndSize((char *)ptr, 1);
 }
@@ -1168,9 +1160,9 @@ c_get(void *ptr, unsigned size)
 #ifdef CTYPES_UNICODE
 /* u - a single wchar_t character */
 static PyObject *
-u_set(void *ptr, PyObject *value, unsigned size)
+u_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
-       int len;
+       Py_ssize_t len;
 
        if (PyString_Check(value)) {
                value = PyUnicode_FromEncodedObject(value,
@@ -1202,17 +1194,17 @@ u_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-u_get(void *ptr, unsigned size)
+u_get(void *ptr, Py_ssize_t size)
 {
        return PyUnicode_FromWideChar((wchar_t *)ptr, 1);
 }
 
 /* U - a unicode string */
 static PyObject *
-U_get(void *ptr, unsigned size)
+U_get(void *ptr, Py_ssize_t size)
 {
        PyObject *result;
-       unsigned int len;
+       Py_ssize_t len;
        Py_UNICODE *p;
 
        size /= sizeof(wchar_t); /* we count character units here, not bytes */
@@ -1240,9 +1232,9 @@ U_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-U_set(void *ptr, PyObject *value, unsigned length)
+U_set(void *ptr, PyObject *value, Py_ssize_t length)
 {
-       unsigned int size;
+       Py_ssize_t size;
 
        /* It's easier to calculate in characters than in bytes */
        length /= sizeof(wchar_t);
@@ -1263,7 +1255,11 @@ U_set(void *ptr, PyObject *value, unsigned length)
        size = PyUnicode_GET_SIZE(value);
        if (size > length) {
                PyErr_Format(PyExc_ValueError,
+#if (PY_VERSION_HEX < 0x02050000)
                             "string too long (%d, maximum length %d)",
+#else
+                            "string too long (%zd, maximum length %zd)",
+#endif
                             size, length);
                Py_DECREF(value);
                return NULL;
@@ -1277,9 +1273,10 @@ U_set(void *ptr, PyObject *value, unsigned length)
 #endif
 
 static PyObject *
-s_get(void *ptr, unsigned size)
+s_get(void *ptr, Py_ssize_t size)
 {
        PyObject *result;
+       size_t slen;
 
        result = PyString_FromString((char *)ptr);
        if (!result)
@@ -1287,7 +1284,8 @@ s_get(void *ptr, unsigned size)
        /* chop off at the first NUL character, if any.
         * On error, result will be deallocated and set to NULL.
         */
-       size = min(size, strlen(PyString_AS_STRING(result)));
+       slen = strlen(PyString_AS_STRING(result));
+       size = min(size, (Py_ssize_t)slen);
        if (result->ob_refcnt == 1) {
                /* shorten the result */
                _PyString_Resize(&result, size);
@@ -1298,10 +1296,10 @@ s_get(void *ptr, unsigned size)
 }
 
 static PyObject *
-s_set(void *ptr, PyObject *value, unsigned length)
+s_set(void *ptr, PyObject *value, Py_ssize_t length)
 {
        char *data;
-       unsigned size;
+       Py_ssize_t size;
 
        data = PyString_AsString(value);
        if (!data)
@@ -1314,7 +1312,11 @@ s_set(void *ptr, PyObject *value, unsigned length)
                ++size;
        } else if (size > length) {
                PyErr_Format(PyExc_ValueError,
+#if (PY_VERSION_HEX < 0x02050000)
                             "string too long (%d, maximum length %d)",
+#else
+                            "string too long (%zd, maximum length %zd)",
+#endif
                             size, length);
                return NULL;
        }
@@ -1324,7 +1326,7 @@ s_set(void *ptr, PyObject *value, unsigned length)
 }
 
 static PyObject *
-z_set(void *ptr, PyObject *value, unsigned size)
+z_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        if (value == Py_None) {
                *(char **)ptr = NULL;
@@ -1358,7 +1360,7 @@ z_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-z_get(void *ptr, unsigned size)
+z_get(void *ptr, Py_ssize_t size)
 {
        /* XXX What about invalid pointers ??? */
        if (*(void **)ptr) {
@@ -1379,7 +1381,7 @@ z_get(void *ptr, unsigned size)
 
 #ifdef CTYPES_UNICODE
 static PyObject *
-Z_set(void *ptr, PyObject *value, unsigned size)
+Z_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        if (value == Py_None) {
                *(wchar_t **)ptr = NULL;
@@ -1447,7 +1449,7 @@ Z_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-Z_get(void *ptr, unsigned size)
+Z_get(void *ptr, Py_ssize_t size)
 {
        wchar_t *p;
        p = *(wchar_t **)ptr;
@@ -1470,7 +1472,7 @@ Z_get(void *ptr, unsigned size)
 
 #ifdef MS_WIN32
 static PyObject *
-BSTR_set(void *ptr, PyObject *value, unsigned size)
+BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        BSTR bstr;
 
@@ -1494,8 +1496,13 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
 
        /* create a BSTR from value */
        if (value) {
+               Py_ssize_t size = PyUnicode_GET_SIZE(value);
+               if ((unsigned) size != size) {
+                       PyErr_SetString(PyExc_ValueError, "String too long for BSTR");
+                       return NULL;
+               }
                bstr = SysAllocStringLen(PyUnicode_AS_UNICODE(value),
-                                        PyUnicode_GET_SIZE(value));
+                                        (unsigned)size);
                Py_DECREF(value);
        } else
                bstr = NULL;
@@ -1513,7 +1520,7 @@ BSTR_set(void *ptr, PyObject *value, unsigned size)
 
 
 static PyObject *
-BSTR_get(void *ptr, unsigned size)
+BSTR_get(void *ptr, Py_ssize_t size)
 {
        BSTR p;
        p = *(BSTR *)ptr;
@@ -1530,7 +1537,7 @@ BSTR_get(void *ptr, unsigned size)
 #endif
 
 static PyObject *
-P_set(void *ptr, PyObject *value, unsigned size)
+P_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
        void *v;
        if (value == Py_None) {
@@ -1563,7 +1570,7 @@ P_set(void *ptr, PyObject *value, unsigned size)
 }
 
 static PyObject *
-P_get(void *ptr, unsigned size)
+P_get(void *ptr, Py_ssize_t size)
 {
        if (*(void **)ptr == NULL) {
                Py_INCREF(Py_None);
index 5fb603075d3363606872c1088e79c8469d880b97..5846e3fc594a2c0b38d69745a11f6251cf37f8f5 100644 (file)
@@ -4,6 +4,7 @@
 
 #if (PY_VERSION_HEX < 0x02050000)
 typedef int Py_ssize_t;
+#define PyInt_FromSsize_t PyInt_FromLong
 #endif
 
 #ifndef MS_WIN32
@@ -23,16 +24,10 @@ typedef int Py_ssize_t;
 #define PY_LONG_LONG LONG_LONG
 #endif
 
-#if SIZEOF_VOID_P == SIZEOF_LONG
-#define PY_VOID_P_CODE "k"
-#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P == SIZEOF_LONG_LONG)
-#define PY_VOID_P_CODE "K"
-#endif
-
 typedef struct tagPyCArgObject PyCArgObject;
 typedef struct tagCDataObject CDataObject;
-typedef PyObject *(* GETFUNC)(void *, unsigned size);
-typedef PyObject *(* SETFUNC)(void *, PyObject *value, unsigned size);
+typedef PyObject *(* GETFUNC)(void *, Py_ssize_t size);
+typedef PyObject *(* SETFUNC)(void *, PyObject *value, Py_ssize_t size);
 typedef PyCArgObject *(* PARAMFUNC)(CDataObject *obj);
 
 /* A default buffer in CDataObject, which can be used for small C types.  If
@@ -137,9 +132,9 @@ extern struct fielddesc *getentry(char *fmt);
 
 
 extern PyObject *
-CField_FromDesc(PyObject *desc, int index,
-               int *pfield_size, int bitsize, int *pbitofs,
-               int *psize, int *poffset, int *palign,
+CField_FromDesc(PyObject *desc, Py_ssize_t index,
+               Py_ssize_t *pfield_size, int bitsize, int *pbitofs,
+               Py_ssize_t *psize, Py_ssize_t *poffset, Py_ssize_t *palign,
                int pack, int is_big_endian);
 
 extern PyObject *CData_AtAddress(PyObject *type, void *buf);
@@ -310,7 +305,7 @@ struct tagPyCArgObject {
                void *p;
        } value;
        PyObject *obj;
-       int size; /* for the 'V' tag */
+       Py_ssize_t size; /* for the 'V' tag */
 };
 
 extern PyTypeObject PyCArg_Type;
@@ -387,7 +382,7 @@ extern char *conversion_mode_errors;
 #  define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
 
 extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, Py_ssize_t);
-extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
+extern Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, Py_ssize_t);
 
 #endif
 
index 7f792b7a9204406e42e02b04ed0a99569eefd024..cc63b6bd2aedda1c7b28a061572d7b53985418ca 100644 (file)
@@ -174,7 +174,7 @@ extern void ffi_call_SYSV(void (*)(char *, extended_cif *),
                          /*@out@*/ extended_cif *, 
                          unsigned, unsigned, 
                          /*@out@*/ unsigned *, 
-                         void (*fn)());
+                         void (*fn)(void));
 /*@=declundef@*/
 /*@=exportheader@*/
 
@@ -185,13 +185,13 @@ extern void ffi_call_STDCALL(void (*)(char *, extended_cif *),
                          /*@out@*/ extended_cif *,
                          unsigned, unsigned,
                          /*@out@*/ unsigned *,
-                         void (*fn)());
+                         void (*fn)(void));
 /*@=declundef@*/
 /*@=exportheader@*/
 #endif /* X86_WIN32 */
 
 void ffi_call(/*@dependent@*/ ffi_cif *cif, 
-             void (*fn)(), 
+             void (*fn)(void), 
              /*@out@*/ void *rvalue, 
              /*@dependent@*/ void **avalue)
 {
@@ -405,7 +405,7 @@ ffi_call_SYSV(void (*)(char *, extended_cif *),
              /*@out@*/ extended_cif *, 
              unsigned, unsigned, 
              /*@out@*/ unsigned *, 
-             void (*fn)());
+             void (*fn)(void));
 
 #ifdef X86_WIN32
 extern void
@@ -413,12 +413,12 @@ ffi_call_STDCALL(void (*)(char *, extended_cif *),
              /*@out@*/ extended_cif *,
              unsigned, unsigned,
              /*@out@*/ unsigned *,
-             void (*fn)());
+             void (*fn)(void));
 #endif /* X86_WIN32 */
 
 void
 ffi_raw_call(/*@dependent@*/ ffi_cif *cif, 
-            void (*fn)(), 
+            void (*fn)(void), 
             /*@out@*/ void *rvalue, 
             /*@dependent@*/ ffi_raw *fake_avalue)
 {
index c6cf330c2c3e7321027e30639654a8e5faba5b9f..fa352f78fc7ec3a0c0a5b2451fd3d79f99245c71 100644 (file)
@@ -42,7 +42,7 @@ struct register_args
 };
 
 extern void ffi_call_unix64 (void *args, unsigned long bytes, unsigned flags,
-                            void *raddr, void (*fnaddr)(), unsigned ssecount);
+                            void *raddr, void (*fnaddr)(void), unsigned ssecount);
 
 /* All reference to register classes here is identical to the code in
    gcc/config/i386/i386.c. Do *not* change one without the other.  */
@@ -339,7 +339,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
 }
 
 void
-ffi_call (ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
+ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
 {
   enum x86_64_reg_class classes[MAX_CLASSES];
   char *stack, *argp;
index 4241d3cc4cb83069f70cbc29966cac3c290c0a1d..07e142bdfe0675a0b01b0fc5904c12492578d160 100644 (file)
@@ -50,7 +50,7 @@ int
 StgDict_clone(StgDictObject *dst, StgDictObject *src)
 {
        char *d, *s;
-       int size;
+       Py_ssize_t size;
 
        StgDict_clear(dst);
        PyMem_Free(dst->ffi_type_pointer.elements);
@@ -285,13 +285,13 @@ int
 StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
 {
        StgDictObject *stgdict, *basedict;
-       int len, offset, size, align, i;
-       int union_size, total_align;
-       int field_size = 0;
+       Py_ssize_t len, offset, size, align, i;
+       Py_ssize_t union_size, total_align;
+       Py_ssize_t field_size = 0;
        int bitofs;
        PyObject *isPacked;
        int pack = 0;
-       int ffi_ofs;
+       Py_ssize_t ffi_ofs;
        int big_endian;
 
        /* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
@@ -402,7 +402,11 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
                if (dict == NULL) {
                        Py_DECREF(pair);
                        PyErr_Format(PyExc_TypeError,
+#if (PY_VERSION_HEX < 0x02050000)
                                     "second item in _fields_ tuple (index %d) must be a C type",
+#else
+                                    "second item in _fields_ tuple (index %zd) must be a C type",
+#endif
                                     i);
                        return -1;
                }
@@ -480,7 +484,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
        /* Adjust the size according to the alignment requirements */
        size = ((size + total_align - 1) / total_align) * total_align;
 
-       stgdict->ffi_type_pointer.alignment = total_align;
+       stgdict->ffi_type_pointer.alignment = Py_SAFE_DOWNCAST(total_align,
+                                                              Py_ssize_t,
+                                                              unsigned short);
        stgdict->ffi_type_pointer.size = size;
 
        stgdict->size = size;
index 18a40667aee82f493d0a243b97f0f153d852a609..6094eb3a0b04ad581682354c25bf99dddddeea51 100644 (file)
@@ -243,6 +243,7 @@ PyObject* pysqlite_cache_display(pysqlite_Cache* self, PyObject* args)
         }
         template = PyString_FromString("%s <- %s ->%s\n");
         if (!template) {
+            Py_DECREF(fmt_args);
             return NULL;
         }
         display_str = PyString_Format(template, fmt_args);
index 8844d81ad400c6e97f9d97dce47f02c3ad3f025c..4525c61acb4158a57f4bfbf7f58cef6bf0258862 100644 (file)
@@ -287,12 +287,12 @@ PyMODINIT_FUNC init_sqlite3(void)
 
     /*** Create DB-API Exception hierarchy */
 
-    if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_StandardError, NULL))) {
+    if (!(pysqlite_Error = PyErr_NewException(MODULE_NAME ".Error", PyExc_Exception, NULL))) {
         goto error;
     }
     PyDict_SetItemString(dict, "Error", pysqlite_Error);
 
-    if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_StandardError, NULL))) {
+    if (!(pysqlite_Warning = PyErr_NewException(MODULE_NAME ".Warning", PyExc_Exception, NULL))) {
         goto error;
     }
     PyDict_SetItemString(dict, "Warning", pysqlite_Warning);
index 71e42c10e6c38b2f0554453fe64d4372df3cf7f9..3a72b40640b649af98a8ec1163596d36a9dca777 100644 (file)
@@ -726,7 +726,7 @@ void print_delta(int test, struct timeval *s, struct timeval *e)
                e->tv_sec -=1;
                e->tv_usec += 1000000;
        }
-       printf("Test %d: %d.%06ds\n", test, (int)e->tv_sec, e->tv_usec);
+       printf("Test %d: %d.%06ds\n", test, (int)e->tv_sec, (int)e->tv_usec);
 }
 
 static PyObject *
@@ -884,6 +884,10 @@ typedef struct {
        unsigned long ulong_member;
        float float_member;
        double double_member;
+#ifdef HAVE_LONG_LONG
+       PY_LONG_LONG longlong_member;
+       unsigned PY_LONG_LONG ulonglong_member;
+#endif
 } all_structmembers;
 
 typedef struct {
@@ -902,23 +906,40 @@ static struct PyMemberDef test_members[] = {
        {"T_ULONG", T_ULONG, offsetof(test_structmembers, structmembers.ulong_member), 0, NULL},
        {"T_FLOAT", T_FLOAT, offsetof(test_structmembers, structmembers.float_member), 0, NULL},
        {"T_DOUBLE", T_DOUBLE, offsetof(test_structmembers, structmembers.double_member), 0, NULL},
+#ifdef HAVE_LONG_LONG
+       {"T_LONGLONG", T_LONGLONG, offsetof(test_structmembers, structmembers.longlong_member), 0, NULL},
+       {"T_ULONGLONG", T_ULONGLONG, offsetof(test_structmembers, structmembers.ulonglong_member), 0, NULL},
+#endif
        {NULL}
 };
 
 
 static PyObject *test_structmembers_new(PyTypeObject *type, PyObject *args, PyObject *kwargs){
        static char *keywords[]={"T_BYTE", "T_UBYTE", "T_SHORT", "T_USHORT", "T_INT", "T_UINT",
-               "T_LONG", "T_ULONG", "T_FLOAT", "T_DOUBLE", NULL};
+               "T_LONG", "T_ULONG", "T_FLOAT", "T_DOUBLE",
+               #ifdef HAVE_LONG_LONG   
+               "T_LONGLONG", "T_ULONGLONG",
+               #endif
+               NULL};
+       static char *fmt="|bBhHiIlkfd"
+               #ifdef HAVE_LONG_LONG
+               "LK"
+               #endif
+               ;
        test_structmembers *ob=PyObject_New(test_structmembers, type);
        if (ob==NULL)
                return NULL;
        memset(&ob->structmembers, 0, sizeof(all_structmembers));
-       if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|bBhHiIlkfd", keywords,
+       if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt, keywords,
                &ob->structmembers.byte_member, &ob->structmembers.ubyte_member,
                &ob->structmembers.short_member, &ob->structmembers.ushort_member,
                &ob->structmembers.int_member, &ob->structmembers.uint_member, 
                &ob->structmembers.long_member, &ob->structmembers.ulong_member,
-               &ob->structmembers.float_member, &ob->structmembers.double_member)){
+               &ob->structmembers.float_member, &ob->structmembers.double_member
+               #ifdef HAVE_LONG_LONG
+               ,&ob->structmembers.longlong_member, &ob->structmembers.ulonglong_member
+               #endif
+               )){
                Py_DECREF(ob);
                return NULL;
                }
@@ -1001,6 +1022,9 @@ init_testcapi(void)
        PyModule_AddObject(m, "FLT_MIN", PyFloat_FromDouble(FLT_MIN));
        PyModule_AddObject(m, "DBL_MAX", PyFloat_FromDouble(DBL_MAX));
        PyModule_AddObject(m, "DBL_MIN", PyFloat_FromDouble(DBL_MIN));
+       PyModule_AddObject(m, "LLONG_MAX", PyLong_FromLongLong(PY_LLONG_MAX));
+       PyModule_AddObject(m, "LLONG_MIN", PyLong_FromLongLong(PY_LLONG_MIN));
+       PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
        PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX));
        PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN));
 
index dae82b7c2c4b78c0f2e614609c7c23f8b5ee5cc3..81b3500d98ac8ec83ef81b7ed4124500b215fe59 100644 (file)
@@ -1220,6 +1220,8 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
        cres = NULL;
 
        for (;;) {
+               int endoffile;
+
                if (sizehint < 0)
                        cres = PyObject_CallMethod(self->stream,
                                        (char *)method, NULL);
@@ -1245,6 +1247,8 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
                        goto errorexit;
                }
 
+               endoffile = (PyString_GET_SIZE(cres) == 0);
+
                if (self->pendingsize > 0) {
                        PyObject *ctr;
                        char *ctrdata;
@@ -1272,7 +1276,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
                                (MultibyteStatefulDecoderContext *)self, &buf))
                        goto errorexit;
 
-               if (rsize == 0 || sizehint < 0) { /* end of file */
+               if (endoffile || sizehint < 0) {
                        if (buf.inbuf < buf.inbuf_end &&
                            multibytecodec_decerror(self->codec, &self->state,
                                        &buf, self->errors, MBERR_TOOFEW))
index 0f71ca03d0a52894cd4817ea16ebe8048028a6b3..b673f3f98d4150a2993dcd37fa5e8eaf07d2ce7d 100644 (file)
 #endif
 #endif
 
+/* on unix, SVNVERSION is passed on the command line.
+ * on Windows, the string is interpolated using
+ * subwcrev.exe
+ */
+#ifndef SVNVERSION
 #define SVNVERSION "$WCRANGE$$WCMODS?M:$"
+#endif
+
 const char *
 Py_GetBuildInfo(void)
 {
@@ -39,7 +46,7 @@ _Py_svnversion(void)
 {
        /* the following string can be modified by subwcrev.exe */
        static const char svnversion[] = SVNVERSION;
-       if (!strstr(svnversion, "$"))
-               return svnversion; /* it was interpolated */
+       if (svnversion[0] != '$')
+               return svnversion; /* it was interpolated, or passed on command line */
        return "exported";
 }
index 94ddddaab055f0495ca241ed90c6264bc58285bb..52436405d1344b8bd717afae8b91fa06f0a63838 100644 (file)
@@ -361,8 +361,11 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
 #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP
 #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM
 #define BTPROTO_HCI BLUETOOTH_PROTO_HCI
+#define SOL_HCI SOL_HCI_RAW
+#define HCI_FILTER SO_HCI_RAW_FILTER
 #define sockaddr_l2 sockaddr_l2cap
 #define sockaddr_rc sockaddr_rfcomm
+#define hci_dev hci_node
 #define _BT_L2_MEMB(sa, memb) ((sa)->l2cap_##memb)
 #define _BT_RC_MEMB(sa, memb) ((sa)->rfcomm_##memb)
 #define _BT_HCI_MEMB(sa, memb) ((sa)->hci_##memb)
@@ -4335,10 +4338,10 @@ init_socket(void)
        PyModule_AddIntConstant(m, "BTPROTO_L2CAP", BTPROTO_L2CAP);
        PyModule_AddIntConstant(m, "BTPROTO_HCI", BTPROTO_HCI);
        PyModule_AddIntConstant(m, "SOL_HCI", SOL_HCI);
-       PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP);
-       PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR);
        PyModule_AddIntConstant(m, "HCI_FILTER", HCI_FILTER);
 #if !defined(__FreeBSD__)
+       PyModule_AddIntConstant(m, "HCI_TIME_STAMP", HCI_TIME_STAMP);
+       PyModule_AddIntConstant(m, "HCI_DATA_DIR", HCI_DATA_DIR);
        PyModule_AddIntConstant(m, "BTPROTO_SCO", BTPROTO_SCO);
 #endif
        PyModule_AddIntConstant(m, "BTPROTO_RFCOMM", BTPROTO_RFCOMM);
index 6e638525d7c11109f397d1d8c4f8290e93063347..d43bb6a40b075aafdbe4de348d4e93d789a73a88 100644 (file)
@@ -969,6 +969,22 @@ PyNumber_Float(PyObject *o)
        return PyFloat_FromString(o);
 }
 
+
+PyObject *
+PyNumber_ToBase(PyObject *n, int base)
+{
+       PyObject *res;
+       PyObject *index = PyNumber_Index(n);
+
+       if (!index)
+               return NULL;
+       assert(PyLong_Check(index));
+       res = _PyLong_Format(index, base);
+       Py_DECREF(index);
+       return res;
+}
+
+
 /* Operations on sequences */
 
 int
index dd2566820da989e5c5558f82683fc81e9c03a23c..4b38aa2e70807614e1d3989fce675a3609d873f1 100644 (file)
@@ -19,7 +19,7 @@ enum buffer_t {
     READ_BUFFER,
     WRITE_BUFFER,
     CHAR_BUFFER,
-    ANY_BUFFER,
+    ANY_BUFFER
 };
 
 static int
index 2fb58e253794a88874c5d832ef92cb623e0ca362..c9335ad8380d506fdba042a90084a6990147a205 100644 (file)
@@ -314,17 +314,9 @@ SimpleExtendsException(PyExc_BaseException, Exception,
 
 
 /*
- *    StandardError extends Exception
+ *    TypeError extends Exception
  */
-SimpleExtendsException(PyExc_Exception, StandardError,
-    "Base class for all standard Python exceptions that do not represent\n"
-    "interpreter exiting.");
-
-
-/*
- *    TypeError extends StandardError
- */
-SimpleExtendsException(PyExc_StandardError, TypeError,
+SimpleExtendsException(PyExc_Exception, TypeError,
                        "Inappropriate argument type.");
 
 
@@ -405,14 +397,14 @@ SimpleExtendsException(PyExc_BaseException, KeyboardInterrupt,
 
 
 /*
- *    ImportError extends StandardError
+ *    ImportError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, ImportError,
+SimpleExtendsException(PyExc_Exception, ImportError,
           "Import can't find module, or can't find name in module.");
 
 
 /*
- *    EnvironmentError extends StandardError
+ *    EnvironmentError extends Exception
  */
 
 /* Where a function has a single filename, such as open() or some
@@ -561,7 +553,7 @@ static PyMethodDef EnvironmentError_methods[] = {
     {NULL}
 };
 
-ComplexExtendsException(PyExc_StandardError, EnvironmentError,
+ComplexExtendsException(PyExc_Exception, EnvironmentError,
                         EnvironmentError, EnvironmentError_dealloc,
                         EnvironmentError_methods, EnvironmentError_members,
                         EnvironmentError_str,
@@ -695,16 +687,16 @@ MiddlingExtendsException(PyExc_OSError, VMSError, EnvironmentError,
 
 
 /*
- *    EOFError extends StandardError
+ *    EOFError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, EOFError,
+SimpleExtendsException(PyExc_Exception, EOFError,
                        "Read beyond end of file.");
 
 
 /*
- *    RuntimeError extends StandardError
+ *    RuntimeError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, RuntimeError,
+SimpleExtendsException(PyExc_Exception, RuntimeError,
                        "Unspecified run-time error.");
 
 
@@ -715,9 +707,9 @@ SimpleExtendsException(PyExc_RuntimeError, NotImplementedError,
                        "Method or function hasn't been implemented yet.");
 
 /*
- *    NameError extends StandardError
+ *    NameError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, NameError,
+SimpleExtendsException(PyExc_Exception, NameError,
                        "Name not found globally.");
 
 /*
@@ -727,14 +719,14 @@ SimpleExtendsException(PyExc_NameError, UnboundLocalError,
                        "Local name referenced but not bound to a value.");
 
 /*
- *    AttributeError extends StandardError
+ *    AttributeError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, AttributeError,
+SimpleExtendsException(PyExc_Exception, AttributeError,
                        "Attribute not found.");
 
 
 /*
- *    SyntaxError extends StandardError
+ *    SyntaxError extends Exception
  */
 
 static int
@@ -884,7 +876,7 @@ static PyMemberDef SyntaxError_members[] = {
     {NULL}  /* Sentinel */
 };
 
-ComplexExtendsException(PyExc_StandardError, SyntaxError, SyntaxError,
+ComplexExtendsException(PyExc_Exception, SyntaxError, SyntaxError,
                         SyntaxError_dealloc, 0, SyntaxError_members,
                         SyntaxError_str, "Invalid syntax.");
 
@@ -904,9 +896,9 @@ MiddlingExtendsException(PyExc_IndentationError, TabError, SyntaxError,
 
 
 /*
- *    LookupError extends StandardError
+ *    LookupError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, LookupError,
+SimpleExtendsException(PyExc_Exception, LookupError,
                        "Base class for lookup errors.");
 
 
@@ -943,9 +935,9 @@ ComplexExtendsException(PyExc_LookupError, KeyError, BaseException,
 
 
 /*
- *    ValueError extends StandardError
+ *    ValueError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, ValueError,
+SimpleExtendsException(PyExc_Exception, ValueError,
                        "Inappropriate argument value (of correct type).");
 
 /*
@@ -1558,16 +1550,16 @@ PyUnicodeTranslateError_Create(
 
 
 /*
- *    AssertionError extends StandardError
+ *    AssertionError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, AssertionError,
+SimpleExtendsException(PyExc_Exception, AssertionError,
                        "Assertion failed.");
 
 
 /*
- *    ArithmeticError extends StandardError
+ *    ArithmeticError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, ArithmeticError,
+SimpleExtendsException(PyExc_Exception, ArithmeticError,
                        "Base class for arithmetic errors.");
 
 
@@ -1593,9 +1585,9 @@ SimpleExtendsException(PyExc_ArithmeticError, ZeroDivisionError,
 
 
 /*
- *    SystemError extends StandardError
+ *    SystemError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, SystemError,
+SimpleExtendsException(PyExc_Exception, SystemError,
     "Internal error in the Python interpreter.\n"
     "\n"
     "Please report this to the Python maintainer, along with the traceback,\n"
@@ -1603,16 +1595,16 @@ SimpleExtendsException(PyExc_StandardError, SystemError,
 
 
 /*
- *    ReferenceError extends StandardError
+ *    ReferenceError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, ReferenceError,
+SimpleExtendsException(PyExc_Exception, ReferenceError,
                        "Weak ref proxy used after referent went away.");
 
 
 /*
- *    MemoryError extends StandardError
+ *    MemoryError extends Exception
  */
-SimpleExtendsException(PyExc_StandardError, MemoryError, "Out of memory.");
+SimpleExtendsException(PyExc_Exception, MemoryError, "Out of memory.");
 
 
 /* Warning category docstrings */
@@ -1725,7 +1717,6 @@ _PyExc_Init(void)
 
     PRE_INIT(BaseException)
     PRE_INIT(Exception)
-    PRE_INIT(StandardError)
     PRE_INIT(TypeError)
     PRE_INIT(StopIteration)
     PRE_INIT(GeneratorExit)
@@ -1785,7 +1776,6 @@ _PyExc_Init(void)
 
     POST_INIT(BaseException)
     POST_INIT(Exception)
-    POST_INIT(StandardError)
     POST_INIT(TypeError)
     POST_INIT(StopIteration)
     POST_INIT(GeneratorExit)
index ad60a49b2d9685aa58cf2921b320780e67b670b1..14f98b941fdb78dd0cb7d93f854309038a4a9a0c 100644 (file)
@@ -917,28 +917,6 @@ int_float(PyIntObject *v)
        return PyFloat_FromDouble((double)(v -> ob_ival));
 }
 
-static PyObject *
-int_oct(PyIntObject *v)
-{
-       long x = v -> ob_ival;
-       if (x < 0)
-               return PyUnicode_FromFormat("-0%lo", -x);
-       else if (x == 0)
-               return PyUnicode_FromString("0");
-       else
-               return PyUnicode_FromFormat("0%lo", x);
-}
-
-static PyObject *
-int_hex(PyIntObject *v)
-{
-       long x = v -> ob_ival;
-       if (x < 0)
-               return PyUnicode_FromFormat("-0x%lx", -x);
-       else
-               return PyUnicode_FromFormat("0x%lx", x);
-}
-
 static PyObject *
 int_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
 
@@ -1064,8 +1042,8 @@ static PyNumberMethods int_as_number = {
        (unaryfunc)int_int,     /*nb_int*/
        (unaryfunc)int_long,    /*nb_long*/
        (unaryfunc)int_float,   /*nb_float*/
-       (unaryfunc)int_oct,     /*nb_oct*/
-       (unaryfunc)int_hex,     /*nb_hex*/
+       0,                      /*nb_oct*/ /* not in use */
+       0,                      /*nb_hex*/ /* not in use */
        0,                      /*nb_inplace_add*/
        0,                      /*nb_inplace_subtract*/
        0,                      /*nb_inplace_multiply*/
index 1f497c4141f6ba6f779014f47a5fb3e4d1114960..1f568d8eac43ebfa9d3a6858551db6cd238b2981 100644 (file)
@@ -80,7 +80,6 @@ static PyLongObject *long_normalize(PyLongObject *);
 static PyLongObject *mul1(PyLongObject *, wdigit);
 static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
 static PyLongObject *divrem1(PyLongObject *, digit, digit *);
-static PyObject *long_format(PyObject *aa, int base);
 
 #define SIGCHECK(PyTryBlock) \
        if (--_Py_Ticker < 0) { \
@@ -1384,7 +1383,7 @@ muladd1(PyLongObject *a, wdigit n, wdigit extra)
 /* Divide long pin, w/ size digits, by non-zero digit n, storing quotient
    in pout, and returning the remainder.  pin and pout point at the LSD.
    It's OK for pin == pout on entry, which saves oodles of mallocs/frees in
-   long_format, but that should be done with great care since longs are
+   _PyLong_Format, but that should be done with great care since longs are
    immutable. */
 
 static digit
@@ -1424,10 +1423,10 @@ divrem1(PyLongObject *a, digit n, digit *prem)
 
 /* Convert a long int object to a string, using a given conversion base.
    Return a string object.
-   If base is 8 or 16, add the proper prefix '0' or '0x'. */
+   If base is 2, 8 or 16, add the proper prefix '0b', '0o' or '0x'. */
 
-static PyObject *
-long_format(PyObject *aa, int base)
+PyObject *
+_PyLong_Format(PyObject *aa, int base)
 {
        register PyLongObject *a = (PyLongObject *)aa;
        PyObject *str;
@@ -1551,14 +1550,18 @@ long_format(PyObject *aa, int base)
                Py_DECREF(scratch);
        }
 
-       if (base == 8) {
-               if (size_a != 0)
-                       *--p = '0';
-       }
-       else if (base == 16) {
+       if (base == 16) {
                *--p = 'x';
                *--p = '0';
        }
+       else if (base == 8) {
+               *--p = 'o';
+               *--p = '0';
+       }
+       else if (base == 2) {
+               *--p = 'b';
+               *--p = '0';
+       }
        else if (base != 10) {
                *--p = '#';
                *--p = '0' + base%10;
@@ -1677,9 +1680,9 @@ long_from_binary_base(char **str, int base)
 PyObject *
 PyLong_FromString(char *str, char **pend, int base)
 {
-       int sign = 1;
+       int sign = 1, error_if_nonzero = 0;
        char *start, *orig_str = str;
-       PyLongObject *z;
+       PyLongObject *z = NULL;
        PyObject *strobj, *strrepr;
        Py_ssize_t slen;
 
@@ -1703,10 +1706,21 @@ PyLong_FromString(char *str, char **pend, int base)
                        base = 10;
                else if (str[1] == 'x' || str[1] == 'X')
                        base = 16;
-               else
+               else if (str[1] == 'o' || str[1] == 'O')
                        base = 8;
+               else if (str[1] == 'b' || str[1] == 'B')
+                       base = 2;
+               else {
+                       /* "old" (C-style) octal literal, now invalid.
+                          it might still be zero though */
+                       error_if_nonzero = 1;
+                       base = 10;
+               }
        }
-       if (base == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
+       if (str[0] == '0' &&
+           ((base == 16 && (str[1] == 'x' || str[1] == 'X')) ||
+            (base == 8  && (str[1] == 'o' || str[1] == 'O')) ||
+            (base == 2  && (str[1] == 'b' || str[1] == 'B'))))
                str += 2;
 
        start = str;
@@ -1910,6 +1924,15 @@ digit beyond the first.
        }
        if (z == NULL)
                return NULL;
+       if (error_if_nonzero) {
+               /* reset the base to 0, else the exception message
+                  doesn't make too much sense */
+               base = 0;
+               if (z->ob_size != 0)
+                       goto onError;
+               /* there might still be other problems, therefore base
+                  remains zero here for the same reason */
+       }
        if (str == start)
                goto onError;
        if (sign < 0)
@@ -2130,7 +2153,7 @@ long_dealloc(PyObject *v)
 static PyObject *
 long_repr(PyObject *v)
 {
-       return long_format(v, 10);
+       return _PyLong_Format(v, 10);
 }
 
 static int
@@ -3488,18 +3511,6 @@ long_float(PyObject *v)
        return PyFloat_FromDouble(result);
 }
 
-static PyObject *
-long_oct(PyObject *v)
-{
-       return long_format(v, 8);
-}
-
-static PyObject *
-long_hex(PyObject *v)
-{
-       return long_format(v, 16);
-}
-
 static PyObject *
 long_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
 
@@ -3631,8 +3642,8 @@ static PyNumberMethods long_as_number = {
                        long_int,       /*nb_int*/
                        long_long,      /*nb_long*/
                        long_float,     /*nb_float*/
-                       long_oct,       /*nb_oct*/
-                       long_hex,       /*nb_hex*/
+                       0,              /*nb_oct*/ /* not used */
+                       0,              /*nb_hex*/ /* not used */
        0,                              /* nb_inplace_add */
        0,                              /* nb_inplace_subtract */
        0,                              /* nb_inplace_multiply */
index 92bc95bf371048f4c65c8864a66651cd15fec97a..62955b9c7aa93df8acdd4e8b055e070ce4ed826d 100644 (file)
@@ -3265,7 +3265,7 @@ string_expandtabs(PyStringObject *self, PyObject *args)
 {
     const char *e, *p;
     char *q;
-    Py_ssize_t i, j;
+    Py_ssize_t i, j, old_j;
     PyObject *u;
     int tabsize = 8;
 
@@ -3273,21 +3273,38 @@ string_expandtabs(PyStringObject *self, PyObject *args)
        return NULL;
 
     /* First pass: determine size of output string */
-    i = j = 0;
+    i = j = old_j = 0;
     e = PyString_AS_STRING(self) + PyString_GET_SIZE(self);
     for (p = PyString_AS_STRING(self); p < e; p++)
         if (*p == '\t') {
-           if (tabsize > 0)
+           if (tabsize > 0) {
                j += tabsize - (j % tabsize);
+               if (old_j > j) {
+                   PyErr_SetString(PyExc_OverflowError,
+                                   "new string is too long");
+                   return NULL;
+               }
+               old_j = j;
+            }
        }
         else {
             j++;
             if (*p == '\n' || *p == '\r') {
                 i += j;
-                j = 0;
+                old_j = j = 0;
+                if (i < 0) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "new string is too long");
+                    return NULL;
+                }
             }
         }
 
+    if ((i + j) < 0) {
+        PyErr_SetString(PyExc_OverflowError, "new string is too long");
+        return NULL;
+    }
+
     /* Second pass: create output string and fill it */
     u = PyString_FromStringAndSize(NULL, i + j);
     if (!u)
@@ -4199,12 +4216,13 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
                result = val->ob_type->tp_str(val);
                break;
        case 'o':
-               result = val->ob_type->tp_as_number->nb_oct(val);
+               numnondigits = 2;
+               result = PyNumber_ToBase(val, 8);
                break;
        case 'x':
        case 'X':
                numnondigits = 2;
-               result = val->ob_type->tp_as_number->nb_hex(val);
+               result = PyNumber_ToBase(val, 16);
                break;
        default:
                assert(!"'type' not in [duoxX]");
@@ -4239,32 +4257,16 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
        assert(numdigits > 0);
 
        /* Get rid of base marker unless F_ALT */
-       if ((flags & F_ALT) == 0) {
-               /* Need to skip 0x, 0X or 0. */
-               int skipped = 0;
-               switch (type) {
-               case 'o':
-                       assert(buf[sign] == '0');
-                       /* If 0 is only digit, leave it alone. */
-                       if (numdigits > 1) {
-                               skipped = 1;
-                               --numdigits;
-                       }
-                       break;
-               case 'x':
-               case 'X':
-                       assert(buf[sign] == '0');
-                       assert(buf[sign + 1] == 'x');
-                       skipped = 2;
-                       numnondigits -= 2;
-                       break;
-               }
-               if (skipped) {
-                       buf += skipped;
-                       len -= skipped;
-                       if (sign)
-                               buf[0] = '-';
-               }
+       if (((flags & F_ALT) == 0 &&
+           (type == 'o' || type == 'x' || type == 'X'))) {
+               assert(buf[sign] == '0');
+               assert(buf[sign+1] == 'x' || buf[sign+1] == 'X' ||
+                       buf[sign+1] == 'o');
+               numnondigits -= 2;
+               buf += 2;
+               len -= 2;
+               if (sign)
+                       buf[0] = '-';
                assert(len == numnondigits + numdigits);
                assert(numdigits > 0);
        }
@@ -4333,9 +4335,10 @@ formatint(char *buf, size_t buflen, int flags,
                prec = 1;
 
        if ((flags & F_ALT) &&
-           (type == 'x' || type == 'X')) {
-               /* When converting under %#x or %#X, there are a number
+           (type == 'x' || type == 'X' || type == 'o')) {
+               /* When converting under %#o, %#x or %#X, there are a number
                 * of issues that cause pain:
+                * - for %#o, we want a different base marker than C
                 * - when 0 is being converted, the C standard leaves off
                 *   the '0x' or '0X', which is inconsistent with other
                 *   %#x/%#X conversions and inconsistent with Python's
@@ -4363,7 +4366,7 @@ formatint(char *buf, size_t buflen, int flags,
                              prec, type);
        }
 
-       /* buf = '+'/'-'/'' + '0'/'0x'/'' + '[0-9]'*max(prec, len(x in octal))
+       /* buf = '+'/'-'/'' + '0o'/'0x'/'' + '[0-9]'*max(prec, len(x in octal))
         * worst case buf = '-0x' + [0-9]*prec, where prec >= 11
         */
        if (buflen <= 14 || buflen <= (size_t)3 + (size_t)prec) {
@@ -4751,7 +4754,8 @@ PyString_Format(PyObject *format, PyObject *args)
                                if (width > len)
                                        width--;
                        }
-                       if ((flags & F_ALT) && (c == 'x' || c == 'X')) {
+                       if ((flags & F_ALT) &&
+                           (c == 'x' || c == 'X' || c == 'o')) {
                                assert(pbuf[0] == '0');
                                assert(pbuf[1] == c);
                                if (fill != ' ') {
@@ -4774,7 +4778,7 @@ PyString_Format(PyObject *format, PyObject *args)
                                if (sign)
                                        *res++ = sign;
                                if ((flags & F_ALT) &&
-                                   (c == 'x' || c == 'X')) {
+                                   (c == 'x' || c == 'X' || c == 'o')) {
                                        assert(pbuf[0] == '0');
                                        assert(pbuf[1] == c);
                                        *res++ = *pbuf++;
index 4cdb7e30d46fe98140b61095e67810ca86e7d956..9d65451fcaab3c70109bca7aed8f2c318b70d038 100644 (file)
@@ -1,6 +1,7 @@
 /* Type object implementation */
 
 #include "Python.h"
+#include "frameobject.h"
 #include "structmember.h"
 
 #include <ctype.h>
@@ -3190,8 +3191,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
                COPYNUM(nb_int);
                COPYNUM(nb_long);
                COPYNUM(nb_float);
-               COPYNUM(nb_oct);
-               COPYNUM(nb_hex);
                COPYNUM(nb_inplace_add);
                COPYNUM(nb_inplace_subtract);
                COPYNUM(nb_inplace_multiply);
@@ -4510,8 +4509,6 @@ SLOT1BIN(slot_nb_or, nb_or, "__or__", "__ror__")
 SLOT0(slot_nb_int, "__int__")
 SLOT0(slot_nb_long, "__long__")
 SLOT0(slot_nb_float, "__float__")
-SLOT0(slot_nb_oct, "__oct__")
-SLOT0(slot_nb_hex, "__hex__")
 SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
 SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *, "O")
 SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *, "O")
@@ -5168,10 +5165,6 @@ static slotdef slotdefs[] = {
               "long(x)"),
        UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc,
               "float(x)"),
-       UNSLOT("__oct__", nb_oct, slot_nb_oct, wrap_unaryfunc,
-              "oct(x)"),
-       UNSLOT("__hex__", nb_hex, slot_nb_hex, wrap_unaryfunc,
-              "hex(x)"),
        NBSLOT("__index__", nb_index, slot_nb_index, wrap_unaryfunc, 
               "x[y:z] <==> x[y.__index__():z.__index__()]"),
        IBSLOT("__iadd__", nb_inplace_add, slot_nb_inplace_add,
@@ -5834,14 +5827,77 @@ static int
 super_init(PyObject *self, PyObject *args, PyObject *kwds)
 {
        superobject *su = (superobject *)self;
-       PyTypeObject *type;
+       PyTypeObject *type = NULL;
        PyObject *obj = NULL;
        PyTypeObject *obj_type = NULL;
 
        if (!_PyArg_NoKeywords("super", kwds))
                return -1;
-       if (!PyArg_ParseTuple(args, "O!|O:super", &PyType_Type, &type, &obj))
+       if (!PyArg_ParseTuple(args, "|O!O:super", &PyType_Type, &type, &obj))
                return -1;
+
+        if (type == NULL) {
+               /* Call super(), without args -- fill in from __class__
+                  and first local variable on the stack. */
+               PyFrameObject *f = PyThreadState_GET()->frame;
+               PyCodeObject *co = f->f_code;
+               int i, n;
+               if (co == NULL) {
+                       PyErr_SetString(PyExc_SystemError,
+                                       "super(): no code object");
+                       return -1;
+               }
+               if (co->co_argcount == 0) {
+                       PyErr_SetString(PyExc_SystemError,
+                                       "super(): no arguments");
+                       return -1;
+               }
+               obj = f->f_localsplus[0];
+               if (obj == NULL) {
+                       PyErr_SetString(PyExc_SystemError,
+                                       "super(): arg[0] deleted");
+                       return -1;
+               }
+               if (co->co_freevars == NULL)
+                       n = 0;
+               else {
+                       assert(PyTuple_Check(co->co_freevars));
+                       n = PyTuple_GET_SIZE(co->co_freevars);
+               }
+               for (i = 0; i < n; i++) {
+                       PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i);
+                       assert(PyUnicode_Check(name));
+                        if (!PyUnicode_CompareWithASCIIString(name,
+                                                              "__class__")) {
+                               PyObject *cell =
+                                       f->f_localsplus[co->co_nlocals + i];
+                               if (cell == NULL || !PyCell_Check(cell)) {
+                                       PyErr_SetString(PyExc_SystemError,
+                                         "super(): bad __class__ cell");
+                                       return -1;
+                               }
+                               type = (PyTypeObject *) PyCell_GET(cell);
+                               if (type == NULL) {
+                                       PyErr_SetString(PyExc_SystemError,
+                                         "super(): empty __class__ cell");
+                                       return -1;
+                               }
+                               if (!PyType_Check(type)) {
+                                   PyErr_Format(PyExc_SystemError,
+                                     "super(): __class__ is not a type (%s)",
+                                     type->ob_type->tp_name);
+                                   return -1;
+                               }
+                               break;
+                       }
+               }
+               if (type == NULL) {
+                       PyErr_SetString(PyExc_SystemError,
+                                       "super(): __class__ cell not found");
+                       return -1;
+               }
+        }
+
        if (obj == Py_None)
                obj = NULL;
        if (obj != NULL) {
@@ -5858,13 +5914,19 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)
 }
 
 PyDoc_STRVAR(super_doc,
+"super() -> same as super(__class__, <first argument>)\n"
 "super(type) -> unbound super object\n"
 "super(type, obj) -> bound super object; requires isinstance(obj, type)\n"
 "super(type, type2) -> bound super object; requires issubclass(type2, type)\n"
 "Typical use to call a cooperative superclass method:\n"
 "class C(B):\n"
 "    def meth(self, arg):\n"
-"       super(C, self).meth(arg)");
+"       super().meth(arg)\n"
+"This works for class methods too:\n"
+"class C(B):\n"
+"    @classmethod\n"
+"    def cmeth(cls, arg):\n"
+"       super().cmeth(arg)\n");
 
 static int
 super_traverse(PyObject *self, visitproc visit, void *arg)
index 18843c060bed60cbb94fe56ea8a11f184524f258..7310ebd02681a30623ab8f65fd27a160c2615e3f 100644 (file)
@@ -6217,7 +6217,7 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
     Py_UNICODE *e;
     Py_UNICODE *p;
     Py_UNICODE *q;
-    Py_ssize_t i, j;
+    Py_ssize_t i, j, old_j;
     PyUnicodeObject *u;
     int tabsize = 8;
 
@@ -6225,21 +6225,38 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
        return NULL;
 
     /* First pass: determine size of output string */
-    i = j = 0;
+    i = j = old_j = 0;
     e = self->str + self->length;
     for (p = self->str; p < e; p++)
         if (*p == '\t') {
-           if (tabsize > 0)
+           if (tabsize > 0) {
                j += tabsize - (j % tabsize);
+               if (old_j > j) {
+                   PyErr_SetString(PyExc_OverflowError,
+                                   "new string is too long");
+                   return NULL;
+               }
+               old_j = j;
+           }
        }
         else {
             j++;
             if (*p == '\n' || *p == '\r') {
                 i += j;
-                j = 0;
+                old_j = j = 0;
+                if (i < 0) {
+                    PyErr_SetString(PyExc_OverflowError,
+                                    "new string is too long");
+                    return NULL;
+                }
             }
         }
 
+    if ((i + j) < 0) {
+        PyErr_SetString(PyExc_OverflowError, "new string is too long");
+        return NULL;
+    }
+
     /* Second pass: create output string and fill it */
     u = _PyUnicode_New(i + j);
     if (!u)
@@ -7997,9 +8014,10 @@ formatint(Py_UNICODE *buf,
     }
 
     if ((flags & F_ALT) &&
-        (type == 'x' || type == 'X')) {
-        /* When converting under %#x or %#X, there are a number
+        (type == 'x' || type == 'X' || type == 'o')) {
+        /* When converting under %#o, %#x or %#X, there are a number
          * of issues that cause pain:
+        * - for %#o, we want a different base marker than C
          * - when 0 is being converted, the C standard leaves off
          *   the '0x' or '0X', which is inconsistent with other
          *   %#x/%#X conversions and inconsistent with Python's
@@ -8457,7 +8475,7 @@ PyObject *PyUnicode_Format(PyObject *format,
                if (width > len)
                    width--;
            }
-           if ((flags & F_ALT) && (c == 'x' || c == 'X')) {
+           if ((flags & F_ALT) && (c == 'x' || c == 'X' || c == 'o')) {
                assert(pbuf[0] == '0');
                assert(pbuf[1] == c);
                if (fill != ' ') {
@@ -8479,7 +8497,7 @@ PyObject *PyUnicode_Format(PyObject *format,
            if (fill == ' ') {
                if (sign)
                    *res++ = sign;
-               if ((flags & F_ALT) && (c == 'x' || c == 'X')) {
+               if ((flags & F_ALT) && (c == 'x' || c == 'X' || c == 'o')) {
                    assert(pbuf[0] == '0');
                    assert(pbuf[1] == c);
                    *res++ = *pbuf++;
index 190b3aae3a8c6e18b88712a8755fbc74041e18fc..a6eb97bc9deebf7922c126337ac97b93f7bc69f8 100644 (file)
@@ -767,7 +767,6 @@ EXPORTS
   "_PyExc_Fini"
   "PyExc_BaseException"
   "PyExc_Exception"
-  "PyExc_StandardError"
   "PyExc_TypeError"
   "PyExc_StopIteration"
   "PyExc_GeneratorExit"
index 79d05b05f0b8aede94e14fa2920b2a21fa50f81c..b33644503cc538add4b3b479aa692774215f0c1a 100644 (file)
@@ -30,7 +30,6 @@ EXPORTS
                PyExc_OSError
                PyExc_OverflowError
                PyExc_RuntimeError
-               PyExc_StandardError
                PyExc_SyntaxError
                PyExc_SystemError
                PyExc_SystemExit
index 11086e480836d733572f338d8662b2eda6c844ee..fed87754a297ee5212de72f054d023e360d8beb9 100644 (file)
@@ -247,6 +247,9 @@ typedef int pid_t;
 #define COMPILER "[gcc]"
 #define hypot _hypot
 #define PY_LONG_LONG long long
+#define PY_LLONG_MIN LLONG_MIN
+#define PY_LLONG_MAX LLONG_MAX
+#define PY_ULLONG_MAX ULLONG_MAX
 #endif /* GNUC */
 
 /* ------------------------------------------------------------------------*/
@@ -272,6 +275,9 @@ typedef int pid_t;
 #define HAVE_LONG_LONG 1
 #ifndef PY_LONG_LONG
 #      define PY_LONG_LONG __int64
+#      define PY_LLONG_MAX LLONG_MAX
+#      define PY_LLONG_MIN LLONG_MIN
+#      define PY_ULLONG_MAX ULLONG_MAX
 #endif
 
 /* For Windows the Python core is in a DLL by default.  Test
index f901d53639737394bf5f6a3ec10d42e8ae2d8edf..85da3b352fbbf74aa5b787e8a974037177439de3 100644 (file)
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalOptions=" /MACHINE:AMD64 /USELINK:MS_SDK"
-                               AdditionalDependencies="..\..\db-4.4.20\build_win32\Release_AMD64\libdb44s.lib"
+                               AdditionalDependencies="..\..\db-4.4.20\build_win32\Release_AMD64\libdb44s.lib bufferoverflowU.lib"
                                OutputFile="./_bsddb.pyd"
                                LinkIncremental="1"
                                SuppressStartupBanner="TRUE"
index 5641c6a72db1623869fd1bc5fb36cf5a30202746..3420ef13f32b1859d486fa780fb0c00e4194d6ff 100644 (file)
@@ -1,3 +1,4 @@
+EXTRA_LIBS=
 
 !IFDEF DEBUG
 SUFFIX=_d.pyd
@@ -26,12 +27,12 @@ _ssl$(SUFFIX): $(SSL_SOURCE) $(SSL_LIB_DIR)/libeay32.lib $(SSL_LIB_DIR)/ssleay32
        @if not exist "$(TEMP)/_ssl/." mkdir "$(TEMP)/_ssl"
        cl /nologo /c $(SSL_SOURCE) $(CFLAGS) /Fo$(TEMP)\_ssl\$*.obj $(INCLUDES)
        link /nologo @<<
-             /dll /out:_ssl$(SUFFIX) $(TEMP)\_ssl\$*.obj $(SSL_LIBS)
+             /dll /out:_ssl$(SUFFIX) $(TEMP)\_ssl\$*.obj $(SSL_LIBS) $(EXTRA_LIBS)
 <<
 
 _hashlib$(SUFFIX): $(HASH_SOURCE) $(SSL_LIB_DIR)/libeay32.lib ../PC/*.h ../Include/*.h
     @if not exist "$(TEMP)/_hashlib/." mkdir "$(TEMP)/_hashlib"
     cl /nologo /c $(HASH_SOURCE) $(CFLAGS) $(EXTRA_CFLAGS) /Fo$(TEMP)\_hashlib\$*.obj $(INCLUDES) 
     link /nologo @<<
-       /dll /out:_hashlib$(SUFFIX) $(HASH_LIBS) $(TEMP)\_hashlib\$*.obj
+       /dll /out:_hashlib$(SUFFIX) $(HASH_LIBS) $(EXTRA_LIBS) $(TEMP)\_hashlib\$*.obj
 <<
index 82572ed18ae53c82a307c6cdf03db55fac7649d6..9aad44127baf158a6ab92fc1146fb7df7d2b8e63 100644 (file)
@@ -1,3 +1,5 @@
+if "%1" == "ReleaseAMD64" call "%MSSdk%\SetEnv" /XP64 /RETAIL\r
+\r
 @echo off\r
 if not defined HOST_PYTHON (\r
   if %1 EQU Debug (\r
index 2a31ca4679f2dcbd5a92612aff692969c3a867f5..96809b3daef085d2075b39e79324089bdf27a512 100644 (file)
@@ -170,7 +170,7 @@ def main():
     if debug:
         defs = defs + " " + "DEBUG=1"
     if arch in ('amd64', 'ia64'):
-        defs = defs + " EXTRA_CFLAGS=/GS-"
+        defs = defs + " EXTRA_CFLAGS=/GS- EXTRA_LIBS=bufferoverflowU.lib"
     makeCommand = 'nmake /nologo -f _ssl.mak ' + defs + " " + make_flags
     print "Executing:", makeCommand
     sys.stdout.flush()
index 20d3ecfd8c1d48540665daf8582cecfce9036aed..e44a39eefdf255f3a1bdeb0c8d0c6fb73159cc14 100644 (file)
@@ -259,12 +259,14 @@ Global
                {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release.ActiveCfg = Release|Win32
                {F22F40F4-D318-40DC-96B3-88DC81CE0894}.Release.Build.0 = Release|Win32
                {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32
+               {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32
                {F22F40F4-D318-40DC-96B3-88DC81CE0894}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug.ActiveCfg = Debug|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Debug.Build.0 = Debug|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release.ActiveCfg = Release|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.Release.Build.0 = Release|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64.ActiveCfg = ReleaseAMD64|Win32
+               {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseAMD64.Build.0 = ReleaseAMD64|Win32
                {8CF334D9-4F82-42EB-97AF-83592C5AFD2F}.ReleaseItanium.ActiveCfg = ReleaseItanium|Win32
                {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug.ActiveCfg = Debug|Win32
                {2FF0A312-22F9-4C34-B070-842916DE27A9}.Debug.Build.0 = Debug|Win32
index 27f665a4c84dc37f8b9b66c167fc477d583f2c75..9cbc8fe20f879a6752241b1c934cc2b20633cc33 100644 (file)
@@ -1220,7 +1220,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
        /* Number */
        if (isdigit(c)) {
                if (c == '0') {
-                       /* Hex or octal -- maybe. */
+                       /* Hex, octal or binary -- maybe. */
                        c = tok_nextc(tok);
                        if (c == '.')
                                goto fraction;
@@ -1234,18 +1234,27 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
                                        c = tok_nextc(tok);
                                } while (isxdigit(c));
                        }
+                        else if (c == 'o' || c == 'O') {
+                               /* Octal */
+                               do {
+                                       c = tok_nextc(tok);
+                               } while ('0' <= c && c < '8');
+                       }
+                       else if (c == 'b' || c == 'B') {
+                               /* Binary */
+                               do {
+                                       c = tok_nextc(tok);
+                               } while (c == '0' || c == '1');
+                       }
                        else {
-                               int found_decimal = 0;
-                               /* Octal; c is first char of it */
-                               /* There's no 'isoctdigit' macro, sigh */
-                               while ('0' <= c && c < '8') {
+                               int nonzero = 0;
+                               /* maybe old-style octal; c is first char of it */
+                               /* in any case, allow '0' as a literal */
+                               while (c == '0')
+                                       c = tok_nextc(tok);
+                               while (isdigit(c)) {
+                                       nonzero = 1;
                                        c = tok_nextc(tok);
-                               }
-                               if (isdigit(c)) {
-                                       found_decimal = 1;
-                                       do {
-                                               c = tok_nextc(tok);
-                                       } while (isdigit(c));
                                }
                                if (c == '.')
                                        goto fraction;
@@ -1255,7 +1264,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end)
                                else if (c == 'j' || c == 'J')
                                        goto imaginary;
 #endif
-                               else if (found_decimal) {
+                               else if (nonzero) {
                                        tok->done = E_TOKEN;
                                        tok_backup(tok, c);
                                        return ERRORTOKEN;
index b313ef2aa459f2c388c5fbc4b78ded4da0644294..c611436f6d51604cffa870c0205f8c4f9cf2adfb 100644 (file)
@@ -376,10 +376,6 @@ set_context(expr_ty e, expr_context_ty ctx, const node *n)
 
     switch (e->kind) {
         case Attribute_kind:
-            if (ctx == Store &&
-                !PyUnicode_CompareWithASCIIString(e->v.Attribute.attr, "None")) {
-                return ast_error(n, "assignment to None");
-            }
             e->v.Attribute.ctx = ctx;
             break;
         case Subscript_kind:
@@ -600,10 +596,6 @@ compiler_arg(struct compiling *c, const node *n)
 
     assert(TYPE(n) == tfpdef || TYPE(n) == vfpdef);
     ch = CHILD(n, 0);
-    if (!strcmp(STR(ch), "None")) {
-        ast_error(ch, "assignment to None");
-        return NULL;
-    }
     name = NEW_IDENTIFIER(ch);
     if (!name)
         return NULL;
@@ -641,10 +633,6 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
             case tfpdef:
                 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
                     expression = ast_for_expr(c, CHILD(n, i + 2));
-                    if (!expression) {
-                        ast_error(ch, "assignment to None");
-                        goto error;
-                    }
                     asdl_seq_SET(kwdefaults, j, expression);
                     i += 2; /* '=' and test */
                 }
@@ -663,10 +651,6 @@ handle_keywordonly_args(struct compiling *c, const node *n, int start,
                     annotation = NULL;
                 }
                 ch = CHILD(ch, 0);
-                if (!strcmp(STR(ch), "None")) {
-                    ast_error(ch, "assignment to None");
-                    goto error;
-                }
                 arg = arg(NEW_IDENTIFIER(ch), annotation, c->c_arena);
                 if (!arg) {
                     ast_error(ch, "expecting name");
@@ -817,10 +801,6 @@ ast_for_arguments(struct compiling *c, const node *n)
                     if (res == -1) goto error;
                     i = res; /* res has new position to process */
                 }
-                else if (!strcmp(STR(CHILD(ch, 0)), "None")) {
-                    ast_error(CHILD(ch, 0), "assignment to None");
-                    goto error;
-                }
                 else {
                     vararg = NEW_IDENTIFIER(CHILD(ch, 0));
                     if (NCH(ch) > 1) {
@@ -841,10 +821,6 @@ ast_for_arguments(struct compiling *c, const node *n)
             case DOUBLESTAR:
                 ch = CHILD(n, i+1);  /* tfpdef */
                 assert(TYPE(ch) == tfpdef || TYPE(ch) == vfpdef);
-                if (!strcmp(STR(CHILD(ch, 0)), "None")) {
-                        ast_error(CHILD(ch, 0), "assignment to None");
-                        goto error;
-                }
                 kwarg = NEW_IDENTIFIER(CHILD(ch, 0));
                 if (NCH(ch) > 1) {
                     /* there is an annotation on the kwarg */
@@ -971,10 +947,6 @@ ast_for_funcdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
     name = NEW_IDENTIFIER(CHILD(n, name_i));
     if (!name)
         return NULL;
-    else if (!strcmp(STR(CHILD(n, name_i)), "None")) {
-        ast_error(CHILD(n, name_i), "assignment to None");
-        return NULL;
-    }
     args = ast_for_arguments(c, CHILD(n, name_i + 1));
     if (!args)
         return NULL;
@@ -2913,11 +2885,6 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
 
     REQ(n, classdef);
 
-    if (!strcmp(STR(CHILD(n, 1)), "None")) {
-            ast_error(n, "assignment to None");
-            return NULL;
-    }
-
     if (NCH(n) == 4) { /* class NAME ':' suite */
         s = ast_for_suite(c, CHILD(n, 3));
         if (!s)
@@ -3039,8 +3006,6 @@ parsenumber(const char *s)
 #ifndef WITHOUT_COMPLEX
     imflag = *end == 'j' || *end == 'J';
 #endif
-    if (*end == 'l' || *end == 'L')
-        return PyLong_FromString((char *)s, (char **)0, 0);
     if (s[0] == '0') {
         x = (long) PyOS_strtoul((char *)s, (char **)&end, 0);
         if (x < 0 && errno == 0) {
index 3b43ff953a9ef775d3c66feaad9c9569e1329ef7..a2e48b1d9cc8c8b0503c4d5796f136be24bdd975 100644 (file)
@@ -31,7 +31,8 @@ static PyObject *filtertuple (PyObject *, PyObject *);
 static PyObject *
 builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
 {
-       PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *res;
+       PyObject *func, *name, *bases, *mkw, *meta, *prep, *ns, *cell;
+       PyObject *cls = NULL;
        Py_ssize_t nargs, nbases;
 
        assert(args != NULL);
@@ -112,22 +113,25 @@ builtin___build_class__(PyObject *self, PyObject *args, PyObject *kwds)
                        return NULL;
                }
        }
-       res = PyObject_CallFunctionObjArgs(func, ns, NULL);
-       if (res != NULL) {
+       cell = PyObject_CallFunctionObjArgs(func, ns, NULL);
+       if (cell != NULL) {
                PyObject *margs;
-               Py_DECREF(res);
-               res = NULL;
                margs = Py_BuildValue("OOO", name, bases, ns);
                if (margs != NULL) {
-                       res = PyEval_CallObjectWithKeywords(meta, margs, mkw);
+                       cls = PyEval_CallObjectWithKeywords(meta, margs, mkw);
                        Py_DECREF(margs);
                }
+               if (cls != NULL && PyCell_Check(cell)) {
+                       Py_INCREF(cls);
+                       PyCell_SET(cell, cls);
+               }
+               Py_DECREF(cell);
        }
        Py_DECREF(ns);
        Py_DECREF(meta);
        Py_XDECREF(mkw);
        Py_DECREF(bases);
-       return res;
+       return cls;
 }
 
 PyDoc_STRVAR(build_class_doc,
@@ -244,6 +248,18 @@ PyDoc_STRVAR(any_doc,
 Return True if bool(x) is True for any x in the iterable.");
 
 
+static PyObject *
+builtin_bin(PyObject *self, PyObject *v)
+{
+       return PyNumber_ToBase(v, 2);
+}
+
+PyDoc_STRVAR(bin_doc,
+"bin(number) -> string\n\
+\n\
+Return the binary representation of an integer or long integer.");
+
+
 static PyObject *
 builtin_filter(PyObject *self, PyObject *args)
 {
@@ -1192,24 +1208,7 @@ the same hash value.  The reverse is not necessarily true, but likely.");
 static PyObject *
 builtin_hex(PyObject *self, PyObject *v)
 {
-       PyNumberMethods *nb;
-       PyObject *res;
-
-       if ((nb = v->ob_type->tp_as_number) == NULL ||
-           nb->nb_hex == NULL) {
-               PyErr_SetString(PyExc_TypeError,
-                          "hex() argument can't be converted to hex");
-               return NULL;
-       }
-       res = (*nb->nb_hex)(v);
-       if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
-               PyErr_Format(PyExc_TypeError,
-                            "__hex__ returned non-string (type %.200s)",
-                            res->ob_type->tp_name);
-               Py_DECREF(res);
-               return NULL;
-       }
-       return res;
+       return PyNumber_ToBase(v, 16);
 }
 
 PyDoc_STRVAR(hex_doc,
@@ -1392,24 +1391,7 @@ With two or more arguments, return the largest argument.");
 static PyObject *
 builtin_oct(PyObject *self, PyObject *v)
 {
-       PyNumberMethods *nb;
-       PyObject *res;
-
-       if (v == NULL || (nb = v->ob_type->tp_as_number) == NULL ||
-           nb->nb_oct == NULL) {
-               PyErr_SetString(PyExc_TypeError,
-                          "oct() argument can't be converted to oct");
-               return NULL;
-       }
-       res = (*nb->nb_oct)(v);
-       if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
-               PyErr_Format(PyExc_TypeError,
-                            "__oct__ returned non-string (type %.200s)",
-                            res->ob_type->tp_name);
-               Py_DECREF(res);
-               return NULL;
-       }
-       return res;
+       return PyNumber_ToBase(v, 8);
 }
 
 PyDoc_STRVAR(oct_doc,
@@ -1949,6 +1931,7 @@ static PyMethodDef builtin_methods[] = {
        {"abs",         builtin_abs,        METH_O, abs_doc},
        {"all",         builtin_all,        METH_O, all_doc},
        {"any",         builtin_any,        METH_O, any_doc},
+       {"bin",         builtin_bin,        METH_O, bin_doc},
        {"chr",         builtin_chr,     METH_VARARGS, chr_doc},
        {"chr8",        builtin_chr8,        METH_VARARGS, chr8_doc},
        {"cmp",         builtin_cmp,        METH_VARARGS, cmp_doc},
index fde4591cf3be3e3940f27675982a2202de421599..0f5fd2dfde25280e0b5600305d67bef1072a9d2f 100644 (file)
@@ -373,10 +373,12 @@ dictbytype(PyObject *src, int scope_type, int flag, int offset)
 
        while (PyDict_Next(src, &pos, &k, &v)) {
                /* XXX this should probably be a macro in symtable.h */
+               long vi;
                assert(PyInt_Check(v));
-               scope = (PyInt_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
+               vi = PyInt_AS_LONG(v);
+               scope = (vi >> SCOPE_OFFSET) & SCOPE_MASK;
 
-               if (scope == scope_type || PyInt_AS_LONG(v) & flag) {
+               if (scope == scope_type || vi & flag) {
                        PyObject *tuple, *item = PyInt_FromLong(i);
                        if (item == NULL) {
                                Py_DECREF(dest);
@@ -1125,7 +1127,8 @@ compiler_body(struct compiler *c, asdl_seq *stmts)
        if (!asdl_seq_LEN(stmts))
                return 1;
        st = (stmt_ty)asdl_seq_GET(stmts, 0);
-       if (compiler_isdocstring(st)) {
+       if (compiler_isdocstring(st) && Py_OptimizeFlag < 2) {
+               /* don't generate docstrings if -OO */
                i = 1;
                VISIT(c, expr, st->v.Expr.value);
                if (!compiler_nameop(c, __doc__, Store))
@@ -1251,7 +1254,8 @@ compiler_make_closure(struct compiler *c, PyCodeObject *co, int args)
                else /* (reftype == FREE) */
                        arg = compiler_lookup_arg(c->u->u_freevars, name);
                if (arg == -1) {
-                       printf("lookup %s in %s %d %d\n"
+                       fprintf(stderr,
+                               "lookup %s in %s %d %d\n"
                                "freevars of %s: %s\n",
                                PyObject_REPR(name), 
                                PyString_AS_STRING(c->u->u_name), 
@@ -1474,7 +1478,6 @@ compiler_function(struct compiler *c, stmt_ty s)
 static int
 compiler_class(struct compiler *c, stmt_ty s)
 {
-       static PyObject *build_class = NULL;
        static PyObject *locals = NULL;
        PyCodeObject *co;
        PyObject *str;
@@ -1485,13 +1488,7 @@ compiler_class(struct compiler *c, stmt_ty s)
         if (!compiler_decorators(c, decos))
                 return 0;
 
-
        /* initialize statics */
-       if (build_class == NULL) {
-               build_class = PyUnicode_FromString("__build_class__");
-               if (build_class == NULL)
-                       return 0;
-       }
        if (locals == NULL) {
                locals = PyUnicode_FromString("__locals__");
                if (locals == NULL)
@@ -1501,14 +1498,16 @@ compiler_class(struct compiler *c, stmt_ty s)
        /* ultimately generate code for:
             <name> = __build_class__(<func>, <name>, *<bases>, **<keywords>)
           where:
-            <func> is a function/closure created from the class body
+            <func> is a function/closure created from the class body;
+                    it has a single argument (__locals__) where the dict
+                   (or MutableSequence) representing the locals is passed
             <name> is the class name
              <bases> is the positional arguments and *varargs argument
             <keywords> is the keyword arguments and **kwds argument
           This borrows from compiler_call.
        */
 
-       /* 0. Create a fake variable named __locals__ */
+       /* 0. Create a fake argument named __locals__ */
        ste = PySymtable_Lookup(c->c_st, s);
        if (ste == NULL)
                return 0;
@@ -1528,11 +1527,11 @@ compiler_class(struct compiler *c, stmt_ty s)
                c->u->u_private = s->v.ClassDef.name;
                /* force it to have one mandatory argument */
                c->u->u_argcount = 1;
-               /* load the first argument ... */
+               /* load the first argument (__locals__) ... */
                ADDOP_I(c, LOAD_FAST, 0);
                /* ... and store it into f_locals */
                ADDOP_IN_SCOPE(c, STORE_LOCALS);
-               /* load __name__ ... */
+               /* load (global) __name__ ... */
                str = PyUnicode_InternFromString("__name__");
                if (!str || !compiler_nameop(c, str, Load)) {
                        Py_XDECREF(str);
@@ -1553,8 +1552,24 @@ compiler_class(struct compiler *c, stmt_ty s)
                        compiler_exit_scope(c);
                        return 0;
                }
-               /* return None */
-               ADDOP_O(c, LOAD_CONST, Py_None, consts);
+               /* return the (empty) __class__ cell */
+               str = PyUnicode_InternFromString("__class__");
+               if (str == NULL) {
+                       compiler_exit_scope(c);
+                       return 0;
+               }
+               i = compiler_lookup_arg(c->u->u_cellvars, str);
+               Py_DECREF(str);
+               if (i == -1) {
+                       /* This happens when nobody references the cell */
+                       PyErr_Clear();
+                       /* Return None */
+                       ADDOP_O(c, LOAD_CONST, Py_None, consts);
+                }
+               else {
+                       /* Return the cell where to store __class__ */
+                       ADDOP_I(c, LOAD_CLOSURE, i);
+               }
                ADDOP_IN_SCOPE(c, RETURN_VALUE);
                /* create the code object */
                co = assemble(c, 1);
@@ -2421,7 +2436,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
                return compiler_error(c, "can not assign to __debug__");
        }
 
-mangled = _Py_Mangle(c->u->u_private, name);
+       mangled = _Py_Mangle(c->u->u_private, name);
        if (!mangled)
                return 0;
 
@@ -2947,6 +2962,7 @@ compiler_visit_keyword(struct compiler *c, keyword_ty k)
 static int
 expr_constant(expr_ty e)
 {
+       char *id;
        switch (e->kind) {
        case Ellipsis_kind:
                return 1;
@@ -2955,11 +2971,13 @@ expr_constant(expr_ty e)
        case Str_kind:
                return PyObject_IsTrue(e->v.Str.s);
        case Name_kind:
-               /* __debug__ is not assignable, so we can optimize
-                * it away in if and while statements */
-               if (PyUnicode_CompareWithASCIIString(e->v.Name.id,
-                                                    "__debug__") == 0)
-                          return ! Py_OptimizeFlag;
+               /* optimize away names that can't be reassigned */
+               id = _PyUnicode_AsDefaultEncodedString(e->v.Name.id, NULL);
+               if (strcmp(id, "True") == 0) return 1;
+               if (strcmp(id, "False") == 0) return 0;
+               if (strcmp(id, "None") == 0) return 0;
+               if (strcmp(id, "__debug__") == 0)
+                       return ! Py_OptimizeFlag;
                /* fall through */
        default:
                return -1;
index f0070575dbf68bdba5fb56cf945cd3ee7ffb3710..cf23051a43155a4aefc8298a6b59bed33efc1c5c 100644 (file)
@@ -91,7 +91,7 @@ static int digitlimit[] = {
 **             This is a general purpose routine for converting
 **             an ascii string to an integer in an arbitrary base.
 **             Leading white space is ignored.  If 'base' is zero
-**             it looks for a leading 0, 0x or 0X to tell which
+**             it looks for a leading 0b, 0o or 0x to tell which
 **             base.  If these are absent it defaults to 10.
 **             Base must be 0 or between 2 and 36 (inclusive).
 **             If 'ptr' is non-NULL it will contain a pointer to
@@ -110,29 +110,57 @@ PyOS_strtoul(register char *str, char **ptr, int base)
        while (*str && isspace(Py_CHARMASK(*str)))
                ++str;
 
-       /* check for leading 0 or 0x for auto-base or base 16 */
+       /* check for leading 0b, 0o or 0x for auto-base or base 16 */
        switch (base) {
-               case 0:         /* look for leading 0, 0x or 0X */
-                       if (*str == '0') {
+       case 0:         /* look for leading 0b, 0o or 0x */
+               if (*str == '0') {
+                       ++str;
+                       if (*str == 'x' || *str == 'X') {
+                               ++str;
+                               base = 16;
+                       } else if (*str == 'o' || *str == 'O') {
                                ++str;
-                               if (*str == 'x' || *str == 'X') {
+                               base = 8;
+                       } else if (*str == 'b' || *str == 'B') {
+                               ++str;
+                               base = 2;
+                       } else {
+                               /* skip all zeroes... */
+                               while (*str == '0')
+                                       ++str;
+                               while (isspace(Py_CHARMASK(*str)))
                                        ++str;
-                                       base = 16;
-                               }
-                               else
-                                       base = 8;
+                               if (ptr)
+                                       *ptr = str;
+                               return 0;
                        }
-                       else
-                               base = 10;
-                       break;
+               }
+               else
+                       base = 10;
+               break;
 
-               case 16:        /* skip leading 0x or 0X */
-                       if (*str == '0') {
+       /* even with explicit base, skip leading 0? prefix */
+       case 16:
+               if (*str == '0') {
+                       ++str;
+                       if (*str == 'x' || *str == 'X')
                                ++str;
-                               if (*str == 'x' || *str == 'X')
-                                       ++str;
-                       }
-                       break;
+               }
+               break;
+       case 8:
+               if (*str == '0') {
+                       ++str;
+                       if (*str == 'o' || *str == 'O')
+                               ++str;
+               }
+               break;
+       case 2:
+               if(*str == '0') {
+                       ++str;
+                       if (*str == 'b' || *str == 'B')
+                               ++str;
+               }
+               break;
        }
 
        /* catch silly bases */
index 7c4640cac7598fbc4d69719933dd64b2c6638aad..d012d391e71a6fb60be71118e442e3b0a3197bb5 100644 (file)
@@ -257,6 +257,37 @@ markblocks(unsigned char *code, int len)
        return blocks;
 }
 
+/* Helper to replace LOAD_NAME None/True/False with LOAD_CONST
+   Returns: 0 if no change, 1 if change, -1 if error */
+static int
+load_global(unsigned char *codestr, Py_ssize_t i, char *name, PyObject *consts)
+{
+       Py_ssize_t j;
+       PyObject *obj;
+       if (name == NULL)
+               return 0;
+       if (strcmp(name, "None") == 0)
+               obj = Py_None;
+       else if (strcmp(name, "True") == 0)
+               obj = Py_True;
+       else if (strcmp(name, "False") == 0)
+               obj = Py_False;
+       else
+               return 0;
+       for (j = 0; j < PyList_GET_SIZE(consts); j++) {
+               if (PyList_GET_ITEM(consts, j) == obj)
+                       break;
+       }
+       if (j == PyList_GET_SIZE(consts)) {
+               if (PyList_Append(consts, obj) < 0)
+                       return -1;
+       }
+       assert(PyList_GET_ITEM(consts, j) == obj);
+       codestr[i] = LOAD_CONST;
+       SETARG(codestr, i, j);
+       return 1;
+}
+
 /* Perform basic peephole optimizations to components of a code object.
    The consts object should still be in list form to allow new constants 
    to be appended.
@@ -302,7 +333,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
 
        /* Avoid situations where jump retargeting could overflow */
        assert(PyString_Check(code));
-       codelen = PyString_Size(code);
+       codelen = PyString_GET_SIZE(code);
        if (codelen > 32700)
                goto exitUnchanged;
 
@@ -371,25 +402,17 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
                                codestr[i+3] = NOP;
                                break;
 
-                               /* Replace LOAD_GLOBAL/LOAD_NAME None
-                                   with LOAD_CONST None */
+                               /* Replace LOAD_GLOBAL/LOAD_NAME None/True/False
+                                   with LOAD_CONST None/True/False */
                        case LOAD_NAME:
                        case LOAD_GLOBAL:
                                j = GETARG(codestr, i);
                                name = PyString_AsString(PyTuple_GET_ITEM(names, j));
-                               if (name == NULL  ||  strcmp(name, "None") != 0)
+                               h = load_global(codestr, i, name, consts);
+                               if (h < 0)
+                                       goto exitUnchanged;
+                               else if (h == 0)
                                        continue;
-                               for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {
-                                       if (PyList_GET_ITEM(consts, j) == Py_None)
-                                               break;
-                               }
-                               if (j == PyList_GET_SIZE(consts)) {
-                                       if (PyList_Append(consts, Py_None) == -1)
-                                               goto exitUnchanged;                                        
-                               }
-                               assert(PyList_GET_ITEM(consts, j) == Py_None);
-                               codestr[i] = LOAD_CONST;
-                               SETARG(codestr, i, j);
                                cumlc = lastlc + 1;
                                break;
 
index b6cf2ac17b3c2cefdbc68a791311f597ffa5212b..1de223850c81f4f75ac3f7a20b8cdc8ca9feecc8 100644 (file)
@@ -289,31 +289,25 @@ PyMember_SetOne(char *addr, PyMemberDef *l, PyObject *v)
                }
                break;
 #ifdef HAVE_LONG_LONG
-       case T_LONGLONG:
-               if (!PyLong_Check(v)) {
-                       PyErr_BadArgument();
+       case T_LONGLONG:{
+               PY_LONG_LONG value;
+               *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
+               if ((value == -1) && PyErr_Occurred())
                        return -1;
-               } else {
-                        PY_LONG_LONG value;
-                        *(PY_LONG_LONG*)addr = value = PyLong_AsLongLong(v);
-                        if ((value == -1) && PyErr_Occurred()) {
-                                return -1;
-                        }
-                }
-                break;
-       case T_ULONGLONG:
-                if (!PyLong_Check(v)) {
-                        PyErr_BadArgument();
-                        return -1;
-                } else {
-                        unsigned PY_LONG_LONG value;
-                        *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
-                        if ((value == (unsigned PY_LONG_LONG)-1) &&
-                           PyErr_Occurred()) {
-                                return -1;
-                        }
-                }
-                break;
+               break;
+               }
+       case T_ULONGLONG:{
+               unsigned PY_LONG_LONG value;
+               /* ??? PyLong_AsLongLong accepts an int, but PyLong_AsUnsignedLongLong
+                       doesn't ??? */
+               if (PyLong_Check(v))
+                       *(unsigned PY_LONG_LONG*)addr = value = PyLong_AsUnsignedLongLong(v);
+               else
+                       *(unsigned PY_LONG_LONG*)addr = value = PyInt_AsLong(v);
+               if ((value == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())
+                       return -1;
+               break;
+               }
 #endif /* HAVE_LONG_LONG */
        default:
                PyErr_Format(PyExc_SystemError,
index 68c182133a941467d33fd18ec8edfd994d16b300..30e97d6f5a0ff4052a6734420d7dcd8275b6c442 100644 (file)
@@ -183,7 +183,7 @@ static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
 
 
 static identifier top = NULL, lambda = NULL, genexpr = NULL,
-    listcomp = NULL, setcomp = NULL;
+    listcomp = NULL, setcomp = NULL, __class__ = NULL;
 
 #define GET_IDENTIFIER(VAR) \
        ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
@@ -317,7 +317,7 @@ PyST_GetScope(PySTEntryObject *ste, PyObject *name)
 
 /* Analyze raw symbol information to determine scope of each name.
 
-   The next several functions are helpers for PySymtable_Analyze(),
+   The next several functions are helpers for symtable_analyze(),
    which determines whether a name is local, global, or free.  In addition, 
    it determines which local variables are cell variables; they provide
    bindings that are used for free variables in enclosed blocks.  
@@ -464,10 +464,13 @@ analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
 
    Note that the current block's free variables are included in free.
    That's safe because no name can be free and local in the same scope.
+
+   The 'restrict' argument may be set to a string to restrict the analysis
+   to the one variable whose name equals that string (e.g. "__class__").
 */
 
 static int
-analyze_cells(PyObject *scopes, PyObject *free)
+analyze_cells(PyObject *scopes, PyObject *free, const char *restrict)
 {
         PyObject *name, *v, *v_cell;
        int success = 0;
@@ -484,6 +487,9 @@ analyze_cells(PyObject *scopes, PyObject *free)
                        continue;
                if (!PySet_Contains(free, name))
                        continue;
+               if (restrict != NULL &&
+                    PyUnicode_CompareWithASCIIString(name, restrict))
+                       continue;
                /* Replace LOCAL with CELL for this name, and remove
                   from free. It is safe to replace the value of name 
                   in the dict, because it will not cause a resize.
@@ -589,7 +595,7 @@ update_symbols(PyObject *symbols, PyObject *scopes,
                                }
                                Py_DECREF(v_new);
                        }
-                       /* It's a cell, or already a free variable in this scope */
+                       /* It's a cell, or already free in this scope */
                        Py_DECREF(name);
                        continue;
                }
@@ -675,8 +681,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
                        goto error;
        }
 
-       /* Populate global and bound sets to be passed to children.
-        */
+       /* Populate global and bound sets to be passed to children. */
        if (ste->ste_type != ClassBlock) {
                /* Add function locals to bound set */
                if (ste->ste_type == FunctionBlock) {
@@ -695,6 +700,14 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
                        goto error;
                Py_DECREF(newglobal);
        }
+       else {
+               /* Special-case __class__ */
+               if (!GET_IDENTIFIER(__class__))
+                       goto error;
+               assert(PySet_Contains(local, __class__) == 1);
+               if (PySet_Add(newbound, __class__) < 0)
+                       goto error;
+       }
 
        /* Recursively call analyze_block() on each child block */
        for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) {
@@ -709,8 +722,12 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free,
                        ste->ste_child_free = 1;
        }
 
-       /* Check if any local variables need to be converted to cell variables */
-       if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree))
+       /* Check if any local variables must be converted to cell variables */
+       if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree,
+                                                            NULL))
+               goto error;
+        else if (ste->ste_type == ClassBlock && !analyze_cells(scopes, newfree,
+                                                              "__class__"))
                goto error;
        /* Records the results of the analysis in the symbol table entry */
        if (!update_symbols(ste->ste_symbols, scopes, bound, newfree,
@@ -1027,6 +1044,11 @@ symtable_visit_stmt(struct symtable *st, stmt_ty s)
                if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock, 
                                          (void *)s, s->lineno))
                        return 0;
+               if (!GET_IDENTIFIER(__class__) ||
+                   !symtable_add_def(st, __class__, DEF_LOCAL)) {
+                       symtable_exit_block(st, s);
+                       return 0;
+               }
                tmp = st->st_private;
                st->st_private = s->v.ClassDef.name;
                VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s);
@@ -1294,6 +1316,14 @@ symtable_visit_expr(struct symtable *st, expr_ty e)
                if (!symtable_add_def(st, e->v.Name.id, 
                                      e->v.Name.ctx == Load ? USE : DEF_LOCAL))
                        return 0;
+               /* Special-case super: it counts as a use of __class__ */
+                if (e->v.Name.ctx == Load &&
+                   st->st_cur->ste_type == FunctionBlock &&
+                    !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
+                       if (!GET_IDENTIFIER(__class__) ||
+                           !symtable_add_def(st, __class__, USE))
+                               return 0;
+                }
                break;
        /* child nodes of List and Tuple will have expr_context set */
         case List_kind:
diff --git a/README b/README
index 790ff9880c4d9f6a90d70b85c385ecfafaab3e1f..4fecd7a68f01a029d16c898fbf20bdc68fcb9b31 100644 (file)
--- a/README
+++ b/README
@@ -666,7 +666,11 @@ Cygwin: With recent (relative to the time of writing, 2001-12-19)
         News regarding these platforms with more recent Cygwin
         versions would be appreciated!
 
-AtheOS: From Octavian Cerna <tavy at ylabs.com>:
+AtheOS: Official support has been stopped as of Python 2.6.  All code will be
+        removed in Python 2.7 unless a maintainer steps forward for this
+        platform.
+
+        From Octavian Cerna <tavy at ylabs.com>:
 
         Before building:
 
diff --git a/Tools/buildbot/build-amd64.bat b/Tools/buildbot/build-amd64.bat
new file mode 100644 (file)
index 0000000..88edd8d
--- /dev/null
@@ -0,0 +1,6 @@
+@rem Used by the buildbot "compile" step.
+setlocal
+cmd /c Tools\buildbot\external-amd64.bat
+call "%VS71COMNTOOLS%vsvars32.bat"
+REM cmd /q/c Tools\buildbot\kill_python.bat
+devenv.com /build ReleaseAMD64 PCbuild\pcbuild.sln
diff --git a/Tools/buildbot/clean-amd64.bat b/Tools/buildbot/clean-amd64.bat
new file mode 100644 (file)
index 0000000..7ef5e02
--- /dev/null
@@ -0,0 +1,6 @@
+@rem Used by the buildbot "clean" step.
+call "%VS71COMNTOOLS%vsvars32.bat"
+cd PCbuild
+@echo Deleting .pyc/.pyo files ...
+python.exe rmpyc.py
+devenv.com /clean ReleaseAMD64 pcbuild.sln
diff --git a/Tools/buildbot/external-amd64.bat b/Tools/buildbot/external-amd64.bat
new file mode 100644 (file)
index 0000000..dac8cb3
--- /dev/null
@@ -0,0 +1,44 @@
+@rem Fetches (and builds if necessary) external dependencies
+setlocal
+
+@rem need this so that 'devenv' is found
+call "%VS71COMNTOOLS%vsvars32.bat"
+@rem set the build environment
+call "%MSSdk%\SetEnv" /XP64 /RETAIL
+
+@rem Assume we start inside the Python source directory
+cd ..
+
+@rem sqlite
+if not exist sqlite-source-3.3.4 (
+   svn export http://svn.python.org/projects/external/sqlite-source-3.3.4
+   if exist build\PCbuild\sqlite3.dll del build\PCbuild\sqlite3.dll
+)
+if not exist build\PCbuild\sqlite3.dll (
+   cd sqlite-source-3.3.4\amd64
+   cl ..\*.c
+   link /def:..\sqlite3.def  /dll *.obj /out:sqlite3.dll bufferoverflowU.lib
+   cd ..\..
+   copy sqlite-source-3.3.4\amd64\sqlite3.dll build\PCbuild
+)
+
+@rem bzip
+if not exist bzip2-1.0.3 svn export http://svn.python.org/projects/external/bzip2-1.0.3
+
+@rem Sleepycat db
+if not exist db-4.4.20 svn export http://svn.python.org/projects/external/db-4.4.20
+if not exist "db-4.4.20\build_win32\Release_AMD64\libdb44s.lib" (
+   cd db-4.4.20\build_win32
+   devenv Berkeley_DB.sln /build "Release AMD64" /project db_static /useenv
+   cd ..\..
+)
+
+@rem OpenSSL
+if not exist openssl-0.9.8a svn export http://svn.python.org/projects/external/openssl-0.9.8a
+
+@rem tcltk
+if not exist tcl8.4.12 (
+   if exist tcltk rd /s/q tcltk
+   svn export http://svn.python.org/projects/external/tcl8.4.12
+   svn export http://svn.python.org/projects/external/tk8.4.12
+)
diff --git a/Tools/buildbot/test-amd64.bat b/Tools/buildbot/test-amd64.bat
new file mode 100644 (file)
index 0000000..6995ece
--- /dev/null
@@ -0,0 +1,3 @@
+@rem Used by the buildbot "test" step.
+cd PCbuild
+call rt.bat -q -uall -rw
index 353be8b9c6936cd22b5329954b27fb2cdb699f8b..c2f39a1afe35c4f5088be1ce260fab62b7b8d153 100755 (executable)
@@ -83,7 +83,7 @@ def generate():
         voffsets += [l2, o2+valuestart]
     offsets = koffsets + voffsets
     output = struct.pack("Iiiiiii",
-                         0x950412deL,       # Magic
+                         0x950412de,       # Magic
                          0,                 # Version
                          len(keys),         # # of entries
                          7*4,               # start of key index
index 6ef2f205f228ecd45f5be6b6858b504b3a64629c..d4766a701614130f39a0e23604db4ac096f46c7d 100644 (file)
@@ -476,9 +476,9 @@ class SimpleLongArithmetic(Test):
 
         for i in range(self.rounds):
 
-            a = 2220001L
-            b = 100001L
-            c = 30005L
+            a = 2220001
+            b = 100001
+            c = 30005
 
             c = a + b
             c = b + c
@@ -504,9 +504,9 @@ class SimpleLongArithmetic(Test):
             c = b / a
             c = c / b
 
-            a = 2220001L
-            b = 100001L
-            c = 30005L
+            a = 2220001
+            b = 100001
+            c = 30005
 
             c = a + b
             c = b + c
@@ -532,9 +532,9 @@ class SimpleLongArithmetic(Test):
             c = b / a
             c = c / b
 
-            a = 2220001L
-            b = 100001L
-            c = 30005L
+            a = 2220001
+            b = 100001
+            c = 30005
 
             c = a + b
             c = b + c
@@ -560,9 +560,9 @@ class SimpleLongArithmetic(Test):
             c = b / a
             c = c / b
 
-            a = 2220001L
-            b = 100001L
-            c = 30005L
+            a = 2220001
+            b = 100001
+            c = 30005
 
             c = a + b
             c = b + c
@@ -588,9 +588,9 @@ class SimpleLongArithmetic(Test):
             c = b / a
             c = c / b
 
-            a = 2220001L
-            b = 100001L
-            c = 30005L
+            a = 2220001
+            b = 100001
+            c = 30005
 
             c = a + b
             c = b + c
index 909ef02db98e8d6a0f10ee6fb01e3b8938a96e3e..1cdcfc18a19998de9bf13056d04d973eafa7535a 100644 (file)
@@ -82,7 +82,7 @@ def fileopen(name, mode='wb', encoding=None):
         else:
             f = open(name, mode)
         if 'w' in mode:
-            os.chmod(name, 0600)
+            os.chmod(name, 0o600)
         return f
 
 def option_dict(options):
index b0a11f4ce5f58256fdca360d13f280351d89f433..1b216734a8e995c7aa8057fe6935ab20233d5939 100644 (file)
@@ -598,185 +598,185 @@ class CompareLongs(Test):
 
         for i in range(self.rounds):
 
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
-
-            1234567890L < 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L == 3456789012345L
-            1234567890L > 3456789012345L
-            1234567890L < 3456789012345L
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
+
+            1234567890 < 3456789012345
+            1234567890 > 3456789012345
+            1234567890 == 3456789012345
+            1234567890 > 3456789012345
+            1234567890 < 3456789012345
 
     def calibrate(self):
 
index 5478c288a21260d34b4fe360f2e98783c892d731..13bed2f18eaf2617edcbaad35e340c07565bc80e 100644 (file)
@@ -180,9 +180,9 @@ def processtime():
 ### Testing
 
 def some_workload():
-    x = 0L
-    for i in range(10000000L):
-        x = x + 1L
+    x = 0
+    for i in range(10000000):
+        x = x + 1
 
 def test_workload():
     print 'Testing systimes() under load conditions'
index f65e63035eae9be78eb9daf547b166c3b3b1705f..0cd1e4955ffbbeecc561345374bd92aea4df0676 100755 (executable)
@@ -129,7 +129,7 @@ def fix(filename):
     # First copy the file's mode to the temp file
     try:
         statbuf = os.stat(filename)
-        os.chmod(tempname, statbuf[ST_MODE] & 07777)
+        os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
     except os.error as msg:
         err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
     # Then make a backup of the original file as filename~
index 29e0e1030cf74f6f47454b137d44b0429dfc1b47..d4343455a7ef2ffe90db128a7c1ea1c527b9bd79 100755 (executable)
@@ -174,7 +174,7 @@ def fix(filename):
     # First copy the file's mode to the temp file
     try:
         statbuf = os.stat(filename)
-        os.chmod(tempname, statbuf[ST_MODE] & 07777)
+        os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
     except os.error as msg:
         err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
     # Then make a backup of the original file as filename~
index 39ef18e661ba53fa0cc9568e5168822f421cfc71..7318b37907ec6b7c964c585fe6035c2c9bc2465a 100755 (executable)
@@ -375,7 +375,7 @@ def makedir(pathname):
         return
     dirname = os.path.dirname(pathname)
     if dirname: makedir(dirname)
-    os.mkdir(pathname, 0777)
+    os.mkdir(pathname, 0o777)
 
 # Write a dictionary to a file in a way that can be read back using
 # rval() but is still somewhat readable (i.e. not a single long line).
index 7f1704645391ac3ddc78cebc9cb1870c672deb77..2b41e7d2a51495e8f4d7ae3ba133cb4168dd0185 100755 (executable)
@@ -31,7 +31,7 @@ def main():
         print oldtree + ': not a directory'
         return 1
     try:
-        os.mkdir(newtree, 0777)
+        os.mkdir(newtree, 0o777)
     except os.error as msg:
         print newtree + ': cannot mkdir:', msg
         return 1
@@ -63,7 +63,7 @@ def linknames(old, new, link):
             if os.path.isdir(oldname) and \
                not os.path.islink(oldname):
                 try:
-                    os.mkdir(newname, 0777)
+                    os.mkdir(newname, 0o777)
                     ok = 1
                 except:
                     print newname + \
index 11875a18359751a3f8e3473ed357e977b4c49513..f5fe7cd6ec705617e77a178fda468b963db5faf3 100755 (executable)
@@ -140,7 +140,7 @@ def fix(filename):
     # First copy the file's mode to the temp file
     try:
         statbuf = os.stat(filename)
-        os.chmod(tempname, statbuf[ST_MODE] & 07777)
+        os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
     except os.error as msg:
         err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
     # Then make a backup of the original file as filename~
index c59c0f21e35c5df33c7d57fa5d054dba3c46f123..601a172fdc483596c54d8bfa9ea57531089573d9 100755 (executable)
@@ -121,7 +121,7 @@ def fix(filename):
     # First copy the file's mode to the temp file
     try:
         statbuf = os.stat(filename)
-        os.chmod(tempname, statbuf[ST_MODE] & 07777)
+        os.chmod(tempname, statbuf[ST_MODE] & 0o7777)
     except os.error as msg:
         err('%s: warning: chmod failed (%r)\n' % (tempname, msg))
     # Then make a backup of the original file as filename~
old mode 100644 (file)
new mode 100755 (executable)
index 49b69acf83b220b54bc95baa5ea3983e7b6af1d3..368eea2503791d405429b17ce4e1b0e3722454ba 100755 (executable)
@@ -35,7 +35,7 @@ def main():
                 msg(filename + ': not a disk file')
             else:
                 mode = S_IMODE(st[ST_MODE])
-                if mode & 0111:
+                if mode & 0o111:
                     if not ident:
                         print filename
                         ident = st[:3]
index 2a85e8405c5bd046ae0a7b1f0af827908bec0e22..673f7136a364bd56d28008c5e20d999f1e228ce7 100644 (file)
@@ -757,7 +757,7 @@ def myhash(s, magic):
     h = 0
     for c in map(ord, s.upper()):
         h = (h * magic) + c
-        ix = h & 0xff000000L
+        ix = h & 0xff000000
         if ix:
             h = (h ^ ((ix>>24) & 0xff)) & 0x00ffffff
     return h
index 239cb529afffbfec264017ab836411320bd15594..12be86eb5590652664eb168acfbb68d5d0caa348 100755 (executable)
@@ -119,7 +119,7 @@ def makedirs(dir):
         print "Huh?  Don't know how to make dir", dir
         return
     makedirs(head)
-    os.mkdir(dir, 0777)
+    os.mkdir(dir, 0o777)
 
 if __name__ == '__main__':
     sys.exit(main() or 0)
index aca101dcd4d5895d69dabc5ad40e2a8c0660efbc..61d9d39bfa4b2e207e637ca2c3ffac9889b9c7ff 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 53610 .
+# From configure.in Revision: 54283 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 3.0.
 #
@@ -3753,7 +3753,7 @@ rm -f conftest*
 
 # Check for unsupported systems
 case $ac_sys_system/$ac_sys_release in
-Linux*/1*)
+atheos*|Linux*/1*)
    echo This system \($ac_sys_system/$ac_sys_release\) is no longer supported.
    echo See README for details.
    exit 1;;
index 7004a0657871a4431a64c618c78d49b9f367f972..9a07fb9c68cd31712f0b4f0dadc4b0408b047eff 100644 (file)
@@ -450,7 +450,7 @@ AC_AIX
 
 # Check for unsupported systems
 case $ac_sys_system/$ac_sys_release in
-Linux*/1*)
+atheos*|Linux*/1*)
    echo This system \($ac_sys_system/$ac_sys_release\) is no longer supported.
    echo See README for details.
    exit 1;;
index e8d4b894645fe1b37fe865c9066e003e063c2551..b1e1c1e938632d4a4bb5f9f5cc4a55e5d6990754 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1486,8 +1486,8 @@ class PyBuildInstallLib(install_lib):
 
     def install(self):
         outfiles = install_lib.install(self)
-        self.set_file_modes(outfiles, 0644, 0755)
-        self.set_dir_modes(self.install_dir, 0755)
+        self.set_file_modes(outfiles, 0o644, 0o755)
+        self.set_dir_modes(self.install_dir, 0o755)
         return outfiles
 
     def set_file_modes(self, files, defaultMode, sharedLibMode):