@@ -1461,31 +1461,35 @@ def resolve(thing, forceload=0):
1461
1461
else :
1462
1462
return thing , getattr (thing , '__name__' , None )
1463
1463
1464
+ def render_doc (thing , title = 'Python Library Documentation: %s' , forceload = 0 ):
1465
+ """Render text documentation, given an object or a path to an object."""
1466
+ object , name = resolve (thing , forceload )
1467
+ desc = describe (object )
1468
+ module = inspect .getmodule (object )
1469
+ if name and '.' in name :
1470
+ desc += ' in ' + name [:name .rfind ('.' )]
1471
+ elif module and module is not object :
1472
+ desc += ' in module ' + module .__name__
1473
+ if type (object ) is _OLD_INSTANCE_TYPE :
1474
+ # If the passed object is an instance of an old-style class,
1475
+ # document its available methods instead of its value.
1476
+ object = object .__class__
1477
+ elif not (inspect .ismodule (object ) or
1478
+ inspect .isclass (object ) or
1479
+ inspect .isroutine (object ) or
1480
+ inspect .isgetsetdescriptor (object ) or
1481
+ inspect .ismemberdescriptor (object ) or
1482
+ isinstance (object , property )):
1483
+ # If the passed object is a piece of data or an instance,
1484
+ # document its available methods instead of its value.
1485
+ object = type (object )
1486
+ desc += ' object'
1487
+ return title % desc + '\n \n ' + text .document (object , name )
1488
+
1464
1489
def doc (thing , title = 'Python Library Documentation: %s' , forceload = 0 ):
1465
1490
"""Display text documentation, given an object or a path to an object."""
1466
1491
try :
1467
- object , name = resolve (thing , forceload )
1468
- desc = describe (object )
1469
- module = inspect .getmodule (object )
1470
- if name and '.' in name :
1471
- desc += ' in ' + name [:name .rfind ('.' )]
1472
- elif module and module is not object :
1473
- desc += ' in module ' + module .__name__
1474
- if type (object ) is _OLD_INSTANCE_TYPE :
1475
- # If the passed object is an instance of an old-style class,
1476
- # document its available methods instead of its value.
1477
- object = object .__class__
1478
- elif not (inspect .ismodule (object ) or
1479
- inspect .isclass (object ) or
1480
- inspect .isroutine (object ) or
1481
- inspect .isgetsetdescriptor (object ) or
1482
- inspect .ismemberdescriptor (object ) or
1483
- isinstance (object , property )):
1484
- # If the passed object is a piece of data or an instance,
1485
- # document its available methods instead of its value.
1486
- object = type (object )
1487
- desc += ' object'
1488
- pager (title % desc + '\n \n ' + text .document (object , name ))
1492
+ pager (render_doc (thing , title , forceload ))
1489
1493
except (ImportError , ErrorDuringImport ), value :
1490
1494
print value
1491
1495
0 commit comments