generate and parse LDIF data (see RFC 2849).
Project description
ldif3 - generate and parse LDIF data (see RFC 2849).
This is a fork of the ldif module from python-ldap with python3/unicode support. See the first entry in CHANGES.rst for a more complete list of differences.
Usage
Parse LDIF from a file (or BytesIO):
from ldif3 import LDIFParser 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) pprint(record)
Write LDIF to a file (or BytesIO):
from ldif3 import LDIFWriter writer = LDIFWriter(open('data.ldif', 'wb')) writer.unparse('mail=alice@example.com', { 'cn': ['Alice Alison'], 'mail': ['alice@example.com'], 'objectclass': ['top', 'person'], })
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ldif3-3.0.0.tar.gz
(5.1 kB
view hashes)