summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/configparser.rst14
-rw-r--r--Doc/whatsnew/2.6.rst95
-rwxr-xr-xLib/pdb.py2
-rw-r--r--Lib/test/test_format.py411
-rw-r--r--Lib/test/test_imaplib.py27
-rw-r--r--Lib/test/test_mailbox.py8
-rw-r--r--Lib/test/test_ntpath.py345
-rw-r--r--Lib/test/test_timeout.py15
-rw-r--r--Misc/ACKS11
-rw-r--r--Misc/developers.txt3
-rw-r--r--Modules/_ctypes/_ctypes.c6
-rw-r--r--Modules/selectmodule.c21
12 files changed, 532 insertions, 426 deletions
diff --git a/Doc/library/configparser.rst b/Doc/library/configparser.rst
index aa4dc7c..a7ad2e7 100644
--- a/Doc/library/configparser.rst
+++ b/Doc/library/configparser.rst
@@ -29,18 +29,20 @@ easily.
The configuration file consists of sections, led by a ``[section]`` header and
followed by ``name: value`` entries, with continuations in the style of
-:rfc:`822`; ``name=value`` is also accepted. Note that leading whitespace is
-removed from values. The optional values can contain format strings which refer
-to other values in the same section, or values in a special ``DEFAULT`` section.
-Additional defaults can be provided on initialization and retrieval. Lines
-beginning with ``'#'`` or ``';'`` are ignored and may be used to provide
-comments.
+:rfc:`822` (see section 3.1.1, "LONG HEADER FIELDS"); ``name=value`` is also
+accepted. Note that leading whitespace is removed from values. The optional
+values can contain format strings which refer to other values in the same
+section, or values in a special ``DEFAULT`` section. Additional defaults can be
+provided on initialization and retrieval. Lines beginning with ``'#'`` or
+``';'`` are ignored and may be used to provide comments.
For example::
[My Section]
foodir: %(dir)s/whatever
dir=frob
+ long: this value continues
+ in the next line
would resolve the ``%(dir)s`` to the value of ``dir`` (``frob`` in this case).
All reference expansions are done on demand.
diff --git a/Doc/whatsnew/2.6.rst b/Doc/whatsnew/2.6.rst
index 0e8901b..9299c01 100644
--- a/Doc/whatsnew/2.6.rst
+++ b/Doc/whatsnew/2.6.rst
@@ -555,10 +555,11 @@ adding a colon followed by a format specifier. For example::
Format specifiers can reference other fields through nesting::
fmt = '{0:{1}}'
- fmt.format('Invoice #1234', width) ->
- 'Invoice #1234 '
fmt.format('Invoice #1234', 15) ->
'Invoice #1234 '
+ width = 35
+ fmt.format('Invoice #1234', width) ->
+ 'Invoice #1234 '
The alignment of a field within the desired width can be specified:
@@ -571,11 +572,38 @@ Character Effect
= (For numeric types only) Pad after the sign.
================ ============================================
-Format data types::
-
- ... XXX take table from PEP 3101
-
-Classes and types can define a __format__ method to control how it's
+Format specifiers can also include a presentation type, which
+controls how the value is formatted. For example, floating-point numbers
+can be formatted as a general number or in exponential notation:
+
+ >>> '{0:g}'.format(3.75)
+ '3.75'
+ >>> '{0:e}'.format(3.75)
+ '3.750000e+00'
+
+A variety of presentation types are available. Consult the 2.6
+documentation for a complete list (XXX add link, once it's in the 2.6
+docs), but here's a sample::
+
+ 'b' - Binary. Outputs the number in base 2.
+ 'c' - Character. Converts the integer to the corresponding
+ Unicode character before printing.
+ 'd' - Decimal Integer. Outputs the number in base 10.
+ 'o' - Octal format. Outputs the number in base 8.
+ 'x' - Hex format. Outputs the number in base 16, using lower-
+ case letters for the digits above 9.
+ 'e' - Exponent notation. Prints the number in scientific
+ notation using the letter 'e' to indicate the exponent.
+ 'g' - General format. This prints the number as a fixed-point
+ number, unless the number is too large, in which case
+ it switches to 'e' exponent notation.
+ 'n' - Number. This is the same as 'g', except that it uses the
+ current locale setting to insert the appropriate
+ number separator characters.
+ '%' - Percentage. Multiplies the number by 100 and displays
+ in fixed ('f') format, followed by a percent sign.
+
+Classes and types can define a __format__ method to control how they're
formatted. It receives a single argument, the format specifier::
def __format__(self, format_spec):
@@ -610,7 +638,6 @@ function from somewhere else.
Python 2.6 has a ``__future__`` import that removes ``print`` as language
syntax, letting you use the functional form instead. For example::
- XXX need to check
from __future__ import print_function
print('# of entries', len(dictionary), file=sys.stderr)
@@ -701,6 +728,21 @@ and it also supports the ``b''`` notation.
.. ======================================================================
+.. _pep-3118:
+
+PEP 3118: Revised Buffer Protocol
+=====================================================
+
+The buffer protocol is a C-level API that lets Python extensions
+XXX
+
+.. seealso::
+
+ :pep:`3118` - Revising the buffer protocol
+ PEP written by Travis Oliphant and Carl Banks.
+
+.. ======================================================================
+
.. _pep-3119:
PEP 3119: Abstract Base Classes
@@ -1082,7 +1124,7 @@ Optimizations
by using pymalloc for the Unicode string's data.
* The ``with`` statement now stores the :meth:`__exit__` method on the stack,
- producing a small speedup. (Implemented by Nick Coghlan.)
+ producing a small speedup. (Implemented by Jeffrey Yasskin.)
* To reduce memory usage, the garbage collector will now clear internal
free lists when garbage-collecting the highest generation of objects.
@@ -1361,10 +1403,8 @@ complete list of changes, or look through the CVS logs for all the details.
the forward search.
(Contributed by John Lenton.)
-* The :mod:`new` module has been removed from Python 3.0.
- Importing it therefore
- triggers a warning message when Python is running in 3.0-warning
- mode.
+* (3.0-warning mode) The :mod:`new` module has been removed from
+ Python 3.0. Importing it therefore triggers a warning message.
* The :mod:`operator` module gained a
:func:`methodcaller` function that takes a name and an optional
@@ -1483,6 +1523,14 @@ complete list of changes, or look through the CVS logs for all the details.
.. Issue 1727780
+ The new ``triangular(low, high, mode)`` function returns random
+ numbers following a triangular distribution. The returned values
+ are between *low* and *high*, not including *high* itself, and
+ with *mode* as the mode, the most frequently occurring value
+ in the distribution. (Contributed by Raymond Hettinger. XXX check)
+
+ .. Patch 1681432
+
* Long regular expression searches carried out by the :mod:`re`
module will now check for signals being delivered, so especially
long searches can now be interrupted.
@@ -1500,6 +1548,16 @@ complete list of changes, or look through the CVS logs for all the details.
.. Patch 1861
+* The :mod:`select` module now has wrapper functions
+ for the Linux :cfunc:`epoll` and BSD :cfunc:`kqueue` system calls.
+ Also, a :meth:`modify` method was added to the existing :class:`poll`
+ objects; ``pollobj.modify(fd, eventmask)`` takes a file descriptor
+ or file object and an event mask,
+
+ (Contributed by XXX.)
+
+ .. Patch 1657
+
* The :mod:`sets` module has been deprecated; it's better to
use the built-in :class:`set` and :class:`frozenset` types.
@@ -1948,9 +2006,8 @@ Some of the more notable changes are:
Porting to Python 2.6
=====================
-This section lists previously described changes, and a few
-esoteric bugfixes, that may require changes to your
-code:
+This section lists previously described changes and other bugfixes
+that may require changes to your code:
* The :meth:`__init__` method of :class:`collections.deque`
now clears any existing contents of the deque
@@ -1986,7 +2043,11 @@ code:
.. Issue 1330538
-* In 3.0-warning mode, inequality comparisons between two dictionaries
+* (3.0-warning mode) The :class:`Exception` class now warns
+ when accessed using slicing or index access; having
+ :class:`Exception` behave like a tuple is being phased out.
+
+* (3.0-warning mode) inequality comparisons between two dictionaries
or two objects that don't implement comparison methods are reported
as warnings. ``dict1 == dict2`` still works, but ``dict1 < dict2``
is being phased out.
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 29746d7..a6355ec 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1233,7 +1233,7 @@ def help():
print('along the Python search path')
def main():
- if not sys.argv[1:]:
+ if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):
print("usage: pdb.py scriptfile [arg] ...")
sys.exit(2)
diff --git a/Lib/test/test_format.py b/Lib/test/test_format.py
index 53e7d04..cbb7be8 100644
--- a/Lib/test/test_format.py
+++ b/Lib/test/test_format.py
@@ -1,7 +1,9 @@
from test.test_support import verbose, TestFailed
import sys
-from test.test_support import MAX_Py_ssize_t
-maxsize = MAX_Py_ssize_t
+import test.test_support as test_support
+import unittest
+
+maxsize = test_support.MAX_Py_ssize_t
# test string formatting operator (I am not sure if this is being tested
# elsewhere but, surely, some of the given cases are *not* tested because
@@ -33,8 +35,10 @@ def testformat(formatstr, args, output=None, limit=None):
elif output and limit is None and result != output:
if verbose:
print('no')
- print("%r %% %r == %r != %r" %\
- (formatstr, args, result, output))
+ #print("%r %% %r == %r != %r" %\
+ # (formatstr, args, result, output))
+ raise AssertionError("%r %% %r == %r != %r" %
+ (formatstr, args, result, output))
# when 'limit' is specified, it determines how many characters
# must match exactly; lengths must always match.
# ex: limit=5, '12345678' matches '12345___'
@@ -50,207 +54,210 @@ def testformat(formatstr, args, output=None, limit=None):
if verbose:
print('yes')
-testformat("%.1d", (1,), "1")
-testformat("%.*d", (sys.maxsize,1)) # expect overflow
-testformat("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-testformat("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-testformat("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-
-testformat("%f", (1.0,), "1.000000")
-# these are trying to test the limits of the internal magic-number-length
-# formatting buffer, if that number changes then these tests are less
-# effective
-testformat("%#.*g", (109, -1.e+49/3.))
-testformat("%#.*g", (110, -1.e+49/3.))
-testformat("%#.*g", (110, -1.e+100/3.))
-
-# test some ridiculously large precision, expect overflow
-testformat('%12.*f', (123456, 1.0))
-
-# check for internal overflow validation on length of precision
-overflowrequired = 1
-testformat("%#.*g", (110, -1.e+100/3.))
-testformat("%#.*G", (110, -1.e+100/3.))
-testformat("%#.*f", (110, -1.e+100/3.))
-testformat("%#.*F", (110, -1.e+100/3.))
-overflowrequired = 0
-
-# Formatting of long integers. Overflow is not ok
-overflowok = 0
-testformat("%x", 10, "a")
-testformat("%x", 100000000000, "174876e800")
-testformat("%o", 10, "12")
-testformat("%o", 100000000000, "1351035564000")
-testformat("%d", 10, "10")
-testformat("%d", 100000000000, "100000000000")
-
-big = 123456789012345678901234567890
-testformat("%d", big, "123456789012345678901234567890")
-testformat("%d", -big, "-123456789012345678901234567890")
-testformat("%5d", -big, "-123456789012345678901234567890")
-testformat("%31d", -big, "-123456789012345678901234567890")
-testformat("%32d", -big, " -123456789012345678901234567890")
-testformat("%-32d", -big, "-123456789012345678901234567890 ")
-testformat("%032d", -big, "-0123456789012345678901234567890")
-testformat("%-032d", -big, "-123456789012345678901234567890 ")
-testformat("%034d", -big, "-000123456789012345678901234567890")
-testformat("%034d", big, "0000123456789012345678901234567890")
-testformat("%0+34d", big, "+000123456789012345678901234567890")
-testformat("%+34d", big, " +123456789012345678901234567890")
-testformat("%34d", big, " 123456789012345678901234567890")
-testformat("%.2d", big, "123456789012345678901234567890")
-testformat("%.30d", big, "123456789012345678901234567890")
-testformat("%.31d", big, "0123456789012345678901234567890")
-testformat("%32.31d", big, " 0123456789012345678901234567890")
-testformat("%d", float(big), "123456________________________", 6)
-
-big = 0x1234567890abcdef12345 # 21 hex digits
-testformat("%x", big, "1234567890abcdef12345")
-testformat("%x", -big, "-1234567890abcdef12345")
-testformat("%5x", -big, "-1234567890abcdef12345")
-testformat("%22x", -big, "-1234567890abcdef12345")
-testformat("%23x", -big, " -1234567890abcdef12345")
-testformat("%-23x", -big, "-1234567890abcdef12345 ")
-testformat("%023x", -big, "-01234567890abcdef12345")
-testformat("%-023x", -big, "-1234567890abcdef12345 ")
-testformat("%025x", -big, "-0001234567890abcdef12345")
-testformat("%025x", big, "00001234567890abcdef12345")
-testformat("%0+25x", big, "+0001234567890abcdef12345")
-testformat("%+25x", big, " +1234567890abcdef12345")
-testformat("%25x", big, " 1234567890abcdef12345")
-testformat("%.2x", big, "1234567890abcdef12345")
-testformat("%.21x", big, "1234567890abcdef12345")
-testformat("%.22x", big, "01234567890abcdef12345")
-testformat("%23.22x", big, " 01234567890abcdef12345")
-testformat("%-23.22x", big, "01234567890abcdef12345 ")
-testformat("%X", big, "1234567890ABCDEF12345")
-testformat("%#X", big, "0X1234567890ABCDEF12345")
-testformat("%#x", big, "0x1234567890abcdef12345")
-testformat("%#x", -big, "-0x1234567890abcdef12345")
-testformat("%#.23x", -big, "-0x001234567890abcdef12345")
-testformat("%#+.23x", big, "+0x001234567890abcdef12345")
-testformat("%# .23x", big, " 0x001234567890abcdef12345")
-testformat("%#+.23X", big, "+0X001234567890ABCDEF12345")
-testformat("%#-+.23X", big, "+0X001234567890ABCDEF12345")
-testformat("%#-+26.23X", big, "+0X001234567890ABCDEF12345")
-testformat("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ")
-testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
-# next one gets two leading zeroes from precision, and another from the
-# 0 flag and the width
-testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
-# same, except no 0 flag
-testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
-testformat("%x", float(big), "123456_______________", 6)
-
-big = 0o12345670123456701234567012345670 # 32 octal digits
-testformat("%o", big, "12345670123456701234567012345670")
-testformat("%o", -big, "-12345670123456701234567012345670")
-testformat("%5o", -big, "-12345670123456701234567012345670")
-testformat("%33o", -big, "-12345670123456701234567012345670")
-testformat("%34o", -big, " -12345670123456701234567012345670")
-testformat("%-34o", -big, "-12345670123456701234567012345670 ")
-testformat("%034o", -big, "-012345670123456701234567012345670")
-testformat("%-034o", -big, "-12345670123456701234567012345670 ")
-testformat("%036o", -big, "-00012345670123456701234567012345670")
-testformat("%036o", big, "000012345670123456701234567012345670")
-testformat("%0+36o", big, "+00012345670123456701234567012345670")
-testformat("%+36o", big, " +12345670123456701234567012345670")
-testformat("%36o", big, " 12345670123456701234567012345670")
-testformat("%.2o", big, "12345670123456701234567012345670")
-testformat("%.32o", big, "12345670123456701234567012345670")
-testformat("%.33o", big, "012345670123456701234567012345670")
-testformat("%34.33o", big, " 012345670123456701234567012345670")
-testformat("%-34.33o", big, "012345670123456701234567012345670 ")
-testformat("%o", big, "12345670123456701234567012345670")
-testformat("%#o", big, "0o12345670123456701234567012345670")
-testformat("%#o", -big, "-0o12345670123456701234567012345670")
-testformat("%#.34o", -big, "-0o0012345670123456701234567012345670")
-testformat("%#+.34o", big, "+0o0012345670123456701234567012345670")
-testformat("%# .34o", big, " 0o0012345670123456701234567012345670")
-testformat("%#-+.34o", big, "+0o0012345670123456701234567012345670")
-testformat("%#-+39.34o", big, "+0o0012345670123456701234567012345670 ")
-testformat("%#+39.34o", big, " +0o0012345670123456701234567012345670")
-# next one gets one leading zero from precision
-testformat("%.33o", big, "012345670123456701234567012345670")
-# one leading zero from precision
-testformat("%#.33o", big, "0o012345670123456701234567012345670")
-# leading zero vanishes
-testformat("%#.32o", big, "0o12345670123456701234567012345670")
-# one leading zero from precision, and another from '0' flag & width
-testformat("%034.33o", big, "0012345670123456701234567012345670")
-# max width includes base marker; padding zeroes come after marker
-testformat("%0#38.33o", big, "0o000012345670123456701234567012345670")
-# padding spaces come before marker
-testformat("%#36.33o", big, " 0o012345670123456701234567012345670")
-testformat("%o", float(big), "123456__________________________", 6)
-# Some small ints, in both Python int and long flavors).
-testformat("%d", 42, "42")
-testformat("%d", -42, "-42")
-testformat("%#x", 1, "0x1")
-testformat("%#X", 1, "0X1")
-testformat("%#o", 1, "0o1")
-testformat("%#o", 1, "0o1")
-testformat("%#o", 0, "0o0")
-testformat("%#o", 0, "0o0")
-testformat("%o", 0, "0")
-testformat("%d", 0, "0")
-testformat("%#x", 0, "0x0")
-testformat("%#X", 0, "0X0")
+class FormatTest(unittest.TestCase):
+ def test_format(self):
+ testformat("%.1d", (1,), "1")
+ testformat("%.*d", (sys.maxsize,1)) # expect overflow
+ testformat("%.100d", (1,), '0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
+ testformat("%#.117x", (1,), '0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
+ testformat("%#.118x", (1,), '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001')
-testformat("%x", 0x42, "42")
-testformat("%x", -0x42, "-42")
-testformat("%x", float(0x42), "42")
+ testformat("%f", (1.0,), "1.000000")
+ # these are trying to test the limits of the internal magic-number-length
+ # formatting buffer, if that number changes then these tests are less
+ # effective
+ testformat("%#.*g", (109, -1.e+49/3.))
+ testformat("%#.*g", (110, -1.e+49/3.))
+ testformat("%#.*g", (110, -1.e+100/3.))
+ # test some ridiculously large precision, expect overflow
+ testformat('%12.*f', (123456, 1.0))
+ # check for internal overflow validation on length of precision
+ overflowrequired = 1
+ testformat("%#.*g", (110, -1.e+100/3.))
+ testformat("%#.*G", (110, -1.e+100/3.))
+ testformat("%#.*f", (110, -1.e+100/3.))
+ testformat("%#.*F", (110, -1.e+100/3.))
+ overflowrequired = 0
+ # Formatting of integers. Overflow is not ok
+ overflowok = 0
+ testformat("%x", 10, "a")
+ testformat("%x", 100000000000, "174876e800")
+ testformat("%o", 10, "12")
+ testformat("%o", 100000000000, "1351035564000")
+ testformat("%d", 10, "10")
+ testformat("%d", 100000000000, "100000000000")
+ big = 123456789012345678901234567890
+ testformat("%d", big, "123456789012345678901234567890")
+ testformat("%d", -big, "-123456789012345678901234567890")
+ testformat("%5d", -big, "-123456789012345678901234567890")
+ testformat("%31d", -big, "-123456789012345678901234567890")
+ testformat("%32d", -big, " -123456789012345678901234567890")
+ testformat("%-32d", -big, "-123456789012345678901234567890 ")
+ testformat("%032d", -big, "-0123456789012345678901234567890")
+ testformat("%-032d", -big, "-123456789012345678901234567890 ")
+ testformat("%034d", -big, "-000123456789012345678901234567890")
+ testformat("%034d", big, "0000123456789012345678901234567890")
+ testformat("%0+34d", big, "+000123456789012345678901234567890")
+ testformat("%+34d", big, " +123456789012345678901234567890")
+ testformat("%34d", big, " 123456789012345678901234567890")
+ testformat("%.2d", big, "123456789012345678901234567890")
+ testformat("%.30d", big, "123456789012345678901234567890")
+ testformat("%.31d", big, "0123456789012345678901234567890")
+ testformat("%32.31d", big, " 0123456789012345678901234567890")
+ testformat("%d", float(big), "123456________________________", 6)
+ big = 0x1234567890abcdef12345 # 21 hex digits
+ testformat("%x", big, "1234567890abcdef12345")
+ testformat("%x", -big, "-1234567890abcdef12345")
+ testformat("%5x", -big, "-1234567890abcdef12345")
+ testformat("%22x", -big, "-1234567890abcdef12345")
+ testformat("%23x", -big, " -1234567890abcdef12345")
+ testformat("%-23x", -big, "-1234567890abcdef12345 ")
+ testformat("%023x", -big, "-01234567890abcdef12345")
+ testformat("%-023x", -big, "-1234567890abcdef12345 ")
+ testformat("%025x", -big, "-0001234567890abcdef12345")
+ testformat("%025x", big, "00001234567890abcdef12345")
+ testformat("%0+25x", big, "+0001234567890abcdef12345")
+ testformat("%+25x", big, " +1234567890abcdef12345")
+ testformat("%25x", big, " 1234567890abcdef12345")
+ testformat("%.2x", big, "1234567890abcdef12345")
+ testformat("%.21x", big, "1234567890abcdef12345")
+ testformat("%.22x", big, "01234567890abcdef12345")
+ testformat("%23.22x", big, " 01234567890abcdef12345")
+ testformat("%-23.22x", big, "01234567890abcdef12345 ")
+ testformat("%X", big, "1234567890ABCDEF12345")
+ testformat("%#X", big, "0X1234567890ABCDEF12345")
+ testformat("%#x", big, "0x1234567890abcdef12345")
+ testformat("%#x", -big, "-0x1234567890abcdef12345")
+ testformat("%#.23x", -big, "-0x001234567890abcdef12345")
+ testformat("%#+.23x", big, "+0x001234567890abcdef12345")
+ testformat("%# .23x", big, " 0x001234567890abcdef12345")
+ testformat("%#+.23X", big, "+0X001234567890ABCDEF12345")
+ testformat("%#-+.23X", big, "+0X001234567890ABCDEF12345")
+ testformat("%#-+26.23X", big, "+0X001234567890ABCDEF12345")
+ testformat("%#-+27.23X", big, "+0X001234567890ABCDEF12345 ")
+ testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+ # next one gets two leading zeroes from precision, and another from the
+ # 0 flag and the width
+ testformat("%#+027.23X", big, "+0X0001234567890ABCDEF12345")
+ # same, except no 0 flag
+ testformat("%#+27.23X", big, " +0X001234567890ABCDEF12345")
+ testformat("%x", float(big), "123456_______________", 6)
+ big = 0o12345670123456701234567012345670 # 32 octal digits
+ testformat("%o", big, "12345670123456701234567012345670")
+ testformat("%o", -big, "-12345670123456701234567012345670")
+ testformat("%5o", -big, "-12345670123456701234567012345670")
+ testformat("%33o", -big, "-12345670123456701234567012345670")
+ testformat("%34o", -big, " -12345670123456701234567012345670")
+ testformat("%-34o", -big, "-12345670123456701234567012345670 ")
+ testformat("%034o", -big, "-012345670123456701234567012345670")
+ testformat("%-034o", -big, "-12345670123456701234567012345670 ")
+ testformat("%036o", -big, "-00012345670123456701234567012345670")
+ testformat("%036o", big, "000012345670123456701234567012345670")
+ testformat("%0+36o", big, "+00012345670123456701234567012345670")
+ testformat("%+36o", big, " +12345670123456701234567012345670")
+ testformat("%36o", big, " 12345670123456701234567012345670")
+ testformat("%.2o", big, "12345670123456701234567012345670")
+ testformat("%.32o", big, "12345670123456701234567012345670")
+ testformat("%.33o", big, "012345670123456701234567012345670")
+ testformat("%34.33o", big, " 012345670123456701234567012345670")
+ testformat("%-34.33o", big, "012345670123456701234567012345670 ")
+ testformat("%o", big, "12345670123456701234567012345670")
+ testformat("%#o", big, "0o12345670123456701234567012345670")
+ testformat("%#o", -big, "-0o12345670123456701234567012345670")
+ testformat("%#.34o", -big, "-0o0012345670123456701234567012345670")
+ testformat("%#+.34o", big, "+0o0012345670123456701234567012345670")
+ testformat("%# .34o", big, " 0o0012345670123456701234567012345670")
+ testformat("%#+.34o", big, "+0o0012345670123456701234567012345670")
+ testformat("%#-+.34o", big, "+0o0012345670123456701234567012345670")
+ testformat("%#-+37.34o", big, "+0o0012345670123456701234567012345670")
+ testformat("%#+37.34o", big, "+0o0012345670123456701234567012345670")
+ # next one gets one leading zero from precision
+ testformat("%.33o", big, "012345670123456701234567012345670")
+ # base marker shouldn't change that, since "0" is redundant
+ testformat("%#.33o", big, "0o012345670123456701234567012345670")
+ # but reduce precision, and base marker should add a zero
+ testformat("%#.32o", big, "0o12345670123456701234567012345670")
+ # one leading zero from precision, and another from "0" flag & width
+ testformat("%034.33o", big, "0012345670123456701234567012345670")
+ # base marker shouldn't change that
+ testformat("%0#34.33o", big, "0o012345670123456701234567012345670")
+ testformat("%o", float(big), "123456__________________________", 6)
+ # Some small ints, in both Python int and flavors).
+ testformat("%d", 42, "42")
+ testformat("%d", -42, "-42")
+ testformat("%d", 42, "42")
+ testformat("%d", -42, "-42")
+ testformat("%d", 42.0, "42")
+ testformat("%#x", 1, "0x1")
+ testformat("%#x", 1, "0x1")
+ testformat("%#X", 1, "0X1")
+ testformat("%#X", 1, "0X1")
+ testformat("%#x", 1.0, "0x1")
+ testformat("%#o", 1, "0o1")
+ testformat("%#o", 1, "0o1")
+ testformat("%#o", 0, "0o0")
+ testformat("%#o", 0, "0o0")
+ testformat("%o", 0, "0")
+ testformat("%o", 0, "0")
+ testformat("%d", 0, "0")
+ testformat("%d", 0, "0")
+ testformat("%#x", 0, "0x0")
+ testformat("%#x", 0, "0x0")
+ testformat("%#X", 0, "0X0")
+ testformat("%#X", 0, "0X0")
+ testformat("%x", 0x42, "42")
+ testformat("%x", -0x42, "-42")
+ testformat("%x", 0x42, "42")
+ testformat("%x", -0x42, "-42")
+ testformat("%x", float(0x42), "42")
+ testformat("%o", 0o42, "42")
+ testformat("%o", -0o42, "-42")
+ testformat("%o", 0o42, "42")
+ testformat("%o", -0o42, "-42")
+ testformat("%o", float(0o42), "42")
+ # Test exception for unknown format characters
+ if verbose:
+ print('Testing exceptions')
+ def test_exc(formatstr, args, exception, excmsg):
+ try:
+ testformat(formatstr, args)
+ except exception as exc:
+ if str(exc) == excmsg:
+ if verbose:
+ print("yes")
+ else:
+ if verbose: print('no')
+ print('Unexpected ', exception, ':', repr(str(exc)))
+ except:
+ if verbose: print('no')
+ print('Unexpected exception')
+ raise
+ else:
+ raise TestFailed('did not get expected exception: %s' % excmsg)
+ test_exc('abc %a', 1, ValueError,
+ "unsupported format character 'a' (0x61) at index 5")
+ #test_exc(unicode('abc %\u3000','raw-unicode-escape'), 1, ValueError,
+ # "unsupported format character '?' (0x3000) at index 5")
+ test_exc('%d', '1', TypeError, "%d format: a number is required, not str")
+ test_exc('%g', '1', TypeError, "a float is required")
+ test_exc('no format', '1', TypeError,
+ "not all arguments converted during string formatting")
+ test_exc('no format', '1', TypeError,
+ "not all arguments converted during string formatting")
-testformat("%o", 0o42, "42")
-testformat("%o", -0o42, "-42")
-testformat("%o", 0o42, "42")
-testformat("%o", -0o42, "-42")
-testformat("%o", float(0o42), "42")
+ if maxsize == 2**31-1:
+ # crashes 2.2.1 and earlier:
+ try:
+ "%*d"%(maxsize, -127)
+ except MemoryError:
+ pass
+ else:
+ raise TestFailed('"%*d"%(maxsize, -127) should fail')
-# Test exception for unknown format characters
-if verbose:
- print('Testing exceptions')
+def test_main():
+ test_support.run_unittest(FormatTest)
-def test_exc(formatstr, args, exception, excmsg):
- try:
- testformat(formatstr, args)
- except exception as exc:
- if str(exc) == excmsg:
- if verbose:
- print("yes")
- else:
- if verbose: print('no')
- print('Unexpected ', exception, ':', repr(str(exc)))
- except:
- if verbose: print('no')
- print('Unexpected exception')
- raise
- else:
- raise TestFailed('did not get expected exception: %s' % excmsg)
-test_exc('abc %a', 1, ValueError,
- "unsupported format character 'a' (0x61) at index 5")
-test_exc(str(b'abc %\u3000', 'raw-unicode-escape'), 1, ValueError,
- "unsupported format character '?' (0x3000) at index 5")
-
-#test_exc('%d', '1', TypeError, "an integer is required")
-test_exc('%d', '1', TypeError, '%d format: a number is required, not str')
-test_exc('%g', '1', TypeError, "a float is required")
-test_exc('no format', '1', TypeError,
- "not all arguments converted during string formatting")
-test_exc('no format', '1', TypeError,
- "not all arguments converted during string formatting")
-test_exc('no format', '1', TypeError,
- "not all arguments converted during string formatting")
-test_exc('no format', '1', TypeError,
- "not all arguments converted during string formatting")
-
-if maxsize == 2**31-1:
- # crashes 2.2.1 and earlier:
- try:
- "%*d"%(maxsize, -127)
- except MemoryError:
- pass
- else:
- raise TestFailed('"%*d"%(maxsize, -127) should fail')
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py
index 78bb613..ce0e075 100644
--- a/Lib/test/test_imaplib.py
+++ b/Lib/test/test_imaplib.py
@@ -1,12 +1,25 @@
import imaplib
import time
-# We can check only that it successfully produces a result,
-# not the correctness of the result itself, since the result
-# depends on the timezone the machine is in.
+from test import test_support
+import unittest
-timevalues = [2000000000, 2000000000.0, time.localtime(2000000000),
- '"18-May-2033 05:33:20 +0200"']
-for t in timevalues:
- imaplib.Time2Internaldate(t)
+class TestImaplib(unittest.TestCase):
+ def test_that_Time2Internaldate_returns_a_result(self):
+ # We can check only that it successfully produces a result,
+ # not the correctness of the result itself, since the result
+ # depends on the timezone the machine is in.
+ timevalues = [2000000000, 2000000000.0, time.localtime(2000000000),
+ '"18-May-2033 05:33:20 +0200"']
+
+ for t in timevalues:
+ imaplib.Time2Internaldate(t)
+
+
+def test_main():
+ test_support.run_unittest(TestImaplib)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 925f878..8f4b486 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -374,7 +374,7 @@ class TestMailbox(TestBase):
def test_flush(self):
# Write changes to disk
- self._test_flush_or_close(self._box.flush)
+ self._test_flush_or_close(self._box.flush, True)
def test_lock_unlock(self):
# Lock and unlock the mailbox
@@ -386,15 +386,17 @@ class TestMailbox(TestBase):
def test_close(self):
# Close mailbox and flush changes to disk
- self._test_flush_or_close(self._box.close)
+ self._test_flush_or_close(self._box.close, False)
- def _test_flush_or_close(self, method):
+ def _test_flush_or_close(self, method, should_call_close):
contents = [self._template % i for i in range(3)]
self._box.add(contents[0])
self._box.add(contents[1])
self._box.add(contents[2])
oldbox = self._box
method()
+ if should_call_close:
+ self._box.close()
self._box = self._factory(self._path)
keys = self._box.keys()
self.assertEqual(len(keys), 3)
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 3c05e63..627b167 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -1,174 +1,187 @@
import ntpath
-from test.test_support import verbose, TestFailed
import os
+from test.test_support import verbose, TestFailed
+import test.test_support as test_support
+import unittest
-errors = 0
def tester(fn, wantResult):
- global errors
fn = fn.replace("\\", "\\\\")
gotResult = eval(fn)
if wantResult != gotResult:
- print("error!")
- print("evaluated: " + str(fn))
- print("should be: " + str(wantResult))
- print(" returned: " + str(gotResult))
- print("")
- errors = errors + 1
-
-tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
-tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
-tester('ntpath.splitext(".ext")', ('.ext', ''))
-tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
-tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
-tester('ntpath.splitext("")', ('', ''))
-tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
-tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
-tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
-tester('ntpath.splitext("c:a/b\\c.d")', ('c:a/b\\c', '.d'))
-
-tester('ntpath.splitdrive("c:\\foo\\bar")',
- ('c:', '\\foo\\bar'))
-tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
- ('\\\\conky\\mountpoint', '\\foo\\bar'))
-tester('ntpath.splitdrive("c:/foo/bar")',
- ('c:', '/foo/bar'))
-tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
- ('//conky/mountpoint', '/foo/bar'))
-
-tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
-tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
- ('\\\\conky\\mountpoint\\foo', 'bar'))
-
-tester('ntpath.split("c:\\")', ('c:\\', ''))
-tester('ntpath.split("\\\\conky\\mountpoint\\")',
- ('\\\\conky\\mountpoint', ''))
-
-tester('ntpath.split("c:/")', ('c:/', ''))
-tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
-
-tester('ntpath.isabs("c:\\")', 1)
-tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
-tester('ntpath.isabs("\\foo")', 1)
-tester('ntpath.isabs("\\foo\\bar")', 1)
-
-tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
- "/home/swen")
-tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
- "\\home\\swen\\")
-tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
- "/home/swen/spam")
-
-tester('ntpath.join("")', '')
-tester('ntpath.join("", "", "")', '')
-tester('ntpath.join("a")', 'a')
-tester('ntpath.join("/a")', '/a')
-tester('ntpath.join("\\a")', '\\a')
-tester('ntpath.join("a:")', 'a:')
-tester('ntpath.join("a:", "b")', 'a:b')
-tester('ntpath.join("a:", "/b")', 'a:/b')
-tester('ntpath.join("a:", "\\b")', 'a:\\b')
-tester('ntpath.join("a", "/b")', '/b')
-tester('ntpath.join("a", "\\b")', '\\b')
-tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
-tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
-tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
-tester('ntpath.join("a", "b", "\\c")', '\\c')
-tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
-tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
-tester("ntpath.join('c:', '/a')", 'c:/a')
-tester("ntpath.join('c:/', '/a')", 'c:/a')
-tester("ntpath.join('c:/a', '/b')", '/b')
-tester("ntpath.join('c:', 'd:/')", 'd:/')
-tester("ntpath.join('c:/', 'd:/')", 'd:/')
-tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
-
-tester("ntpath.join('')", '')
-tester("ntpath.join('', '', '', '', '')", '')
-tester("ntpath.join('a')", 'a')
-tester("ntpath.join('', 'a')", 'a')
-tester("ntpath.join('', '', '', '', 'a')", 'a')
-tester("ntpath.join('a', '')", 'a\\')
-tester("ntpath.join('a', '', '', '', '')", 'a\\')
-tester("ntpath.join('a\\', '')", 'a\\')
-tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
-
-tester("ntpath.normpath('A//////././//.//B')", r'A\B')
-tester("ntpath.normpath('A/./B')", r'A\B')
-tester("ntpath.normpath('A/foo/../B')", r'A\B')
-tester("ntpath.normpath('C:A//B')", r'C:A\B')
-tester("ntpath.normpath('D:A/./B')", r'D:A\B')
-tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
-
-tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
-tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
-tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
-
-tester("ntpath.normpath('..')", r'..')
-tester("ntpath.normpath('.')", r'.')
-tester("ntpath.normpath('')", r'.')
-tester("ntpath.normpath('/')", '\\')
-tester("ntpath.normpath('c:/')", 'c:\\')
-tester("ntpath.normpath('/../.././..')", '\\')
-tester("ntpath.normpath('c:/../../..')", 'c:\\')
-tester("ntpath.normpath('../.././..')", r'..\..\..')
-tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
-tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
-tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
-
-oldenv = os.environ.copy()
-try:
- os.environ.clear()
- os.environ["foo"] = "bar"
- os.environ["{foo"] = "baz1"
- os.environ["{foo}"] = "baz2"
- tester('ntpath.expandvars("foo")', "foo")
- tester('ntpath.expandvars("$foo bar")', "bar bar")
- tester('ntpath.expandvars("${foo}bar")', "barbar")
- tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")
- tester('ntpath.expandvars("$bar bar")', "$bar bar")
- tester('ntpath.expandvars("$?bar")', "$?bar")
- tester('ntpath.expandvars("${foo}bar")', "barbar")
- tester('ntpath.expandvars("$foo}bar")', "bar}bar")
- tester('ntpath.expandvars("${foo")', "${foo")
- tester('ntpath.expandvars("${{foo}}")', "baz1}")
- tester('ntpath.expandvars("$foo$foo")', "barbar")
- tester('ntpath.expandvars("$bar$bar")', "$bar$bar")
- tester('ntpath.expandvars("%foo% bar")', "bar bar")
- tester('ntpath.expandvars("%foo%bar")', "barbar")
- tester('ntpath.expandvars("%foo%%foo%")', "barbar")
- tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar")
- tester('ntpath.expandvars("%?bar%")', "%?bar%")
- tester('ntpath.expandvars("%foo%%bar")', "bar%bar")
- tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
-finally:
- os.environ.clear()
- os.environ.update(oldenv)
-
-# ntpath.abspath() can only be used on a system with the "nt" module
-# (reasonably), so we protect this test with "import nt". This allows
-# the rest of the tests for the ntpath module to be run to completion
-# on any platform, since most of the module is intended to be usable
-# from any platform.
-try:
- import nt
-except ImportError:
- pass
-else:
- tester('ntpath.abspath("C:\\")', "C:\\")
-
-currentdir = os.path.split(os.getcwd())[-1]
-tester('ntpath.relpath("a")', 'a')
-tester('ntpath.relpath(os.path.abspath("a"))', 'a')
-tester('ntpath.relpath("a/b")', 'a\\b')
-tester('ntpath.relpath("../a/b")', '..\\a\\b')
-tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
-tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
-tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
-tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
-tester('ntpath.relpath("a", "a")', '.')
-
-if errors:
- raise TestFailed(str(errors) + " errors.")
-elif verbose:
- print("No errors. Thank your lucky stars.")
+ raise TestFailed("%s should return: %s but returned: %s" \
+ %(str(fn), str(wantResult), str(gotResult)))
+
+
+class TestNtpath(unittest.TestCase):
+ def test_splitext(self):
+ tester('ntpath.splitext("foo.ext")', ('foo', '.ext'))
+ tester('ntpath.splitext("/foo/foo.ext")', ('/foo/foo', '.ext'))
+ tester('ntpath.splitext(".ext")', ('.ext', ''))
+ tester('ntpath.splitext("\\foo.ext\\foo")', ('\\foo.ext\\foo', ''))
+ tester('ntpath.splitext("foo.ext\\")', ('foo.ext\\', ''))
+ tester('ntpath.splitext("")', ('', ''))
+ tester('ntpath.splitext("foo.bar.ext")', ('foo.bar', '.ext'))
+ tester('ntpath.splitext("xx/foo.bar.ext")', ('xx/foo.bar', '.ext'))
+ tester('ntpath.splitext("xx\\foo.bar.ext")', ('xx\\foo.bar', '.ext'))
+ tester('ntpath.splitext("c:a/b\\c.d")', ('c:a/b\\c', '.d'))
+
+ def test_splitdrive(self):
+ tester('ntpath.splitdrive("c:\\foo\\bar")',
+ ('c:', '\\foo\\bar'))
+ tester('ntpath.splitdrive("c:/foo/bar")',
+ ('c:', '/foo/bar'))
+
+ def test_splitunc(self):
+ tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
+ ('\\\\conky\\mountpoint', '\\foo\\bar'))
+ tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
+ ('//conky/mountpoint', '/foo/bar'))
+
+ def test_split(self):
+ tester('ntpath.split("c:\\foo\\bar")', ('c:\\foo', 'bar'))
+ tester('ntpath.split("\\\\conky\\mountpoint\\foo\\bar")',
+ ('\\\\conky\\mountpoint\\foo', 'bar'))
+
+ tester('ntpath.split("c:\\")', ('c:\\', ''))
+ tester('ntpath.split("\\\\conky\\mountpoint\\")',
+ ('\\\\conky\\mountpoint', ''))
+
+ tester('ntpath.split("c:/")', ('c:/', ''))
+ tester('ntpath.split("//conky/mountpoint/")', ('//conky/mountpoint', ''))
+
+ def test_isabs(self):
+ tester('ntpath.isabs("c:\\")', 1)
+ tester('ntpath.isabs("\\\\conky\\mountpoint\\")', 1)
+ tester('ntpath.isabs("\\foo")', 1)
+ tester('ntpath.isabs("\\foo\\bar")', 1)
+
+ def test_commonprefix(self):
+ tester('ntpath.commonprefix(["/home/swenson/spam", "/home/swen/spam"])',
+ "/home/swen")
+ tester('ntpath.commonprefix(["\\home\\swen\\spam", "\\home\\swen\\eggs"])',
+ "\\home\\swen\\")
+ tester('ntpath.commonprefix(["/home/swen/spam", "/home/swen/spam"])',
+ "/home/swen/spam")
+
+ def test_join(self):
+ tester('ntpath.join("")', '')
+ tester('ntpath.join("", "", "")', '')
+ tester('ntpath.join("a")', 'a')
+ tester('ntpath.join("/a")', '/a')
+ tester('ntpath.join("\\a")', '\\a')
+ tester('ntpath.join("a:")', 'a:')
+ tester('ntpath.join("a:", "b")', 'a:b')
+ tester('ntpath.join("a:", "/b")', 'a:/b')
+ tester('ntpath.join("a:", "\\b")', 'a:\\b')
+ tester('ntpath.join("a", "/b")', '/b')
+ tester('ntpath.join("a", "\\b")', '\\b')
+ tester('ntpath.join("a", "b", "c")', 'a\\b\\c')
+ tester('ntpath.join("a\\", "b", "c")', 'a\\b\\c')
+ tester('ntpath.join("a", "b\\", "c")', 'a\\b\\c')
+ tester('ntpath.join("a", "b", "\\c")', '\\c')
+ tester('ntpath.join("d:\\", "\\pleep")', 'd:\\pleep')
+ tester('ntpath.join("d:\\", "a", "b")', 'd:\\a\\b')
+ tester("ntpath.join('c:', '/a')", 'c:/a')
+ tester("ntpath.join('c:/', '/a')", 'c:/a')
+ tester("ntpath.join('c:/a', '/b')", '/b')
+ tester("ntpath.join('c:', 'd:/')", 'd:/')
+ tester("ntpath.join('c:/', 'd:/')", 'd:/')
+ tester("ntpath.join('c:/', 'd:/a/b')", 'd:/a/b')
+
+ tester("ntpath.join('')", '')
+ tester("ntpath.join('', '', '', '', '')", '')
+ tester("ntpath.join('a')", 'a')
+ tester("ntpath.join('', 'a')", 'a')
+ tester("ntpath.join('', '', '', '', 'a')", 'a')
+ tester("ntpath.join('a', '')", 'a\\')
+ tester("ntpath.join('a', '', '', '', '')", 'a\\')
+ tester("ntpath.join('a\\', '')", 'a\\')
+ tester("ntpath.join('a\\', '', '', '', '')", 'a\\')
+
+ def test_normpath(self):
+ tester("ntpath.normpath('A//////././//.//B')", r'A\B')
+ tester("ntpath.normpath('A/./B')", r'A\B')
+ tester("ntpath.normpath('A/foo/../B')", r'A\B')
+ tester("ntpath.normpath('C:A//B')", r'C:A\B')
+ tester("ntpath.normpath('D:A/./B')", r'D:A\B')
+ tester("ntpath.normpath('e:A/foo/../B')", r'e:A\B')
+
+ tester("ntpath.normpath('C:///A//B')", r'C:\A\B')
+ tester("ntpath.normpath('D:///A/./B')", r'D:\A\B')
+ tester("ntpath.normpath('e:///A/foo/../B')", r'e:\A\B')
+
+ tester("ntpath.normpath('..')", r'..')
+ tester("ntpath.normpath('.')", r'.')
+ tester("ntpath.normpath('')", r'.')
+ tester("ntpath.normpath('/')", '\\')
+ tester("ntpath.normpath('c:/')", 'c:\\')
+ tester("ntpath.normpath('/../.././..')", '\\')
+ tester("ntpath.normpath('c:/../../..')", 'c:\\')
+ tester("ntpath.normpath('../.././..')", r'..\..\..')
+ tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
+ tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
+ tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
+
+ def test_expandvars(self):
+ oldenv = os.environ.copy()
+ try:
+ os.environ.clear()
+ os.environ["foo"] = "bar"
+ os.environ["{foo"] = "baz1"
+ os.environ["{foo}"] = "baz2"
+ tester('ntpath.expandvars("foo")', "foo")
+ tester('ntpath.expandvars("$foo bar")', "bar bar")
+ tester('ntpath.expandvars("${foo}bar")', "barbar")
+ tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")
+ tester('ntpath.expandvars("$bar bar")', "$bar bar")
+ tester('ntpath.expandvars("$?bar")', "$?bar")
+ tester('ntpath.expandvars("${foo}bar")', "barbar")
+ tester('ntpath.expandvars("$foo}bar")', "bar}bar")
+ tester('ntpath.expandvars("${foo")', "${foo")
+ tester('ntpath.expandvars("${{foo}}")', "baz1}")
+ tester('ntpath.expandvars("$foo$foo")', "barbar")
+ tester('ntpath.expandvars("$bar$bar")', "$bar$bar")
+ tester('ntpath.expandvars("%foo% bar")', "bar bar")
+ tester('ntpath.expandvars("%foo%bar")', "barbar")
+ tester('ntpath.expandvars("%foo%%foo%")', "barbar")
+ tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar")
+ tester('ntpath.expandvars("%?bar%")', "%?bar%")
+ tester('ntpath.expandvars("%foo%%bar")', "bar%bar")
+ tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
+ finally:
+ os.environ.clear()
+ os.environ.update(oldenv)
+
+ def test_abspath(self):
+ # ntpath.abspath() can only be used on a system with the "nt" module
+ # (reasonably), so we protect this test with "import nt". This allows
+ # the rest of the tests for the ntpath module to be run to completion
+ # on any platform, since most of the module is intended to be usable
+ # from any platform.
+ try:
+ import nt
+ except ImportError:
+ pass
+ else:
+ tester('ntpath.abspath("C:\\")', "C:\\")
+
+ def test_relpath(self):
+ currentdir = os.path.split(os.getcwd())[-1]
+ tester('ntpath.relpath("a")', 'a')
+ tester('ntpath.relpath(os.path.abspath("a"))', 'a')
+ tester('ntpath.relpath("a/b")', 'a\\b')
+ tester('ntpath.relpath("../a/b")', '..\\a\\b')
+ tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
+ tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
+ tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
+ tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
+ tester('ntpath.relpath("a", "a")', '.')
+
+
+def test_main():
+ test_support.run_unittest(TestNtpath)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py
index 5986afa..6324fc1 100644
--- a/Lib/test/test_timeout.py
+++ b/Lib/test/test_timeout.py
@@ -107,24 +107,19 @@ class TimeoutTestCase(unittest.TestCase):
self.sock.close()
def testConnectTimeout(self):
- # If we are too close to www.python.org, this test will fail.
- # Pick a host that should be farther away.
- if (socket.getfqdn().split('.')[-2:] == ['python', 'org'] or
- socket.getfqdn().split('.')[-2:-1] == ['xs4all']):
- self.addr_remote = ('tut.fi', 80)
-
- # Lookup the IP address to avoid including the DNS lookup time
+ # Choose a private address that is unlikely to exist to prevent
+ # failures due to the connect succeeding before the timeout.
+ # Use a dotted IP address to avoid including the DNS lookup time
# with the connect time. This avoids failing the assertion that
# the timeout occurred fast enough.
- self.addr_remote = (socket.gethostbyname(self.addr_remote[0]), 80)
+ addr = ('10.0.0.0', 12345)
# Test connect() timeout
_timeout = 0.001
self.sock.settimeout(_timeout)
_t1 = time.time()
- self.failUnlessRaises(socket.error, self.sock.connect,
- self.addr_remote)
+ self.failUnlessRaises(socket.error, self.sock.connect, addr)
_t2 = time.time()
_delta = abs(_t1 - _t2)
diff --git a/Misc/ACKS b/Misc/ACKS
index 327d8f3..58e55d2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1,3 +1,14 @@
+Acknowledgements
+----------------
+
+This list is not complete and not in any useful order, but I would
+like to thank everybody who contributed in any way, with code, hints,
+bug reports, ideas, moral support, endorsement, or even complaints....
+Without you I would've stopped working on Python long ago!
+
+ --Guido
+
+PS: In the standard Python distribution this file is encoded in Latin-1.
David Abrahams
Jim Ahlstrom
diff --git a/Misc/developers.txt b/Misc/developers.txt
index afb031f..0e7ddd5 100644
--- a/Misc/developers.txt
+++ b/Misc/developers.txt
@@ -17,6 +17,9 @@ the format to accommodate documentation needs as they arise.
Permissions History
-------------------
+- Josiah Carlson was given SVN access on 26 March 2008 by Georg Brandl,
+ for work on asyncore/asynchat.
+
- Benjamin Peterson was given SVN access on 25 March 2008 by Georg
Brandl, for bug triage work.
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index d39cf4b..842ebb2 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -99,6 +99,8 @@ bytes(cdata)
*
*/
+#define PY_SSIZE_T_CLEAN
+
#include "Python.h"
#include "structmember.h"
@@ -2273,7 +2275,7 @@ static PyObject *
CData_setstate(PyObject *_self, PyObject *args)
{
void *data;
- int len;
+ Py_ssize_t len;
int res;
PyObject *dict, *mydict;
CDataObject *self = (CDataObject *)_self;
@@ -3007,7 +3009,7 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
char *name = NULL;
PyObject *paramflags = NULL;
GUID *iid = NULL;
- int iid_len = 0;
+ Py_ssize_t iid_len = 0;
if (!PyArg_ParseTuple(args, "is|Oz#", &index, &name, &paramflags, &iid, &iid_len))
return NULL;
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 0f0cabd..653b713 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -409,7 +409,7 @@ poll_register(pollObject *self, PyObject *args)
PyDoc_STRVAR(poll_modify_doc,
"modify(fd, eventmask) -> None\n\n\
-Modify an already register file descriptor.\n\
+Modify an already registered file descriptor.\n\
fd -- either an integer, or an object with a fileno() method returning an\n\
int.\n\
events -- an optional bitmask describing the type of events to check for");
@@ -915,10 +915,10 @@ pyepoll_register(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
PyDoc_STRVAR(pyepoll_register_doc,
"register(fd[, eventmask]) -> bool\n\
\n\
-Registers a new fd or modifies an already registered fd. register returns\n\
+Registers a new fd or modifies an already registered fd. register() returns\n\
True if a new fd was registered or False if the event mask for fd was modified.\n\
-fd is the target file descriptor of the operation\n\
-events is a bit set composed of the various EPOLL constants, the default\n\
+fd is the target file descriptor of the operation.\n\
+events is a bit set composed of the various EPOLL constants; the default\n\
is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\
\n\
The epoll interface supports all file descriptors that support poll.");
@@ -988,6 +988,7 @@ pyepoll_poll(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
else if (dtimeout * 1000.0 > INT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"timeout is too large");
+ return NULL;
}
else {
timeout = (int)(dtimeout * 1000.0);
@@ -1024,19 +1025,15 @@ pyepoll_poll(pyEpoll_Object *self, PyObject *args, PyObject *kwds)
}
for (i = 0; i < nfds; i++) {
- etuple = Py_BuildValue("iI", evs[i].data.fd,
- evs[i].events);
+ etuple = Py_BuildValue("iI", evs[i].data.fd, evs[i].events);
if (etuple == NULL) {
+ Py_CLEAR(elist);
goto error;
}
PyList_SET_ITEM(elist, i, etuple);
}
- if (0) {
- error:
- Py_CLEAR(elist);
- Py_XDECREF(etuple);
- }
+ error:
PyMem_Free(evs);
return elist;
}
@@ -1716,7 +1713,7 @@ that are ready.\n\
\n\
*** IMPORTANT NOTICE ***\n\
On Windows and OpenVMS, only sockets are supported; on Unix, all file\n\
-descriptors.");
+descriptors can be used.");
static PyMethodDef select_methods[] = {
{"select", select_select, METH_VARARGS, select_doc},