summaryrefslogtreecommitdiff
path: root/examples/console/web/index.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-07 07:47:55 +0000
committerianb <devnull@localhost>2005-05-07 07:47:55 +0000
commit76fcfe11f5268dffd0b3f2aae256e3f8e83a8ed3 (patch)
tree6eb84757d4fd4c4f363a304231ba65dc86d214a7 /examples/console/web/index.py
parent672a4dd88a1764a9d1a4342d06e2dec35c9b8c10 (diff)
downloadpaste-76fcfe11f5268dffd0b3f2aae256e3f8e83a8ed3.tar.gz
Moved evaluation into its own module
Diffstat (limited to 'examples/console/web/index.py')
-rw-r--r--examples/console/web/index.py57
1 files changed, 6 insertions, 51 deletions
diff --git a/examples/console/web/index.py b/examples/console/web/index.py
index d181857..aec3498 100644
--- a/examples/console/web/index.py
+++ b/examples/console/web/index.py
@@ -1,34 +1,8 @@
-from cStringIO import StringIO
-import traceback
-import pdb
-import threading
-import sys
from console.sitepage import SitePage
from console.JSONComponent import JSONComponent
+from console.evalcontext import EvalContext
-global_namespace = {}
-namespace_lock = threading.Lock()
-
-# From doctest
-class _OutputRedirectingPdb(pdb.Pdb):
- """
- A specialized version of the python debugger that redirects stdout
- to a given stream when interacting with the user. Stdout is *not*
- redirected when traced code is executed.
- """
- def __init__(self, out):
- self.__out = out
- pdb.Pdb.__init__(self)
-
- def trace_dispatch(self, *args):
- # Redirect stdout to the given stream.
- save_stdout = sys.stdout
- sys.stdout = self.__out
- # Call Pdb's trace dispatch method.
- try:
- return pdb.Pdb.trace_dispatch(self, *args)
- finally:
- sys.stdout = save_stdout
+context = EvalContext()
class index(SitePage):
@@ -41,26 +15,7 @@ class index(SitePage):
def jsonMethods(self):
return ['run']
- def run(self, value):
- out = StringIO()
- namespace_lock.acquire()
- save_stdout = sys.stdout
- try:
- debugger = _OutputRedirectingPdb(save_stdout)
- debugger.reset()
- pdb.set_trace = debugger.set_trace
- sys.stdout = out
- try:
- code = compile(value, '<web>', "single", 0, 1)
- exec code in global_namespace
- debugger.set_continue()
- except KeyboardInterrupt:
- raise
- except:
- traceback.print_exc(file=out)
- debugger.set_continue()
- finally:
- sys.stdout = save_stdout
- namespace_lock.release()
- value = out.getvalue()
- return value
+ def run(self, expr):
+ if not expr.endswith('\n'):
+ expr += '\n'
+ return context.exec_expr(expr)