|
From: <mi...@st...> - 2002-06-29 11:04:30
|
Derrick 'dman' Hudson wrote:
> On Fri, Jun 28, 2002 at 09:36:26PM +0200, Michael Str=F6der wrote:
> | Derrick 'dman' Hudson wrote:
> | >On Fri, Jun 28, 2002 at 04:44:54PM +0200, Michael Str=F6der wrote:
> | >| Michael Str=F6der wrote:
> | >|=20
> | >| Anyone having any objections against removing methods url_search*(=
)?
> | >|=20
> | >| Anyone really using it?
> | >
> | >The only objection I have is that it really helped me to learn how t=
o
> | >work with an LDAP URL.
> |=20
> | How about practicing with the module ldapurl?
>=20
> How? The documentation is pretty sparse.
> [..]
> If the ldapurl module does everything that the current url_search
> methods do, then there is no compelling reason to keep the latter
> around.
It parses and unparses LDAP URLs and is designed to be completely=20
independent from module ldap.
Some sample code for parsing a LDAP URL:
>>> import ldapurl
>>> ldap_url =3D=20
ldapurl.LDAPUrl('ldap://localhost:1389/dc=3Dstroeder,dc=3Dcom?cn???bindna=
me=3Dcn=3DMichael%2cdc=3Dstroeder%2cdc=3Dcom,X-BINDPW=3Dsecret')
>>> # Using the parsed LDAP URL by reading the class attributes
>>> ldap_url.dn
u'dc=3Dstroeder,dc=3Dcom'
>>> ldap_url.hostport
'localhost:1389'
>>> ldap_url.attrs
['cn']
>>> ldap_url.filterstr
u'(objectclass=3D*)'
>>> ldap_url.who
'cn=3DMichael,dc=3Dstroeder,dc=3Dcom'
>>> ldap_url.cred
'secret'
>>> ldap_url.scope
0
Some sample code for the other way round:
>>> ldap_url =3D=20
ldapurl.LDAPUrl(hostport=3D'localhost:1389',dn=3Du'dc=3Dstroeder,dc=3Dcom=
',attrs=3D['cn','mail'],who=3D'cn=3DMichael,dc=3Dstroeder,dc=3Dcom',cred=3D=
'secret')
>>> ldap_url.unparse()
u'ldap://localhost:1389/dc=3Dstroeder,dc=3Dcom?cn,mail?base?(objectclass=3D=
*)?bindname=3Dcn=3DMichael%2Cdc=3Dstroeder%2Cdc=3Dcom,X-BINDPW=3Dsecret'
That's pretty much all it does. Note that you don't have to=20
specify all the class attributes. There are reasonable defaults=20
assumed. And who and cred maps to None if not specified. See the=20
tests at the bottom of ldapurl.py for more examples.
Advice: For security reasons you shouldn't specify passwords in=20
LDAP URLs unless you really know what you're doing.
Ciao, Michael.
|