/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 bzrlib/transport/http/wsgi.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

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