/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/smart/request.py

  • Committer: Andrew Bennetts
  • Date: 2009-10-21 11:13:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4762.
  • Revision ID: andrew.bennetts@canonical.com-20091021111340-w7x4d5yf83qwjncc
Add test that WSGI glue allows request handlers to access paths above that request's. backing transport, so long as it is within the WSGI app's backing transport.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
32
32
 
33
33
 
34
34
import tempfile
35
 
import thread
36
35
import threading
37
36
 
38
37
from bzrlib import (
39
38
    bzrdir,
40
 
    debug,
41
39
    errors,
42
 
    osutils,
43
40
    registry,
44
41
    revision,
45
42
    trace,
191
188
            relpath = urlutils.joinpath('/', path)
192
189
            if not relpath.startswith('/'):
193
190
                raise ValueError(relpath)
194
 
            return urlutils.escape('.' + relpath)
 
191
            return '.' + relpath
195
192
        else:
196
193
            raise errors.PathNotChild(client_path, self._root_client_path)
197
194
 
274
271
    # and allow it to be streamed into the server.
275
272
 
276
273
    def __init__(self, backing_transport, commands, root_client_path,
277
 
        jail_root=None):
 
274
        jail_root):
278
275
        """Constructor.
279
276
 
280
277
        :param backing_transport: a Transport to handle requests for.
284
281
        self._backing_transport = backing_transport
285
282
        self._root_client_path = root_client_path
286
283
        self._commands = commands
287
 
        if jail_root is None:
288
 
            jail_root = backing_transport
289
284
        self._jail_root = jail_root
290
285
        self.response = None
291
286
        self.finished_reading = False
292
287
        self._command = None
293
 
        if 'hpss' in debug.debug_flags:
294
 
            self._request_start_time = osutils.timer_func()
295
 
            self._thread_id = thread.get_ident()
296
 
 
297
 
    def _trace(self, action, message, extra_bytes=None, include_time=False):
298
 
        # It is a bit of a shame that this functionality overlaps with that of 
299
 
        # ProtocolThreeRequester._trace. However, there is enough difference
300
 
        # that just putting it in a helper doesn't help a lot. And some state
301
 
        # is taken from the instance.
302
 
        if include_time:
303
 
            t = '%5.3fs ' % (osutils.timer_func() - self._request_start_time)
304
 
        else:
305
 
            t = ''
306
 
        if extra_bytes is None:
307
 
            extra = ''
308
 
        else:
309
 
            extra = ' ' + repr(extra_bytes[:40])
310
 
            if len(extra) > 33:
311
 
                extra = extra[:29] + extra[-1] + '...'
312
 
        trace.mutter('%12s: [%s] %s%s%s'
313
 
                     % (action, self._thread_id, t, message, extra))
314
288
 
315
289
    def accept_body(self, bytes):
316
290
        """Accept body data."""
318
292
            # no active command object, so ignore the event.
319
293
            return
320
294
        self._run_handler_code(self._command.do_chunk, (bytes,), {})
321
 
        if 'hpss' in debug.debug_flags:
322
 
            self._trace('accept body',
323
 
                        '%d bytes' % (len(bytes),), bytes)
324
295
 
325
296
    def end_of_body(self):
326
297
        """No more body data will be received."""
327
298
        self._run_handler_code(self._command.do_end, (), {})
328
299
        # cannot read after this.
329
300
        self.finished_reading = True
330
 
        if 'hpss' in debug.debug_flags:
331
 
            self._trace('end of body', '', include_time=True)
332
301
 
333
302
    def _run_handler_code(self, callable, args, kwargs):
334
303
        """Run some handler specific code 'callable'.
363
332
 
364
333
    def headers_received(self, headers):
365
334
        # Just a no-op at the moment.
366
 
        if 'hpss' in debug.debug_flags:
367
 
            self._trace('headers', repr(headers))
 
335
        pass
368
336
 
369
337
    def args_received(self, args):
370
338
        cmd = args[0]
372
340
        try:
373
341
            command = self._commands.get(cmd)
374
342
        except LookupError:
375
 
            if 'hpss' in debug.debug_flags:
376
 
                self._trace('hpss unknown request', 
377
 
                            cmd, repr(args)[1:-1])
378
343
            raise errors.UnknownSmartMethod(cmd)
379
 
        if 'hpss' in debug.debug_flags:
380
 
            from bzrlib.smart import vfs
381
 
            if issubclass(command, vfs.VfsRequest):
382
 
                action = 'hpss vfs req'
383
 
            else:
384
 
                action = 'hpss request'
385
 
            self._trace(action, 
386
 
                        '%s %s' % (cmd, repr(args)[1:-1]))
387
344
        self._command = command(
388
345
            self._backing_transport, self._root_client_path, self._jail_root)
389
346
        self._run_handler_code(self._command.execute, args, {})
393
350
            # no active command object, so ignore the event.
394
351
            return
395
352
        self._run_handler_code(self._command.do_end, (), {})
396
 
        if 'hpss' in debug.debug_flags:
397
 
            self._trace('end', '', include_time=True)
398
353
 
399
354
    def post_body_error_received(self, error_args):
400
355
        # Just a no-op at the moment.
561
516
    'BzrDir.open_branchV2', 'bzrlib.smart.bzrdir',
562
517
    'SmartServerRequestOpenBranchV2')
563
518
request_handlers.register_lazy(
564
 
    'BzrDir.open_branchV3', 'bzrlib.smart.bzrdir',
565
 
    'SmartServerRequestOpenBranchV3')
566
 
request_handlers.register_lazy(
567
519
    'delete', 'bzrlib.smart.vfs', 'DeleteRequest')
568
520
request_handlers.register_lazy(
569
521
    'get', 'bzrlib.smart.vfs', 'GetRequest')