Rev 1318: Cope with bzr not having username available. in http://people.samba.org/bzr/jelmer/bzr-svn/0.4

Jelmer Vernooij jelmer at samba.org
Mon Jun 23 15:48:55 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-svn/0.4

------------------------------------------------------------
revno: 1318
revision-id: jelmer at samba.org-20080623144846-0t01vdjrsdw66erx
parent: jelmer at samba.org-20080623142601-difooqykfwj3363e
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: 0.4
timestamp: Mon 2008-06-23 16:48:46 +0200
message:
  Cope with bzr not having username available.
modified:
  auth.py                        auth.py-20071209174622-w8d42k6nm5yhxvi8-1
  ra.c                           ra.pyx-20080313140933-qybkqaxe3m4mcll7-1
=== modified file 'auth.py'
--- a/auth.py	2008-06-23 03:59:02 +0000
+++ b/auth.py	2008-06-23 14:48:46 +0000
@@ -52,6 +52,8 @@
         """
         mutter("Obtaining username for SVN connection")
         username = self.get_user(self.scheme, host=self.host, path=self.path, realm=realm)
+        if username is None:
+            return None
         return (username, False)
 
     def get_svn_simple(self, realm, username, may_save):

=== modified file 'ra.c'
--- a/ra.c	2008-06-23 14:16:21 +0000
+++ b/ra.c	2008-06-23 14:48:46 +0000
@@ -1664,18 +1664,38 @@
 static svn_error_t *py_username_prompt(svn_auth_cred_username_t **cred, void *baton, const char *realm, int may_save, apr_pool_t *pool)
 {
     PyObject *fn = (PyObject *)baton, *ret;
+	PyObject *py_username, *py_may_save;
 	ret = PyObject_CallFunction(fn, "sb", realm, may_save);
 	if (ret == NULL)
 		return py_svn_error();
 
+	if (ret == Py_None)
+		return NULL;
+
 	if (!PyTuple_Check(ret)) {
 		PyErr_SetString(PyExc_TypeError, "expected tuple with username credentials");
 		return py_svn_error();
 	}
 
+	if (PyTuple_Size(ret) != 2) {
+		PyErr_SetString(PyExc_TypeError, "expected tuple with username credentials to be size 2");
+		return py_svn_error();
+	}
+
+	py_may_save = PyTuple_GetItem(ret, 1);
+	if (!PyBool_Check(py_may_save)) {
+		PyErr_SetString(PyExc_TypeError, "may_save should be boolean");
+		return py_svn_error();
+	}
+	py_username = PyTuple_GetItem(ret, 0);
+	if (!PyString_Check(py_username)) {
+		PyErr_SetString(PyExc_TypeError, "username hsould be string");
+		return py_svn_error();
+	}
+
 	*cred = apr_pcalloc(pool, sizeof(**cred));
-	(*cred)->username = apr_pstrdup(pool, PyString_AsString(PyTuple_GetItem(ret, 0)));
-	(*cred)->may_save = (PyTuple_GetItem(ret, 1) == Py_True);
+	(*cred)->username = apr_pstrdup(pool, PyString_AsString(py_username));
+	(*cred)->may_save = (py_may_save == Py_True);
     return NULL;
 }
 




More information about the bazaar-commits mailing list