Commit 41181743 authored by Benjamin Peterson's avatar Benjamin Peterson

Merged revisions...

Merged revisions 64475,64544-64545,64550,64557-64558,64565,64570,64577,64582-64583,64585,64590,64592-64593,64625,64630,64638,64647,64655-64656,64663-64664 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r64475 | raymond.hettinger | 2008-06-22 22:29:28 -0500 (Sun, 22 Jun 2008) | 1 line

  Issue 3161: Missing import and test.
........
  r64544 | georg.brandl | 2008-06-26 16:12:55 -0500 (Thu, 26 Jun 2008) | 2 lines

  Use newer versions of externals.
........
  r64545 | benjamin.peterson | 2008-06-26 16:23:30 -0500 (Thu, 26 Jun 2008) | 1 line

  add a htmlview directive
........
  r64550 | brett.cannon | 2008-06-26 19:32:16 -0500 (Thu, 26 Jun 2008) | 2 lines

  Ignore .pyc and .pyo files.
........
  r64557 | mark.dickinson | 2008-06-27 05:11:52 -0500 (Fri, 27 Jun 2008) | 3 lines

  Remove trailing 'L's from numerator and denominator in the
  repr() of a Fraction instance.
........
  r64558 | mark.dickinson | 2008-06-27 06:03:21 -0500 (Fri, 27 Jun 2008) | 2 lines

  Add Jean Brouwers for his work on math.sum
........
  r64565 | raymond.hettinger | 2008-06-27 16:34:24 -0500 (Fri, 27 Jun 2008) | 1 line

  Fix whitespace in example code.
........
  r64570 | hyeshik.chang | 2008-06-27 20:04:31 -0500 (Fri, 27 Jun 2008) | 8 lines

  Give information for compililation of _multiprocessing.SemLock on FreeBSD:

  FreeBSD's P1003.1b semaphore support is highly experimental and
  it's disabled by default.  Even if a user loads the experimental
  kernel module manually, _multiprocessing doesn't work correctly due
  to several known incompatibilities around sem_unlink and sem_getvalue,
  yet.
........
  r64577 | raymond.hettinger | 2008-06-28 17:16:53 -0500 (Sat, 28 Jun 2008) | 1 line

  Issue 3230:  Do not the set specific size macro.
........
  r64582 | benjamin.peterson | 2008-06-28 18:06:05 -0500 (Sat, 28 Jun 2008) | 2 lines

  convert test_audioop to unittest. Thanks to Giampaolo Rodola.
........
  r64583 | benjamin.peterson | 2008-06-28 18:06:49 -0500 (Sat, 28 Jun 2008) | 1 line

  rewrap
........
  r64585 | benjamin.peterson | 2008-06-28 18:35:31 -0500 (Sat, 28 Jun 2008) | 1 line

  fix typo
........
  r64590 | benjamin.peterson | 2008-06-29 08:43:07 -0500 (Sun, 29 Jun 2008) | 1 line

  reinstate the ending backtick. thanks Nick :)
........
  r64592 | vinay.sajip | 2008-06-29 16:25:28 -0500 (Sun, 29 Jun 2008) | 2 lines

  Removed out-of-date comment in _install_handlers and
  used issubclass in place of equality comparison of classes.
........
  r64593 | vinay.sajip | 2008-06-29 16:27:15 -0500 (Sun, 29 Jun 2008) | 1 line

  Updated to reflect change in logging.config to remove out-of-date comment in _install_handlers and the use of issubclass in place of equality comparison of classes.
........
  r64625 | georg.brandl | 2008-07-01 14:59:00 -0500 (Tue, 01 Jul 2008) | 2 lines

  Add a link to PEP 324.
........
  r64630 | georg.brandl | 2008-07-01 15:18:10 -0500 (Tue, 01 Jul 2008) | 2 lines

  #3216: fix Execute's parameter description.
........
  r64638 | georg.brandl | 2008-07-01 15:50:02 -0500 (Tue, 01 Jul 2008) | 2 lines

  #1410739: add a footnote about "is" and "unusual" behavior.
........
  r64647 | benjamin.peterson | 2008-07-01 18:33:06 -0500 (Tue, 01 Jul 2008) | 1 line

  add ABC to the glossary
........
  r64655 | mark.dickinson | 2008-07-02 04:37:01 -0500 (Wed, 02 Jul 2008) | 7 lines

  Replace occurrences of '\d' with '[0-9]' in Decimal regex, to make sure
  that the behaviour of Decimal doesn't change if/when re.UNICODE becomes
  assumed in Python 3.0.

  Also add a check that alternative Unicode digits (e.g. u'\N{FULLWIDTH
  DIGIT ONE}') are *not* accepted in a numeric string.
........
  r64656 | nick.coghlan | 2008-07-02 08:09:19 -0500 (Wed, 02 Jul 2008) | 1 line

  Issue 3190: pydoc now hides module __package__ attributes
........
  r64663 | jesse.noller | 2008-07-02 11:44:09 -0500 (Wed, 02 Jul 2008) | 1 line

  Reenable the manager tests with Amaury's threading fix
........
  r64664 | facundo.batista | 2008-07-02 11:52:55 -0500 (Wed, 02 Jul 2008) | 4 lines


  Issue #449227: Now with the rlcompleter module, callable objects are
  added a '(' when completed.
........
parent 200ff185
...@@ -33,15 +33,15 @@ checkout: ...@@ -33,15 +33,15 @@ checkout:
fi fi
@if [ ! -d tools/docutils ]; then \ @if [ ! -d tools/docutils ]; then \
echo "Checking out Docutils..."; \ echo "Checking out Docutils..."; \
svn checkout $(SVNROOT)/external/docutils-0.4/docutils tools/docutils; \ svn checkout $(SVNROOT)/external/docutils-0.5/docutils tools/docutils; \
fi fi
@if [ ! -d tools/jinja ]; then \ @if [ ! -d tools/jinja ]; then \
echo "Checking out Jinja..."; \ echo "Checking out Jinja..."; \
svn checkout $(SVNROOT)/external/Jinja-1.1/jinja tools/jinja; \ svn checkout $(SVNROOT)/external/Jinja-1.2/jinja tools/jinja; \
fi fi
@if [ ! -d tools/pygments ]; then \ @if [ ! -d tools/pygments ]; then \
echo "Checking out Pygments..."; \ echo "Checking out Pygments..."; \
svn checkout $(SVNROOT)/external/Pygments-0.9/pygments tools/pygments; \ svn checkout $(SVNROOT)/external/Pygments-0.10/pygments tools/pygments; \
fi fi
update: checkout update: checkout
...@@ -103,6 +103,8 @@ pydoc-topics: build ...@@ -103,6 +103,8 @@ pydoc-topics: build
@echo "Building finished; now copy build/pydoc-topics/pydoc_topics.py " \ @echo "Building finished; now copy build/pydoc-topics/pydoc_topics.py " \
"into the Lib/ directory" "into the Lib/ directory"
htmlview: html
$(PYTHON) -c "import webbrowser; webbrowser.open('build/html/index.html')"
clean: clean:
-rm -rf build/* -rm -rf build/*
-rm -rf tools/sphinx -rm -rf tools/sphinx
...@@ -16,6 +16,14 @@ Glossary ...@@ -16,6 +16,14 @@ Glossary
The typical Python prompt of the interactive shell when entering code for The typical Python prompt of the interactive shell when entering code for
an indented code block. an indented code block.
Abstract Base Class
Abstract Base Classes (abbreviated ABCs) complement :term:`duck-typing` by
providing a way to define interfaces when other techniques like :func:`hasattr`
would be clumsy. Python comes with many builtin ABCs for data structures
(in the :mod:`collections` module), numbers (in the :mod:`numbers`
module), and streams (in the :mod:`io` module). You can create your own
ABC with the :mod:`abc` module.
argument argument
A value passed to a function or method, assigned to a name local to A value passed to a function or method, assigned to a name local to
the body. A function or method may have both positional arguments and the body. A function or method may have both positional arguments and
...@@ -93,15 +101,16 @@ Glossary ...@@ -93,15 +101,16 @@ Glossary
be any object with a :meth:`__hash__` function, not just integers starting be any object with a :meth:`__hash__` function, not just integers starting
from zero. Called a hash in Perl. from zero. Called a hash in Perl.
duck-typing duck-typing
Pythonic programming style that determines an object's type by inspection Pythonic programming style that determines an object's type by inspection
of its method or attribute signature rather than by explicit relationship of its method or attribute signature rather than by explicit relationship
to some type object ("If it looks like a duck and quacks like a duck, it to some type object ("If it looks like a duck and quacks like a duck, it
must be a duck.") By emphasizing interfaces rather than specific types, must be a duck.") By emphasizing interfaces rather than specific types,
well-designed code improves its flexibility by allowing polymorphic well-designed code improves its flexibility by allowing polymorphic
substitution. Duck-typing avoids tests using :func:`type` or substitution. Duck-typing avoids tests using :func:`type` or
:func:`isinstance`. Instead, it typically employs :func:`hasattr` tests or :func:`isinstance`. (Note, however, that duck-typing can be complemented
:term:`EAFP` programming. with abstract base classes.) Instead, it typically employs :func:`hasattr`
tests or :term:`EAFP` programming.
EAFP EAFP
Easier to ask for forgiveness than permission. This common Python coding Easier to ask for forgiveness than permission. This common Python coding
......
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
.. sectionauthor:: Georg Brandl .. sectionauthor:: Georg Brandl
.. much of the content adapted from docstrings .. much of the content adapted from docstrings
This module provides the infrastructure for defining abstract base classes This module provides the infrastructure for defining :term:`abstract base
(ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this was added classes` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
to Python. (See also :pep:`3141` and the :mod:`numbers` module regarding a type was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
hierarchy for numbers based on ABCs.) regarding a type hierarchy for numbers based on ABCs.)
The :mod:`collections` module has some concrete classes that derive from The :mod:`collections` module has some concrete classes that derive from
ABCs; these can, of course, be further derived. In addition the ABCs; these can, of course, be further derived. In addition the
......
...@@ -520,8 +520,8 @@ Example: ...@@ -520,8 +520,8 @@ Example:
raise ValueError('Got unexpected field names: %r' % kwds.keys()) raise ValueError('Got unexpected field names: %r' % kwds.keys())
return result return result
<BLANKLINE> <BLANKLINE>
def __getnewargs__(self): def __getnewargs__(self):
return tuple(self) return tuple(self)
<BLANKLINE> <BLANKLINE>
x = property(itemgetter(0)) x = property(itemgetter(0))
y = property(itemgetter(1)) y = property(itemgetter(1))
......
:mod:`msilib` --- Read and write Microsoft Installer files :mod:`msilib` --- Read and write Microsoft Installer files
========================================================== ==========================================================
...@@ -163,11 +162,11 @@ View Objects ...@@ -163,11 +162,11 @@ View Objects
------------ ------------
.. method:: View.Execute([params=None]) .. method:: View.Execute(params)
Execute the SQL query of the view, through :cfunc:`MSIViewExecute`. *params* is Execute the SQL query of the view, through :cfunc:`MSIViewExecute`. If
an optional record describing actual values of the parameter tokens in the *params* is not ``None``, it is a record describing actual values of the
query. parameter tokens in the query.
.. method:: View.GetColumnInfo(kind) .. method:: View.GetColumnInfo(kind)
......
...@@ -20,9 +20,9 @@ Example:: ...@@ -20,9 +20,9 @@ Example::
>>> import readline >>> import readline
>>> readline.parse_and_bind("tab: complete") >>> readline.parse_and_bind("tab: complete")
>>> readline. <TAB PRESSED> >>> readline. <TAB PRESSED>
readline.__doc__ readline.get_line_buffer readline.read_init_file readline.__doc__ readline.get_line_buffer( readline.read_init_file(
readline.__file__ readline.insert_text readline.set_completer readline.__file__ readline.insert_text( readline.set_completer(
readline.__name__ readline.parse_and_bind readline.__name__ readline.parse_and_bind(
>>> readline. >>> readline.
The :mod:`rlcompleter` module is designed for use with Python's interactive The :mod:`rlcompleter` module is designed for use with Python's interactive
......
...@@ -18,6 +18,10 @@ replace several other, older modules and functions, such as:: ...@@ -18,6 +18,10 @@ replace several other, older modules and functions, such as::
Information about how the :mod:`subprocess` module can be used to replace these Information about how the :mod:`subprocess` module can be used to replace these
modules and functions can be found in the following sections. modules and functions can be found in the following sections.
.. seealso::
:pep:`324` -- PEP proposing the subprocess module
Using the subprocess Module Using the subprocess Module
--------------------------- ---------------------------
......
...@@ -583,10 +583,10 @@ variables with different implementation details. ...@@ -583,10 +583,10 @@ variables with different implementation details.
:pep:`3129` - Class Decorators :pep:`3129` - Class Decorators
Class definitions, like function definitions, may be wrapped by one or Class definitions, like function definitions, may be wrapped by one or more
more :term:`decorator` expressions. The evaluation rules for the :term:`decorator` expressions. The evaluation rules for the decorator
decorator expressions are the same as for functions. The result must expressions are the same as for functions. The result must be a class object,
be a class object, which is then bound to the class name. which is then bound to the class name.
.. rubric:: Footnotes .. rubric:: Footnotes
......
...@@ -1082,7 +1082,7 @@ The operator :keyword:`not in` is defined to have the inverse true value of ...@@ -1082,7 +1082,7 @@ The operator :keyword:`not in` is defined to have the inverse true value of
The operators :keyword:`is` and :keyword:`is not` test for object identity: ``x The operators :keyword:`is` and :keyword:`is not` test for object identity: ``x
is y`` is true if and only if *x* and *y* are the same object. ``x is not y`` is y`` is true if and only if *x* and *y* are the same object. ``x is not y``
yields the inverse truth value. yields the inverse truth value. [#]_
.. _booleans: .. _booleans:
...@@ -1314,3 +1314,7 @@ groups from right to left). ...@@ -1314,3 +1314,7 @@ groups from right to left).
identity only, but this caused surprises because people expected to be able identity only, but this caused surprises because people expected to be able
to test a dictionary for emptiness by comparing it to ``{}``. to test a dictionary for emptiness by comparing it to ``{}``.
.. [#] Due to automatic garbage-collection, free lists, and the dynamic nature of
descriptors, you may notice seemingly unusual behaviour in certain uses of
the :keyword:`is` operator, like those involving comparisons between instance
methods, or constants. Check their documentation for more info.
...@@ -9,6 +9,7 @@ bootstrapping issues. Unit tests are in test_collections. ...@@ -9,6 +9,7 @@ bootstrapping issues. Unit tests are in test_collections.
""" """
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import sys
__all__ = ["Hashable", "Iterable", "Iterator", __all__ = ["Hashable", "Iterable", "Iterator",
"Sized", "Container", "Callable", "Sized", "Container", "Callable",
......
...@@ -5423,20 +5423,20 @@ ExtendedContext = Context( ...@@ -5423,20 +5423,20 @@ ExtendedContext = Context(
# other meaning for \d than the numbers [0-9]. # other meaning for \d than the numbers [0-9].
import re import re
_parser = re.compile(r""" # A numeric string consists of: _parser = re.compile(r""" # A numeric string consists of:
# \s* # \s*
(?P<sign>[-+])? # an optional sign, followed by either... (?P<sign>[-+])? # an optional sign, followed by either...
( (
(?=\d|\.\d) # ...a number (with at least one digit) (?=[0-9]|\.[0-9]) # ...a number (with at least one digit)
(?P<int>\d*) # consisting of a (possibly empty) integer part (?P<int>[0-9]*) # having a (possibly empty) integer part
(\.(?P<frac>\d*))? # followed by an optional fractional part (\.(?P<frac>[0-9]*))? # followed by an optional fractional part
(E(?P<exp>[-+]?\d+))? # followed by an optional exponent, or... (E(?P<exp>[-+]?[0-9]+))? # followed by an optional exponent, or...
| |
Inf(inity)? # ...an infinity, or... Inf(inity)? # ...an infinity, or...
| |
(?P<signal>s)? # ...an (optionally signaling) (?P<signal>s)? # ...an (optionally signaling)
NaN # NaN NaN # NaN
(?P<diag>\d*) # with (possibly empty) diagnostic information. (?P<diag>[0-9]*) # with (possibly empty) diagnostic info.
) )
# \s* # \s*
\Z \Z
......
...@@ -201,7 +201,7 @@ class Fraction(numbers.Rational): ...@@ -201,7 +201,7 @@ class Fraction(numbers.Rational):
def __repr__(self): def __repr__(self):
"""repr(self)""" """repr(self)"""
return ('Fraction(%r, %r)' % (self._numerator, self._denominator)) return ('Fraction(%s, %s)' % (self._numerator, self._denominator))
def __str__(self): def __str__(self):
"""str(self)""" """str(self)"""
......
...@@ -152,8 +152,7 @@ def _install_handlers(cp, formatters): ...@@ -152,8 +152,7 @@ def _install_handlers(cp, formatters):
h.setLevel(logging._levelNames[level]) h.setLevel(logging._levelNames[level])
if len(fmt): if len(fmt):
h.setFormatter(formatters[fmt]) h.setFormatter(formatters[fmt])
#temporary hack for FileHandler and MemoryHandler. if issubclass(klass, logging.handlers.MemoryHandler):
if klass == logging.handlers.MemoryHandler:
if "target" in opts: if "target" in opts:
target = cp.get(sectname,"target") target = cp.get(sectname,"target")
else: else:
......
...@@ -159,8 +159,9 @@ def _split_list(s, predicate): ...@@ -159,8 +159,9 @@ def _split_list(s, predicate):
def visiblename(name, all=None): def visiblename(name, all=None):
"""Decide whether to show documentation on a variable.""" """Decide whether to show documentation on a variable."""
# Certain special names are redundant. # Certain special names are redundant.
if name in ('__builtins__', '__doc__', '__file__', '__path__', _hidden_names = ('__builtins__', '__doc__', '__file__', '__path__',
'__module__', '__name__', '__slots__'): return 0 '__module__', '__name__', '__slots__', '__package__')
if name in _hidden_names: return 0
# Private names are hidden, but special names are displayed. # Private names are hidden, but special names are displayed.
if name.startswith('__') and name.endswith('__'): return 1 if name.startswith('__') and name.endswith('__'): return 1
if all is not None: if all is not None:
......
...@@ -86,6 +86,11 @@ class Completer: ...@@ -86,6 +86,11 @@ class Completer:
except IndexError: except IndexError:
return None return None
def _callable_postfix(self, val, word):
if callable(val):
word = word + "("
return word
def global_matches(self, text): def global_matches(self, text):
"""Compute matches when text is a simple name. """Compute matches when text is a simple name.
...@@ -96,12 +101,13 @@ class Completer: ...@@ -96,12 +101,13 @@ class Completer:
import keyword import keyword
matches = [] matches = []
n = len(text) n = len(text)
for list in [keyword.kwlist, for word in keyword.kwlist:
builtins.__dict__, if word[:n] == text:
self.namespace]: matches.append(word)
for word in list: for nspace in [builtins.__dict__, self.namespace]:
if word[:n] == text and word != "__builtins__": for word, val in nspace.items():
matches.append(word) if word[:n] == text and word != "builtins":
matches.append(self._callable_postfix(val, word))
return matches return matches
def attr_matches(self, text): def attr_matches(self, text):
...@@ -133,7 +139,9 @@ class Completer: ...@@ -133,7 +139,9 @@ class Completer:
n = len(attr) n = len(attr)
for word in words: for word in words:
if word[:n] == attr and word != "__builtins__": if word[:n] == attr and word != "__builtins__":
matches.append("%s.%s" % (expr, word)) val = getattr(object, word)
word = self._callable_postfix(val, "%s.%s" % (expr, word))
matches.append(word)
return matches return matches
def get_class_members(klass): def get_class_members(klass):
......
# Test audioop.
import audioop import audioop
from test.support import verbose import unittest
from test.support import run_unittest
def gendata1(): def gendata1():
return b'\0\1\2' return b'\0\1\2'
def gendata2(): def gendata2():
if verbose:
print('getsample')
if audioop.getsample(b'\0\1', 2, 0) == 1: if audioop.getsample(b'\0\1', 2, 0) == 1:
return b'\0\0\0\1\0\2' return b'\0\0\0\1\0\2'
else: else:
return b'\0\0\1\0\2\0' return b'\0\0\1\0\2\0'
def gendata4(): def gendata4():
if verbose:
print('getsample')
if audioop.getsample(b'\0\0\0\1', 4, 0) == 1: if audioop.getsample(b'\0\0\0\1', 4, 0) == 1:
return b'\0\0\0\0\0\0\0\1\0\0\0\2' return b'\0\0\0\0\0\0\0\1\0\0\0\2'
else: else:
return b'\0\0\0\0\1\0\0\0\2\0\0\0' return b'\0\0\0\0\1\0\0\0\2\0\0\0'
def testmax(data): data = [gendata1(), gendata2(), gendata4()]
if verbose:
print('max')
if audioop.max(data[0], 1) != 2 or \ class TestAudioop(unittest.TestCase):
audioop.max(data[1], 2) != 2 or \
audioop.max(data[2], 4) != 2: def test_max(self):
return 0 self.assertEqual(audioop.max(data[0], 1), 2)
return 1 self.assertEqual(audioop.max(data[1], 2), 2)
self.assertEqual(audioop.max(data[2], 4), 2)
def testminmax(data):
if verbose: def test_minmax(self):
print('minmax') self.assertEqual(audioop.minmax(data[0], 1), (0, 2))
if audioop.minmax(data[0], 1) != (0, 2) or \ self.assertEqual(audioop.minmax(data[1], 2), (0, 2))
audioop.minmax(data[1], 2) != (0, 2) or \ self.assertEqual(audioop.minmax(data[2], 4), (0, 2))
audioop.minmax(data[2], 4) != (0, 2):
return 0 def test_maxpp(self):
return 1 self.assertEqual(audioop.maxpp(data[0], 1), 0)
self.assertEqual(audioop.maxpp(data[1], 2), 0)
def testmaxpp(data): self.assertEqual(audioop.maxpp(data[2], 4), 0)
if verbose:
print('maxpp') def test_avg(self):
if audioop.maxpp(data[0], 1) != 0 or \ self.assertEqual(audioop.avg(data[0], 1), 1)
audioop.maxpp(data[1], 2) != 0 or \ self.assertEqual(audioop.avg(data[1], 2), 1)
audioop.maxpp(data[2], 4) != 0: self.assertEqual(audioop.avg(data[2], 4), 1)
return 0
return 1 def test_avgpp(self):
self.assertEqual(audioop.avgpp(data[0], 1), 0)
def testavg(data): self.assertEqual(audioop.avgpp(data[1], 2), 0)
if verbose: self.assertEqual(audioop.avgpp(data[2], 4), 0)
print('avg')
if audioop.avg(data[0], 1) != 1 or \ def test_rms(self):
audioop.avg(data[1], 2) != 1 or \ self.assertEqual(audioop.rms(data[0], 1), 1)
audioop.avg(data[2], 4) != 1: self.assertEqual(audioop.rms(data[1], 2), 1)
return 0 self.assertEqual(audioop.rms(data[2], 4), 1)
return 1
def test_cross(self):
def testavgpp(data): self.assertEqual(audioop.cross(data[0], 1), 0)
if verbose: self.assertEqual(audioop.cross(data[1], 2), 0)
print('avgpp') self.assertEqual(audioop.cross(data[2], 4), 0)
if audioop.avgpp(data[0], 1) != 0 or \
audioop.avgpp(data[1], 2) != 0 or \ def test_add(self):
audioop.avgpp(data[2], 4) != 0: data2 = []
return 0 for d in data:
return 1 str = bytearray(len(d))
for i,b in enumerate(d):
def testrms(data): str[i] = 2*b
if audioop.rms(data[0], 1) != 1 or \ data2.append(str)
audioop.rms(data[1], 2) != 1 or \ self.assertEqual(audioop.add(data[0], data[0], 1), data2[0])
audioop.rms(data[2], 4) != 1: self.assertEqual(audioop.add(data[1], data[1], 2), data2[1])
return 0 self.assertEqual(audioop.add(data[2], data[2], 4), data2[2])
return 1
def test_bias(self):
def testcross(data): # Note: this test assumes that avg() works
if verbose: d1 = audioop.bias(data[0], 1, 100)
print('cross') d2 = audioop.bias(data[1], 2, 100)
if audioop.cross(data[0], 1) != 0 or \ d4 = audioop.bias(data[2], 4, 100)
audioop.cross(data[1], 2) != 0 or \ self.assertEqual(audioop.avg(d1, 1), 101)
audioop.cross(data[2], 4) != 0: self.assertEqual(audioop.avg(d2, 2), 101)
return 0 self.assertEqual(audioop.avg(d4, 4), 101)
return 1
def test_lin2lin(self):
def testadd(data): # too simple: we test only the size
if verbose: for d1 in data:
print('add') for d2 in data:
data2 = [] got = len(d1)//3
for d in data: wtd = len(d2)//3
str = bytearray(len(d)) self.assertEqual(len(audioop.lin2lin(d1, got, wtd)), len(d2))
for i,b in enumerate(d):
str[i] = 2*b def test_adpcm2lin(self):
data2.append(str) # Very cursory test
if audioop.add(data[0], data[0], 1) != data2[0] or \ self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0\0\0\0', (0,0)))
audioop.add(data[1], data[1], 2) != data2[1] or \
audioop.add(data[2], data[2], 4) != data2[2]: def test_lin2adpcm(self):
return 0 # Very cursory test
return 1 self.assertEqual(audioop.lin2adpcm(b'\0\0\0\0', 1, None), (b'\0\0', (0,0)))
def testbias(data): def test_lin2alaw(self):
if verbose: self.assertEqual(audioop.lin2alaw(data[0], 1), b'\xd5\xc5\xf5')
print('bias') self.assertEqual(audioop.lin2alaw(data[1], 2), b'\xd5\xd5\xd5')
# Note: this test assumes that avg() works self.assertEqual(audioop.lin2alaw(data[2], 4), b'\xd5\xd5\xd5')
d1 = audioop.bias(data[0], 1, 100)
d2 = audioop.bias(data[1], 2, 100) def test_alaw2lin(self):
d4 = audioop.bias(data[2], 4, 100) # Cursory
if audioop.avg(d1, 1) != 101 or \ d = audioop.lin2alaw(data[0], 1)
audioop.avg(d2, 2) != 101 or \ self.assertEqual(audioop.alaw2lin(d, 1), data[0])
audioop.avg(d4, 4) != 101:
return 0 def test_lin2ulaw(self):
return 1 self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
self.assertEqual(audioop.lin2ulaw(data[1], 2), b'\xff\xff\xff')
def testlin2lin(data): self.assertEqual(audioop.lin2ulaw(data[2], 4), b'\xff\xff\xff')
if verbose:
print('lin2lin') def test_ulaw2lin(self):
# too simple: we test only the size # Cursory
for d1 in data: d = audioop.lin2ulaw(data[0], 1)
for d2 in data: self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
got = len(d1)//3
wtd = len(d2)//3 def test_mul(self):
if len(audioop.lin2lin(d1, got, wtd)) != len(d2): data2 = []
return 0 for d in data:
return 1 str = bytearray(len(d))
for i,b in enumerate(d):
def testadpcm2lin(data): str[i] = 2*b
# Very cursory test data2.append(str)
if audioop.adpcm2lin(b'\0\0', 1, None) != (b'\0\0\0\0', (0,0)): self.assertEqual(audioop.mul(data[0], 1, 2), data2[0])
return 0 self.assertEqual(audioop.mul(data[1],2, 2), data2[1])
return 1 self.assertEqual(audioop.mul(data[2], 4, 2), data2[2])
def testlin2adpcm(data): def test_ratecv(self):
if verbose: state = None
print('lin2adpcm') d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
# Very cursory test d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
if audioop.lin2adpcm(b'\0\0\0\0', 1, None) != (b'\0\0', (0,0)): self.assertEqual(d1 + d2, b'\000\000\001\001\002\001\000\000\001\001\002')
return 0
return 1 def test_reverse(self):
self.assertEqual(audioop.reverse(data[0], 1), b'\2\1\0')
def testlin2alaw(data):
if verbose: def test_tomono(self):
print('lin2alaw') data2 = bytearray()
if audioop.lin2alaw(data[0], 1) != b'\xd5\xc5\xf5' or \ for d in data[0]:
audioop.lin2alaw(data[1], 2) != b'\xd5\xd5\xd5' or \ data2.append(d)
audioop.lin2alaw(data[2], 4) != b'\xd5\xd5\xd5': data2.append(d)
return 0 self.assertEqual(audioop.tomono(data2, 1, 0.5, 0.5), data[0])
return 1
def test_tostereo(self):
def testalaw2lin(data): data2 = bytearray()
if verbose: for d in data[0]:
print('alaw2lin') data2.append(d)
# Cursory data2.append(d)
d = audioop.lin2alaw(data[0], 1) self.assertEqual(audioop.tostereo(data[0], 1, 1, 1), data2)
if audioop.alaw2lin(d, 1) != data[0]:
return 0 def test_findfactor(self):
return 1 self.assertEqual(audioop.findfactor(data[1], data[1]), 1.0)
def testlin2ulaw(data): def test_findfit(self):
if verbose: self.assertEqual(audioop.findfit(data[1], data[1]), (0, 1.0))
print('lin2ulaw')
if audioop.lin2ulaw(data[0], 1) != b'\xff\xe7\xdb' or \ def test_findmax(self):
audioop.lin2ulaw(data[1], 2) != b'\xff\xff\xff' or \ self.assertEqual(audioop.findmax(data[1], 1), 2)
audioop.lin2ulaw(data[2], 4) != b'\xff\xff\xff':
return 0 def test_getsample(self):
return 1 for i in range(3):
self.assertEqual(audioop.getsample(data[0], 1, i), i)
def testulaw2lin(data): self.assertEqual(audioop.getsample(data[1], 2, i), i)
if verbose: self.assertEqual(audioop.getsample(data[2], 4, i), i)
print('ulaw2lin')
# Cursory
d = audioop.lin2ulaw(data[0], 1)
if audioop.ulaw2lin(d, 1) != data[0]:
return 0
return 1
def testmul(data):
if verbose:
print('mul')
data2 = []
for d in data:
str = bytearray(len(d))
for i,b in enumerate(d):
str[i] = 2*b
data2.append(str)
if audioop.mul(data[0], 1, 2) != data2[0] or \
audioop.mul(data[1],2, 2) != data2[1] or \
audioop.mul(data[2], 4, 2) != data2[2]:
return 0
return 1
def testratecv(data):
if verbose:
print('ratecv')
state = None
d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state)
if d1 + d2 != b'\000\000\001\001\002\001\000\000\001\001\002':
return 0
return 1
def testreverse(data):
if verbose:
print('reverse')
if audioop.reverse(data[0], 1) != b'\2\1\0':
return 0
return 1
def testtomono(data):
if verbose:
print('tomono')
data2 = bytearray()
for d in data[0]:
data2.append(d)
data2.append(d)
if audioop.tomono(data2, 1, 0.5, 0.5) != data[0]:
return 0
return 1
def testtostereo(data):
if verbose:
print('tostereo')
data2 = bytearray()
for d in data[0]:
data2.append(d)
data2.append(d)
if audioop.tostereo(data[0], 1, 1, 1) != data2:
return 0
return 1
def testfindfactor(data):
if verbose:
print('findfactor')
if audioop.findfactor(data[1], data[1]) != 1.0:
return 0
return 1
def testfindfit(data):
if verbose:
print('findfit')
if audioop.findfit(data[1], data[1]) != (0, 1.0):
return 0
return 1
def testfindmax(data):
if verbose:
print('findmax')
if audioop.findmax(data[1], 1) != 2:
return 0
return 1
def testgetsample(data):
if verbose:
print('getsample')
for i in range(3):
if audioop.getsample(data[0], 1, i) != i or \
audioop.getsample(data[1], 2, i) != i or \
audioop.getsample(data[2], 4, i) != i:
return 0
return 1
def testone(name, data):
try:
func = eval('test'+name)
except NameError:
print('No test found for audioop.'+name+'()')
return
try:
rv = func(data)
except Exception as e:
print('Test FAILED for audioop.'+name+'() (with %s)' % repr(e))
return
if not rv:
print('Test FAILED for audioop.'+name+'()')
def test_main():
data = [gendata1(), gendata2(), gendata4()]
names = dir(audioop)
# We know there is a routine 'add'
routines = []
for n in names:
if type(eval('audioop.'+n)) == type(audioop.add):
routines.append(n)
for n in routines:
testone(n, data)
def test_main():
run_unittest(TestAudioop)
if __name__ == '__main__': if __name__ == '__main__':
test_main() test_main()
...@@ -296,6 +296,21 @@ class TestCollectionABCs(unittest.TestCase): ...@@ -296,6 +296,21 @@ class TestCollectionABCs(unittest.TestCase):
self.failUnless(isinstance(sample(), Set)) self.failUnless(isinstance(sample(), Set))
self.failUnless(issubclass(sample, Set)) self.failUnless(issubclass(sample, Set))
def test_hash_Set(self):
class OneTwoThreeSet(Set):
def __init__(self):
self.contents = [1, 2, 3]
def __contains__(self, x):
return x in self.contents
def __len__(self):
return len(self.contents)
def __iter__(self):
return iter(self.contents)
def __hash__(self):
return self._hash()
a, b = OneTwoThreeSet(), OneTwoThreeSet()
self.failUnless(hash(a) == hash(b))
def test_MutableSet(self): def test_MutableSet(self):
self.failUnless(isinstance(set(), MutableSet)) self.failUnless(isinstance(set(), MutableSet))
self.failUnless(issubclass(set, MutableSet)) self.failUnless(issubclass(set, MutableSet))
......
...@@ -426,6 +426,9 @@ class DecimalExplicitConstructionTest(unittest.TestCase): ...@@ -426,6 +426,9 @@ class DecimalExplicitConstructionTest(unittest.TestCase):
self.assertEqual(str(Decimal('1.3E4 \n')), '1.3E+4') self.assertEqual(str(Decimal('1.3E4 \n')), '1.3E+4')
self.assertEqual(str(Decimal(' -7.89')), '-7.89') self.assertEqual(str(Decimal(' -7.89')), '-7.89')
#but alternate unicode digits should not
self.assertEqual(str(Decimal('\uff11')), 'NaN')
def test_explicit_from_tuples(self): def test_explicit_from_tuples(self):
#zero #zero
......
...@@ -364,6 +364,10 @@ class FractionTest(unittest.TestCase): ...@@ -364,6 +364,10 @@ class FractionTest(unittest.TestCase):
def testStringification(self): def testStringification(self):
self.assertEquals("Fraction(7, 3)", repr(F(7, 3))) self.assertEquals("Fraction(7, 3)", repr(F(7, 3)))
self.assertEquals("Fraction(6283185307, 2000000000)",
repr(F('3.1415926535')))
self.assertEquals("Fraction(-1, 100000000000000000000)",
repr(F(1, -10**20)))
self.assertEquals("7/3", str(F(7, 3))) self.assertEquals("7/3", str(F(7, 3)))
self.assertEquals("7", str(F(7, 1))) self.assertEquals("7", str(F(7, 1)))
......
...@@ -960,7 +960,6 @@ class _TestContainers(BaseTestCase): ...@@ -960,7 +960,6 @@ class _TestContainers(BaseTestCase):
def sqr(x, wait=0.0): def sqr(x, wait=0.0):
time.sleep(wait) time.sleep(wait)
return x*x return x*x
"""
class _TestPool(BaseTestCase): class _TestPool(BaseTestCase):
def test_apply(self): def test_apply(self):
...@@ -1030,7 +1029,6 @@ class _TestPool(BaseTestCase): ...@@ -1030,7 +1029,6 @@ class _TestPool(BaseTestCase):
join = TimingWrapper(self.pool.join) join = TimingWrapper(self.pool.join)
join() join()
self.assertTrue(join.elapsed < 0.2) self.assertTrue(join.elapsed < 0.2)
"""
# #
# Test that manager has expected number of shared objects left # Test that manager has expected number of shared objects left
# #
...@@ -1333,7 +1331,6 @@ class _TestConnection(BaseTestCase): ...@@ -1333,7 +1331,6 @@ class _TestConnection(BaseTestCase):
self.assertRaises(ValueError, a.send_bytes, msg, 4, -1) self.assertRaises(ValueError, a.send_bytes, msg, 4, -1)
"""
class _TestListenerClient(BaseTestCase): class _TestListenerClient(BaseTestCase):
ALLOWED_TYPES = ('processes', 'threads') ALLOWED_TYPES = ('processes', 'threads')
...@@ -1353,7 +1350,6 @@ class _TestListenerClient(BaseTestCase): ...@@ -1353,7 +1350,6 @@ class _TestListenerClient(BaseTestCase):
self.assertEqual(conn.recv(), 'hello') self.assertEqual(conn.recv(), 'hello')
p.join() p.join()
l.close() l.close()
"""
# #
# Test of sending connection and socket objects between processes # Test of sending connection and socket objects between processes
# #
...@@ -1769,28 +1765,28 @@ def test_main(run=None): ...@@ -1769,28 +1765,28 @@ def test_main(run=None):
multiprocessing.get_logger().setLevel(LOG_LEVEL) multiprocessing.get_logger().setLevel(LOG_LEVEL)
#ProcessesMixin.pool = multiprocessing.Pool(4) ProcessesMixin.pool = multiprocessing.Pool(4)
#ThreadsMixin.pool = multiprocessing.dummy.Pool(4) ThreadsMixin.pool = multiprocessing.dummy.Pool(4)
#ManagerMixin.manager.__init__() ManagerMixin.manager.__init__()
#ManagerMixin.manager.start() ManagerMixin.manager.start()
#ManagerMixin.pool = ManagerMixin.manager.Pool(4) ManagerMixin.pool = ManagerMixin.manager.Pool(4)
testcases = ( testcases = (
sorted(testcases_processes.values(), key=lambda tc:tc.__name__) #+ sorted(testcases_processes.values(), key=lambda tc:tc.__name__) +
#sorted(testcases_threads.values(), key=lambda tc:tc.__name__) + sorted(testcases_threads.values(), key=lambda tc:tc.__name__) +
#sorted(testcases_manager.values(), key=lambda tc:tc.__name__) sorted(testcases_manager.values(), key=lambda tc:tc.__name__)
) )
loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase loadTestsFromTestCase = unittest.defaultTestLoader.loadTestsFromTestCase
suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases) suite = unittest.TestSuite(loadTestsFromTestCase(tc) for tc in testcases)
run(suite) run(suite)
#ThreadsMixin.pool.terminate() ThreadsMixin.pool.terminate()
#ProcessesMixin.pool.terminate() ProcessesMixin.pool.terminate()
#ManagerMixin.pool.terminate() ManagerMixin.pool.terminate()
#ManagerMixin.manager.shutdown() ManagerMixin.manager.shutdown()
#del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool del ProcessesMixin.pool, ThreadsMixin.pool, ManagerMixin.pool
def main(): def main():
test_main(unittest.TextTestRunner(verbosity=2).run) test_main(unittest.TextTestRunner(verbosity=2).run)
......
...@@ -66,7 +66,6 @@ FUNCTIONS ...@@ -66,7 +66,6 @@ FUNCTIONS
DATA DATA
__author__ = 'Benjamin Peterson' __author__ = 'Benjamin Peterson'
__credits__ = 'Nobody' __credits__ = 'Nobody'
__package__ = None
__version__ = '1.2.3.4' __version__ = '1.2.3.4'
VERSION VERSION
...@@ -163,7 +162,6 @@ war</tt></dd></dl> ...@@ -163,7 +162,6 @@ war</tt></dd></dl>
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td> <tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%%"><strong>__author__</strong> = 'Benjamin Peterson'<br> <td width="100%%"><strong>__author__</strong> = 'Benjamin Peterson'<br>
<strong>__credits__</strong> = 'Nobody'<br> <strong>__credits__</strong> = 'Nobody'<br>
<strong>__package__</strong> = None<br>
<strong>__version__</strong> = '1.2.3.4'</td></tr></table><p> <strong>__version__</strong> = '1.2.3.4'</td></tr></table><p>
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section"> <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee"> <tr bgcolor="#7799ee">
......
...@@ -87,6 +87,7 @@ Dave Brennan ...@@ -87,6 +87,7 @@ Dave Brennan
Tom Bridgman Tom Bridgman
Richard Brodie Richard Brodie
Daniel Brotsky Daniel Brotsky
Jean Brouwers
Gary S. Brown Gary S. Brown
Oleg Broytmann Oleg Broytmann
Dave Brueck Dave Brueck
......
...@@ -1226,7 +1226,7 @@ dict_fromkeys(PyObject *cls, PyObject *args) ...@@ -1226,7 +1226,7 @@ dict_fromkeys(PyObject *cls, PyObject *args)
PyObject *key; PyObject *key;
long hash; long hash;
if (dictresize(mp, PySet_GET_SIZE(seq))) if (dictresize(mp, Py_SIZE(seq)))
return NULL; return NULL;
while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) { while (_PyDict_Next(seq, &pos, &key, &oldvalue, &hash)) {
......
...@@ -1136,6 +1136,17 @@ class PyBuildExt(build_ext): ...@@ -1136,6 +1136,17 @@ class PyBuildExt(build_ext):
HAVE_BROKEN_SEM_UNLINK=1 HAVE_BROKEN_SEM_UNLINK=1
) )
libraries = [] libraries = []
elif platform in ('freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'):
# FreeBSD's P1003.1b semaphore support is very experimental
# and has many known problems. (as of June 2008)
macros = dict( # FreeBSD
HAVE_SEM_OPEN=0,
HAVE_SEM_TIMEDWAIT=0,
HAVE_FD_TRANSFER=1,
)
libraries = []
else: # Linux and other unices else: # Linux and other unices
macros = dict( macros = dict(
HAVE_SEM_OPEN=1, HAVE_SEM_OPEN=1,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment