Re: unicode value

2007-07-20 Thread Alain Spineux

Hi

First I'm not upset by anything.

You are responsible to maintain the package in an healthy state.
This also your responsibility to add or remove some features and then
to maintain them.
Thanks for doing that.

As you have suggested, I made a class wrapper that keep  both code as
independent as possible, and I'm happy with that.

Anyway I'have some comment about your answerer ...

On 7/19/07, Michael Ströder <[EMAIL PROTECTED]> wrote:

Alain,

Alain Spineux wrote:
>
> When investigating about python and unicode, I read somewhere (in a PEP
> I thing) that python functions should accept and manage unicode string
> as well as normal string.

Without knowing the PEP (reference?) I guess this affects functions
which takes a string as an argument and process it directly returning a
result. In context of python-ldap this would be directly applicable to
the functions in modules ldap.dn and ldap.filter.


Unicode string in python are made in a way that let the developer use them
in a complete transparent way. If the libraries are respecting this
principle too,
the developer can exchange data from different sources (user input,
SQL, ldap ...)
without never making any conversion.

The problem is strings are also used for binary storage and LDAP don't
make difference
between both usage (no charset and unicode types like in SQL), only
the developer know
and can make the conversion.



The basic problem here is that for the sake of backward-compability to
LDAPv2 the charset has to be passed around either. That's what I'm doing
in web2ldap.

> Of course if these strings could contains user
> readable characters.

Let's call that "textual strings".

> Anyway I see 2 solutions
>
> 1. Let result() return non unicode strings. _HERE_ The user know all
> returned
> strings are normal strings utf-8 encoded and he can do the encoding
> himself. A helper function doing the job for the result structure
> should be welcome.
>
> 2. Do the conversion regarding the info provided in the query, as my
> source sample does.
>
> I answer now some of your previous comment:
>
>> > In this case maybe is it possible to use [ '*', u'givenName', u'sn' ]
>> > to convert only 'givenName' and 'sn'
>
>> But then you will not gain much! Still the application has to know which
>> attributes have to be converted. => It's not worth hiding the conversion
>> within python-ldap.
>
> I don't really hide the conversion, because the user has to request it using
> unicode field name.

I don't like this approach. The type of the attribute names is causing a
type conversion side-effect. I don't consider this to be good design and
I guess most Python developers would not expect something like this.
Think about an application accidently passing in Unicode strings but is
not really prepared to get the Unicode/string mix.


Today passing unicode argument to ldap functions raise an exception, then
no accidents is possible :-)
On the other side, with unicode support, things could accidentally
work as expected.
But this is only speculation about witch inconvenient is the worst.



> Do you really consider to add the schema processing for unicode
> integration in the future?

Nope. It's up to the application programmer, especially based on whether
LDAPv2 support is still needed for a particular application or not. I
consider python-ldap to be rather a low-level API.

> Keep in mind, none of my code break compatibility with existing application.

Generally I don't want to discourage people to work on something. But
sorry, I won't add your code to python-ldap's Lib/. I hope you're not
upset. My proposal would be to add it under Demo/ so you're work can be
considered to be used by others. Or you can put it on your own web page
(for further development) and I'll put a link to it on
http://python-ldap.sourceforge.net/docs.shtml.


I have no website today :-(
Please use the last version in attachment.

Regards



Ciao, Michael.




--
--
Alain Spineux
aspineux gmail com
May the sources be with you
#!/usr/bin/env python
# 
# This library wrapper bring some Unicode support to python-ldap
#
# This wrapper helped the author to avoid any explicit
# pre and post unicode conversion, this was the goal.
#
# The main idea is that any unicode argument will be encoded 
# using utf-8 encoding before to reach the ldap server.
# On the other side any result will be decoded regarding the 
# tips you have given in the attribute list.
#
# Read the code at the end to have more info about 
# how to use it
#
# written by Alain Spineux 
#
# v0.1.0 Fri Jul 20 14:49:06 CEST 2007


__version__ = '0.1.0'

import types, datetime
import ldap, ldapurl, ldap.modlist

from ldap.ldapobject import LDAPObject
from ldap.ldapobject import ReconnectLDAPObject

def unicode2utf8(st):
"""Convert unicode (and only unicode) string into utf-8 raw string as expected by ldap"""
if isinstance(st, types.UnicodeType):
return st.encode('utf-8')
else:
return st

def utf82unicode(st):
"""e

Re: Experiments with pyasn1 and preread control

2007-07-20 Thread Andreas Hasenack
On Thu, Jul 19, 2007 at 05:03:12PM +0200, Michael Ströder wrote:
> Andreas Hasenack wrote:
> > On Thu, Jul 19, 2007 at 01:21:07PM +0200, Michael Ströder wrote:
> >> Hello Andreas,
> >>
> >> I've added your demo script to python-ldap's CVS as
> >> Demo/pyasn1/prereadcontrol.py. I'd appreciate if you could implement the
> >> decodeControlValue() method with pyasn1.
> > 
> > I think that would be more difficult, there are lots of classes that
> > would need to be created, I guess almost the entire LDAP specification
> > :)
> 
> Hmm...do you really think so?

That was my impression when I first tried it. Since the control result
is exactly like the ldap search result value, it means it can hold a lot
of things.

> > I'll try something with openldap's internal functions, but last time I
> > hit a rock because I needed the connection object to do that, and it
> > wasn't available.
> 
> I'd be interested to implement support for the post-read control in
> web2ldap because if you add/modify entries to OpenLDAP's back-config the
> DNs may be modified (due to X-ORDERED).

Does web2ldap have any special handling of the back-config entries? I
find that using a regular ldap client to handle these entries is
cumbersome (didn't try web2ldap: only lyma and gq so far).


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev


Re: Experiments with pyasn1 and preread control

2007-07-20 Thread Michael Ströder
Andreas Hasenack wrote:
> 
> Does web2ldap have any special handling of the back-config entries?

Not up to now. But using the LDIF and HTML templates pre-configured for
cn=config name space is quite handy. You can contact me off-list if you
need further information on that.

You might find some therein:

  http://www.openldap.org/conf/odd-tuebingen-2006/Michael.pdf

The templates are available in the normal source distribution.

> I find that using a regular ldap client to handle these entries is 
> cumbersome (didn't try web2ldap: only lyma and gq so far).

In web2ldap the DN handling after add/modify is somewhat strange if the
DN is changed by X-ORDERED handling. I presented this at ODD 2006. Kurt
et al suggested to use post-read control.

Ciao, Michael.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Python-LDAP-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/python-ldap-dev