本文整理汇总了Python中ldap.controls.SimplePagedResultsControl.size方法的典型用法代码示例。如果您正苦于以下问题:Python SimplePagedResultsControl.size方法的具体用法?Python SimplePagedResultsControl.size怎么用?Python SimplePagedResultsControl.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ldap.controls.SimplePagedResultsControl
的用法示例。
在下文中一共展示了SimplePagedResultsControl.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _search
# 需要导入模块: from ldap.controls import SimplePagedResultsControl [as 别名]
# 或者: from ldap.controls.SimplePagedResultsControl import size [as 别名]
def _search(self, basedn='', scope=ldap.SCOPE_SUBTREE, filter='', timeout=-1, sizelimit=0):
if not self._handle:
self._open()
result = []
serverctrls = None
clientctrls = None
paged = SimplePagedResultsControl(
criticality=False,
size=self.pagesize,
cookie=''
)
paged_ctrls = {SimplePagedResultsControl.controlType: SimplePagedResultsControl}
page = 0
while True:
serverctrls = [paged]
id = self._handle.search_ext(
basedn,
scope,
filterstr=filter,
attrlist=None,
attrsonly=0,
serverctrls=serverctrls,
clientctrls=clientctrls,
timeout=timeout,
sizelimit=sizelimit
)
(rtype, rdata, rmsgid, serverctrls) = self._handle.result3(
id, resp_ctrl_classes=paged_ctrls
)
result.extend(rdata)
paged.size = 0
paged.cookie = cookie = None
for sc in serverctrls:
if sc.controlType == SimplePagedResultsControl.controlType:
cookie = sc.cookie
if cookie:
paged.cookie = cookie
paged.size = self.pagesize
break
if not cookie:
break
page += 1
return result
示例2: _run_ldap_query
# 需要导入模块: from ldap.controls import SimplePagedResultsControl [as 别名]
# 或者: from ldap.controls.SimplePagedResultsControl import size [as 别名]
def _run_ldap_query(self, query):
self.conn = get_ldap()
lc = SimplePagedResultsControl(size=LDAP_RESULTS_PAGE_SIZE, cookie='')
msgid = self.conn.search_ext(
settings.AUTH_LDAP_USER_SEARCH_BASE,
ldap.SCOPE_SUBTREE,
query,
serverctrls=[lc],
)
page_num = 0
while True:
page_num += 1
r_type, r_data, r_msgid, serverctrls = self.conn.result3(msgid)
print "Pack of %s users loaded (page %s)" % (
LDAP_RESULTS_PAGE_SIZE,
page_num,
)
for item in r_data:
yield item
if serverctrls:
if serverctrls[0].cookie:
lc.size = LDAP_RESULTS_PAGE_SIZE
lc.cookie = serverctrls[0].cookie
msgid = self.conn.search_ext(
settings.AUTH_LDAP_USER_SEARCH_BASE,
ldap.SCOPE_SUBTREE,
query,
serverctrls=[lc],
)
else:
break
else:
logger.error(
'LDAP::_run_ldap_query\tQuery: %s\t'
'Server ignores RFC 2696 control',
)
sys.exit(-1)
self._disconnect()