]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/interpreter.py
48e9056464e0a044dc97f11f7ca77ad55d5d881d
1 """PyCrust Interpreter executes Python commands."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __date__
= "July 1, 2001"
6 __version__
= "$Revision$"[11:-2]
10 from code
import InteractiveInterpreter
14 class Interpreter(InteractiveInterpreter
):
15 """PyCrust Interpreter based on code.InteractiveInterpreter."""
17 revision
= __version__
19 def __init__(self
, locals=None, rawin
=None, \
20 stdin
=sys
.stdin
, stdout
=sys
.stdout
, stderr
=sys
.stderr
):
21 """Create an interactive interpreter object."""
22 InteractiveInterpreter
.__init
__(self
, locals=locals)
28 __builtin__
.raw_input = rawin
30 copyright
= 'Type "copyright", "credits" or "license" for more information.'
31 self
.introText
= 'Python %s on %s%s%s' % \
32 (sys
.version
, sys
.platform
, os
.linesep
, copyright
)
35 except AttributeError:
39 except AttributeError:
42 self
.commandBuffer
= [] # List of lists to support recursive push().
43 self
.commandHistory
= []
44 self
.startupScript
= os
.environ
.get('PYTHONSTARTUP')
46 def push(self
, command
):
47 """Send command to the interpreter to be executed.
49 Because this may be called recursively, we append a new list
50 onto the commandBuffer list and then append commands into that.
51 If the passed in command is part of a multi-line command we keep
52 appending the pieces to the last list in commandBuffer until we
53 have a complete command, then, finally, we delete that last list.
55 if not self
.more
: self
.commandBuffer
.append([])
56 self
.commandBuffer
[-1].append(command
)
57 source
= '\n'.join(self
.commandBuffer
[-1])
58 self
.more
= self
.runsource(source
)
59 if not self
.more
: del self
.commandBuffer
[-1]
62 def runsource(self
, source
):
63 """Compile and run source code in the interpreter."""
64 stdin
, stdout
, stderr
= sys
.stdin
, sys
.stdout
, sys
.stderr
65 sys
.stdin
= self
.stdin
66 sys
.stdout
= self
.stdout
67 sys
.stderr
= self
.stderr
68 more
= InteractiveInterpreter
.runsource(self
, source
)
69 sys
.stdin
, sys
.stdout
, sys
.stderr
= stdin
, stdout
, stderr
72 def getAutoCompleteList(self
, command
='', *args
, **kwds
):
73 """Return list of auto-completion options for a command.
75 The list of options will be based on the locals namespace."""
76 return introspect
.getAutoCompleteList(command
, self
.locals, *args
, **kwds
)
78 def getCallTip(self
, command
='', *args
, **kwds
):
79 """Return call tip text for a command.
81 The call tip information will be based on the locals namespace."""
82 return introspect
.getCallTip(command
, self
.locals, *args
, **kwds
)
85 class InterpreterAlaCarte(Interpreter
):
86 """PyCrustAlaCarte Demo Interpreter."""
88 def __init__(self
, locals, rawin
, stdin
, stdout
, stderr
, \
89 ps1
='main prompt', ps2
='continuation prompt'):
90 """Create an interactive interpreter object."""
91 Interpreter
.__init
__(self
, locals=locals, rawin
=rawin
, \
92 stdin
=stdin
, stdout
=stdout
, stderr
=stderr
)