Rev 2922: Polishing. in http://code.launchpad.net/%7Ev-ladeuil/bzr/auth.ring

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Oct 23 15:31:25 BST 2007


At http://code.launchpad.net/%7Ev-ladeuil/bzr/auth.ring

------------------------------------------------------------
revno: 2922
revision-id:v.ladeuil+lp at free.fr-20071023143110-xzvdlw5ltdwqlfxj
parent: v.ladeuil+lp at free.fr-20071023125011-xfe73s1iki0wpl2w
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: auth.ring
timestamp: Tue 2007-10-23 16:31:10 +0200
message:
  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.
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/plugins/launchpad/lp_registration.py lp_registration.py-20060315190948-daa617eafe3a8d48
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2007-10-23 10:58:09 +0000
+++ b/bzrlib/config.py	2007-10-23 14:31:10 +0000
@@ -70,8 +70,7 @@
 import errno
 from fnmatch import fnmatch
 import re
-# FIXME: Why not CStringIO ? -- vila 20071019
-from StringIO import StringIO
+from cStringIO import StringIO
 
 import bzrlib
 from bzrlib import (
@@ -961,10 +960,9 @@
         if self._config is not None:
             return self._config
         try:
-            # FIXME: Should we validate something here ? Includes: port must be
-            # numeric, empty sections are useless, verify_certificates is
-            # boolean, at least one of user/password/password_encoding should
-            # be defined, etc.
+            # FIXME: Should we validate something here ? Includes: empty
+            # sections are useless, at least one of
+            # user/password/password_encoding should be defined, etc.
 
             # Note: the encoding below declares that the file itself is utf-8
             # encoded, but the values in the ConfigObj are always Unicode.
@@ -1022,10 +1020,15 @@
                 a_port = auth_def.as_int('port')
             except KeyError:
                 a_port = None
+            except ValueError:
+                raise ValueError("'port' not numeric in %s" % auth_def_name)
             try:
                 a_verify_certificates = auth_def.as_bool('verify_certificates')
             except KeyError:
                 a_verify_certificates = True
+            except ValueError:
+                raise ValueError(
+                    "'verify_certificates' not boolean in %s" % auth_def_name)
 
             # Attempt matching
             if a_scheme is not None and scheme != a_scheme:
@@ -1046,13 +1049,12 @@
             if a_user is None:
                 # Can't find a user
                 continue
-            a_password, a_encoding = map(auth_def.get,
-                                         ['password', 'password_encoding'])
-            password = self.decode_password(a_password, a_encoding)
             credentials = {'name': auth_def_name,
-                           'user': a_user, 'password': password,
+                           'user': a_user, 'password': auth_def['password'],
                            'verify_certificates': a_verify_certificates,
                            }
+            self.decode_password(credentials,
+                                 auth_def.get('password_encoding', None))
             if 'auth' in debug.debug_flags:
                 trace.mutter("Using authentication section: %r", auth_def_name)
             break
@@ -1120,5 +1122,5 @@
                                                   host=prompt_host, user=user)
         return password
 
-    def decode_password(self, password, encoding):
-        return password
+    def decode_password(self, credentials, encoding):
+        return credentials

=== modified file 'bzrlib/plugins/launchpad/lp_registration.py'
--- a/bzrlib/plugins/launchpad/lp_registration.py	2007-10-23 12:50:11 +0000
+++ b/bzrlib/plugins/launchpad/lp_registration.py	2007-10-23 14:31:10 +0000
@@ -24,6 +24,7 @@
 from bzrlib import (
     config,
     errors,
+    __version__ as _bzrlib_version,
     )
 
 # for testing, do
@@ -55,7 +56,7 @@
             else:
                 transport = xmlrpclib.Transport()
             transport.user_agent = 'bzr/%s (xmlrpclib/%s)' \
-                    % (bzrlib.__version__, xmlrpclib.__version__)
+                    % (_bzrlib_version, xmlrpclib.__version__)
         self.transport = transport
 
 

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2007-10-23 08:51:09 +0000
+++ b/bzrlib/tests/test_config.py	2007-10-23 14:31:10 +0000
@@ -1149,6 +1149,13 @@
 verify_certificates=askme # Error: Not a boolean
 """))
         self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
+        conf = config.AuthenticationConfig(_file=StringIO(
+                """[broken]
+scheme=ftp
+user=joe
+port=port # Error: Not an int
+"""))
+        self.assertRaises(ValueError, conf.get_credentials, 'ftp', 'foo.net')
 
     def test_credentials_for_scheme_host(self):
         conf = config.AuthenticationConfig(_file=StringIO(
@@ -1319,7 +1326,8 @@
                                    'ssh', port=12345)
         # SMTP port handling is a bit special (it's handled if embedded in the
         # host too)
-        # FIXME: should we forbid that or extend it to other schemes ?
+        # FIXME: should we: forbid that, extend it to other schemes, leave
+        # things as they are that's fine thank you ?
         self._check_default_prompt('SMTP %(user)s@%(host)s password: ',
                                    'smtp')
         self._check_default_prompt('SMTP %(user)s@%(host)s password: ',



More information about the bazaar-commits mailing list