Merge pull request #22 from encukou/ldif-space-fix
Merge upstream fix to #17
This commit is contained in:
commit
1b5f815d36
11
CHANGES
11
CHANGES
|
@ -1,3 +1,12 @@
|
||||||
|
----------------------------------------------------------------
|
||||||
|
Released 2.4.22 2015-10-xx
|
||||||
|
|
||||||
|
Changes since 2.4.21:
|
||||||
|
|
||||||
|
Lib/
|
||||||
|
* LDIFParser now also accepts value-spec without a space
|
||||||
|
after the colon.
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
Released 2.4.21 2015-09-25
|
Released 2.4.21 2015-09-25
|
||||||
|
|
||||||
|
@ -1195,4 +1204,4 @@ Released 2.0.0pre02 2002-02-01
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
Released 1.10alpha3 2000-09-19
|
Released 1.10alpha3 2000-09-19
|
||||||
|
|
||||||
$Id: CHANGES,v 1.356 2015/09/25 16:21:47 stroeder Exp $
|
$Id: CHANGES,v 1.358 2015/09/30 17:17:28 stroeder Exp $
|
||||||
|
|
|
@ -4,13 +4,13 @@ dsml - generate and parse DSMLv1 data
|
||||||
|
|
||||||
See http://www.python-ldap.org/ for details.
|
See http://www.python-ldap.org/ for details.
|
||||||
|
|
||||||
$Id: dsml.py,v 1.38 2015/08/08 13:36:30 stroeder Exp $
|
$Id: dsml.py,v 1.39 2015/09/30 17:15:53 stroeder Exp $
|
||||||
|
|
||||||
Python compability note:
|
Python compability note:
|
||||||
Tested with Python 2.0+.
|
Tested with Python 2.0+.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '2.4.21'
|
__version__ = '2.4.22'
|
||||||
|
|
||||||
import string,base64
|
import string,base64
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ ldap - base module
|
||||||
|
|
||||||
See http://www.python-ldap.org/ for details.
|
See http://www.python-ldap.org/ for details.
|
||||||
|
|
||||||
$Id: __init__.py,v 1.98 2015/08/08 13:36:30 stroeder Exp $
|
$Id: __init__.py,v 1.99 2015/09/30 17:15:53 stroeder Exp $
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# This is also the overall release version number
|
# This is also the overall release version number
|
||||||
|
|
||||||
__version__ = '2.4.21'
|
__version__ = '2.4.22'
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ ldapurl - handling of LDAP URLs as described in RFC 4516
|
||||||
|
|
||||||
See http://www.python-ldap.org/ for details.
|
See http://www.python-ldap.org/ for details.
|
||||||
|
|
||||||
\$Id: ldapurl.py,v 1.73 2015/08/08 13:36:30 stroeder Exp $
|
\$Id: ldapurl.py,v 1.74 2015/09/30 17:15:53 stroeder Exp $
|
||||||
|
|
||||||
Python compability note:
|
Python compability note:
|
||||||
This module only works with Python 2.0+ since
|
This module only works with Python 2.0+ since
|
||||||
|
@ -11,7 +11,7 @@ This module only works with Python 2.0+ since
|
||||||
2. list comprehensions are used.
|
2. list comprehensions are used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '2.4.21'
|
__version__ = '2.4.22'
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# constants
|
# constants
|
||||||
|
|
10
Lib/ldif.py
10
Lib/ldif.py
|
@ -3,13 +3,13 @@ ldif - generate and parse LDIF data (see RFC 2849)
|
||||||
|
|
||||||
See http://www.python-ldap.org/ for details.
|
See http://www.python-ldap.org/ for details.
|
||||||
|
|
||||||
$Id: ldif.py,v 1.83 2015/08/08 13:36:30 stroeder Exp $
|
$Id: ldif.py,v 1.85 2015/09/30 17:17:28 stroeder Exp $
|
||||||
|
|
||||||
Python compability note:
|
Python compability note:
|
||||||
Tested with Python 2.0+, but should work with Python 1.5.2+.
|
Tested with Python 2.0+, but should work with Python 1.5.2+.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = '2.4.21'
|
__version__ = '2.4.22'
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
# constants
|
# constants
|
||||||
|
@ -347,7 +347,7 @@ class LDIFParser:
|
||||||
# if needed attribute value is BASE64 decoded
|
# if needed attribute value is BASE64 decoded
|
||||||
value_spec = unfolded_line[colon_pos:colon_pos+2]
|
value_spec = unfolded_line[colon_pos:colon_pos+2]
|
||||||
if value_spec==': ':
|
if value_spec==': ':
|
||||||
attr_value = unfolded_line[colon_pos+2:]
|
attr_value = unfolded_line[colon_pos+2:].lstrip()
|
||||||
if isinstance(unfolded_line, unicode):
|
if isinstance(unfolded_line, unicode):
|
||||||
attr_value = attr_value.encode('utf-8')
|
attr_value = attr_value.encode('utf-8')
|
||||||
elif value_spec=='::':
|
elif value_spec=='::':
|
||||||
|
@ -364,8 +364,8 @@ class LDIFParser:
|
||||||
u = urlparse(url)
|
u = urlparse(url)
|
||||||
if u[0] in self._process_url_schemes:
|
if u[0] in self._process_url_schemes:
|
||||||
attr_value = urllib.urlopen(url).read()
|
attr_value = urllib.urlopen(url).read()
|
||||||
elif value_spec==':\r\n' or value_spec=='\n':
|
else:
|
||||||
attr_value = b''
|
attr_value = unfolded_line[colon_pos+1:].encode('utf-8')
|
||||||
return attr_type,attr_value
|
return attr_type,attr_value
|
||||||
|
|
||||||
def parse_entry_records(self):
|
def parse_entry_records(self):
|
||||||
|
|
|
@ -15,29 +15,24 @@ except ImportError:
|
||||||
class TestParse(unittest.TestCase):
|
class TestParse(unittest.TestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
||||||
def check_ldif_to_records(self, ldif_string, expected):
|
def _parse_entry_records(self, ldif_string):
|
||||||
#import pdb; pdb.set_trace()
|
return ldif.ParseLDIF(StringIO(ldif_string))
|
||||||
got = ldif.ParseLDIF(StringIO(ldif_string))
|
|
||||||
self.assertEqual(got, expected)
|
|
||||||
|
|
||||||
def check_records_to_ldif(self, records, expected):
|
def _unparse_entry_records(self, records):
|
||||||
f = StringIO()
|
f = StringIO()
|
||||||
ldif_writer = ldif.LDIFWriter(f)
|
ldif_writer = ldif.LDIFWriter(f)
|
||||||
for dn, attrs in records:
|
for dn, attrs in records:
|
||||||
ldif_writer.unparse(dn, attrs)
|
ldif_writer.unparse(dn, attrs)
|
||||||
got = f.getvalue()
|
return f.getvalue()
|
||||||
self.assertEqual(got, expected)
|
|
||||||
|
|
||||||
def check_roundtrip(self, ldif_source, records, ldif_expected=None):
|
def check_roundtrip(self, ldif_source, entry_records):
|
||||||
ldif_source = textwrap.dedent(ldif_source).lstrip() + '\n'
|
ldif_source = textwrap.dedent(ldif_source).lstrip() + '\n'
|
||||||
if ldif_expected is None:
|
parsed_entry_records = self._parse_entry_records(ldif_source)
|
||||||
ldif_expected = ldif_source
|
parsed_entry_records2 = self._parse_entry_records(
|
||||||
else:
|
self._unparse_entry_records(entry_records)
|
||||||
ldif_expected = textwrap.dedent(ldif_expected).lstrip() + '\n'
|
)
|
||||||
|
self.assertEqual(parsed_entry_records, entry_records)
|
||||||
self.check_ldif_to_records(ldif_source, records)
|
self.assertEqual(parsed_entry_records2, entry_records)
|
||||||
self.check_records_to_ldif(records, ldif_expected)
|
|
||||||
self.check_ldif_to_records(ldif_expected, records)
|
|
||||||
|
|
||||||
def test_simple(self):
|
def test_simple(self):
|
||||||
self.check_roundtrip("""
|
self.check_roundtrip("""
|
||||||
|
@ -48,6 +43,15 @@ class TestParse(unittest.TestCase):
|
||||||
('cn=x,cn=y,cn=z', {'attrib': [b'value', b'value2']}),
|
('cn=x,cn=y,cn=z', {'attrib': [b'value', b'value2']}),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_simple2(self):
|
||||||
|
self.check_roundtrip("""
|
||||||
|
dn:cn=x,cn=y,cn=z
|
||||||
|
attrib:value
|
||||||
|
attrib:value2
|
||||||
|
""", [
|
||||||
|
('cn=x,cn=y,cn=z', {'attrib': [b'value', b'value2']}),
|
||||||
|
])
|
||||||
|
|
||||||
def test_multiple(self):
|
def test_multiple(self):
|
||||||
self.check_roundtrip("""
|
self.check_roundtrip("""
|
||||||
dn: cn=x,cn=y,cn=z
|
dn: cn=x,cn=y,cn=z
|
||||||
|
@ -74,12 +78,7 @@ class TestParse(unittest.TestCase):
|
||||||
""" % ('asdf.' * 20), [
|
""" % ('asdf.' * 20), [
|
||||||
('cn=x,cn=y,cn=z', {'attrib': [b'verylong value'],
|
('cn=x,cn=y,cn=z', {'attrib': [b'verylong value'],
|
||||||
'attrib2': [b'asdf.' * 20]}),
|
'attrib2': [b'asdf.' * 20]}),
|
||||||
], """
|
])
|
||||||
dn: cn=x,cn=y,cn=z
|
|
||||||
attrib: verylong value
|
|
||||||
attrib2: asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.asdf.as
|
|
||||||
df.asdf.asdf.asdf.asdf.asdf.asdf.
|
|
||||||
""")
|
|
||||||
|
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
self.check_roundtrip("""
|
self.check_roundtrip("""
|
||||||
|
@ -98,6 +97,14 @@ class TestParse(unittest.TestCase):
|
||||||
('cn=x,cn=y,cn=z', {'attrib': [b'\t\0\n:%@']}),
|
('cn=x,cn=y,cn=z', {'attrib': [b'\t\0\n:%@']}),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_binary2(self):
|
||||||
|
self.check_roundtrip("""
|
||||||
|
dn: cn=x,cn=y,cn=z
|
||||||
|
attrib::CQAKOiVA
|
||||||
|
""", [
|
||||||
|
('cn=x,cn=y,cn=z', {'attrib': [b'\t\0\n:%@']}),
|
||||||
|
])
|
||||||
|
|
||||||
def test_unicode(self):
|
def test_unicode(self):
|
||||||
self.check_roundtrip("""
|
self.check_roundtrip("""
|
||||||
dn: cn=Michael Stroeder,dc=stroeder,dc=com
|
dn: cn=Michael Stroeder,dc=stroeder,dc=com
|
||||||
|
@ -105,10 +112,7 @@ class TestParse(unittest.TestCase):
|
||||||
""", [
|
""", [
|
||||||
('cn=Michael Stroeder,dc=stroeder,dc=com',
|
('cn=Michael Stroeder,dc=stroeder,dc=com',
|
||||||
{'lastname': [b'Str\303\266der']}),
|
{'lastname': [b'Str\303\266der']}),
|
||||||
], """
|
])
|
||||||
dn: cn=Michael Stroeder,dc=stroeder,dc=com
|
|
||||||
lastname:: U3Ryw7ZkZXI=
|
|
||||||
""")
|
|
||||||
|
|
||||||
def test_sorted(self):
|
def test_sorted(self):
|
||||||
self.check_roundtrip("""
|
self.check_roundtrip("""
|
||||||
|
@ -120,12 +124,7 @@ class TestParse(unittest.TestCase):
|
||||||
('cn=x,cn=y,cn=z', {'a': [b'value_a'],
|
('cn=x,cn=y,cn=z', {'a': [b'value_a'],
|
||||||
'b': [b'value_b'],
|
'b': [b'value_b'],
|
||||||
'c': [b'value_c']}),
|
'c': [b'value_c']}),
|
||||||
], """
|
])
|
||||||
dn: cn=x,cn=y,cn=z
|
|
||||||
a: value_a
|
|
||||||
b: value_b
|
|
||||||
c: value_c
|
|
||||||
""")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue