@@ -795,7 +795,12 @@ def search_ext(self,base,scope,filterstr='(objectClass=*)',attrlist=None,attrson
795
795
"""
796
796
if PY2 :
797
797
base = self ._bytesify_input ('base' , base )
798
- filterstr = self ._bytesify_input ('filterstr' , filterstr )
798
+ # workaround for default argument,
799
+ # see https://github.com/python-ldap/python-ldap/issues/147
800
+ if self .bytes_mode and filterstr == '(objectClass=*)' :
801
+ filterstr = b'(objectClass=*)'
802
+ else :
803
+ filterstr = self ._bytesify_input ('filterstr' , filterstr )
799
804
if attrlist is not None :
800
805
attrlist = tuple (self ._bytesify_input ('attrlist' , a )
801
806
for a in attrlist )
@@ -885,7 +890,7 @@ def set_option(self,option,invalue):
885
890
invalue = RequestControlTuples (invalue )
886
891
return self ._ldap_call (self ._l .set_option ,option ,invalue )
887
892
888
- def search_subschemasubentry_s (self ,dn = '' ):
893
+ def search_subschemasubentry_s (self ,dn = None ):
889
894
"""
890
895
Returns the distinguished name of the sub schema sub entry
891
896
for a part of a DIT specified by dn.
@@ -895,9 +900,17 @@ def search_subschemasubentry_s(self,dn=''):
895
900
896
901
Returns: None or text/bytes depending on bytes_mode.
897
902
"""
903
+ if self .bytes_mode :
904
+ empty_dn = b''
905
+ attrname = b'subschemaSubentry'
906
+ else :
907
+ empty_dn = u''
908
+ attrname = u'subschemaSubentry'
909
+ if dn is None :
910
+ dn = empty_dn
898
911
try :
899
912
r = self .search_s (
900
- dn ,ldap .SCOPE_BASE ,'(objectClass=*)' ,['subschemaSubentry' ]
913
+ dn ,ldap .SCOPE_BASE ,'(objectClass=*)' ,[attrname ]
901
914
)
902
915
except (ldap .NO_SUCH_OBJECT ,ldap .NO_SUCH_ATTRIBUTE ,ldap .INSUFFICIENT_ACCESS ):
903
916
r = []
@@ -906,11 +919,11 @@ def search_subschemasubentry_s(self,dn=''):
906
919
try :
907
920
if r :
908
921
e = ldap .cidict .cidict (r [0 ][1 ])
909
- search_subschemasubentry_dn = e .get ('subschemaSubentry' ,[None ])[0 ]
922
+ search_subschemasubentry_dn = e .get (attrname ,[None ])[0 ]
910
923
if search_subschemasubentry_dn is None :
911
924
if dn :
912
925
# Try to find sub schema sub entry in root DSE
913
- return self .search_subschemasubentry_s (dn = '' )
926
+ return self .search_subschemasubentry_s (dn = empty_dn )
914
927
else :
915
928
# If dn was already root DSE we can return here
916
929
return None
@@ -945,11 +958,19 @@ def read_subschemasubentry_s(self,subschemasubentry_dn,attrs=None):
945
958
"""
946
959
Returns the sub schema sub entry's data
947
960
"""
961
+ if self .bytes_mode :
962
+ filterstr = b'(objectClass=subschema)'
963
+ if attrs is None :
964
+ attrs = [attr .encode ('utf-8' ) for attr in SCHEMA_ATTRS ]
965
+ else :
966
+ filterstr = u'(objectClass=subschema)'
967
+ if attrs is None :
968
+ attrs = SCHEMA_ATTRS
948
969
try :
949
970
subschemasubentry = self .read_s (
950
971
subschemasubentry_dn ,
951
- filterstr = '(objectClass=subschema)' ,
952
- attrlist = attrs or SCHEMA_ATTRS
972
+ filterstr = filterstr ,
973
+ attrlist = attrs
953
974
)
954
975
except ldap .NO_SUCH_OBJECT :
955
976
return None
@@ -964,7 +985,7 @@ def find_unique_entry(self,base,scope=ldap.SCOPE_SUBTREE,filterstr='(objectClass
964
985
base ,
965
986
scope ,
966
987
filterstr ,
967
- attrlist = attrlist or [ '*' ] ,
988
+ attrlist = attrlist ,
968
989
attrsonly = attrsonly ,
969
990
serverctrls = serverctrls ,
970
991
clientctrls = clientctrls ,
@@ -979,10 +1000,16 @@ def read_rootdse_s(self, filterstr='(objectClass=*)', attrlist=None):
979
1000
"""
980
1001
convenience wrapper around read_s() for reading rootDSE
981
1002
"""
1003
+ if self .bytes_mode :
1004
+ base = b''
1005
+ attrlist = attrlist or [b'*' , b'+' ]
1006
+ else :
1007
+ base = u''
1008
+ attrlist = attrlist or [u'*' , u'+' ]
982
1009
ldap_rootdse = self .read_s (
983
- '' ,
1010
+ base ,
984
1011
filterstr = filterstr ,
985
- attrlist = attrlist or [ '*' , '+' ] ,
1012
+ attrlist = attrlist ,
986
1013
)
987
1014
return ldap_rootdse # read_rootdse_s()
988
1015
@@ -991,9 +1018,13 @@ def get_naming_contexts(self):
991
1018
returns all attribute values of namingContexts in rootDSE
992
1019
if namingContexts is not present (not readable) then empty list is returned
993
1020
"""
1021
+ if self .bytes_mode :
1022
+ name = b'namingContexts'
1023
+ else :
1024
+ name = u'namingContexts'
994
1025
return self .read_rootdse_s (
995
- attrlist = ['namingContexts' ]
996
- ).get ('namingContexts' , [])
1026
+ attrlist = [name ]
1027
+ ).get (name , [])
997
1028
998
1029
999
1030
class ReconnectLDAPObject (SimpleLDAPObject ):
0 commit comments