Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c28e1fa

Browse files
committed
Merged revisions 64002-64003,64012,64036-64037,64047,64050-64052,64054-64055,64066,64071 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r64002 | travis.oliphant | 2008-06-07 00:33:21 +0200 (Sat, 07 Jun 2008) | 1 line Add long double check support to configure test. ........ r64003 | travis.oliphant | 2008-06-07 00:39:47 +0200 (Sat, 07 Jun 2008) | 1 line Remove locking part of new buffer protocol. ........ r64012 | facundo.batista | 2008-06-07 15:36:36 +0200 (Sat, 07 Jun 2008) | 4 lines Finished bug #2451. Fixed the retrying part to make it more robust. ........ r64036 | georg.brandl | 2008-06-08 10:54:40 +0200 (Sun, 08 Jun 2008) | 2 lines #3028: tokenize passes the physical line. ........ r64037 | georg.brandl | 2008-06-08 10:59:38 +0200 (Sun, 08 Jun 2008) | 2 lines Argh, I read it wrong. Reverted 64036 and added a clarifying remark. ........ r64047 | raymond.hettinger | 2008-06-09 03:28:30 +0200 (Mon, 09 Jun 2008) | 1 line Issue3065: Fixed pickling of named tuples. Added tests. ........ r64050 | raymond.hettinger | 2008-06-09 08:54:45 +0200 (Mon, 09 Jun 2008) | 1 line Issue #2138: Add math.factorial(). ........ r64051 | raymond.hettinger | 2008-06-09 10:33:37 +0200 (Mon, 09 Jun 2008) | 1 line Let set.union() and set.update() accept multiple inputs. ........ r64052 | raymond.hettinger | 2008-06-09 11:29:17 +0200 (Mon, 09 Jun 2008) | 1 line Address double-rounding scenarios by setting all variables to long doubles. ........ r64054 | raymond.hettinger | 2008-06-09 13:24:47 +0200 (Mon, 09 Jun 2008) | 1 line Unhappy buildbots. Revert 64052. Long doubles have unexpected effects on some builds. ........ r64055 | raymond.hettinger | 2008-06-09 15:07:27 +0200 (Mon, 09 Jun 2008) | 1 line Let set.intersection() and set.intersection_update() take multiple input arguments. ........ r64066 | robert.schuppenies | 2008-06-10 12:10:31 +0200 (Tue, 10 Jun 2008) | 2 lines Issue 3048: Fixed sys.getsizeof for unicode objects. ........ r64071 | thomas.heller | 2008-06-10 16:07:12 +0200 (Tue, 10 Jun 2008) | 3 lines NEWS entry for: Add an optional 'offset' parameter to byref, defaulting to zero. ........
1 parent e932c5c commit c28e1fa

13 files changed

Lines changed: 269 additions & 49 deletions

Doc/library/collections.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ Example:
519519
if kwds:
520520
raise ValueError('Got unexpected field names: %r' % kwds.keys())
521521
return result
522+
<BLANKLINE>
523+
def __getnewargs__(self):
524+
return tuple(self)
522525
<BLANKLINE>
523526
x = property(itemgetter(0))
524527
y = property(itemgetter(1))

Doc/library/math.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ Number-theoretic and representation functions:
4141

4242
Return the absolute value of *x*.
4343

44+
.. function:: factorial(x)
45+
46+
Return *x* factorial. Raises :exc:`ValueError` if *x* is not intergral or
47+
is negative.
4448

4549
.. function:: floor(x)
4650

Doc/library/stdtypes.rst

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,16 +1501,22 @@ The constructors for both classes work the same:
15011501
Test whether the set is a true superset of *other*, that is, ``set >=
15021502
other and set != other``.
15031503

1504-
.. method:: union(other)
1505-
set | other
1504+
.. method:: union(other, ...)
1505+
set | other | ...
15061506

15071507
Return a new set with elements from both sets.
15081508

1509-
.. method:: intersection(other)
1510-
set & other
1509+
.. versionchanged:: 2.6
1510+
Accepts multiple input iterables.
1511+
1512+
.. method:: intersection(other, ...)
1513+
set & other & ...
15111514

15121515
Return a new set with elements common to both sets.
15131516

1517+
.. versionchanged:: 2.6
1518+
Accepts multiple input iterables.
1519+
15141520
.. method:: difference(other)
15151521
set - other
15161522

@@ -1562,16 +1568,22 @@ The constructors for both classes work the same:
15621568
The following table lists operations available for :class:`set` that do not
15631569
apply to immutable instances of :class:`frozenset`:
15641570

1565-
.. method:: update(other)
1566-
set |= other
1571+
.. method:: update(other, ...)
1572+
set |= other | ...
15671573

15681574
Update the set, adding elements from *other*.
15691575

1570-
.. method:: intersection_update(other)
1571-
set &= other
1576+
.. versionchanged:: 2.6
1577+
Accepts multiple input iterables.
1578+
1579+
.. method:: intersection_update(other, ...)
1580+
set &= other & ...
15721581

15731582
Update the set, keeping only elements found in it and *other*.
15741583

1584+
.. versionchanged:: 2.6
1585+
Accepts multiple input iterables.
1586+
15751587
.. method:: difference_update(other)
15761588
set -= other
15771589

Doc/library/tokenize.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
:mod:`tokenize` --- Tokenizer for Python source
32
===============================================
43

@@ -15,7 +14,6 @@ colorizers for on-screen displays.
1514

1615
The primary entry point is a :term:`generator`:
1716

18-
1917
.. function:: tokenize(readline)
2018

2119
The :func:`tokenize` generator requires one argument, *readline*, which
@@ -28,11 +26,11 @@ The primary entry point is a :term:`generator`:
2826
token string; a 2-tuple ``(srow, scol)`` of ints specifying the row and
2927
column where the token begins in the source; a 2-tuple ``(erow, ecol)`` of
3028
ints specifying the row and column where the token ends in the source; and
31-
the line on which the token was found. The line passed is the *logical*
32-
line; continuation lines are included.
29+
the line on which the token was found. The line passed (the last tuple item)
30+
is the *logical* line; continuation lines are included.
3331

34-
tokenize determines the source encoding of the file by looking for a utf-8
35-
bom or encoding cookie, according to :pep:`263`.
32+
:func:`tokenize` determines the source encoding of the file by looking for a
33+
UTF-8 BOM or encoding cookie, according to :pep:`263`.
3634

3735

3836
All constants from the :mod:`token` module are also exported from

Lib/collections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ def _replace(self, **kwds):
8787
result = self._make(map(kwds.pop, %(field_names)r, self))
8888
if kwds:
8989
raise ValueError('Got unexpected field names: %%r' %% kwds.keys())
90-
return result \n\n''' % locals()
90+
return result \n
91+
def __getnewargs__(self):
92+
return tuple(self) \n\n''' % locals()
9193
for i, name in enumerate(field_names):
9294
template += ' %s = property(itemgetter(%d))\n' % (name, i)
9395
if verbose:

Lib/test/test_collections.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import unittest, doctest
44
from test import support
55
from collections import namedtuple
6+
import pickle, copy
67
from collections import Hashable, Iterable, Iterator
78
from collections import Sized, Container, Callable
89
from collections import Set, MutableSet
910
from collections import Mapping, MutableMapping
1011
from collections import Sequence, MutableSequence
1112
from collections import ByteString
1213

14+
TestNT = namedtuple('TestNT', 'x y z') # type used for pickle tests
1315

1416
class TestNamedTuple(unittest.TestCase):
1517

@@ -111,7 +113,7 @@ def test_odd_sizes(self):
111113
self.assertEqual(Dot(1)._replace(d=999), (999,))
112114
self.assertEqual(Dot(1)._fields, ('d',))
113115

114-
# n = 10000
116+
# n = 5000
115117
n = 254 # SyntaxError: more than 255 arguments:
116118
import string, random
117119
names = list(set(''.join([random.choice(string.ascii_letters)
@@ -134,6 +136,23 @@ def test_odd_sizes(self):
134136
self.assertEqual(b2, tuple(b2_expected))
135137
self.assertEqual(b._fields, tuple(names))
136138

139+
def test_pickle(self):
140+
p = TestNT(x=10, y=20, z=30)
141+
for module in (pickle,):
142+
loads = getattr(module, 'loads')
143+
dumps = getattr(module, 'dumps')
144+
for protocol in -1, 0, 1, 2:
145+
q = loads(dumps(p, protocol))
146+
self.assertEqual(p, q)
147+
self.assertEqual(p._fields, q._fields)
148+
149+
def test_copy(self):
150+
p = TestNT(x=10, y=20, z=30)
151+
for copier in copy.copy, copy.deepcopy:
152+
q = copier(p)
153+
self.assertEqual(p, q)
154+
self.assertEqual(p._fields, q._fields)
155+
137156
class TestOneTrickPonyABCs(unittest.TestCase):
138157

139158
def test_Hashable(self):

Lib/test/test_math.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import math
77
import os
88
import sys
9+
import random
910

1011
eps = 1E-05
1112
NAN = float('nan')
@@ -274,6 +275,20 @@ def testFabs(self):
274275
self.ftest('fabs(0)', math.fabs(0), 0)
275276
self.ftest('fabs(1)', math.fabs(1), 1)
276277

278+
def testFactorial(self):
279+
def fact(n):
280+
result = 1
281+
for i in range(1, int(n)+1):
282+
result *= i
283+
return result
284+
values = list(range(10)) + [50, 100, 500]
285+
random.shuffle(values)
286+
for x in range(10):
287+
for cast in (int, float):
288+
self.assertEqual(math.factorial(cast(x)), fact(x), (x, fact(x), math.factorial(x)))
289+
self.assertRaises(ValueError, math.factorial, -1)
290+
self.assertRaises(ValueError, math.factorial, math.pi)
291+
277292
def testFloor(self):
278293
self.assertRaises(TypeError, math.floor)
279294
self.assertEquals(int, type(math.floor(0.5)))

Lib/test/test_set.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def test_union(self):
7979
self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg'))
8080
self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc'))
8181
self.assertEqual(self.thetype('abcba').union(C('ef')), set('abcef'))
82+
self.assertEqual(self.thetype('abcba').union(C('ef'), C('fg')), set('abcefg'))
8283

8384
def test_or(self):
8485
i = self.s.union(self.otherword)
@@ -103,6 +104,7 @@ def test_intersection(self):
103104
self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set(''))
104105
self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc'))
105106
self.assertEqual(self.thetype('abcba').intersection(C('ef')), set(''))
107+
self.assertEqual(self.thetype('abcba').intersection(C('cbcf'), C('bag')), set('b'))
106108

107109
def test_isdisjoint(self):
108110
def f(s1, s2):
@@ -410,6 +412,12 @@ def test_update(self):
410412
s = self.thetype('abcba')
411413
self.assertEqual(s.update(C(p)), None)
412414
self.assertEqual(s, set(q))
415+
for p in ('cdc', 'efgfe', 'ccb', 'ef', 'abcda'):
416+
q = 'ahi'
417+
for C in set, frozenset, dict.fromkeys, str, list, tuple:
418+
s = self.thetype('abcba')
419+
self.assertEqual(s.update(C(p), C(q)), None)
420+
self.assertEqual(s, set(s) | set(p) | set(q))
413421

414422
def test_ior(self):
415423
self.s |= set(self.otherword)
@@ -431,6 +439,11 @@ def test_intersection_update(self):
431439
s = self.thetype('abcba')
432440
self.assertEqual(s.intersection_update(C(p)), None)
433441
self.assertEqual(s, set(q))
442+
ss = 'abcba'
443+
s = self.thetype(ss)
444+
t = 'cbc'
445+
self.assertEqual(s.intersection_update(C(p), C(t)), None)
446+
self.assertEqual(s, set('abcba')&set(p)&set(t))
434447

435448
def test_iand(self):
436449
self.s &= set(self.otherword)

Lib/test/test_sys.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,14 @@ def tearDown(self):
386386
self.file.close()
387387
test.support.unlink(test.support.TESTFN)
388388

389-
def check_sizeof(self, o, size):
389+
def check_sizeof(self, o, size, size2=None):
390+
"""Check size of o. Possible are size and optionally size2)."""
390391
result = sys.getsizeof(o)
391-
msg = 'wrong size for %s: got %d, expected %d' \
392-
% (type(o), result, size)
393-
self.assertEqual(result, size, msg)
392+
msg = 'wrong size for %s: got %d, expected ' % (type(o), result)
393+
if (size2 != None) and (result != size):
394+
self.assertEqual(result, size2, msg + str(size2))
395+
else:
396+
self.assertEqual(result, size, msg + str(size))
394397

395398
def align(self, value):
396399
mod = value % self.p
@@ -486,6 +489,24 @@ def test_specialtypes(self):
486489
# list
487490
self.check_sizeof([], h + l + p + l)
488491
self.check_sizeof([1, 2, 3], h + l + p + l + 3*l)
492+
# unicode
493+
import math
494+
usize = math.log(sys.maxunicode + 1, 2) / 8
495+
samples = ['', '1'*100]
496+
# we need to test for both sizes, because we don't know if the string
497+
# has been cached
498+
for s in samples:
499+
basicsize = h + l + p + l + l + p + usize * (len(s) + 1)
500+
defenc = bytes(s, 'ascii')
501+
self.check_sizeof(s, basicsize,
502+
size2=basicsize + sys.getsizeof(defenc))
503+
# trigger caching encoded version as bytes object
504+
try:
505+
getattr(sys, s)
506+
except AttributeError:
507+
pass
508+
finally:
509+
self.check_sizeof(s, basicsize + sys.getsizeof(defenc))
489510

490511
h += l
491512
# long
@@ -495,9 +516,6 @@ def test_specialtypes(self):
495516
self.check_sizeof(32768, h + self.align(2) + 2)
496517
self.check_sizeof(32768*32768-1, h + self.align(2) + 2)
497518
self.check_sizeof(32768*32768, h + self.align(2) + 4)
498-
# XXX add Unicode support
499-
# self.check_sizeof('', h + l + self.align(i + 1))
500-
# self.check_sizeof('abc', h + l + self.align(i + 1) + 3)
501519

502520

503521
def test_main():

Lib/test/test_urllib2net.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,25 @@
1111
import mimetools
1212

1313

14-
def _urlopen_with_retry(host, *args, **kwargs):
15-
# Connecting to remote hosts is flaky. Make it more robust
16-
# by retrying the connection several times.
14+
def _retry_thrice(func, exc, *args, **kwargs):
1715
for i in range(3):
1816
try:
19-
return urllib2.urlopen(host, *args, **kwargs)
20-
except urllib2.URLError as e:
17+
return func(*args, **kwargs)
18+
except exc as e:
2119
last_exc = e
2220
continue
2321
except:
2422
raise
2523
raise last_exc
2624

25+
def _wrap_with_retry_thrice(func, exc):
26+
def wrapped(*args, **kwargs):
27+
return _retry_thrice(func, exc, *args, **kwargs)
28+
return wrapped
29+
30+
# Connecting to remote hosts is flaky. Make it more robust by retrying
31+
# the connection several times.
32+
_urlopen_with_retry = _wrap_with_retry_thrice(urllib2.urlopen, urllib2.URLError)
2733

2834

2935
class AuthTests(unittest.TestCase):
@@ -114,7 +120,7 @@ def test_file(self):
114120
'file:'+sanepathname2url(os.path.abspath(TESTFN)),
115121
('file:///nonsensename/etc/passwd', None, urllib2.URLError),
116122
]
117-
self._test_urls(urls, self._extra_handlers(), urllib2.urlopen)
123+
self._test_urls(urls, self._extra_handlers(), retry=True)
118124
finally:
119125
os.remove(TESTFN)
120126

@@ -146,13 +152,15 @@ def test_file(self):
146152

147153
## self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
148154

149-
def _test_urls(self, urls, handlers, urlopen=_urlopen_with_retry):
155+
def _test_urls(self, urls, handlers, retry=True):
150156
import socket
151157
import time
152158
import logging
153159
debug = logging.getLogger("test_urllib2").debug
154160

155-
urllib2.install_opener(urllib2.build_opener(*handlers))
161+
urlopen = urllib2.build_opener(*handlers).open
162+
if retry:
163+
urlopen = _wrap_with_retry_thrice(urlopen, urllib2.URLError)
156164

157165
for url in urls:
158166
if isinstance(url, tuple):

0 commit comments

Comments
 (0)