瀏覽代碼

first commit

Eran Goldman-Malka 5 年之前
父節點
當前提交
998807c960
共有 2 個文件被更改,包括 49 次插入0 次删除
  1. 49 0
      p.py
  2. 二進制
      websocketd

+ 49 - 0
p.py

@@ -0,0 +1,49 @@
+#!/usr/bin/python
+from sys import stdout, stdin, exit
+import sys
+import traceback
+
+import os
+
+lockFile = "/var/lock/socketLock"
+c = ""
+
+exists = os.path.isfile(lockFile)
+if exists:
+    stdout.write("socket is already connected.")
+    stdout.flush()
+    exit()
+else:
+    with open(lockFile, 'a'):
+        os.utime(lockFile, None)
+    # Store configuration file values
+
+while True:
+    s = stdin.readline().replace('\n','')  #  raw_input()
+    if s == 'exit':
+        os.remove(lockFile)
+        exit()
+    if s == 'go':
+        description='source string'
+        try:
+            exec(c)
+            stdout.flush()
+            c = ""
+        except SyntaxError as err:
+            error_class = err.__class__.__name__
+            detail = err.args[0]
+            line_number = err.lineno
+            stdout.write(("%s at line %d of %s: %s\n\n" % (error_class, line_number, description, detail)))
+            stdout.flush()
+            c = ""
+        except Exception as err:
+            error_class = err.__class__.__name__
+            detail = err.args[0]
+            cl, exc, tb = sys.exc_info()
+            line_number = traceback.extract_tb(tb)[-1][1]
+            stdout.write(("%s at line %d of %s: %s\n\n" % (error_class, line_number, description, detail)))
+            stdout.flush()
+            c = ""
+    else:
+        s.replace('print','stdout.write')
+        c += s + '\n'

二進制
websocketd