@@ -294,32 +294,40 @@ def iter_search_result(self, base_dn, scope, filter_string, attributes):
294
294
connection = self .connection
295
295
search_page_size = self .options ['search_page_size' ]
296
296
297
- lc = ldap .controls .libldap .SimplePagedResultsControl (True , size = search_page_size , cookie = '' )
298
-
299
297
msgid = None
300
298
try :
301
- has_next_page = True
302
- while has_next_page :
303
- response_data = None
304
- result_type = None
305
- if msgid is not None :
306
- result_type , response_data , _rmsgid , serverctrls = connection .result3 (msgid )
307
- msgid = None
308
- pctrls = [c for c in serverctrls
309
- if c .controlType == ldap .controls .libldap .SimplePagedResultsControl .controlType ]
310
- if not pctrls :
311
- self .logger .warn ('Server ignored RFC 2696 control.' )
312
- has_next_page = False
313
- else :
314
- lc .cookie = cookie = pctrls [0 ].cookie
315
- if not cookie :
316
- has_next_page = False
317
- if has_next_page :
318
- msgid = connection .search_ext (base_dn , scope ,
319
- filterstr = filter_string , attrlist = attributes , serverctrls = [lc ])
299
+ if search_page_size == 0 :
300
+ msgid = connection .search (base_dn , scope ,
301
+ filterstr = filter_string , attrlist = attributes )
302
+ result_type , response_data , _rmsgid = connection .result2 (msgid )
320
303
if result_type in self .expected_result_types and (response_data is not None ):
321
304
for item in response_data :
322
305
yield item
306
+ else :
307
+ lc = ldap .controls .libldap .SimplePagedResultsControl (True , size = search_page_size , cookie = '' )
308
+
309
+ has_next_page = True
310
+ while has_next_page :
311
+ response_data = None
312
+ result_type = None
313
+ if msgid is not None :
314
+ result_type , response_data , _rmsgid , serverctrls = connection .result3 (msgid )
315
+ msgid = None
316
+ pctrls = [c for c in serverctrls
317
+ if c .controlType == ldap .controls .libldap .SimplePagedResultsControl .controlType ]
318
+ if not pctrls :
319
+ self .logger .warn ('Server ignored RFC 2696 control.' )
320
+ has_next_page = False
321
+ else :
322
+ lc .cookie = cookie = pctrls [0 ].cookie
323
+ if not cookie :
324
+ has_next_page = False
325
+ if has_next_page :
326
+ msgid = connection .search_ext (base_dn , scope ,
327
+ filterstr = filter_string , attrlist = attributes , serverctrls = [lc ])
328
+ if result_type in self .expected_result_types and (response_data is not None ):
329
+ for item in response_data :
330
+ yield item
323
331
except GeneratorExit :
324
332
if msgid is not None :
325
333
connection .abandon (msgid )
0 commit comments