Merged revisions 62713,62715,62728,62737,62740,62744,62749,62756 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62713 | georg.brandl | 2008-05-04 23:40:44 +0200 (Sun, 04 May 2008) | 2 lines

  #2695: Do case-insensitive check for algorithms.
........
  r62715 | benjamin.peterson | 2008-05-05 00:39:33 +0200 (Mon, 05 May 2008) | 2 lines

  Remove method signatures from the docstrings of io.py
........
  r62728 | martin.v.loewis | 2008-05-05 19:54:01 +0200 (Mon, 05 May 2008) | 2 lines

  Revert bogus checkin in r62724 to that file.
........
  r62737 | georg.brandl | 2008-05-05 22:59:05 +0200 (Mon, 05 May 2008) | 2 lines

  #2769: markup glitch.
........
  r62740 | georg.brandl | 2008-05-05 23:06:48 +0200 (Mon, 05 May 2008) | 2 lines

  #2752: fix second example too.
........
  r62744 | gregory.p.smith | 2008-05-05 23:53:45 +0200 (Mon, 05 May 2008) | 13 lines

  Fix a bug introduced in r62627.  see issue2760 and issue2632.

  An assertion in readline() would fail as data was already in the
  internal buffer even though the socket was in unbuffered read mode.
  That case is now handled.  More importantly, read() has been fixed to
  not over-recv() and leave newly recv()d data in the _fileobject buffer.

  The max() vs min() issue in read() is now gone.  Neither was correct.
  On bounded reads, always ask recv() for the exact amount of data we
  still need.

  Candidate for backporting to release25-maint along with r62627.
........
  r62749 | brett.cannon | 2008-05-06 06:37:31 +0200 (Tue, 06 May 2008) | 3 lines

  Fix a bug in the handling of the stacklevel argument in warnings.warn() where
  the stack was being unwound by two levels instead of one each time.
........
  r62756 | gregory.p.smith | 2008-05-06 09:05:18 +0200 (Tue, 06 May 2008) | 2 lines

  fix issue2707 - os.walk docstring example correctness typo.
........
This commit is contained in:
Christian Heimes 2008-05-06 13:58:24 +00:00
parent b91960c687
commit 5d8da20dd1
7 changed files with 47 additions and 51 deletions

View File

@ -803,7 +803,7 @@ sends traffic to the first one connected successfully. ::
import socket import socket
import sys import sys
HOST = '' # Symbolic name meaning the local host HOST = '' # Symbolic name meaning all available interfaces
PORT = 50007 # Arbitrary non-privileged port PORT = 50007 # Arbitrary non-privileged port
s = None s = None
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):

View File

@ -1692,7 +1692,7 @@ complete list of changes, or look through the CVS logs for all the details.
``permutations(iter[, r])`` returns all the permutations of length *r* of ``permutations(iter[, r])`` returns all the permutations of length *r* of
the iterable's elements. If *r* is not specified, it will default to the the iterable's elements. If *r* is not specified, it will default to the
number of elements produced by the iterable. number of elements produced by the iterable. ::
itertools.permutations([1,2,3,4], 2) -> itertools.permutations([1,2,3,4], 2) ->
[(1, 2), (1, 3), (1, 4), [(1, 2), (1, 3), (1, 4),

View File

@ -77,8 +77,9 @@ class BlockingIOError(IOError):
def open(file, mode="r", buffering=None, encoding=None, errors=None, def open(file, mode="r", buffering=None, encoding=None, errors=None,
newline=None, closefd=True): newline=None, closefd=True):
r"""Open file and return a stream. If the file cannot be opened, an
IOError is raised. r"""Open file and return a stream. If the file cannot be opened, an IOError is
raised.
file is either a string giving the name (and the path if the file file is either a string giving the name (and the path if the file
isn't in the current working directory) of the file to be opened or an isn't in the current working directory) of the file to be opened or an
@ -325,7 +326,7 @@ class IOBase(metaclass=abc.ABCMeta):
### Positioning ### ### Positioning ###
def seek(self, pos: int, whence: int = 0) -> int: def seek(self, pos: int, whence: int = 0) -> int:
"""seek(pos: int, whence: int = 0) -> int. Change stream position. """Change stream position.
Change the stream position to byte offset offset. offset is Change the stream position to byte offset offset. offset is
interpreted relative to the position indicated by whence. Values interpreted relative to the position indicated by whence. Values
@ -340,21 +341,21 @@ class IOBase(metaclass=abc.ABCMeta):
self._unsupported("seek") self._unsupported("seek")
def tell(self) -> int: def tell(self) -> int:
"""tell() -> int. Return current stream position.""" """Return current stream position."""
return self.seek(0, 1) return self.seek(0, 1)
def truncate(self, pos: int = None) -> int: def truncate(self, pos: int = None) -> int:
"""truncate(pos: int = None) -> int. Truncate file to pos bytes. """Truncate file to size bytes.
Pos defaults to the current IO position as reported by tell(). Size defaults to the current IO position as reported by tell(). Return
Returns the new size. the new size.
""" """
self._unsupported("truncate") self._unsupported("truncate")
### Flush and close ### ### Flush and close ###
def flush(self) -> None: def flush(self) -> None:
"""flush() -> None. Flushes write buffers, if applicable. """Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams. This is not implemented for read-only and non-blocking streams.
""" """
@ -363,7 +364,7 @@ class IOBase(metaclass=abc.ABCMeta):
__closed = False __closed = False
def close(self) -> None: def close(self) -> None:
"""close() -> None. Flushes and closes the IO object. """Flush and close the IO object.
This method has no effect if the file is already closed. This method has no effect if the file is already closed.
""" """
@ -389,7 +390,7 @@ class IOBase(metaclass=abc.ABCMeta):
### Inquiries ### ### Inquiries ###
def seekable(self) -> bool: def seekable(self) -> bool:
"""seekable() -> bool. Return whether object supports random access. """Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError. If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek(). This method may need to do a test seek().
@ -405,7 +406,7 @@ class IOBase(metaclass=abc.ABCMeta):
def readable(self) -> bool: def readable(self) -> bool:
"""readable() -> bool. Return whether object was opened for reading. """Return whether object was opened for reading.
If False, read() will raise IOError. If False, read() will raise IOError.
""" """
@ -419,7 +420,7 @@ class IOBase(metaclass=abc.ABCMeta):
if msg is None else msg) if msg is None else msg)
def writable(self) -> bool: def writable(self) -> bool:
"""writable() -> bool. Return whether object was opened for writing. """Return whether object was opened for writing.
If False, write() and truncate() will raise IOError. If False, write() and truncate() will raise IOError.
""" """
@ -463,14 +464,16 @@ class IOBase(metaclass=abc.ABCMeta):
# XXX Should these be present even if unimplemented? # XXX Should these be present even if unimplemented?
def fileno(self) -> int: def fileno(self) -> int:
"""fileno() -> int. Returns underlying file descriptor if one exists. """Returns underlying file descriptor if one exists.
Raises IOError if the IO object does not use a file descriptor. An IOError is raised if the IO object does not use a file descriptor.
""" """
self._unsupported("fileno") self._unsupported("fileno")
def isatty(self) -> bool: def isatty(self) -> bool:
"""isatty() -> int. Returns whether this is an 'interactive' stream. """Return whether this is an 'interactive' stream.
Return False if it can't be determined.
""" """
self._checkClosed() self._checkClosed()
return False return False
@ -478,8 +481,7 @@ class IOBase(metaclass=abc.ABCMeta):
### Readline[s] and writelines ### ### Readline[s] and writelines ###
def readline(self, limit: int = -1) -> bytes: def readline(self, limit: int = -1) -> bytes:
r"""readline(limit: int = -1) -> bytes Read and return a line from the r"""Read and return a line from the stream.
stream.
If limit is specified, at most limit bytes will be read. If limit is specified, at most limit bytes will be read.
@ -523,7 +525,7 @@ class IOBase(metaclass=abc.ABCMeta):
return line return line
def readlines(self, hint=None): def readlines(self, hint=None):
"""readlines(hint=None) -> list Return a list of lines from the stream. """Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more hint can be specified to control the number of lines read: no more
lines will be read if the total size (in bytes/characters) of all lines will be read if the total size (in bytes/characters) of all
@ -561,7 +563,7 @@ class RawIOBase(IOBase):
# a subclass doesn't implement either.) # a subclass doesn't implement either.)
def read(self, n: int = -1) -> bytes: def read(self, n: int = -1) -> bytes:
"""read(n: int) -> bytes. Read and return up to n bytes. """Read and return up to n bytes.
Returns an empty bytes object on EOF, or None if the object is Returns an empty bytes object on EOF, or None if the object is
set not to block and has no data to read. set not to block and has no data to read.
@ -576,7 +578,7 @@ class RawIOBase(IOBase):
return bytes(b) return bytes(b)
def readall(self): def readall(self):
"""readall() -> bytes. Read until EOF, using multiple read() calls.""" """Read until EOF, using multiple read() call."""
res = bytearray() res = bytearray()
while True: while True:
data = self.read(DEFAULT_BUFFER_SIZE) data = self.read(DEFAULT_BUFFER_SIZE)
@ -586,7 +588,7 @@ class RawIOBase(IOBase):
return bytes(res) return bytes(res)
def readinto(self, b: bytearray) -> int: def readinto(self, b: bytearray) -> int:
"""readinto(b: bytearray) -> int. Read up to len(b) bytes into b. """Read up to len(b) bytes into b.
Returns number of bytes read (0 for EOF), or None if the object Returns number of bytes read (0 for EOF), or None if the object
is set not to block as has no data to read. is set not to block as has no data to read.
@ -594,7 +596,7 @@ class RawIOBase(IOBase):
self._unsupported("readinto") self._unsupported("readinto")
def write(self, b: bytes) -> int: def write(self, b: bytes) -> int:
"""write(b: bytes) -> int. Write the given buffer to the IO stream. """Write the given buffer to the IO stream.
Returns the number of bytes written, which may be less than len(b). Returns the number of bytes written, which may be less than len(b).
""" """
@ -642,7 +644,7 @@ class BufferedIOBase(IOBase):
""" """
def read(self, n: int = None) -> bytes: def read(self, n: int = None) -> bytes:
"""read(n: int = None) -> bytes. Read and return up to n bytes. """Read and return up to n bytes.
If the argument is omitted, None, or negative, reads and If the argument is omitted, None, or negative, reads and
returns all data until EOF. returns all data until EOF.
@ -662,7 +664,7 @@ class BufferedIOBase(IOBase):
self._unsupported("read") self._unsupported("read")
def readinto(self, b: bytearray) -> int: def readinto(self, b: bytearray) -> int:
"""readinto(b: bytearray) -> int. Read up to len(b) bytes into b. """Read up to len(b) bytes into b.
Like read(), this may issue multiple reads to the underlying raw Like read(), this may issue multiple reads to the underlying raw
stream, unless the latter is 'interactive'. stream, unless the latter is 'interactive'.
@ -685,9 +687,9 @@ class BufferedIOBase(IOBase):
return n return n
def write(self, b: bytes) -> int: def write(self, b: bytes) -> int:
"""write(b: bytes) -> int. Write the given buffer to the IO stream. """Write the given buffer to the IO stream.
Returns the number of bytes written, which is never less than Return the number of bytes written, which is never less than
len(b). len(b).
Raises BlockingIOError if the buffer is full and the Raises BlockingIOError if the buffer is full and the
@ -775,7 +777,7 @@ class BytesIO(BufferedIOBase):
self._pos = 0 self._pos = 0
def getvalue(self): def getvalue(self):
"""getvalue() -> bytes Return the bytes value (contents) of the buffer """Return the bytes value (contents) of the buffer
""" """
return bytes(self._buffer) return bytes(self._buffer)
@ -929,9 +931,7 @@ class BufferedReader(_BufferedIOMixin):
class BufferedWriter(_BufferedIOMixin): class BufferedWriter(_BufferedIOMixin):
"""BufferedWriter(raw[, buffer_size[, max_buffer_size]]) """A buffer for a writeable sequential RawIO object.
A buffer for a writeable sequential RawIO object.
The constructor creates a BufferedWriter for the given writeable raw The constructor creates a BufferedWriter for the given writeable raw
stream. If the buffer_size is not given, it defaults to stream. If the buffer_size is not given, it defaults to
@ -1069,9 +1069,7 @@ class BufferedRWPair(BufferedIOBase):
class BufferedRandom(BufferedWriter, BufferedReader): class BufferedRandom(BufferedWriter, BufferedReader):
"""BufferedRandom(raw[, buffer_size[, max_buffer_size]]) """A buffered interface to random access streams.
A buffered interface to random access streams.
The constructor creates a reader and writer for a seekable stream, The constructor creates a reader and writer for a seekable stream,
raw, given in the first argument. If the buffer_size is omitted it raw, given in the first argument. If the buffer_size is omitted it
@ -1134,7 +1132,7 @@ class TextIOBase(IOBase):
""" """
def read(self, n: int = -1) -> str: def read(self, n: int = -1) -> str:
"""read(n: int = -1) -> str. Read at most n characters from stream. """Read at most n characters from stream.
Read from underlying buffer until we have n characters or we hit EOF. Read from underlying buffer until we have n characters or we hit EOF.
If n is negative or omitted, read until EOF. If n is negative or omitted, read until EOF.
@ -1142,11 +1140,11 @@ class TextIOBase(IOBase):
self._unsupported("read") self._unsupported("read")
def write(self, s: str) -> int: def write(self, s: str) -> int:
"""write(s: str) -> int. Write string s to stream.""" """Write string s to stream."""
self._unsupported("write") self._unsupported("write")
def truncate(self, pos: int = None) -> int: def truncate(self, pos: int = None) -> int:
"""truncate(pos: int = None) -> int. Truncate size to pos.""" """Truncate size to pos."""
self.flush() self.flush()
if pos is None: if pos is None:
pos = self.tell() pos = self.tell()
@ -1154,7 +1152,7 @@ class TextIOBase(IOBase):
return self.buffer.truncate() return self.buffer.truncate()
def readline(self) -> str: def readline(self) -> str:
"""readline() -> str. Read until newline or EOF. """Read until newline or EOF.
Returns an empty string if EOF is hit immediately. Returns an empty string if EOF is hit immediately.
""" """
@ -1167,8 +1165,7 @@ class TextIOBase(IOBase):
@property @property
def newlines(self): def newlines(self):
"""newlines -> None | str | tuple of str. Line endings translated """Line endings translated so far.
so far.
Only line endings translated during reading are considered. Only line endings translated during reading are considered.
@ -1258,9 +1255,7 @@ class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
class TextIOWrapper(TextIOBase): class TextIOWrapper(TextIOBase):
r"""TextIOWrapper(buffer[, encoding[, errors[, newline[, line_buffering]]]]) r"""Character and line based layer over a BufferedIOBase object, buffer.
Character and line based layer over a BufferedIOBase object, buffer.
encoding gives the name of the encoding that the stream will be encoding gives the name of the encoding that the stream will be
decoded or encoded with. It defaults to locale.getpreferredencoding. decoded or encoded with. It defaults to locale.getpreferredencoding.
@ -1718,9 +1713,7 @@ class TextIOWrapper(TextIOBase):
return self._decoder.newlines if self._decoder else None return self._decoder.newlines if self._decoder else None
class StringIO(TextIOWrapper): class StringIO(TextIOWrapper):
"""StringIO([initial_value[, encoding, [errors, [newline]]]]) """An in-memory stream for text. The initial_value argument sets the
An in-memory stream for text. The initial_value argument sets the
value of object. The other arguments are like those of TextIOWrapper's value of object. The other arguments are like those of TextIOWrapper's
constructor. constructor.
""" """

View File

@ -251,8 +251,9 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
Example: Example:
import os
from os.path import join, getsize from os.path import join, getsize
for root, dirs, files in walk('python/Lib/email'): for root, dirs, files in os.walk('python/Lib/email'):
print root, "consumes", print root, "consumes",
print sum([getsize(join(root, name)) for name in files]), print sum([getsize(join(root, name)) for name in files]),
print "bytes in", len(files), "non-directory files" print "bytes in", len(files), "non-directory files"

View File

@ -225,6 +225,8 @@ class WarnTests(unittest.TestCase):
self.assertEqual(os.path.basename(w.filename), "test_warnings.py") self.assertEqual(os.path.basename(w.filename), "test_warnings.py")
warning_tests.outer("spam6", stacklevel=2) warning_tests.outer("spam6", stacklevel=2)
self.assertEqual(os.path.basename(w.filename), "warning_tests.py") self.assertEqual(os.path.basename(w.filename), "warning_tests.py")
warning_tests.outer("spam6.5", stacklevel=3)
self.assertEqual(os.path.basename(w.filename), "test_warnings.py")
warning_tests.inner("spam7", stacklevel=9999) warning_tests.inner("spam7", stacklevel=9999)
self.assertEqual(os.path.basename(w.filename), "sys") self.assertEqual(os.path.basename(w.filename), "sys")

View File

@ -964,6 +964,8 @@ class AbstractDigestAuthHandler:
return base return base
def get_algorithm_impls(self, algorithm): def get_algorithm_impls(self, algorithm):
# algorithm should be case-insensitive according to RFC2617
algorithm = algorithm.upper()
# lambdas assume digest modules are imported at the top level # lambdas assume digest modules are imported at the top level
if algorithm == 'MD5': if algorithm == 'MD5':
H = lambda x: hashlib.md5(x.encode("ascii")).hexdigest() H = lambda x: hashlib.md5(x.encode("ascii")).hexdigest()

View File

@ -415,10 +415,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
/* Setup globals and lineno. */ /* Setup globals and lineno. */
PyFrameObject *f = PyThreadState_GET()->frame; PyFrameObject *f = PyThreadState_GET()->frame;
while (--stack_level > 0 && f != NULL) { while (--stack_level > 0 && f != NULL)
f = f->f_back; f = f->f_back;
--stack_level;
}
if (f == NULL) { if (f == NULL) {
globals = PyThreadState_Get()->interp->sysdict; globals = PyThreadState_Get()->interp->sysdict;