]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/PyCrustInterp.py
dd606c2138223eb947aa55334d0636d87d5d1824
   2 __author__ 
= "Patrick K. O'Brien <pobrien@orbtech.com>" 
   4 __date__ 
= "July 1, 2001" 
   5 __version__ 
= "$Revision$"[11:-2] 
  10 from code 
import InteractiveInterpreter
 
  14 class Interpreter(InteractiveInterpreter
): 
  15     """PyCrust Interpreter based on code.InteractiveInterpreter.""" 
  16     revision 
= __version__
 
  17     def __init__(self
, locals=None, rawin
=None, 
  18                  stdin
=sys
.stdin
, stdout
=sys
.stdout
, stderr
=sys
.stderr
): 
  19         """Create an interactive interpreter object.""" 
  20         InteractiveInterpreter
.__init
__(self
, locals=locals) 
  26             __builtin__
.raw_input = rawin
 
  28         copyright 
= 'Type "copyright", "credits" or "license" for more information.' 
  29         self
.introText 
= 'Python %s on %s\n%s' % \
 
  30                          (sys
.version
, sys
.platform
, copyright
) 
  33         except AttributeError: 
  37         except AttributeError: 
  40         self
.commandBuffer 
= []  # List of lists to support recursive push(). 
  41         self
.commandHistory 
= [] 
  42         self
.startupScript 
= os
.environ
.get('PYTHONSTARTUP') 
  44     def push(self
, command
): 
  45         """Send command to the interpreter to be executed. 
  47         Because this may be called recursively, we append a new list  
  48         onto the commandBuffer list and then append commands into that. 
  49         If the passed in command is part of a multi-line command we keep 
  50         appending the pieces to the last list in commandBuffer until we 
  51         have a complete command, then, finally, we delete that last list. 
  53         if not self
.more
: self
.commandBuffer
.append([]) 
  54         self
.commandBuffer
[-1].append(command
) 
  55         source 
= '\n'.join(self
.commandBuffer
[-1]) 
  56         self
.more 
= self
.runsource(source
) 
  57         if not self
.more
: del self
.commandBuffer
[-1] 
  60     def runsource(self
, source
): 
  61         """Compile and run source code in the interpreter.""" 
  62         stdin
, stdout
, stderr 
= sys
.stdin
, sys
.stdout
, sys
.stderr
 
  63         sys
.stdin 
= self
.stdin
 
  64         sys
.stdout 
= self
.stdout
 
  65         sys
.stderr 
= self
.stderr
 
  66         more 
= InteractiveInterpreter
.runsource(self
, source
) 
  67         sys
.stdin
, sys
.stdout
, sys
.stderr 
= stdin
, stdout
, stderr
 
  70     def getAutoCompleteList(self
, command
=''): 
  71         """Return list of auto-completion options for a command. 
  73         The list of options will be based on the locals namespace.""" 
  74         return introspect
.getAutoCompleteList(command
, self
.locals) 
  76     def getCallTip(self
, command
=''): 
  77         """Return call tip text for a command. 
  79         The call tip information will be based on the locals namespace.""" 
  80         return introspect
.getCallTip(command
, self
.locals)