[Python-checkins] CVS: python/dist/src/Lib cmd.py,1.23.4.1,1.23.4.2 imputil.py,1.19,1.19.4.1 pstats.py,1.15.4.1,1.15.4.2

Tim Peters tim_one@users.sourceforge.net
Sun, 29 Jul 2001 21:08:16 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv9082/descr/dist/src/Lib

Modified Files:
      Tag: descr-branch
	cmd.py imputil.py pstats.py 
Log Message:
Merge of trunk tag delta date2001-07-28 to date2001-07-30.


Index: cmd.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/cmd.py,v
retrieving revision 1.23.4.1
retrieving revision 1.23.4.2
diff -C2 -d -r1.23.4.1 -r1.23.4.2
*** cmd.py	2001/07/21 06:07:12	1.23.4.1
--- cmd.py	2001/07/30 04:08:14	1.23.4.2
***************
*** 16,23 ****
--- 16,33 ----
  6. The command '?' is a synonym for `help'.  The command '!' is a synonym
     for `shell', if a do_shell method exists.
+ 7. If completion is enabled, completing commands will be done automatically,
+    and completing of commands args is done by calling complete_foo() with
+    arguments text, line, begidx, endidx.  text is string we are matching
+    against, all returned matches must begin with it.  line is the current
+    input line (lstripped), begidx and endidx are the beginning and end
+    indexes of the text being matched, which could be used to provide 
+    different completion depending upon which position the argument is in.
  
  The `default' method may be overridden to intercept commands for which there
  is no do_ method.
  
+ The `completedefault' method may be overridden to intercept completions for
+ commands that have no complete_ method. 
+ 
  The data member `self.ruler' sets the character used to draw separator lines
  in the help messages.  If empty, no ruler line is drawn.  It defaults to "=".
***************
*** 57,61 ****
      use_rawinput = 1
  
!     def __init__(self): pass
  
      def cmdloop(self, intro=None):
--- 67,78 ----
      use_rawinput = 1
  
!     def __init__(self, completekey='tab'): 
!         if completekey:
!             try:
!                 import readline
!                 readline.set_completer(self.complete)
!                 readline.parse_and_bind(completekey+": complete")
!             except ImportError:
!                 pass
  
      def cmdloop(self, intro=None):
***************
*** 100,107 ****
          pass
  
!     def onecmd(self, line):
          line = line.strip()
          if not line:
!             return self.emptyline()
          elif line[0] == '?':
              line = 'help ' + line[1:]
--- 117,124 ----
          pass
  
!     def parseline(self, line):
          line = line.strip()
          if not line:
!             return None, None, line
          elif line[0] == '?':
              line = 'help ' + line[1:]
***************
*** 110,118 ****
                  line = 'shell ' + line[1:]
              else:
!                 return self.default(line)
!         self.lastcmd = line
          i, n = 0, len(line)
          while i < n and line[i] in self.identchars: i = i+1
          cmd, arg = line[:i], line[i:].strip()
          if cmd == '':
              return self.default(line)
--- 127,143 ----
                  line = 'shell ' + line[1:]
              else:
!                 return None, None, line
          i, n = 0, len(line)
          while i < n and line[i] in self.identchars: i = i+1
          cmd, arg = line[:i], line[i:].strip()
+         return cmd, arg, line
+     
+     def onecmd(self, line):
+         cmd, arg, line = self.parseline(line)
+         if not line:
+             return self.emptyline()
+         if cmd is None:
+             return self.default(line)
+         self.lastcmd = line
          if cmd == '':
              return self.default(line)
***************
*** 131,134 ****
--- 156,212 ----
          print '*** Unknown syntax:', line
  
+     def completedefault(self, *ignored):
+         return []
+ 
+     def completenames(self, text, *ignored):
+         dotext = 'do_'+text
+         return [a[3:] for a in self.get_names() if a.startswith(dotext)]
+ 
+     def complete(self, text, state):
+         """Return the next possible completion for 'text'.
+ 
+         If a command has not been entered, then complete against command list.
+         Otherwise try to call complete_<command> to get list of completions.
+         """
+         if state == 0:
+             import readline
+             origline = readline.get_line_buffer()
+             line = origline.lstrip()
+             stripped = len(origline) - len(line)
+             begidx = readline.get_begidx() - stripped
+             endidx = readline.get_endidx() - stripped
+             if begidx>0:
+                 cmd, args, foo = self.parseline(line)
+                 if cmd == '':
+                     compfunc = self.completedefault
+                 else:
+                     try:
+                         compfunc = getattr(self, 'complete_' + cmd)
+                     except AttributeError:
+                         compfunc = self.completedefault
+             else:
+                 compfunc = self.completenames
+             self.completion_matches = compfunc(text, line, begidx, endidx)
+         try:
+             return self.completion_matches[state]
+         except IndexError:
+             return None
+     
+     def get_names(self):
+         # Inheritance says we have to look in class and
+         # base classes; order is not important.
+         names = []
+         classes = [self.__class__]
+         while classes:
+             aclass = classes[0]
+             if aclass.__bases__:
+                 classes = classes + list(aclass.__bases__)
+             names = names + dir(aclass)
+             del classes[0]
+         return names
+ 
+     def complete_help(self, *args):
+         return self.completenames(*args)
+ 
      def do_help(self, arg):
          if arg:
***************
*** 148,161 ****
              func()
          else:
!             # Inheritance says we have to look in class and
!             # base classes; order is not important.
!             names = []
!             classes = [self.__class__]
!             while classes:
!                 aclass = classes[0]
!                 if aclass.__bases__:
!                     classes = classes + list(aclass.__bases__)
!                 names = names + dir(aclass)
!                 del classes[0]
              cmds_doc = []
              cmds_undoc = []
--- 226,230 ----
              func()
          else:
!             names = self.get_names()
              cmds_doc = []
              cmds_undoc = []

Index: imputil.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/imputil.py,v
retrieving revision 1.19
retrieving revision 1.19.4.1
diff -C2 -d -r1.19 -r1.19.4.1
*** imputil.py	2001/04/07 16:05:24	1.19
--- imputil.py	2001/07/30 04:08:14	1.19.4.1
***************
*** 8,12 ****
  import imp                      ### not available in JPython?
  import sys
- import strop
  import __builtin__
  
--- 8,11 ----
***************
*** 79,83 ****
          """Python calls this hook to locate and import a module."""
  
!         parts = strop.split(fqname, '.')
  
          # determine the context of this import
--- 78,82 ----
          """Python calls this hook to locate and import a module."""
  
!         parts = fqname.split('.')
  
          # determine the context of this import
***************
*** 127,130 ****
--- 126,133 ----
              return importer._finish_import(top_module, parts[1:], fromlist)
  
+         # Grrr, some people "import os.path"
+         if len(parts) == 2 and hasattr(top_module, parts[1]):
+             return top_module
+ 
          # If the importer does not exist, then we have to bail. A missing
          # importer means that something else imported the module, and we have
***************
*** 158,162 ****
              return parent
  
!         i = strop.rfind(parent_fqname, '.')
  
          # a module outside of a package has no particular import context
--- 161,165 ----
              return parent
  
!         i = parent_fqname.rfind('.')
  
          # a module outside of a package has no particular import context
***************
*** 292,296 ****
  
          # fetch from sys.modules instead of returning module directly.
!         return sys.modules[fqname]
  
      def _load_tail(self, m, parts):
--- 295,303 ----
  
          # fetch from sys.modules instead of returning module directly.
!         # also make module's __name__ agree with fqname, in case
!         # the "exec code in module.__dict__" played games on us.
!         module = sys.modules[fqname]
!         module.__name__ = fqname
!         return module
  
      def _load_tail(self, m, parts):
***************
*** 613,617 ****
  #
  # from Finn Bock:
- #   remove use of "strop" -- not available in JPython
  #   type(sys) is not a module in JPython. what to use instead?
  #   imp.C_EXTENSION is not in JPython. same for get_suffixes and new_module
--- 620,623 ----
***************
*** 639,643 ****
  #   performance
  #   move chaining to a subclass [gjs: it's been nuked]
- #   avoid strop
  #   deinstall should be possible
  #   query mechanism needed: is a specific Importer installed?
--- 645,648 ----

Index: pstats.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pstats.py,v
retrieving revision 1.15.4.1
retrieving revision 1.15.4.2
diff -C2 -d -r1.15.4.1 -r1.15.4.2
*** pstats.py	2001/07/07 22:55:28	1.15.4.1
--- pstats.py	2001/07/30 04:08:14	1.15.4.2
***************
*** 539,542 ****
--- 539,543 ----
      class ProfileBrowser(cmd.Cmd):
          def __init__(self, profile=None):
+             cmd.Cmd.__init__(self)
              self.prompt = "% "
              if profile: