Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Python 3 (and keep compatibility with Python 2) #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: System :: Systems Administration :: Authentication/Directory',
'Topic :: System :: Systems Administration :: Authentication/Directory :: LDAP',
]

setup(
name="simpleldap",
version="0.8",
version="0.9",
description="A module that makes simple LDAP usage simple.",
long_description=open('README.rst').read(),
keywords="ldap simple simpleldap",
Expand All @@ -27,6 +30,6 @@
url="https://github.com/gdub/python-simpleldap",
license="MIT",
packages=["simpleldap"],
install_requires=["python-ldap"],
tests_require=["tox", "pytest", "pep8", "python-ldap"],
install_requires=["pyldap"],
tests_require=["tox", "pytest", "pep8", "pyldap"],
)
4 changes: 2 additions & 2 deletions simpleldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, result):
self.dn, self.attributes = result
# XXX: quick and dirty, should really proxy straight to the existing
# self.attributes dict.
for attribute, values in self.attributes.iteritems():
for attribute, values in self.attributes.items():
# Make the entire list of values for each LDAP attribute
# accessible through a dictionary mapping.
self[attribute] = values
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, hostname='localhost', port=None, dn='', password='',
else:
self.connection = ldap.initialize(uri)
if options:
for name, value in options.iteritems():
for name, value in options.items():
self.connection.set_option(getattr(ldap, name), value)
if encryption == 'tls':
self.connection.start_tls_s()
Expand Down
2 changes: 1 addition & 1 deletion simpleldap/cidict.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def update(self, dict):
self[key] = dict[key]

def has_key(self, key):
return super(cidict, self).has_key(key.lower())
return super(cidict, self).__contains__(key.lower())

__contains__ = has_key

Expand Down
10 changes: 7 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ def test_connect(self):
conn = simpleldap.Connection(hostname=host, port=port,
encryption=method,
require_cert=cert)
except Exception, e:
except Exception as e:
self.fail("Got error connecting to %s %s %s %s: %s"
% (host, port, method, cert, e))
else:
conn.close()

def test_initialize_kwargs(self):
from StringIO import StringIO
try: # Python 2
from StringIO import StringIO
except ImportError: # Python 3
from io import StringIO

output = StringIO()
initialize_kwargs = {'trace_file': output, 'trace_level': 0}
conn = simpleldap.Connection('ldap.utexas.edu',
Expand Down Expand Up @@ -107,7 +111,7 @@ def test_get(self):
obj = conn.get('cn=External Anonymous',
base_dn='ou=Groups,dc=ucdavis,dc=edu')
self.assertTrue(isinstance(obj, conn.result_item_class))
self.assertEqual(obj['cn'], ['External Anonymous'])
self.assertEqual(obj['cn'], [b'External Anonymous'])

self.assertRaises(simpleldap.ObjectNotFound, conn.get,
'cn=Does not exist',
Expand Down