Skip to content

Commit

Permalink
Remove Python 2 syntax (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Éloi Rivard authored and GitHub committed Nov 13, 2020
1 parent 4fc9038 commit 3484d57
Show file tree
Hide file tree
Showing 74 changed files with 114 additions and 184 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ PKG-INFO

# generated in the sample workflow
/__venv__/

# test dirs
python-ldap-test-*
2 changes: 0 additions & 2 deletions Demo/Lib/ldap/async/deltree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import ldap,ldap.async

class DeleteLeafs(ldap.async.AsyncSearchHandler):
Expand Down
1 change: 0 additions & 1 deletion Demo/Lib/ldapurl/urlsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
No output of LDAP data is produced except trace output.
"""
from __future__ import print_function
import sys,getpass,ldap,ldapurl

try:
Expand Down
1 change: 0 additions & 1 deletion Demo/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
ldaps://localhost:1391 (LDAP over SSL)
ldapi://%2ftmp%2fopenldap2 (domain socket /tmp/openldap2)
"""
from __future__ import print_function

import sys,os,ldap

Expand Down
1 change: 0 additions & 1 deletion Demo/ldapcontrols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import ldap,ldapurl,pprint

from ldap.controls import LDAPControl,BooleanControl
Expand Down
2 changes: 0 additions & 2 deletions Demo/ldapurl_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import sys,pprint,ldap

from ldap.ldapobject import LDAPObject
Expand Down
3 changes: 1 addition & 2 deletions Demo/matchedvalues.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
# 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
Expand All @@ -37,7 +36,7 @@ def print_result(search_result):
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("{}: {}".format(attr, search_result[n][1][attr][i]))
print


Expand Down
2 changes: 0 additions & 2 deletions Demo/options.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import ldap

host="localhost:1390"
Expand Down
3 changes: 0 additions & 3 deletions Demo/page_control.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import print_function

url = "ldap://localhost:1390"
base = "dc=stroeder,dc=de"
search_flt = r'(objectClass=*)'
Expand Down
1 change: 0 additions & 1 deletion Demo/paged_search_ext_s.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
url = "ldap://localhost:1390/"
base = "dc=stroeder,dc=de"
search_flt = r'(objectClass=*)'
Expand Down
1 change: 0 additions & 1 deletion Demo/passwd_ext_op.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Example showing the use of the password extended operation.
"""
from __future__ import print_function

import sys,ldap,ldapurl,getpass

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/dds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Demo script for Dynamic Entries (see RFC 2589)
Expand All @@ -8,7 +7,6 @@
pyasn1-modules
python-ldap 2.4+
"""
from __future__ import print_function

from ldap.extop.dds import RefreshRequest,RefreshResponse

Expand Down
1 change: 0 additions & 1 deletion Demo/pyasn1/derefcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
This sample script demonstrates the use of the dereference control
(see https://tools.ietf.org/html/draft-masarati-ldap-deref)
"""
from __future__ import print_function

import pprint,ldap,ldap.modlist,ldap.resiter

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/noopsearch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Demo script for counting searching with OpenLDAP's no-op control
Expand All @@ -9,7 +8,6 @@
pyasn1-modules
python-ldap 2.4+
"""
from __future__ import print_function

import sys,ldap,ldapurl,getpass

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/ppolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Demo script for Password Policy Controls
(see https://tools.ietf.org/html/draft-behera-ldap-password-policy)
Expand All @@ -9,7 +8,6 @@
pyasn1-modules
python-ldap 2.4+
"""
from __future__ import print_function

import sys,ldap,ldapurl,getpass

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/psearch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Demo script for Persistent Search Control
(see https://tools.ietf.org/html/draft-ietf-ldapext-psearch)
Expand All @@ -10,7 +9,6 @@
pyasn1-modules
python-ldap 2.4+
"""
from __future__ import print_function

import sys,ldap,ldapurl,getpass

Expand Down
1 change: 0 additions & 1 deletion Demo/pyasn1/readentrycontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Originally contributed by Andreas Hasenack <ahasenack@terra.com.br>
"""
from __future__ import print_function

import pprint,ldap,ldap.modlist

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/sessiontrack.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
demo_track_ldap_session.py
Expand All @@ -8,7 +7,6 @@
https://tools.ietf.org/html/draft-wahl-ldap-session-03
"""

from __future__ import print_function

__version__ = '0.1'

Expand Down
2 changes: 0 additions & 2 deletions Demo/pyasn1/syncrepl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This script implements a syncrepl consumer which syncs data from an OpenLDAP
server to a local (shelve) database.
Expand All @@ -8,7 +7,6 @@
The bound user needs read access to the attributes entryDN and entryCSN.
"""
from __future__ import print_function

# Import modules from Python standard lib
import logging
Expand Down
1 change: 0 additions & 1 deletion Demo/rename.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import ldap
from getpass import getpass

Expand Down
1 change: 0 additions & 1 deletion Demo/resiter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
See https://www.python-ldap.org for details.
"""
from __future__ import print_function

import ldap,ldap.resiter

Expand Down
1 change: 0 additions & 1 deletion Demo/sasl_bind.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# For documentation, see comments in Module/LDAPObject.c and the
# ldap.sasl module documentation.
from __future__ import print_function

import ldap,ldap.sasl

Expand Down
1 change: 0 additions & 1 deletion Demo/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys,ldap,ldap.schema

schema_attrs = ldap.schema.SCHEMA_ATTRS
Expand Down
7 changes: 3 additions & 4 deletions Demo/schema_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Usage: schema_oc_tree.py [--html] [LDAP URL]
"""
from __future__ import print_function

import sys,getopt,ldap,ldap.schema

Expand All @@ -28,10 +27,10 @@ def HTMLSchemaTree(schema,se_class,se_tree,se_oid,level):
se_obj = schema.get_obj(se_class,se_oid)
if se_obj!=None:
print("""
<dt><strong>%s (%s)</strong></dt>
<dt><strong>{} ({})</strong></dt>
<dd>
%s
""" % (', '.join(se_obj.names),se_obj.oid,se_obj.desc))
{}
""".format(', '.join(se_obj.names),se_obj.oid,se_obj.desc))
if se_tree[se_oid]:
print('<dl>')
for sub_se_oid in se_tree[se_oid]:
Expand Down
3 changes: 1 addition & 2 deletions Demo/simple.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import sys,getpass
import ldap

Expand Down Expand Up @@ -86,7 +85,7 @@
("labeleduri", ["labeleduri"]),
("manager", ["cn=Jaga Indulska"]),
("reports", ["reports"]),
("jpegPhoto", [open("/www/leonard/leonard.jpg","r").read()]),
("jpegPhoto", [open("/www/leonard/leonard.jpg").read()]),
("uid", ["leonard"]),
("userPassword", [""])

Expand Down
1 change: 0 additions & 1 deletion Demo/simplebrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#
# simple LDAP server browsing example
#
from __future__ import print_function

import ldap
from traceback import print_exc
Expand Down
1 change: 0 additions & 1 deletion Doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# python-ldap documentation build configuration file, created by
# sphinx-quickstart on Sat Mar 29 15:08:17 2008.
Expand Down
6 changes: 3 additions & 3 deletions Lib/ldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
ImportError(f'ldap {__version__} and _ldap {_ldap.__version__} version mismatch!')
from _ldap import *
# call into libldap to initialize it right now
LIBLDAP_API_INFO = _ldap.get_option(_ldap.OPT_API_INFO)
Expand Down Expand Up @@ -83,14 +83,14 @@ def acquire(self):
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***%s.acquire() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
_trace_file.write('***{}.acquire() {} {}\n'.format(self.__class__.__name__,repr(self),self._desc))
return self._lock.acquire()

def release(self):
if __debug__:
global _trace_level
if _trace_level>=self._min_trace_level:
_trace_file.write('***%s.release() %s %s\n' % (self.__class__.__name__,repr(self),self._desc))
_trace_file.write('***{}.release() {} {}\n'.format(self.__class__.__name__,repr(self),self._desc))
return self._lock.release()


Expand Down
2 changes: 1 addition & 1 deletion Lib/ldap/asyncsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self,receivedResultType,expectedResultTypes):
Exception.__init__(self)

def __str__(self):
return 'Received wrong result type %s (expected one of %s).' % (
return 'Received wrong result type {} (expected one of {}).'.format(
self.receivedResultType,
', '.join(self.expectedResultTypes),
)
Expand Down
11 changes: 5 additions & 6 deletions Lib/ldap/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
# This module cannot import anything from ldap.
# When building documentation, it is used to initialize ldap.__init__.

from __future__ import print_function

class Constant(object):
class Constant:
"""Base class for a definition of an OpenLDAP constant
"""

def __init__(self, name, optional=False, requirements=(), doc=None):
self.name = name
if optional:
self_requirement = 'defined(LDAP_{})'.format(self.name)
self_requirement = f'defined(LDAP_{self.name})'
requirements = list(requirements) + [self_requirement]
self.requirements = requirements
self.doc = self.__doc__ = doc
Expand Down Expand Up @@ -50,7 +49,7 @@ class TLSInt(Int):
def __init__(self, *args, **kwargs):
requrements = list(kwargs.get('requirements', ()))
kwargs['requirements'] = ['HAVE_TLS'] + requrements
super(TLSInt, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class Feature(Constant):
Expand All @@ -70,7 +69,7 @@ class Feature(Constant):


def __init__(self, name, c_feature, **kwargs):
super(Feature, self).__init__(name, **kwargs)
super().__init__(name, **kwargs)
self.c_feature = c_feature


Expand Down Expand Up @@ -392,7 +391,7 @@ def pop_requirement():
if requirement not in current_requirements:
current_requirements.append(requirement)
print()
print('#if {}'.format(requirement))
print(f'#if {requirement}')

print(definition.c_template.format(self=definition))

Expand Down
3 changes: 1 addition & 2 deletions Lib/ldap/controls/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
controls.py - support classes for LDAP controls
Expand All @@ -13,7 +12,7 @@

import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
ImportError(f'ldap {__version__} and _ldap {_ldap.__version__} version mismatch!')

import ldap

Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/deref.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.deref - classes for
(see https://tools.ietf.org/html/draft-masarati-ldap-deref)
Expand Down
3 changes: 1 addition & 2 deletions Lib/ldap/controls/libldap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
controls.libldap - LDAP controls wrapper classes with en-/decoding done
by OpenLDAP functions
Expand All @@ -10,7 +9,7 @@

import _ldap
assert _ldap.__version__==__version__, \
ImportError('ldap %s and _ldap %s version mismatch!' % (__version__,_ldap.__version__))
ImportError(f'ldap {__version__} and _ldap {_ldap.__version__} version mismatch!')

import ldap

Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/openldap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.openldap - classes for OpenLDAP-specific controls
Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/pagedresults.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.paged - classes for Simple Paged control
(see RFC 2696)
Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/ppolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.ppolicy - classes for Password Policy controls
(see https://tools.ietf.org/html/draft-behera-ldap-password-policy)
Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/psearch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.psearch - classes for Persistent Search Control
(see https://tools.ietf.org/html/draft-ietf-ldapext-psearch)
Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/pwdpolicy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.pwdpolicy - classes for Password Policy controls
(see https://tools.ietf.org/html/draft-vchu-ldap-pwd-policy)
Expand Down
1 change: 0 additions & 1 deletion Lib/ldap/controls/readentry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
ldap.controls.readentry - classes for the Read Entry controls
(see RFC 4527)
Expand Down
Loading

0 comments on commit 3484d57

Please sign in to comment.