Pretty print the given object.
(self, obj)
| 354 | self.deferred_pprinters = deferred_pprinters |
| 355 | |
| 356 | def pretty(self, obj): |
| 357 | """Pretty print the given object.""" |
| 358 | obj_id = id(obj) |
| 359 | cycle = obj_id in self.stack |
| 360 | self.stack.append(obj_id) |
| 361 | self.begin_group() |
| 362 | try: |
| 363 | obj_class = _safe_getattr(obj, '__class__', None) or type(obj) |
| 364 | # First try to find registered singleton printers for the type. |
| 365 | try: |
| 366 | printer = self.singleton_pprinters[obj_id] |
| 367 | except (TypeError, KeyError): |
| 368 | pass |
| 369 | else: |
| 370 | return printer(obj, self, cycle) |
| 371 | # Next walk the mro and check for either: |
| 372 | # 1) a registered printer |
| 373 | # 2) a _repr_pretty_ method |
| 374 | for cls in _get_mro(obj_class): |
| 375 | if cls in self.type_pprinters: |
| 376 | # printer registered in self.type_pprinters |
| 377 | return self.type_pprinters[cls](obj, self, cycle) |
| 378 | else: |
| 379 | # deferred printer |
| 380 | printer = self._in_deferred_types(cls) |
| 381 | if printer is not None: |
| 382 | return printer(obj, self, cycle) |
| 383 | else: |
| 384 | # Finally look for special method names. |
| 385 | # Some objects automatically create any requested |
| 386 | # attribute. Try to ignore most of them by checking for |
| 387 | # callability. |
| 388 | if '_repr_pretty_' in cls.__dict__: |
| 389 | meth = cls._repr_pretty_ |
| 390 | if callable(meth): |
| 391 | return meth(obj, self, cycle) |
| 392 | if cls is not object \ |
| 393 | and callable(cls.__dict__.get('__repr__')): |
| 394 | return _repr_pprint(obj, self, cycle) |
| 395 | |
| 396 | return _default_pprint(obj, self, cycle) |
| 397 | finally: |
| 398 | self.end_group() |
| 399 | self.stack.pop() |
| 400 | |
| 401 | def _in_deferred_types(self, cls): |
| 402 | """ |