Skip to content

Commit

Permalink
Support pusher>=1.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
iurisilvio committed Dec 18, 2016
1 parent 4cebe6b commit 4be823f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -45,7 +45,7 @@ matrix:
env: FLASK="==0.11"

install:
- pip install -q Flask$FLASK $PUSHER
- pip install Flask$FLASK $PUSHER
- pip install unittest2 coverage coveralls
- python setup.py install

Expand Down
19 changes: 18 additions & 1 deletion flask_pusher.py
Expand Up @@ -33,6 +33,23 @@ def verify(key, message, signature):
return sign(key, message) == signature


class _Pusher(_pusher.Pusher):
"""
Pusher client wrapper to get attributes from `_pusher_client`
if the attribute does not exist.
Provide backward compatibility to `pusher>=1.6`.
"""
def __getattr__(self, attr):
try:
client = self._pusher_client
except AttributeError:
# call super to raise the original exception
return super(_Pusher, self).__getattr__(attr)
else:
return getattr(client, attr)


class Pusher(object):

def __init__(self, app=None, url_prefix="/pusher"):
Expand Down Expand Up @@ -71,7 +88,7 @@ def init_app(self, app):
else:
pusher_kwargs["encoder"] = getattr(app, "json_encoder", None)

client = _pusher.Pusher(**pusher_kwargs)
client = _Pusher(**pusher_kwargs)

self._make_blueprint(app.config["PUSHER_AUTH"])
app.register_blueprint(self._blueprint)
Expand Down

0 comments on commit 4be823f

Please sign in to comment.