Skip to content

Commit

Permalink
py3: Use print as a function rather than statement
Browse files Browse the repository at this point in the history
  • Loading branch information
pyldap contributors authored and Petr Viktorin committed Nov 24, 2017
1 parent 83c7235 commit e73f8d8
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 174 deletions.
4 changes: 3 additions & 1 deletion Demo/Lib/ldap/async/deltree.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import ldap,ldap.async

class DeleteLeafs(ldap.async.AsyncSearchHandler):
Expand Down Expand Up @@ -62,7 +64,7 @@ def DelTree(l,dn,scope=ldap.SCOPE_ONELEVEL):
non_leaf_entries = leafs_deleter.nonLeafEntries[:]
while non_leaf_entries:
dn = non_leaf_entries.pop()
print deleted_entries,len(non_leaf_entries),dn
print(deleted_entries,len(non_leaf_entries),dn)
leafs_deleter.startSearch(dn,ldap.SCOPE_SUBTREE)
leafs_deleter.processResults()
deleted_entries = deleted_entries+leafs_deleter.deletedEntries
Expand Down
10 changes: 5 additions & 5 deletions Demo/Lib/ldapurl/urlsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
No output of LDAP data is produced except trace output.
"""

from __future__ import print_function
import sys,getpass,ldap,ldapurl

try:
ldapUrl = ldapurl.LDAPUrl(ldapUrl=sys.argv[1])
except IndexError:
print 'Usage: %s [LDAP URL]' % (sys.argv[0])
print('Usage: %s [LDAP URL]' % (sys.argv[0]))
sys.exit(1)

for a in [
'urlscheme','hostport','dn','attrs','scope',
'filterstr','extensions','who','cred'
]:
print a,repr(getattr(ldapUrl,a))
print(a,repr(getattr(ldapUrl,a)))

l = ldap.initialize(ldapUrl.initializeUrl(),trace_level=1)
if ldapUrl.who!=None:
if ldapUrl.cred!=None:
cred=ldapUrl.cred
else:
print 'Enter password for simple bind with',repr(ldapUrl.who)
print('Enter password for simple bind with',repr(ldapUrl.who))
cred=getpass.getpass()
l.simple_bind_s(ldapUrl.who,cred)

res = l.search_s(ldapUrl.dn,ldapUrl.scope,ldapUrl.filterstr,ldapUrl.attrs)

print len(res),'search results'
print(len(res),'search results')
21 changes: 11 additions & 10 deletions Demo/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ldaps://localhost:1391 (LDAP over SSL)
ldapi://%2ftmp%2fopenldap2 (domain socket /tmp/openldap2)
"""
from __future__ import print_function

import sys,os,ldap

Expand All @@ -23,10 +24,10 @@
# Complete path name of the file containing all trusted CA certs
CACERTFILE='/etc/ssl/ca-bundle.pem'

print """##################################################################
print("""##################################################################
# LDAPv3 connection with StartTLS ext. op.
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldap://localhost:1390',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand All @@ -44,19 +45,19 @@
# Now try StartTLS extended operation
l.start_tls_s()

print '***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION)
print '***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER)
print('***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION))
print('***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER))

# Try an explicit anon bind to provoke failure
l.simple_bind_s('','')

# Close connection
l.unbind_s()

print """##################################################################
print("""##################################################################
# LDAPv3 connection over SSL
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldaps://localhost:1391',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand All @@ -74,16 +75,16 @@
# Try an explicit anon bind to provoke failure
l.simple_bind_s('','')

print '***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION)
print '***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER)
print('***ldap.OPT_X_TLS_VERSION',l.get_option(ldap.OPT_X_TLS_VERSION))
print('***ldap.OPT_X_TLS_CIPHER',l.get_option(ldap.OPT_X_TLS_CIPHER))

# Close connection
l.unbind_s()

print """##################################################################
print("""##################################################################
# LDAPv3 connection over Unix domain socket
##################################################################
"""
""")

# Create LDAPObject instance
l = ldap.initialize('ldapi://%2ftmp%2fopenldap-socket',trace_level=ldapmodule_trace_level,trace_file=ldapmodule_trace_file)
Expand Down
9 changes: 5 additions & 4 deletions Demo/ldapcontrols.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from __future__ import print_function
import ldap,ldapurl,pprint

from ldap.controls import LDAPControl,BooleanControl

l = ldap.initialize('ldap://localhost:1390',trace_level=2)

print 60*'#'
print(60*'#')

pprint.pprint(l.get_option(ldap.OPT_SERVER_CONTROLS))
l.manage_dsa_it(1,1)
pprint.pprint(l.get_option(ldap.OPT_SERVER_CONTROLS))
print 60*'#'
print(60*'#')

# Search with ManageDsaIT control (which has no value)
pprint.pprint(l.search_ext_s(
Expand All @@ -19,7 +20,7 @@
['*','+'],
serverctrls = [ LDAPControl('2.16.840.1.113730.3.4.2',1,None) ],
))
print 60*'#'
print(60*'#')

# Search with Subentries control (which has boolean value)
pprint.pprint(l.search_ext_s(
Expand All @@ -30,4 +31,4 @@
serverctrls = [ BooleanControl('1.3.6.1.4.1.4203.1.10.1',1,1) ],
))

print 60*'#'
print(60*'#')
6 changes: 4 additions & 2 deletions Demo/ldapurl_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import sys,pprint,ldap

from ldap.ldapobject import LDAPObject
Expand All @@ -15,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

Expand All @@ -37,6 +39,6 @@ class MyLDAPUrl(LDAPUrl):

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()
13 changes: 7 additions & 6 deletions Demo/matchedvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
# Matched values control: (mail=*@example.org)
# dn: uid=jsmith,ou=People,dc=example,dc=com
# mail: jsmith@example.org
from __future__ import print_function

import ldap
from ldap.controls import MatchedValuesControl

def print_result(search_result):
for n in range(len(search_result)):
print "dn: %s" % search_result[n][0]
print("dn: %s" % search_result[n][0])
for attr in search_result[n][1].keys():
for i in range(len(search_result[n][1][attr])):
print "%s: %s" % (attr, search_result[n][1][attr][i])
print("%s: %s" % (attr, search_result[n][1][attr][i]))
print


Expand All @@ -51,13 +52,13 @@ def print_result(search_result):
mv = MatchedValuesControl(criticality=True, controlValue=control_filter)

res = ld.search_ext_s(base, scope, filter, attrlist = ['mail'])
print "LDAP filter used: %s" % filter
print "Requesting 'mail' attribute back"
print("LDAP filter used: %s" % filter)
print("Requesting 'mail' attribute back")
print
print "No matched values control:"
print("No matched values control:")
print_result(res)

res = ld.search_ext_s(base, scope, filter, attrlist = ['mail'], serverctrls = [mv])
print "Matched values control: %s" % control_filter
print("Matched values control: %s" % control_filter)
print_result(res)

29 changes: 15 additions & 14 deletions Demo/options.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
from __future__ import print_function

import ldap

host="localhost:1390"

print "API info:",ldap.get_option(ldap.OPT_API_INFO)
print "debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL)
#print "Setting debug level to 255..."
print("API info:",ldap.get_option(ldap.OPT_API_INFO))
print("debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL))
#print("Setting debug level to 255...")
#ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
#print "debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL)
print "default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT)
print "Setting default size limit to 10..."
#print("debug level:",ldap.get_option(ldap.OPT_DEBUG_LEVEL))
print("default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT))
print("Setting default size limit to 10...")
ldap.set_option(ldap.OPT_SIZELIMIT,10)
print "default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT)
print "Creating connection to",host,"..."
print("default size limit:",ldap.get_option(ldap.OPT_SIZELIMIT))
print("Creating connection to",host,"...")
l=ldap.init(host)
print "size limit:",l.get_option(ldap.OPT_SIZELIMIT)
print "Setting connection size limit to 20..."
print("size limit:",l.get_option(ldap.OPT_SIZELIMIT))
print("Setting connection size limit to 20...")
l.set_option(ldap.OPT_SIZELIMIT,20)
print "size limit:",l.get_option(ldap.OPT_SIZELIMIT)
#print "Setting time limit to 60 secs..."
print("size limit:",l.get_option(ldap.OPT_SIZELIMIT))
#print("Setting time limit to 60 secs...")
l.set_option(ldap.OPT_TIMELIMIT,60)
#print "time limit:",l.get_option(ldap.OPT_TIMELIMIT)
print "Binding..."
#print("time limit:",l.get_option(ldap.OPT_TIMELIMIT))
print("Binding...")
l.simple_bind_s("","")


Expand Down
17 changes: 9 additions & 8 deletions Demo/page_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function

url = "ldap://localhost:1390"
base = "dc=stroeder,dc=de"
Expand Down Expand Up @@ -41,20 +42,20 @@
pages = 0
while True:
pages += 1
print '-'*60
print "Getting page %d" % (pages)
print('-'*60)
print("Getting page %d" % (pages))
rtype, rdata, rmsgid, serverctrls = l.result3(msgid,resp_ctrl_classes=known_ldap_resp_ctrls)
print '%d results' % len(rdata)
print 'serverctrls=',pprint.pprint(serverctrls)
print 'rdata=',pprint.pprint(rdata)
print('%d results' % len(rdata))
print('serverctrls=',pprint.pprint(serverctrls))
print('rdata=',pprint.pprint(rdata))
pctrls = [
c
for c in serverctrls
if c.controlType == SimplePagedResultsControl.controlType
]
if pctrls:
print 'pctrls[0].size',repr(pctrls[0].size)
print 'pctrls[0].cookie',repr(pctrls[0].cookie)
print('pctrls[0].size',repr(pctrls[0].size))
print('pctrls[0].cookie',repr(pctrls[0].cookie))
if pctrls[0].cookie:
# Copy cookie from response control to request control
req_ctrl.cookie = pctrls[0].cookie
Expand All @@ -68,7 +69,7 @@
else:
break
else:
print "Warning: Server ignores RFC 2696 control."
print("Warning: Server ignores RFC 2696 control.")
break

l.unbind_s()
3 changes: 2 additions & 1 deletion Demo/paged_search_ext_s.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
url = "ldap://localhost:1390/"
base = "dc=stroeder,dc=de"
search_flt = r'(objectClass=*)'
Expand Down Expand Up @@ -104,4 +105,4 @@ class MyLDAPObject(ReconnectLDAPObject,PagedResultsSearchObject):

l.unbind_s()

print 'Received %d results in %d pages.' % (len(all_results),result_pages)
print('Received %d results in %d pages.' % (len(all_results),result_pages))
5 changes: 3 additions & 2 deletions Demo/passwd_ext_op.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Example showing the use of the password extended operation.
"""
from __future__ import print_function

import sys,ldap,ldapurl,getpass

Expand All @@ -11,9 +12,9 @@

lu = ldapurl.LDAPUrl(sys.argv[1])

print 'Old password'
print('Old password')
oldpw = getpass.getpass()
print 'New password'
print('New password')
newpw = getpass.getpass()

# Set path name of file containing all CA certificates
Expand Down
13 changes: 7 additions & 6 deletions Demo/pyasn1/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pyasn1-modules
python-ldap 2.4+
"""
from __future__ import print_function

from ldap.extop.dds import RefreshRequest,RefreshResponse

Expand All @@ -17,7 +18,7 @@
ldap_url = ldapurl.LDAPUrl(sys.argv[1])
request_ttl = int(sys.argv[2])
except IndexError,ValueError:
print 'Usage: dds.py <LDAP URL> <TTL>'
print('Usage: dds.py <LDAP URL> <TTL>')
sys.exit(1)

# Set debugging level
Expand All @@ -32,24 +33,24 @@
)

if ldap_url.cred is None:
print 'Password for %s:' % (repr(ldap_url.who))
print('Password for %s:' % (repr(ldap_url.who)))
ldap_url.cred = getpass.getpass()

try:
ldap_conn.simple_bind_s(ldap_url.who or '',ldap_url.cred or '')

except ldap.INVALID_CREDENTIALS,e:
print 'Simple bind failed:',str(e)
print('Simple bind failed:',str(e))
sys.exit(1)

else:
extreq = RefreshRequest(entryName=ldap_url.dn,requestTtl=request_ttl)
try:
extop_resp_obj = ldap_conn.extop_s(extreq,extop_resp_class=RefreshResponse)
except ldap.LDAPError,e:
print str(e)
print(str(e))
else:
if extop_resp_obj.responseTtl!=request_ttl:
print 'Different response TTL:',extop_resp_obj.responseTtl
print('Different response TTL:',extop_resp_obj.responseTtl)
else:
print 'Response TTL:',extop_resp_obj.responseTtl
print('Response TTL:',extop_resp_obj.responseTtl)
Loading

0 comments on commit e73f8d8

Please sign in to comment.