Пример #1
0
class Shell:

  def __init__(self):
    self.builtins = Builtins(self)
    self.completion = Completion(self)
    self.history = History()
    self.javascript = Javascript()
    self.log = Log()
    self.prompt = Prompt()

  def execute(self, command):
    self.log.append(str(self.prompt) + command)
    self.history.append(command)

    if command:
      # execute builtins command
      try:
        self.builtins.execute(command.strip())
      except self.builtins.UnknownCommandError as e:
        self.log.append('websh: command not found: {0}'.format(e.command))
      except Exception as e:
        print 'Error in builtins: {0}'.format(e)

    return json.dumps({'javascript': str(self.javascript),
                       'log': str(self.log),
                       'prompt': str(self.prompt)})

  def template(self):
    # read template file
    file = open('data/template.html', 'r')
    template = string.Template(file.read())
    file.close()

    return template.substitute(log = str(self.log),
                               prompt = str(self.prompt))
Пример #2
0
 def __init__(self):
   self.builtins = Builtins(self)
   self.completion = Completion(self)
   self.history = History()
   self.javascript = Javascript()
   self.log = Log()
   self.prompt = Prompt()
Пример #3
0
# Python (2.7) port of Lithp
# Because C++ is too hard.

#

from lithptypes import *
from builtins import Builtins
from interpreter import Interpreter
from lithpparser import BootstrapParser
import time

if __name__ == "__main__":
    interp = Interpreter()
    t0 = time.time()
    builtins = Builtins()
    chain = OpChain()
    builtins.fillClosure(chain.closure)
    t1 = time.time()
    print "Standard library loaded in ", t1 - t0
    test_1 = 1 << 0
    test_2 = 1 << 1
    test_3 = 1 << 2
    test_4 = 1 << 3
    test_5 = 1 << 4
    tests = 0
    #tests |= test_1
    #tests |= test_2
    #tests |= test_3
    #tests |= test_4
    tests |= test_5