From 082e1f3e534621e8f2365674f034aa7f123efd1b Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Wed, 15 Jul 2015 14:18:15 +0200 Subject: [PATCH] Python 3 compatibility after rebase --- Lib/ldap/__init__.py | 2 +- Lib/ldif.py | 8 +++---- Modules/LDAPObject.c | 4 ++-- Modules/common.h | 1 + Modules/ldapcontrol.c | 1 - Tests/Lib/ldap/schema/test_tokenizer.py | 6 +++--- Tests/Lib/ldap/test_modlist.py | 12 +++++------ Tests/Lib/test_ldapurl.py | 28 ++++++++++++------------- Tests/search.py | 4 ++-- Tests/slapd.py | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Lib/ldap/__init__.py b/Lib/ldap/__init__.py index e7b72e7..c6ee9fe 100644 --- a/Lib/ldap/__init__.py +++ b/Lib/ldap/__init__.py @@ -84,7 +84,7 @@ _ldap_module_lock = LDAPLock(desc='Module wide') from ldap.functions import open,initialize,init,get_option,set_option,escape_str -from ldapobject import NO_UNIQUE_ENTRY +from ldap.ldapobject import NO_UNIQUE_ENTRY from ldap.dn import explode_dn,explode_rdn,str2dn,dn2str del str2dn diff --git a/Lib/ldif.py b/Lib/ldif.py index 708c5f0..b22dd3e 100644 --- a/Lib/ldif.py +++ b/Lib/ldif.py @@ -576,7 +576,7 @@ if __name__ == '__main__': parser_method() end_time = time.time() input_file.close() - print '***Time needed:',end_time-start_time,'seconds' - print '***Records read:',ldif_parser.records_read - print '***Lines read:',ldif_parser.line_counter - print '***Bytes read:',ldif_parser.byte_counter,'of',input_file_size + print('***Time needed:',end_time-start_time,'seconds') + print('***Records read:',ldif_parser.records_read) + print('***Lines read:',ldif_parser.line_counter) + print('***Bytes read:',ldif_parser.byte_counter,'of',input_file_size) diff --git a/Modules/LDAPObject.c b/Modules/LDAPObject.c index 72b56ea..db10f40 100644 --- a/Modules/LDAPObject.c +++ b/Modules/LDAPObject.c @@ -664,10 +664,10 @@ l_ldap_sasl_bind_s( LDAPObject* self, PyObject* args ) if (ldaperror == LDAP_SASL_BIND_IN_PROGRESS) { if (servercred && servercred->bv_val && *servercred->bv_val) - return PyString_FromStringAndSize( servercred->bv_val, servercred->bv_len ); + return PyBytes_FromStringAndSize( servercred->bv_val, servercred->bv_len ); } else if (ldaperror != LDAP_SUCCESS) return LDAPerror( self->ldap, "l_ldap_sasl_bind_s" ); - return PyInt_FromLong( ldaperror ); + return PyLong_FromLong( ldaperror ); } static PyObject* diff --git a/Modules/common.h b/Modules/common.h index db0a41c..ceab6bc 100644 --- a/Modules/common.h +++ b/Modules/common.h @@ -40,6 +40,7 @@ void LDAPadd_methods( PyObject*d, PyMethodDef*methods ); #define PyBytes_Check PyString_Check #define PyBytes_Size PyString_Size #define PyBytes_AsString PyString_AsString +#define PyBytes_FromStringAndSize PyString_FromStringAndSize #endif #endif /* __h_common_ */ diff --git a/Modules/ldapcontrol.c b/Modules/ldapcontrol.c index b8a8593..5917b1e 100644 --- a/Modules/ldapcontrol.c +++ b/Modules/ldapcontrol.c @@ -69,7 +69,6 @@ Tuple_to_LDAPControl( PyObject* tup ) char iscritical; struct berval berbytes; PyObject *bytes; - PyObject *bytes_utf8; LDAPControl *lc = NULL; Py_ssize_t len; diff --git a/Tests/Lib/ldap/schema/test_tokenizer.py b/Tests/Lib/ldap/schema/test_tokenizer.py index 8f66f8a..08cd0e0 100644 --- a/Tests/Lib/ldap/schema/test_tokenizer.py +++ b/Tests/Lib/ldap/schema/test_tokenizer.py @@ -25,6 +25,6 @@ testcases_split_tokens = ( for t,r in testcases_split_tokens: l = ldap.schema.tokenizer.split_tokens(t,{'MUST':None}) if l!=r: - print 'String:',repr(t) - print '=>',l - print 'differs from',r + print('String:',repr(t)) + print('=>',l) + print('differs from',r) diff --git a/Tests/Lib/ldap/test_modlist.py b/Tests/Lib/ldap/test_modlist.py index fef0f65..a15cb76 100644 --- a/Tests/Lib/ldap/test_modlist.py +++ b/Tests/Lib/ldap/test_modlist.py @@ -6,7 +6,7 @@ import ldap from ldap.modlist import addModlist,modifyModlist -print '\nTesting function addModlist():' +print('\nTesting function addModlist():') addModlist_tests = [ ( { @@ -31,11 +31,11 @@ for entry,test_modlist in addModlist_tests: result_modlist = addModlist(entry) result_modlist.sort() if test_modlist!=result_modlist: - print 'addModlist(%s) returns\n%s\ninstead of\n%s.' % ( + print('addModlist(%s) returns\n%s\ninstead of\n%s.' % ( repr(entry),repr(result_modlist),repr(test_modlist) - ) + )) -print '\nTesting function modifyModlist():' +print('\nTesting function modifyModlist():') modifyModlist_tests = [ ( @@ -129,9 +129,9 @@ for old_entry,new_entry,case_ignore_attr_types,test_modlist in modifyModlist_tes result_modlist.sort() if test_modlist!=result_modlist: - print 'modifyModlist(%s,%s) returns\n%s\ninstead of\n%s.' % ( + print('modifyModlist(%s,%s) returns\n%s\ninstead of\n%s.' % ( repr(old_entry), repr(new_entry), repr(result_modlist), repr(test_modlist) - ) + )) diff --git a/Tests/Lib/test_ldapurl.py b/Tests/Lib/test_ldapurl.py index 0016683..1685949 100644 --- a/Tests/Lib/test_ldapurl.py +++ b/Tests/Lib/test_ldapurl.py @@ -5,7 +5,7 @@ Performes various tests for module ldapurl import ldapurl from ldapurl import * -print '\nTesting function isLDAPUrl():' +print('\nTesting function isLDAPUrl():') is_ldap_url_tests = { # Examples from RFC2255 'ldap:///o=University%20of%20Michigan,c=US':1, @@ -28,11 +28,11 @@ is_ldap_url_tests = { for ldap_url in is_ldap_url_tests.keys(): result_is_ldap_url = isLDAPUrl(ldap_url) if result_is_ldap_url !=is_ldap_url_tests[ldap_url]: - print 'isLDAPUrl("%s") returns %d instead of %d.' % ( + print('isLDAPUrl("%s") returns %d instead of %d.' % ( repr(ldap_url),result_is_ldap_url,is_ldap_url_tests[ldap_url] - ) + )) -print '\nTesting class LDAPUrl:' +print('\nTesting class LDAPUrl:') parse_ldap_url_tests = [ ( 'ldap://root.openldap.org/dc=openldap,dc=org', @@ -130,25 +130,25 @@ parse_ldap_url_tests = [ for ldap_url_str,test_ldap_url_obj in parse_ldap_url_tests: # print '\nTesting LDAP URL:',repr(ldap_url) ldap_url_obj = LDAPUrl(ldapUrl=ldap_url_str) - print '#'*72 - print test_ldap_url_obj.unparse() + print('#'*72) + print(test_ldap_url_obj.unparse()) if ldap_url_obj.__ne__(test_ldap_url_obj): - print '-'*72 - print 'Parsing error! Attributes of LDAPUrl(%s) are:\n%s\ninstead of:\n%s' % ( + print('-'*72) + print('Parsing error! Attributes of LDAPUrl(%s) are:\n%s\ninstead of:\n%s' % ( repr(ldap_url_str), repr(ldap_url_obj), repr(test_ldap_url_obj) - ) + )) else: - print 'Parsing ok' + print('Parsing ok') unparsed_ldap_url_str = test_ldap_url_obj.unparse() unparsed_ldap_url_obj = LDAPUrl(ldapUrl=unparsed_ldap_url_str) if unparsed_ldap_url_obj.__ne__(test_ldap_url_obj): - print '-'*72 - print 'Unparsing error! Attributes of LDAPUrl(%s) are:\n%s\ninstead of:\n%s' % ( + print('-'*72) + print('Unparsing error! Attributes of LDAPUrl(%s) are:\n%s\ninstead of:\n%s' % ( repr(unparsed_ldap_url_str), repr(unparsed_ldap_url_obj), repr(test_ldap_url_obj) - ) + )) else: - print 'Unparsing ok' + print('Unparsing ok') diff --git a/Tests/search.py b/Tests/search.py index 429a5d6..521e00b 100644 --- a/Tests/search.py +++ b/Tests/search.py @@ -17,7 +17,7 @@ class MyLDAPUrl(LDAPUrl): ldap_url = MyLDAPUrl(sys.argv[1]) trace_level = int(ldap_url.trace_level or '0') -print '***trace_level',trace_level +print('***trace_level',trace_level) ldap.trace_level = trace_level @@ -39,6 +39,6 @@ result = l.search_s( pprint.pprint(result) -print '***DIAGNOSTIC_MESSAGE',repr(l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)) +print('***DIAGNOSTIC_MESSAGE',repr(l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE))) l.unbind_s() diff --git a/Tests/slapd.py b/Tests/slapd.py index 9610771..7bf3158 100644 --- a/Tests/slapd.py +++ b/Tests/slapd.py @@ -377,7 +377,7 @@ if __name__ == '__main__' and sys.argv == ['run']: slapd.start() print("Contents of LDAP server follow:\n") for dn,attrs in slapd.ldapsearch(): - print("dn: " + dn) + print(("dn: " + dn)) for name,val in attrs: print(name + ": " + val) print("")