diff options
| author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-08-02 00:24:26 (GMT) |
|---|---|---|
| committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-08-02 00:24:26 (GMT) |
| commit | 8dc04a4dd1fc0e8c5feaba7308eaf8b8c8df8373 (patch) | |
| tree | 8a4de788c6c22e4d185f43b199735b44607fdf88 /Lib/pprint.py | |
| parent | 8c7fe2d6f98908a597fec05767dc8a032c06dc61 (diff) | |
| download | cpython-8dc04a4dd1fc0e8c5feaba7308eaf8b8c8df8373.zip cpython-8dc04a4dd1fc0e8c5feaba7308eaf8b8c8df8373.tar.gz cpython-8dc04a4dd1fc0e8c5feaba7308eaf8b8c8df8373.tar.bz2 | |
Merged revisions 77310-77311 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77310 | antoine.pitrou | 2010-01-05 01:22:44 +0200 (Tue, 05 Jan 2010) | 4 lines
Issue #7092: Fix the DeprecationWarnings emitted by the standard library
when using the -3 flag. Patch by Florent Xicluna.
........
r77311 | antoine.pitrou | 2010-01-05 01:28:16 +0200 (Tue, 05 Jan 2010) | 3 lines
Kill a couple of "<>"
........
Diffstat (limited to 'Lib/pprint.py')
| -rw-r--r-- | Lib/pprint.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/pprint.py b/Lib/pprint.py index c48465b..910283e 100644 --- a/Lib/pprint.py +++ b/Lib/pprint.py @@ -35,6 +35,7 @@ saferepr() """ import sys as _sys +import warnings from cStringIO import StringIO as _StringIO @@ -70,6 +71,13 @@ def isrecursive(object): """Determine if object requires a recursive representation.""" return _safe_repr(object, {}, None, 0)[2] +def _sorted(iterable): + with warnings.catch_warnings(): + if _sys.py3kwarning: + warnings.filterwarnings("ignore", "comparing unequal types " + "not supported", DeprecationWarning) + return sorted(iterable) + class PrettyPrinter: def __init__(self, indent=1, width=80, depth=None, stream=None): """Handle pretty printing operations onto a stream using a set of @@ -144,8 +152,7 @@ class PrettyPrinter: if length: context[objid] = 1 indent = indent + self._indent_per_level - items = object.items() - items.sort() + items = _sorted(object.items()) key, ent = items[0] rep = self._repr(key, context, level) write(rep) @@ -181,7 +188,7 @@ class PrettyPrinter: return write('set([') endchar = '])' - object = sorted(object) + object = _sorted(object) indent += 4 elif issubclass(typ, frozenset): if not length: @@ -189,7 +196,7 @@ class PrettyPrinter: return write('frozenset([') endchar = '])' - object = sorted(object) + object = _sorted(object) indent += 10 else: write('(') @@ -274,7 +281,7 @@ def _safe_repr(object, context, maxlevels, level): append = components.append level += 1 saferepr = _safe_repr - for k, v in sorted(object.items()): + for k, v in _sorted(object.items()): krepr, kreadable, krecur = saferepr(k, context, maxlevels, level) vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level) append("%s: %s" % (krepr, vrepr)) |
