[Python-checkins] r63547 - in python/trunk: Demo/pdist/cmptree.py Demo/pdist/server.py Doc/library/datatypes.rst Doc/library/repr.rst Doc/library/reprlib.rst Doc/tutorial/stdlib2.rst Lib/bdb.py Lib/copy.py Lib/idlelib/Debugger.py Lib/idlelib/ObjectBrowser.py Lib/pdb.py Lib/pydoc.py Lib/repr.py Lib/reprlib.py Lib/test/test___all__.py Lib/test/test_py3kwarn.py Lib/test/test_repr.py Lib/test/test_reprlib.py Misc/NEWS

brett.cannon python-checkins at python.org
Fri May 23 07:04:00 CEST 2008


Author: brett.cannon
Date: Fri May 23 07:03:59 2008
New Revision: 63547

Log:
Revert the renaming of repr to reprlib.

Added:
   python/trunk/Doc/library/repr.rst
   python/trunk/Lib/repr.py
      - copied unchanged from r63542, /python/trunk/Lib/reprlib.py
   python/trunk/Lib/test/test_repr.py
      - copied, changed from r63542, /python/trunk/Lib/test/test_reprlib.py
Removed:
   python/trunk/Doc/library/reprlib.rst
   python/trunk/Lib/reprlib.py
   python/trunk/Lib/test/test_reprlib.py
Modified:
   python/trunk/Demo/pdist/cmptree.py
   python/trunk/Demo/pdist/server.py
   python/trunk/Doc/library/datatypes.rst
   python/trunk/Doc/tutorial/stdlib2.rst
   python/trunk/Lib/bdb.py
   python/trunk/Lib/copy.py
   python/trunk/Lib/idlelib/Debugger.py
   python/trunk/Lib/idlelib/ObjectBrowser.py
   python/trunk/Lib/pdb.py
   python/trunk/Lib/pydoc.py
   python/trunk/Lib/test/test___all__.py
   python/trunk/Lib/test/test_py3kwarn.py
   python/trunk/Misc/NEWS

Modified: python/trunk/Demo/pdist/cmptree.py
==============================================================================
--- python/trunk/Demo/pdist/cmptree.py	(original)
+++ python/trunk/Demo/pdist/cmptree.py	Fri May 23 07:03:59 2008
@@ -1,7 +1,7 @@
 """Compare local and remote dictionaries and transfer differing files -- like rdist."""
 
 import sys
-from reprlib import repr
+from repr import repr
 import FSProxy
 import time
 import os

Modified: python/trunk/Demo/pdist/server.py
==============================================================================
--- python/trunk/Demo/pdist/server.py	(original)
+++ python/trunk/Demo/pdist/server.py	Fri May 23 07:03:59 2008
@@ -4,7 +4,7 @@
 import socket
 import pickle
 from fnmatch import fnmatch
-from reprlib import repr
+from repr import repr
 
 
 # Default verbosity (0 = silent, 1 = print connections, 2 = print requests too)

Modified: python/trunk/Doc/library/datatypes.rst
==============================================================================
--- python/trunk/Doc/library/datatypes.rst	(original)
+++ python/trunk/Doc/library/datatypes.rst	Fri May 23 07:03:59 2008
@@ -36,4 +36,4 @@
    new.rst
    copy.rst
    pprint.rst
-   reprlib.rst
+   repr.rst

Added: python/trunk/Doc/library/repr.rst
==============================================================================
--- (empty file)
+++ python/trunk/Doc/library/repr.rst	Fri May 23 07:03:59 2008
@@ -0,0 +1,139 @@
+
+:mod:`repr` --- Alternate :func:`repr` implementation
+=====================================================
+
+.. module:: repr
+   :synopsis: Alternate repr() implementation with size limits.
+.. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
+
+.. note::
+   The :mod:`repr` module has been renamed to :mod:`reprlib` in
+   Python 3.0.
+
+The :mod:`repr` module provides a means for producing object representations
+with limits on the size of the resulting strings. This is used in the Python
+debugger and may be useful in other contexts as well.
+
+This module provides a class, an instance, and a function:
+
+
+.. class:: Repr()
+
+   Class which provides formatting services useful in implementing functions
+   similar to the built-in :func:`repr`; size limits for  different object types
+   are added to avoid the generation of representations which are excessively long.
+
+
+.. data:: aRepr
+
+   This is an instance of :class:`Repr` which is used to provide the :func:`repr`
+   function described below.  Changing the attributes of this object will affect
+   the size limits used by :func:`repr` and the Python debugger.
+
+
+.. function:: repr(obj)
+
+   This is the :meth:`repr` method of ``aRepr``.  It returns a string similar to
+   that returned by the built-in function of the same  name, but with limits on
+   most sizes.
+
+
+.. _repr-objects:
+
+Repr Objects
+------------
+
+:class:`Repr` instances provide several members which can be used to provide
+size limits for the representations of different object types,  and methods
+which format specific object types.
+
+
+.. attribute:: Repr.maxlevel
+
+   Depth limit on the creation of recursive representations.  The default is ``6``.
+
+
+.. attribute:: Repr.maxdict
+               Repr.maxlist
+               Repr.maxtuple
+               Repr.maxset
+               Repr.maxfrozenset
+               Repr.maxdeque
+               Repr.maxarray
+
+   Limits on the number of entries represented for the named object type.  The
+   default is ``4`` for :attr:`maxdict`, ``5`` for :attr:`maxarray`, and  ``6`` for
+   the others.
+
+   .. versionadded:: 2.4
+      :attr:`maxset`, :attr:`maxfrozenset`, and :attr:`set`.
+
+
+.. attribute:: Repr.maxlong
+
+   Maximum number of characters in the representation for a long integer.  Digits
+   are dropped from the middle.  The default is ``40``.
+
+
+.. attribute:: Repr.maxstring
+
+   Limit on the number of characters in the representation of the string.  Note
+   that the "normal" representation of the string is used as the character source:
+   if escape sequences are needed in the representation, these may be mangled when
+   the representation is shortened.  The default is ``30``.
+
+
+.. attribute:: Repr.maxother
+
+   This limit is used to control the size of object types for which no specific
+   formatting method is available on the :class:`Repr` object. It is applied in a
+   similar manner as :attr:`maxstring`.  The default is ``20``.
+
+
+.. method:: Repr.repr(obj)
+
+   The equivalent to the built-in :func:`repr` that uses the formatting imposed by
+   the instance.
+
+
+.. method:: Repr.repr1(obj, level)
+
+   Recursive implementation used by :meth:`repr`.  This uses the type of *obj* to
+   determine which formatting method to call, passing it *obj* and *level*.  The
+   type-specific methods should call :meth:`repr1` to perform recursive formatting,
+   with ``level - 1`` for the value of *level* in the recursive  call.
+
+
+.. method:: Repr.repr_TYPE(obj, level)
+   :noindex:
+
+   Formatting methods for specific types are implemented as methods with a name
+   based on the type name.  In the method name, **TYPE** is replaced by
+   ``string.join(string.split(type(obj).__name__, '_'))``. Dispatch to these
+   methods is handled by :meth:`repr1`. Type-specific methods which need to
+   recursively format a value should call ``self.repr1(subobj, level - 1)``.
+
+
+.. _subclassing-reprs:
+
+Subclassing Repr Objects
+------------------------
+
+The use of dynamic dispatching by :meth:`Repr.repr1` allows subclasses of
+:class:`Repr` to add support for additional built-in object types or to modify
+the handling of types already supported. This example shows how special support
+for file objects could be added::
+
+   import repr
+   import sys
+
+   class MyRepr(repr.Repr):
+       def repr_file(self, obj, level):
+           if obj.name in ['<stdin>', '<stdout>', '<stderr>']:
+               return obj.name
+           else:
+               return `obj`
+
+   aRepr = MyRepr()
+   print aRepr.repr(sys.stdin)          # prints '<stdin>'
+

Deleted: python/trunk/Doc/library/reprlib.rst
==============================================================================
--- python/trunk/Doc/library/reprlib.rst	Fri May 23 07:03:59 2008
+++ (empty file)
@@ -1,143 +0,0 @@
-:mod:`reprlib` --- Alternate :func:`repr` implementation
-========================================================
-
-.. module:: repr
-   :synopsis: Old name for the reprlib module.
-
-.. module:: reprlib
-   :synopsis: Alternate repr() implementation with size limits.
-.. sectionauthor:: Fred L. Drake, Jr. <fdrake at acm.org>
-
-.. note::
-   The :mod:`repr` module has been renamed to :mod:`reprlib` in
-   Python 3.0.  It is importable under both names in Python 2.6
-   and the rest of the 2.x series.
-
-
-The :mod:`reprlib` module provides a means for producing object representations
-with limits on the size of the resulting strings. This is used in the Python
-debugger and may be useful in other contexts as well.
-
-This module provides a class, an instance, and a function:
-
-
-.. class:: Repr()
-
-   Class which provides formatting services useful in implementing functions
-   similar to the built-in :func:`repr`; size limits for  different object types
-   are added to avoid the generation of representations which are excessively long.
-
-
-.. data:: aRepr
-
-   This is an instance of :class:`Repr` which is used to provide the :func:`repr`
-   function described below.  Changing the attributes of this object will affect
-   the size limits used by :func:`repr` and the Python debugger.
-
-
-.. function:: repr(obj)
-
-   This is the :meth:`repr` method of ``aRepr``.  It returns a string similar to
-   that returned by the built-in function of the same  name, but with limits on
-   most sizes.
-
-
-.. _repr-objects:
-
-Repr Objects
-------------
-
-:class:`Repr` instances provide several members which can be used to provide
-size limits for the representations of different object types,  and methods
-which format specific object types.
-
-
-.. attribute:: Repr.maxlevel
-
-   Depth limit on the creation of recursive representations.  The default is ``6``.
-
-
-.. attribute:: Repr.maxdict
-               Repr.maxlist
-               Repr.maxtuple
-               Repr.maxset
-               Repr.maxfrozenset
-               Repr.maxdeque
-               Repr.maxarray
-
-   Limits on the number of entries represented for the named object type.  The
-   default is ``4`` for :attr:`maxdict`, ``5`` for :attr:`maxarray`, and  ``6`` for
-   the others.
-
-   .. versionadded:: 2.4
-      :attr:`maxset`, :attr:`maxfrozenset`, and :attr:`set`.
-
-
-.. attribute:: Repr.maxlong
-
-   Maximum number of characters in the representation for a long integer.  Digits
-   are dropped from the middle.  The default is ``40``.
-
-
-.. attribute:: Repr.maxstring
-
-   Limit on the number of characters in the representation of the string.  Note
-   that the "normal" representation of the string is used as the character source:
-   if escape sequences are needed in the representation, these may be mangled when
-   the representation is shortened.  The default is ``30``.
-
-
-.. attribute:: Repr.maxother
-
-   This limit is used to control the size of object types for which no specific
-   formatting method is available on the :class:`Repr` object. It is applied in a
-   similar manner as :attr:`maxstring`.  The default is ``20``.
-
-
-.. method:: Repr.repr(obj)
-
-   The equivalent to the built-in :func:`repr` that uses the formatting imposed by
-   the instance.
-
-
-.. method:: Repr.repr1(obj, level)
-
-   Recursive implementation used by :meth:`repr`.  This uses the type of *obj* to
-   determine which formatting method to call, passing it *obj* and *level*.  The
-   type-specific methods should call :meth:`repr1` to perform recursive formatting,
-   with ``level - 1`` for the value of *level* in the recursive  call.
-
-
-.. method:: Repr.repr_TYPE(obj, level)
-   :noindex:
-
-   Formatting methods for specific types are implemented as methods with a name
-   based on the type name.  In the method name, **TYPE** is replaced by
-   ``string.join(string.split(type(obj).__name__, '_'))``. Dispatch to these
-   methods is handled by :meth:`repr1`. Type-specific methods which need to
-   recursively format a value should call ``self.repr1(subobj, level - 1)``.
-
-
-.. _subclassing-reprs:
-
-Subclassing Repr Objects
-------------------------
-
-The use of dynamic dispatching by :meth:`Repr.repr1` allows subclasses of
-:class:`Repr` to add support for additional built-in object types or to modify
-the handling of types already supported. This example shows how special support
-for file objects could be added::
-
-   import repr
-   import sys
-
-   class MyRepr(repr.Repr):
-       def repr_file(self, obj, level):
-           if obj.name in ['<stdin>', '<stdout>', '<stderr>']:
-               return obj.name
-           else:
-               return `obj`
-
-   aRepr = MyRepr()
-   print aRepr.repr(sys.stdin)          # prints '<stdin>'
-

Modified: python/trunk/Doc/tutorial/stdlib2.rst
==============================================================================
--- python/trunk/Doc/tutorial/stdlib2.rst	(original)
+++ python/trunk/Doc/tutorial/stdlib2.rst	Fri May 23 07:03:59 2008
@@ -13,11 +13,11 @@
 Output Formatting
 =================
 
-The :mod:`reprlib` module provides a version of :func:`repr` customized for
+The :mod:`repr` module provides a version of :func:`repr` customized for
 abbreviated displays of large or deeply nested containers::
 
-   >>> import reprlib
-   >>> reprlib.repr(set('supercalifragilisticexpialidocious'))
+   >>> import repr   
+   >>> repr.repr(set('supercalifragilisticexpialidocious'))
    "set(['a', 'c', 'd', 'e', 'f', 'g', ...])"
 
 The :mod:`pprint` module offers more sophisticated control over printing both

Modified: python/trunk/Lib/bdb.py
==============================================================================
--- python/trunk/Lib/bdb.py	(original)
+++ python/trunk/Lib/bdb.py	Fri May 23 07:03:59 2008
@@ -325,7 +325,7 @@
     #
 
     def format_stack_entry(self, frame_lineno, lprefix=': '):
-        import linecache, reprlib
+        import linecache, repr
         frame, lineno = frame_lineno
         filename = self.canonic(frame.f_code.co_filename)
         s = '%s(%r)' % (filename, lineno)
@@ -338,13 +338,13 @@
         else:
             args = None
         if args:
-            s = s + reprlib.repr(args)
+            s = s + repr.repr(args)
         else:
             s = s + '()'
         if '__return__' in frame.f_locals:
             rv = frame.f_locals['__return__']
             s = s + '->'
-            s = s + reprlib.repr(rv)
+            s = s + repr.repr(rv)
         line = linecache.getline(filename, lineno)
         if line: s = s + lprefix + line.strip()
         return s

Modified: python/trunk/Lib/copy.py
==============================================================================
--- python/trunk/Lib/copy.py	(original)
+++ python/trunk/Lib/copy.py	Fri May 23 07:03:59 2008
@@ -399,16 +399,17 @@
     print l2
     l.append({l[1]: l, 'xyz': l[2]})
     l3 = copy(l)
-    import reprlib
-    print map(reprlib.repr, l)
-    print map(reprlib.repr, l1)
-    print map(reprlib.repr, l2)
-    print map(reprlib.repr, l3)
+    import repr
+    print map(repr.repr, l)
+    print map(repr.repr, l1)
+    print map(repr.repr, l2)
+    print map(repr.repr, l3)
     l3 = deepcopy(l)
-    print map(reprlib.repr, l)
-    print map(reprlib.repr, l1)
-    print map(reprlib.repr, l2)
-    print map(reprlib.repr, l3)
+    import repr
+    print map(repr.repr, l)
+    print map(repr.repr, l1)
+    print map(repr.repr, l2)
+    print map(repr.repr, l3)
 
 if __name__ == '__main__':
     _test()

Modified: python/trunk/Lib/idlelib/Debugger.py
==============================================================================
--- python/trunk/Lib/idlelib/Debugger.py	(original)
+++ python/trunk/Lib/idlelib/Debugger.py	Fri May 23 07:03:59 2008
@@ -413,8 +413,8 @@
             height = 20*len(dict) # XXX 20 == observed height of Entry widget
         self.master = master
         self.title = title
-        import reprlib
-        self.repr = reprlib.Repr()
+        import repr
+        self.repr = repr.Repr()
         self.repr.maxstring = 60
         self.repr.maxother = 60
         self.frame = frame = Frame(master)

Modified: python/trunk/Lib/idlelib/ObjectBrowser.py
==============================================================================
--- python/trunk/Lib/idlelib/ObjectBrowser.py	(original)
+++ python/trunk/Lib/idlelib/ObjectBrowser.py	Fri May 23 07:03:59 2008
@@ -11,7 +11,7 @@
 
 from TreeWidget import TreeItem, TreeNode, ScrolledCanvas
 
-from reprlib import Repr
+from repr import Repr
 
 myrepr = Repr()
 myrepr.maxstring = 100

Modified: python/trunk/Lib/pdb.py
==============================================================================
--- python/trunk/Lib/pdb.py	(original)
+++ python/trunk/Lib/pdb.py	Fri May 23 07:03:59 2008
@@ -8,7 +8,7 @@
 import linecache
 import cmd
 import bdb
-from reprlib import Repr
+from repr import Repr
 import os
 import re
 import pprint

Modified: python/trunk/Lib/pydoc.py
==============================================================================
--- python/trunk/Lib/pydoc.py	(original)
+++ python/trunk/Lib/pydoc.py	Fri May 23 07:03:59 2008
@@ -53,7 +53,7 @@
 #     path will be displayed.
 
 import sys, imp, os, re, types, inspect, __builtin__, pkgutil
-from reprlib import Repr
+from repr import Repr
 from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
 try:
     from collections import deque

Deleted: python/trunk/Lib/reprlib.py
==============================================================================
--- python/trunk/Lib/reprlib.py	Fri May 23 07:03:59 2008
+++ (empty file)
@@ -1,132 +0,0 @@
-"""Redo the builtin repr() (representation) but with limits on most sizes."""
-
-__all__ = ["Repr","repr"]
-
-import __builtin__
-from itertools import islice
-
-class Repr:
-
-    def __init__(self):
-        self.maxlevel = 6
-        self.maxtuple = 6
-        self.maxlist = 6
-        self.maxarray = 5
-        self.maxdict = 4
-        self.maxset = 6
-        self.maxfrozenset = 6
-        self.maxdeque = 6
-        self.maxstring = 30
-        self.maxlong = 40
-        self.maxother = 20
-
-    def repr(self, x):
-        return self.repr1(x, self.maxlevel)
-
-    def repr1(self, x, level):
-        typename = type(x).__name__
-        if ' ' in typename:
-            parts = typename.split()
-            typename = '_'.join(parts)
-        if hasattr(self, 'repr_' + typename):
-            return getattr(self, 'repr_' + typename)(x, level)
-        else:
-            s = __builtin__.repr(x)
-            if len(s) > self.maxother:
-                i = max(0, (self.maxother-3)//2)
-                j = max(0, self.maxother-3-i)
-                s = s[:i] + '...' + s[len(s)-j:]
-            return s
-
-    def _repr_iterable(self, x, level, left, right, maxiter, trail=''):
-        n = len(x)
-        if level <= 0 and n:
-            s = '...'
-        else:
-            newlevel = level - 1
-            repr1 = self.repr1
-            pieces = [repr1(elem, newlevel) for elem in islice(x, maxiter)]
-            if n > maxiter:  pieces.append('...')
-            s = ', '.join(pieces)
-            if n == 1 and trail:  right = trail + right
-        return '%s%s%s' % (left, s, right)
-
-    def repr_tuple(self, x, level):
-        return self._repr_iterable(x, level, '(', ')', self.maxtuple, ',')
-
-    def repr_list(self, x, level):
-        return self._repr_iterable(x, level, '[', ']', self.maxlist)
-
-    def repr_array(self, x, level):
-        header = "array('%s', [" % x.typecode
-        return self._repr_iterable(x, level, header, '])', self.maxarray)
-
-    def repr_set(self, x, level):
-        x = _possibly_sorted(x)
-        return self._repr_iterable(x, level, 'set([', '])', self.maxset)
-
-    def repr_frozenset(self, x, level):
-        x = _possibly_sorted(x)
-        return self._repr_iterable(x, level, 'frozenset([', '])',
-                                   self.maxfrozenset)
-
-    def repr_deque(self, x, level):
-        return self._repr_iterable(x, level, 'deque([', '])', self.maxdeque)
-
-    def repr_dict(self, x, level):
-        n = len(x)
-        if n == 0: return '{}'
-        if level <= 0: return '{...}'
-        newlevel = level - 1
-        repr1 = self.repr1
-        pieces = []
-        for key in islice(_possibly_sorted(x), self.maxdict):
-            keyrepr = repr1(key, newlevel)
-            valrepr = repr1(x[key], newlevel)
-            pieces.append('%s: %s' % (keyrepr, valrepr))
-        if n > self.maxdict: pieces.append('...')
-        s = ', '.join(pieces)
-        return '{%s}' % (s,)
-
-    def repr_str(self, x, level):
-        s = __builtin__.repr(x[:self.maxstring])
-        if len(s) > self.maxstring:
-            i = max(0, (self.maxstring-3)//2)
-            j = max(0, self.maxstring-3-i)
-            s = __builtin__.repr(x[:i] + x[len(x)-j:])
-            s = s[:i] + '...' + s[len(s)-j:]
-        return s
-
-    def repr_long(self, x, level):
-        s = __builtin__.repr(x) # XXX Hope this isn't too slow...
-        if len(s) > self.maxlong:
-            i = max(0, (self.maxlong-3)//2)
-            j = max(0, self.maxlong-3-i)
-            s = s[:i] + '...' + s[len(s)-j:]
-        return s
-
-    def repr_instance(self, x, level):
-        try:
-            s = __builtin__.repr(x)
-            # Bugs in x.__repr__() can cause arbitrary
-            # exceptions -- then make up something
-        except Exception:
-            return '<%s instance at %x>' % (x.__class__.__name__, id(x))
-        if len(s) > self.maxstring:
-            i = max(0, (self.maxstring-3)//2)
-            j = max(0, self.maxstring-3-i)
-            s = s[:i] + '...' + s[len(s)-j:]
-        return s
-
-
-def _possibly_sorted(x):
-    # Since not all sequences of items can be sorted and comparison
-    # functions may raise arbitrary exceptions, return an unsorted
-    # sequence in that case.
-    try:
-        return sorted(x)
-    except Exception:
-        return list(x)
-
-aRepr = Repr()
-repr = aRepr.repr

Modified: python/trunk/Lib/test/test___all__.py
==============================================================================
--- python/trunk/Lib/test/test___all__.py	(original)
+++ python/trunk/Lib/test/test___all__.py	Fri May 23 07:03:59 2008
@@ -123,7 +123,7 @@
         self.check_all("quopri")
         self.check_all("random")
         self.check_all("re")
-        self.check_all("reprlib")
+        self.check_all("repr")
         self.check_all("rexec")
         self.check_all("rfc822")
         self.check_all("rlcompleter")

Modified: python/trunk/Lib/test/test_py3kwarn.py
==============================================================================
--- python/trunk/Lib/test/test_py3kwarn.py	(original)
+++ python/trunk/Lib/test/test_py3kwarn.py	Fri May 23 07:03:59 2008
@@ -218,7 +218,7 @@
     renames = {'Queue': 'queue',
                'SocketServer': 'socketserver',
                'ConfigParser': 'configparser',
-               'repr': 'reprlib'}
+              }
 
     def check_rename(self, module_name, new_module_name):
         """Make sure that:

Copied: python/trunk/Lib/test/test_repr.py (from r63542, /python/trunk/Lib/test/test_reprlib.py)
==============================================================================
--- /python/trunk/Lib/test/test_reprlib.py	(original)
+++ python/trunk/Lib/test/test_repr.py	Fri May 23 07:03:59 2008
@@ -9,8 +9,8 @@
 import unittest
 
 from test.test_support import run_unittest
-from reprlib import repr as r # Don't shadow builtin repr
-from reprlib import Repr
+from repr import repr as r # Don't shadow builtin repr
+from repr import Repr
 
 
 def nestedTuple(nesting):

Deleted: python/trunk/Lib/test/test_reprlib.py
==============================================================================
--- python/trunk/Lib/test/test_reprlib.py	Fri May 23 07:03:59 2008
+++ (empty file)
@@ -1,327 +0,0 @@
-"""
-  Test cases for the repr module
-  Nick Mathewson
-"""
-
-import sys
-import os
-import shutil
-import unittest
-
-from test.test_support import run_unittest
-from reprlib import repr as r # Don't shadow builtin repr
-from reprlib import Repr
-
-
-def nestedTuple(nesting):
-    t = ()
-    for i in range(nesting):
-        t = (t,)
-    return t
-
-class ReprTests(unittest.TestCase):
-
-    def test_string(self):
-        eq = self.assertEquals
-        eq(r("abc"), "'abc'")
-        eq(r("abcdefghijklmnop"),"'abcdefghijklmnop'")
-
-        s = "a"*30+"b"*30
-        expected = repr(s)[:13] + "..." + repr(s)[-14:]
-        eq(r(s), expected)
-
-        eq(r("\"'"), repr("\"'"))
-        s = "\""*30+"'"*100
-        expected = repr(s)[:13] + "..." + repr(s)[-14:]
-        eq(r(s), expected)
-
-    def test_tuple(self):
-        eq = self.assertEquals
-        eq(r((1,)), "(1,)")
-
-        t3 = (1, 2, 3)
-        eq(r(t3), "(1, 2, 3)")
-
-        r2 = Repr()
-        r2.maxtuple = 2
-        expected = repr(t3)[:-2] + "...)"
-        eq(r2.repr(t3), expected)
-
-    def test_container(self):
-        from array import array
-        from collections import deque
-
-        eq = self.assertEquals
-        # Tuples give up after 6 elements
-        eq(r(()), "()")
-        eq(r((1,)), "(1,)")
-        eq(r((1, 2, 3)), "(1, 2, 3)")
-        eq(r((1, 2, 3, 4, 5, 6)), "(1, 2, 3, 4, 5, 6)")
-        eq(r((1, 2, 3, 4, 5, 6, 7)), "(1, 2, 3, 4, 5, 6, ...)")
-
-        # Lists give up after 6 as well
-        eq(r([]), "[]")
-        eq(r([1]), "[1]")
-        eq(r([1, 2, 3]), "[1, 2, 3]")
-        eq(r([1, 2, 3, 4, 5, 6]), "[1, 2, 3, 4, 5, 6]")
-        eq(r([1, 2, 3, 4, 5, 6, 7]), "[1, 2, 3, 4, 5, 6, ...]")
-
-        # Sets give up after 6 as well
-        eq(r(set([])), "set([])")
-        eq(r(set([1])), "set([1])")
-        eq(r(set([1, 2, 3])), "set([1, 2, 3])")
-        eq(r(set([1, 2, 3, 4, 5, 6])), "set([1, 2, 3, 4, 5, 6])")
-        eq(r(set([1, 2, 3, 4, 5, 6, 7])), "set([1, 2, 3, 4, 5, 6, ...])")
-
-        # Frozensets give up after 6 as well
-        eq(r(frozenset([])), "frozenset([])")
-        eq(r(frozenset([1])), "frozenset([1])")
-        eq(r(frozenset([1, 2, 3])), "frozenset([1, 2, 3])")
-        eq(r(frozenset([1, 2, 3, 4, 5, 6])), "frozenset([1, 2, 3, 4, 5, 6])")
-        eq(r(frozenset([1, 2, 3, 4, 5, 6, 7])), "frozenset([1, 2, 3, 4, 5, 6, ...])")
-
-        # collections.deque after 6
-        eq(r(deque([1, 2, 3, 4, 5, 6, 7])), "deque([1, 2, 3, 4, 5, 6, ...])")
-
-        # Dictionaries give up after 4.
-        eq(r({}), "{}")
-        d = {'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}
-        eq(r(d), "{'alice': 1, 'bob': 2, 'charles': 3, 'dave': 4}")
-        d['arthur'] = 1
-        eq(r(d), "{'alice': 1, 'arthur': 1, 'bob': 2, 'charles': 3, ...}")
-
-        # array.array after 5.
-        eq(r(array('i')), "array('i', [])")
-        eq(r(array('i', [1])), "array('i', [1])")
-        eq(r(array('i', [1, 2])), "array('i', [1, 2])")
-        eq(r(array('i', [1, 2, 3])), "array('i', [1, 2, 3])")
-        eq(r(array('i', [1, 2, 3, 4])), "array('i', [1, 2, 3, 4])")
-        eq(r(array('i', [1, 2, 3, 4, 5])), "array('i', [1, 2, 3, 4, 5])")
-        eq(r(array('i', [1, 2, 3, 4, 5, 6])),
-                   "array('i', [1, 2, 3, 4, 5, ...])")
-
-    def test_numbers(self):
-        eq = self.assertEquals
-        eq(r(123), repr(123))
-        eq(r(123L), repr(123L))
-        eq(r(1.0/3), repr(1.0/3))
-
-        n = 10L**100
-        expected = repr(n)[:18] + "..." + repr(n)[-19:]
-        eq(r(n), expected)
-
-    def test_instance(self):
-        eq = self.assertEquals
-        i1 = ClassWithRepr("a")
-        eq(r(i1), repr(i1))
-
-        i2 = ClassWithRepr("x"*1000)
-        expected = repr(i2)[:13] + "..." + repr(i2)[-14:]
-        eq(r(i2), expected)
-
-        i3 = ClassWithFailingRepr()
-        eq(r(i3), ("<ClassWithFailingRepr instance at %x>"%id(i3)))
-
-        s = r(ClassWithFailingRepr)
-        self.failUnless(s.startswith("<class "))
-        self.failUnless(s.endswith(">"))
-        self.failUnless(s.find("...") == 8)
-
-    def test_file(self):
-        fp = open(unittest.__file__)
-        self.failUnless(repr(fp).startswith(
-            "<open file '%s', mode 'r' at 0x" % unittest.__file__))
-        fp.close()
-        self.failUnless(repr(fp).startswith(
-            "<closed file '%s', mode 'r' at 0x" % unittest.__file__))
-
-    def test_lambda(self):
-        self.failUnless(repr(lambda x: x).startswith(
-            "<function <lambda"))
-        # XXX anonymous functions?  see func_repr
-
-    def test_builtin_function(self):
-        eq = self.assertEquals
-        # Functions
-        eq(repr(hash), '<built-in function hash>')
-        # Methods
-        self.failUnless(repr(''.split).startswith(
-            '<built-in method split of str object at 0x'))
-
-    def test_xrange(self):
-        eq = self.assertEquals
-        eq(repr(xrange(1)), 'xrange(1)')
-        eq(repr(xrange(1, 2)), 'xrange(1, 2)')
-        eq(repr(xrange(1, 2, 3)), 'xrange(1, 4, 3)')
-
-    def test_nesting(self):
-        eq = self.assertEquals
-        # everything is meant to give up after 6 levels.
-        eq(r([[[[[[[]]]]]]]), "[[[[[[[]]]]]]]")
-        eq(r([[[[[[[[]]]]]]]]), "[[[[[[[...]]]]]]]")
-
-        eq(r(nestedTuple(6)), "(((((((),),),),),),)")
-        eq(r(nestedTuple(7)), "(((((((...),),),),),),)")
-
-        eq(r({ nestedTuple(5) : nestedTuple(5) }),
-           "{((((((),),),),),): ((((((),),),),),)}")
-        eq(r({ nestedTuple(6) : nestedTuple(6) }),
-           "{((((((...),),),),),): ((((((...),),),),),)}")
-
-        eq(r([[[[[[{}]]]]]]), "[[[[[[{}]]]]]]")
-        eq(r([[[[[[[{}]]]]]]]), "[[[[[[[...]]]]]]]")
-
-    def test_buffer(self):
-        # XXX doesn't test buffers with no b_base or read-write buffers (see
-        # bufferobject.c).  The test is fairly incomplete too.  Sigh.
-        x = buffer('foo')
-        self.failUnless(repr(x).startswith('<read-only buffer for 0x'))
-
-    def test_cell(self):
-        # XXX Hmm? How to get at a cell object?
-        pass
-
-    def test_descriptors(self):
-        eq = self.assertEquals
-        # method descriptors
-        eq(repr(dict.items), "<method 'items' of 'dict' objects>")
-        # XXX member descriptors
-        # XXX attribute descriptors
-        # XXX slot descriptors
-        # static and class methods
-        class C:
-            def foo(cls): pass
-        x = staticmethod(C.foo)
-        self.failUnless(repr(x).startswith('<staticmethod object at 0x'))
-        x = classmethod(C.foo)
-        self.failUnless(repr(x).startswith('<classmethod object at 0x'))
-
-    def test_unsortable(self):
-        # Repr.repr() used to call sorted() on sets, frozensets and dicts
-        # without taking into account that not all objects are comparable
-        x = set([1j, 2j, 3j])
-        y = frozenset(x)
-        z = {1j: 1, 2j: 2}
-        r(x)
-        r(y)
-        r(z)
-
-def touch(path, text=''):
-    fp = open(path, 'w')
-    fp.write(text)
-    fp.close()
-
-class LongReprTest(unittest.TestCase):
-    def setUp(self):
-        longname = 'areallylongpackageandmodulenametotestreprtruncation'
-        self.pkgname = os.path.join(longname)
-        self.subpkgname = os.path.join(longname, longname)
-        # Make the package and subpackage
-        shutil.rmtree(self.pkgname, ignore_errors=True)
-        os.mkdir(self.pkgname)
-        touch(os.path.join(self.pkgname, '__init__'+os.extsep+'py'))
-        shutil.rmtree(self.subpkgname, ignore_errors=True)
-        os.mkdir(self.subpkgname)
-        touch(os.path.join(self.subpkgname, '__init__'+os.extsep+'py'))
-        # Remember where we are
-        self.here = os.getcwd()
-        sys.path.insert(0, self.here)
-
-    def tearDown(self):
-        actions = []
-        for dirpath, dirnames, filenames in os.walk(self.pkgname):
-            for name in dirnames + filenames:
-                actions.append(os.path.join(dirpath, name))
-        actions.append(self.pkgname)
-        actions.sort()
-        actions.reverse()
-        for p in actions:
-            if os.path.isdir(p):
-                os.rmdir(p)
-            else:
-                os.remove(p)
-        del sys.path[0]
-
-    def test_module(self):
-        eq = self.assertEquals
-        touch(os.path.join(self.subpkgname, self.pkgname + os.extsep + 'py'))
-        from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation
-        eq(repr(areallylongpackageandmodulenametotestreprtruncation),
-           "<module '%s' from '%s'>" % (areallylongpackageandmodulenametotestreprtruncation.__name__, areallylongpackageandmodulenametotestreprtruncation.__file__))
-        eq(repr(sys), "<module 'sys' (built-in)>")
-
-    def test_type(self):
-        eq = self.assertEquals
-        touch(os.path.join(self.subpkgname, 'foo'+os.extsep+'py'), '''\
-class foo(object):
-    pass
-''')
-        from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo
-        eq(repr(foo.foo),
-               "<class '%s.foo'>" % foo.__name__)
-
-    def test_object(self):
-        # XXX Test the repr of a type with a really long tp_name but with no
-        # tp_repr.  WIBNI we had ::Inline? :)
-        pass
-
-    def test_class(self):
-        touch(os.path.join(self.subpkgname, 'bar'+os.extsep+'py'), '''\
-class bar:
-    pass
-''')
-        from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import bar
-        # Module name may be prefixed with "test.", depending on how run.
-        self.failUnless(repr(bar.bar).startswith(
-            "<class %s.bar at 0x" % bar.__name__))
-
-    def test_instance(self):
-        touch(os.path.join(self.subpkgname, 'baz'+os.extsep+'py'), '''\
-class baz:
-    pass
-''')
-        from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import baz
-        ibaz = baz.baz()
-        self.failUnless(repr(ibaz).startswith(
-            "<%s.baz instance at 0x" % baz.__name__))
-
-    def test_method(self):
-        eq = self.assertEquals
-        touch(os.path.join(self.subpkgname, 'qux'+os.extsep+'py'), '''\
-class aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
-    def amethod(self): pass
-''')
-        from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import qux
-        # Unbound methods first
-        eq(repr(qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod),
-        '<unbound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod>')
-        # Bound method next
-        iqux = qux.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
-        self.failUnless(repr(iqux.amethod).startswith(
-            '<bound method aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.amethod of <%s.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa instance at 0x' \
-            % (qux.__name__,) ))
-
-    def test_builtin_function(self):
-        # XXX test built-in functions and methods with really long names
-        pass
-
-class ClassWithRepr:
-    def __init__(self, s):
-        self.s = s
-    def __repr__(self):
-        return "ClassWithLongRepr(%r)" % self.s
-
-
-class ClassWithFailingRepr:
-    def __repr__(self):
-        raise Exception("This should be caught by Repr.repr_instance")
-
-
-def test_main():
-    run_unittest(ReprTests)
-    if os.name != 'mac':
-        run_unittest(LongReprTest)
-
-
-if __name__ == "__main__":
-    test_main()

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri May 23 07:03:59 2008
@@ -76,9 +76,6 @@
   ctypes.util.find_library(name) now call this function when name is
   'm' or 'c'.
 
-- The repr module has been renamed 'reprlib'.  The old name is now
-  deprecated.
-
 - The statvfs module has been deprecated for removal in Python 3.0.
 
 - The sunaudiodev and SUNAUDIODEV modules have been deprecated for


More information about the Python-checkins mailing list