[Python-checkins] CVS: python/nondist/sandbox/help htmldoc.py,1.2,1.3 textdoc.py,1.1,1.2

Ka-Ping Yee python-dev@python.org
Sun, 14 Jan 2001 03:49:54 -0800


Update of /cvsroot/python/python/nondist/sandbox/help
In directory usw-pr-cvs1:/tmp/cvs-serv19284

Modified Files:
	htmldoc.py textdoc.py 
Log Message:
Show constants in documentation pages.


Index: htmldoc.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/help/htmldoc.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** htmldoc.py	2001/01/14 11:40:38	1.2
--- htmldoc.py	2001/01/14 11:49:50	1.3
***************
*** 162,165 ****
--- 162,171 ----
      return results
  
+ def isconstant(object):
+     """Check if an object is of a type that probably means it's a constant."""
+     return type(object) in [
+         types.FloatType, types.IntType, types.ListType, types.LongType,
+         types.StringType, types.TupleType, types.TypeType, types.UnicodeType]
+ 
  def document_module(object):
      """Produce HTML documentation for a given module object."""
***************
*** 179,190 ****
      modules = map(cadr, inspect.getmembers(object, inspect.ismodule))
  
-     constants = []
-     for key, value in inspect.getmembers(object):
-         if key[:1] != '_' and type(value) in [types.FloatType,
-             types.IntType, types.ListType, types.LongType,
-             types.StringType, types.TupleType, types.TypeType,
-             types.UnicodeType]:
-             constants.append((key, value))
- 
      classes, cdict = [], {}
      for key, value in inspect.getmembers(object, inspect.isclass):
--- 185,188 ----
***************
*** 198,201 ****
--- 196,203 ----
              fdict[key] = '#-' + key
              if inspect.isfunction(value): fdict[value] = fdict[key]
+     constants = []
+     for key, value in inspect.getmembers(object, isconstant):
+         if key[:1] != '_':
+             constants.append((key, value))
  
      for c in classes:

Index: textdoc.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/help/textdoc.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** textdoc.py	2001/01/14 02:27:10	1.1
--- textdoc.py	2001/01/14 11:49:50	1.2
***************
*** 3,7 ****
  __version__ = 'Ka-Ping Yee <ping@lfw.org>, 10 Jan 2001'
  
! import sys, inspect
  from string import join, split, strip, rstrip
  
--- 3,7 ----
  __version__ = 'Ka-Ping Yee <ping@lfw.org>, 10 Jan 2001'
  
! import sys, types, inspect
  from string import join, split, strip, rstrip
  
***************
*** 64,67 ****
--- 64,73 ----
      return results
  
+ def isconstant(object):
+     """Check if an object is of a type that probably means it's a constant."""
+     return type(object) in [
+         types.FloatType, types.IntType, types.ListType, types.LongType,
+         types.StringType, types.TupleType, types.TypeType, types.UnicodeType]
+ 
  def document_module(object):
      """Produce text documentation for a given module object."""
***************
*** 71,78 ****
      lines = split(strip(getdoc(object)), '\n')
      if len(lines) == 1:
!         name = name + ' - ' + lines[0]
          lines = []
      elif len(lines) >= 2 and not rstrip(lines[1]):
!         name = name + ' - ' + lines[0]
          lines = lines[2:]
      results.append(section('NAME', name))
--- 77,84 ----
      lines = split(strip(getdoc(object)), '\n')
      if len(lines) == 1:
!         if lines[0]: name = name + ' - ' + lines[0]
          lines = []
      elif len(lines) >= 2 and not rstrip(lines[1]):
!         if lines[0]: name = name + ' - ' + lines[0]
          lines = lines[2:]
      results.append(section('NAME', name))
***************
*** 91,94 ****
--- 97,104 ----
          if inspect.isbuiltin(value) or inspect.getmodule(value) is object:
              functions.append(value)
+     constants = []
+     for key, value in inspect.getmembers(object, isconstant):
+         if key[:1] != '_':
+             constants.append((key, value))
  
      if classes:
***************
*** 105,108 ****
--- 115,128 ----
              contents.append([document_function(item), '\n'])
          results.append(section('FUNCTIONS', contents))
+ 
+     if constants:
+         contents = []
+         for key, value in constants:
+             line = key + ' = ' + repr(value)
+             chop = 70 - len(line)
+             line = bold(key) + ' = ' + repr(value)
+             if chop < 0: line = line[:chop] + '...'
+             contents.append(line + '\n')
+         results.append(section('CONSTANTS', contents))
  
      if hasattr(object, '__version__'):