我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用pydoc.describe()。
def _writedoc(doc, thing, forceload=0): """Write HTML documentation to a file in the current directory. """ try: obj, name = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name)) fname = os.path.join(doc, name + '.html') fd = open(fname, 'w') fd.write(page) fd.close() except (ImportError, pydoc.ErrorDuringImport): traceback.print_exc(sys.stderr) else: return name + '.html'
def _writeclientdoc(doc, thing, forceload=0): """Write HTML documentation to a file in the current directory. """ docmodule = pydoc.HTMLDoc.docmodule def strongarm(self, obj, name=None, mod=None, *ignored): result = docmodule(self, obj, name, mod, *ignored) # Grab all the aliases to pyclasses and create links. nonmembers = [] push = nonmembers.append for k,v in inspect.getmembers(obj, inspect.isclass): if inspect.getmodule(v) is not obj and getattr(v,'typecode',None) is not None: push('<a href="%s.html">%s</a>: pyclass alias<br/>' %(v.__name__,k)) result += self.bigsection('Aliases', '#ffffff', '#eeaa77', ''.join(nonmembers)) return result pydoc.HTMLDoc.docmodule = strongarm try: obj, name = pydoc.resolve(thing, forceload) page = pydoc.html.page(pydoc.describe(obj), pydoc.html.document(obj, name)) name = os.path.join(doc, name + '.html') fd = open(name, 'w') fd.write(page) fd.close() except (ImportError, pydoc.ErrorDuringImport), value: log.debug(str(value)) pydoc.HTMLDoc.docmodule = docmodule
def _writebrokedoc(doc, ex, name, forceload=0): try: fname = os.path.join(doc, name + '.html') page = pydoc.html.page(pydoc.describe(ex), pydoc.html.document(str(ex), fname)) fd = open(fname, 'w') fd.write(page) fd.close() except (ImportError, pydoc.ErrorDuringImport), value: log.debug(str(value)) return name + '.html'
def test_class(self): class C: "New-style class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s object' % __name__ self.assertIn(expected, pydoc.render_doc(c))
def test_classic_class(self): class C: "Classic class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'instance of C') expected = 'instance of C in module %s' % __name__ self.assertIn(expected, pydoc.render_doc(c))
def test_class(self): class C(object): "New-style class" c = C() self.assertEqual(pydoc.describe(C), 'class C') self.assertEqual(pydoc.describe(c), 'C') expected = 'C in module %s object' % __name__ self.assertIn(expected, pydoc.render_doc(c))
def process( self ): """Having added all of the base and/or interesting modules, proceed to generate the appropriate documentation for each module in the appropriate directory, doing the recursion as we go.""" try: while self.pending: try: if self.completed.has_key( self.pending[0] ): raise AlreadyDone( self.pending[0] ) self.info( """Start %s"""% (repr(self.pending[0]))) object = pydoc.locate ( self.pending[0] ) self.info( """ ... found %s"""% (repr(object.__name__))) except AlreadyDone: pass except pydoc.ErrorDuringImport, value: self.info( """ ... FAILED %s"""% (repr( value))) self.warn( """Unable to import the module %s"""% (repr(self.pending[0]))) except (SystemError, SystemExit), value: self.info( """ ... FAILED %s"""% (repr( value))) self.warn( """Unable to import the module %s"""% (repr(self.pending[0]))) except Exception, value: self.info( """ ... FAILED %s"""% (repr( value))) self.warn( """Unable to import the module %s"""% (repr(self.pending[0]))) else: page = self.formatter.page( pydoc.describe(object), self.formatter.docmodule( object, object.__name__, packageContext = self, ) ) file = open ( os.path.join( self.destinationDirectory, self.pending[0] + ".html", ), 'w', ) file.write(page) file.close() self.completed[ self.pending[0]] = object del self.pending[0] finally: for item in self.warnings: print item