File: ldif.tex

package info (click to toggle)
python-ldap-doc 2.3-1
  • links: PTS
  • area: contrib
  • in suites: lenny
  • size: 200 kB
  • ctags: 121
  • sloc: python: 661; makefile: 44
file content (83 lines) | stat: -rw-r--r-- 2,434 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% $Id: ldif.tex,v 1.8 2006/08/15 11:55:08 stroeder Exp $

% ==== 1. ====
% The section prologue.  Give the section a title and provide some
% meta-information.  References to the module should use
% \refbimodindex, \refstmodindex, \refexmodindex or \refmodindex, as
% appropriate.

\section{\module{ldif} ---
         LDIF parser and generator}

\declaremodule{standard}{ldif}

% Author of the module code;
\moduleauthor{python-ldap developers}{python-ldap-dev@lists.sourceforge.net}
% Author of the documentation,
\sectionauthor{Michael Str\"oder}{michael@stroeder.com}

% Leave at least one blank line after this, to simplify ad-hoc tools
% that are sometimes used to massage these files.
\modulesynopsis{Parses and generates LDIF files}


% ==== 2. ====
% Give a short overview of what the module does.
% If it is platform specific, mention this.
% Mention other important restrictions or general operating principles.

This module parses and generates LDAP data in the format LDIF.

It is implemented in pure Python and does not rely on any
non-standard modules. Therefore it can be used stand-alone without
the rest of the python-ldap package.

\begin{seealso}
\seerfc{2849}{The LDAP Data Interchange Format (LDIF) - Technical Specification}{}
\end{seealso}

\subsection{Example \label{ldif-example}}

The following example demonstrates how to write LDIF output
of an LDAP entry with \module{ldif} module.

\begin{verbatim}
>>> import sys,ldif
>>> entry={'objectClass':['top','person'],'cn':['Michael Stroeder'],'sn':['Stroeder']}
>>> dn='cn=Michael Stroeder,ou=Test'
>>> ldif_writer=ldif.LDIFWriter(sys.stdout)
>>> ldif_writer.unparse(dn,entry)
dn: cn=Michael Stroeder,ou=Test
cn: Michael Stroeder
objectClass: top
objectClass: person
sn: Stroeder

>>> 
\end{verbatim}

The following example demonstrates how to parse an LDIF file
with \module{ldif} module, skip some entries and write the result
to stdout.

\begin{verbatim}
import sys
from ldif import LDIFParser, LDIFWriter

skip_dn = ["uid=foo,ou=People,dc=example,dc=com", 
    "uid=bar,ou=People,dc=example,dc=com"]

class MyLDIF(LDIFParser):
    def __init__(self, input, output):
        LDIFParser.__init__(self, input)
        self.writer = LDIFWriter(output)

    def handle(self, dn, entry):
        for i in skip_dn:
            if i == dn: return
	self.writer.unparse(dn, entry)

parser = MyLDIF(open("input.ldif", 'r'), sys.stdout)
parser.parse()
\end{verbatim}