|
|
@ -5,7 +5,6 @@ import sys |
|
|
|
import os |
|
|
|
import json |
|
|
|
from httplib import HTTPConnection |
|
|
|
from urllib import urlencode |
|
|
|
|
|
|
|
|
|
|
|
if sys.platform == 'darwin': |
|
|
@ -30,22 +29,25 @@ class Connection: |
|
|
|
|
|
|
|
def __enter__(self): |
|
|
|
self.http_connection = HTTPConnection(str(self.config[u'address']), int(self.config[u'port'])) |
|
|
|
return self |
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback): |
|
|
|
self.http_connection.close() |
|
|
|
|
|
|
|
def __call__(self, method, *params): |
|
|
|
func = {'method': method} |
|
|
|
func['params': params] |
|
|
|
func['params'] = params |
|
|
|
func['id'] = self.next_id |
|
|
|
self.next_id += 1 |
|
|
|
func['jsonrpc'] = '2.0' |
|
|
|
func['security_token'] = str(self.config[u'security_token']) |
|
|
|
params = urlencode(func) |
|
|
|
params = json.dumps(func) |
|
|
|
headers = {"Connection": "Keep-Alive"} |
|
|
|
self.http_connection.request("POST", str(self.config[u'path']), params, headers) |
|
|
|
response = conn.getresponse() |
|
|
|
self.http_connection.request("POST", str(self.config[u'path']) + "callFunction", params, headers) |
|
|
|
response = self.http_connection.getresponse() |
|
|
|
data = None |
|
|
|
if int(response.status) < 400: |
|
|
|
if response.status < 400: |
|
|
|
data = response.read() |
|
|
|
return data |
|
|
|
else: |
|
|
|
print response.status |
|
|
|
return json.loads(data)['result'] |