~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/smart/request.py

  • Committer: Vincent Ladeuil
  • Date: 2009-04-27 16:10:10 UTC
  • mto: (4310.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4311.
  • Revision ID: v.ladeuil+lp@free.fr-20090427161010-7swfzeagf63cpixd
Fix bug #367726 by reverting some default user handling introduced
while fixing bug #256612.

* bzrlib/transport/ssh.py:
(_paramiko_auth): Explicitly use getpass.getuser() as default
user.

* bzrlib/transport/ftp/_gssapi.py:
(GSSAPIFtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/transport/ftp/__init__.py:
(FtpTransport._create_connection): Explicitly use
getpass.getuser() as default user.

* bzrlib/tests/test_sftp_transport.py:
(TestUsesAuthConfig.test_sftp_is_none_if_no_config)
(TestUsesAuthConfig.test_sftp_doesnt_prompt_username): Revert to
None as the default user.

* bzrlib/tests/test_remote.py:
(TestRemoteSSHTransportAuthentication): The really offending one:
revert to None as the default user.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfig.test_username_default_no_prompt): Update
test (and some PEP8).

* bzrlib/smtp_connection.py:
(SMTPConnection._authenticate): Revert to None as the default
user.

* bzrlib/plugins/launchpad/account.py:
(_get_auth_user): Revert default value handling.

* bzrlib/config.py:
(AuthenticationConfig.get_user): Fix doc-string. Leave default
value handling to callers.

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,
89
86
    # XXX: rename this class to BaseSmartServerRequestHandler ?  A request
90
87
    # *handler* is a different concept to the request.
91
88
 
92
 
    def __init__(self, backing_transport, root_client_path='/', jail_root=None):
 
89
    def __init__(self, backing_transport, root_client_path='/'):
93
90
        """Constructor.
94
91
 
95
92
        :param backing_transport: the base transport to be used when performing
99
96
            from the client.  Clients will not be able to refer to paths above
100
97
            this root.  If root_client_path is None, then no translation will
101
98
            be performed on client paths.  Default is '/'.
102
 
        :param jail_root: if specified, the root of the BzrDir.open jail to use
103
 
            instead of backing_transport.
104
99
        """
105
100
        self._backing_transport = backing_transport
106
 
        if jail_root is None:
107
 
            jail_root = backing_transport
108
 
        self._jail_root = jail_root
109
101
        if root_client_path is not None:
110
102
            if not root_client_path.startswith('/'):
111
103
                root_client_path = '/' + root_client_path
163
155
        return self.do_body(body_bytes)
164
156
 
165
157
    def setup_jail(self):
166
 
        jail_info.transports = [self._jail_root]
 
158
        jail_info.transports = [self._backing_transport]
167
159
 
168
160
    def teardown_jail(self):
169
161
        jail_info.transports = None
191
183
            relpath = urlutils.joinpath('/', path)
192
184
            if not relpath.startswith('/'):
193
185
                raise ValueError(relpath)
194
 
            return urlutils.escape('.' + relpath)
 
186
            return '.' + relpath
195
187
        else:
196
188
            raise errors.PathNotChild(client_path, self._root_client_path)
197
189
 
273
265
    # TODO: Better way of representing the body for commands that take it,
274
266
    # and allow it to be streamed into the server.
275
267
 
276
 
    def __init__(self, backing_transport, commands, root_client_path,
277
 
        jail_root=None):
 
268
    def __init__(self, backing_transport, commands, root_client_path):
278
269
        """Constructor.
279
270
 
280
271
        :param backing_transport: a Transport to handle requests for.
284
275
        self._backing_transport = backing_transport
285
276
        self._root_client_path = root_client_path
286
277
        self._commands = commands
287
 
        if jail_root is None:
288
 
            jail_root = backing_transport
289
 
        self._jail_root = jail_root
290
278
        self.response = None
291
279
        self.finished_reading = False
292
280
        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
281
 
315
282
    def accept_body(self, bytes):
316
283
        """Accept body data."""
317
 
        if self._command is None:
318
 
            # no active command object, so ignore the event.
319
 
            return
320
284
        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
285
 
325
286
    def end_of_body(self):
326
287
        """No more body data will be received."""
327
288
        self._run_handler_code(self._command.do_end, (), {})
328
289
        # cannot read after this.
329
290
        self.finished_reading = True
330
 
        if 'hpss' in debug.debug_flags:
331
 
            self._trace('end of body', '', include_time=True)
 
291
 
 
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, {})
332
300
 
333
301
    def _run_handler_code(self, callable, args, kwargs):
334
302
        """Run some handler specific code 'callable'.
363
331
 
364
332
    def headers_received(self, headers):
365
333
        # Just a no-op at the moment.
366
 
        if 'hpss' in debug.debug_flags:
367
 
            self._trace('headers', repr(headers))
 
334
        pass
368
335
 
369
336
    def args_received(self, args):
370
337
        cmd = args[0]
372
339
        try:
373
340
            command = self._commands.get(cmd)
374
341
        except LookupError:
375
 
            if 'hpss' in debug.debug_flags:
376
 
                self._trace('hpss unknown request', 
377
 
                            cmd, repr(args)[1:-1])
378
342
            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
 
        self._command = command(
388
 
            self._backing_transport, self._root_client_path, self._jail_root)
 
343
        self._command = command(self._backing_transport)
389
344
        self._run_handler_code(self._command.execute, args, {})
390
345
 
391
346
    def end_received(self):
392
 
        if self._command is None:
393
 
            # no active command object, so ignore the event.
394
 
            return
395
347
        self._run_handler_code(self._command.do_end, (), {})
396
 
        if 'hpss' in debug.debug_flags:
397
 
            self._trace('end', '', include_time=True)
398
348
 
399
349
    def post_body_error_received(self, error_args):
400
350
        # Just a no-op at the moment.
408
358
        return ('FileExists', err.path)
409
359
    elif isinstance(err, errors.DirectoryNotEmpty):
410
360
        return ('DirectoryNotEmpty', err.path)
411
 
    elif isinstance(err, errors.IncompatibleRepositories):
412
 
        return ('IncompatibleRepositories', str(err.source), str(err.target),
413
 
            str(err.details))
414
361
    elif isinstance(err, errors.ShortReadvError):
415
362
        return ('ShortReadvError', err.path, str(err.offset), str(err.length),
416
363
                str(err.actual))
445
392
    elif isinstance(err, errors.TokenMismatch):
446
393
        return ('TokenMismatch', err.given_token, err.lock_token)
447
394
    elif isinstance(err, errors.LockContention):
448
 
        return ('LockContention',)
 
395
        return ('LockContention', err.lock, err.msg)
449
396
    # Unserialisable error.  Log it, and return a generic error
450
397
    trace.log_exception_quietly()
451
398
    return ('error', str(err))
498
445
    'Branch.get_tags_bytes', 'bzrlib.smart.branch',
499
446
    'SmartServerBranchGetTagsBytes')
500
447
request_handlers.register_lazy(
501
 
    'Branch.set_tags_bytes', 'bzrlib.smart.branch',
502
 
    'SmartServerBranchSetTagsBytes')
503
 
request_handlers.register_lazy(
504
448
    'Branch.get_stacked_on_url', 'bzrlib.smart.branch', 'SmartServerBranchRequestGetStackedOnURL')
505
449
request_handlers.register_lazy(
506
450
    'Branch.last_revision_info', 'bzrlib.smart.branch', 'SmartServerBranchRequestLastRevisionInfo')
510
454
    'bzrlib.smart.branch', 'SmartServerRequestRevisionHistory')
511
455
request_handlers.register_lazy( 'Branch.set_config_option',
512
456
    'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOption')
513
 
request_handlers.register_lazy( 'Branch.set_config_option_dict',
514
 
    'bzrlib.smart.branch', 'SmartServerBranchRequestSetConfigOptionDict')
515
457
request_handlers.register_lazy( 'Branch.set_last_revision',
516
458
    'bzrlib.smart.branch', 'SmartServerBranchRequestSetLastRevision')
517
459
request_handlers.register_lazy(
550
492
    'BzrDirFormat.initialize', 'bzrlib.smart.bzrdir',
551
493
    'SmartServerRequestInitializeBzrDir')
552
494
request_handlers.register_lazy(
553
 
    'BzrDirFormat.initialize_ex_1.16', 'bzrlib.smart.bzrdir',
 
495
    'BzrDirFormat.initialize_ex', 'bzrlib.smart.bzrdir',
554
496
    'SmartServerRequestBzrDirInitializeEx')
555
497
request_handlers.register_lazy(
556
498
    'BzrDir.open', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir')
557
499
request_handlers.register_lazy(
558
 
    'BzrDir.open_2.1', 'bzrlib.smart.bzrdir', 'SmartServerRequestOpenBzrDir_2_1')
559
 
request_handlers.register_lazy(
560
500
    'BzrDir.open_branch', 'bzrlib.smart.bzrdir',
561
501
    'SmartServerRequestOpenBranch')
562
502
request_handlers.register_lazy(
563
503
    'BzrDir.open_branchV2', 'bzrlib.smart.bzrdir',
564
504
    'SmartServerRequestOpenBranchV2')
565
505
request_handlers.register_lazy(
566
 
    'BzrDir.open_branchV3', 'bzrlib.smart.bzrdir',
567
 
    'SmartServerRequestOpenBranchV3')
568
 
request_handlers.register_lazy(
569
506
    'delete', 'bzrlib.smart.vfs', 'DeleteRequest')
570
507
request_handlers.register_lazy(
571
508
    'get', 'bzrlib.smart.vfs', 'GetRequest')
607
544
request_handlers.register_lazy(
608
545
    'Repository.insert_stream', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream')
609
546
request_handlers.register_lazy(
610
 
    'Repository.insert_stream_1.19', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStream_1_19')
611
 
request_handlers.register_lazy(
612
547
    'Repository.insert_stream_locked', 'bzrlib.smart.repository', 'SmartServerRepositoryInsertStreamLocked')
613
548
request_handlers.register_lazy(
614
549
    'Repository.is_shared', 'bzrlib.smart.repository', 'SmartServerRepositoryIsShared')
620
555
request_handlers.register_lazy(
621
556
    'Repository.unlock', 'bzrlib.smart.repository', 'SmartServerRepositoryUnlock')
622
557
request_handlers.register_lazy(
623
 
    'Repository.get_rev_id_for_revno', 'bzrlib.smart.repository',
624
 
    'SmartServerRepositoryGetRevIdForRevno')
625
 
request_handlers.register_lazy(
626
558
    'Repository.get_stream', 'bzrlib.smart.repository',
627
559
    'SmartServerRepositoryGetStream')
628
560
request_handlers.register_lazy(
629
 
    'Repository.get_stream_1.19', 'bzrlib.smart.repository',
630
 
    'SmartServerRepositoryGetStream_1_19')
631
 
request_handlers.register_lazy(
632
561
    'Repository.tarball', 'bzrlib.smart.repository',
633
562
    'SmartServerRepositoryTarball')
634
563
request_handlers.register_lazy(