To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit f45c9940 authored by Tobias Pape's avatar Tobias Pape Committed by Stefan Marr
Browse files

rpythonize the shell

for that, provide own raw_input.
also: crtl-d works now.
parent de1f0fd7
from rpython.rlib.objectmodel import we_are_translated
class Shell(object): class Shell(object):
def __init__(self, universe, interpreter): def __init__(self, universe, interpreter):
...@@ -9,10 +11,10 @@ class Shell(object): ...@@ -9,10 +11,10 @@ class Shell(object):
self._bootstrap_method = method self._bootstrap_method = method
def start(self): def start(self):
from som.vm.universe import std_println, error_println, raw_input
counter = 0 counter = 0
it = self._universe.nilObject it = self._universe.nilObject
from som.vm.universe import std_println
std_println("SOM Shell. Type \"quit\" to exit.\n"); std_println("SOM Shell. Type \"quit\" to exit.\n");
# Create a fake bootstrap frame # Create a fake bootstrap frame
...@@ -25,7 +27,7 @@ class Shell(object): ...@@ -25,7 +27,7 @@ class Shell(object):
try: try:
# Read a statement from the keyboard # Read a statement from the keyboard
stmt = raw_input("---> ") stmt = raw_input("---> ")
if stmt == "quit": if stmt == "quit" or stmt == "":
return return
# Generate a temporary class with a run method # Generate a temporary class with a run method
...@@ -65,8 +67,9 @@ class Shell(object): ...@@ -65,8 +67,9 @@ class Shell(object):
# Save the result of the run method # Save the result of the run method
it = current_frame.pop() it = current_frame.pop()
except Exception, e: except Exception, e:
import traceback if not we_are_translated(): # this cannot be done in rpython
traceback.print_exc() import traceback
self._universe.error_println("Caught exception: " + str(e)) traceback.print_exc()
self._universe.error_println(str( error_println("Caught exception: %s" % e)
error_println(str(
self._interpreter.get_frame().get_previous_frame())) self._interpreter.get_frame().get_previous_frame()))
...@@ -588,6 +588,22 @@ def std_print(msg): ...@@ -588,6 +588,22 @@ def std_print(msg):
def std_println(msg=""): def std_println(msg=""):
print msg print msg
def _read_raw(answer):
buf = os.read(1, 32)
if len(buf) == 0:
return (answer, False)
elif buf[-1] == "\n":
return (answer + buf[:-1], False)
else:
return (answer + buf, True)
def raw_input(msg=""):
os.write(1, msg)
answer, cont = _read_raw("")
while cont:
answer, cont = _read_raw(answer)
return answer
def main(args): def main(args):
u = Universe() u = Universe()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment