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)
| 654 | return decorator |
| 655 | |
| 656 | def mount(self, prefix, app, **options): |
| 657 | ''' Mount an application (:class:`Bottle` or plain WSGI) to a specific |
| 658 | URL prefix. Example:: |
| 659 | |
| 660 | root_app.mount('/admin/', admin_app) |
| 661 | |
| 662 | :param prefix: path prefix or `mount-point`. If it ends in a slash, |
| 663 | that slash is mandatory. |
| 664 | :param app: an instance of :class:`Bottle` or a WSGI application. |
| 665 | |
| 666 | All other parameters are passed to the underlying :meth:`route` call. |
| 667 | ''' |
| 668 | if isinstance(app, basestring): |
| 669 | depr('Parameter order of Bottle.mount() changed.', True) # 0.10 |
| 670 | |
| 671 | segments = [p for p in prefix.split('/') if p] |
| 672 | if not segments: raise ValueError('Empty path prefix.') |
| 673 | path_depth = len(segments) |
| 674 | |
| 675 | def mountpoint_wrapper(): |
| 676 | try: |
| 677 | request.path_shift(path_depth) |
| 678 | rs = HTTPResponse([]) |
| 679 | def start_response(status, headerlist, exc_info=None): |
| 680 | if exc_info: |
| 681 | try: |
| 682 | _raise(*exc_info) |
| 683 | finally: |
| 684 | exc_info = None |
| 685 | rs.status = status |
| 686 | for name, value in headerlist: rs.add_header(name, value) |
| 687 | return rs.body.append |
| 688 | body = app(request.environ, start_response) |
| 689 | if body and rs.body: body = itertools.chain(rs.body, body) |
| 690 | rs.body = body or rs.body |
| 691 | return rs |
| 692 | finally: |
| 693 | request.path_shift(-path_depth) |
| 694 | |
| 695 | options.setdefault('skip', True) |
| 696 | options.setdefault('method', 'PROXY') |
| 697 | options.setdefault('mountpoint', {'prefix': prefix, 'target': app}) |
| 698 | options['callback'] = mountpoint_wrapper |
| 699 | |
| 700 | self.route('/%s/<:re:.*>' % '/'.join(segments), **options) |
| 701 | if not prefix.endswith('/'): |
| 702 | self.route('/' + '/'.join(segments), **options) |
| 703 | |
| 704 | def merge(self, routes): |
| 705 | ''' Merge the routes of another :class:`Bottle` application or a list of |
nothing calls this directly
no test coverage detected