Browse Source

Switch raw_input to input when needed.

Bentley James Oakes 6 years ago
parent
commit
1b68fd2e8a
5 changed files with 55 additions and 15 deletions
  1. 28 6
      scripts/debug_prompt.py
  2. 6 2
      services/HUTN/main.py
  3. 7 2
      services/JSON/main.py
  4. 6 2
      services/files/main.py
  5. 8 3
      wrappers/test_service.py

+ 28 - 6
scripts/debug_prompt.py

@@ -1,11 +1,20 @@
-import urllib
-import urllib2
+
+
 import threading
 import subprocess
 import os
 import sys
 import json
 
+if sys.version_info[0] < 3:
+    from urllib2 import urlopen as urlopen
+    from urllib2 import Request as Request
+    from urllib import urlencode as urlencode
+else:
+    from urllib.request import urlopen as urlopen
+    from urllib.request import Request as Request
+    from urllib.parse import urlencode as urlencode
+
 def local_print(string):
     if os.name == "posix":
         # Nicer colour output when using posix (and thus supporting colour)
@@ -21,13 +30,21 @@ def remote_print(string):
 local_print("Welcome to the debugging shell!")
 local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
 
-location = raw_input()
+if sys.version_info[0] < 3:
+    location = raw_input()
+else:
+    location = input()
+
 if location == "":
     address = "http://127.0.0.1:8001/"
     
 local_print("Please specify task name (default: test)")
 
-taskname = raw_input()
+if sys.version_info[0] < 3:
+    taskname = raw_input()
+else:
+    taskname = input()
+
 if location == "":
     taskname = "test"
 
@@ -36,10 +53,15 @@ local_print("Available commands: 'pause', 'resume'")
 local_print("To quit: execute command 'quit'")
 
 while 1:
-    inp = raw_input().split(" ")
+    if sys.version_info[0] < 3:
+        inp = raw_input().split(" ")
+    else:
+        inp = input().split(" ")
+
     action = inp[0]
     if action == "quit":
         local_print("Received quit: breaking connection to Modelverse immediately!")
         break
 
-    print json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "taskname": taskname}))).read())
+    data = urlencode({"op": action, "taskname": taskname})
+    print(json.loads(urlopen(Request(address, data)).read()))

+ 6 - 2
services/HUTN/main.py

@@ -77,8 +77,12 @@ def compile_service(port):
 service_register("compiler", compile_service)
 
 try:
-    while raw_input() != "STOP":
-        pass
+    if sys.version_info[0] < 3:
+        while raw_input() != "STOP":
+            pass
+    else:
+        while input() != "STOP":
+            pass
 except EOFError:
     import time
     while 1:

+ 7 - 2
services/JSON/main.py

@@ -77,8 +77,13 @@ def json_service(port):
 service_register("JSON", json_service)
 
 try:
-    while raw_input() != "STOP":
-        pass
+    if sys.version_info[0] < 3:
+        while raw_input() != "STOP":
+            pass
+    else:
+        while input() != "STOP":
+            pass
+
 except EOFError:
     import time
     while 1:

+ 6 - 2
services/files/main.py

@@ -24,8 +24,12 @@ def file_service(port):
 service_register("files", file_service)
 
 try:
-    while raw_input() != "STOP":
-        pass
+    if sys.version_info[0] < 3:
+        while raw_input() != "STOP":
+            pass
+    else:
+        while input() != "STOP":
+            pass
 except EOFError:
     import time
     while 1:

+ 8 - 3
wrappers/test_service.py

@@ -1,4 +1,5 @@
 from modelverse import *
+import sys
 
 init()
 login("test_service", "my_password")
@@ -14,8 +15,12 @@ def fibonacci_service(port):
     
 service_register("fibonacci", fibonacci_service)
 
-while raw_input() != "STOP":
-    # Stay active, as we shouldn't exit while the service is running!
-    pass
+# Stay active, as we shouldn't exit while the service is running!
+if sys.version_info[0] < 3:
+    while raw_input() != "STOP":
+        pass
+else:
+    while input() != "STOP":
+        pass
 
 service_stop()