diff --git a/Lib/ldap/asyncsearch.py b/Lib/ldap/asyncsearch.py index 80b5b2a9..f9874d28 100644 --- a/Lib/ldap/asyncsearch.py +++ b/Lib/ldap/asyncsearch.py @@ -51,9 +51,9 @@ def __init__(self,l): def startSearch( self, - searchRoot, - searchScope, - filterStr, + searchRoot=None, + searchScope=None, + filterStr=None, attrList=None, attrsOnly=0, timeout=-1, diff --git a/Lib/ldap/controls/openldap.py b/Lib/ldap/controls/openldap.py index 5da2dd3f..58dafee0 100644 --- a/Lib/ldap/controls/openldap.py +++ b/Lib/ldap/controls/openldap.py @@ -51,7 +51,7 @@ class SearchNoOpMixIn: for easily using the no-op search control. """ - def noop_search_st(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1): + def noop_search_st(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass=*)',timeout=-1): try: msg_id = self.search_ext( base, diff --git a/Lib/ldap/functions.py b/Lib/ldap/functions.py index 6c351eff..afcadd74 100644 --- a/Lib/ldap/functions.py +++ b/Lib/ldap/functions.py @@ -65,10 +65,11 @@ def _ldap_function_call(lock,func,*args,**kwargs): return result -def initialize(uri,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, bytes_mode=None): +def initialize(uri=None,trace_level=0,trace_file=sys.stdout,trace_stack_limit=None, bytes_mode=None): """ Return LDAPObject instance by opening LDAP connection to - LDAP host specified by LDAP URL + LDAP host specified by LDAP URL. If uri is None, use the value + from ldap.conf/.ldaprc. Parameters: uri diff --git a/Lib/ldap/ldapobject.py b/Lib/ldap/ldapobject.py index 36bf034f..7ba29f6d 100644 --- a/Lib/ldap/ldapobject.py +++ b/Lib/ldap/ldapobject.py @@ -92,7 +92,7 @@ class SimpleLDAPObject: } def __init__( - self,uri, + self,uri=None, trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None, bytes_strictness=None, ): @@ -769,13 +769,13 @@ def result4(self,msgid=ldap.RES_ANY,all=1,timeout=None,add_ctrls=0,add_intermedi resp_data = self._bytesify_results(resp_data, with_ctrls=add_ctrls) return resp_type, resp_data, resp_msgid, decoded_resp_ctrls, resp_name, resp_value - def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0): + def search_ext(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0): """ - search(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) -> int - search_s(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]) - search_st(base, scope [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]]) - search_ext(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]) - search_ext_s(base,scope,[,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]) + search([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]]]) -> int + search_s([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0]]]]]) + search_st([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,timeout=-1]]]]]]) + search_ext([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]]]) + search_ext_s([base=None, [scope=ldap.SCOPE_SUBTREE, [,filterstr='(objectClass=*)' [,attrlist=None [,attrsonly=0 [,serverctrls=None [,clientctrls=None [,timeout=-1 [,sizelimit=0]]]]]]]]]) Perform an LDAP search operation, with base as the DN of the entry at which to start the search, scope being one of @@ -841,17 +841,17 @@ def search_ext(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverct timeout,sizelimit, ) - def search_ext_s(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0): + def search_ext_s(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0): msgid = self.search_ext(base,scope,filterstr,attrlist,attrsonly,serverctrls,clientctrls,timeout,sizelimit) return self.result(msgid,all=1,timeout=timeout)[1] - def search(self,base,scope,filterstr=None,attrlist=None,attrsonly=0): + def search(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0): return self.search_ext(base,scope,filterstr,attrlist,attrsonly,None,None) - def search_s(self,base,scope,filterstr=None,attrlist=None,attrsonly=0): + def search_s(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0): return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout) - def search_st(self,base,scope,filterstr=None,attrlist=None,attrsonly=0,timeout=-1): + def search_st(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,timeout=-1): return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout) def start_tls_s(self): @@ -962,7 +962,7 @@ def search_subschemasubentry_s(self,dn=None): except IndexError: return None - def read_s(self,dn,filterstr=None,attrlist=None,serverctrls=None,clientctrls=None,timeout=-1): + def read_s(self,dn=None,filterstr=None,attrlist=None,serverctrls=None,clientctrls=None,timeout=-1): """ Reads and returns a single entry specified by `dn'. @@ -1005,7 +1005,7 @@ def read_subschemasubentry_s(self,subschemasubentry_dn,attrs=None): else: return subschemasubentry - def find_unique_entry(self,base,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1): + def find_unique_entry(self,base=None,scope=ldap.SCOPE_SUBTREE,filterstr=None,attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1): """ Returns a unique entry, raises exception if not unique """ @@ -1077,7 +1077,7 @@ class ReconnectLDAPObject(SimpleLDAPObject): } def __init__( - self,uri, + self,uri=None, trace_level=0,trace_file=None,trace_stack_limit=5,bytes_mode=None, bytes_strictness=None, retry_max=1, retry_delay=60.0 ): diff --git a/Lib/ldap/syncrepl.py b/Lib/ldap/syncrepl.py index 0de5cec4..660d0a30 100644 --- a/Lib/ldap/syncrepl.py +++ b/Lib/ldap/syncrepl.py @@ -349,7 +349,7 @@ class SyncreplConsumer: SyncreplConsumer - LDAP syncrepl consumer object. """ - def syncrepl_search(self, base, scope, mode='refreshOnly', cookie=None, **search_args): + def syncrepl_search(self, base=None, scope=None, mode='refreshOnly', cookie=None, **search_args): """ Starts syncrepl search operation. diff --git a/Modules/LDAPObject.c b/Modules/LDAPObject.c index 2bd6209c..9d33b93d 100644 --- a/Modules/LDAPObject.c +++ b/Modules/LDAPObject.c @@ -1250,7 +1250,7 @@ l_ldap_search_ext(LDAPObject *self, PyObject *args) int msgid; int ldaperror; - if (!PyArg_ParseTuple(args, "sis|OiOOdi:search_ext", + if (!PyArg_ParseTuple(args, "zis|OiOOdi:search_ext", &base, &scope, &filter, &attrlist, &attrsonly, &serverctrls, &clientctrls, &timeout, &sizelimit)) return NULL; diff --git a/Modules/functions.c b/Modules/functions.c index 4731efb8..f7ef446f 100644 --- a/Modules/functions.c +++ b/Modules/functions.c @@ -16,7 +16,7 @@ l_ldap_initialize(PyObject *unused, PyObject *args) LDAP *ld = NULL; int ret; - if (!PyArg_ParseTuple(args, "s:initialize", &uri)) + if (!PyArg_ParseTuple(args, "z:initialize", &uri)) return NULL; Py_BEGIN_ALLOW_THREADS ret = ldap_initialize(&ld, uri); diff --git a/Tests/t_ldapobject.py b/Tests/t_ldapobject.py index 33c2c5a9..b586207c 100644 --- a/Tests/t_ldapobject.py +++ b/Tests/t_ldapobject.py @@ -117,7 +117,7 @@ def test_reject_bytes_base(self): elif sys.version_info >= (3, 5, 0): # Python 3.4.x does not include 'search_ext()' in message self.assertEqual( - "search_ext() argument 1 must be str, not bytes", + "search_ext() argument 1 must be str or None, not bytes", text_type(e.exception) )