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

Add py3 support, now that ldap Python lib supports it #13

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
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'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 @@ -28,5 +30,5 @@
license="MIT",
packages=["simpleldap"],
install_requires=["python-ldap"],
tests_require=["tox", "pytest", "pep8", "python-ldap"],
tests_require=["tox", "pytest", "pycodestye", "python-ldap", "six"],
)
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 key.lower() in super(cidict, self).keys()

__contains__ = has_key

Expand Down
6 changes: 3 additions & 3 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import TestCase

import ldap
from six import StringIO

import simpleldap

Expand All @@ -25,14 +26,13 @@ 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
output = StringIO()
initialize_kwargs = {'trace_file': output, 'trace_level': 0}
conn = simpleldap.Connection('ldap.utexas.edu',
Expand Down Expand Up @@ -107,7 +107,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
13 changes: 6 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[tox]
envlist = py26, py27
indexserver =
pypi = http://pypi.python.org/simple
envlist = py26,py27,py36,py37

[testenv]
deps=
:pypi:python-ldap
:pypi:pytest
:pypi:pep8
python-ldap
pytest<5
pycodestyle
six

commands =
py.test -v tests/tests.py tests/cidict.py
pep8 --ignore=W601 simpleldap
pycodestyle --ignore=W601 simpleldap