Skip to content

Commit 1af737c

Browse files
committed
Merged revisions 60176-60209 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60178 | georg.brandl | 2008-01-21 22:05:49 +0100 (Mon, 21 Jan 2008) | 2 lines python#1715: include sub-extension modules in pydoc text output. ........ r60179 | georg.brandl | 2008-01-21 22:14:21 +0100 (Mon, 21 Jan 2008) | 2 lines Add a "const" to make gcc happy. ........ r60180 | georg.brandl | 2008-01-21 22:19:07 +0100 (Mon, 21 Jan 2008) | 2 lines Add the correct build dir when building with pydebug. ........ r60181 | georg.brandl | 2008-01-21 22:23:15 +0100 (Mon, 21 Jan 2008) | 3 lines Patch #1720595: add T_BOOL to the range of structmember types. Patch by Angelo Mottola, reviewed by MvL, tests by me. ........ r60182 | georg.brandl | 2008-01-21 22:28:32 +0100 (Mon, 21 Jan 2008) | 2 lines Reformat some ugly code. ........ r60187 | brett.cannon | 2008-01-22 00:50:16 +0100 (Tue, 22 Jan 2008) | 4 lines Make's MAKEFLAGS variable is set to a string containing the single-letter arguments to Make. This means there are no hyphens. Fix the '-s' check to silence distutils to now work. ........ r60188 | gregory.p.smith | 2008-01-22 01:19:41 +0100 (Tue, 22 Jan 2008) | 3 lines accepts and closes issue #1221598: adds an optional callback to ftplib.FTP storbinary() and storlines() methods. ........ r60189 | gregory.p.smith | 2008-01-22 02:12:02 +0100 (Tue, 22 Jan 2008) | 2 lines Replace spam.acquire() try: ... finally: spam.release() with "with spam:" ........ r60190 | gregory.p.smith | 2008-01-22 02:20:42 +0100 (Tue, 22 Jan 2008) | 4 lines - Fix Issue #1703448: A joined thread could show up in the threading.enumerate() list after the join() for a brief period until it actually exited. ........ r60193 | georg.brandl | 2008-01-22 08:53:31 +0100 (Tue, 22 Jan 2008) | 2 lines Fix \xhh specs, python#1889. ........ r60198 | christian.heimes | 2008-01-22 16:01:25 +0100 (Tue, 22 Jan 2008) | 1 line Fixed a missing (X) in define ........ r60199 | christian.heimes | 2008-01-22 16:25:18 +0100 (Tue, 22 Jan 2008) | 2 lines Don't repeat yourself Added the macros PyModule_AddIntMacro and PyModule_AddStringMacro. They shorten PyModule_AddIntConstant(m, "AF_INET", AF_INET) to PyModule_AddIntMacro(m, AF_INET) ........ r60201 | raymond.hettinger | 2008-01-22 20:51:41 +0100 (Tue, 22 Jan 2008) | 1 line Document when to use izip_longest(). ........ r60202 | georg.brandl | 2008-01-22 20:56:03 +0100 (Tue, 22 Jan 2008) | 2 lines Fix for #1087741 patch. ........ r60203 | raymond.hettinger | 2008-01-22 21:18:53 +0100 (Tue, 22 Jan 2008) | 1 line Give zip() the same guarantee as izip() for left-to-right evaluation. ........ r60204 | raymond.hettinger | 2008-01-22 23:09:26 +0100 (Tue, 22 Jan 2008) | 1 line Improve variable name in sample code ........ r60205 | gregory.p.smith | 2008-01-23 00:15:34 +0100 (Wed, 23 Jan 2008) | 2 lines docstring and comment updates suggested by Giampaolo Rodola' ........ r60207 | raymond.hettinger | 2008-01-23 01:04:40 +0100 (Wed, 23 Jan 2008) | 1 line Let pprint() support sets and frozensets (suggested by David Mertz). ........ r60208 | guido.van.rossum | 2008-01-23 02:18:27 +0100 (Wed, 23 Jan 2008) | 4 lines I'm tired of these tests breaking at Google due to our large number of users and groups in LDAP/NIS. So I'm limiting the extra-heavy part of the tests to passwd/group files with at most 1000 entries. ........
1 parent 1dfde1d commit 1af737c

24 files changed

+270
-114
lines changed

Doc/c-api/module.rst

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ There are only a few functions special to module objects.
1818
is exposed to Python programs as ``types.ModuleType``.
1919

2020

21-
.. cfunction:: int PyModule_Check(PyObject *p)
21+
.. cmacro:: int PyModule_Check(PyObject *p)
2222

2323
Return true if *p* is a module object, or a subtype of a module object.
2424

2525

26-
.. cfunction:: int PyModule_CheckExact(PyObject *p)
26+
.. cmacro:: int PyModule_CheckExact(PyObject *p)
2727

2828
Return true if *p* is a module object, but not a subtype of
2929
:cdata:`PyModule_Type`.
@@ -92,3 +92,17 @@ There are only a few functions special to module objects.
9292
Add a string constant to *module* as *name*. This convenience function can be
9393
used from the module's initialization function. The string *value* must be
9494
null-terminated. Return ``-1`` on error, ``0`` on success.
95+
96+
97+
.. cmacro:: int PyModule_AddIntMacro(PyObject *module, macro)
98+
99+
Add an int constant to *module*. The name and the value are taken from
100+
*macro*. For example ``PyModule_AddConstant(module, AF_INET)`` adds the int
101+
constant *AF_INET* with the value of *AF_INET* to *module*.
102+
Return ``-1`` on error, ``0`` on success.
103+
104+
105+
.. cmacro:: int PyModule_AddStringMacro(PyObject *module, macro)
106+
107+
Add a string constant to *module*.
108+

Doc/library/functions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,10 @@ available. They are listed here in alphabetical order.
11401140
sequence argument, it returns an iterator of 1-tuples. With no arguments, it
11411141
returns an empty iterator.
11421142

1143+
The left-to-right evaluation order of the iterables is guaranteed. This
1144+
makes possible an idiom for clustering a data series into n-length groups
1145+
using ``zip(*[iter(s)]*n)``.
1146+
11431147

11441148
.. rubric:: Footnotes
11451149

Doc/library/itertools.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ loops that truncate the stream.
210210
iterables = [iter(it) for it in iterables)
211211
while True:
212212
args = [next(it) for it in iterables]
213-
yield function(*args)
213+
if function is None:
214+
yield tuple(args)
215+
else:
216+
yield function(*args)
214217

215218

216219
.. function:: islice(iterable, [start,] stop [, step])
@@ -252,12 +255,11 @@ loops that truncate the stream.
252255

253256
When no iterables are specified, return a zero length iterator.
254257

255-
Note, the left-to-right evaluation order of the iterables is guaranteed. This
256-
makes possible an idiom for clustering a data series into n-length groups using
257-
``izip(*[iter(s)]*n)``. For data that doesn't fit n-length groups exactly, the
258-
last tuple can be pre-padded with fill values using ``izip(*[chain(s,
259-
[None]*(n-1))]*n)``.
258+
The left-to-right evaluation order of the iterables is guaranteed. This
259+
makes possible an idiom for clustering a data series into n-length groups
260+
using ``izip(*[iter(s)]*n)``.
260261

262+
<<<<<<< .working
261263
Note, when :func:`izip` is used with unequal length inputs, subsequent
262264
iteration over the longer iterables cannot reliably be continued after
263265
:func:`izip` terminates. Potentially, up to one entry will be missing from
@@ -268,6 +270,11 @@ loops that truncate the stream.
268270
the iterator for retrieval with ``next(it)``). In general, :func:`izip`
269271
should only be used with unequal length inputs when you don't care about
270272
trailing, unmatched values from the longer iterables.
273+
=======
274+
:func:`izip` should only be used with unequal length inputs when you don't
275+
care about trailing, unmatched values from the longer iterables. If those
276+
values are important, use :func:`izip_longest` instead.
277+
>>>>>>> .merge-right.r60208
271278

272279

273280
.. function:: izip_longest(*iterables[, fillvalue])

Doc/library/pprint.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ width constraint.
2222

2323
Dictionaries are sorted by key before the display is computed.
2424

25+
.. versionchanged:: 2.6
26+
Added support for :class:`set` and :class:`frozenset`.
27+
2528
The :mod:`pprint` module defines one class:
2629

2730
.. First the implementation class:

Doc/reference/lexical_analysis.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Notes:
502502

503503
(4)
504504
Individual code units which form parts of a surrogate pair can be encoded using
505-
this escape sequence.
505+
this escape sequence. Unlike in Standard C, exactly two hex digits are required.
506506

507507
(5)
508508
Any Unicode character can be encoded this way, but characters outside the Basic

Include/modsupport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);
4040
PyAPI_FUNC(int) PyModule_AddObject(PyObject *, const char *, PyObject *);
4141
PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);
4242
PyAPI_FUNC(int) PyModule_AddStringConstant(PyObject *, const char *, const char *);
43-
43+
#define PyModule_AddIntMacro(m, c) PyModule_AddIntConstant(m, #c, c)
44+
#define PyModule_AddStringMacro(m, c) PyModule_AddStringConstant(m, #c, c)
4445

4546
#define PYTHON_API_VERSION 1013
4647
#define PYTHON_API_STRING "1013"

Include/pyport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ extern "C" {
389389
*/
390390
#ifndef Py_IS_FINITE
391391
#ifdef HAVE_FINITE
392-
#define Py_IS_FINITE(X) finite
392+
#define Py_IS_FINITE(X) finite(X)
393393
#else
394394
#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
395395
#endif

Include/structmember.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ typedef struct PyMemberDef {
5454
/* Added by Jack: strings contained in the structure */
5555
#define T_STRING_INPLACE 13
5656

57+
/* Added by Lillo: bools contained in the structure (assumed char) */
58+
#define T_BOOL 14
59+
5760
#define T_OBJECT_EX 16 /* Like T_OBJECT, but raises AttributeError
5861
when the value is NULL, instead of
5962
converting to None. */

Lib/ftplib.py

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# Changes and improvements suggested by Steve Majewski.
3333
# Modified by Jack to work on the mac.
3434
# Modified by Siebren to support docstrings and PASV.
35+
# Modified by Phil Schwartz to add storbinary and storlines callbacks.
3536
#
3637

3738
import os
@@ -313,7 +314,7 @@ def ntransfercmd(self, cmd, rest=None):
313314
expected size may be None if it could not be determined.
314315
315316
Optional `rest' argument can be a string that is sent as the
316-
argument to a RESTART command. This is essentially a server
317+
argument to a REST command. This is essentially a server
317318
marker used to tell the server to skip over any data up to the
318319
given marker.
319320
"""
@@ -376,14 +377,18 @@ def login(self, user = '', passwd = '', acct = ''):
376377
return resp
377378

378379
def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
379-
"""Retrieve data in binary mode.
380-
381-
`cmd' is a RETR command. `callback' is a callback function is
382-
called for each block. No more than `blocksize' number of
383-
bytes will be read from the socket. Optional `rest' is passed
384-
to transfercmd().
385-
386-
A new port is created for you. Return the response code.
380+
"""Retrieve data in binary mode. A new port is created for you.
381+
382+
Args:
383+
cmd: A RETR command.
384+
callback: A single parameter callable to be called on each
385+
block of data read.
386+
blocksize: The maximum number of bytes to read from the
387+
socket at one time. [default: 8192]
388+
rest: Passed to transfercmd(). [default: None]
389+
390+
Returns:
391+
The response code.
387392
"""
388393
self.voidcmd('TYPE I')
389394
conn = self.transfercmd(cmd, rest)
@@ -396,11 +401,17 @@ def retrbinary(self, cmd, callback, blocksize=8192, rest=None):
396401
return self.voidresp()
397402

398403
def retrlines(self, cmd, callback = None):
399-
'''Retrieve data in line mode.
400-
The argument is a RETR or LIST command.
401-
The callback function (2nd argument) is called for each line,
402-
with trailing CRLF stripped. This creates a new port for you.
403-
print_line() is the default callback.'''
404+
"""Retrieve data in line mode. A new port is created for you.
405+
406+
Args:
407+
cmd: A RETR, LIST, NLST, or MLSD command.
408+
callback: An optional single parameter callable that is called
409+
for each line with the trailing CRLF stripped.
410+
[default: print_line()]
411+
412+
Returns:
413+
The response code.
414+
"""
404415
if callback is None: callback = print_line
405416
resp = self.sendcmd('TYPE A')
406417
conn = self.transfercmd(cmd)
@@ -419,19 +430,42 @@ def retrlines(self, cmd, callback = None):
419430
conn.close()
420431
return self.voidresp()
421432

422-
def storbinary(self, cmd, fp, blocksize=8192):
423-
'''Store a file in binary mode.'''
433+
def storbinary(self, cmd, fp, blocksize=8192, callback=None):
434+
"""Store a file in binary mode. A new port is created for you.
435+
436+
Args:
437+
cmd: A STOR command.
438+
fp: A file-like object with a read(num_bytes) method.
439+
blocksize: The maximum data size to read from fp and send over
440+
the connection at once. [default: 8192]
441+
callback: An optional single parameter callable that is called on
442+
on each block of data after it is sent. [default: None]
443+
444+
Returns:
445+
The response code.
446+
"""
424447
self.voidcmd('TYPE I')
425448
conn = self.transfercmd(cmd)
426449
while 1:
427450
buf = fp.read(blocksize)
428451
if not buf: break
429452
conn.sendall(buf)
453+
if callback: callback(buf)
430454
conn.close()
431455
return self.voidresp()
432456

433-
def storlines(self, cmd, fp):
434-
'''Store a file in line mode.'''
457+
def storlines(self, cmd, fp, callback=None):
458+
"""Store a file in line mode. A new port is created for you.
459+
460+
Args:
461+
cmd: A STOR command.
462+
fp: A file-like object with a readline() method.
463+
callback: An optional single parameter callable that is called on
464+
on each line after it is sent. [default: None]
465+
466+
Returns:
467+
The response code.
468+
"""
435469
self.voidcmd('TYPE A')
436470
conn = self.transfercmd(cmd)
437471
while 1:
@@ -441,6 +475,7 @@ def storlines(self, cmd, fp):
441475
if buf[-1] in CRLF: buf = buf[:-1]
442476
buf = buf + CRLF
443477
conn.sendall(buf)
478+
if callback: callback(buf)
444479
conn.close()
445480
return self.voidresp()
446481

@@ -505,7 +540,7 @@ def cwd(self, dirname):
505540

506541
def size(self, filename):
507542
'''Retrieve the size of a file.'''
508-
# Note that the RFC doesn't say anything about 'SIZE'
543+
# The SIZE command is defined in RFC-3659
509544
resp = self.sendcmd('SIZE ' + filename)
510545
if resp[:3] == '213':
511546
s = resp[3:].strip()

Lib/pprint.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,24 @@ def _format(self, object, stream, indent, allowance, context, level):
159159
write('}')
160160
return
161161

162-
if (issubclass(typ, list) and r is list.__repr__) or \
163-
(issubclass(typ, tuple) and r is tuple.__repr__):
162+
if ((issubclass(typ, list) and r is list.__repr__) or
163+
(issubclass(typ, tuple) and r is tuple.__repr__) or
164+
(issubclass(typ, set) and r is set.__repr__) or
165+
(issubclass(typ, frozenset) and r is frozenset.__repr__)
166+
):
164167
if issubclass(typ, list):
165168
write('[')
166169
endchar = ']'
170+
elif issubclass(typ, set):
171+
write('{')
172+
endchar = '}'
173+
object = sorted(object)
174+
indent += 4
175+
elif issubclass(typ, frozenset):
176+
write('frozenset([')
177+
endchar = '])'
178+
object = sorted(object)
179+
indent += 9
167180
else:
168181
write('(')
169182
endchar = ')'

0 commit comments

Comments
 (0)