DSML & async.py

Cristian S. Rocha crocha at dc.uba.ar
Thu Nov 27 15:28:00 CET 2003


Hi,

I'm here again. I would like to do more modifications but the async
module will change a lot, before I want to ask you what do you think
about some modifications.

At now the async code is dependent to the format output: exists two
classes to output ldif (ldif.LDIFWriter & ldap.async.LDIFWriter) and
another two for dsml (dsml.DSMLWriter & ldap.async.DSMLWriter). I want
to propose just one class for output (ldap.async.Writer) and other two
for format considerations (dsml.DSMLWriter & ldif.LDIFWriter). That let
you to output both format with less changes on the code. An example
could be:

"""
format = {
	'dsml': dsml.DSMLWriter(sys.stdout),
	'ldif': ldif.LDIFWriter(sys.stdout),
}

def print(host, base, filtre, formatstr):
  s = ldap.async.Writer(
	ldap.initialize(host),
	format[formatstr]
      )

  s.startSearch(
 	base,
 	ldap.SCOPE_SUBTREE,
	filtre
      )
"""

To do it, the classes must share the following interface:

"""
class XWriter:
  def __init__(self, f, ...):
    """
    Init the writer class.
    f
       file object for output.
    """
    ...
    return

  def header(self):
    """
    Return a header string.
    """
    ...
    return ''

  def footer(self):
    """
    Return a footer string.
    """
    ...
    return ''

  def unparse(self, dn, entry):
    """
    Write the entry to the object for output.
    dn
        string-representation of distinguished name
    entry
        dictionary holding the LDAP entry {attr:data}
    """
    ...
    return
"""

I just append these functions (header & footer) to the LDIFWriter and
DSMLWriter classes in "ldif.py" and "dsml.py" files. I append the
async.Writer class to use the interface in the "async.py" file. And I
test the code with the "Test.py" program. All the files are attached on
the mail.

Regards to all,
Cristian.

-- 
Lic. Cristian S. Rocha.
<crocha at dc.uba.ar>
Departamento de Computacin. FCEyN. UBA.
Pabellon I. Cuarto 9.
Ciudad Universitaria.
(1428) Buenos Aires. Argentina.
Tel: +54-11-4576-3390/96 int 714
Tel/Fax: +54-11-4576-3359
Cel: 15-5-607-9192
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.py
Type: text/x-python
Size: 926 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20031127/7773c6db/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dsml.py
Type: text/x-python
Size: 8843 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20031127/7773c6db/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ldif.py
Type: text/x-python
Size: 14805 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20031127/7773c6db/attachment-0002.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: async.py
Type: text/x-python
Size: 8145 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20031127/7773c6db/attachment-0003.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Esta parte del mensaje est? firmada	digitalmente
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20031127/7773c6db/attachment.pgp>


More information about the python-ldap mailing list