/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/transport/http/wsgi.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from cStringIO import StringIO
26
26
 
27
 
from bzrlib.smart import medium
28
 
from bzrlib.transport import chroot, get_transport
29
 
from bzrlib.urlutils import local_path_to_url
 
27
from breezy.smart import medium
 
28
from breezy.transport import chroot, get_transport
 
29
from breezy.urlutils import local_path_to_url
30
30
 
31
31
 
32
32
def make_app(root, prefix, path_var='REQUEST_URI', readonly=True,
43
43
    else:
44
44
        base_transport = get_transport(local_url)
45
45
    if load_plugins:
46
 
        from bzrlib.plugin import load_plugins
 
46
        from breezy.plugin import load_plugins
47
47
        load_plugins()
48
48
    if enable_logging:
49
 
        import bzrlib.trace
50
 
        bzrlib.trace.enable_default_logging()
 
49
        import breezy.trace
 
50
        breezy.trace.enable_default_logging()
51
51
    app = SmartWSGIApp(base_transport, prefix)
52
52
    app = RelpathSetter(app, '', path_var)
53
53
    return app
54
54
 
55
55
 
56
56
class RelpathSetter(object):
57
 
    """WSGI middleware to set 'bzrlib.relpath' in the environ.
 
57
    """WSGI middleware to set 'breezy.relpath' in the environ.
58
58
 
59
59
    Different servers can invoke a SmartWSGIApp in different ways.  This
60
60
    middleware allows an adminstrator to configure how to the SmartWSGIApp will
65
65
    a typical Apache and mod_fastcgi configuration will set `REQUEST_URI` to
66
66
    "/some/prefix/repo/branch/.bzr/smart".  A RelpathSetter with
67
67
    prefix="/some/prefix/" and path_var="REQUEST_URI" will set that request's
68
 
    'bzrlib.relpath' variable to "repo/branch".
 
68
    'breezy.relpath' variable to "repo/branch".
69
69
    """
70
70
 
71
71
    def __init__(self, app, prefix='', path_var='REQUEST_URI'):
73
73
 
74
74
        :param app: WSGI app to wrap, e.g. a SmartWSGIApp instance.
75
75
        :param path_var: the variable in the WSGI environ to calculate the
76
 
            'bzrlib.relpath' variable from.
 
76
            'breezy.relpath' variable from.
77
77
        :param prefix: a prefix to strip from the variable specified in
78
 
            path_var before setting 'bzrlib.relpath'.
 
78
            path_var before setting 'breezy.relpath'.
79
79
        """
80
80
        self.app = app
81
81
        self.prefix = prefix
87
87
        if not (path.startswith(self.prefix) and path.endswith(suffix)):
88
88
            start_response('404 Not Found', [])
89
89
            return []
90
 
        environ['bzrlib.relpath'] = path[len(self.prefix):-len(suffix)]
 
90
        environ['breezy.relpath'] = path[len(self.prefix):-len(suffix)]
91
91
        return self.app(environ, start_response)
92
92
 
93
93
 
114
114
        # While the chroot server can technically be torn down at this point,
115
115
        # as all it does is remove the scheme registration from transport's
116
116
        # protocol dictionary, we don't *just in case* there are parts of
117
 
        # bzrlib that will invoke 'get_transport' on urls rather than cloning
 
117
        # breezy that will invoke 'get_transport' on urls rather than cloning
118
118
        # around the existing transport.
119
119
        #self.chroot_server.stop_server()
120
120
 
124
124
            start_response('405 Method not allowed', [('Allow', 'POST')])
125
125
            return []
126
126
 
127
 
        relpath = environ['bzrlib.relpath']
 
127
        relpath = environ['breezy.relpath']
128
128
 
129
129
        if not relpath.startswith('/'):
130
130
            relpath = '/' + relpath