MCPcopy
hub / github.com/pyload/pyload / mount

Method mount

module/lib/bottle.py:547–584  ·  view source on GitHub ↗

Mount an application (:class:`Bottle` or plain WSGI) to a specific URL prefix. Example:: root_app.mount('/admin/', admin_app) :param prefix: path prefix or `mount-point`. If it ends in a slash, that slash is mandatory. :param app

(self, prefix, app, **options)

Source from the content-addressed store, hash-verified

545 self.install(TemplatePlugin())
546
547 def mount(self, prefix, app, **options):
548 ''' Mount an application (:class:`Bottle` or plain WSGI) to a specific
549 URL prefix. Example::
550
551 root_app.mount('/admin/', admin_app)
552
553 :param prefix: path prefix or `mount-point`. If it ends in a slash,
554 that slash is mandatory.
555 :param app: an instance of :class:`Bottle` or a WSGI application.
556
557 All other parameters are passed to the underlying :meth:`route` call.
558 '''
559 if isinstance(app, basestring):
560 prefix, app = app, prefix
561 depr('Parameter order of Bottle.mount() changed.') # 0.10
562
563 parts = filter(None, prefix.split('/'))
564 if not parts: raise ValueError('Empty path prefix.')
565 path_depth = len(parts)
566 options.setdefault('skip', True)
567 options.setdefault('method', 'ANY')
568
569 @self.route('/%s/:#.*#' % '/'.join(parts), **options)
570 def mountpoint():
571 try:
572 request.path_shift(path_depth)
573 rs = BaseResponse([], 200)
574 def start_response(status, header):
575 rs.status = status
576 for name, value in header: rs.add_header(name, value)
577 return rs.body.append
578 rs.body = itertools.chain(rs.body, app(request.environ, start_response))
579 return HTTPResponse(rs.body, rs.status, rs.headers)
580 finally:
581 request.path_shift(-path_depth)
582
583 if not prefix.endswith('/'):
584 self.route('/' + '/'.join(parts), callback=mountpoint, **options)
585
586 def install(self, plugin):
587 ''' Add a plugin to the list of plugins and prepare it for being

Callers

nothing calls this directly

Calls 6

routeMethod · 0.95
deprFunction · 0.85
filterFunction · 0.85
splitMethod · 0.80
joinMethod · 0.80
setdefaultMethod · 0.45

Tested by

no test coverage detected