[Python-modules-commits] [ldif3] 01/03: Imported Upstream version 3.1.1

Michael Fladischer fladi at moszumanska.debian.org
Fri Sep 25 15:53:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to annotated tag debian/3.1.1-1
in repository ldif3.

commit ad7e3688b291afeb906423f33e59bdfc9cd1133d
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Fri Sep 25 17:25:15 2015 +0200

    Imported Upstream version 3.1.1
---
 CHANGES.rst |  6 ++++++
 README.rst  | 11 ++++-------
 ldif3.py    | 22 ++++++++++------------
 setup.cfg   |  2 +-
 tests.py    | 24 +++++++++++++++++++++++-
 5 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index b276036..c93b63f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,9 @@
+3.1.1 (2015-09-20)
+------------------
+
+- Allow empty values for attributes.
+
+
 3.1.0 (2015-07-09)
 ------------------
 
diff --git a/README.rst b/README.rst
index 9e12265..6e53e85 100644
--- a/README.rst
+++ b/README.rst
@@ -13,11 +13,8 @@ Parse LDIF from a file (or ``BytesIO``)::
     from pprint import pprint
 
     parser = LDIFParser(open('data.ldif', 'rb'))
-    for dn, changetype, record in parser.parse():
-        if dn is not None:
-            print('got entry record: %s' % dn)
-        else:
-            print('got change record: %s' % changetype)
+    for dn, entry in parser.parse():
+        print('got entry record: %s' % dn)
         pprint(record)
 
 
@@ -38,8 +35,8 @@ Unicode support
 The stream object that is passed to parser or writer must be a byte
 stream. It must use UTF-8 encoding as described in the spec.
 
-The parsed objects (``dn``, ``changetype`` and the keys and values of
-``record``) on the other hand are unicode strings.
+The parsed objects (``dn`` and the keys and values of ``record``) on the
+other hand are unicode strings.
 
 
 .. _RFC 2849: https://tools.ietf.org/html/rfc2849
diff --git a/ldif3.py b/ldif3.py
index 24efd69..1789896 100644
--- a/ldif3.py
+++ b/ldif3.py
@@ -2,7 +2,7 @@
 
 from __future__ import unicode_literals
 
-__version__ = '3.1.0'
+__version__ = '3.1.1'
 
 __all__ = [
     # constants
@@ -81,7 +81,8 @@ class LDIFWriter(object):
         self._base64_attrs = lower(base64_attrs)
         self._cols = cols
         self._line_sep = line_sep
-        self.records_written = 0
+
+        self.records_written = 0  #: number of records that have been written
 
     def _fold_line(self, line):
         """Write string line as one or more folded lines."""
@@ -228,9 +229,9 @@ class LDIFParser(object):
         self._line_sep = line_sep
         self._strict = strict
 
-        self.line_counter = 0
-        self.byte_counter = 0
-        self.records_read = 0
+        self.line_counter = 0  #: number of lines that have been read
+        self.byte_counter = 0  #: number of bytes that have been read
+        self.records_read = 0  #: number of records that have been read
 
     def _iter_unfolded_lines(self):
         """Iter input unfoled lines. Skip comments."""
@@ -268,20 +269,17 @@ class LDIFParser(object):
         """Parse a single attribute type/value pair."""
         colon_pos = line.index(b':')
         attr_type = line[0:colon_pos]
-        value_spec = line[colon_pos:colon_pos + 2]
-        if value_spec == b': ':
-            attr_value = line[colon_pos + 2:].lstrip()
-        elif value_spec == b'::':
+        if line[colon_pos:].startswith(b'::'):
             attr_value = base64.decodestring(line[colon_pos + 2:])
-        elif value_spec == b':<':
+        elif line[colon_pos:].startswith(b':<'):
             url = line[colon_pos + 2:].strip()
             attr_value = b''
             if self._process_url_schemes:
                 u = urlparse(url)
                 if u[0] in self._process_url_schemes:
                     attr_value = urlopen(url.decode('ascii')).read()
-        elif value_spec == b':\r\n' or value_spec == b'\n':
-            attr_value = b''
+        else:
+            attr_value = line[colon_pos + 1:].strip()
         return attr_type.decode('utf8'), attr_value.decode('utf8')
 
     def _error(self, msg):
diff --git a/setup.cfg b/setup.cfg
index 3e99b07..5d32289 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,7 +1,7 @@
 [nosetests]
 all-modules=1
 with-coverage=1
-cover-inclusive=1
+cover-package=ldif3
 cover-erase=1
 cover-branches=1
 cover-html=1
diff --git a/tests.py b/tests.py
index d86159f..acd8198 100644
--- a/tests.py
+++ b/tests.py
@@ -46,6 +46,14 @@ objectclass: person
 
 """
 
+BYTES_EMPTY_ATTR_VALUE = b"""dn: uid=foo123,dc=ws1,dc=webhosting,o=eim
+uid: foo123
+domainname: foo.bar
+homeDirectory: /foo/bar.local
+aliases:
+aliases: foo.bar
+"""
+
 LINES = [
     b'version: 1',
     b'dn: cn=Alice Alison,mail=alicealison at example.com',
@@ -179,7 +187,7 @@ class TestLDIFParser(unittest.TestCase):
         with mock.patch('ldif3.log.warning') as warning:
             self.p._strict = False
             fn()
-            warning.assert_called()
+            assert warning.called
 
     def test_check_dn_not_none(self):
         self._test_error(lambda:
@@ -235,6 +243,20 @@ class TestLDIFParser(unittest.TestCase):
             self.assertEqual(record, RECORDS[i])
 
 
+class TestLDIFParserEmptyAttrValue(unittest.TestCase):
+    def setUp(self):
+        self.stream = BytesIO(BYTES_EMPTY_ATTR_VALUE)
+        self.p = ldif3.LDIFParser(self.stream)
+
+    def test_parse(self):
+        list(self.p.parse())
+
+    def test_parse_value(self):
+        dn, record = list(self.p.parse())[0]
+
+        self.assertEqual(record['aliases'], ['', 'foo.bar'])
+
+
 class TestLDIFWriter(unittest.TestCase):
     def setUp(self):
         self.stream = BytesIO()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/ldif3.git



More information about the Python-modules-commits mailing list