result() timeout

David Leonard david.leonard at itee.uq.edu.au
Tue Nov 13 03:07:35 CET 2001


i am cleaning out some of the diffs in my local tree; and want to know if this
change needs to be committed or something different.

currently when l.result(msgid, all, timeout) is called with a nonzero timeout
and timeout expires, then None is returned rather than the usual
 (res_type, value) tuple.

this change makes result() raise an ldap.TIMEOUT exception instead.
supposedly this makes it easier to write code to handle result timeouts?

old way:
	res = l.result(ldap.RES_ANY, 1, timeout)
	if res is None:
		#-- handle timeout
	else:
		typ,msg = res
		#-- handle message

new way:
	try:
		typ,msg = l.result(ldap.RES_ANY, 1, tiemout)
		#-- handle message
	except ldap.TIMEOUT:
		#-- handle timeout

so... ditch or commit?

The current documentation is totally wrong anyway; it says
	"\tIf a timeout occurs, the tuple (None, None) is returned.";
which is false. In any event it should be fixed.


Index: Modules/LDAPObject.c
===================================================================
RCS file: /cvsroot/python-ldap/python-ldap/Modules/LDAPObject.c,v
retrieving revision 1.14
diff -u -u -r1.14 LDAPObject.c
--- Modules/LDAPObject.c	2001/11/12 14:47:51	1.14
+++ Modules/LDAPObject.c	2001/11/13 02:06:41
@@ -1237,8 +1237,7 @@

     if (res_type == 0) {
 	/* Timeout has occured */
-	Py_INCREF(Py_None);
-    	return Py_None;
+	return PyErr_SetObject(errobjects[LDAP_TIMEOUT], Py_None);
     }

     if (res_type == LDAP_RES_SEARCH_ENTRY
@@ -1321,7 +1320,7 @@
 "\tindefinitely if timeout is negative.  A timeout of 0 will effect\n"
 "\ta poll.  The timeout can be expressed as a floating-point value.\n"
 "\n"
-"\tIf a timeout occurs, the tuple (None, None) is returned.";
+"\tIf a timeout occurs, a TIMEOUT exception is raised.";

 /* ldap_search */

Index: Doc/libldap.tex
===================================================================
RCS file: /cvsroot/python-ldap/python-ldap/Doc/libldap.tex,v
retrieving revision 1.4
diff -u -u -r1.4 libldap.tex
--- Doc/libldap.tex	2001/11/13 01:50:51	1.4
+++ Doc/libldap.tex	2001/11/13 02:06:43
@@ -525,8 +525,7 @@
 the method will wait indefinitely for a response.
 The timeout can be expressed as a floating-point value, and
 a value of \constant{0} effects a poll.
-If a timeout does occur, the tuple \constant{(None,None)} is returned.
-(This should really have been a \exception{TIMEOUT} exception!)
+If a timeout does occur, a \exception{TIMEOUT} exception is raised.

 The \method{result()} method returns a tuple of the form
 \code{(\textit{result-type}, \textit{result-data})}.

-- 
David Leonard                           David.Leonard at itee.uq.edu.au
Dept of Inf. Tech. and Elec. Engg   _   Ph:+61 404 844 850
The University of Queensland       |+|  http://www.itee.uq.edu.au/~leonard/
QLD 4072  AUSTRALIA               ~` '~ B73CD65FBEF4C089B79A8EBADF1A932F13EA0FC8





More information about the python-ldap mailing list