diff options
| author | Devendra | 2013-12-18 23:23:22 +0530 | 
|---|---|---|
| committer | Devendra | 2013-12-18 23:23:22 +0530 | 
| commit | 786390e9ee0024ab3061a9133700457b07ae0f80 (patch) | |
| tree | 0aa0acda65ed1c51c68f138c0114055f6769374c /python-tornado/Pubnub.py | |
| parent | 1d601e3411af27c1b39e697849a538b692a535e7 (diff) | |
| download | pubnub-python-786390e9ee0024ab3061a9133700457b07ae0f80.tar.bz2 | |
adding pam client support to python sdk
Diffstat (limited to 'python-tornado/Pubnub.py')
| -rw-r--r-- | python-tornado/Pubnub.py | 50 | 
1 files changed, 38 insertions, 12 deletions
| 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' | 
