/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/apps/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-11-02 01:23:00 UTC
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: jelmer@samba.org-20111102012300-8w1gktialc1jwcnn
Add hook 'controller' to BranchWSGIApp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import bzrlib.branch
24
24
import bzrlib.errors
 
25
from bzrlib.hooks import Hooks
25
26
import bzrlib.lru_cache
26
27
 
27
28
from paste import request
155
156
                    self.served_url = self.url([])
156
157
                except bzrlib.errors.InvalidURL:
157
158
                    self.served_url = None
 
159
        for hook in self.hooks['controller']:
 
160
            controller = hook(self, environ)
 
161
            if controller is not None:
 
162
                return controller
158
163
        path = request.path_info_pop(environ)
159
164
        if not path:
160
165
            raise httpexceptions.HTTPMovedPermanently(
181
186
                raise
182
187
        finally:
183
188
            self.branch.unlock()
 
189
 
 
190
 
 
191
class BranchWSGIAppHooks(Hooks):
 
192
    """A dictionary mapping hook name to a list of callables for WSGI app branch hooks.
 
193
    """
 
194
 
 
195
    def __init__(self):
 
196
        """Create the default hooks.
 
197
        """
 
198
        Hooks.__init__(self, "bzrlib.plugins.loggerhead.apps.branch",
 
199
            "BranchWSGIApp.hooks")
 
200
        self.add_hook('controller',
 
201
            "Invoked when looking for the controller to use for a "
 
202
            "branch subpage. The api signature is (branch_app, environ)."
 
203
            "If a hook can provide a controller, it should return one, "
 
204
            "as a standard WSGI app. If it can't provide a controller, "
 
205
            "it should return None", (1, 19))
 
206
 
 
207
 
 
208
BranchWSGIApp.hooks = BranchWSGIAppHooks()