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

Skip to content

Commit eca20b6

Browse files
committed
Merged revisions 63119-63128,63130-63131,63133,63135-63144,63146-63148,63151-63152,63155-63165,63167-63176,63181-63186,63188-63189 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r63119 | benjamin.peterson | 2008-05-11 20:41:23 -0400 (Sun, 11 May 2008) | 2 lines #2196 hasattr now allows SystemExit and KeyboardInterrupt to propagate ........ r63122 | benjamin.peterson | 2008-05-11 20:46:49 -0400 (Sun, 11 May 2008) | 2 lines make message slightly more informative, so there's no chance of misunderstanding it ........ r63158 | ronald.oussoren | 2008-05-12 07:24:33 -0400 (Mon, 12 May 2008) | 5 lines Remove references to platform 'mac' The 'mac' platform (that is, os.name == 'mac') was used for the MacOS 9 port, which is no longer supported (as of Python 2.4 IIRC). ........ r63159 | ronald.oussoren | 2008-05-12 07:31:05 -0400 (Mon, 12 May 2008) | 8 lines MacOSX: remove dependency on Carbon package for urllib This patch removes the dependency on the Carbon package from urllib. The mac-specific code for getting proxy configuration is now writting in Python using ctypes and uses the SystemConfiguration framework instead of InternetConfig. Also provides a mac-specific implementation of proxy_bypass. ........ r63162 | eric.smith | 2008-05-12 10:00:01 -0400 (Mon, 12 May 2008) | 1 line Added 'n' presentation type for integers. ........ r63164 | georg.brandl | 2008-05-12 12:26:52 -0400 (Mon, 12 May 2008) | 2 lines #1713041: fix pprint's handling of maximum depth. ........ r63170 | georg.brandl | 2008-05-12 12:53:42 -0400 (Mon, 12 May 2008) | 2 lines Fix parameter name for enumerate(). ........ r63173 | georg.brandl | 2008-05-12 13:01:58 -0400 (Mon, 12 May 2008) | 2 lines #2766: remove code without effect. ........ r63174 | georg.brandl | 2008-05-12 13:04:10 -0400 (Mon, 12 May 2008) | 3 lines #2767: don't clear globs in run() call, since they could be needed in tearDown, which clears them at the end. ........ r63175 | georg.brandl | 2008-05-12 13:14:51 -0400 (Mon, 12 May 2008) | 2 lines #1760: try-except-finally is one statement since PEP 341. ........ r63186 | amaury.forgeotdarc | 2008-05-12 17:30:24 -0400 (Mon, 12 May 2008) | 2 lines Sync code with documentation, and remove Win95 support in winsound module. ........ r63189 | amaury.forgeotdarc | 2008-05-12 18:21:39 -0400 (Mon, 12 May 2008) | 3 lines Adapt test_pyclbr to the new version of urllib.py: The new mac-specific functions must be ignored. ........
1 parent 18bf893 commit eca20b6

16 files changed

Lines changed: 277 additions & 151 deletions

File tree

Doc/library/functions.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,15 @@ are always available. They are listed here in alphabetical order.
325325
< abs(b)``.
326326

327327

328-
.. function:: enumerate(iterable)
329-
330-
Return an enumerate object. *iterable* must be a sequence, an :term:`iterator`, or some
331-
other object which supports iteration. The :meth:`__next__` method of the
332-
iterator returned by :func:`enumerate` returns a tuple containing a count (from
333-
zero) and the corresponding value obtained from iterating over *iterable*.
334-
:func:`enumerate` is useful for obtaining an indexed series: ``(0, seq[0])``,
335-
``(1, seq[1])``, ``(2, seq[2])``, .... For example:
328+
.. function:: enumerate(sequence)
329+
330+
Return an enumerate object. *sequence* must be a sequence, an
331+
:term:`iterator`, or some other object which supports iteration. The
332+
:meth:`__next__` method of the iterator returned by :func:`enumerate` returns a
333+
tuple containing a count (from zero) and the corresponding value obtained
334+
from iterating over *iterable*. :func:`enumerate` is useful for obtaining an
335+
indexed series: ``(0, seq[0])``, ``(1, seq[1])``, ``(2, seq[2])``, .... For
336+
example:
336337

337338
>>> for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter')]:
338339
... print(i, season)

Doc/library/pprint.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ The :mod:`pprint` module defines one class:
6060
... ('parrot', ('fresh fruit',))))))))
6161
>>> pp = pprint.PrettyPrinter(depth=6)
6262
>>> pp.pprint(tup)
63-
('spam',
64-
('eggs', ('lumberjack', ('knights', ('ni', ('dead', ('parrot', (...,))))))))
63+
('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead', (...)))))))
6564

6665
The :class:`PrettyPrinter` class supports several derivative functions:
6766

@@ -208,7 +207,7 @@ This example demonstrates several uses of the :func:`pprint` function and its pa
208207
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
209208
>>> pprint.pprint(stuff, depth=3)
210209
['aaaaaaaaaa',
211-
('spam', ('eggs', ('lumberjack', (...)))),
210+
('spam', ('eggs', (...))),
212211
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
213212
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
214213
>>> pprint.pprint(stuff, width=60)

Doc/reference/executionmodel.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ the code block where the error occurred.
198198
The Python interpreter raises an exception when it detects a run-time error
199199
(such as division by zero). A Python program can also explicitly raise an
200200
exception with the :keyword:`raise` statement. Exception handlers are specified
201-
with the :keyword:`try` ... :keyword:`except` statement. The :keyword:`try` ...
202-
:keyword:`finally` statement specifies cleanup code which does not handle the
203-
exception, but is executed whether an exception occurred or not in the preceding
204-
code.
201+
with the :keyword:`try` ... :keyword:`except` statement. The :keyword:`finally`
202+
clause of such a statement can be used to specify cleanup code which does not
203+
handle the exception, but is executed whether an exception occurred or not in
204+
the preceding code.
205205

206206
.. index:: single: termination model
207207

Doc/whatsnew/2.6.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,9 @@ docs), but here's a sample::
627627
'g' - General format. This prints the number as a fixed-point
628628
number, unless the number is too large, in which case
629629
it switches to 'e' exponent notation.
630-
'n' - Number. This is the same as 'g', except that it uses the
631-
current locale setting to insert the appropriate
632-
number separator characters.
630+
'n' - Number. This is the same as 'g' (for floats) or 'd' (for
631+
integers), except that it uses the current locale setting to
632+
insert the appropriate number separator characters.
633633
'%' - Percentage. Multiplies the number by 100 and displays
634634
in fixed ('f') format, followed by a percent sign.
635635

Lib/doctest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ def debug(self):
21372137
self.setUp()
21382138
runner = DebugRunner(optionflags=self._dt_optionflags,
21392139
checker=self._dt_checker, verbose=False)
2140-
runner.run(self._dt_test)
2140+
runner.run(self._dt_test, clear_globs=False)
21412141
self.tearDown()
21422142

21432143
def id(self):
@@ -2194,8 +2194,6 @@ def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
21942194

21952195
module = _normalize_module(module)
21962196
tests = test_finder.find(module, globs=globs, extraglobs=extraglobs)
2197-
if globs is None:
2198-
globs = module.__dict__
21992197
if not tests:
22002198
# Why do we want to do this? Because it reveals a bug that might
22012199
# otherwise be hidden.

Lib/os.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
r"""OS routines for Mac, NT, or Posix depending on what system we're on.
22
33
This exports:
4-
- all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc.
5-
- os.path is one of the modules posixpath, ntpath, or macpath
6-
- os.name is 'posix', 'nt', 'os2', 'mac' or 'ce'
4+
- all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.
5+
- os.path is either posixpath or ntpath
6+
- os.name is either 'posix', 'nt', 'os2' or 'ce'.
77
- os.curdir is a string representing the current directory ('.' or ':')
88
- os.pardir is a string representing the parent directory ('..' or '::')
99
- os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
@@ -83,20 +83,6 @@ def _get_exports_list(module):
8383
__all__.extend(_get_exports_list(os2))
8484
del os2
8585

86-
elif 'mac' in _names:
87-
name = 'mac'
88-
linesep = '\r'
89-
from mac import *
90-
try:
91-
from mac import _exit
92-
except ImportError:
93-
pass
94-
import macpath as path
95-
96-
import mac
97-
__all__.extend(_get_exports_list(mac))
98-
del mac
99-
10086
elif 'ce' in _names:
10187
name = 'ce'
10288
linesep = '\r\n'

Lib/pprint.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ def _format(self, object, stream, indent, allowance, context, level):
131131
sepLines = _len(rep) > (self._width - 1 - indent - allowance)
132132
write = stream.write
133133

134+
if self._depth and level > self._depth:
135+
write(rep)
136+
return
137+
134138
if sepLines:
135139
r = getattr(typ, "__repr__", None)
136140
if issubclass(typ, dict) and r is dict.__repr__:
@@ -252,7 +256,7 @@ def _safe_repr(object, context, maxlevels, level):
252256
if not object:
253257
return "{}", True, False
254258
objid = _id(object)
255-
if maxlevels and level > maxlevels:
259+
if maxlevels and level >= maxlevels:
256260
return "{...}", False, objid in context
257261
if objid in context:
258262
return _recursion(object), False, True
@@ -294,7 +298,7 @@ def sortkey(item):
294298
return "()", True, False
295299
format = "(%s)"
296300
objid = _id(object)
297-
if maxlevels and level > maxlevels:
301+
if maxlevels and level >= maxlevels:
298302
return format % "...", False, objid in context
299303
if objid in context:
300304
return _recursion(object), False, True

Lib/tempfile.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
import errno as _errno
3535
from random import Random as _Random
3636

37-
if _os.name == 'mac':
38-
import Carbon.Folder as _Folder
39-
import Carbon.Folders as _Folders
40-
4137
try:
4238
import fcntl as _fcntl
4339
except ImportError:
@@ -149,15 +145,7 @@ def _candidate_tempdir_list():
149145
if dirname: dirlist.append(dirname)
150146

151147
# Failing that, try OS-specific locations.
152-
if _os.name == 'mac':
153-
try:
154-
fsr = _Folder.FSFindFolder(_Folders.kOnSystemDisk,
155-
_Folders.kTemporaryFolderType, 1)
156-
dirname = fsr.as_pathname()
157-
dirlist.append(dirname)
158-
except _Folder.error:
159-
pass
160-
elif _os.name == 'nt':
148+
if _os.name == 'nt':
161149
dirlist.extend([ r'c:\temp', r'c:\tmp', r'\temp', r'\tmp' ])
162150
else:
163151
dirlist.extend([ '/tmp', '/var/tmp', '/usr/tmp' ])

Lib/test/test_builtin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,16 @@ def test_hasattr(self):
499499
self.assertRaises(TypeError, hasattr)
500500
self.assertEqual(False, hasattr(sys, chr(sys.maxunicode)))
501501

502+
# Check that hasattr allows SystemExit and KeyboardInterrupts by
503+
class A:
504+
def __getattr__(self, what):
505+
raise KeyboardInterrupt
506+
self.assertRaises(KeyboardInterrupt, hasattr, A(), "b")
507+
class B:
508+
def __getattr__(self, what):
509+
raise SystemExit
510+
self.assertRaises(SystemExit, hasattr, B(), "b")
511+
502512
def test_hash(self):
503513
hash(None)
504514
self.assertEqual(hash(1), hash(1))

Lib/test/test_pprint.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,21 @@ def test_set_reprs(self):
381381
cubo = test.test_set.linegraph(cube)
382382
self.assertEqual(pprint.pformat(cubo), cubo_repr_tgt)
383383

384+
def test_depth(self):
385+
nested_tuple = (1, (2, (3, (4, (5, 6)))))
386+
nested_dict = {1: {2: {3: {4: {5: {6: 6}}}}}}
387+
nested_list = [1, [2, [3, [4, [5, [6, []]]]]]]
388+
self.assertEqual(pprint.pformat(nested_tuple), repr(nested_tuple))
389+
self.assertEqual(pprint.pformat(nested_dict), repr(nested_dict))
390+
self.assertEqual(pprint.pformat(nested_list), repr(nested_list))
391+
392+
lv1_tuple = '(1, (...))'
393+
lv1_dict = '{1: {...}}'
394+
lv1_list = '[1, [...]]'
395+
self.assertEqual(pprint.pformat(nested_tuple, depth=1), lv1_tuple)
396+
self.assertEqual(pprint.pformat(nested_dict, depth=1), lv1_dict)
397+
self.assertEqual(pprint.pformat(nested_list, depth=1), lv1_list)
398+
384399

385400
class DottedPrettyPrinter(pprint.PrettyPrinter):
386401

0 commit comments

Comments
 (0)