/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5177.1.1 by Vincent Ladeuil
Manually assign docstrings to command objects, so that they work with python -OO
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
16
5131.2.2 by Martin
Catch a couple of missed plugin module docstrings, note need for assignment to __doc__ in developer documentation and NEWS
17
__doc__ = """Use ~/.netrc as a credential store for authentication.conf."""
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
18
4283.3.1 by Vincent Ladeuil
Make built-in plugins display the same version than bzrlib.
19
# Since we are a built-in plugin we share the bzrlib version
20
from bzrlib import version_info
21
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
22
from bzrlib import (
23
    config,
24
    lazy_import,
25
    )
26
27
lazy_import.lazy_import(globals(), """
28
    import errno
29
    import netrc
30
31
    from bzrlib import (
32
        errors,
33
        )
34
""")
35
36
37
class NetrcCredentialStore(config.CredentialStore):
38
39
    def __init__(self):
40
        super(NetrcCredentialStore, self).__init__()
41
        try:
42
            self._netrc = netrc.netrc()
43
        except IOError, e:
44
            if e.args[0] == errno.ENOENT:
45
                raise errors.NoSuchFile(e.filename)
46
            else:
47
                raise
48
49
    def decode_password(self, credentials):
50
        auth = self._netrc.authenticators(credentials['host'])
51
        password = None
52
        if auth is not None:
53
            user, account, password = auth
54
            cred_user = credentials.get('user', None)
55
            if cred_user is None or user != cred_user:
3757.3.3 by Vincent Ladeuil
Aaron's feedback.
56
                # We don't use the netrc ability to provide a user since there
57
                # is no way to give it back to AuthConfig. So if the user
58
                # doesn't match, we don't return a password.
3757.3.2 by Vincent Ladeuil
Add a credential store for '.netrc'.
59
                password = None
60
        return password
61
62
63
config.credential_store_registry.register_lazy(
64
    'netrc', __name__, 'NetrcCredentialStore', help=__doc__)
65
66
67
def load_tests(basic_tests, module, loader):
68
    testmod_names = [
69
        'tests',
70
        ]
71
    basic_tests.addTest(loader.loadTestsFromModuleNames(
72
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
73
    return basic_tests