Skip to content
Browse files

Get WSGIParty functional without dispatcher.

  • Loading branch information...
1 parent 8d6eef0 commit b9fa7af2d04022e4bf0fc279eedb34c0ebb5bc41 @rduplain committed
Showing with 21 additions and 19 deletions.
  1. +21 −19 wsgi_party.py
View
40 wsgi_party.py
@@ -26,11 +26,11 @@ class PartylineOperator(object):
def __init__(self, partyline):
self.partyline = partyline
- def connect(self, service, handler):
- return self.partyline.connect(service, handler)
+ def connect(self, service_name, handler):
+ return self.partyline.connect(service_name, handler)
- def send_all(self, service, payload):
- return self.partyline.send_all(service, payload)
+ def ask_around(self, service_name, payload):
+ return self.partyline.ask_around(service_name, payload)
class WSGIParty(object):
@@ -45,31 +45,33 @@ class WSGIParty(object):
def __init__(self, application, invites=()):
#: Wrapped WSGI application.
self.application = application
+
+ #: A dict of service name -> handler mappings.
+ self.handlers = {}
+
+ #: PartylineOperator to expose APIs to connect to this WSGIParty.
+ self.operator = self.operator_class(self)
+
self.send_invitations(invites)
def __call__(self, environ, start_response):
"""Call wrapped application."""
- self.applications(environ, start_response)
+ return self.application(environ, start_response)
def send_invitations(self, invites):
"""Call each invite route to establish a partyline."""
- self.operator = self.operator_class(self)
for invite in invites:
- self.send_invitation(invite)
-
- def send_invitation(self, invite):
- """Call individual route to add an application to the partyline."""
- environ = create_environ(path=invite)
- environ[self.partyline_key] = operator
- run_wsgi_app(application, environ)
+ environ = create_environ(path=invite)
+ environ[self.partyline_key] = self.operator
+ run_wsgi_app(self.application, environ)
- def connect(self, service, handler):
- """Register a handler for a given service."""
- self.partyline.setdefault(service, []).append(handler)
+ def connect(self, service_name, handler):
+ """Register a handler for a given service name."""
+ self.handlers.setdefault(service_name, []).append(handler)
- def send_all(self, service, payload):
- """Notify all listeners of a service and yield their results."""
- for handler in self.partyline[service]:
+ def ask_around(self, service_name, payload):
+ """Notify all listeners of a service name and yield their results."""
+ for handler in self.handlers[service_name]:
try:
yield handler(payload)
except HighAndDry:

0 comments on commit b9fa7af

Please sign in to comment.
Something went wrong with that request. Please try again.