- commit
- 77e4eb71cc26da0a99d0692ad2056e2980d9e550
- parent
- 100ef7e9d211e7b8189cdbab43980087a61dc0c5
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-05-22 09:58
switch to ldif3
Diffstat
| M | cctool.py | 32 | +++++++++----------------------- |
| M | tests.py | 4 | ++-- |
| M | tox.ini | 1 | + |
3 files changed, 12 insertions, 25 deletions
diff --git a/cctool.py b/cctool.py
@@ -43,7 +43,6 @@ from io import BytesIO 43 43 import argparse 44 44 import codecs 45 45 import json46 -1 import logging as log47 46 import os 48 47 import pickle 49 48 import re @@ -55,9 +54,9 @@ except ImportError: # pragma: nocover 55 54 from configparser import RawConfigParser as ConfigParser 56 55 57 56 try: # pragma: nocover58 -1 import ldif-1 57 import ldif3 59 58 except ImportError as err: # pragma: nocover60 -1 ldif = err-1 59 ldif3 = err 61 60 62 61 try: # pragma: nocover 63 62 import icalendar @@ -98,7 +97,7 @@ def formats(): # pragma: nocover 98 97 if not isinstance(icalendar, Exception): # pragma: nocover 99 98 informats['ics'] = ICal 100 99 outformats['ics'] = ICal101 -1 if not isinstance(ldif, Exception): # pragma: nocover-1 100 if not isinstance(ldif3, Exception): # pragma: nocover 102 101 informats['ldif'] = LDIF 103 102 if not isinstance(yaml, Exception): # pragma: nocover 104 103 informats['yml'] = YAML @@ -386,16 +385,6 @@ class ABook(Format): 386 385 cp.write(_fh) 387 386 388 387389 -1 if not isinstance(ldif, Exception):390 -1 class LDIFParser(ldif.LDIFParser):391 -1 def __init__(self, fh):392 -1 ldif.LDIFParser.__init__(self, fh)393 -1 self.entries = {}394 -1395 -1 def handle(self, dn, entry):396 -1 self.entries[dn] = entry397 -1398 -1399 388 class LDIF(Format): 400 389 fields = { 401 390 'cn': 'name', @@ -404,15 +393,12 @@ class LDIF(Format): 404 393 405 394 @classmethod 406 395 def load(cls, fh):407 -1 if isinstance(ldif, Exception):408 -1 raise ldif409 -1 parser = LDIFParser(fh)410 -1 try:411 -1 parser.parse()412 -1 except ValueError as err:413 -1 log.warning("ValueError after reading %i records: %s",414 -1 parser.records_read, err)415 -1 for entry in parser.entries.values():-1 396 if isinstance(ldif3, Exception): -1 397 raise ldif3 -1 398 -1 399 parser = ldif3.LDIFParser(fh, strict=False) -1 400 -1 401 for dn, changetype, entry in parser.parse(): 416 402 yield map_keys(MultiDict(entry), cls.fields) 417 403 418 404
diff --git a/tests.py b/tests.py
@@ -312,13 +312,13 @@ class TestABook(_TestFormat): 312 312 self.text = b'[0]\nname = foo\nbday = 1970-01-01\n\n' 313 313 314 314315 -1 @unittest.skipIf(isinstance(cctool.ldif, Exception), 'ldif not available')-1 315 @unittest.skipIf(isinstance(cctool.ldif3, Exception), 'ldif3 not available') 316 316 class TestLDIF(_TestFormat): 317 317 def setUp(self): 318 318 self.format = cctool.LDIF() 319 319 self.data = [cctool.MultiDict([320 -1 ('name', ['foo']),321 320 ('email', ['foo@example.com']), -1 321 ('name', ['foo']), 322 322 ])] 323 323 self.text = b'cn: foo\nmail:: Zm9vQGV4YW1wbGUuY29t' 324 324
diff --git a/tox.ini b/tox.ini
@@ -14,5 +14,6 @@ deps = 14 14 nose 15 15 coverage 16 16 flake8 -1 17 ldif3 17 18 icalendar 18 19 PyYAML