|
@ -15,7 +15,11 @@ |
|
|
* GNU General Public License for more details. |
|
|
* GNU General Public License for more details. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
import simplejson |
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
import simplejson |
|
|
|
|
|
except ImportError: |
|
|
|
|
|
import json as simplejson |
|
|
|
|
|
|
|
|
import httplib |
|
|
import httplib |
|
|
from threading import Lock |
|
|
from threading import Lock |
|
|
from urlparse import urljoin, urlparse |
|
|
from urlparse import urljoin, urlparse |
|
@ -100,12 +104,15 @@ class Client(object): |
|
|
self.cookie = cookie |
|
|
self.cookie = cookie |
|
|
|
|
|
|
|
|
purl = urlparse( self.apiurl ) |
|
|
purl = urlparse( self.apiurl ) |
|
|
conn = httplib.HTTPConnection( purl.netloc ) |
|
|
|
|
|
|
|
|
conn = { |
|
|
|
|
|
"http": httplib.HTTPConnection, |
|
|
|
|
|
"https": httplib.HTTPSConnection |
|
|
|
|
|
}[purl.scheme.lower()]( purl.netloc ) |
|
|
conn.putrequest( "GET", purl.path ) |
|
|
conn.putrequest( "GET", purl.path ) |
|
|
conn.endheaders() |
|
|
conn.endheaders() |
|
|
resp = conn.getresponse() |
|
|
resp = conn.getresponse() |
|
|
conn.close() |
|
|
|
|
|
foundvars = lexjs( resp.read() ) |
|
|
foundvars = lexjs( resp.read() ) |
|
|
|
|
|
conn.close() |
|
|
|
|
|
|
|
|
self.api = foundvars[apiname] |
|
|
self.api = foundvars[apiname] |
|
|
self.routerurl = urljoin( self.apiurl, self.api["url"] ) |
|
|
self.routerurl = urljoin( self.apiurl, self.api["url"] ) |
|
@ -137,16 +144,18 @@ class Client(object): |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
purl = urlparse( self.routerurl ) |
|
|
purl = urlparse( self.routerurl ) |
|
|
conn = httplib.HTTPConnection( purl.netloc ) |
|
|
|
|
|
|
|
|
conn = { |
|
|
|
|
|
"http": httplib.HTTPConnection, |
|
|
|
|
|
"https": httplib.HTTPSConnection |
|
|
|
|
|
}[purl.scheme.lower()]( purl.netloc ) |
|
|
conn.putrequest( "POST", purl.path ) |
|
|
conn.putrequest( "POST", purl.path ) |
|
|
conn.putheader( "Content-Type", "application/json" ) |
|
|
conn.putheader( "Content-Type", "application/json" ) |
|
|
conn.putheader( "Content-Length", len(data) ) |
|
|
|
|
|
|
|
|
conn.putheader( "Content-Length", str(len(data)) ) |
|
|
if self.cookie: |
|
|
if self.cookie: |
|
|
conn.putheader( "Cookie", self.cookie ) |
|
|
conn.putheader( "Cookie", self.cookie ) |
|
|
conn.endheaders() |
|
|
conn.endheaders() |
|
|
conn.send( data ) |
|
|
conn.send( data ) |
|
|
resp = conn.getresponse() |
|
|
resp = conn.getresponse() |
|
|
conn.close() |
|
|
|
|
|
|
|
|
|
|
|
if resp.status != 200: |
|
|
if resp.status != 200: |
|
|
raise RequestError( resp.status, resp.reason ) |
|
|
raise RequestError( resp.status, resp.reason ) |
|
@ -161,6 +170,7 @@ class Client(object): |
|
|
if cookie: |
|
|
if cookie: |
|
|
self.cookie = cookie.split(';')[0] |
|
|
self.cookie = cookie.split(';')[0] |
|
|
|
|
|
|
|
|
|
|
|
conn.close() |
|
|
return respdata['result'] |
|
|
return respdata['result'] |
|
|
|
|
|
|
|
|
def get_object( self, action ): |
|
|
def get_object( self, action ): |
|
|