Browse Source

incorporate djextdirect updates

Natenom/support-murmur-13-1446181288462
Michael Ziegler 14 years ago
parent
commit
10d0a1b81f
  1. 22
      pyweb/djextdirect/client.py
  2. 4
      pyweb/djextdirect/provider.py

22
pyweb/djextdirect/client.py

@ -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 ):

4
pyweb/djextdirect/provider.py

@ -105,7 +105,7 @@ class Provider( object ):
if flags is None: if flags is None:
flags = {} flags = {}
self.classes[ clsname ][ method.__name__ ] = method self.classes[ clsname ][ method.__name__ ] = method
method.EXT_argnames = inspect.getargspec( method ).args[1:]
method.EXT_argnames = inspect.getargspec( method )[0][1:]
method.EXT_len = len( method.EXT_argnames ) method.EXT_len = len( method.EXT_argnames )
method.EXT_flags = flags method.EXT_flags = flags
return method return method
@ -158,7 +158,7 @@ class Provider( object ):
except (MultiValueDictKeyError, KeyError), err: except (MultiValueDictKeyError, KeyError), err:
try: try:
rawjson = simplejson.loads( request.raw_post_data ) rawjson = simplejson.loads( request.raw_post_data )
except simplejson.JSONDecodeError:
except getattr( simplejson, "JSONDecodeError", ValueError ):
return HttpResponse( simplejson.dumps({ return HttpResponse( simplejson.dumps({
'type': 'exception', 'type': 'exception',
'message': 'malformed request', 'message': 'malformed request',

Loading…
Cancel
Save