~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/apps/transport.py

  • Committer: Michael Hudson
  • Date: 2009-08-04 04:08:03 UTC
  • Revision ID: michael.hudson@canonical.com-20090804040803-7i2ax9r5z19xsk3l
fix stupid thinko that resulted in bug 405686

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from bzrlib import branch, errors, lru_cache, urlutils
22
22
from bzrlib.config import LocationConfig
23
 
from bzrlib.smart import request
24
23
from bzrlib.transport import get_transport
25
24
from bzrlib.transport.http import wsgi
26
25
 
29
28
from paste import urlparser
30
29
 
31
30
from loggerhead.apps.branch import BranchWSGIApp
32
 
from loggerhead.apps import favicon_app, robots_app, static_app
 
31
from loggerhead.apps import favicon_app, static_app
33
32
from loggerhead.controllers.directory_ui import DirectoryUI
34
33
 
35
34
_bools = {
55
54
            name = self.name
56
55
            is_root = False
57
56
        branch_app = BranchWSGIApp(
58
 
            branch,
59
 
            name,
 
57
            branch, name,
60
58
            {'cachepath': self._config.SQL_DIR},
61
 
            self.root.graph_cache,
62
 
            is_root=is_root,
63
 
            use_cdn=self._config.get_option('use_cdn'),
64
 
            )
 
59
            self.root.graph_cache, is_root=is_root,
 
60
            use_cdn=self._config.get_option('use_cdn'))
65
61
        return branch_app.app
66
62
 
67
63
    def app_for_non_branch(self, environ):
86
82
 
87
83
    def app_for_bazaar_data(self, relpath):
88
84
        if relpath == '/.bzr/smart':
89
 
            root_transport = get_transport_for_thread(self.root.base)
90
 
            wsgi_app = wsgi.SmartWSGIApp(root_transport)
91
 
            return wsgi.RelpathSetter(wsgi_app, '', 'loggerhead.path_info')
 
85
            wsgi_app = wsgi.SmartWSGIApp(self.transport)
 
86
            return wsgi.RelpathSetter(wsgi_app, '', 'PATH_INFO')
92
87
        else:
93
88
            # TODO: Use something here that uses the transport API
94
89
            # rather than relying on the local filesystem API.
132
127
_transport_store = threading.local()
133
128
 
134
129
def get_transport_for_thread(base):
 
130
    """ """
135
131
    thread_transports = getattr(_transport_store, 'transports', None)
136
132
    if thread_transports is None:
137
133
        thread_transports = _transport_store.transports = {}
138
134
    if base in thread_transports:
139
135
        return thread_transports[base]
140
136
    transport = get_transport(base)
141
 
    thread_transports[base] = transport
142
137
    return transport
143
138
 
144
139
 
151
146
 
152
147
    def __call__(self, environ, start_response):
153
148
        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
154
 
        environ['loggerhead.path_info'] = environ['PATH_INFO']
155
149
        if environ['PATH_INFO'].startswith('/static/'):
156
150
            segment = path_info_pop(environ)
157
151
            assert segment == 'static'
158
152
            return static_app(environ, start_response)
159
153
        elif environ['PATH_INFO'] == '/favicon.ico':
160
154
            return favicon_app(environ, start_response)
161
 
        elif environ['PATH_INFO'] == '/robots.txt':
162
 
            return robots_app(environ, start_response)
163
155
        else:
164
156
            transport = get_transport_for_thread(self.base)
165
157
            return BranchesFromTransportServer(
176
168
 
177
169
    def __call__(self, environ, start_response):
178
170
        environ['loggerhead.static.url'] = environ['SCRIPT_NAME']
179
 
        environ['loggerhead.path_info'] = environ['PATH_INFO']
180
171
        path_info = environ['PATH_INFO']
181
172
        if path_info.startswith('/static/'):
182
173
            segment = path_info_pop(environ)
184
175
            return static_app(environ, start_response)
185
176
        elif path_info == '/favicon.ico':
186
177
            return favicon_app(environ, start_response)
187
 
        elif environ['PATH_INFO'] == '/robots.txt':
188
 
            return robots_app(environ, start_response)
189
178
        else:
190
179
            transport = get_transport_for_thread(self.base)
191
180
            # segments starting with ~ are user branches