~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-23 14:31:10 UTC
  • mto: (2961.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 2962.
  • Revision ID: v.ladeuil+lp@free.fr-20071023143110-xzvdlw5ltdwqlfxj
Polishing.

* bzrlib/config.py: 
Use cStringIO instead of StringIO.

* bzrlib/tests/test_config.py:
(TestAuthenticationConfigFile.test_broken_config): Add one more test.

* bzrlib/plugins/launchpad/lp_registration.py: 
Fix import again.

* bzrlib/config.py:
(AuthenticationConfig.get_credentials): Slightly rework ValueError
exceptions.
(AuthenticationConfig.decode_password): Change signature, it will
be needed anyway in the short future.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
import errno
71
71
from fnmatch import fnmatch
72
72
import re
73
 
# FIXME: Why not CStringIO ? -- vila 20071019
74
 
from StringIO import StringIO
 
73
from cStringIO import StringIO
75
74
 
76
75
import bzrlib
77
76
from bzrlib import (
961
960
        if self._config is not None:
962
961
            return self._config
963
962
        try:
964
 
            # FIXME: Should we validate something here ? Includes: port must be
965
 
            # numeric, empty sections are useless, verify_certificates is
966
 
            # boolean, at least one of user/password/password_encoding should
967
 
            # be defined, etc.
 
963
            # FIXME: Should we validate something here ? Includes: empty
 
964
            # sections are useless, at least one of
 
965
            # user/password/password_encoding should be defined, etc.
968
966
 
969
967
            # Note: the encoding below declares that the file itself is utf-8
970
968
            # encoded, but the values in the ConfigObj are always Unicode.
1022
1020
                a_port = auth_def.as_int('port')
1023
1021
            except KeyError:
1024
1022
                a_port = None
 
1023
            except ValueError:
 
1024
                raise ValueError("'port' not numeric in %s" % auth_def_name)
1025
1025
            try:
1026
1026
                a_verify_certificates = auth_def.as_bool('verify_certificates')
1027
1027
            except KeyError:
1028
1028
                a_verify_certificates = True
 
1029
            except ValueError:
 
1030
                raise ValueError(
 
1031
                    "'verify_certificates' not boolean in %s" % auth_def_name)
1029
1032
 
1030
1033
            # Attempt matching
1031
1034
            if a_scheme is not None and scheme != a_scheme:
1046
1049
            if a_user is None:
1047
1050
                # Can't find a user
1048
1051
                continue
1049
 
            a_password, a_encoding = map(auth_def.get,
1050
 
                                         ['password', 'password_encoding'])
1051
 
            password = self.decode_password(a_password, a_encoding)
1052
1052
            credentials = {'name': auth_def_name,
1053
 
                           'user': a_user, 'password': password,
 
1053
                           'user': a_user, 'password': auth_def['password'],
1054
1054
                           'verify_certificates': a_verify_certificates,
1055
1055
                           }
 
1056
            self.decode_password(credentials,
 
1057
                                 auth_def.get('password_encoding', None))
1056
1058
            if 'auth' in debug.debug_flags:
1057
1059
                trace.mutter("Using authentication section: %r", auth_def_name)
1058
1060
            break
1120
1122
                                                  host=prompt_host, user=user)
1121
1123
        return password
1122
1124
 
1123
 
    def decode_password(self, password, encoding):
1124
 
        return password
 
1125
    def decode_password(self, credentials, encoding):
 
1126
        return credentials