Commits

Shu Zong Chen  committed e8209cd

REPL behavior created

  • Participants
  • Parent commits 5b6ef51

Comments (0)

Files changed (4)

+#!/usr/bin/env python
+
+import simpledb
+
+import sys
+
+def main():
+	sdb = simpledb.SDB()
+	while True:
+		line = sys.stdin.readline()
+		if len(line):
+			try:
+				sdb.interpret(line.strip())
+			except simpledb.exceptions.StopProgram:
+				break
+		else:
+			break
+
+if __name__ == "__main__":
+	main()
+

File simpledb/__init__.py

+from engine import DBEngine
+
+class SDB(object):
+	def __init__(self):
+		self.db = DBEngine()
+	
+	def interpret(self, line):
+		parts = line.split(" ")
+		cmd = parts[0].upper()
+		args = parts[1:]
+		if hasattr(self.db, 'DO_' + cmd):
+			f = getattr(self.db, 'DO_' + cmd)
+			try:
+				f(*args)
+			except TypeError:
+				print "INCORRECT NUM OF ARGS FOR CMD: {0}".format(cmd)

File simpledb/engine.py

+from collections import Counter
+from exceptions import StopProgram
+
+class DBEngine(object):
+	def __init__(self):
+		self.d = {}
+		self.c = Counter()
+
+	def DO_SET(self, name, value):
+		pass
+
+	def DO_GET(self, name):
+		pass
+
+	def DO_UNSET(self, name):
+		pass
+
+	def DO_NUMEQUALTO(self, name):
+		pass
+
+	def DO_END(self, name):
+		raise StopProgram

File simpledb/exceptions.py

+class StopProgram(Exception):
+	pass
+