[Python-modules-commits] [ldif3] 01/03: Imported Upstream version 3.1.0
Michael Fladischer
fladi at moszumanska.debian.org
Mon Jul 13 18:54:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository ldif3.
commit f86e5045299e845bf597e4c37e2d3977a9c134c1
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date: Mon Jul 13 20:43:10 2015 +0200
Imported Upstream version 3.1.0
---
CHANGES.rst | 18 ++++++++++++++++++
ldif3.py | 53 +++++++++++++++++++++++++++++++----------------------
tests.py | 3 +--
3 files changed, 50 insertions(+), 24 deletions(-)
diff --git a/CHANGES.rst b/CHANGES.rst
index bd2f171..b276036 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,20 @@
+3.1.0 (2015-07-09)
+------------------
+
+This is mostly a reaction to `python-ldap 2.4.20
+<https://mail.python.org/pipermail/python-ldap/2015q3/003557.html>`_.
+
+- Restore support for ``records_read`` as well as adding ``line_counter`` and
+ ``byte_counter`` that were introduced in python-ldap 2.4.20.
+- Stricter order checking of ``dn:``.
+- Remove partial support for parsing change records. A more complete
+ implementation based on improvements made in python-ldap may be included
+ later. But for now, I don't have the time.
+
+ **Breaking change**: ``LDIFParser.parse()`` now yields ``dn, entry`` rather
+ than ``dn, changetype, entry``.
+
+
3.0.2 (2015-06-22)
------------------
@@ -5,6 +22,7 @@
(Thanks to Michael Fladischer)
- Add LICENSE file
+
3.0.1 (2015-05-22)
------------------
diff --git a/ldif3.py b/ldif3.py
index 6f1b723..24efd69 100644
--- a/ldif3.py
+++ b/ldif3.py
@@ -2,7 +2,7 @@
from __future__ import unicode_literals
-__version__ = '3.0.2'
+__version__ = '3.1.0'
__all__ = [
# constants
@@ -228,10 +228,17 @@ class LDIFParser(object):
self._line_sep = line_sep
self._strict = strict
+ self.line_counter = 0
+ self.byte_counter = 0
+ self.records_read = 0
+
def _iter_unfolded_lines(self):
"""Iter input unfoled lines. Skip comments."""
line = self._input_file.readline()
while line:
+ self.line_counter += 1
+ self.byte_counter += len(line)
+
line = self._strip_line_sep(line)
nextline = self._input_file.readline()
@@ -250,9 +257,11 @@ class LDIFParser(object):
if line:
lines.append(line)
else:
+ self.records_read += 1
yield lines
lines = []
if lines:
+ self.records_read += 1
yield lines
def _parse_attr(self, line):
@@ -260,7 +269,9 @@ class LDIFParser(object):
colon_pos = line.index(b':')
attr_type = line[0:colon_pos]
value_spec = line[colon_pos:colon_pos + 2]
- if value_spec == b'::':
+ if value_spec == b': ':
+ attr_value = line[colon_pos + 2:].lstrip()
+ elif value_spec == b'::':
attr_value = base64.decodestring(line[colon_pos + 2:])
elif value_spec == b':<':
url = line[colon_pos + 2:].strip()
@@ -271,8 +282,6 @@ class LDIFParser(object):
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 + 2:].lstrip()
return attr_type.decode('utf8'), attr_value.decode('utf8')
def _error(self, msg):
@@ -298,10 +307,9 @@ class LDIFParser(object):
if attr_value not in CHANGE_TYPES:
self._error('changetype value %s is invalid.' % attr_value)
- def _parse_record(self, lines):
- """Parse a single record from a list of lines."""
+ def _parse_entry_record(self, lines):
+ """Parse a single entry record from a list of lines."""
dn = None
- changetype = None
entry = OrderedDict()
for line in lines:
@@ -312,23 +320,24 @@ class LDIFParser(object):
dn = attr_value
elif attr_type == 'version' and dn is None:
pass # version = 1
- elif attr_type == 'changetype':
- self._check_changetype(dn, changetype, attr_value)
- changetype = attr_value
- elif attr_value is not None and \
- attr_type.lower() not in self._ignored_attr_types:
- if attr_type in entry:
- entry[attr_type].append(attr_value)
- else:
- entry[attr_type] = [attr_value]
-
- return dn, changetype, entry
+ else:
+ if dn is None:
+ self._error('First line of record does not start '
+ 'with "dn:": %s' % attr_type)
+ if attr_value is not None and \
+ attr_type.lower() not in self._ignored_attr_types:
+ if attr_type in entry:
+ entry[attr_type].append(attr_value)
+ else:
+ entry[attr_type] = [attr_value]
+
+ return dn, entry
def parse(self):
- """Iterate LDIF records.
+ """Iterate LDIF entry records.
- :rtype: Iterator[Tuple[string, string, Dict]]
- :return: (dn, changetype, entry)
+ :rtype: Iterator[Tuple[string, Dict]]
+ :return: (dn, entry)
"""
for block in self._iter_blocks():
- yield self._parse_record(block)
+ yield self._parse_entry_record(block)
diff --git a/tests.py b/tests.py
index 05dd98b..d86159f 100644
--- a/tests.py
+++ b/tests.py
@@ -229,10 +229,9 @@ class TestLDIFParser(unittest.TestCase):
def test_parse(self):
items = list(self.p.parse())
for i, item in enumerate(items):
- dn, changetype, record = item
+ dn, record = item
self.assertEqual(dn, DNS[i])
- self.assertEqual(changetype, CHANGETYPES[i])
self.assertEqual(record, RECORDS[i])
--
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