diff options
author | ankitjavalkar | 2016-09-21 15:07:43 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-09-30 10:33:42 +0530 |
commit | ac8d6720bc75676e05462cc38ad144d5aedc14e7 (patch) | |
tree | e2e527e159a0704ecdaa2f15ae13900f4555ea63 /yaksh/xmlrpc_clients.py | |
parent | 6b08e56fe3cf70ffbcbd1ed432dde25babe48148 (diff) | |
download | online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.gz online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.tar.bz2 online_test-ac8d6720bc75676e05462cc38ad144d5aedc14e7.zip |
Migrate python code server and evaluators to python 2/3 compatible
Diffstat (limited to 'yaksh/xmlrpc_clients.py')
-rw-r--r-- | yaksh/xmlrpc_clients.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/yaksh/xmlrpc_clients.py b/yaksh/xmlrpc_clients.py index 6bfe0d6..83ba277 100644 --- a/yaksh/xmlrpc_clients.py +++ b/yaksh/xmlrpc_clients.py @@ -1,11 +1,19 @@ -from xmlrpclib import ServerProxy +from __future__ import absolute_import import time import random import socket import json import urllib +from six.moves import urllib -from settings import SERVER_PORTS, SERVER_POOL_PORT +try: + from xmlrpclib import ServerProxy +except ImportError: + # The above import will not work on Python-3.x. + from xmlrpc.client import ServerProxy + +# Local imports +from .settings import SERVER_PORTS, SERVER_POOL_PORT class ConnectionError(Exception): @@ -58,7 +66,8 @@ class CodeServerProxy(object): return result def _get_server(self): - port = json.loads(urllib.urlopen(self.pool_url).read()) + response = urllib.request.urlopen(self.pool_url) + port = json.loads(response.read().decode('utf-8')) proxy = ServerProxy('http://localhost:%d' % port) return proxy |