Show More
@@ -197,6 +197,28 b' class WsgiProxy(object):' | |||
|
197 | 197 | yield msgpack.packb(d) |
|
198 | 198 | |
|
199 | 199 | |
|
200 | def not_found(request): | |
|
201 | return {'status': '404 NOT FOUND'} | |
|
202 | ||
|
203 | ||
|
204 | class VCSViewPredicate(object): | |
|
205 | def __init__(self, val, config): | |
|
206 | self.remotes = val | |
|
207 | ||
|
208 | def text(self): | |
|
209 | return 'vcs view method = %s' % (self.remotes.keys(),) | |
|
210 | ||
|
211 | phash = text | |
|
212 | ||
|
213 | def __call__(self, context, request): | |
|
214 | """ | |
|
215 | View predicate that returns true if given backend is supported by | |
|
216 | defined remotes. | |
|
217 | """ | |
|
218 | backend = request.matchdict.get('backend') | |
|
219 | return backend in self.remotes | |
|
220 | ||
|
221 | ||
|
200 | 222 | class HTTPApplication(object): |
|
201 | 223 | ALLOWED_EXCEPTIONS = ('KeyError', 'URLError') |
|
202 | 224 | |
@@ -279,9 +301,7 b' class HTTPApplication(object):' | |||
|
279 | 301 | 1024) |
|
280 | 302 | |
|
281 | 303 | def _configure(self): |
|
282 | self.config.add_renderer( | |
|
283 | name='msgpack', | |
|
284 | factory=self._msgpack_renderer_factory) | |
|
304 | self.config.add_renderer(name='msgpack', factory=self._msgpack_renderer_factory) | |
|
285 | 305 | |
|
286 | 306 | self.config.add_route('service', '/_service') |
|
287 | 307 | self.config.add_route('status', '/status') |
@@ -291,23 +311,20 b' class HTTPApplication(object):' | |||
|
291 | 311 | self.config.add_route('stream_git', '/stream/git/*repo_name') |
|
292 | 312 | self.config.add_route('stream_hg', '/stream/hg/*repo_name') |
|
293 | 313 | |
|
294 | self.config.add_view( | |
|
295 |
|
|
|
296 | self.config.add_view( | |
|
297 | self.service_view, route_name='service', renderer='msgpack') | |
|
314 | self.config.add_view(self.status_view, route_name='status', renderer='json') | |
|
315 | self.config.add_view(self.service_view, route_name='service', renderer='msgpack') | |
|
298 | 316 | |
|
299 | 317 | self.config.add_view(self.hg_proxy(), route_name='hg_proxy') |
|
300 | 318 | self.config.add_view(self.git_proxy(), route_name='git_proxy') |
|
301 | self.config.add_view( | |
|
302 | self.vcs_view, route_name='vcs', renderer='msgpack', | |
|
303 | custom_predicates=[self.is_vcs_view]) | |
|
319 | self.config.add_view(self.vcs_view, route_name='vcs', renderer='msgpack', | |
|
320 | vcs_view=self._remotes) | |
|
304 | 321 | |
|
305 | 322 | self.config.add_view(self.hg_stream(), route_name='stream_hg') |
|
306 | 323 | self.config.add_view(self.git_stream(), route_name='stream_git') |
|
307 | 324 | |
|
308 | def notfound(request): | |
|
309 | return {'status': '404 NOT FOUND'} | |
|
310 | self.config.add_notfound_view(notfound, renderer='json') | |
|
325 | self.config.add_view_predicate('vcs_view', VCSViewPredicate) | |
|
326 | ||
|
327 | self.config.add_notfound_view(not_found, renderer='json') | |
|
311 | 328 | |
|
312 | 329 | self.config.add_view(self.handle_vcs_exception, context=Exception) |
|
313 | 330 | |
@@ -543,14 +560,6 b' class HTTPApplication(object):' | |||
|
543 | 560 | |
|
544 | 561 | return _git_stream |
|
545 | 562 | |
|
546 | def is_vcs_view(self, context, request): | |
|
547 | """ | |
|
548 | View predicate that returns true if given backend is supported by | |
|
549 | defined remotes. | |
|
550 | """ | |
|
551 | backend = request.matchdict.get('backend') | |
|
552 | return backend in self._remotes | |
|
553 | ||
|
554 | 563 | def handle_vcs_exception(self, exception, request): |
|
555 | 564 | _vcs_kind = getattr(exception, '_vcs_kind', '') |
|
556 | 565 | if _vcs_kind == 'repo_locked': |
General Comments 0
You need to be logged in to leave comments.
Login now