[Python-checkins] r60788 - in python/branches/trunk-math: Doc/library/collections.rst Doc/library/ctypes.rst Doc/library/decimal.rst Doc/library/fractions.rst Doc/library/numeric.rst Doc/library/os.rst Lib/abc.py Lib/ctypes/test/test_pickling.py Lib/decimal.py Lib/fractions.py Lib/httplib.py Lib/idlelib/NEWS.txt Lib/idlelib/configHandler.py Lib/numbers.py Lib/test/test_abc.py Lib/test/test_decimal.py Lib/test/test_fractions.py Misc/NEWS Modules/_collectionsmodule.c Modules/_ctypes/_ctypes.c Modules/_ctypes/callproc.c Modules/_ctypes/ctypes.h Modules/_ctypes/stgdict.c Modules/posixmodule.c Objects/dictobject.c Objects/setobject.c PC/_msi.c configure configure.in

christian.heimes python-checkins at python.org
Thu Feb 14 09:32:41 CET 2008


Author: christian.heimes
Date: Thu Feb 14 09:32:39 2008
New Revision: 60788

Added:
   python/branches/trunk-math/Lib/ctypes/test/test_pickling.py
      - copied unchanged from r60786, python/trunk/Lib/ctypes/test/test_pickling.py
Modified:
   python/branches/trunk-math/   (props changed)
   python/branches/trunk-math/Doc/library/collections.rst
   python/branches/trunk-math/Doc/library/ctypes.rst
   python/branches/trunk-math/Doc/library/decimal.rst
   python/branches/trunk-math/Doc/library/fractions.rst
   python/branches/trunk-math/Doc/library/numeric.rst
   python/branches/trunk-math/Doc/library/os.rst
   python/branches/trunk-math/Lib/abc.py
   python/branches/trunk-math/Lib/decimal.py
   python/branches/trunk-math/Lib/fractions.py
   python/branches/trunk-math/Lib/httplib.py
   python/branches/trunk-math/Lib/idlelib/NEWS.txt
   python/branches/trunk-math/Lib/idlelib/configHandler.py
   python/branches/trunk-math/Lib/numbers.py
   python/branches/trunk-math/Lib/test/test_abc.py
   python/branches/trunk-math/Lib/test/test_decimal.py
   python/branches/trunk-math/Lib/test/test_fractions.py
   python/branches/trunk-math/Misc/NEWS
   python/branches/trunk-math/Modules/_collectionsmodule.c
   python/branches/trunk-math/Modules/_ctypes/_ctypes.c
   python/branches/trunk-math/Modules/_ctypes/callproc.c
   python/branches/trunk-math/Modules/_ctypes/ctypes.h
   python/branches/trunk-math/Modules/_ctypes/stgdict.c
   python/branches/trunk-math/Modules/posixmodule.c
   python/branches/trunk-math/Objects/dictobject.c
   python/branches/trunk-math/Objects/setobject.c
   python/branches/trunk-math/PC/_msi.c
   python/branches/trunk-math/configure
   python/branches/trunk-math/configure.in
Log:
Merged revisions 60735-60787 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r60735 | raymond.hettinger | 2008-02-11 23:53:01 +0100 (Mon, 11 Feb 2008) | 1 line
  
  Add notes on how decimal fits into the model.
........
  r60737 | raymond.hettinger | 2008-02-12 00:34:56 +0100 (Tue, 12 Feb 2008) | 1 line
  
  Fix markup
........
  r60738 | raymond.hettinger | 2008-02-12 00:38:00 +0100 (Tue, 12 Feb 2008) | 1 line
  
  Backport ABC docs
........
  r60739 | raymond.hettinger | 2008-02-12 01:15:32 +0100 (Tue, 12 Feb 2008) | 1 line
  
  Restore fractions.rst to the document tree.
........
  r60740 | raymond.hettinger | 2008-02-12 01:48:20 +0100 (Tue, 12 Feb 2008) | 1 line
  
  Fix typo in comments
........
  r60741 | raymond.hettinger | 2008-02-12 02:18:03 +0100 (Tue, 12 Feb 2008) | 1 line
  
  Bring decimal a bit closer to the spec for Reals.
........
  r60743 | martin.v.loewis | 2008-02-12 14:47:26 +0100 (Tue, 12 Feb 2008) | 2 lines
  
  Patch #1736: Fix file name handling of _msi.FCICreate.
........
  r60745 | kurt.kaiser | 2008-02-12 16:45:50 +0100 (Tue, 12 Feb 2008) | 2 lines
  
  what??! Correct r60225.
........
  r60747 | martin.v.loewis | 2008-02-12 19:47:34 +0100 (Tue, 12 Feb 2008) | 4 lines
  
  Patch #1966: Break infinite loop in httplib when the servers
  implements the chunked encoding incorrectly.
  Will backport to 2.5.
........
  r60749 | raymond.hettinger | 2008-02-12 20:05:36 +0100 (Tue, 12 Feb 2008) | 1 line
  
  dict.copy() rises from the ashes.  Revert r60687.
........
  r60752 | mark.dickinson | 2008-02-12 22:31:59 +0100 (Tue, 12 Feb 2008) | 5 lines
  
  Implementation of Fraction.limit_denominator.
  
  Remove Fraction.to_continued_fraction and
  Fraction.from_continued_fraction
........
  r60754 | mark.dickinson | 2008-02-12 22:40:53 +0100 (Tue, 12 Feb 2008) | 3 lines
  
  Revert change in r60712:  turn alternate constructors back into
  classmethods instead of staticmethods.
........
  r60755 | mark.dickinson | 2008-02-12 22:46:54 +0100 (Tue, 12 Feb 2008) | 4 lines
  
  Replace R=fractions.Fraction with F=fractions.Fraction in
  test_fractions.py.  This should have been part of the name
  change from Rational to Fraction.
........
  r60758 | georg.brandl | 2008-02-13 08:20:22 +0100 (Wed, 13 Feb 2008) | 3 lines
  
  #2063: correct order of utime and stime in os.times()
  result on Windows.
........
  r60762 | jeffrey.yasskin | 2008-02-13 18:58:04 +0100 (Wed, 13 Feb 2008) | 7 lines
  
  Working on issue #1762: Brought 
    ./python.exe -m timeit -s 'from fractions import Fraction; f = Fraction(3, 2)' 'isinstance(3, Fraction); isinstance(f, Fraction)'
  from 12.3 usec/loop to 3.44 usec/loop and 
    ./python.exe -m timeit -s 'from fractions import Fraction' 'Fraction(3, 2)'
  from 48.8 usec to 23.6 usec by avoiding genexps and sets in __instancecheck__
  and inlining the common case from __subclasscheck__.
........
  r60765 | brett.cannon | 2008-02-13 20:15:44 +0100 (Wed, 13 Feb 2008) | 5 lines
  
  Fix --enable-universalsdk and its comment line so that zsh's flag completion
  works.
  
  Thanks to Jeroen Ruigrok van der Werven for the fix.
........
  r60767 | thomas.heller | 2008-02-13 21:21:53 +0100 (Wed, 13 Feb 2008) | 1 line
  
  Add pickle support to ctypes types.
........
  r60768 | thomas.heller | 2008-02-13 21:36:51 +0100 (Wed, 13 Feb 2008) | 1 line
  
  Make the test somewhat clearer (I hope).
........
  r60771 | kurt.kaiser | 2008-02-14 01:08:55 +0100 (Thu, 14 Feb 2008) | 2 lines
  
  Bring NEWS.txt up to date from check-in msgs.
........
  r60772 | raymond.hettinger | 2008-02-14 02:08:02 +0100 (Thu, 14 Feb 2008) | 3 lines
  
  Update notes on Decimal.
........
  r60773 | raymond.hettinger | 2008-02-14 03:41:22 +0100 (Thu, 14 Feb 2008) | 1 line
  
  Fix decimal repr which should have used single quotes like other reprs.
........
  r60785 | jeffrey.yasskin | 2008-02-14 07:12:24 +0100 (Thu, 14 Feb 2008) | 11 lines
  
  Performance optimizations on Fraction's constructor.
  
    ./python.exe -m timeit -s 'from fractions import Fraction' 'Fraction(3)`
  31.7 usec/loop -> 9.2 usec/loop
  
    ./python.exe -m timeit -s 'from fractions import Fraction' 'Fraction(3, 2)'`
  27.7 usec/loop -> 9.32 usec/loop
  
    ./python.exe -m timeit -s 'from fractions import Fraction; f = Fraction(3, 2)' 'Fraction(f)'
  31.9 usec/loop -> 14.3 usec/loop
........
  r60786 | jeffrey.yasskin | 2008-02-14 08:49:25 +0100 (Thu, 14 Feb 2008) | 5 lines
  
  Change simple instances (in Fraction) of self.numerator and self.denominator to
  self._numerator and self._denominator. This speeds abs() up from 12.2us to
  10.8us and trunc() from 2.07us to 1.11us. This doesn't change _add and friends
  because they're more complicated.
........


Modified: python/branches/trunk-math/Doc/library/collections.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/collections.rst	(original)
+++ python/branches/trunk-math/Doc/library/collections.rst	Thu Feb 14 09:32:39 2008
@@ -12,14 +12,7 @@
 
 This module implements high-performance container datatypes.  Currently,
 there are two datatypes, :class:`deque` and :class:`defaultdict`, and
-one datatype factory function, :func:`namedtuple`. Python already
-includes built-in containers, :class:`dict`, :class:`list`,
-:class:`set`, and :class:`tuple`. In addition, the optional :mod:`bsddb`
-module has a :meth:`bsddb.btopen` method that can be used to create in-memory
-or file based ordered dictionaries with string keys.
-
-Future editions of the standard library may include balanced trees and
-ordered dictionaries.
+one datatype factory function, :func:`namedtuple`. 
 
 .. versionchanged:: 2.5
    Added :class:`defaultdict`.
@@ -27,6 +20,125 @@
 .. versionchanged:: 2.6
    Added :func:`namedtuple`.
 
+The specialized containers provided in this module provide alternatives
+to Python's general purpose built-in containers, :class:`dict`, 
+:class:`list`, :class:`set`, and :class:`tuple`.
+
+Besides the containers provided here, the optional :mod:`bsddb`
+module offers the ability to create in-memory or file based ordered 
+dictionaries with string keys using the :meth:`bsddb.btopen` method.
+
+In addition to containers, the collections module provides some ABCs
+(abstract base classes) that can be used to test whether a class 
+provides a particular interface, for example, is it hashable or
+a mapping. 
+
+.. versionchanged:: 2.6
+   Added abstract base classes.
+
+ABCs - abstract base classes
+----------------------------
+
+The collections module offers the following ABCs:
+
+=========================  ====================  ======================  ====================================================
+ABC                        Inherits              Abstract Methods        Mixin Methods
+=========================  ====================  ======================  ====================================================
+:class:`Container`                               ``__contains__``
+:class:`Hashable`                                ``__hash__``
+:class:`Iterable`                                ``__iter__``
+:class:`Iterator`          :class:`Iterable`     ``__next__``            ``__iter__``
+:class:`Sized`          			 ``__len__``
+
+:class:`Mapping`           :class:`Sized`,       ``__getitem__``,        ``__contains__``, ``keys``, ``items``, ``values``,
+                           :class:`Iterable`,    ``__len__``. and        ``get``, ``__eq__``, and ``__ne__``
+                           :class:`Container`    ``__iter__``
+
+:class:`MutableMapping`    :class:`Mapping`      ``__getitem__``         Inherited Mapping methods and
+                                                 ``__setitem__``,        ``pop``, ``popitem``, ``clear``, ``update``,
+                                                 ``__delitem__``,        and ``setdefault``
+						 ``__iter__``, and
+                                                 ``__len__``
+
+:class:`Sequence`          :class:`Sized`,       ``__getitem__``         ``__contains__``. ``__iter__``, ``__reversed__``.
+                           :class:`Iterable`,    and ``__len__``         ``index``, and ``count``
+                           :class:`Container`
+
+:class:`MutableSequnce`    :class:`Sequence`     ``__getitem__``         Inherited Sequence methods and
+                                                 ``__delitem__``,        ``append``, ``reverse``, ``extend``, ``pop``,
+                                                 ``insert``,             ``remove``, and ``__iadd__``
+                                                 and ``__len__``
+
+:class:`Set`               :class:`Sized`,       ``__len__``,            ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``,
+                           :class:`Iterable`,    ``__iter__``, and       ``__gt__``, ``__ge__``, ``__and__``, ``__or__``
+                           :class:`Container`    ``__contains__``        ``__sub__``, ``__xor__``, and ``isdisjoint``
+
+:class:`MutableSet`        :class:`Set`          ``add`` and             Inherited Set methods and
+                                                 ``discard``             ``clear``, ``pop``, ``remove``, ``__ior__``,
+                                                                         ``__iand__``, ``__ixor__``, and ``__isub__``
+=========================  ====================  ======================  ====================================================
+
+These ABCs allow us to ask classes or instances if they provide
+particular functionality, for example::
+
+    size = None
+    if isinstance(myvar, collections.Sized):
+	size = len(myvar)
+
+Several of the ABCs are also useful as mixins that make it easier to develop
+classes supporting container APIs.  For example, to write a class supporting
+the full :class:`Set` API, it only necessary to supply the three underlying
+abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`.
+The ABC supplies the remaining methods such as :meth:`__and__` and
+:meth:`isdisjoint` ::
+
+    class ListBasedSet(collections.Set):
+         ''' Alternate set implementation favoring space over speed
+             and not requiring the set elements to be hashable. '''
+         def __init__(self, iterable):
+             self.elements = lst = []
+             for value in iterable:
+                 if value not in lst:
+                     lst.append(value)
+         def __iter__(self):
+             return iter(self.elements)
+         def __contains__(self, value):
+             return value in self.elements
+         def __len__(self):
+             return len(self.elements)
+
+    s1 = ListBasedSet('abcdef')
+    s2 = ListBasedSet('defghi')
+    overlap = s1 & s2            # The __and__() method is supported automatically
+
+Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
+
+(1) 
+   Since some set operations create new sets, the default mixin methods need
+   a way to create new instances from an iterable. The class constructor is 
+   assumed to have a signature in the form ``ClassName(iterable)``.  
+   That assumption is factored-out to a singleinternal classmethod called
+   :meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set.
+   If the :class:`Set` mixin is being used in a class with a different
+   constructor signature, you will need to override :meth:`from_iterable` 
+   with a classmethod that can construct new instances from 
+   an iterable argument.
+
+(2)
+   To override the comparisons (presumably for speed, as the
+   semantics are fixed), redefine :meth:`__le__` and
+   then the other operations will automatically follow suit.
+
+(3)
+   The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value
+   for the set; however, :meth:`__hash__` is not defined because not all sets
+   are hashable or immutable.  To add set hashabilty using mixins,
+   inherit from both :meth:`Set` and :meth:`Hashable`, then define
+   ``__hash__ = Set._hash``.
+
+(For more about ABCs, see the :mod:`abc` module and :pep:`3119`.)
+
+
 
 .. _deque-objects:
 

Modified: python/branches/trunk-math/Doc/library/ctypes.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/ctypes.rst	(original)
+++ python/branches/trunk-math/Doc/library/ctypes.rst	Thu Feb 14 09:32:39 2008
@@ -2011,6 +2011,11 @@
    ctypes data types.  ``_SimpleCData`` is a subclass of ``_CData``, so it inherits
    their methods and attributes.
 
+   .. versionchanged:: 2.6
+
+      ctypes data types that are not and do not contain pointers can
+      now be pickled.
+
 Instances have a single attribute:
 
 

Modified: python/branches/trunk-math/Doc/library/decimal.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/decimal.rst	(original)
+++ python/branches/trunk-math/Doc/library/decimal.rst	Thu Feb 14 09:32:39 2008
@@ -51,10 +51,10 @@
 
      >>> getcontext().prec = 6
      >>> Decimal(1) / Decimal(7)
-     Decimal("0.142857")
+     Decimal('0.142857')
      >>> getcontext().prec = 28
      >>> Decimal(1) / Decimal(7)
-     Decimal("0.1428571428571428571428571429")
+     Decimal('0.1428571428571428571428571429')
 
 * Both binary and decimal floating point are implemented in terms of published
   standards.  While the built-in float type exposes only a modest portion of its
@@ -133,19 +133,19 @@
 :const:`Infinity`, and :const:`-0`.         ::
 
    >>> Decimal(10)
-   Decimal("10")
-   >>> Decimal("3.14")
-   Decimal("3.14")
+   Decimal('10')
+   >>> Decimal('3.14')
+   Decimal('3.14')
    >>> Decimal((0, (3, 1, 4), -2))
-   Decimal("3.14")
+   Decimal('3.14')
    >>> Decimal(str(2.0 ** 0.5))
-   Decimal("1.41421356237")
-   >>> Decimal(2) ** Decimal("0.5")
-   Decimal("1.414213562373095048801688724")
-   >>> Decimal("NaN")
-   Decimal("NaN")
-   >>> Decimal("-Infinity")
-   Decimal("-Infinity")
+   Decimal('1.41421356237')
+   >>> Decimal(2) ** Decimal('0.5')
+   Decimal('1.414213562373095048801688724')
+   >>> Decimal('NaN')
+   Decimal('NaN')
+   >>> Decimal('-Infinity')
+   Decimal('-Infinity')
 
 The significance of a new Decimal is determined solely by the number of digits
 input.  Context precision and rounding only come into play during arithmetic
@@ -153,28 +153,28 @@
 
    >>> getcontext().prec = 6
    >>> Decimal('3.0')
-   Decimal("3.0")
+   Decimal('3.0')
    >>> Decimal('3.1415926535')
-   Decimal("3.1415926535")
+   Decimal('3.1415926535')
    >>> Decimal('3.1415926535') + Decimal('2.7182818285')
-   Decimal("5.85987")
+   Decimal('5.85987')
    >>> getcontext().rounding = ROUND_UP
    >>> Decimal('3.1415926535') + Decimal('2.7182818285')
-   Decimal("5.85988")
+   Decimal('5.85988')
 
 Decimals interact well with much of the rest of Python.  Here is a small decimal
 floating point flying circus::
 
    >>> data = map(Decimal, '1.34 1.87 3.45 2.35 1.00 0.03 9.25'.split())
    >>> max(data)
-   Decimal("9.25")
+   Decimal('9.25')
    >>> min(data)
-   Decimal("0.03")
+   Decimal('0.03')
    >>> sorted(data)
-   [Decimal("0.03"), Decimal("1.00"), Decimal("1.34"), Decimal("1.87"),
-    Decimal("2.35"), Decimal("3.45"), Decimal("9.25")]
+   [Decimal('0.03'), Decimal('1.00'), Decimal('1.34'), Decimal('1.87'),
+    Decimal('2.35'), Decimal('3.45'), Decimal('9.25')]
    >>> sum(data)
-   Decimal("19.29")
+   Decimal('19.29')
    >>> a,b,c = data[:3]
    >>> str(a)
    '1.34'
@@ -185,31 +185,31 @@
    >>> int(a)
    1
    >>> a * 5
-   Decimal("6.70")
+   Decimal('6.70')
    >>> a * b
-   Decimal("2.5058")
+   Decimal('2.5058')
    >>> c % a
-   Decimal("0.77")
+   Decimal('0.77')
 
 And some mathematical functions are also available to Decimal::
 
    >>> Decimal(2).sqrt()
-   Decimal("1.414213562373095048801688724")
+   Decimal('1.414213562373095048801688724')
    >>> Decimal(1).exp()
-   Decimal("2.718281828459045235360287471")
-   >>> Decimal("10").ln()
-   Decimal("2.302585092994045684017991455")
-   >>> Decimal("10").log10()
-   Decimal("1")
+   Decimal('2.718281828459045235360287471')
+   >>> Decimal('10').ln()
+   Decimal('2.302585092994045684017991455')
+   >>> Decimal('10').log10()
+   Decimal('1')
 
 The :meth:`quantize` method rounds a number to a fixed exponent.  This method is
 useful for monetary applications that often round results to a fixed number of
 places::
 
    >>> Decimal('7.325').quantize(Decimal('.01'), rounding=ROUND_DOWN)
-   Decimal("7.32")
+   Decimal('7.32')
    >>> Decimal('7.325').quantize(Decimal('1.'), rounding=ROUND_UP)
-   Decimal("8")
+   Decimal('8')
 
 As shown above, the :func:`getcontext` function accesses the current context and
 allows the settings to be changed.  This approach meets the needs of most
@@ -227,16 +227,16 @@
    >>> myothercontext = Context(prec=60, rounding=ROUND_HALF_DOWN)
    >>> setcontext(myothercontext)
    >>> Decimal(1) / Decimal(7)
-   Decimal("0.142857142857142857142857142857142857142857142857142857142857")
+   Decimal('0.142857142857142857142857142857142857142857142857142857142857')
 
    >>> ExtendedContext
    Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999,
            capitals=1, flags=[], traps=[])
    >>> setcontext(ExtendedContext)
    >>> Decimal(1) / Decimal(7)
-   Decimal("0.142857143")
+   Decimal('0.142857143')
    >>> Decimal(42) / Decimal(0)
-   Decimal("Infinity")
+   Decimal('Infinity')
 
    >>> setcontext(BasicContext)
    >>> Decimal(42) / Decimal(0)
@@ -253,7 +253,7 @@
    >>> setcontext(ExtendedContext)
    >>> getcontext().clear_flags()
    >>> Decimal(355) / Decimal(113)
-   Decimal("3.14159292")
+   Decimal('3.14159292')
    >>> getcontext()
    Context(prec=9, rounding=ROUND_HALF_EVEN, Emin=-999999999, Emax=999999999,
            capitals=1, flags=[Inexact, Rounded], traps=[])
@@ -266,7 +266,7 @@
 context::
 
    >>> Decimal(1) / Decimal(0)
-   Decimal("Infinity")
+   Decimal('Infinity')
    >>> getcontext().traps[DivisionByZero] = 1
    >>> Decimal(1) / Decimal(0)
    Traceback (most recent call last):
@@ -294,7 +294,7 @@
    Construct a new :class:`Decimal` object based from *value*.
 
    *value* can be an integer, string, tuple, or another :class:`Decimal`
-   object. If no *value* is given, returns ``Decimal("0")``.  If *value* is a
+   object. If no *value* is given, returns ``Decimal('0')``.  If *value* is a
    string, it should conform to the decimal numeric string syntax after leading
    and trailing whitespace characters are removed::
 
@@ -312,11 +312,11 @@
    If *value* is a :class:`tuple`, it should have three components, a sign
    (:const:`0` for positive or :const:`1` for negative), a :class:`tuple` of
    digits, and an integer exponent. For example, ``Decimal((0, (1, 4, 1, 4), -3))``
-   returns ``Decimal("1.414")``.
+   returns ``Decimal('1.414')``.
 
    The *context* precision does not affect how many digits are stored. That is
    determined exclusively by the number of digits in *value*. For example,
-   ``Decimal("3.00000")`` records all five zeros even if the context precision is
+   ``Decimal('3.00000')`` records all five zeros even if the context precision is
    only three.
 
    The purpose of the *context* argument is determining what to do if *value* is a
@@ -343,7 +343,7 @@
 .. method:: Decimal.adjusted()
 
    Return the adjusted exponent after shifting out the coefficient's rightmost
-   digits until only the lead digit remains: ``Decimal("321e+5").adjusted()``
+   digits until only the lead digit remains: ``Decimal('321e+5').adjusted()``
    returns seven.  Used for determining the position of the most significant digit
    with respect to the decimal point.
 
@@ -373,10 +373,10 @@
    instance rather than an integer, and if either operand is a NaN
    then the result is a NaN::
 
-      a or b is a NaN ==> Decimal("NaN")
-      a < b           ==> Decimal("-1")
-      a == b          ==> Decimal("0")
-      a > b           ==> Decimal("1")
+      a or b is a NaN ==> Decimal('NaN')
+      a < b           ==> Decimal('-1')
+      a == b          ==> Decimal('0')
+      a > b           ==> Decimal('1')
 
 .. method:: Decimal.compare_signal(other[, context])
 
@@ -396,14 +396,14 @@
    value but different representations compare unequal in this
    ordering::
    
-      >>> Decimal("12.0").compare_total(Decimal("12"))
-      Decimal("-1")
+      >>> Decimal('12.0').compare_total(Decimal('12'))
+      Decimal('-1')
 
    Quiet and signaling NaNs are also included in the total ordering.
-   The result of this function is ``Decimal("0")`` if both operands
-   have the same representation, ``Decimal("-1")`` if the first
+   The result of this function is ``Decimal('0')`` if both operands
+   have the same representation, ``Decimal('-1')`` if the first
    operand is lower in the total order than the second, and
-   ``Decimal("1")`` if the first operand is higher in the total order
+   ``Decimal('1')`` if the first operand is higher in the total order
    than the second operand.  See the specification for details of the
    total order.
 
@@ -439,8 +439,8 @@
    Return a copy of the first operand with the sign set to be the
    same as the sign of the second operand.  For example::
 
-      >>> Decimal("2.3").copy_sign(Decimal("-1.5"))
-      Decimal("-2.3")
+      >>> Decimal('2.3').copy_sign(Decimal('-1.5'))
+      Decimal('-2.3')
    
    This operation is unaffected by the context and is quiet: no flags
    are changed and no rounding is performed.
@@ -454,9 +454,9 @@
    :const:`ROUND_HALF_EVEN` rounding mode.
 
    >>> Decimal(1).exp()
-   Decimal("2.718281828459045235360287471")
+   Decimal('2.718281828459045235360287471')
    >>> Decimal(321).exp()
-   Decimal("2.561702493119680037517373933E+139")
+   Decimal('2.561702493119680037517373933E+139')
 
    .. versionadded:: 2.6
 
@@ -466,7 +466,7 @@
    the intermediate product self*other.
 
    >>> Decimal(2).fma(3, 5)
-   Decimal("11")
+   Decimal('11')
 
    .. versionadded:: 2.6
 
@@ -563,9 +563,9 @@
 
    For a nonzero number, return the adjusted exponent of its operand
    as a :class:`Decimal` instance.  If the operand is a zero then
-   ``Decimal("-Infinity")`` is returned and the
+   ``Decimal('-Infinity')`` is returned and the
    :const:`DivisionByZero` flag is raised.  If the operand is an
-   infinity then ``Decimal("Infinity")`` is returned.
+   infinity then ``Decimal('Infinity')`` is returned.
 
    .. versionadded:: 2.6
 
@@ -655,10 +655,10 @@
 .. method:: Decimal.normalize([context])
 
    Normalize the number by stripping the rightmost trailing zeros and converting
-   any result equal to :const:`Decimal("0")` to :const:`Decimal("0e0")`. Used for
+   any result equal to :const:`Decimal('0')` to :const:`Decimal('0e0')`. Used for
    producing canonical values for members of an equivalence class. For example,
-   ``Decimal("32.100")`` and ``Decimal("0.321000e+2")`` both normalize to the
-   equivalent value ``Decimal("32.1")``.
+   ``Decimal('32.100')`` and ``Decimal('0.321000e+2')`` both normalize to the
+   equivalent value ``Decimal('32.1')``.
 
 .. method:: Decimal.number_class([context])
 
@@ -683,8 +683,8 @@
    Return a value equal to the first operand after rounding and
    having the exponent of the second operand.
 
-   >>> Decimal("1.41421356").quantize(Decimal("1.000"))
-   Decimal("1.414")
+   >>> Decimal('1.41421356').quantize(Decimal('1.000'))
+   Decimal('1.414')
 
    Unlike other operations, if the length of the coefficient after the
    quantize operation would be greater than precision, then an
@@ -716,7 +716,7 @@
 
    Compute the modulo as either a positive or negative value depending on which is
    closest to zero.  For instance, ``Decimal(10).remainder_near(6)`` returns
-   ``Decimal("-2")`` which is closer to zero than ``Decimal("4")``.
+   ``Decimal('-2')`` which is closer to zero than ``Decimal('4')``.
 
    If both are equally close, the one chosen will have the same sign as *self*.
 
@@ -771,7 +771,7 @@
 
    Engineering notation has an exponent which is a multiple of 3, so there are up
    to 3 digits left of the decimal place.  For example, converts
-   ``Decimal('123E+1')`` to ``Decimal("1.23E+3")``
+   ``Decimal('123E+1')`` to ``Decimal('1.23E+3')``
 
 .. method:: Decimal.to_integral([rounding[, context]])
 
@@ -985,10 +985,10 @@
    change the result::
 
       >>> getcontext().prec = 3
-      >>> Decimal("3.4445") + Decimal("1.0023")
-      Decimal("4.45")
-      >>> Decimal("3.4445") + Decimal(0) + Decimal("1.0023")
-      Decimal("4.44")
+      >>> Decimal('3.4445') + Decimal('1.0023')
+      Decimal('4.45')
+      >>> Decimal('3.4445') + Decimal(0) + Decimal('1.0023')
+      Decimal('4.44')
 
    This method implements the to-number operation of the IBM
    specification.  If the argument is a string, no leading or trailing
@@ -1247,15 +1247,15 @@
 
    >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
    >>> (u + v) + w
-   Decimal("9.5111111")
+   Decimal('9.5111111')
    >>> u + (v + w)
-   Decimal("10")
+   Decimal('10')
 
    >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
    >>> (u*v) + (u*w)
-   Decimal("0.01")
+   Decimal('0.01')
    >>> u * (v+w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
 
 The :mod:`decimal` module makes it possible to restore the identities by
 expanding the precision sufficiently to avoid loss of significance::
@@ -1263,15 +1263,15 @@
    >>> getcontext().prec = 20
    >>> u, v, w = Decimal(11111113), Decimal(-11111111), Decimal('7.51111111')
    >>> (u + v) + w
-   Decimal("9.51111111")
+   Decimal('9.51111111')
    >>> u + (v + w)
-   Decimal("9.51111111")
+   Decimal('9.51111111')
    >>> 
    >>> u, v, w = Decimal(20000), Decimal(-6), Decimal('6.0000003')
    >>> (u*v) + (u*w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
    >>> u * (v+w)
-   Decimal("0.0060000")
+   Decimal('0.0060000')
 
 
 Special values
@@ -1327,7 +1327,7 @@
 the following calculation returns a value equal to zero::
 
    >>> 1 / Decimal('Infinity')
-   Decimal("0E-1000000026")
+   Decimal('0E-1000000026')
 
 .. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -1538,7 +1538,7 @@
 
    >>> D = decimal.Decimal
    >>> D('1.23') + D('3.45')
-   Decimal("4.68")
+   Decimal('4.68')
 
 Q. In a fixed-point application with two decimal places, some inputs have many
 places and need to be rounded.  Others are not supposed to have excess digits
@@ -1550,14 +1550,14 @@
    >>> TWOPLACES = Decimal(10) ** -2       # same as Decimal('0.01')
 
    >>> # Round to two places
-   >>> Decimal("3.214").quantize(TWOPLACES)
-   Decimal("3.21")
+   >>> Decimal('3.214').quantize(TWOPLACES)
+   Decimal('3.21')
 
    >>> # Validate that a number does not exceed two places 
-   >>> Decimal("3.21").quantize(TWOPLACES, context=Context(traps=[Inexact]))
-   Decimal("3.21")
+   >>> Decimal('3.21').quantize(TWOPLACES, context=Context(traps=[Inexact]))
+   Decimal('3.21')
 
-   >>> Decimal("3.214").quantize(TWOPLACES, context=Context(traps=[Inexact]))
+   >>> Decimal('3.214').quantize(TWOPLACES, context=Context(traps=[Inexact]))
    Traceback (most recent call last):
       ...
    Inexact: Changed in rounding
@@ -1579,7 +1579,7 @@
 
    >>> values = map(Decimal, '200 200.000 2E2 .02E+4'.split())
    >>> [v.normalize() for v in values]
-   [Decimal("2E+2"), Decimal("2E+2"), Decimal("2E+2"), Decimal("2E+2")]
+   [Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2'), Decimal('2E+2')]
 
 Q. Some decimal values always print with exponential notation.  Is there a way
 to get a non-exponential representation?
@@ -1607,7 +1607,7 @@
                     ctx.prec += 1
 
     >>> float_to_decimal(math.pi)
-    Decimal("3.141592653589793115997963468544185161590576171875")
+    Decimal('3.141592653589793115997963468544185161590576171875')
 
 Q. Why isn't the :func:`float_to_decimal` routine included in the module?
 
@@ -1616,7 +1616,7 @@
 representation issues associated with binary floating point::
 
    >>> float_to_decimal(1.1)
-   Decimal("1.100000000000000088817841970012523233890533447265625")
+   Decimal('1.100000000000000088817841970012523233890533447265625')
 
 Q. Within a complex calculation, how can I make sure that I haven't gotten a
 spurious result because of insufficient precision or rounding anomalies.
@@ -1637,20 +1637,20 @@
 
    >>> getcontext().prec = 3
    >>> Decimal('3.104') + D('2.104')
-   Decimal("5.21")
+   Decimal('5.21')
    >>> Decimal('3.104') + D('0.000') + D('2.104')
-   Decimal("5.20")
+   Decimal('5.20')
 
 The solution is either to increase precision or to force rounding of inputs
 using the unary plus operation::
 
    >>> getcontext().prec = 3
    >>> +Decimal('1.23456789')      # unary plus triggers rounding
-   Decimal("1.23")
+   Decimal('1.23')
 
 Alternatively, inputs can be rounded upon creation using the
 :meth:`Context.create_decimal` method::
 
    >>> Context(prec=5, rounding=ROUND_DOWN).create_decimal('1.2345678')
-   Decimal("1.2345")
+   Decimal('1.2345')
 

Modified: python/branches/trunk-math/Doc/library/fractions.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/fractions.rst	(original)
+++ python/branches/trunk-math/Doc/library/fractions.rst	Thu Feb 14 09:32:39 2008
@@ -1,6 +1,6 @@
 
 :mod:`fractions` --- Rational numbers
-====================================
+=====================================
 
 .. module:: fractions
    :synopsis: Rational numbers.
@@ -46,6 +46,24 @@
    :class:`decimal.Decimal`.
 
 
+.. method:: Fraction.limit_denominator(max_denominator=1000000)
+
+   Finds and returns the closest :class:`Fraction` to ``self`` that
+   has denominator at most max_denominator.  This method is useful for
+   finding rational approximations to a given floating-point number::
+
+      >>> Fraction('3.1415926535897932').limit_denominator(1000)
+      Fraction(355, 113)
+
+   or for recovering a rational number that's represented as a float::
+
+      >>> from math import pi, cos
+      >>> Fraction.from_float(cos(pi/3))
+      Fraction(4503599627370497L, 9007199254740992L)
+      >>> Fraction.from_float(cos(pi/3)).limit_denominator()
+      Fraction(1, 2)
+
+
 .. method:: Fraction.__floor__()
 
    Returns the greatest :class:`int` ``<= self``. Will be accessible

Modified: python/branches/trunk-math/Doc/library/numeric.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/numeric.rst	(original)
+++ python/branches/trunk-math/Doc/library/numeric.rst	Thu Feb 14 09:32:39 2008
@@ -21,7 +21,7 @@
    math.rst
    cmath.rst
    decimal.rst
-   rational.rst
+   fractions.rst
    random.rst
    itertools.rst
    functools.rst

Modified: python/branches/trunk-math/Doc/library/os.rst
==============================================================================
--- python/branches/trunk-math/Doc/library/os.rst	(original)
+++ python/branches/trunk-math/Doc/library/os.rst	Thu Feb 14 09:32:39 2008
@@ -1846,7 +1846,7 @@
    user time, children's system time, and elapsed real time since a fixed point in
    the past, in that order.  See the Unix manual page :manpage:`times(2)` or the
    corresponding Windows Platform API documentation. Availability: Macintosh, Unix,
-   Windows.
+   Windows.  On Windows, only the first two items are filled, the others are zero.
 
 
 .. function:: wait()

Modified: python/branches/trunk-math/Lib/abc.py
==============================================================================
--- python/branches/trunk-math/Lib/abc.py	(original)
+++ python/branches/trunk-math/Lib/abc.py	Thu Feb 14 09:32:39 2008
@@ -163,8 +163,20 @@
 
     def __instancecheck__(cls, instance):
         """Override for isinstance(instance, cls)."""
-        return any(cls.__subclasscheck__(c)
-                   for c in set([instance.__class__, type(instance)]))
+        # Inline the cache checking for new-style classes.
+        subclass = instance.__class__
+        if subclass in cls._abc_cache:
+            return True
+        subtype = type(instance)
+        if subtype is subclass:
+            if (cls._abc_negative_cache_version ==
+                ABCMeta._abc_invalidation_counter and
+                subclass in cls._abc_negative_cache):
+                return False
+            # Fall back to the subclass check.
+            return cls.__subclasscheck__(subclass)
+        return (cls.__subclasscheck__(subclass) or
+                cls.__subclasscheck__(subtype))
 
     def __subclasscheck__(cls, subclass):
         """Override for issubclass(subclass, cls)."""

Modified: python/branches/trunk-math/Lib/decimal.py
==============================================================================
--- python/branches/trunk-math/Lib/decimal.py	(original)
+++ python/branches/trunk-math/Lib/decimal.py	Thu Feb 14 09:32:39 2008
@@ -35,26 +35,26 @@
 useful for financial applications or for contexts where users have
 expectations that are at odds with binary floating point (for instance,
 in binary floating point, 1.00 % 0.1 gives 0.09999999999999995 instead
-of the expected Decimal("0.00") returned by decimal floating point).
+of the expected Decimal('0.00') returned by decimal floating point).
 
 Here are some examples of using the decimal module:
 
 >>> from decimal import *
 >>> setcontext(ExtendedContext)
 >>> Decimal(0)
-Decimal("0")
->>> Decimal("1")
-Decimal("1")
->>> Decimal("-.0123")
-Decimal("-0.0123")
+Decimal('0')
+>>> Decimal('1')
+Decimal('1')
+>>> Decimal('-.0123')
+Decimal('-0.0123')
 >>> Decimal(123456)
-Decimal("123456")
->>> Decimal("123.45e12345678901234567890")
-Decimal("1.2345E+12345678901234567892")
->>> Decimal("1.33") + Decimal("1.27")
-Decimal("2.60")
->>> Decimal("12.34") + Decimal("3.87") - Decimal("18.41")
-Decimal("-2.20")
+Decimal('123456')
+>>> Decimal('123.45e12345678901234567890')
+Decimal('1.2345E+12345678901234567892')
+>>> Decimal('1.33') + Decimal('1.27')
+Decimal('2.60')
+>>> Decimal('12.34') + Decimal('3.87') - Decimal('18.41')
+Decimal('-2.20')
 >>> dig = Decimal(1)
 >>> print dig / Decimal(3)
 0.333333333
@@ -91,7 +91,7 @@
 >>> print c.flags[InvalidOperation]
 0
 >>> c.divide(Decimal(0), Decimal(0))
-Decimal("NaN")
+Decimal('NaN')
 >>> c.traps[InvalidOperation] = 1
 >>> print c.flags[InvalidOperation]
 1
@@ -516,15 +516,15 @@
         """Create a decimal point instance.
 
         >>> Decimal('3.14')              # string input
-        Decimal("3.14")
+        Decimal('3.14')
         >>> Decimal((0, (3, 1, 4), -2))  # tuple (sign, digit_tuple, exponent)
-        Decimal("3.14")
+        Decimal('3.14')
         >>> Decimal(314)                 # int or long
-        Decimal("314")
+        Decimal('314')
         >>> Decimal(Decimal(314))        # another decimal instance
-        Decimal("314")
+        Decimal('314')
         >>> Decimal('  3.14  \\n')        # leading and trailing whitespace okay
-        Decimal("3.14")
+        Decimal('3.14')
         """
 
         # Note that the coefficient, self._int, is actually stored as
@@ -883,7 +883,7 @@
         #
         # The hash of a nonspecial noninteger Decimal must depend only
         # on the value of that Decimal, and not on its representation.
-        # For example: hash(Decimal("100E-1")) == hash(Decimal("10")).
+        # For example: hash(Decimal('100E-1')) == hash(Decimal('10')).
         if self._is_special:
             if self._isnan():
                 raise TypeError('Cannot hash a NaN value.')
@@ -917,7 +917,7 @@
     def __repr__(self):
         """Represents the number as an instance of Decimal."""
         # Invariant:  eval(repr(d)) == d
-        return 'Decimal("%s")' % str(self)
+        return "Decimal('%s')" % str(self)
 
     def __str__(self, eng=False, context=None):
         """Return string representation of the number in scientific notation.
@@ -1519,6 +1519,20 @@
 
     __trunc__ = __int__
 
+    @property
+    def real(self):
+        return self
+
+    @property
+    def imag(self):
+        return Decimal(0)
+
+    def conjugate(self):
+        return self
+
+    def __complex__(self):
+        return complex(float(self))
+
     def __long__(self):
         """Converts to a long.
 
@@ -3633,13 +3647,13 @@
         the plus operation on the operand.
 
         >>> ExtendedContext.abs(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.abs(Decimal('-100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.abs(Decimal('101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         >>> ExtendedContext.abs(Decimal('-101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         """
         return a.__abs__(context=self)
 
@@ -3647,9 +3661,9 @@
         """Return the sum of the two operands.
 
         >>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
-        Decimal("19.00")
+        Decimal('19.00')
         >>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
-        Decimal("1.02E+4")
+        Decimal('1.02E+4')
         """
         return a.__add__(b, context=self)
 
@@ -3663,7 +3677,7 @@
         received object already is in its canonical form.
 
         >>> ExtendedContext.canonical(Decimal('2.50'))
-        Decimal("2.50")
+        Decimal('2.50')
         """
         return a.canonical(context=self)
 
@@ -3682,17 +3696,17 @@
         zero or negative zero, or '1' if the result is greater than zero.
 
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('2.10'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare(Decimal('3'), Decimal('2.1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare(Decimal('2.1'), Decimal('-3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare(Decimal('-3'), Decimal('2.1'))
-        Decimal("-1")
+        Decimal('-1')
         """
         return a.compare(b, context=self)
 
@@ -3704,21 +3718,21 @@
 
         >>> c = ExtendedContext
         >>> c.compare_signal(Decimal('2.1'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> c.compare_signal(Decimal('2.1'), Decimal('2.1'))
-        Decimal("0")
+        Decimal('0')
         >>> c.flags[InvalidOperation] = 0
         >>> print c.flags[InvalidOperation]
         0
         >>> c.compare_signal(Decimal('NaN'), Decimal('2.1'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> print c.flags[InvalidOperation]
         1
         >>> c.flags[InvalidOperation] = 0
         >>> print c.flags[InvalidOperation]
         0
         >>> c.compare_signal(Decimal('sNaN'), Decimal('2.1'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> print c.flags[InvalidOperation]
         1
         """
@@ -3732,17 +3746,17 @@
         representations.
 
         >>> ExtendedContext.compare_total(Decimal('12.73'), Decimal('127.9'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('-127'),  Decimal('12'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.compare_total(Decimal('12.30'), Decimal('12.30'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('12.300'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.compare_total(Decimal('12.3'),  Decimal('NaN'))
-        Decimal("-1")
+        Decimal('-1')
         """
         return a.compare_total(b)
 
@@ -3757,9 +3771,9 @@
         """Returns a copy of the operand with the sign set to 0.
 
         >>> ExtendedContext.copy_abs(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.copy_abs(Decimal('-100'))
-        Decimal("100")
+        Decimal('100')
         """
         return a.copy_abs()
 
@@ -3767,9 +3781,9 @@
         """Returns a copy of the decimal objet.
 
         >>> ExtendedContext.copy_decimal(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.copy_decimal(Decimal('-1.00'))
-        Decimal("-1.00")
+        Decimal('-1.00')
         """
         return Decimal(a)
 
@@ -3777,9 +3791,9 @@
         """Returns a copy of the operand with the sign inverted.
 
         >>> ExtendedContext.copy_negate(Decimal('101.5'))
-        Decimal("-101.5")
+        Decimal('-101.5')
         >>> ExtendedContext.copy_negate(Decimal('-101.5'))
-        Decimal("101.5")
+        Decimal('101.5')
         """
         return a.copy_negate()
 
@@ -3790,13 +3804,13 @@
         equal to the sign of the second operand.
 
         >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('7.33'))
-        Decimal("1.50")
+        Decimal('1.50')
         >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('7.33'))
-        Decimal("1.50")
+        Decimal('1.50')
         >>> ExtendedContext.copy_sign(Decimal( '1.50'), Decimal('-7.33'))
-        Decimal("-1.50")
+        Decimal('-1.50')
         >>> ExtendedContext.copy_sign(Decimal('-1.50'), Decimal('-7.33'))
-        Decimal("-1.50")
+        Decimal('-1.50')
         """
         return a.copy_sign(b)
 
@@ -3804,25 +3818,25 @@
         """Decimal division in a specified context.
 
         >>> ExtendedContext.divide(Decimal('1'), Decimal('3'))
-        Decimal("0.333333333")
+        Decimal('0.333333333')
         >>> ExtendedContext.divide(Decimal('2'), Decimal('3'))
-        Decimal("0.666666667")
+        Decimal('0.666666667')
         >>> ExtendedContext.divide(Decimal('5'), Decimal('2'))
-        Decimal("2.5")
+        Decimal('2.5')
         >>> ExtendedContext.divide(Decimal('1'), Decimal('10'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.divide(Decimal('12'), Decimal('12'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.divide(Decimal('8.00'), Decimal('2'))
-        Decimal("4.00")
+        Decimal('4.00')
         >>> ExtendedContext.divide(Decimal('2.400'), Decimal('2.0'))
-        Decimal("1.20")
+        Decimal('1.20')
         >>> ExtendedContext.divide(Decimal('1000'), Decimal('100'))
-        Decimal("10")
+        Decimal('10')
         >>> ExtendedContext.divide(Decimal('1000'), Decimal('1'))
-        Decimal("1000")
+        Decimal('1000')
         >>> ExtendedContext.divide(Decimal('2.40E+6'), Decimal('2'))
-        Decimal("1.20E+6")
+        Decimal('1.20E+6')
         """
         return a.__div__(b, context=self)
 
@@ -3830,11 +3844,11 @@
         """Divides two numbers and returns the integer part of the result.
 
         >>> ExtendedContext.divide_int(Decimal('2'), Decimal('3'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.divide_int(Decimal('10'), Decimal('3'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.divide_int(Decimal('1'), Decimal('0.3'))
-        Decimal("3")
+        Decimal('3')
         """
         return a.__floordiv__(b, context=self)
 
@@ -3848,17 +3862,17 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.exp(Decimal('-Infinity'))
-        Decimal("0")
+        Decimal('0')
         >>> c.exp(Decimal('-1'))
-        Decimal("0.367879441")
+        Decimal('0.367879441')
         >>> c.exp(Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.exp(Decimal('1'))
-        Decimal("2.71828183")
+        Decimal('2.71828183')
         >>> c.exp(Decimal('0.693147181'))
-        Decimal("2.00000000")
+        Decimal('2.00000000')
         >>> c.exp(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.exp(context=self)
 
@@ -3870,11 +3884,11 @@
         multiplication, using add, all with only one final rounding.
 
         >>> ExtendedContext.fma(Decimal('3'), Decimal('5'), Decimal('7'))
-        Decimal("22")
+        Decimal('22')
         >>> ExtendedContext.fma(Decimal('3'), Decimal('-5'), Decimal('7'))
-        Decimal("-8")
+        Decimal('-8')
         >>> ExtendedContext.fma(Decimal('888565290'), Decimal('1557.96930'), Decimal('-86087.7578'))
-        Decimal("1.38435736E+12")
+        Decimal('1.38435736E+12')
         """
         return a.fma(b, c, context=self)
 
@@ -4028,15 +4042,15 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.ln(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.ln(Decimal('1.000'))
-        Decimal("0")
+        Decimal('0')
         >>> c.ln(Decimal('2.71828183'))
-        Decimal("1.00000000")
+        Decimal('1.00000000')
         >>> c.ln(Decimal('10'))
-        Decimal("2.30258509")
+        Decimal('2.30258509')
         >>> c.ln(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.ln(context=self)
 
@@ -4047,19 +4061,19 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.log10(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.log10(Decimal('0.001'))
-        Decimal("-3")
+        Decimal('-3')
         >>> c.log10(Decimal('1.000'))
-        Decimal("0")
+        Decimal('0')
         >>> c.log10(Decimal('2'))
-        Decimal("0.301029996")
+        Decimal('0.301029996')
         >>> c.log10(Decimal('10'))
-        Decimal("1")
+        Decimal('1')
         >>> c.log10(Decimal('70'))
-        Decimal("1.84509804")
+        Decimal('1.84509804')
         >>> c.log10(Decimal('+Infinity'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         """
         return a.log10(context=self)
 
@@ -4072,13 +4086,13 @@
         value of that digit and without limiting the resulting exponent).
 
         >>> ExtendedContext.logb(Decimal('250'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.logb(Decimal('2.50'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logb(Decimal('0.03'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.logb(Decimal('0'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.logb(context=self)
 
@@ -4088,17 +4102,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_and(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('0'), Decimal('1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('1'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_and(Decimal('1'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_and(Decimal('1100'), Decimal('1010'))
-        Decimal("1000")
+        Decimal('1000')
         >>> ExtendedContext.logical_and(Decimal('1111'), Decimal('10'))
-        Decimal("10")
+        Decimal('10')
         """
         return a.logical_and(b, context=self)
 
@@ -4108,13 +4122,13 @@
         The operand must be a logical number.
 
         >>> ExtendedContext.logical_invert(Decimal('0'))
-        Decimal("111111111")
+        Decimal('111111111')
         >>> ExtendedContext.logical_invert(Decimal('1'))
-        Decimal("111111110")
+        Decimal('111111110')
         >>> ExtendedContext.logical_invert(Decimal('111111111'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_invert(Decimal('101010101'))
-        Decimal("10101010")
+        Decimal('10101010')
         """
         return a.logical_invert(context=self)
 
@@ -4124,17 +4138,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_or(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_or(Decimal('0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_or(Decimal('1100'), Decimal('1010'))
-        Decimal("1110")
+        Decimal('1110')
         >>> ExtendedContext.logical_or(Decimal('1110'), Decimal('10'))
-        Decimal("1110")
+        Decimal('1110')
         """
         return a.logical_or(b, context=self)
 
@@ -4144,17 +4158,17 @@
         The operands must be both logical numbers.
 
         >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_xor(Decimal('0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.logical_xor(Decimal('1'), Decimal('1'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.logical_xor(Decimal('1100'), Decimal('1010'))
-        Decimal("110")
+        Decimal('110')
         >>> ExtendedContext.logical_xor(Decimal('1111'), Decimal('10'))
-        Decimal("1101")
+        Decimal('1101')
         """
         return a.logical_xor(b, context=self)
 
@@ -4168,13 +4182,13 @@
         infinity) of the two operands is chosen as the result.
 
         >>> ExtendedContext.max(Decimal('3'), Decimal('2'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.max(Decimal('-10'), Decimal('3'))
-        Decimal("3")
+        Decimal('3')
         >>> ExtendedContext.max(Decimal('1.0'), Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.max(Decimal('7'), Decimal('NaN'))
-        Decimal("7")
+        Decimal('7')
         """
         return a.max(b, context=self)
 
@@ -4192,13 +4206,13 @@
         infinity) of the two operands is chosen as the result.
 
         >>> ExtendedContext.min(Decimal('3'), Decimal('2'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.min(Decimal('-10'), Decimal('3'))
-        Decimal("-10")
+        Decimal('-10')
         >>> ExtendedContext.min(Decimal('1.0'), Decimal('1'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.min(Decimal('7'), Decimal('NaN'))
-        Decimal("7")
+        Decimal('7')
         """
         return a.min(b, context=self)
 
@@ -4214,9 +4228,9 @@
         has the same exponent as the operand.
 
         >>> ExtendedContext.minus(Decimal('1.3'))
-        Decimal("-1.3")
+        Decimal('-1.3')
         >>> ExtendedContext.minus(Decimal('-1.3'))
-        Decimal("1.3")
+        Decimal('1.3')
         """
         return a.__neg__(context=self)
 
@@ -4229,15 +4243,15 @@
         of the two operands.
 
         >>> ExtendedContext.multiply(Decimal('1.20'), Decimal('3'))
-        Decimal("3.60")
+        Decimal('3.60')
         >>> ExtendedContext.multiply(Decimal('7'), Decimal('3'))
-        Decimal("21")
+        Decimal('21')
         >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('0.8'))
-        Decimal("0.72")
+        Decimal('0.72')
         >>> ExtendedContext.multiply(Decimal('0.9'), Decimal('-0'))
-        Decimal("-0.0")
+        Decimal('-0.0')
         >>> ExtendedContext.multiply(Decimal('654321'), Decimal('654321'))
-        Decimal("4.28135971E+11")
+        Decimal('4.28135971E+11')
         """
         return a.__mul__(b, context=self)
 
@@ -4248,13 +4262,13 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> ExtendedContext.next_minus(Decimal('1'))
-        Decimal("0.999999999")
+        Decimal('0.999999999')
         >>> c.next_minus(Decimal('1E-1007'))
-        Decimal("0E-1007")
+        Decimal('0E-1007')
         >>> ExtendedContext.next_minus(Decimal('-1.00000003'))
-        Decimal("-1.00000004")
+        Decimal('-1.00000004')
         >>> c.next_minus(Decimal('Infinity'))
-        Decimal("9.99999999E+999")
+        Decimal('9.99999999E+999')
         """
         return a.next_minus(context=self)
 
@@ -4265,13 +4279,13 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> ExtendedContext.next_plus(Decimal('1'))
-        Decimal("1.00000001")
+        Decimal('1.00000001')
         >>> c.next_plus(Decimal('-1E-1007'))
-        Decimal("-0E-1007")
+        Decimal('-0E-1007')
         >>> ExtendedContext.next_plus(Decimal('-1.00000003'))
-        Decimal("-1.00000002")
+        Decimal('-1.00000002')
         >>> c.next_plus(Decimal('-Infinity'))
-        Decimal("-9.99999999E+999")
+        Decimal('-9.99999999E+999')
         """
         return a.next_plus(context=self)
 
@@ -4287,19 +4301,19 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.next_toward(Decimal('1'), Decimal('2'))
-        Decimal("1.00000001")
+        Decimal('1.00000001')
         >>> c.next_toward(Decimal('-1E-1007'), Decimal('1'))
-        Decimal("-0E-1007")
+        Decimal('-0E-1007')
         >>> c.next_toward(Decimal('-1.00000003'), Decimal('0'))
-        Decimal("-1.00000002")
+        Decimal('-1.00000002')
         >>> c.next_toward(Decimal('1'), Decimal('0'))
-        Decimal("0.999999999")
+        Decimal('0.999999999')
         >>> c.next_toward(Decimal('1E-1007'), Decimal('-100'))
-        Decimal("0E-1007")
+        Decimal('0E-1007')
         >>> c.next_toward(Decimal('-1.00000003'), Decimal('-10'))
-        Decimal("-1.00000004")
+        Decimal('-1.00000004')
         >>> c.next_toward(Decimal('0.00'), Decimal('-0.0000'))
-        Decimal("-0.00")
+        Decimal('-0.00')
         """
         return a.next_toward(b, context=self)
 
@@ -4310,17 +4324,17 @@
         result.
 
         >>> ExtendedContext.normalize(Decimal('2.1'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.normalize(Decimal('-2.0'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.normalize(Decimal('1.200'))
-        Decimal("1.2")
+        Decimal('1.2')
         >>> ExtendedContext.normalize(Decimal('-120'))
-        Decimal("-1.2E+2")
+        Decimal('-1.2E+2')
         >>> ExtendedContext.normalize(Decimal('120.00'))
-        Decimal("1.2E+2")
+        Decimal('1.2E+2')
         >>> ExtendedContext.normalize(Decimal('0.00'))
-        Decimal("0")
+        Decimal('0')
         """
         return a.normalize(context=self)
 
@@ -4379,9 +4393,9 @@
         has the same exponent as the operand.
 
         >>> ExtendedContext.plus(Decimal('1.3'))
-        Decimal("1.3")
+        Decimal('1.3')
         >>> ExtendedContext.plus(Decimal('-1.3'))
-        Decimal("-1.3")
+        Decimal('-1.3')
         """
         return a.__pos__(context=self)
 
@@ -4411,46 +4425,46 @@
         >>> c.Emin = -999
         >>> c.Emax = 999
         >>> c.power(Decimal('2'), Decimal('3'))
-        Decimal("8")
+        Decimal('8')
         >>> c.power(Decimal('-2'), Decimal('3'))
-        Decimal("-8")
+        Decimal('-8')
         >>> c.power(Decimal('2'), Decimal('-3'))
-        Decimal("0.125")
+        Decimal('0.125')
         >>> c.power(Decimal('1.7'), Decimal('8'))
-        Decimal("69.7575744")
+        Decimal('69.7575744')
         >>> c.power(Decimal('10'), Decimal('0.301029996'))
-        Decimal("2.00000000")
+        Decimal('2.00000000')
         >>> c.power(Decimal('Infinity'), Decimal('-1'))
-        Decimal("0")
+        Decimal('0')
         >>> c.power(Decimal('Infinity'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('Infinity'), Decimal('1'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         >>> c.power(Decimal('-Infinity'), Decimal('-1'))
-        Decimal("-0")
+        Decimal('-0')
         >>> c.power(Decimal('-Infinity'), Decimal('0'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('-Infinity'), Decimal('1'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> c.power(Decimal('-Infinity'), Decimal('2'))
-        Decimal("Infinity")
+        Decimal('Infinity')
         >>> c.power(Decimal('0'), Decimal('0'))
-        Decimal("NaN")
+        Decimal('NaN')
 
         >>> c.power(Decimal('3'), Decimal('7'), Decimal('16'))
-        Decimal("11")
+        Decimal('11')
         >>> c.power(Decimal('-3'), Decimal('7'), Decimal('16'))
-        Decimal("-11")
+        Decimal('-11')
         >>> c.power(Decimal('-3'), Decimal('8'), Decimal('16'))
-        Decimal("1")
+        Decimal('1')
         >>> c.power(Decimal('3'), Decimal('7'), Decimal('-16'))
-        Decimal("11")
+        Decimal('11')
         >>> c.power(Decimal('23E12345'), Decimal('67E189'), Decimal('123456789'))
-        Decimal("11729830")
+        Decimal('11729830')
         >>> c.power(Decimal('-0'), Decimal('17'), Decimal('1729'))
-        Decimal("-0")
+        Decimal('-0')
         >>> c.power(Decimal('-23'), Decimal('0'), Decimal('65537'))
-        Decimal("1")
+        Decimal('1')
         """
         return a.__pow__(b, modulo, context=self)
 
@@ -4473,35 +4487,35 @@
         if the result is subnormal and inexact.
 
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.001'))
-        Decimal("2.170")
+        Decimal('2.170')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.01'))
-        Decimal("2.17")
+        Decimal('2.17')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('0.1'))
-        Decimal("2.2")
+        Decimal('2.2')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+0'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.quantize(Decimal('2.17'), Decimal('1e+1'))
-        Decimal("0E+1")
+        Decimal('0E+1')
         >>> ExtendedContext.quantize(Decimal('-Inf'), Decimal('Infinity'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         >>> ExtendedContext.quantize(Decimal('2'), Decimal('Infinity'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('-0.1'), Decimal('1'))
-        Decimal("-0")
+        Decimal('-0')
         >>> ExtendedContext.quantize(Decimal('-0'), Decimal('1e+5'))
-        Decimal("-0E+5")
+        Decimal('-0E+5')
         >>> ExtendedContext.quantize(Decimal('+35236450.6'), Decimal('1e-2'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('-35236450.6'), Decimal('1e-2'))
-        Decimal("NaN")
+        Decimal('NaN')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-1'))
-        Decimal("217.0")
+        Decimal('217.0')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e-0'))
-        Decimal("217")
+        Decimal('217')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+1'))
-        Decimal("2.2E+2")
+        Decimal('2.2E+2')
         >>> ExtendedContext.quantize(Decimal('217'), Decimal('1e+2'))
-        Decimal("2E+2")
+        Decimal('2E+2')
         """
         return a.quantize(b, context=self)
 
@@ -4509,7 +4523,7 @@
         """Just returns 10, as this is Decimal, :)
 
         >>> ExtendedContext.radix()
-        Decimal("10")
+        Decimal('10')
         """
         return Decimal(10)
 
@@ -4526,17 +4540,17 @@
         remainder cannot be calculated).
 
         >>> ExtendedContext.remainder(Decimal('2.1'), Decimal('3'))
-        Decimal("2.1")
+        Decimal('2.1')
         >>> ExtendedContext.remainder(Decimal('10'), Decimal('3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.remainder(Decimal('-10'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.remainder(Decimal('10.2'), Decimal('1'))
-        Decimal("0.2")
+        Decimal('0.2')
         >>> ExtendedContext.remainder(Decimal('10'), Decimal('0.3'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.remainder(Decimal('3.6'), Decimal('1.3'))
-        Decimal("1.0")
+        Decimal('1.0')
         """
         return a.__mod__(b, context=self)
 
@@ -4551,19 +4565,19 @@
         remainder cannot be calculated).
 
         >>> ExtendedContext.remainder_near(Decimal('2.1'), Decimal('3'))
-        Decimal("-0.9")
+        Decimal('-0.9')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('6'))
-        Decimal("-2")
+        Decimal('-2')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('3'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.remainder_near(Decimal('-10'), Decimal('3'))
-        Decimal("-1")
+        Decimal('-1')
         >>> ExtendedContext.remainder_near(Decimal('10.2'), Decimal('1'))
-        Decimal("0.2")
+        Decimal('0.2')
         >>> ExtendedContext.remainder_near(Decimal('10'), Decimal('0.3'))
-        Decimal("0.1")
+        Decimal('0.1')
         >>> ExtendedContext.remainder_near(Decimal('3.6'), Decimal('1.3'))
-        Decimal("-0.3")
+        Decimal('-0.3')
         """
         return a.remainder_near(b, context=self)
 
@@ -4577,15 +4591,15 @@
         positive or to the right otherwise.
 
         >>> ExtendedContext.rotate(Decimal('34'), Decimal('8'))
-        Decimal("400000003")
+        Decimal('400000003')
         >>> ExtendedContext.rotate(Decimal('12'), Decimal('9'))
-        Decimal("12")
+        Decimal('12')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('-2'))
-        Decimal("891234567")
+        Decimal('891234567')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('0'))
-        Decimal("123456789")
+        Decimal('123456789')
         >>> ExtendedContext.rotate(Decimal('123456789'), Decimal('+2'))
-        Decimal("345678912")
+        Decimal('345678912')
         """
         return a.rotate(b, context=self)
 
@@ -4610,11 +4624,11 @@
         """Returns the first operand after adding the second value its exp.
 
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('-2'))
-        Decimal("0.0750")
+        Decimal('0.0750')
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('0'))
-        Decimal("7.50")
+        Decimal('7.50')
         >>> ExtendedContext.scaleb(Decimal('7.50'), Decimal('3'))
-        Decimal("7.50E+3")
+        Decimal('7.50E+3')
         """
         return a.scaleb (b, context=self)
 
@@ -4629,15 +4643,15 @@
         coefficient are zeros.
 
         >>> ExtendedContext.shift(Decimal('34'), Decimal('8'))
-        Decimal("400000000")
+        Decimal('400000000')
         >>> ExtendedContext.shift(Decimal('12'), Decimal('9'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('-2'))
-        Decimal("1234567")
+        Decimal('1234567')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('0'))
-        Decimal("123456789")
+        Decimal('123456789')
         >>> ExtendedContext.shift(Decimal('123456789'), Decimal('+2'))
-        Decimal("345678900")
+        Decimal('345678900')
         """
         return a.shift(b, context=self)
 
@@ -4648,23 +4662,23 @@
         algorithm.
 
         >>> ExtendedContext.sqrt(Decimal('0'))
-        Decimal("0")
+        Decimal('0')
         >>> ExtendedContext.sqrt(Decimal('-0'))
-        Decimal("-0")
+        Decimal('-0')
         >>> ExtendedContext.sqrt(Decimal('0.39'))
-        Decimal("0.624499800")
+        Decimal('0.624499800')
         >>> ExtendedContext.sqrt(Decimal('100'))
-        Decimal("10")
+        Decimal('10')
         >>> ExtendedContext.sqrt(Decimal('1'))
-        Decimal("1")
+        Decimal('1')
         >>> ExtendedContext.sqrt(Decimal('1.0'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.sqrt(Decimal('1.00'))
-        Decimal("1.0")
+        Decimal('1.0')
         >>> ExtendedContext.sqrt(Decimal('7'))
-        Decimal("2.64575131")
+        Decimal('2.64575131')
         >>> ExtendedContext.sqrt(Decimal('10'))
-        Decimal("3.16227766")
+        Decimal('3.16227766')
         >>> ExtendedContext.prec
         9
         """
@@ -4674,11 +4688,11 @@
         """Return the difference between the two operands.
 
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.07'))
-        Decimal("0.23")
+        Decimal('0.23')
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('1.30'))
-        Decimal("0.00")
+        Decimal('0.00')
         >>> ExtendedContext.subtract(Decimal('1.3'), Decimal('2.07'))
-        Decimal("-0.77")
+        Decimal('-0.77')
         """
         return a.__sub__(b, context=self)
 
@@ -4707,21 +4721,21 @@
         context.
 
         >>> ExtendedContext.to_integral_exact(Decimal('2.1'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.to_integral_exact(Decimal('100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_exact(Decimal('100.0'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_exact(Decimal('101.5'))
-        Decimal("102")
+        Decimal('102')
         >>> ExtendedContext.to_integral_exact(Decimal('-101.5'))
-        Decimal("-102")
+        Decimal('-102')
         >>> ExtendedContext.to_integral_exact(Decimal('10E+5'))
-        Decimal("1.0E+6")
+        Decimal('1.0E+6')
         >>> ExtendedContext.to_integral_exact(Decimal('7.89E+77'))
-        Decimal("7.89E+77")
+        Decimal('7.89E+77')
         >>> ExtendedContext.to_integral_exact(Decimal('-Inf'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.to_integral_exact(context=self)
 
@@ -4735,21 +4749,21 @@
         be set.  The rounding mode is taken from the context.
 
         >>> ExtendedContext.to_integral_value(Decimal('2.1'))
-        Decimal("2")
+        Decimal('2')
         >>> ExtendedContext.to_integral_value(Decimal('100'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_value(Decimal('100.0'))
-        Decimal("100")
+        Decimal('100')
         >>> ExtendedContext.to_integral_value(Decimal('101.5'))
-        Decimal("102")
+        Decimal('102')
         >>> ExtendedContext.to_integral_value(Decimal('-101.5'))
-        Decimal("-102")
+        Decimal('-102')
         >>> ExtendedContext.to_integral_value(Decimal('10E+5'))
-        Decimal("1.0E+6")
+        Decimal('1.0E+6')
         >>> ExtendedContext.to_integral_value(Decimal('7.89E+77'))
-        Decimal("7.89E+77")
+        Decimal('7.89E+77')
         >>> ExtendedContext.to_integral_value(Decimal('-Inf'))
-        Decimal("-Infinity")
+        Decimal('-Infinity')
         """
         return a.to_integral_value(context=self)
 

Modified: python/branches/trunk-math/Lib/fractions.py
==============================================================================
--- python/branches/trunk-math/Lib/fractions.py	(original)
+++ python/branches/trunk-math/Lib/fractions.py	Thu Feb 14 09:32:39 2008
@@ -64,7 +64,7 @@
         """
         self = super(Fraction, cls).__new__(cls)
 
-        if denominator == 1:
+        if type(numerator) not in (int, long) and denominator == 1:
             if isinstance(numerator, basestring):
                 # Handle construction from strings.
                 input = numerator
@@ -86,96 +86,112 @@
                 if m.group('sign') == '-':
                     numerator = -numerator
 
-            elif (not isinstance(numerator, numbers.Integral) and
-                  isinstance(numerator, Rational)):
-                # Handle copies from other rationals.
+            elif isinstance(numerator, Rational):
+                # Handle copies from other rationals. Integrals get
+                # caught here too, but it doesn't matter because
+                # denominator is already 1.
                 other_rational = numerator
                 numerator = other_rational.numerator
                 denominator = other_rational.denominator
 
-        if (not isinstance(numerator, numbers.Integral) or
-            not isinstance(denominator, numbers.Integral)):
-            raise TypeError("Fraction(%(numerator)s, %(denominator)s):"
-                            " Both arguments must be integral." % locals())
-
         if denominator == 0:
             raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
 
+        numerator = numerator.__index__()
+        denominator = denominator.__index__()
         g = gcd(numerator, denominator)
-        self._numerator = int(numerator // g)
-        self._denominator = int(denominator // g)
+        self._numerator = numerator // g
+        self._denominator = denominator // g
         return self
 
-    @staticmethod
-    def from_float(f):
+    @classmethod
+    def from_float(cls, f):
         """Converts a finite float to a rational number, exactly.
 
         Beware that Fraction.from_float(0.3) != Fraction(3, 10).
 
         """
         if not isinstance(f, float):
-            raise TypeError("Fraction.from_float() only takes floats, "
-                            "not %r (%s)" % (f, type(f).__name__))
+            raise TypeError("%s.from_float() only takes floats, not %r (%s)" %
+                            (cls.__name__, f, type(f).__name__))
         if math.isnan(f) or math.isinf(f):
-            raise TypeError("Cannot convert %r to Fraction." % f)
-        return Fraction(*f.as_integer_ratio())
+            raise TypeError("Cannot convert %r to %s." % (f, cls.__name__))
+        return cls(*f.as_integer_ratio())
 
-    @staticmethod
-    def from_decimal(dec):
+    @classmethod
+    def from_decimal(cls, dec):
         """Converts a finite Decimal instance to a rational number, exactly."""
         from decimal import Decimal
         if not isinstance(dec, Decimal):
             raise TypeError(
-                "Fraction.from_decimal() only takes Decimals, not %r (%s)" %
-                (dec, type(dec).__name__))
+                "%s.from_decimal() only takes Decimals, not %r (%s)" %
+                (cls.__name__, dec, type(dec).__name__))
         if not dec.is_finite():
             # Catches infinities and nans.
-            raise TypeError("Cannot convert %s to Fraction." % dec)
+            raise TypeError("Cannot convert %s to %s." % (dec, cls.__name__))
         sign, digits, exp = dec.as_tuple()
         digits = int(''.join(map(str, digits)))
         if sign:
             digits = -digits
         if exp >= 0:
-            return Fraction(digits * 10 ** exp)
+            return cls(digits * 10 ** exp)
         else:
-            return Fraction(digits, 10 ** -exp)
+            return cls(digits, 10 ** -exp)
+
+    def limit_denominator(self, max_denominator=1000000):
+        """Closest Fraction to self with denominator at most max_denominator.
+
+        >>> Fraction('3.141592653589793').limit_denominator(10)
+        Fraction(22, 7)
+        >>> Fraction('3.141592653589793').limit_denominator(100)
+        Fraction(311, 99)
+        >>> Fraction(1234, 5678).limit_denominator(10000)
+        Fraction(1234, 5678)
 
-    @staticmethod
-    def from_continued_fraction(seq):
-        'Build a Fraction from a continued fraction expessed as a sequence'
-        n, d = 1, 0
-        for e in reversed(seq):
-            n, d = d, n
-            n += e * d
-        return Fraction(n, d) if seq else Fraction(0)
-
-    def as_continued_fraction(self):
-        'Return continued fraction expressed as a list'
-        n = self.numerator
-        d = self.denominator
-        cf = []
-        while d:
-            e = int(n // d)
-            cf.append(e)
-            n -= e * d
-            n, d = d, n
-        return cf
-
-    def approximate(self, max_denominator):
-        'Best rational approximation with a denominator <= max_denominator'
-        # XXX First cut at algorithm
-        # Still needs rounding rules as specified at
-        #       http://en.wikipedia.org/wiki/Continued_fraction
-        if self.denominator <= max_denominator:
-            return self
-        cf = self.as_continued_fraction()
-        result = Fraction(0)
-        for i in range(1, len(cf)):
-            new = self.from_continued_fraction(cf[:i])
-            if new.denominator > max_denominator:
+        """
+        # Algorithm notes: For any real number x, define a *best upper
+        # approximation* to x to be a rational number p/q such that:
+        #
+        #   (1) p/q >= x, and
+        #   (2) if p/q > r/s >= x then s > q, for any rational r/s.
+        #
+        # Define *best lower approximation* similarly.  Then it can be
+        # proved that a rational number is a best upper or lower
+        # approximation to x if, and only if, it is a convergent or
+        # semiconvergent of the (unique shortest) continued fraction
+        # associated to x.
+        #
+        # To find a best rational approximation with denominator <= M,
+        # we find the best upper and lower approximations with
+        # denominator <= M and take whichever of these is closer to x.
+        # In the event of a tie, the bound with smaller denominator is
+        # chosen.  If both denominators are equal (which can happen
+        # only when max_denominator == 1 and self is midway between
+        # two integers) the lower bound---i.e., the floor of self, is
+        # taken.
+
+        if max_denominator < 1:
+            raise ValueError("max_denominator should be at least 1")
+        if self._denominator <= max_denominator:
+            return Fraction(self)
+
+        p0, q0, p1, q1 = 0, 1, 1, 0
+        n, d = self._numerator, self._denominator
+        while True:
+            a = n//d
+            q2 = q0+a*q1
+            if q2 > max_denominator:
                 break
-            result = new
-        return result
+            p0, q0, p1, q1 = p1, q1, p0+a*p1, q2
+            n, d = d, n-a*d
+
+        k = (max_denominator-q0)//q1
+        bound1 = Fraction(p0+k*p1, q0+k*q1)
+        bound2 = Fraction(p1, q1)
+        if abs(bound2 - self) <= abs(bound1-self):
+            return bound2
+        else:
+            return bound1
 
     @property
     def numerator(a):
@@ -187,14 +203,14 @@
 
     def __repr__(self):
         """repr(self)"""
-        return ('Fraction(%r, %r)' % (self.numerator, self.denominator))
+        return ('Fraction(%r, %r)' % (self._numerator, self._denominator))
 
     def __str__(self):
         """str(self)"""
-        if self.denominator == 1:
-            return str(self.numerator)
+        if self._denominator == 1:
+            return str(self._numerator)
         else:
-            return '%s/%s' % (self.numerator, self.denominator)
+            return '%s/%s' % (self._numerator, self._denominator)
 
     def _operator_fallbacks(monomorphic_operator, fallback_operator):
         """Generates forward and reverse operators given a purely-rational
@@ -379,11 +395,11 @@
             if b.denominator == 1:
                 power = b.numerator
                 if power >= 0:
-                    return Fraction(a.numerator ** power,
-                                    a.denominator ** power)
+                    return Fraction(a._numerator ** power,
+                                    a._denominator ** power)
                 else:
-                    return Fraction(a.denominator ** -power,
-                                    a.numerator ** -power)
+                    return Fraction(a._denominator ** -power,
+                                    a._numerator ** -power)
             else:
                 # A fractional power will generally produce an
                 # irrational number.
@@ -393,36 +409,36 @@
 
     def __rpow__(b, a):
         """a ** b"""
-        if b.denominator == 1 and b.numerator >= 0:
+        if b._denominator == 1 and b._numerator >= 0:
             # If a is an int, keep it that way if possible.
-            return a ** b.numerator
+            return a ** b._numerator
 
         if isinstance(a, Rational):
             return Fraction(a.numerator, a.denominator) ** b
 
-        if b.denominator == 1:
-            return a ** b.numerator
+        if b._denominator == 1:
+            return a ** b._numerator
 
         return a ** float(b)
 
     def __pos__(a):
         """+a: Coerces a subclass instance to Fraction"""
-        return Fraction(a.numerator, a.denominator)
+        return Fraction(a._numerator, a._denominator)
 
     def __neg__(a):
         """-a"""
-        return Fraction(-a.numerator, a.denominator)
+        return Fraction(-a._numerator, a._denominator)
 
     def __abs__(a):
         """abs(a)"""
-        return Fraction(abs(a.numerator), a.denominator)
+        return Fraction(abs(a._numerator), a._denominator)
 
     def __trunc__(a):
         """trunc(a)"""
-        if a.numerator < 0:
-            return -(-a.numerator // a.denominator)
+        if a._numerator < 0:
+            return -(-a._numerator // a._denominator)
         else:
-            return a.numerator // a.denominator
+            return a._numerator // a._denominator
 
     def __hash__(self):
         """hash(self)
@@ -432,22 +448,22 @@
 
         """
         # XXX since this method is expensive, consider caching the result
-        if self.denominator == 1:
+        if self._denominator == 1:
             # Get integers right.
-            return hash(self.numerator)
+            return hash(self._numerator)
         # Expensive check, but definitely correct.
         if self == float(self):
             return hash(float(self))
         else:
             # Use tuple's hash to avoid a high collision rate on
             # simple fractions.
-            return hash((self.numerator, self.denominator))
+            return hash((self._numerator, self._denominator))
 
     def __eq__(a, b):
         """a == b"""
         if isinstance(b, Rational):
-            return (a.numerator == b.numerator and
-                    a.denominator == b.denominator)
+            return (a._numerator == b.numerator and
+                    a._denominator == b.denominator)
         if isinstance(b, numbers.Complex) and b.imag == 0:
             b = b.real
         if isinstance(b, float):
@@ -502,7 +518,7 @@
 
     def __nonzero__(a):
         """a != 0"""
-        return a.numerator != 0
+        return a._numerator != 0
 
     # support for pickling, copy, and deepcopy
 
@@ -512,9 +528,9 @@
     def __copy__(self):
         if type(self) == Fraction:
             return self     # I'm immutable; therefore I am my own clone
-        return self.__class__(self.numerator, self.denominator)
+        return self.__class__(self._numerator, self._denominator)
 
     def __deepcopy__(self, memo):
         if type(self) == Fraction:
             return self     # My components are also immutable
-        return self.__class__(self.numerator, self.denominator)
+        return self.__class__(self._numerator, self._denominator)

Modified: python/branches/trunk-math/Lib/httplib.py
==============================================================================
--- python/branches/trunk-math/Lib/httplib.py	(original)
+++ python/branches/trunk-math/Lib/httplib.py	Thu Feb 14 09:32:39 2008
@@ -573,6 +573,10 @@
         ### note: we shouldn't have any trailers!
         while True:
             line = self.fp.readline()
+            if not line:
+                # a vanishingly small number of sites EOF without
+                # sending the trailer
+                break
             if line == '\r\n':
                 break
 

Modified: python/branches/trunk-math/Lib/idlelib/NEWS.txt
==============================================================================
--- python/branches/trunk-math/Lib/idlelib/NEWS.txt	(original)
+++ python/branches/trunk-math/Lib/idlelib/NEWS.txt	Thu Feb 14 09:32:39 2008
@@ -28,6 +28,13 @@
 
 - Clean up EditorWindow close.
 
+- Patch 1693258: Fix for duplicate "preferences" menu-OS X. Backport of r56204.
+
+- OSX: Avoid crash for those versions of Tcl/Tk which don't have a console
+
+- Bug in idlelib.MultiCall: Options dialog was crashing IDLE if there was an
+  option in config-extensions w/o a value. Patch #1672481, Tal Einat
+
 - Corrected some bugs in AutoComplete.  Also, Page Up/Down in ACW implemented;
   mouse and cursor selection in ACWindow implemented; double Tab inserts
   current selection and closes ACW (similar to double-click and Return); scroll

Modified: python/branches/trunk-math/Lib/idlelib/configHandler.py
==============================================================================
--- python/branches/trunk-math/Lib/idlelib/configHandler.py	(original)
+++ python/branches/trunk-math/Lib/idlelib/configHandler.py	Thu Feb 14 09:32:39 2008
@@ -143,7 +143,7 @@
             try:
                 cfgFile = open(fname, 'w')
             except IOError:
-                fname.unlink()
+                os.unlink(fname)
                 cfgFile = open(fname, 'w')
             self.write(cfgFile)
         else:

Modified: python/branches/trunk-math/Lib/numbers.py
==============================================================================
--- python/branches/trunk-math/Lib/numbers.py	(original)
+++ python/branches/trunk-math/Lib/numbers.py	Thu Feb 14 09:32:39 2008
@@ -49,6 +49,34 @@
 # Inexact.register(decimal.Decimal)
 
 
+## Notes on Decimal
+## ----------------
+## Decimal has all of the methods specified by the Real abc, but it should
+## not be registered as a Real because decimals do not interoperate with
+## binary floats.
+##
+## Decimal has some of the characteristics of Integrals.  It provides
+## logical operations but not as operators.  The logical operations only apply
+## to a subset of decimals (those that are non-negative, have a zero exponent,
+## and have digits that are only 0 or 1).  It does provide __long__() and
+## a three argument form of __pow__ that includes exactness guarantees.
+## It does not provide an __index__() method.
+##
+## Depending on context, decimal operations may be exact or inexact.
+##
+## When decimal is run in a context with small precision and automatic rounding,
+## it is Inexact.  See the "Floating point notes" section of the decimal docs
+## for an example of losing the associative and distributive properties of
+## addition.
+##
+## When decimal is used for high precision integer arithmetic, it is Exact.
+## When the decimal used as fixed-point, it is Exact.
+## When it is run with sufficient precision, it is Exact.
+## When the decimal.Inexact trap is set, decimal operations are Exact.
+## For an example, see the float_to_decimal() recipe in the "Decimal FAQ"
+## section of the docs -- it shows an how traps are used in conjunction
+## with variable precision to reliably achieve exact results.
+
 class Complex(Number):
     """Complex defines the operations that work on the builtin complex type.
 
@@ -279,7 +307,6 @@
         return +self
 
 Real.register(float)
-# Real.register(decimal.Decimal)
 
 
 class Rational(Real, Exact):

Modified: python/branches/trunk-math/Lib/test/test_abc.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_abc.py	(original)
+++ python/branches/trunk-math/Lib/test/test_abc.py	Thu Feb 14 09:32:39 2008
@@ -83,6 +83,16 @@
         self.assertEqual(issubclass(C, A), True)
         self.assertEqual(isinstance(c, A), True)
 
+    def test_isinstance_invalidation(self):
+        class A:
+            __metaclass__ = abc.ABCMeta
+        class B(object):
+            pass
+        b = B()
+        self.assertEqual(isinstance(b, A), False)
+        A.register(B)
+        self.assertEqual(isinstance(b, A), True)
+
     def test_registration_builtins(self):
         class A:
             __metaclass__ = abc.ABCMeta

Modified: python/branches/trunk-math/Lib/test/test_decimal.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_decimal.py	(original)
+++ python/branches/trunk-math/Lib/test/test_decimal.py	Thu Feb 14 09:32:39 2008
@@ -1049,7 +1049,7 @@
 
         d = Decimal('15.32')
         self.assertEqual(str(d), '15.32')               # str
-        self.assertEqual(repr(d), 'Decimal("15.32")')   # repr
+        self.assertEqual(repr(d), "Decimal('15.32')")   # repr
 
     def test_tonum_methods(self):
         #Test float, int and long methods.

Modified: python/branches/trunk-math/Lib/test/test_fractions.py
==============================================================================
--- python/branches/trunk-math/Lib/test/test_fractions.py	(original)
+++ python/branches/trunk-math/Lib/test/test_fractions.py	Thu Feb 14 09:32:39 2008
@@ -8,7 +8,7 @@
 import unittest
 from copy import copy, deepcopy
 from cPickle import dumps, loads
-R = fractions.Fraction
+F = fractions.Fraction
 gcd = fractions.gcd
 
 
@@ -49,79 +49,79 @@
             self.fail("%s not raised" % exc_type.__name__)
 
     def testInit(self):
-        self.assertEquals((0, 1), _components(R()))
-        self.assertEquals((7, 1), _components(R(7)))
-        self.assertEquals((7, 3), _components(R(R(7, 3))))
-
-        self.assertEquals((-1, 1), _components(R(-1, 1)))
-        self.assertEquals((-1, 1), _components(R(1, -1)))
-        self.assertEquals((1, 1), _components(R(-2, -2)))
-        self.assertEquals((1, 2), _components(R(5, 10)))
-        self.assertEquals((7, 15), _components(R(7, 15)))
-        self.assertEquals((10**23, 1), _components(R(10**23)))
+        self.assertEquals((0, 1), _components(F()))
+        self.assertEquals((7, 1), _components(F(7)))
+        self.assertEquals((7, 3), _components(F(F(7, 3))))
+
+        self.assertEquals((-1, 1), _components(F(-1, 1)))
+        self.assertEquals((-1, 1), _components(F(1, -1)))
+        self.assertEquals((1, 1), _components(F(-2, -2)))
+        self.assertEquals((1, 2), _components(F(5, 10)))
+        self.assertEquals((7, 15), _components(F(7, 15)))
+        self.assertEquals((10**23, 1), _components(F(10**23)))
 
         self.assertRaisesMessage(ZeroDivisionError, "Fraction(12, 0)",
-                                 R, 12, 0)
-        self.assertRaises(TypeError, R, 1.5)
-        self.assertRaises(TypeError, R, 1.5 + 3j)
+                                 F, 12, 0)
+        self.assertRaises(AttributeError, F, 1.5)
+        self.assertRaises(AttributeError, F, 1.5 + 3j)
 
-        self.assertRaises(TypeError, R, R(1, 2), 3)
-        self.assertRaises(TypeError, R, "3/2", 3)
+        self.assertRaises(AttributeError, F, F(1, 2), 3)
+        self.assertRaises(AttributeError, F, "3/2", 3)
 
     def testFromString(self):
-        self.assertEquals((5, 1), _components(R("5")))
-        self.assertEquals((3, 2), _components(R("3/2")))
-        self.assertEquals((3, 2), _components(R(" \n  +3/2")))
-        self.assertEquals((-3, 2), _components(R("-3/2  ")))
-        self.assertEquals((13, 2), _components(R("    013/02 \n  ")))
-        self.assertEquals((13, 2), _components(R(u"    013/02 \n  ")))
-
-        self.assertEquals((16, 5), _components(R(" 3.2 ")))
-        self.assertEquals((-16, 5), _components(R(u" -3.2 ")))
-        self.assertEquals((-3, 1), _components(R(u" -3. ")))
-        self.assertEquals((3, 5), _components(R(u" .6 ")))
+        self.assertEquals((5, 1), _components(F("5")))
+        self.assertEquals((3, 2), _components(F("3/2")))
+        self.assertEquals((3, 2), _components(F(" \n  +3/2")))
+        self.assertEquals((-3, 2), _components(F("-3/2  ")))
+        self.assertEquals((13, 2), _components(F("    013/02 \n  ")))
+        self.assertEquals((13, 2), _components(F(u"    013/02 \n  ")))
+
+        self.assertEquals((16, 5), _components(F(" 3.2 ")))
+        self.assertEquals((-16, 5), _components(F(u" -3.2 ")))
+        self.assertEquals((-3, 1), _components(F(u" -3. ")))
+        self.assertEquals((3, 5), _components(F(u" .6 ")))
 
 
         self.assertRaisesMessage(
             ZeroDivisionError, "Fraction(3, 0)",
-            R, "3/0")
+            F, "3/0")
         self.assertRaisesMessage(
             ValueError, "Invalid literal for Fraction: 3/",
-            R, "3/")
+            F, "3/")
         self.assertRaisesMessage(
             ValueError, "Invalid literal for Fraction: 3 /2",
-            R, "3 /2")
+            F, "3 /2")
         self.assertRaisesMessage(
             # Denominators don't need a sign.
             ValueError, "Invalid literal for Fraction: 3/+2",
-            R, "3/+2")
+            F, "3/+2")
         self.assertRaisesMessage(
             # Imitate float's parsing.
             ValueError, "Invalid literal for Fraction: + 3/2",
-            R, "+ 3/2")
+            F, "+ 3/2")
         self.assertRaisesMessage(
             # Avoid treating '.' as a regex special character.
             ValueError, "Invalid literal for Fraction: 3a2",
-            R, "3a2")
+            F, "3a2")
         self.assertRaisesMessage(
             # Only parse ordinary decimals, not scientific form.
             ValueError, "Invalid literal for Fraction: 3.2e4",
-            R, "3.2e4")
+            F, "3.2e4")
         self.assertRaisesMessage(
             # Don't accept combinations of decimals and fractions.
             ValueError, "Invalid literal for Fraction: 3/7.2",
-            R, "3/7.2")
+            F, "3/7.2")
         self.assertRaisesMessage(
             # Don't accept combinations of decimals and fractions.
             ValueError, "Invalid literal for Fraction: 3.2/7",
-            R, "3.2/7")
+            F, "3.2/7")
         self.assertRaisesMessage(
             # Allow 3. and .3, but not .
             ValueError, "Invalid literal for Fraction: .",
-            R, ".")
+            F, ".")
 
     def testImmutable(self):
-        r = R(7, 3)
+        r = F(7, 3)
         r.__init__(2, 15)
         self.assertEquals((7, 3), _components(r))
 
@@ -134,250 +134,237 @@
         r._denominator = 2
         self.assertEquals((4, 2), _components(r))
         # Which breaks some important operations:
-        self.assertNotEquals(R(4, 2), r)
+        self.assertNotEquals(F(4, 2), r)
 
     def testFromFloat(self):
         self.assertRaisesMessage(
             TypeError, "Fraction.from_float() only takes floats, not 3 (int)",
-            R.from_float, 3)
+            F.from_float, 3)
 
-        self.assertEquals((0, 1), _components(R.from_float(-0.0)))
-        self.assertEquals((10, 1), _components(R.from_float(10.0)))
-        self.assertEquals((-5, 2), _components(R.from_float(-2.5)))
+        self.assertEquals((0, 1), _components(F.from_float(-0.0)))
+        self.assertEquals((10, 1), _components(F.from_float(10.0)))
+        self.assertEquals((-5, 2), _components(F.from_float(-2.5)))
         self.assertEquals((99999999999999991611392, 1),
-                          _components(R.from_float(1e23)))
-        self.assertEquals(float(10**23), float(R.from_float(1e23)))
+                          _components(F.from_float(1e23)))
+        self.assertEquals(float(10**23), float(F.from_float(1e23)))
         self.assertEquals((3602879701896397, 1125899906842624),
-                          _components(R.from_float(3.2)))
-        self.assertEquals(3.2, float(R.from_float(3.2)))
+                          _components(F.from_float(3.2)))
+        self.assertEquals(3.2, float(F.from_float(3.2)))
 
         inf = 1e1000
         nan = inf - inf
         self.assertRaisesMessage(
             TypeError, "Cannot convert inf to Fraction.",
-            R.from_float, inf)
+            F.from_float, inf)
         self.assertRaisesMessage(
             TypeError, "Cannot convert -inf to Fraction.",
-            R.from_float, -inf)
+            F.from_float, -inf)
         self.assertRaisesMessage(
             TypeError, "Cannot convert nan to Fraction.",
-            R.from_float, nan)
+            F.from_float, nan)
 
     def testFromDecimal(self):
         self.assertRaisesMessage(
             TypeError,
             "Fraction.from_decimal() only takes Decimals, not 3 (int)",
-            R.from_decimal, 3)
-        self.assertEquals(R(0), R.from_decimal(Decimal("-0")))
-        self.assertEquals(R(5, 10), R.from_decimal(Decimal("0.5")))
-        self.assertEquals(R(5, 1000), R.from_decimal(Decimal("5e-3")))
-        self.assertEquals(R(5000), R.from_decimal(Decimal("5e3")))
-        self.assertEquals(1 - R(1, 10**30),
-                          R.from_decimal(Decimal("0." + "9" * 30)))
+            F.from_decimal, 3)
+        self.assertEquals(F(0), F.from_decimal(Decimal("-0")))
+        self.assertEquals(F(5, 10), F.from_decimal(Decimal("0.5")))
+        self.assertEquals(F(5, 1000), F.from_decimal(Decimal("5e-3")))
+        self.assertEquals(F(5000), F.from_decimal(Decimal("5e3")))
+        self.assertEquals(1 - F(1, 10**30),
+                          F.from_decimal(Decimal("0." + "9" * 30)))
 
         self.assertRaisesMessage(
             TypeError, "Cannot convert Infinity to Fraction.",
-            R.from_decimal, Decimal("inf"))
+            F.from_decimal, Decimal("inf"))
         self.assertRaisesMessage(
             TypeError, "Cannot convert -Infinity to Fraction.",
-            R.from_decimal, Decimal("-inf"))
+            F.from_decimal, Decimal("-inf"))
         self.assertRaisesMessage(
             TypeError, "Cannot convert NaN to Fraction.",
-            R.from_decimal, Decimal("nan"))
+            F.from_decimal, Decimal("nan"))
         self.assertRaisesMessage(
             TypeError, "Cannot convert sNaN to Fraction.",
-            R.from_decimal, Decimal("snan"))
+            F.from_decimal, Decimal("snan"))
 
-    def testFromContinuedFraction(self):
-        self.assertRaises(TypeError, R.from_continued_fraction, None)
-        phi = R.from_continued_fraction([1]*100)
-        self.assertEquals(round(phi - (1 + 5 ** 0.5) / 2, 10), 0.0)
-
-        minusphi = R.from_continued_fraction([-1]*100)
-        self.assertEquals(round(minusphi + (1 + 5 ** 0.5) / 2, 10), 0.0)
-
-        self.assertEquals(R.from_continued_fraction([0]), R(0))
-        self.assertEquals(R.from_continued_fraction([]), R(0))
-
-    def testAsContinuedFraction(self):
-        self.assertEqual(R.from_float(math.pi).as_continued_fraction()[:15],
-                         [3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
-        self.assertEqual(R.from_float(-math.pi).as_continued_fraction()[:16],
-                         [-4, 1, 6, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 3, 3])
-        self.assertEqual(R(0).as_continued_fraction(), [0])
-
-    def testApproximateFrom(self):
-        self.assertEqual(R.from_float(math.pi).approximate(10000), R(355, 113))
-        self.assertEqual(R.from_float(-math.pi).approximate(10000), R(-355, 113))
-        self.assertEqual(R.from_float(0.0).approximate(10000), R(0))
+    def testLimitDenominator(self):
+        rpi = F('3.1415926535897932')
+        self.assertEqual(rpi.limit_denominator(10000), F(355, 113))
+        self.assertEqual(-rpi.limit_denominator(10000), F(-355, 113))
+        self.assertEqual(rpi.limit_denominator(113), F(355, 113))
+        self.assertEqual(rpi.limit_denominator(112), F(333, 106))
+        self.assertEqual(F(201, 200).limit_denominator(100), F(1))
+        self.assertEqual(F(201, 200).limit_denominator(101), F(102, 101))
+        self.assertEqual(F(0).limit_denominator(10000), F(0))
 
     def testConversions(self):
-        self.assertTypedEquals(-1, math.trunc(R(-11, 10)))
-        self.assertTypedEquals(-1, int(R(-11, 10)))
+        self.assertTypedEquals(-1, math.trunc(F(-11, 10)))
+        self.assertTypedEquals(-1, int(F(-11, 10)))
 
-        self.assertEquals(False, bool(R(0, 1)))
-        self.assertEquals(True, bool(R(3, 2)))
-        self.assertTypedEquals(0.1, float(R(1, 10)))
+        self.assertEquals(False, bool(F(0, 1)))
+        self.assertEquals(True, bool(F(3, 2)))
+        self.assertTypedEquals(0.1, float(F(1, 10)))
 
         # Check that __float__ isn't implemented by converting the
         # numerator and denominator to float before dividing.
         self.assertRaises(OverflowError, float, long('2'*400+'7'))
         self.assertAlmostEquals(2.0/3,
-                                float(R(long('2'*400+'7'), long('3'*400+'1'))))
+                                float(F(long('2'*400+'7'), long('3'*400+'1'))))
 
-        self.assertTypedEquals(0.1+0j, complex(R(1,10)))
+        self.assertTypedEquals(0.1+0j, complex(F(1,10)))
 
 
     def testArithmetic(self):
-        self.assertEquals(R(1, 2), R(1, 10) + R(2, 5))
-        self.assertEquals(R(-3, 10), R(1, 10) - R(2, 5))
-        self.assertEquals(R(1, 25), R(1, 10) * R(2, 5))
-        self.assertEquals(R(1, 4), R(1, 10) / R(2, 5))
-        self.assertTypedEquals(2, R(9, 10) // R(2, 5))
-        self.assertTypedEquals(10**23, R(10**23, 1) // R(1))
-        self.assertEquals(R(2, 3), R(-7, 3) % R(3, 2))
-        self.assertEquals(R(8, 27), R(2, 3) ** R(3))
-        self.assertEquals(R(27, 8), R(2, 3) ** R(-3))
-        self.assertTypedEquals(2.0, R(4) ** R(1, 2))
+        self.assertEquals(F(1, 2), F(1, 10) + F(2, 5))
+        self.assertEquals(F(-3, 10), F(1, 10) - F(2, 5))
+        self.assertEquals(F(1, 25), F(1, 10) * F(2, 5))
+        self.assertEquals(F(1, 4), F(1, 10) / F(2, 5))
+        self.assertTypedEquals(2, F(9, 10) // F(2, 5))
+        self.assertTypedEquals(10**23, F(10**23, 1) // F(1))
+        self.assertEquals(F(2, 3), F(-7, 3) % F(3, 2))
+        self.assertEquals(F(8, 27), F(2, 3) ** F(3))
+        self.assertEquals(F(27, 8), F(2, 3) ** F(-3))
+        self.assertTypedEquals(2.0, F(4) ** F(1, 2))
         # Will return 1j in 3.0:
-        self.assertRaises(ValueError, pow, R(-1), R(1, 2))
+        self.assertRaises(ValueError, pow, F(-1), F(1, 2))
 
     def testMixedArithmetic(self):
-        self.assertTypedEquals(R(11, 10), R(1, 10) + 1)
-        self.assertTypedEquals(1.1, R(1, 10) + 1.0)
-        self.assertTypedEquals(1.1 + 0j, R(1, 10) + (1.0 + 0j))
-        self.assertTypedEquals(R(11, 10), 1 + R(1, 10))
-        self.assertTypedEquals(1.1, 1.0 + R(1, 10))
-        self.assertTypedEquals(1.1 + 0j, (1.0 + 0j) + R(1, 10))
-
-        self.assertTypedEquals(R(-9, 10), R(1, 10) - 1)
-        self.assertTypedEquals(-0.9, R(1, 10) - 1.0)
-        self.assertTypedEquals(-0.9 + 0j, R(1, 10) - (1.0 + 0j))
-        self.assertTypedEquals(R(9, 10), 1 - R(1, 10))
-        self.assertTypedEquals(0.9, 1.0 - R(1, 10))
-        self.assertTypedEquals(0.9 + 0j, (1.0 + 0j) - R(1, 10))
-
-        self.assertTypedEquals(R(1, 10), R(1, 10) * 1)
-        self.assertTypedEquals(0.1, R(1, 10) * 1.0)
-        self.assertTypedEquals(0.1 + 0j, R(1, 10) * (1.0 + 0j))
-        self.assertTypedEquals(R(1, 10), 1 * R(1, 10))
-        self.assertTypedEquals(0.1, 1.0 * R(1, 10))
-        self.assertTypedEquals(0.1 + 0j, (1.0 + 0j) * R(1, 10))
-
-        self.assertTypedEquals(R(1, 10), R(1, 10) / 1)
-        self.assertTypedEquals(0.1, R(1, 10) / 1.0)
-        self.assertTypedEquals(0.1 + 0j, R(1, 10) / (1.0 + 0j))
-        self.assertTypedEquals(R(10, 1), 1 / R(1, 10))
-        self.assertTypedEquals(10.0, 1.0 / R(1, 10))
-        self.assertTypedEquals(10.0 + 0j, (1.0 + 0j) / R(1, 10))
-
-        self.assertTypedEquals(0, R(1, 10) // 1)
-        self.assertTypedEquals(0.0, R(1, 10) // 1.0)
-        self.assertTypedEquals(10, 1 // R(1, 10))
-        self.assertTypedEquals(10**23, 10**22 // R(1, 10))
-        self.assertTypedEquals(10.0, 1.0 // R(1, 10))
-
-        self.assertTypedEquals(R(1, 10), R(1, 10) % 1)
-        self.assertTypedEquals(0.1, R(1, 10) % 1.0)
-        self.assertTypedEquals(R(0, 1), 1 % R(1, 10))
-        self.assertTypedEquals(0.0, 1.0 % R(1, 10))
+        self.assertTypedEquals(F(11, 10), F(1, 10) + 1)
+        self.assertTypedEquals(1.1, F(1, 10) + 1.0)
+        self.assertTypedEquals(1.1 + 0j, F(1, 10) + (1.0 + 0j))
+        self.assertTypedEquals(F(11, 10), 1 + F(1, 10))
+        self.assertTypedEquals(1.1, 1.0 + F(1, 10))
+        self.assertTypedEquals(1.1 + 0j, (1.0 + 0j) + F(1, 10))
+
+        self.assertTypedEquals(F(-9, 10), F(1, 10) - 1)
+        self.assertTypedEquals(-0.9, F(1, 10) - 1.0)
+        self.assertTypedEquals(-0.9 + 0j, F(1, 10) - (1.0 + 0j))
+        self.assertTypedEquals(F(9, 10), 1 - F(1, 10))
+        self.assertTypedEquals(0.9, 1.0 - F(1, 10))
+        self.assertTypedEquals(0.9 + 0j, (1.0 + 0j) - F(1, 10))
+
+        self.assertTypedEquals(F(1, 10), F(1, 10) * 1)
+        self.assertTypedEquals(0.1, F(1, 10) * 1.0)
+        self.assertTypedEquals(0.1 + 0j, F(1, 10) * (1.0 + 0j))
+        self.assertTypedEquals(F(1, 10), 1 * F(1, 10))
+        self.assertTypedEquals(0.1, 1.0 * F(1, 10))
+        self.assertTypedEquals(0.1 + 0j, (1.0 + 0j) * F(1, 10))
+
+        self.assertTypedEquals(F(1, 10), F(1, 10) / 1)
+        self.assertTypedEquals(0.1, F(1, 10) / 1.0)
+        self.assertTypedEquals(0.1 + 0j, F(1, 10) / (1.0 + 0j))
+        self.assertTypedEquals(F(10, 1), 1 / F(1, 10))
+        self.assertTypedEquals(10.0, 1.0 / F(1, 10))
+        self.assertTypedEquals(10.0 + 0j, (1.0 + 0j) / F(1, 10))
+
+        self.assertTypedEquals(0, F(1, 10) // 1)
+        self.assertTypedEquals(0.0, F(1, 10) // 1.0)
+        self.assertTypedEquals(10, 1 // F(1, 10))
+        self.assertTypedEquals(10**23, 10**22 // F(1, 10))
+        self.assertTypedEquals(10.0, 1.0 // F(1, 10))
+
+        self.assertTypedEquals(F(1, 10), F(1, 10) % 1)
+        self.assertTypedEquals(0.1, F(1, 10) % 1.0)
+        self.assertTypedEquals(F(0, 1), 1 % F(1, 10))
+        self.assertTypedEquals(0.0, 1.0 % F(1, 10))
 
         # No need for divmod since we don't override it.
 
         # ** has more interesting conversion rules.
-        self.assertTypedEquals(R(100, 1), R(1, 10) ** -2)
-        self.assertTypedEquals(R(100, 1), R(10, 1) ** 2)
-        self.assertTypedEquals(0.1, R(1, 10) ** 1.0)
-        self.assertTypedEquals(0.1 + 0j, R(1, 10) ** (1.0 + 0j))
-        self.assertTypedEquals(4 , 2 ** R(2, 1))
+        self.assertTypedEquals(F(100, 1), F(1, 10) ** -2)
+        self.assertTypedEquals(F(100, 1), F(10, 1) ** 2)
+        self.assertTypedEquals(0.1, F(1, 10) ** 1.0)
+        self.assertTypedEquals(0.1 + 0j, F(1, 10) ** (1.0 + 0j))
+        self.assertTypedEquals(4 , 2 ** F(2, 1))
         # Will return 1j in 3.0:
-        self.assertRaises(ValueError, pow, (-1), R(1, 2))
-        self.assertTypedEquals(R(1, 4) , 2 ** R(-2, 1))
-        self.assertTypedEquals(2.0 , 4 ** R(1, 2))
-        self.assertTypedEquals(0.25, 2.0 ** R(-2, 1))
-        self.assertTypedEquals(1.0 + 0j, (1.0 + 0j) ** R(1, 10))
+        self.assertRaises(ValueError, pow, (-1), F(1, 2))
+        self.assertTypedEquals(F(1, 4) , 2 ** F(-2, 1))
+        self.assertTypedEquals(2.0 , 4 ** F(1, 2))
+        self.assertTypedEquals(0.25, 2.0 ** F(-2, 1))
+        self.assertTypedEquals(1.0 + 0j, (1.0 + 0j) ** F(1, 10))
 
     def testMixingWithDecimal(self):
         # Decimal refuses mixed comparisons.
         self.assertRaisesMessage(
             TypeError,
             "unsupported operand type(s) for +: 'Fraction' and 'Decimal'",
-            operator.add, R(3,11), Decimal('3.1415926'))
-        self.assertNotEquals(R(5, 2), Decimal('2.5'))
+            operator.add, F(3,11), Decimal('3.1415926'))
+        self.assertNotEquals(F(5, 2), Decimal('2.5'))
 
     def testComparisons(self):
-        self.assertTrue(R(1, 2) < R(2, 3))
-        self.assertFalse(R(1, 2) < R(1, 2))
-        self.assertTrue(R(1, 2) <= R(2, 3))
-        self.assertTrue(R(1, 2) <= R(1, 2))
-        self.assertFalse(R(2, 3) <= R(1, 2))
-        self.assertTrue(R(1, 2) == R(1, 2))
-        self.assertFalse(R(1, 2) == R(1, 3))
-        self.assertFalse(R(1, 2) != R(1, 2))
-        self.assertTrue(R(1, 2) != R(1, 3))
+        self.assertTrue(F(1, 2) < F(2, 3))
+        self.assertFalse(F(1, 2) < F(1, 2))
+        self.assertTrue(F(1, 2) <= F(2, 3))
+        self.assertTrue(F(1, 2) <= F(1, 2))
+        self.assertFalse(F(2, 3) <= F(1, 2))
+        self.assertTrue(F(1, 2) == F(1, 2))
+        self.assertFalse(F(1, 2) == F(1, 3))
+        self.assertFalse(F(1, 2) != F(1, 2))
+        self.assertTrue(F(1, 2) != F(1, 3))
 
     def testMixedLess(self):
-        self.assertTrue(2 < R(5, 2))
-        self.assertFalse(2 < R(4, 2))
-        self.assertTrue(R(5, 2) < 3)
-        self.assertFalse(R(4, 2) < 2)
-
-        self.assertTrue(R(1, 2) < 0.6)
-        self.assertFalse(R(1, 2) < 0.4)
-        self.assertTrue(0.4 < R(1, 2))
-        self.assertFalse(0.5 < R(1, 2))
+        self.assertTrue(2 < F(5, 2))
+        self.assertFalse(2 < F(4, 2))
+        self.assertTrue(F(5, 2) < 3)
+        self.assertFalse(F(4, 2) < 2)
+
+        self.assertTrue(F(1, 2) < 0.6)
+        self.assertFalse(F(1, 2) < 0.4)
+        self.assertTrue(0.4 < F(1, 2))
+        self.assertFalse(0.5 < F(1, 2))
 
     def testMixedLessEqual(self):
-        self.assertTrue(0.5 <= R(1, 2))
-        self.assertFalse(0.6 <= R(1, 2))
-        self.assertTrue(R(1, 2) <= 0.5)
-        self.assertFalse(R(1, 2) <= 0.4)
-        self.assertTrue(2 <= R(4, 2))
-        self.assertFalse(2 <= R(3, 2))
-        self.assertTrue(R(4, 2) <= 2)
-        self.assertFalse(R(5, 2) <= 2)
+        self.assertTrue(0.5 <= F(1, 2))
+        self.assertFalse(0.6 <= F(1, 2))
+        self.assertTrue(F(1, 2) <= 0.5)
+        self.assertFalse(F(1, 2) <= 0.4)
+        self.assertTrue(2 <= F(4, 2))
+        self.assertFalse(2 <= F(3, 2))
+        self.assertTrue(F(4, 2) <= 2)
+        self.assertFalse(F(5, 2) <= 2)
 
     def testBigFloatComparisons(self):
         # Because 10**23 can't be represented exactly as a float:
-        self.assertFalse(R(10**23) == float(10**23))
+        self.assertFalse(F(10**23) == float(10**23))
         # The first test demonstrates why these are important.
-        self.assertFalse(1e23 < float(R(math.trunc(1e23) + 1)))
-        self.assertTrue(1e23 < R(math.trunc(1e23) + 1))
-        self.assertFalse(1e23 <= R(math.trunc(1e23) - 1))
-        self.assertTrue(1e23 > R(math.trunc(1e23) - 1))
-        self.assertFalse(1e23 >= R(math.trunc(1e23) + 1))
+        self.assertFalse(1e23 < float(F(math.trunc(1e23) + 1)))
+        self.assertTrue(1e23 < F(math.trunc(1e23) + 1))
+        self.assertFalse(1e23 <= F(math.trunc(1e23) - 1))
+        self.assertTrue(1e23 > F(math.trunc(1e23) - 1))
+        self.assertFalse(1e23 >= F(math.trunc(1e23) + 1))
 
     def testBigComplexComparisons(self):
-        self.assertFalse(R(10**23) == complex(10**23))
-        self.assertTrue(R(10**23) > complex(10**23))
-        self.assertFalse(R(10**23) <= complex(10**23))
+        self.assertFalse(F(10**23) == complex(10**23))
+        self.assertTrue(F(10**23) > complex(10**23))
+        self.assertFalse(F(10**23) <= complex(10**23))
 
     def testMixedEqual(self):
-        self.assertTrue(0.5 == R(1, 2))
-        self.assertFalse(0.6 == R(1, 2))
-        self.assertTrue(R(1, 2) == 0.5)
-        self.assertFalse(R(1, 2) == 0.4)
-        self.assertTrue(2 == R(4, 2))
-        self.assertFalse(2 == R(3, 2))
-        self.assertTrue(R(4, 2) == 2)
-        self.assertFalse(R(5, 2) == 2)
+        self.assertTrue(0.5 == F(1, 2))
+        self.assertFalse(0.6 == F(1, 2))
+        self.assertTrue(F(1, 2) == 0.5)
+        self.assertFalse(F(1, 2) == 0.4)
+        self.assertTrue(2 == F(4, 2))
+        self.assertFalse(2 == F(3, 2))
+        self.assertTrue(F(4, 2) == 2)
+        self.assertFalse(F(5, 2) == 2)
 
     def testStringification(self):
-        self.assertEquals("Fraction(7, 3)", repr(R(7, 3)))
-        self.assertEquals("7/3", str(R(7, 3)))
-        self.assertEquals("7", str(R(7, 1)))
+        self.assertEquals("Fraction(7, 3)", repr(F(7, 3)))
+        self.assertEquals("7/3", str(F(7, 3)))
+        self.assertEquals("7", str(F(7, 1)))
 
     def testHash(self):
-        self.assertEquals(hash(2.5), hash(R(5, 2)))
-        self.assertEquals(hash(10**50), hash(R(10**50)))
-        self.assertNotEquals(hash(float(10**23)), hash(R(10**23)))
+        self.assertEquals(hash(2.5), hash(F(5, 2)))
+        self.assertEquals(hash(10**50), hash(F(10**50)))
+        self.assertNotEquals(hash(float(10**23)), hash(F(10**23)))
 
     def testApproximatePi(self):
         # Algorithm borrowed from
         # http://docs.python.org/lib/decimal-recipes.html
-        three = R(3)
+        three = F(3)
         lasts, t, s, n, na, d, da = 0, three, 3, 1, 0, 0, 24
-        while abs(s - lasts) > R(1, 10**9):
+        while abs(s - lasts) > F(1, 10**9):
             lasts = s
             n, na = n+na, na+8
             d, da = d+da, da+32
@@ -388,9 +375,9 @@
     def testApproximateCos1(self):
         # Algorithm borrowed from
         # http://docs.python.org/lib/decimal-recipes.html
-        x = R(1)
-        i, lasts, s, fact, num, sign = 0, 0, R(1), 1, 1, 1
-        while abs(s - lasts) > R(1, 10**9):
+        x = F(1)
+        i, lasts, s, fact, num, sign = 0, 0, F(1), 1, 1, 1
+        while abs(s - lasts) > F(1, 10**9):
             lasts = s
             i += 2
             fact *= i * (i-1)
@@ -400,7 +387,7 @@
         self.assertAlmostEquals(math.cos(1), s)
 
     def test_copy_deepcopy_pickle(self):
-        r = R(13, 7)
+        r = F(13, 7)
         self.assertEqual(r, loads(dumps(r)))
         self.assertEqual(id(r), id(copy(r)))
         self.assertEqual(id(r), id(deepcopy(r)))

Modified: python/branches/trunk-math/Misc/NEWS
==============================================================================
--- python/branches/trunk-math/Misc/NEWS	(original)
+++ python/branches/trunk-math/Misc/NEWS	Thu Feb 14 09:32:39 2008
@@ -408,6 +408,12 @@
 Library
 -------
 
+- ctypes instances that are not or do not contain pointers can now be
+  pickled.
+
+- Patch #1966: Break infinite loop in httplib when the servers
+  implements the chunked encoding incorrectly.
+
 - Rename rational.py to fractions.py and the rational.Rational class
   to fractions.Fraction, to avoid the name clash with the abstract
   base class numbers.Rational.  See discussion in issue #1682.
@@ -1137,6 +1143,10 @@
 Extension Modules
 -----------------
 
+- #2063: correct order of utime and stime in os.times() result on Windows.
+
+- Patch #1736: Fix file name handling of _msi.FCICreate.
+
 - Updated ``big5hkscs`` codec to the HKSCS revision of 2004.
 
 - #1940: make it possible to use curses.filter() before curses.initscr()

Modified: python/branches/trunk-math/Modules/_collectionsmodule.c
==============================================================================
--- python/branches/trunk-math/Modules/_collectionsmodule.c	(original)
+++ python/branches/trunk-math/Modules/_collectionsmodule.c	Thu Feb 14 09:32:39 2008
@@ -1186,23 +1186,13 @@
 {
 	/* This calls the object's class.  That only works for subclasses
 	   whose class constructor has the same signature.  Subclasses that
-	   define a different constructor signature must override __copy__().
+	   define a different constructor signature must override copy().
 	*/
 	return PyObject_CallFunctionObjArgs((PyObject*)Py_TYPE(dd),
 					    dd->default_factory, dd, NULL);
 }
 
 static PyObject *
-defdict_copy_method(defdictobject *dd)
-{
-	if (Py_Py3kWarningFlag &&
-	    PyErr_Warn(PyExc_DeprecationWarning, 
-		       "defaultdict.copy() not supported in 3.x") < 0)
-		return NULL;
-	return defdict_copy(dd);
-}
-
-static PyObject *
 defdict_reduce(defdictobject *dd)
 {
 	/* __reduce__ must return a 5-tuple as follows:
@@ -1251,7 +1241,7 @@
 static PyMethodDef defdict_methods[] = {
 	{"__missing__", (PyCFunction)defdict_missing, METH_O,
 	 defdict_missing_doc},
-	{"copy", (PyCFunction)defdict_copy_method, METH_NOARGS,
+	{"copy", (PyCFunction)defdict_copy, METH_NOARGS,
 	 defdict_copy_doc},
 	{"__copy__", (PyCFunction)defdict_copy, METH_NOARGS,
 	 defdict_copy_doc},

Modified: python/branches/trunk-math/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/trunk-math/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/trunk-math/Modules/_ctypes/_ctypes.c	Thu Feb 14 09:32:39 2008
@@ -128,6 +128,9 @@
 PyObject *PyExc_ArgError;
 static PyTypeObject Simple_Type;
 
+/* a callable object used for unpickling */
+static PyObject *_unpickle;
+
 char *conversion_mode_encoding = NULL;
 char *conversion_mode_errors = NULL;
 
@@ -718,6 +721,7 @@
 	stgdict->length = 1;
 	stgdict->ffi_type_pointer = ffi_type_pointer;
 	stgdict->paramfunc = PointerType_paramfunc;
+	stgdict->flags |= TYPEFLAG_ISPOINTER;
 
 	proto = PyDict_GetItemString(typedict, "_type_"); /* Borrowed ref */
 	if (proto && -1 == PointerType_SetProto(stgdict, proto)) {
@@ -1139,6 +1143,9 @@
 
 	itemalign = itemdict->align;
 
+	if (itemdict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
+		stgdict->flags |= TYPEFLAG_HASPOINTER;
+
 	stgdict->size = itemsize * length;
 	stgdict->align = itemalign;
 	stgdict->length = length;
@@ -1684,12 +1691,21 @@
 		switch (PyString_AS_STRING(proto)[0]) {
 		case 'z': /* c_char_p */
 			ml = &c_char_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		case 'Z': /* c_wchar_p */
 			ml = &c_wchar_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		case 'P': /* c_void_p */
 			ml = &c_void_p_method;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
+			break;
+		case 'u':
+		case 'X':
+		case 'O':
+			ml = NULL;
+			stgdict->flags |= TYPEFLAG_ISPOINTER;
 			break;
 		default:
 			ml = NULL;
@@ -1926,7 +1942,7 @@
 		    "class must define _flags_ which must be an integer");
 		return -1;
 	}
-	stgdict->flags = PyInt_AS_LONG(ob);
+	stgdict->flags = PyInt_AS_LONG(ob) | TYPEFLAG_ISPOINTER;
 
 	/* _argtypes_ is optional... */
 	ob = PyDict_GetItemString((PyObject *)stgdict, "_argtypes_");
@@ -2001,6 +2017,7 @@
 		return NULL;
 
 	stgdict->paramfunc = CFuncPtrType_paramfunc;
+	stgdict->flags |= TYPEFLAG_ISPOINTER;
 
 	/* create the new instance (which is a class,
 	   since we are a metatype!) */
@@ -2255,6 +2272,45 @@
 	return -1;
 }
 
+static PyObject *
+CData_reduce(PyObject *_self, PyObject *args)
+{
+	CDataObject *self = (CDataObject *)_self;
+
+	if (PyObject_stgdict(_self)->flags & (TYPEFLAG_ISPOINTER|TYPEFLAG_HASPOINTER)) {
+		PyErr_SetString(PyExc_ValueError,
+				"ctypes objects containing pointers cannot be pickled");
+		return NULL;
+	}
+	return Py_BuildValue("O(O(NN))",
+			     _unpickle,
+			     Py_TYPE(_self),
+			     PyObject_GetAttrString(_self, "__dict__"),
+			     PyString_FromStringAndSize(self->b_ptr, self->b_size));
+}
+
+static PyObject *
+CData_setstate(PyObject *_self, PyObject *args)
+{
+	void *data;
+	int len;
+	int res;
+	PyObject *dict, *mydict;
+	CDataObject *self = (CDataObject *)_self;
+	if (!PyArg_ParseTuple(args, "Os#", &dict, &data, &len))
+		return NULL;
+	if (len > self->b_size)
+		len = self->b_size;
+	memmove(self->b_ptr, data, len);
+	mydict = PyObject_GetAttrString(_self, "__dict__");
+	res = PyDict_Update(mydict, dict);
+	Py_DECREF(mydict);
+	if (res == -1)
+		return NULL;
+	Py_INCREF(Py_None);
+	return Py_None;
+}
+
 /*
  * default __ctypes_from_outparam__ method returns self.
  */
@@ -2267,6 +2323,8 @@
 
 static PyMethodDef CData_methods[] = {
 	{ "__ctypes_from_outparam__", CData_from_outparam, METH_NOARGS, },
+	{ "__reduce__", CData_reduce, METH_NOARGS, },
+	{ "__setstate__", CData_setstate, METH_VARARGS, },
 	{ NULL, NULL },
 };
 
@@ -5107,6 +5165,10 @@
 	if (!m)
 		return;
 
+	_unpickle = PyObject_GetAttrString(m, "_unpickle");
+	if (_unpickle == NULL)
+		return;
+
 	if (PyType_Ready(&PyCArg_Type) < 0)
 		return;
 

Modified: python/branches/trunk-math/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/trunk-math/Modules/_ctypes/callproc.c	(original)
+++ python/branches/trunk-math/Modules/_ctypes/callproc.c	Thu Feb 14 09:32:39 2008
@@ -1578,7 +1578,30 @@
 	return Py_None;
 }
 
+static PyObject *
+unpickle(PyObject *self, PyObject *args)
+{
+	PyObject *typ;
+	PyObject *state;
+	PyObject *result;
+	PyObject *tmp;
+
+	if (!PyArg_ParseTuple(args, "OO", &typ, &state))
+		return NULL;
+	result = PyObject_CallMethod(typ, "__new__", "O", typ);
+	if (result == NULL)
+		return NULL;
+	tmp = PyObject_CallMethod(result, "__setstate__", "O", state);
+	if (tmp == NULL) {
+		Py_DECREF(result);
+		return NULL;
+	}
+	Py_DECREF(tmp);
+	return result;
+}
+
 PyMethodDef module_methods[] = {
+	{"_unpickle", unpickle, METH_VARARGS },
 	{"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
 #ifdef CTYPES_UNICODE
 	{"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},

Modified: python/branches/trunk-math/Modules/_ctypes/ctypes.h
==============================================================================
--- python/branches/trunk-math/Modules/_ctypes/ctypes.h	(original)
+++ python/branches/trunk-math/Modules/_ctypes/ctypes.h	Thu Feb 14 09:32:39 2008
@@ -286,6 +286,9 @@
 #define FUNCFLAG_HRESULT 0x2
 #define FUNCFLAG_PYTHONAPI 0x4
 
+#define TYPEFLAG_ISPOINTER 0x100
+#define TYPEFLAG_HASPOINTER 0x200
+
 #define DICTFLAG_FINAL 0x1000
 
 struct tagPyCArgObject {

Modified: python/branches/trunk-math/Modules/_ctypes/stgdict.c
==============================================================================
--- python/branches/trunk-math/Modules/_ctypes/stgdict.c	(original)
+++ python/branches/trunk-math/Modules/_ctypes/stgdict.c	Thu Feb 14 09:32:39 2008
@@ -414,6 +414,8 @@
 			return -1;
 		}
 		stgdict->ffi_type_pointer.elements[ffi_ofs + i] = &dict->ffi_type_pointer;
+		if (dict->flags & (TYPEFLAG_ISPOINTER | TYPEFLAG_HASPOINTER))
+			stgdict->flags |= TYPEFLAG_HASPOINTER;
 		dict->flags |= DICTFLAG_FINAL; /* mark field type final */
 		if (PyTuple_Size(pair) == 3) { /* bits specified */
 			switch(dict->ffi_type_pointer.type) {

Modified: python/branches/trunk-math/Modules/posixmodule.c
==============================================================================
--- python/branches/trunk-math/Modules/posixmodule.c	(original)
+++ python/branches/trunk-math/Modules/posixmodule.c	Thu Feb 14 09:32:39 2008
@@ -5987,10 +5987,10 @@
 	*/
 	return Py_BuildValue(
 		"ddddd",
-		(double)(kernel.dwHighDateTime*429.4967296 +
-		         kernel.dwLowDateTime*1e-7),
 		(double)(user.dwHighDateTime*429.4967296 +
 		         user.dwLowDateTime*1e-7),
+		(double)(kernel.dwHighDateTime*429.4967296 +
+		         kernel.dwLowDateTime*1e-7),
 		(double)0,
 		(double)0,
 		(double)0);

Modified: python/branches/trunk-math/Objects/dictobject.c
==============================================================================
--- python/branches/trunk-math/Objects/dictobject.c	(original)
+++ python/branches/trunk-math/Objects/dictobject.c	Thu Feb 14 09:32:39 2008
@@ -1528,10 +1528,6 @@
 static PyObject *
 dict_copy(register PyDictObject *mp)
 {
-	if (Py_Py3kWarningFlag &&
-	    PyErr_Warn(PyExc_DeprecationWarning, 
-		       "dict.copy() not supported in 3.x") < 0)
-		return NULL;
 	return PyDict_Copy((PyObject*)mp);
 }
 

Modified: python/branches/trunk-math/Objects/setobject.c
==============================================================================
--- python/branches/trunk-math/Objects/setobject.c	(original)
+++ python/branches/trunk-math/Objects/setobject.c	Thu Feb 14 09:32:39 2008
@@ -1131,22 +1131,8 @@
 }
 
 static PyObject *
-set_copy_method(PySetObject *so)
-{
-	if (Py_Py3kWarningFlag &&
-	    PyErr_Warn(PyExc_DeprecationWarning, 
-		       "set.copy() not supported in 3.x") < 0)
-		return NULL;
-	return make_new_set(Py_TYPE(so), (PyObject *)so);
-}
-
-static PyObject *
 frozenset_copy(PySetObject *so)
 {
-	if (Py_Py3kWarningFlag &&
-	    PyErr_Warn(PyExc_DeprecationWarning, 
-		       "frozenset.copy() not supported in 3.x") < 0)
-		return NULL;
 	if (PyFrozenSet_CheckExact(so)) {
 		Py_INCREF(so);
 		return (PyObject *)so;
@@ -1925,7 +1911,7 @@
 	 clear_doc},
 	{"__contains__",(PyCFunction)set_direct_contains,	METH_O | METH_COEXIST,
 	 contains_doc},
-	{"copy",	(PyCFunction)set_copy_method,	METH_NOARGS,
+	{"copy",	(PyCFunction)set_copy,		METH_NOARGS,
 	 copy_doc},
 	{"discard",	(PyCFunction)set_discard,	METH_O,
 	 discard_doc},

Modified: python/branches/trunk-math/PC/_msi.c
==============================================================================
--- python/branches/trunk-math/PC/_msi.c	(original)
+++ python/branches/trunk-math/PC/_msi.c	Thu Feb 14 09:32:39 2008
@@ -180,12 +180,12 @@
 
 static PyObject* fcicreate(PyObject* obj, PyObject* args)
 {
-    char *cabname;
+    char *cabname, *p;
     PyObject *files;
     CCAB ccab;
     HFCI hfci;
     ERF erf;
-    int i;
+    Py_ssize_t i;
 
 
     if (!PyArg_ParseTuple(args, "sO:FCICreate", &cabname, &files))
@@ -208,22 +208,22 @@
     ccab.setID = 0;
     ccab.szDisk[0] = '\0';
 
-    for (i=0; cabname[i]; i++)
-	if (cabname[i] == '\\' || cabname[i] == '/')
-	    break;
+    for (i = 0, p = cabname; *p; p = CharNext(p))
+	if (*p == '\\' || *p == '/')
+	    i = p - cabname + 1;
 
-    if (i > sizeof(ccab.szCabPath) ||
-	strlen(cabname+i) > sizeof(ccab.szCab)) {
+    if (i >= sizeof(ccab.szCabPath) ||
+	strlen(cabname+i) >= sizeof(ccab.szCab)) {
 	PyErr_SetString(PyExc_ValueError, "path name too long");
 	return 0;
     }
 
-    if (cabname[i]) {
+    if (i > 0) {
 	memcpy(ccab.szCabPath, cabname, i);
 	ccab.szCabPath[i] = '\0';
 	strcpy(ccab.szCab, cabname+i);
     } else {
-	strcpy(ccab.szCabPath, ".");
+	strcpy(ccab.szCabPath, ".\\");
 	strcpy(ccab.szCab, cabname);
     }
 

Modified: python/branches/trunk-math/configure
==============================================================================
--- python/branches/trunk-math/configure	(original)
+++ python/branches/trunk-math/configure	Thu Feb 14 09:32:39 2008
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 60484 .
+# From configure.in Revision: 60536 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 2.6.
 #
@@ -1312,7 +1312,7 @@
 Optional Features:
   --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
-  --enable-universalsdk[SDKDIR]
+  --enable-universalsdk[=SDKDIR]
                           Build against Mac OS X 10.4u SDK (ppc/i386)
   --enable-framework[=INSTALLDIR]
                           Build (MacOSX|Darwin) framework

Modified: python/branches/trunk-math/configure.in
==============================================================================
--- python/branches/trunk-math/configure.in	(original)
+++ python/branches/trunk-math/configure.in	Thu Feb 14 09:32:39 2008
@@ -61,7 +61,7 @@
 CONFIG_ARGS="$ac_configure_args"
 
 AC_ARG_ENABLE(universalsdk,
-	AC_HELP_STRING(--enable-universalsdk@<:@SDKDIR@:>@, Build against Mac OS X 10.4u SDK (ppc/i386)),
+	AC_HELP_STRING(--enable-universalsdk@<:@=SDKDIR@:>@, Build against Mac OS X 10.4u SDK (ppc/i386)),
 [
 	case $enableval in
 	yes)


More information about the Python-checkins mailing list