##// END OF EJS Templates
pyramid: don't use deprecated custom_predicates in view config
marcink -
r583:d119c397 default
parent child Browse files
Show More
@@ -197,6 +197,28 b' class WsgiProxy(object):'
197 yield msgpack.packb(d)
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 class HTTPApplication(object):
222 class HTTPApplication(object):
201 ALLOWED_EXCEPTIONS = ('KeyError', 'URLError')
223 ALLOWED_EXCEPTIONS = ('KeyError', 'URLError')
202
224
@@ -279,9 +301,7 b' class HTTPApplication(object):'
279 1024)
301 1024)
280
302
281 def _configure(self):
303 def _configure(self):
282 self.config.add_renderer(
304 self.config.add_renderer(name='msgpack', factory=self._msgpack_renderer_factory)
283 name='msgpack',
284 factory=self._msgpack_renderer_factory)
285
305
286 self.config.add_route('service', '/_service')
306 self.config.add_route('service', '/_service')
287 self.config.add_route('status', '/status')
307 self.config.add_route('status', '/status')
@@ -291,23 +311,20 b' class HTTPApplication(object):'
291 self.config.add_route('stream_git', '/stream/git/*repo_name')
311 self.config.add_route('stream_git', '/stream/git/*repo_name')
292 self.config.add_route('stream_hg', '/stream/hg/*repo_name')
312 self.config.add_route('stream_hg', '/stream/hg/*repo_name')
293
313
294 self.config.add_view(
314 self.config.add_view(self.status_view, route_name='status', renderer='json')
295 self.status_view, route_name='status', renderer='json')
315 self.config.add_view(self.service_view, route_name='service', renderer='msgpack')
296 self.config.add_view(
297 self.service_view, route_name='service', renderer='msgpack')
298
316
299 self.config.add_view(self.hg_proxy(), route_name='hg_proxy')
317 self.config.add_view(self.hg_proxy(), route_name='hg_proxy')
300 self.config.add_view(self.git_proxy(), route_name='git_proxy')
318 self.config.add_view(self.git_proxy(), route_name='git_proxy')
301 self.config.add_view(
319 self.config.add_view(self.vcs_view, route_name='vcs', renderer='msgpack',
302 self.vcs_view, route_name='vcs', renderer='msgpack',
320 vcs_view=self._remotes)
303 custom_predicates=[self.is_vcs_view])
304
321
305 self.config.add_view(self.hg_stream(), route_name='stream_hg')
322 self.config.add_view(self.hg_stream(), route_name='stream_hg')
306 self.config.add_view(self.git_stream(), route_name='stream_git')
323 self.config.add_view(self.git_stream(), route_name='stream_git')
307
324
308 def notfound(request):
325 self.config.add_view_predicate('vcs_view', VCSViewPredicate)
309 return {'status': '404 NOT FOUND'}
326
310 self.config.add_notfound_view(notfound, renderer='json')
327 self.config.add_notfound_view(not_found, renderer='json')
311
328
312 self.config.add_view(self.handle_vcs_exception, context=Exception)
329 self.config.add_view(self.handle_vcs_exception, context=Exception)
313
330
@@ -543,14 +560,6 b' class HTTPApplication(object):'
543
560
544 return _git_stream
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 def handle_vcs_exception(self, exception, request):
563 def handle_vcs_exception(self, exception, request):
555 _vcs_kind = getattr(exception, '_vcs_kind', '')
564 _vcs_kind = getattr(exception, '_vcs_kind', '')
556 if _vcs_kind == 'repo_locked':
565 if _vcs_kind == 'repo_locked':
General Comments 0
You need to be logged in to leave comments. Login now