Skip to content

Commit

Permalink
ldap.async: avoid using .has_key() and check result types against set…
Browse files Browse the repository at this point in the history
…() instances
  • Loading branch information
stroeder authored and Petr Viktorin committed Nov 22, 2017
1 parent 7791f95 commit 1514852
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions Lib/ldap/async.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@

from ldap import __version__

SEARCH_RESULT_TYPES = set([
ldap.RES_SEARCH_ENTRY,
ldap.RES_SEARCH_RESULT,
ldap.RES_SEARCH_REFERENCE,
])

_searchResultTypes={
ldap.RES_SEARCH_ENTRY:None,
ldap.RES_SEARCH_RESULT:None,
ldap.RES_SEARCH_REFERENCE:None,
}

_entryResultTypes={
ldap.RES_SEARCH_ENTRY:None,
ldap.RES_SEARCH_RESULT:None,
}
ENTRY_RESULT_TYPES = set([
ldap.RES_SEARCH_ENTRY,
ldap.RES_SEARCH_RESULT,
])


class WrongResultType(Exception):
Expand Down Expand Up @@ -137,8 +136,8 @@ def processResults(self,ignoreResultsNumber=0,processResultsCount=0,timeout=-1):
self._afterFirstResult = 0
if not result_list:
break
if not _searchResultTypes.has_key(result_type):
raise WrongResultType(result_type,_searchResultTypes.keys())
if result_type not in SEARCH_RESULT_TYPES:
raise WrongResultType(result_type,SEARCH_RESULT_TYPES)
# Loop over list of search results
for result_item in result_list:
if result_counter<ignoreResultsNumber:
Expand Down Expand Up @@ -197,7 +196,7 @@ def __init__(self,l):
self.allEntries = {}

def _processSingleResult(self,resultType,resultItem):
if _entryResultTypes.has_key(resultType):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self.allEntries[dn] = entry
Expand All @@ -215,12 +214,12 @@ def __init__(self,l,indexed_attrs=None):
self.index = {}.fromkeys(self.indexed_attrs,{})

def _processSingleResult(self,resultType,resultItem):
if _entryResultTypes.has_key(resultType):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self.allEntries[dn] = entry
for a in self.indexed_attrs:
if entry.has_key(a):
if a in entry:
for v in entry[a]:
try:
self.index[a][v].append(dn)
Expand Down Expand Up @@ -281,7 +280,7 @@ def __init__(self,l,writer_obj,headerStr='',footerStr=''):
FileWriter.__init__(self,l,self._ldif_writer._output_file,headerStr,footerStr)

def _processSingleResult(self,resultType,resultItem):
if _entryResultTypes.has_key(resultType):
if resultType in ENTRY_RESULT_TYPES:
# Search continuations are ignored
dn,entry = resultItem
self._ldif_writer.unparse(dn,entry)

0 comments on commit 1514852

Please sign in to comment.