unicode value
Alain Spineux
aspineux at gmail.com
Thu May 24 15:32:10 CEST 2007
On 5/24/07, Michael Ströder <michael at stroeder.com> wrote:
>
> Alain Spineux wrote:
> >
> > On 5/24/07, Michael Ströder <michael at stroeder.com> wrote:
> >>
>
> And how about specials like '*' and '+' in attrlist?
Thanks for showing me my ignorance. I was not knowing about * and + !
Easy, only named attributes will be converted!
In this case maybe is it possible to use [ '*', u'givenName', u'sn' ]
to convert only 'givenName' and 'sn'
> > Ops, I forgot the asynchronous side of ldap, but the msgid make the link
> > between both
> > the request and the result and a dictionary store in the ldapobject
> > could store the
> > unicode transcoding info used in the request. And then ldap.result(),
> > could use these
> > info to decode the value when user call it.
>
> Yes, you could do this. But IMO it's cumbersome.
YES and I hope you will integrate my patch in your mainstream source code
:-)
> I'start writin a wrapper for search() and modify() now.
> >
> > I send you my results as soon a possible.
>
> I'm not too keen to incorporate Unicode patches in python-ldap's
> low-level API...
not low-level
Here is my work on progress
class UnicodeLDAPObject(LDAPObject):
expiration_delay=300
def __init__(self, uri, **kwargs):
LDAPObject.__init__(self, uri, **kwargs)
self.unicode_decoder={}
self.unicode_decoder_expire=[]
def search_ext(self,base,scope, **kwargs):
#
filterstr='(objectClass=*)',attrlist=None,attrsonly=0,serverctrls=None,clientctrls=None,timeout=-1,sizelimit=0
# convert filter
try:
kwargs['filter']=unicode2utf8(kwargs['filter'])
except KeyError:
pass
# convert arglist and keep a copy of original values for later
decoding
try:
attrlist=kwargs['attrlist']
kwargs['attrlist']=map(unicode2utf8(kwargs['attrlist']))
except KeyError:
attrlist=None
mesgid=LDAPObject.search_ext(self,base,scope, **kwargs)
if attrlist:
self.unicode_decoder[mesgid]=attrlist
self.unicode_decoder_expire.append((mesgid,
datetime.datetime.now()+datetime.timedelta(seconds=self.expiration_delay)))
return mesgid
def result3(self, **kwargs):
# msgid=_ldap.RES_ANY,all=1,timeout=None):
rtype, rdata, rmsgid, decoded_serverctrls=LDAPObject.result3(self,
**kwargs)
Alain
--
Alain Spineux
aspineux gmail com
May the sources be with you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20070524/f2c72635/attachment.html>
More information about the python-ldap
mailing list