ldapurl.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. .. % $Id: ldapurl.rst,v 1.5 2010/02/05 13:13:19 stroeder Exp $
  2. ################################
  3. :mod:`ldapurl` LDAP URL handling
  4. ################################
  5. .. module:: ldapurl
  6. :synopsis: Parses and generates LDAP URLs
  7. .. moduleauthor:: python-ldap project (see http://www.python-ldap.org/)
  8. This module parses and generates LDAP URLs. It is implemented in pure Python
  9. and does not rely on any non-standard modules. Therefore it can be used stand-
  10. alone without the rest of the python-ldap package. Compability note: This
  11. module has been solely tested on Python 2.x and above.
  12. .. seealso::
  13. :rfc:`4516` - The LDAP URL Format
  14. The :mod:`ldapurl` module exports the following constants:
  15. .. data:: SEARCH_SCOPE
  16. This dictionary maps a search scope string identifier to the corresponding
  17. integer value used with search operations in :mod:`ldap`.
  18. .. data:: SEARCH_SCOPE_STR
  19. This dictionary is the inverse to :const:`SEARCH_SCOPE`. It maps a search scope
  20. integer value to the corresponding string identifier used in a LDAP URL string
  21. representation.
  22. .. data:: LDAP_SCOPE_BASE
  23. .. data:: LDAP_SCOPE_ONELEVEL
  24. .. data:: LDAP_SCOPE_SUBTREE
  25. .. _ldapurl-ldapurl:
  26. LDAPUrl Objects
  27. ^^^^^^^^^^^^^^^^
  28. A :class:`LDAPUrl` object represents a complete LDAP URL.
  29. All class methods:
  30. Class attributes:
  31. Instance attributes:
  32. .. Here the actual docstring could be used provided it is fixed according rst rules
  33. .. autoclass:: ldapurl.LDAPUrl
  34. .. _ldapurl-ldapurlextension:
  35. LDAPUrlExtension Objects
  36. ^^^^^^^^^^^^^^^^^^^^^^^^
  37. A :class:`LDAPUrlExtension` object represents a single LDAP URL extension.
  38. All class methods:
  39. Class attributes:
  40. Instance attributes:
  41. .. Here the actual docstring could be used provided it is fixed according rst rules
  42. .. autoclass:: ldapurl.LDAPUrlExtension
  43. .. _ldapurl-example:
  44. Example
  45. ^^^^^^^^
  46. Important security advice:
  47. For security reasons you shouldn't specify passwords in LDAP URLs
  48. unless you really know what you are doing.
  49. The following example demonstrates how to parse a LDAP URL
  50. with :mod:`ldapurl` module.
  51. >>> import ldapurl
  52. >>> ldap_url = ldapurl.LDAPUrl('ldap://localhost:1389/dc=stroeder,dc=com?cn,mail???bindname=cn=Michael%2cdc=stroeder%2cdc=com,X-BINDPW=secret')
  53. >>> # Using the parsed LDAP URL by reading the class attributes
  54. >>> ldap_url.dn
  55. 'dc=stroeder,dc=com'
  56. >>> ldap_url.hostport
  57. 'localhost:1389'
  58. >>> ldap_url.attrs
  59. ['cn','mail']
  60. >>> ldap_url.filterstr
  61. '(objectclass=*)'
  62. >>> ldap_url.who
  63. 'cn=Michael,dc=stroeder,dc=com'
  64. >>> ldap_url.cred
  65. 'secret'
  66. >>> ldap_url.scope
  67. 0
  68. The following example demonstrates how to generate a LDAP URL
  69. with \module{ldapurl} module.
  70. >>> import ldapurl
  71. >>> ldap_url = ldapurl.LDAPUrl(hostport='localhost:1389',dn='dc=stroeder,dc=com',attrs=['cn','mail'],who='cn=Michael,dc=stroeder,dc=com',cred='secret')
  72. >>> ldap_url.unparse()
  73. 'ldap://localhost:1389/dc=stroeder,dc=com?cn,mail?base?(objectclass=*)?bindname=cn=Michael%2Cdc=stroeder%2Cdc=com,X-BINDPW=secret'