Merged revisions 53623-53858 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r53624 | peter.astrand | 2007-02-02 20:06:36 +0100 (Fri, 02 Feb 2007) | 1 line
We had several if statements checking the value of a fd. This is unsafe, since valid fds might be zero. We should check for not None instead.
........
r53635 | kurt.kaiser | 2007-02-05 07:03:18 +0100 (Mon, 05 Feb 2007) | 2 lines
Add 'raw' support to configHandler. Patch 1650174 Tal Einat.
........
r53641 | kurt.kaiser | 2007-02-06 00:02:16 +0100 (Tue, 06 Feb 2007) | 5 lines
1. Calltips now 'handle' tuples in the argument list (display '<tuple>' :)
Suggested solution by Christos Georgiou, Bug 791968.
2. Clean up tests, were not failing when they should have been.
4. Remove some camelcase and an unneeded try/except block.
........
r53644 | kurt.kaiser | 2007-02-06 04:21:40 +0100 (Tue, 06 Feb 2007) | 2 lines
Clean up ModifiedInterpreter.runcode() structure
........
r53646 | peter.astrand | 2007-02-06 16:37:50 +0100 (Tue, 06 Feb 2007) | 1 line
Applied patch 1124861.3.patch to solve bug #1124861: Automatically create pipes on Windows, if GetStdHandle fails. Will backport.
........
r53648 | lars.gustaebel | 2007-02-06 19:38:13 +0100 (Tue, 06 Feb 2007) | 4 lines
Patch #1652681: create nonexistent files in append mode and
allow appending to empty files.
........
r53649 | kurt.kaiser | 2007-02-06 20:09:43 +0100 (Tue, 06 Feb 2007) | 4 lines
Updated patch (CodeContext.061217.patch) to
[ 1362975 ] CodeContext - Improved text indentation
Tal Einat 16Dec06
........
r53650 | kurt.kaiser | 2007-02-06 20:21:19 +0100 (Tue, 06 Feb 2007) | 2 lines
narrow exception per [ 1540849 ] except too broad
........
r53653 | kurt.kaiser | 2007-02-07 04:39:41 +0100 (Wed, 07 Feb 2007) | 4 lines
[ 1621265 ] Auto-completion list placement
Move AC window below input line unless not enough space, then put it above.
Patch: Tal Einat
........
r53654 | kurt.kaiser | 2007-02-07 09:07:13 +0100 (Wed, 07 Feb 2007) | 2 lines
Handle AttributeError during calltip lookup
........
r53656 | raymond.hettinger | 2007-02-07 21:08:22 +0100 (Wed, 07 Feb 2007) | 3 lines
SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses
........
r53658 | raymond.hettinger | 2007-02-07 22:04:20 +0100 (Wed, 07 Feb 2007) | 1 line
SF: 1397711 Set docs conflated immutable and hashable
........
r53660 | raymond.hettinger | 2007-02-07 22:42:17 +0100 (Wed, 07 Feb 2007) | 1 line
Check for a common user error with defaultdict().
........
r53662 | raymond.hettinger | 2007-02-07 23:24:07 +0100 (Wed, 07 Feb 2007) | 1 line
Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict.
........
r53664 | raymond.hettinger | 2007-02-08 00:49:03 +0100 (Thu, 08 Feb 2007) | 1 line
Silence compiler warning
........
r53666 | raymond.hettinger | 2007-02-08 01:07:32 +0100 (Thu, 08 Feb 2007) | 1 line
Do not let overflows in enumerate() and count() pass silently.
........
r53668 | raymond.hettinger | 2007-02-08 01:50:39 +0100 (Thu, 08 Feb 2007) | 1 line
Bypass set specific optimizations for set and frozenset subclasses.
........
r53670 | raymond.hettinger | 2007-02-08 02:42:35 +0100 (Thu, 08 Feb 2007) | 1 line
Fix docstring bug
........
r53671 | martin.v.loewis | 2007-02-08 10:13:36 +0100 (Thu, 08 Feb 2007) | 3 lines
Bug #1653736: Complain about keyword arguments to time.isoformat.
Will backport to 2.5.
........
r53679 | kurt.kaiser | 2007-02-08 23:58:18 +0100 (Thu, 08 Feb 2007) | 6 lines
Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
mouse and cursor selection in ACWindow implemented; double Tab inserts current
selection and closes ACW (similar to double-click and Return); scroll wheel now
works in ACW. Added AutoComplete instructions to IDLE Help.
........
r53689 | martin.v.loewis | 2007-02-09 13:19:32 +0100 (Fri, 09 Feb 2007) | 3 lines
Bug #1653736: Properly discard third argument to slot_nb_inplace_power.
Will backport.
........
r53691 | martin.v.loewis | 2007-02-09 13:36:48 +0100 (Fri, 09 Feb 2007) | 4 lines
Bug #1600860: Search for shared python library in LIBDIR, not
lib/python/config, on "linux" and "gnu" systems.
Will backport.
........
r53693 | martin.v.loewis | 2007-02-09 13:58:49 +0100 (Fri, 09 Feb 2007) | 2 lines
Update broken link. Will backport to 2.5.
........
r53697 | georg.brandl | 2007-02-09 19:48:41 +0100 (Fri, 09 Feb 2007) | 2 lines
Bug #1656078: typo in in profile docs.
........
r53731 | brett.cannon | 2007-02-11 06:36:00 +0100 (Sun, 11 Feb 2007) | 3 lines
Change a very minor inconsistency (that is purely cosmetic) in the AST
definition.
........
r53735 | skip.montanaro | 2007-02-11 19:24:37 +0100 (Sun, 11 Feb 2007) | 1 line
fix trace.py --ignore-dir
........
r53741 | brett.cannon | 2007-02-11 20:44:41 +0100 (Sun, 11 Feb 2007) | 3 lines
Check in changed Python-ast.c from a cosmetic change to Python.asdl (in
r53731).
........
r53751 | brett.cannon | 2007-02-12 04:51:02 +0100 (Mon, 12 Feb 2007) | 5 lines
Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c
is specified at the top of the file. Also add a note that Python/Python-ast.c
needs to be committed separately after a change to the AST grammar to capture
the revision number of the change (which is what __version__ is set to).
........
r53752 | lars.gustaebel | 2007-02-12 10:25:53 +0100 (Mon, 12 Feb 2007) | 3 lines
Bug #1656581: Point out that external file objects are supposed to be
at position 0.
........
r53754 | martin.v.loewis | 2007-02-12 13:21:10 +0100 (Mon, 12 Feb 2007) | 3 lines
Patch 1463026: Support default namespace in XMLGenerator.
Fixes #847665. Will backport.
........
r53757 | armin.rigo | 2007-02-12 17:23:24 +0100 (Mon, 12 Feb 2007) | 4 lines
Fix the line to what is my guess at the original author's meaning.
(The line has no effect anyway, but is present because it's
customary call the base class __init__).
........
r53763 | martin.v.loewis | 2007-02-13 09:34:45 +0100 (Tue, 13 Feb 2007) | 3 lines
Patch #685268: Consider a package's __path__ in imputil.
Will backport.
........
r53765 | martin.v.loewis | 2007-02-13 10:49:38 +0100 (Tue, 13 Feb 2007) | 2 lines
Patch #698833: Support file decryption in zipfile.
........
r53766 | martin.v.loewis | 2007-02-13 11:10:39 +0100 (Tue, 13 Feb 2007) | 3 lines
Patch #1517891: Make 'a' create the file if it doesn't exist.
Fixes #1514451.
........
r53767 | martin.v.loewis | 2007-02-13 13:08:24 +0100 (Tue, 13 Feb 2007) | 3 lines
Bug #1658794: Remove extraneous 'this'.
Will backport to 2.5.
........
r53769 | martin.v.loewis | 2007-02-13 13:14:19 +0100 (Tue, 13 Feb 2007) | 3 lines
Patch #1657276: Make NETLINK_DNRTMSG conditional.
Will backport.
........
r53771 | lars.gustaebel | 2007-02-13 17:09:24 +0100 (Tue, 13 Feb 2007) | 4 lines
Patch #1647484: Renamed GzipFile's filename attribute to name. The
filename attribute is still accessible as a property that emits a
DeprecationWarning.
........
r53772 | lars.gustaebel | 2007-02-13 17:24:00 +0100 (Tue, 13 Feb 2007) | 3 lines
Strip the '.gz' extension from the filename that is written to the
gzip header.
........
r53774 | martin.v.loewis | 2007-02-14 11:07:37 +0100 (Wed, 14 Feb 2007) | 2 lines
Patch #1432399: Add HCI sockets.
........
r53775 | martin.v.loewis | 2007-02-14 12:30:07 +0100 (Wed, 14 Feb 2007) | 2 lines
Update 1432399 to removal of _BT_SOCKADDR_MEMB.
........
r53776 | martin.v.loewis | 2007-02-14 12:30:56 +0100 (Wed, 14 Feb 2007) | 3 lines
Ignore directory time stamps when considering
whether to rerun libffi configure.
........
r53778 | lars.gustaebel | 2007-02-14 15:45:12 +0100 (Wed, 14 Feb 2007) | 4 lines
A missing binary mode in AppendTest caused failures in Windows
Buildbot.
........
r53782 | martin.v.loewis | 2007-02-15 10:51:35 +0100 (Thu, 15 Feb 2007) | 2 lines
Patch #1397848: add the reasoning behind no-resize-on-shrinkage.
........
r53783 | georg.brandl | 2007-02-15 11:37:59 +0100 (Thu, 15 Feb 2007) | 2 lines
Make functools.wraps() docs a bit clearer.
........
r53785 | georg.brandl | 2007-02-15 12:29:04 +0100 (Thu, 15 Feb 2007) | 2 lines
Patch #1494140: Add documentation for the new struct.Struct object.
........
r53787 | georg.brandl | 2007-02-15 12:29:55 +0100 (Thu, 15 Feb 2007) | 2 lines
Add missing \versionadded.
........
r53800 | brett.cannon | 2007-02-15 23:54:39 +0100 (Thu, 15 Feb 2007) | 11 lines
Update the encoding package's search function to use absolute imports when
calling __import__. This helps make the expected search locations for encoding
modules be more explicit.
One could use an explicit value for __path__ when making the call to __import__
to force the exact location searched for encodings. This would give the most
strict search path possible if one is worried about malicious code being
imported. The unfortunate side-effect of that is that if __path__ was modified
on 'encodings' on purpose in a safe way it would not be picked up in future
__import__ calls.
........
r53801 | brett.cannon | 2007-02-16 20:33:01 +0100 (Fri, 16 Feb 2007) | 2 lines
Make the __import__ call in encodings.__init__ absolute with a level 0 call.
........
r53809 | vinay.sajip | 2007-02-16 23:36:24 +0100 (Fri, 16 Feb 2007) | 1 line
Minor fix for currentframe (SF #1652788).
........
r53818 | raymond.hettinger | 2007-02-19 03:03:19 +0100 (Mon, 19 Feb 2007) | 3 lines
Extend work on revision 52962: Eliminate redundant calls to PyObject_Hash().
........
r53820 | raymond.hettinger | 2007-02-19 05:08:43 +0100 (Mon, 19 Feb 2007) | 1 line
Add merge() function to heapq.
........
r53821 | raymond.hettinger | 2007-02-19 06:28:28 +0100 (Mon, 19 Feb 2007) | 1 line
Add tie-breaker count to preserve sort stability.
........
r53822 | raymond.hettinger | 2007-02-19 07:59:32 +0100 (Mon, 19 Feb 2007) | 1 line
Use C heapreplace() instead of slower _siftup() in pure python.
........
r53823 | raymond.hettinger | 2007-02-19 08:30:21 +0100 (Mon, 19 Feb 2007) | 1 line
Add test for merge stability
........
r53824 | raymond.hettinger | 2007-02-19 10:14:10 +0100 (Mon, 19 Feb 2007) | 1 line
Provide an example of defaultdict with non-zero constant factory function.
........
r53825 | lars.gustaebel | 2007-02-19 10:54:47 +0100 (Mon, 19 Feb 2007) | 2 lines
Moved misplaced news item.
........
r53826 | martin.v.loewis | 2007-02-19 11:55:19 +0100 (Mon, 19 Feb 2007) | 3 lines
Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
functions on platforms where the underlying system calls are available.
........
r53827 | raymond.hettinger | 2007-02-19 19:15:04 +0100 (Mon, 19 Feb 2007) | 1 line
Fixup docstrings for merge().
........
r53829 | raymond.hettinger | 2007-02-19 21:44:04 +0100 (Mon, 19 Feb 2007) | 1 line
Fixup set/dict interoperability.
........
r53837 | raymond.hettinger | 2007-02-21 06:20:38 +0100 (Wed, 21 Feb 2007) | 1 line
Add itertools.izip_longest().
........
r53838 | raymond.hettinger | 2007-02-21 18:22:05 +0100 (Wed, 21 Feb 2007) | 1 line
Remove filler struct item and fix leak.
........
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 70b00a4..6b4c667 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -1767,6 +1767,11 @@
self.assertEqual(t.isoformat(), "00:00:00.100000")
self.assertEqual(t.isoformat(), str(t))
+ def test_1653736(self):
+ # verify it doesn't accept extra keyword arguments
+ t = self.theclass(second=1)
+ self.assertRaises(TypeError, t.isoformat, foo=3)
+
def test_strftime(self):
t = self.theclass(1, 2, 3, 4)
self.assertEqual(t.strftime('%H %M %S'), "01 02 03")
diff --git a/Lib/test/test_defaultdict.py b/Lib/test/test_defaultdict.py
index 03900de..c8ae2be 100644
--- a/Lib/test/test_defaultdict.py
+++ b/Lib/test/test_defaultdict.py
@@ -47,6 +47,7 @@
self.assertEqual(err.args, (15,))
else:
self.fail("d2[15] didn't raise KeyError")
+ self.assertRaises(TypeError, defaultdict, 1)
def test_missing(self):
d1 = defaultdict()
@@ -60,10 +61,10 @@
self.assertEqual(repr(d1), "defaultdict(None, {})")
d1[11] = 41
self.assertEqual(repr(d1), "defaultdict(None, {11: 41})")
- d2 = defaultdict(0)
- self.assertEqual(d2.default_factory, 0)
+ d2 = defaultdict(int)
+ self.assertEqual(d2.default_factory, int)
d2[12] = 42
- self.assertEqual(repr(d2), "defaultdict(0, {12: 42})")
+ self.assertEqual(repr(d2), "defaultdict(<type 'int'>, {12: 42})")
def foo(): return 43
d3 = defaultdict(foo)
self.assert_(d3.default_factory is foo)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index d369cf6..e8db29e 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -2093,7 +2093,7 @@
__slots__ = ['prec']
def __init__(self, value=0.0, prec=12):
self.prec = int(prec)
- float.__init__(value)
+ float.__init__(self, value)
def __repr__(self):
return "%.*g" % (self.prec, self)
vereq(repr(precfloat(1.1)), "1.1")
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index fb4483a..679181f 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -182,6 +182,14 @@
self.assertRaises(ValueError, {}.update, [(1, 2, 3)])
+ # SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses
+ class KeyUpperDict(dict):
+ def __getitem__(self, key):
+ return key.upper()
+ d.clear()
+ d.update(KeyUpperDict.fromkeys('abc'))
+ self.assertEqual(d, {'a':'A', 'b':'B', 'c':'C'})
+
def test_fromkeys(self):
self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None})
d = {}
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index fbdbc30..124a469 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -153,6 +153,13 @@
self.assertEqual(f.myfileobj.mode, 'rb')
f.close()
+ def test_1647484(self):
+ for mode in ('wb', 'rb'):
+ f = gzip.GzipFile(self.filename, mode)
+ self.assert_(hasattr(f, "name"))
+ self.assertEqual(f.name, self.filename)
+ f.close()
+
def test_main(verbose=None):
test_support.run_unittest(TestGzip)
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py
index 934f7b6..156c835 100644
--- a/Lib/test/test_heapq.py
+++ b/Lib/test/test_heapq.py
@@ -1,6 +1,6 @@
"""Unittests for heapq."""
-from heapq import heappush, heappop, heapify, heapreplace, nlargest, nsmallest
+from heapq import heappush, heappop, heapify, heapreplace, merge, nlargest, nsmallest
import random
import unittest
from test import test_support
@@ -103,6 +103,29 @@
heap_sorted = [heappop(heap) for i in range(size)]
self.assertEqual(heap_sorted, sorted(data))
+ def test_merge(self):
+ inputs = []
+ for i in xrange(random.randrange(5)):
+ row = sorted(random.randrange(1000) for j in range(random.randrange(10)))
+ inputs.append(row)
+ self.assertEqual(sorted(chain(*inputs)), list(merge(*inputs)))
+ self.assertEqual(list(merge()), [])
+
+ def test_merge_stability(self):
+ class Int(int):
+ pass
+ inputs = [[], [], [], []]
+ for i in range(20000):
+ stream = random.randrange(4)
+ x = random.randrange(500)
+ obj = Int(x)
+ obj.pair = (x, stream)
+ inputs[stream].append(obj)
+ for stream in inputs:
+ stream.sort()
+ result = [i.pair for i in merge(*inputs)]
+ self.assertEqual(result, sorted(result))
+
def test_nsmallest(self):
data = [(random.randrange(2000), i) for i in range(1000)]
for f in (None, lambda x: x[0] * 547 % 2000):
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index ac30495..bbebbd9 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -55,8 +55,7 @@
self.assertEqual(take(2, lzip('abc',count(3))), [('a', 3), ('b', 4)])
self.assertRaises(TypeError, count, 2, 3)
self.assertRaises(TypeError, count, 'a')
- c = count(sys.maxint-2) # verify that rollover doesn't crash
- c.next(); c.next(); c.next(); c.next(); c.next()
+ self.assertRaises(OverflowError, list, islice(count(sys.maxint-5), 10))
c = count(3)
self.assertEqual(repr(c), 'count(3)')
c.next()
@@ -203,6 +202,51 @@
ids = map(id, list(izip('abc', 'def')))
self.assertEqual(len(dict.fromkeys(ids)), len(ids))
+ def test_iziplongest(self):
+ for args in [
+ ['abc', range(6)],
+ [range(6), 'abc'],
+ [range(1000), range(2000,2100), range(3000,3050)],
+ [range(1000), range(0), range(3000,3050), range(1200), range(1500)],
+ [range(1000), range(0), range(3000,3050), range(1200), range(1500), range(0)],
+ ]:
+ target = map(None, *args)
+ self.assertEqual(list(izip_longest(*args)), target)
+ self.assertEqual(list(izip_longest(*args, **{})), target)
+ target = [tuple((e is None and 'X' or e) for e in t) for t in target] # Replace None fills with 'X'
+ self.assertEqual(list(izip_longest(*args, **dict(fillvalue='X'))), target)
+
+ self.assertEqual(take(3,izip_longest('abcdef', count())), list(zip('abcdef', range(3)))) # take 3 from infinite input
+
+ self.assertEqual(list(izip_longest()), list(zip()))
+ self.assertEqual(list(izip_longest([])), list(zip([])))
+ self.assertEqual(list(izip_longest('abcdef')), list(zip('abcdef')))
+
+ self.assertEqual(list(izip_longest('abc', 'defg', **{})), map(None, 'abc', 'defg')) # empty keyword dict
+ self.assertRaises(TypeError, izip_longest, 3)
+ self.assertRaises(TypeError, izip_longest, range(3), 3)
+
+ for stmt in [
+ "izip_longest('abc', fv=1)",
+ "izip_longest('abc', fillvalue=1, bogus_keyword=None)",
+ ]:
+ try:
+ eval(stmt, globals(), locals())
+ except TypeError:
+ pass
+ else:
+ self.fail('Did not raise Type in: ' + stmt)
+
+ # Check tuple re-use (implementation detail)
+ self.assertEqual([tuple(list(pair)) for pair in izip_longest('abc', 'def')],
+ list(zip('abc', 'def')))
+ self.assertEqual([pair for pair in izip_longest('abc', 'def')],
+ list(zip('abc', 'def')))
+ ids = map(id, izip_longest('abc', 'def'))
+ self.assertEqual(min(ids), max(ids))
+ ids = map(id, list(izip_longest('abc', 'def')))
+ self.assertEqual(len(dict.fromkeys(ids)), len(ids))
+
def test_repeat(self):
self.assertEqual(lzip(xrange(3),repeat('a')),
[(0, 'a'), (1, 'a'), (2, 'a')])
@@ -616,6 +660,15 @@
self.assertRaises(TypeError, izip, N(s))
self.assertRaises(ZeroDivisionError, list, izip(E(s)))
+ def test_iziplongest(self):
+ for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)):
+ for g in (G, I, Ig, S, L, R):
+ self.assertEqual(list(izip_longest(g(s))), list(zip(g(s))))
+ self.assertEqual(list(izip_longest(g(s), g(s))), list(zip(g(s), g(s))))
+ self.assertRaises(TypeError, izip_longest, X(s))
+ self.assertRaises(TypeError, izip_longest, N(s))
+ self.assertRaises(ZeroDivisionError, list, izip_longest(E(s)))
+
def test_imap(self):
for s in (range(10), range(0), range(100), (7,11), xrange(20,50,5)):
for g in (G, I, Ig, S, L, R):
diff --git a/Lib/test/test_operator.py b/Lib/test/test_operator.py
index 2183508..e05d054 100644
--- a/Lib/test/test_operator.py
+++ b/Lib/test/test_operator.py
@@ -210,6 +210,8 @@
self.failUnless(operator.isSequenceType(xrange(10)))
self.failUnless(operator.isSequenceType('yeahbuddy'))
self.failIf(operator.isSequenceType(3))
+ class Dict(dict): pass
+ self.failIf(operator.isSequenceType(Dict()))
def test_lshift(self):
self.failUnlessRaises(TypeError, operator.lshift)
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index f98c723..7207de5 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -192,6 +192,18 @@
posix.utime(test_support.TESTFN, (int(now), int(now)))
posix.utime(test_support.TESTFN, (now, now))
+ def test_chflags(self):
+ if hasattr(posix, 'chflags'):
+ st = os.stat(test_support.TESTFN)
+ if hasattr(st, 'st_flags'):
+ posix.chflags(test_support.TESTFN, st.st_flags)
+
+ def test_lchflags(self):
+ if hasattr(posix, 'lchflags'):
+ st = os.stat(test_support.TESTFN)
+ if hasattr(st, 'st_flags'):
+ posix.lchflags(test_support.TESTFN, st.st_flags)
+
def test_main():
test_support.run_unittest(PosixTester)
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
index fbe742d..5b071dd 100644
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -216,7 +216,44 @@
('<ns1:doc xmlns:ns1="%s"><udoc></udoc></ns1:doc>' %
ns_uri)
-# ===== XMLFilterBase
+def test_1463026_1():
+ result = StringIO()
+ gen = XMLGenerator(result)
+
+ gen.startDocument()
+ gen.startElementNS((None, 'a'), 'a', {(None, 'b'):'c'})
+ gen.endElementNS((None, 'a'), 'a')
+ gen.endDocument()
+
+ return result.getvalue() == start+'<a b="c"></a>'
+
+def test_1463026_2():
+ result = StringIO()
+ gen = XMLGenerator(result)
+
+ gen.startDocument()
+ gen.startPrefixMapping(None, 'qux')
+ gen.startElementNS(('qux', 'a'), 'a', {})
+ gen.endElementNS(('qux', 'a'), 'a')
+ gen.endPrefixMapping(None)
+ gen.endDocument()
+
+ return result.getvalue() == start+'<a xmlns="qux"></a>'
+
+def test_1463026_3():
+ result = StringIO()
+ gen = XMLGenerator(result)
+
+ gen.startDocument()
+ gen.startPrefixMapping('my', 'qux')
+ gen.startElementNS(('qux', 'a'), 'a', {(None, 'b'):'c'})
+ gen.endElementNS(('qux', 'a'), 'a')
+ gen.endPrefixMapping('my')
+ gen.endDocument()
+
+ return result.getvalue() == start+'<my:a xmlns:my="qux" b="c"></my:a>'
+
+# ===== Xmlfilterbase
def test_filter_basic():
result = StringIO()
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 2a791e4..8a43109 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -26,6 +26,14 @@
def __repr__(self):
return repr(self.value)
+class HashCountingInt(int):
+ 'int-like object that counts the number of times __hash__ is called'
+ def __init__(self, *args):
+ self.hash_count = 0
+ def __hash__(self):
+ self.hash_count += 1
+ return int.__hash__(self)
+
class TestJointOps(unittest.TestCase):
# Tests common to both set and frozenset
@@ -273,6 +281,18 @@
fo.close()
os.remove(test_support.TESTFN)
+ def test_do_not_rehash_dict_keys(self):
+ n = 10
+ d = dict.fromkeys(map(HashCountingInt, xrange(n)))
+ self.assertEqual(sum(elem.hash_count for elem in d), n)
+ s = self.thetype(d)
+ self.assertEqual(sum(elem.hash_count for elem in d), n)
+ s.difference(d)
+ self.assertEqual(sum(elem.hash_count for elem in d), n)
+ if hasattr(s, 'symmetric_difference_update'):
+ s.symmetric_difference_update(d)
+ self.assertEqual(sum(elem.hash_count for elem in d), n)
+
class TestSet(TestJointOps):
thetype = set
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 9ae913d..e9bf497 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -305,6 +305,61 @@
self.assertEqual(self.dst.getnames(), [], "added the archive to itself")
+class AppendTest(unittest.TestCase):
+ # Test append mode (cp. patch #1652681).
+
+ def setUp(self):
+ self.tarname = tmpname()
+ if os.path.exists(self.tarname):
+ os.remove(self.tarname)
+
+ def _add_testfile(self, fileobj=None):
+ tar = tarfile.open(self.tarname, "a", fileobj=fileobj)
+ tar.addfile(tarfile.TarInfo("bar"))
+ tar.close()
+
+ def _create_testtar(self):
+ src = tarfile.open(tarname())
+ t = src.getmember("0-REGTYPE")
+ t.name = "foo"
+ f = src.extractfile(t)
+ tar = tarfile.open(self.tarname, "w")
+ tar.addfile(t, f)
+ tar.close()
+
+ def _test(self, names=["bar"], fileobj=None):
+ tar = tarfile.open(self.tarname, fileobj=fileobj)
+ self.assert_(tar.getnames() == names)
+
+ def test_non_existing(self):
+ self._add_testfile()
+ self._test()
+
+ def test_empty(self):
+ open(self.tarname, "wb").close()
+ self._add_testfile()
+ self._test()
+
+ def test_empty_fileobj(self):
+ fobj = StringIO.StringIO()
+ self._add_testfile(fobj)
+ fobj.seek(0)
+ self._test(fileobj=fobj)
+
+ def test_fileobj(self):
+ self._create_testtar()
+ data = open(self.tarname, "rb").read()
+ fobj = StringIO.StringIO(data)
+ self._add_testfile(fobj)
+ fobj.seek(0)
+ self._test(names=["foo", "bar"], fileobj=fobj)
+
+ def test_existing(self):
+ self._create_testtar()
+ self._add_testfile()
+ self._test(names=["foo", "bar"])
+
+
class Write100Test(BaseTest):
# The name field in a tar header stores strings of at most 100 chars.
# If a string is shorter than 100 chars it has to be padded with '\0',
@@ -711,6 +766,7 @@
ReadAsteriskTest,
ReadStreamAsteriskTest,
WriteTest,
+ AppendTest,
Write100Test,
WriteSize0Test,
WriteStreamTest,
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index 56c4939..d6f5534 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -307,6 +307,28 @@
class OtherTests(unittest.TestCase):
+ def testCreateNonExistentFileForAppend(self):
+ if os.path.exists(TESTFN):
+ os.unlink(TESTFN)
+
+ filename = 'testfile.txt'
+ content = 'hello, world. this is some content.'
+
+ try:
+ zf = zipfile.ZipFile(TESTFN, 'a')
+ zf.writestr(filename, content)
+ zf.close()
+ except IOError:
+ self.fail('Could not append data to a non-existent zip file.')
+
+ self.assert_(os.path.exists(TESTFN))
+
+ zf = zipfile.ZipFile(TESTFN, 'r')
+ self.assertEqual(zf.read(filename), content)
+ zf.close()
+
+ os.unlink(TESTFN)
+
def testCloseErroneousFile(self):
# This test checks that the ZipFile constructor closes the file object
# it opens if there's an error in the file. If it doesn't, the traceback
@@ -349,8 +371,49 @@
# and report that the first file in the archive was corrupt.
self.assertRaises(RuntimeError, zipf.testzip)
+
+class DecryptionTests(unittest.TestCase):
+ # This test checks that ZIP decryption works. Since the library does not
+ # support encryption at the moment, we use a pre-generated encrypted
+ # ZIP file
+
+ data = (
+ 'PK\x03\x04\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00\x1a\x00'
+ '\x00\x00\x08\x00\x00\x00test.txt\xfa\x10\xa0gly|\xfa-\xc5\xc0=\xf9y'
+ '\x18\xe0\xa8r\xb3Z}Lg\xbc\xae\xf9|\x9b\x19\xe4\x8b\xba\xbb)\x8c\xb0\xdbl'
+ 'PK\x01\x02\x14\x00\x14\x00\x01\x00\x00\x00n\x92i.#y\xef?&\x00\x00\x00'
+ '\x1a\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00\x01\x00 \x00\xb6\x81'
+ '\x00\x00\x00\x00test.txtPK\x05\x06\x00\x00\x00\x00\x01\x00\x01\x006\x00'
+ '\x00\x00L\x00\x00\x00\x00\x00' )
+
+ plain = 'zipfile.py encryption test'
+
+ def setUp(self):
+ fp = open(TESTFN, "wb")
+ fp.write(self.data)
+ fp.close()
+ self.zip = zipfile.ZipFile(TESTFN, "r")
+
+ def tearDown(self):
+ self.zip.close()
+ os.unlink(TESTFN)
+
+ def testNoPassword(self):
+ # Reading the encrypted file without password
+ # must generate a RunTime exception
+ self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+
+ def testBadPassword(self):
+ self.zip.setpassword("perl")
+ self.assertRaises(RuntimeError, self.zip.read, "test.txt")
+
+ def testGoodPassword(self):
+ self.zip.setpassword("python")
+ self.assertEquals(self.zip.read("test.txt"), self.plain)
+
def test_main():
- run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests, PyZipFileTests)
+ run_unittest(TestsWithSourceFile, TestZip64InSmallFiles, OtherTests,
+ PyZipFileTests, DecryptionTests)
#run_unittest(TestZip64InSmallFiles)
if __name__ == "__main__":