From 6a4c0adc4837d74755f47eda20aec057f7fe5e7d Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 6 Oct 2015 12:58:14 +0200 Subject: [PATCH 1/5] [Py3] schema: Decode schema elements to str when loading Fixes https://github.com/pyldap/pyldap/issues/11 --- Lib/ldap/schema/models.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/ldap/schema/models.py b/Lib/ldap/schema/models.py index e017041..afab124 100644 --- a/Lib/ldap/schema/models.py +++ b/Lib/ldap/schema/models.py @@ -33,6 +33,7 @@ class SchemaElement: schema_element_str String which contains the schema element description to be parsed. + (Bytestrings are decoded using UTF-8) Class attributes: @@ -47,6 +48,8 @@ class SchemaElement: } def __init__(self,schema_element_str=None): + if sys.version_info >= (3, 0) and isinstance(schema_element_str, bytes): + schema_element_str = schema_element_str.decode('utf-8') if schema_element_str: l = split_tokens(schema_element_str,self.token_defaults) self.set_id(l[1]) From 65f507a5e67d091b65cc31aeb9af770f66fc70dd Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 14 Oct 2015 11:55:23 +0200 Subject: [PATCH 2/5] ldap.schema.models: Add missing import --- Lib/ldap/schema/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/ldap/schema/models.py b/Lib/ldap/schema/models.py index afab124..a141edd 100644 --- a/Lib/ldap/schema/models.py +++ b/Lib/ldap/schema/models.py @@ -6,6 +6,8 @@ See http://www.python-ldap.org/ for details. \$Id: models.py,v 1.48 2015/06/06 09:21:38 stroeder Exp $ """ +import sys + import ldap.cidict from ldap.compat import UserDict From 4f49849035da30a0beb2ff64684bd7f48516d2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 19 Oct 2015 22:51:43 +0200 Subject: [PATCH 3/5] [Py3] Fix derefcontrol for Python3. This fixes invalid calls of print in commit 3a84c23bec0d4db25865dac4463dc4a27d628ddc --- Demo/pyasn1/derefcontrol.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Demo/pyasn1/derefcontrol.py b/Demo/pyasn1/derefcontrol.py index 4ac5155..887ce60 100644 --- a/Demo/pyasn1/derefcontrol.py +++ b/Demo/pyasn1/derefcontrol.py @@ -5,6 +5,7 @@ This sample script demonstrates the use of the dereference control Requires module pyasn1 (see http://pyasn1.sourceforge.net/) """ +from __future__ import print_function import pprint,ldap,ldap.modlist,ldap.resiter @@ -31,8 +32,8 @@ dc = DereferenceControl( } ) -print 'pyasn1 output of request control:' -print dc._derefSpecs().prettyPrint() +print('pyasn1 output of request control:') +print(dc._derefSpecs().prettyPrint()) msg_id = l.search_ext( 'dc=demo1,dc=freeipa,dc=org', @@ -45,6 +46,6 @@ msg_id = l.search_ext( for res_type,res_data,res_msgid,res_controls in l.allresults(msg_id,add_ctrls=1): for dn,entry,deref_control in res_data: # process dn and entry - print dn,entry['objectClass'] + print(dn,entry['objectClass']) if deref_control: pprint.pprint(deref_control[0].derefRes) From 398a8d60e22f88665c5841a6005218ae9962a391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 19 Oct 2015 23:04:24 +0200 Subject: [PATCH 4/5] ldif: Cleanup Py3 compatibility code. - Avoid using outdated type names (unicode) - Reuse compatibility code Conflicts: Lib/ldif.py --- Lib/ldap/compat.py | 3 ++- Lib/ldif.py | 18 ++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Lib/ldap/compat.py b/Lib/ldap/compat.py index 1ee0b86..22e0fd7 100644 --- a/Lib/ldap/compat.py +++ b/Lib/ldap/compat.py @@ -6,6 +6,7 @@ if sys.version_info[0] < 3: from UserDict import UserDict from urllib import quote from urllib import unquote as urllib_unquote + from urlparse import urlparse def unquote(uri): """Specialized unquote that uses UTF-8 for parsing.""" @@ -14,4 +15,4 @@ if sys.version_info[0] < 3: return unquoted.decode('utf-8') else: from collections import UserDict - from urllib.parse import quote, unquote + from urllib.parse import quote, unquote, urlparse diff --git a/Lib/ldif.py b/Lib/ldif.py index 0d0bc6d..8cf6064 100644 --- a/Lib/ldif.py +++ b/Lib/ldif.py @@ -37,13 +37,7 @@ except ImportError: except ImportError: from io import StringIO -try: - from urllib.parse import urlparse -except ImportError: - from urlparse import urlparse - -if sys.version_info > (3, 0): - unicode = str +from ldap.compat import urlparse attrtype_pattern = r'[\w;.-]+(;[\w_-]+)*' attrvalue_pattern = r'(([^,]|\\,)+|".*?")' @@ -155,7 +149,7 @@ class LDIFWriter: """ if self._needs_base64_encoding(attr_type,attr_value): # Encode with base64 - if isinstance(attr_value, unicode): + if not isinstance(attr_value, bytes): attr_value = attr_value.encode('utf-8') encoded = base64.encodestring(attr_value).decode('ascii') encoded = encoded.replace('\n','') @@ -213,7 +207,7 @@ class LDIFWriter: or a list with a modify list like for LDAPObject.modify(). """ # Start with line containing the distinguished name - if isinstance(dn, unicode): + if not isinstance(dn, bytes): dn = dn.encode('utf-8') self._unparseAttrTypeandValue('dn', dn) # Dispatch to record type specific writers @@ -347,13 +341,13 @@ class LDIFParser: # if needed attribute value is BASE64 decoded value_spec = unfolded_line[colon_pos:colon_pos+2] if value_spec==': ': - attr_value = unfolded_line[colon_pos+2:] - if isinstance(unfolded_line, unicode): + attr_value = unfolded_line[colon_pos+2:].lstrip() + if not isinstance(unfolded_line, bytes): attr_value = attr_value.encode('utf-8') elif value_spec=='::': # attribute value needs base64-decoding attr_value = unfolded_line[colon_pos+2:] - if isinstance(attr_value, unicode): + if not isinstance(attr_value, bytes): attr_value = attr_value.encode('ascii') attr_value = base64.decodestring(attr_value) elif value_spec==':<': From bbe4d13c8394a437e5b1dc211bcdedfc51fd9d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 19 Oct 2015 23:17:34 +0200 Subject: [PATCH 5/5] Add pyldap-2.4.21 release --- CHANGES | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index df17338..ad546b5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,5 @@ ---------------------------------------------------------------- -Released 2.4.21 2015-09-25 +Released 2.4.21 2015-09-25 (upstream), 2015-10-19 (pyldap) Changes since 2.4.20: