/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: Jonathan Lange
  • Date: 2009-12-09 09:20:42 UTC
  • mfrom: (4881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4907.
  • Revision ID: jml@canonical.com-20091209092042-s2zgqcf8f39yzxpj
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    # XXX: rename this class to BaseSmartServerRequestHandler ?  A request
87
87
    # *handler* is a different concept to the request.
88
88
 
89
 
    def __init__(self, backing_transport, root_client_path='/'):
 
89
    def __init__(self, backing_transport, root_client_path='/', jail_root=None):
90
90
        """Constructor.
91
91
 
92
92
        :param backing_transport: the base transport to be used when performing
96
96
            from the client.  Clients will not be able to refer to paths above
97
97
            this root.  If root_client_path is None, then no translation will
98
98
            be performed on client paths.  Default is '/'.
 
99
        :param jail_root: if specified, the root of the BzrDir.open jail to use
 
100
            instead of backing_transport.
99
101
        """
100
102
        self._backing_transport = backing_transport
 
103
        if jail_root is None:
 
104
            jail_root = backing_transport
 
105
        self._jail_root = jail_root
101
106
        if root_client_path is not None:
102
107
            if not root_client_path.startswith('/'):
103
108
                root_client_path = '/' + root_client_path
155
160
        return self.do_body(body_bytes)
156
161
 
157
162
    def setup_jail(self):
158
 
        jail_info.transports = [self._backing_transport]
 
163
        jail_info.transports = [self._jail_root]
159
164
 
160
165
    def teardown_jail(self):
161
166
        jail_info.transports = None
183
188
            relpath = urlutils.joinpath('/', path)
184
189
            if not relpath.startswith('/'):
185
190
                raise ValueError(relpath)
186
 
            return '.' + relpath
 
191
            return urlutils.escape('.' + relpath)
187
192
        else:
188
193
            raise errors.PathNotChild(client_path, self._root_client_path)
189
194
 
265
270
    # TODO: Better way of representing the body for commands that take it,
266
271
    # and allow it to be streamed into the server.
267
272
 
268
 
    def __init__(self, backing_transport, commands, root_client_path):
 
273
    def __init__(self, backing_transport, commands, root_client_path,
 
274
        jail_root=None):
269
275
        """Constructor.
270
276
 
271
277
        :param backing_transport: a Transport to handle requests for.
275
281
        self._backing_transport = backing_transport
276
282
        self._root_client_path = root_client_path
277
283
        self._commands = commands
 
284
        if jail_root is None:
 
285
            jail_root = backing_transport
 
286
        self._jail_root = jail_root
278
287
        self.response = None
279
288
        self.finished_reading = False
280
289
        self._command = None
281
290
 
282
291
    def accept_body(self, bytes):
283
292
        """Accept body data."""
 
293
        if self._command is None:
 
294
            # no active command object, so ignore the event.
 
295
            return
284
296
        self._run_handler_code(self._command.do_chunk, (bytes,), {})
285
297
 
286
298
    def end_of_body(self):
289
301
        # cannot read after this.
290
302
        self.finished_reading = True
291
303
 
292
 
    def dispatch_command(self, cmd, args):
293
 
        """Deprecated compatibility method.""" # XXX XXX
294
 
        try:
295
 
            command = self._commands.get(cmd)
296
 
        except LookupError:
297
 
            raise errors.UnknownSmartMethod(cmd)
298
 
        self._command = command(self._backing_transport, self._root_client_path)
299
 
        self._run_handler_code(self._command.execute, args, {})
300
 
 
301
304
    def _run_handler_code(self, callable, args, kwargs):
302
305
        """Run some handler specific code 'callable'.
303
306
 
340
343
            command = self._commands.get(cmd)
341
344
        except LookupError:
342
345
            raise errors.UnknownSmartMethod(cmd)
343
 
        self._command = command(self._backing_transport)
 
346
        self._command = command(
 
347
            self._backing_transport, self._root_client_path, self._jail_root)
344
348
        self._run_handler_code(self._command.execute, args, {})
345
349
 
346
350
    def end_received(self):
 
351
        if self._command is None:
 
352
            # no active command object, so ignore the event.
 
353
            return
347
354
        self._run_handler_code(self._command.do_end, (), {})
348
355
 
349
356
    def post_body_error_received(self, error_args):
358
365
        return ('FileExists', err.path)
359
366
    elif isinstance(err, errors.DirectoryNotEmpty):
360
367
        return ('DirectoryNotEmpty', err.path)
 
368
    elif isinstance(err, errors.IncompatibleRepositories):
 
369
        return ('IncompatibleRepositories', str(err.source), str(err.target),
 
370
            str(err.details))
361
371
    elif isinstance(err, errors.ShortReadvError):
362
372
        return ('ShortReadvError', err.path, str(err.offset), str(err.length),
363
373
                str(err.actual))
392
402
    elif isinstance(err, errors.TokenMismatch):
393
403
        return ('TokenMismatch', err.given_token, err.lock_token)
394
404
    elif isinstance(err, errors.LockContention):
395
 
        return ('LockContention', err.lock, err.msg)
 
405
        return ('LockContention',)
396
406
    # Unserialisable error.  Log it, and return a generic error
397
407
    trace.log_exception_quietly()
398
408
    return ('error', str(err))
445
455
    'Branch.get_tags_bytes', 'bzrlib.smart.branch',
446
456
    'SmartServerBranchGetTagsBytes')
447
457
request_handlers.register_lazy(
 
458
    'Branch.set_tags_bytes', 'bzrlib.smart.branch',
 
459
    'SmartServerBranchSetTagsBytes')
 
460
request_handlers.register_lazy(
448
461
    'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')
449
462
request_handlers.register_lazy(
450
463
    'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')
497
510
request_handlers.register_lazy(
498
511
    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
499
512
request_handlers.register_lazy(
 
513
    'BzrDir.open_2.1', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir_2_1')
 
514
request_handlers.register_lazy(
500
515
    'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
501
516
    'SmartServerRequestOpenBranch')
502
517
request_handlers.register_lazy(
544
559
request_handlers.register_lazy(
545
560
    'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')
546
561
request_handlers.register_lazy(
 
562
    'Repository.insert_stream_1.19', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream_1_19')
 
563
request_handlers.register_lazy(
547
564
    'Repository.insert_stream_locked', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStreamLocked')
548
565
request_handlers.register_lazy(
549
566
    'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')
561
578
    'Repository.get_stream', 'bzrlib.smart.repository',
562
579
    'SmartServerRepositoryGetStream')
563
580
request_handlers.register_lazy(
 
581
    'Repository.get_stream_1.19', 'bzrlib.smart.repository',
 
582
    'SmartServerRepositoryGetStream_1_19')
 
583
request_handlers.register_lazy(
564
584
    'Repository.tarball', 'bzrlib.smart.repository',
565
585
    'SmartServerRepositoryTarball')
566
586
request_handlers.register_lazy(