Permalink
Browse files

backdoor.login(): override to provide a login prompt

backdoor.print_result(): override to print the result specially (e.g., pprint)
  • Loading branch information...
1 parent 808e5ce commit 1e86b121ec210a2df4a99b63cd8acb5440126cb2 @samrushing samrushing committed Jun 30, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 coro/backdoor.py
View
@@ -108,9 +108,13 @@ def send_welcome_message(self):
lines.append('')
self.send (self.line_separator.join (lines))
+ def login (self):
+ "override to provide authentication"
+ pass
+
def read_eval_print_loop (self):
+ self.login()
self.send_welcome_message()
-
if self.global_dict is None:
# this does the equivalent of 'from __main__ import *'
env = sys.modules['__main__'].__dict__.copy()
@@ -134,7 +138,11 @@ def read_eval_print_loop (self):
else:
self.parse(line, env)
- def parse(self, line, env):
+ def print_result (self, result):
+ "override to process the result (e.g., pprint)"
+ print result
+
+ def parse (self, line, env):
save = sys.stdout, sys.stderr
output = cStringIO.StringIO()
try:
@@ -143,7 +151,7 @@ def parse(self, line, env):
co = compile (line, repr(self), 'eval')
result = eval (co, env)
if result is not None:
- print repr(result)
+ self.print_result (result)
env['_'] = result
except SyntaxError:
try:

0 comments on commit 1e86b12

Please sign in to comment.