Skip to content
Snippets Groups Projects
Commit 21e577ba authored by Alexandre Ferland's avatar Alexandre Ferland
Browse files

add python3 support

parent 866bd81a
Branches
Tags
No related merge requests found
language: python language: python
python: python:
- "2.6"
- "2.7" - "2.7"
- "3.4"
- "3.5"
env: env:
- FLASK=0.11
- FLASK=0.10.1 - FLASK=0.10.1
- FLASK=0.9 - FLASK=0.9
install: install:
......
...@@ -13,15 +13,15 @@ First, install Flask-SimpleLDAP: ...@@ -13,15 +13,15 @@ First, install Flask-SimpleLDAP:
$ pip install flask-simpleldap $ pip install flask-simpleldap
Flask-SimpleLDAP depends, and will install for you, recent versions of Flask Flask-SimpleLDAP depends, and will install for you, recent versions of Flask
(0.9 or later) and python-ldap. Flask-SimpleLDAP is compatible (0.9 or later) and [pyldap](https://github.com/pyldap/pyldap). Flask-SimpleLDAP is compatible
with and tested on Python 2.6 and 2.7. with and tested on Python 2.7, 3.4 and 3.5.
Next, add a ``LDAP`` instance to your code and at least the three Next, add a ``LDAP`` instance to your code and at least the three
required configuration options: required configuration options:
```python ```python
from flask import Flask from flask import Flask
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
ldap = LDAP(app) ldap = LDAP(app)
...@@ -46,7 +46,7 @@ and [blueprints](http://flask.pocoo.org/docs/blueprints/). ...@@ -46,7 +46,7 @@ and [blueprints](http://flask.pocoo.org/docs/blueprints/).
OpenLDAP OpenLDAP
---------- --------
Add the ``LDAP`` instance to your code and depending on your OpenLDAP Add the ``LDAP`` instance to your code and depending on your OpenLDAP
configuration, add the following at least LDAP_USER_OBJECT_FILTER and configuration, add the following at least LDAP_USER_OBJECT_FILTER and
...@@ -54,7 +54,7 @@ LDAP_USER_OBJECT_FILTER. ...@@ -54,7 +54,7 @@ LDAP_USER_OBJECT_FILTER.
```python ```python
from flask import Flask from flask import Flask
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
ldap = LDAP(app) ldap = LDAP(app)
...@@ -84,6 +84,14 @@ def ldap_protected(): ...@@ -84,6 +84,14 @@ def ldap_protected():
``` ```
Migrating from 0.x to 1.x
-------------------------
The only major change from 0.x releases and 1.x is the underlying LDAP library changed from python-ldap to
[pyldap](https://github.com/pyldap/pyldap) which is fork that adds Python 3.x support. Everything else SHOULD
be the same, but don't hesitate to open an issue if encounter some problem upgrading from 0.x to 1.x.
Resources Resources
--------- ---------
......
python-ldap==2.4.20 pyldap==2.4.25.1
...@@ -56,16 +56,16 @@ master_doc = 'index' ...@@ -56,16 +56,16 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'Flask-SimpleLDAP' project = u'Flask-SimpleLDAP'
copyright = u'2015, Alexandre Ferland' copyright = u'2016, Alexandre Ferland'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '0.4.0' version = '1.0.0'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = '0.4.0' release = '1.0.0'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
......
...@@ -19,8 +19,8 @@ First, install Flask-SimpleLDAP: ...@@ -19,8 +19,8 @@ First, install Flask-SimpleLDAP:
$ pip install flask-simpleldap $ pip install flask-simpleldap
Flask-SimpleLDAP depends, and will install for you, recent versions of Flask Flask-SimpleLDAP depends, and will install for you, recent versions of Flask
(0.9 or later) and python-ldap. Flask-SimpleLDAP is compatible (0.9 or later) and pyldap. Flask-SimpleLDAP is compatible
with and tested on Python 2.6 and 2.7. with and tested on Python 2.7, 3.4 and 3.5.
Next, add a :class:`~flask_simpleldap.LDAP` to your code and at least the three Next, add a :class:`~flask_simpleldap.LDAP` to your code and at least the three
required configuration options: required configuration options:
...@@ -28,7 +28,7 @@ required configuration options: ...@@ -28,7 +28,7 @@ required configuration options:
.. code-block:: python .. code-block:: python
from flask import Flask from flask import Flask
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
ldap = LDAP(app) ldap = LDAP(app)
...@@ -114,6 +114,10 @@ History ...@@ -114,6 +114,10 @@ History
Changes: Changes:
- 1.0.0 June 4, 2016
- Python 3.x support. Switched from python-ldap to pyldap which is a fork with Python 3.x support.
- 0.4.0: September 5, 2015 - 0.4.0: September 5, 2015
- Added support for OpenLDAP directories. Thanks to `@jm66 <https://github.com/jm66>`_ on GitHub. - Added support for OpenLDAP directories. Thanks to `@jm66 <https://github.com/jm66>`_ on GitHub.
......
from flask import Flask, g, request, session, redirect, url_for from flask import Flask, g, request, session, redirect, url_for
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'dev key' app.secret_key = 'dev key'
......
from flask import Flask, g, request, session, redirect, url_for from flask import Flask, g, request, session, redirect, url_for
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'dev key' app.secret_key = 'dev key'
......
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
ldap = LDAP() ldap = LDAP()
from flask import Flask, g, request, session, redirect, url_for from flask import Flask, g, request, session, redirect, url_for
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'dev key' app.secret_key = 'dev key'
......
from flask import Flask, g, request, session, redirect, url_for from flask import Flask, g, request, session, redirect, url_for
from flask.ext.simpleldap import LDAP from flask_simpleldap import LDAP
app = Flask(__name__) app = Flask(__name__)
app.secret_key = 'dev key' app.secret_key = 'dev key'
......
...@@ -23,9 +23,6 @@ class LDAPException(RuntimeError): ...@@ -23,9 +23,6 @@ class LDAPException(RuntimeError):
def __str__(self): def __str__(self):
return self.message return self.message
def __unicode__(self):
return self.message
class LDAP(object): class LDAP(object):
def __init__(self, app=None): def __init__(self, app=None):
...@@ -115,8 +112,8 @@ class LDAP(object): ...@@ -115,8 +112,8 @@ class LDAP(object):
conn = self.initialize conn = self.initialize
try: try:
conn.simple_bind_s( conn.simple_bind_s(
current_app.config['LDAP_USERNAME'].encode('utf-8'), current_app.config['LDAP_USERNAME'],
current_app.config['LDAP_PASSWORD'].encode('utf-8')) current_app.config['LDAP_PASSWORD'])
return conn return conn
except ldap.LDAPError as e: except ldap.LDAPError as e:
raise LDAPException(self.error(e)) raise LDAPException(self.error(e))
...@@ -147,7 +144,7 @@ class LDAP(object): ...@@ -147,7 +144,7 @@ class LDAP(object):
return return
try: try:
conn = self.initialize conn = self.initialize
conn.simple_bind_s(user_dn, password) conn.simple_bind_s(user_dn.decode('utf-8'), password)
return True return True
except ldap.LDAPError: except ldap.LDAPError:
return return
...@@ -191,7 +188,7 @@ class LDAP(object): ...@@ -191,7 +188,7 @@ class LDAP(object):
dn = records[0][1][ dn = records[0][1][
current_app.config['LDAP_OBJECTS_DN']] current_app.config['LDAP_OBJECTS_DN']]
return dn[0] return dn[0]
for k, v in records[0][1].items(): for k, v in list(records[0][1].items()):
result[k] = v result[k] = v
return result return result
except ldap.LDAPError as e: except ldap.LDAPError as e:
...@@ -236,7 +233,7 @@ class LDAP(object): ...@@ -236,7 +233,7 @@ class LDAP(object):
records[0][1]: records[0][1]:
groups = records[0][1][ groups = records[0][1][
current_app.config['LDAP_USER_GROUPS_FIELD']] current_app.config['LDAP_USER_GROUPS_FIELD']]
result = [re.findall('(?:cn=|CN=)(.*?),', group)[0] for result = [re.findall(b'(?:cn=|CN=)(.*?),', group)[0] for
group in groups] group in groups]
return result return result
except ldap.LDAPError as e: except ldap.LDAPError as e:
...@@ -268,10 +265,11 @@ class LDAP(object): ...@@ -268,10 +265,11 @@ class LDAP(object):
@staticmethod @staticmethod
def error(e): def error(e):
if 'desc' in dict(e.message): e = e.args[0]
return dict(e.message)['desc'] if 'desc' in e:
return e['desc']
else: else:
return e[1] return e[0]
@staticmethod @staticmethod
def login_required(func): def login_required(func):
......
Flask==0.10.1 Flask==0.11
mock==1.3.0 mock==2.0.0
...@@ -9,7 +9,7 @@ from setuptools import setup ...@@ -9,7 +9,7 @@ from setuptools import setup
setup( setup(
name='Flask-SimpleLDAP', name='Flask-SimpleLDAP',
version='0.4.0', version='1.0.0',
url='https://github.com/admiralobvious/flask-simpleldap', url='https://github.com/admiralobvious/flask-simpleldap',
license='MIT', license='MIT',
author='Alexandre Ferland', author='Alexandre Ferland',
...@@ -21,16 +21,17 @@ setup( ...@@ -21,16 +21,17 @@ setup(
include_package_data=True, include_package_data=True,
platforms='any', platforms='any',
install_requires=[ install_requires=[
'Flask>=0.9', 'Flask>=0.10',
'python-ldap' 'pyldap'
], ],
classifiers=[ classifiers=[
'Environment :: Web Environment', 'Environment :: Web Environment',
'Intended Audience :: Developers', 'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License', 'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent', 'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Software Development :: Libraries :: Python Modules' 'Topic :: Software Development :: Libraries :: Python Modules'
] ]
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment