diff options
| -rw-r--r-- | common/PubnubBase.py | 38 | ||||
| -rw-r--r-- | common/PubnubCore.py | 6 | ||||
| -rw-r--r-- | python-tornado/Pubnub.py | 50 | ||||
| -rw-r--r-- | python-tornado/unassembled/Platform.py | 6 | ||||
| -rw-r--r-- | python-twisted/Pubnub.py | 50 | ||||
| -rw-r--r-- | python-twisted/unassembled/Platform.py | 6 | ||||
| -rw-r--r-- | python/Pubnub.py | 59 | ||||
| -rw-r--r-- | python/examples/here-now-example.py | 4 | ||||
| -rwxr-xr-x | python/examples/publish-example.py | 31 | ||||
| -rw-r--r-- | python/unassembled/Platform.py | 15 |
10 files changed, 204 insertions, 61 deletions
diff --git a/common/PubnubBase.py b/common/PubnubBase.py index 5856921..43eee2a 100644 --- a/common/PubnubBase.py +++ b/common/PubnubBase.py @@ -15,7 +15,8 @@ class PubnubBase(object): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - UUID = None + UUID = None, + auth_key = None ) : """ #** @@ -43,6 +44,7 @@ class PubnubBase(object): self.cipher_key = cipher_key self.ssl = ssl_on self.pc = PubnubCrypto() + self.auth_key = auth_key if self.ssl : self.origin = 'https://' + self.origin @@ -82,6 +84,13 @@ class PubnubBase(object): return message + def _return_wrapped_callback(self, callback=None): + def _new_format_callback(response): + if 'payload' in response: + if (callback != None): callback({'message' : response['message'], 'payload' : response['payload']}) + else: + if (callback != None):callback(response) + if (callback != None): return _new_format_callback def publish( self, args ) : """ @@ -131,7 +140,7 @@ class PubnubBase(object): channel, '0', message - ]}, callback) + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)) def presence( self, args ) : """ @@ -171,7 +180,7 @@ class PubnubBase(object): callback = args['callback'] subscribe_key = args.get('subscribe_key') or self.subscribe_key - return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': callback}) + return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': self._return_wrapped_callback(callback)}) def here_now( self, args ) : @@ -211,7 +220,7 @@ class PubnubBase(object): 'v2','presence', 'sub_key', self.subscribe_key, 'channel', channel - ]}, callback); + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)); def history( self, args ) : @@ -255,7 +264,7 @@ class PubnubBase(object): channel, '0', str(limit) - ] }, callback); + ], 'urlparams' : {'auth' : self.auth_key} }, self._return_wrapped_callback(callback)); def detailedHistory(self, args) : """ @@ -286,6 +295,7 @@ class PubnubBase(object): count = int(args['count']) params['count'] = str(count) + params['auth'] = self.auth_key if args.has_key('reverse'): params['reverse'] = str(args['reverse']).lower() @@ -315,7 +325,7 @@ class PubnubBase(object): self.subscribe_key, 'channel', channel, - ],'urlparams' : params }, callback=callback); + ],'urlparams' : params }, callback=self._return_wrapped_callback(callback)); def time(self, args = None) : """ @@ -345,20 +355,30 @@ class PubnubBase(object): return time[0] + def _encode( self, request ) : - return [ + return "".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) - ]) for bit in request] + ]) for bit in request]) + def _add_param(self, key, value): + if value: + return key + "=" + self._encode(value) + else: + return "" + def getUrl(self,request): ## Build URL + args_string = None url = self.origin + '/' + "/".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) ]) for bit in request["urlcomponents"]]) if (request.has_key("urlparams")): - url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].iteritems()]) + args_string = "&".join([ self._add_param(x,y) for x,y in request["urlparams"].iteritems()]) + if (args_string != None and len(args_string) > 0): + url = url + '?' + args_string return url diff --git a/common/PubnubCore.py b/common/PubnubCore.py index dcfd319..d7af462 100644 --- a/common/PubnubCore.py +++ b/common/PubnubCore.py @@ -7,7 +7,8 @@ class PubnubCore(PubnubBase): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - uuid = None + uuid = None, + auth_key = None ) : """ #** @@ -34,7 +35,8 @@ class PubnubCore(PubnubBase): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, - UUID=uuid + UUID=uuid, + auth_key=auth_key ) self.subscriptions = {} diff --git a/python-tornado/Pubnub.py b/python-tornado/Pubnub.py index 89c0d97..12ad1f0 100644 --- a/python-tornado/Pubnub.py +++ b/python-tornado/Pubnub.py @@ -110,7 +110,8 @@ class PubnubBase(object): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - UUID = None + UUID = None, + auth_key = None ) : """ #** @@ -138,6 +139,7 @@ class PubnubBase(object): self.cipher_key = cipher_key self.ssl = ssl_on self.pc = PubnubCrypto() + self.auth_key = auth_key if self.ssl : self.origin = 'https://' + self.origin @@ -177,6 +179,13 @@ class PubnubBase(object): return message + def _return_wrapped_callback(self, callback=None): + def _new_format_callback(response): + if 'payload' in response: + if (callback != None): callback({'message' : response['message'], 'payload' : response['payload']}) + else: + if (callback != None):callback(response) + if (callback != None): return _new_format_callback def publish( self, args ) : """ @@ -226,7 +235,7 @@ class PubnubBase(object): channel, '0', message - ]}, callback) + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)) def presence( self, args ) : """ @@ -266,7 +275,7 @@ class PubnubBase(object): callback = args['callback'] subscribe_key = args.get('subscribe_key') or self.subscribe_key - return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': callback}) + return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': self._return_wrapped_callback(callback)}) def here_now( self, args ) : @@ -306,7 +315,7 @@ class PubnubBase(object): 'v2','presence', 'sub_key', self.subscribe_key, 'channel', channel - ]}, callback); + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)); def history( self, args ) : @@ -350,7 +359,7 @@ class PubnubBase(object): channel, '0', str(limit) - ] }, callback); + ], 'urlparams' : {'auth' : self.auth_key} }, self._return_wrapped_callback(callback)); def detailedHistory(self, args) : """ @@ -381,6 +390,7 @@ class PubnubBase(object): count = int(args['count']) params['count'] = str(count) + params['auth'] = self.auth_key if args.has_key('reverse'): params['reverse'] = str(args['reverse']).lower() @@ -410,7 +420,7 @@ class PubnubBase(object): self.subscribe_key, 'channel', channel, - ],'urlparams' : params }, callback=callback); + ],'urlparams' : params }, callback=self._return_wrapped_callback(callback)); def time(self, args = None) : """ @@ -440,22 +450,32 @@ class PubnubBase(object): return time[0] + def _encode( self, request ) : - return [ + return "".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) - ]) for bit in request] + ]) for bit in request]) + def _add_param(self, key, value): + if value: + return key + "=" + self._encode(value) + else: + return "" + def getUrl(self,request): ## Build URL + args_string = None url = self.origin + '/' + "/".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) ]) for bit in request["urlcomponents"]]) if (request.has_key("urlparams")): - url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].iteritems()]) + args_string = "&".join([ self._add_param(x,y) for x,y in request["urlparams"].iteritems()]) + if (args_string != None and len(args_string) > 0): + url = url + '?' + args_string return url @@ -482,7 +502,8 @@ class PubnubCoreAsync(PubnubBase): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - uuid = None + uuid = None, + auth_key = None ) : """ #** @@ -508,7 +529,8 @@ class PubnubCoreAsync(PubnubBase): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, - UUID=uuid + UUID=uuid, + auth_key = auth_key ) self.subscriptions = {} @@ -670,7 +692,9 @@ class Pubnub(PubnubCoreAsync): secret_key = False, cipher_key = False, ssl_on = False, - origin = 'pubsub.pubnub.com' + origin = 'pubsub.pubnub.com', + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key=publish_key, @@ -679,6 +703,8 @@ class Pubnub(PubnubCoreAsync): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, + uuid = pres_uuid, + auth_key = auth_key ) self.headers = {} self.headers['User-Agent'] = 'Python-Tornado' diff --git a/python-tornado/unassembled/Platform.py b/python-tornado/unassembled/Platform.py index 62d3a26..3dec1e4 100644 --- a/python-tornado/unassembled/Platform.py +++ b/python-tornado/unassembled/Platform.py @@ -27,7 +27,9 @@ class Pubnub(PubnubCoreAsync): secret_key = False, cipher_key = False, ssl_on = False, - origin = 'pubsub.pubnub.com' + origin = 'pubsub.pubnub.com', + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key=publish_key, @@ -36,6 +38,8 @@ class Pubnub(PubnubCoreAsync): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, + uuid = pres_uuid, + auth_key = auth_key ) self.headers = {} self.headers['User-Agent'] = 'Python-Tornado' diff --git a/python-twisted/Pubnub.py b/python-twisted/Pubnub.py index 66534b5..a244039 100644 --- a/python-twisted/Pubnub.py +++ b/python-twisted/Pubnub.py @@ -110,7 +110,8 @@ class PubnubBase(object): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - UUID = None + UUID = None, + auth_key = None ) : """ #** @@ -138,6 +139,7 @@ class PubnubBase(object): self.cipher_key = cipher_key self.ssl = ssl_on self.pc = PubnubCrypto() + self.auth_key = auth_key if self.ssl : self.origin = 'https://' + self.origin @@ -177,6 +179,13 @@ class PubnubBase(object): return message + def _return_wrapped_callback(self, callback=None): + def _new_format_callback(response): + if 'payload' in response: + if (callback != None): callback({'message' : response['message'], 'payload' : response['payload']}) + else: + if (callback != None):callback(response) + if (callback != None): return _new_format_callback def publish( self, args ) : """ @@ -226,7 +235,7 @@ class PubnubBase(object): channel, '0', message - ]}, callback) + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)) def presence( self, args ) : """ @@ -266,7 +275,7 @@ class PubnubBase(object): callback = args['callback'] subscribe_key = args.get('subscribe_key') or self.subscribe_key - return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': callback}) + return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': self._return_wrapped_callback(callback)}) def here_now( self, args ) : @@ -306,7 +315,7 @@ class PubnubBase(object): 'v2','presence', 'sub_key', self.subscribe_key, 'channel', channel - ]}, callback); + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)); def history( self, args ) : @@ -350,7 +359,7 @@ class PubnubBase(object): channel, '0', str(limit) - ] }, callback); + ], 'urlparams' : {'auth' : self.auth_key} }, self._return_wrapped_callback(callback)); def detailedHistory(self, args) : """ @@ -381,6 +390,7 @@ class PubnubBase(object): count = int(args['count']) params['count'] = str(count) + params['auth'] = self.auth_key if args.has_key('reverse'): params['reverse'] = str(args['reverse']).lower() @@ -410,7 +420,7 @@ class PubnubBase(object): self.subscribe_key, 'channel', channel, - ],'urlparams' : params }, callback=callback); + ],'urlparams' : params }, callback=self._return_wrapped_callback(callback)); def time(self, args = None) : """ @@ -440,22 +450,32 @@ class PubnubBase(object): return time[0] + def _encode( self, request ) : - return [ + return "".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) - ]) for bit in request] + ]) for bit in request]) + def _add_param(self, key, value): + if value: + return key + "=" + self._encode(value) + else: + return "" + def getUrl(self,request): ## Build URL + args_string = None url = self.origin + '/' + "/".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) ]) for bit in request["urlcomponents"]]) if (request.has_key("urlparams")): - url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].iteritems()]) + args_string = "&".join([ self._add_param(x,y) for x,y in request["urlparams"].iteritems()]) + if (args_string != None and len(args_string) > 0): + url = url + '?' + args_string return url @@ -482,7 +502,8 @@ class PubnubCoreAsync(PubnubBase): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - uuid = None + uuid = None, + auth_key = None ) : """ #** @@ -508,7 +529,8 @@ class PubnubCoreAsync(PubnubBase): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, - UUID=uuid + UUID=uuid, + auth_key = auth_key ) self.subscriptions = {} @@ -669,7 +691,9 @@ class Pubnub(PubnubCoreAsync): secret_key = False, cipher_key = False, ssl_on = False, - origin = 'pubsub.pubnub.com' + origin = 'pubsub.pubnub.com', + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key=publish_key, @@ -678,6 +702,8 @@ class Pubnub(PubnubCoreAsync): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, + uuid = pres_uuid, + auth_key = auth_key ) self.headers = {} self.headers['User-Agent'] = ['Python-Twisted'] diff --git a/python-twisted/unassembled/Platform.py b/python-twisted/unassembled/Platform.py index 7318703..0ad8ff8 100644 --- a/python-twisted/unassembled/Platform.py +++ b/python-twisted/unassembled/Platform.py @@ -26,7 +26,9 @@ class Pubnub(PubnubCoreAsync): secret_key = False, cipher_key = False, ssl_on = False, - origin = 'pubsub.pubnub.com' + origin = 'pubsub.pubnub.com', + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key=publish_key, @@ -35,6 +37,8 @@ class Pubnub(PubnubCoreAsync): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, + uuid = pres_uuid, + auth_key = auth_key ) self.headers = {} self.headers['User-Agent'] = ['Python-Twisted'] diff --git a/python/Pubnub.py b/python/Pubnub.py index 59a38af..cd688ad 100644 --- a/python/Pubnub.py +++ b/python/Pubnub.py @@ -110,7 +110,8 @@ class PubnubBase(object): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - UUID = None + UUID = None, + auth_key = None ) : """ #** @@ -138,6 +139,7 @@ class PubnubBase(object): self.cipher_key = cipher_key self.ssl = ssl_on self.pc = PubnubCrypto() + self.auth_key = auth_key if self.ssl : self.origin = 'https://' + self.origin @@ -177,6 +179,13 @@ class PubnubBase(object): return message + def _return_wrapped_callback(self, callback=None): + def _new_format_callback(response): + if 'payload' in response: + if (callback != None): callback({'message' : response['message'], 'payload' : response['payload']}) + else: + if (callback != None):callback(response) + if (callback != None): return _new_format_callback def publish( self, args ) : """ @@ -226,7 +235,7 @@ class PubnubBase(object): channel, '0', message - ]}, callback) + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)) def presence( self, args ) : """ @@ -266,7 +275,7 @@ class PubnubBase(object): callback = args['callback'] subscribe_key = args.get('subscribe_key') or self.subscribe_key - return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': callback}) + return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': self._return_wrapped_callback(callback)}) def here_now( self, args ) : @@ -306,7 +315,7 @@ class PubnubBase(object): 'v2','presence', 'sub_key', self.subscribe_key, 'channel', channel - ]}, callback); + ], 'urlparams' : {'auth' : self.auth_key}}, self._return_wrapped_callback(callback)); def history( self, args ) : @@ -350,7 +359,7 @@ class PubnubBase(object): channel, '0', str(limit) - ] }, callback); + ], 'urlparams' : {'auth' : self.auth_key} }, self._return_wrapped_callback(callback)); def detailedHistory(self, args) : """ @@ -381,6 +390,7 @@ class PubnubBase(object): count = int(args['count']) params['count'] = str(count) + params['auth'] = self.auth_key if args.has_key('reverse'): params['reverse'] = str(args['reverse']).lower() @@ -410,7 +420,7 @@ class PubnubBase(object): self.subscribe_key, 'channel', channel, - ],'urlparams' : params }, callback=callback); + ],'urlparams' : params }, callback=self._return_wrapped_callback(callback)); def time(self, args = None) : """ @@ -440,22 +450,32 @@ class PubnubBase(object): return time[0] + def _encode( self, request ) : - return [ + return "".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) - ]) for bit in request] + ]) for bit in request]) + def _add_param(self, key, value): + if value: + return key + "=" + self._encode(value) + else: + return "" + def getUrl(self,request): ## Build URL + args_string = None url = self.origin + '/' + "/".join([ "".join([ ' ~`!@#$%^&*()+=[]\\{}|;\':",./<>?'.find(ch) > -1 and hex(ord(ch)).replace( '0x', '%' ).upper() or ch for ch in list(bit) ]) for bit in request["urlcomponents"]]) if (request.has_key("urlparams")): - url = url + '?' + "&".join([ x + "=" + y for x,y in request["urlparams"].iteritems()]) + args_string = "&".join([ self._add_param(x,y) for x,y in request["urlparams"].iteritems()]) + if (args_string != None and len(args_string) > 0): + url = url + '?' + args_string return url @@ -468,7 +488,8 @@ class PubnubCore(PubnubBase): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - uuid = None + uuid = None, + auth_key = None ) : """ #** @@ -495,7 +516,8 @@ class PubnubCore(PubnubBase): cipher_key=cipher_key, ssl_on=ssl_on, origin=origin, - UUID=uuid + UUID=uuid, + auth_key=auth_key ) self.subscriptions = {} @@ -586,7 +608,8 @@ class Pubnub(PubnubCore): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - pres_uuid = None + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key = publish_key, @@ -595,21 +618,25 @@ class Pubnub(PubnubCore): cipher_key = cipher_key, ssl_on = ssl_on, origin = origin, - uuid = pres_uuid + uuid = pres_uuid, + auth_key = auth_key ) def _request( self, request, callback = None ) : ## Build URL url = self.getUrl(request) + usock = None + response = None ## Send Request Expecting JSONP Response try: try: usock = urllib2.urlopen( url, None, 310 ) + except urllib2.HTTPError, e: response = e.fp.read() except TypeError: usock = urllib2.urlopen( url, None ) - response = usock.read() - usock.close() + if (response == None): response = usock.read() + if (usock != None): usock.close() resp_json = json.loads(response) - except: + except Exception as e: return None if (callback): diff --git a/python/examples/here-now-example.py b/python/examples/here-now-example.py index d2ca9bd..6c20405 100644 --- a/python/examples/here-now-example.py +++ b/python/examples/here-now-example.py @@ -23,8 +23,10 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- +#pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key, +# secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key, - secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on, auth_key="temp1") crazy = 'hello_world' def print_cb(message): diff --git a/python/examples/publish-example.py b/python/examples/publish-example.py index c97034b..c292e5e 100755 --- a/python/examples/publish-example.py +++ b/python/examples/publish-example.py @@ -1,14 +1,41 @@ + +import sys +sys.path.append('../') from Pubnub import Pubnub ## Initiate Class -pubnub = Pubnub( publish_key='demo', subscribe_key='demo', ssl_on=False ) +pubnub = Pubnub( publish_key='demo', subscribe_key='demo', cipher_key='enigma', ssl_on=False ) ## Publish Example info = pubnub.publish({ - 'channel' : 'hello_world', + 'channel' : 'abcd', 'message' : { 'some_text' : 'Hello my World' } }) print(info) +info = pubnub.publish({ + 'channel' : 'abcd', + 'message' : ['some_text','Hello my World'] +}) +print(info) + +info = pubnub.publish({ + 'channel' : 'abcd', + 'message' : "hi ,this is a string" +}) +print(info) + +info = pubnub.publish({ + 'channel' : 'abcd', + 'message' : 1 +}) +print(info) + +info = pubnub.publish({ + 'channel' : 'abcd', + 'message' : 2.1 +}) +print(info) + diff --git a/python/unassembled/Platform.py b/python/unassembled/Platform.py index f598a98..5b7e8a8 100644 --- a/python/unassembled/Platform.py +++ b/python/unassembled/Platform.py @@ -8,7 +8,8 @@ class Pubnub(PubnubCore): cipher_key = False, ssl_on = False, origin = 'pubsub.pubnub.com', - pres_uuid = None + pres_uuid = None, + auth_key = None ) : super(Pubnub, self).__init__( publish_key = publish_key, @@ -17,21 +18,25 @@ class Pubnub(PubnubCore): cipher_key = cipher_key, ssl_on = ssl_on, origin = origin, - uuid = pres_uuid + uuid = pres_uuid, + auth_key = auth_key ) def _request( self, request, callback = None ) : ## Build URL url = self.getUrl(request) + usock = None + response = None ## Send Request Expecting JSONP Response try: try: usock = urllib2.urlopen( url, None, 310 ) + except urllib2.HTTPError, e: response = e.fp.read() except TypeError: usock = urllib2.urlopen( url, None ) - response = usock.read() - usock.close() + if (response == None): response = usock.read() + if (usock != None): usock.close() resp_json = json.loads(response) - except: + except Exception as e: return None if (callback): |
