From 10d0a1b81f340dd2ac703aa9dde261ef0882b6bf Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Tue, 5 Oct 2010 21:45:30 +0200 Subject: [PATCH] incorporate djextdirect updates --- pyweb/djextdirect/client.py | 22 ++++++++++++++++------ pyweb/djextdirect/provider.py | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/pyweb/djextdirect/client.py b/pyweb/djextdirect/client.py index f83bc79..d845885 100644 --- a/pyweb/djextdirect/client.py +++ b/pyweb/djextdirect/client.py @@ -15,7 +15,11 @@ * GNU General Public License for more details. """ -import simplejson +try: + import simplejson +except ImportError: + import json as simplejson + import httplib from threading import Lock from urlparse import urljoin, urlparse @@ -100,12 +104,15 @@ class Client(object): self.cookie = cookie 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.endheaders() resp = conn.getresponse() - conn.close() foundvars = lexjs( resp.read() ) + conn.close() self.api = foundvars[apiname] self.routerurl = urljoin( self.apiurl, self.api["url"] ) @@ -137,16 +144,18 @@ class Client(object): }) 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.putheader( "Content-Type", "application/json" ) - conn.putheader( "Content-Length", len(data) ) + conn.putheader( "Content-Length", str(len(data)) ) if self.cookie: conn.putheader( "Cookie", self.cookie ) conn.endheaders() conn.send( data ) resp = conn.getresponse() - conn.close() if resp.status != 200: raise RequestError( resp.status, resp.reason ) @@ -161,6 +170,7 @@ class Client(object): if cookie: self.cookie = cookie.split(';')[0] + conn.close() return respdata['result'] def get_object( self, action ): diff --git a/pyweb/djextdirect/provider.py b/pyweb/djextdirect/provider.py index 31bda55..f30b5e1 100644 --- a/pyweb/djextdirect/provider.py +++ b/pyweb/djextdirect/provider.py @@ -105,7 +105,7 @@ class Provider( object ): if flags is None: flags = {} 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_flags = flags return method @@ -158,7 +158,7 @@ class Provider( object ): except (MultiValueDictKeyError, KeyError), err: try: rawjson = simplejson.loads( request.raw_post_data ) - except simplejson.JSONDecodeError: + except getattr( simplejson, "JSONDecodeError", ValueError ): return HttpResponse( simplejson.dumps({ 'type': 'exception', 'message': 'malformed request',