Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Update Flask example for non-dispatcher WSGIParty.
Browse files Browse the repository at this point in the history
  • Loading branch information
rduplain committed Mar 17, 2012
1 parent b9fa7af commit d4e522d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions examples/flask/flask_party.py
Expand Up @@ -5,13 +5,17 @@
from flask import Flask, abort, request
from werkzeug.routing import BuildError
from werkzeug.urls import url_quote
from werkzeug.wsgi import DispatcherMiddleware
from wsgi_party import WSGIParty, HighAndDry


INVITE_PATH = '/__invite__/'


class PartylineFlask(Flask):
def __init__(self, import_name, *args, **kwargs):
super(PartylineFlask, self).__init__(import_name, *args, **kwargs)
self.add_url_rule(WSGIParty.invite_path, endpoint='partyline',
self.add_url_rule(INVITE_PATH, endpoint='partyline',
view_func=self.join_party)
self.partyline = None
self.connected = False
Expand Down Expand Up @@ -63,7 +67,7 @@ def url_for(self, endpoint, use_partyline=True, **values):
# We do not have this URL, ask the partyline.
if not use_partyline:
raise
for url in self.partyline.send_all('url', (endpoint, copy_values)):
for url in self.partyline.ask_around('url', (endpoint, copy_values)):
# First response wins.
return url
if anchor is not None:
Expand All @@ -87,6 +91,7 @@ def my_url_for(self, endpoint, **values):
two.debug = True
three.debug = True

# Tell sessions on which path to store cookies.
one.config['APPLICATION_ROOT'] = '/one'
two.config['APPLICATION_ROOT'] = '/two'
three.config['APPLICATION_ROOT'] = '/three'
Expand Down Expand Up @@ -128,11 +133,11 @@ def three_index():
return 'I do not participate in parties.'


application = WSGIParty(root, {
'/one': one,
'/two': two,
'/three': three,
})
application = WSGIParty(DispatcherMiddleware(root, {
one.config['APPLICATION_ROOT']: one,
two.config['APPLICATION_ROOT']: two,
three.config['APPLICATION_ROOT']: three,
}), invites=(INVITE_PATH, '/one/'+INVITE_PATH, '/two/'+INVITE_PATH))


if __name__ == '__main__':
Expand Down

0 comments on commit d4e522d

Please sign in to comment.