Package ldaptor :: Package protocols :: Package ldap :: Module ldapsyntax :: Class LDAPEntry
[show private | hide private]
[frames | no frames]

Class LDAPEntry

Known Subclasses:
LDAPEntryWithAutoFill

Pythonic API for LDAP object access and modification.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={'anAttribute': ['itsValue', 'secondValue'],
...     'onemore': ['aValue'],
...     })
>>> o
LDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={'anAttribute': ['itsValue', 'secondValue'], 'onemore': ['aValue']})

Method Summary
  __init__(self, client, dn, attributes, complete)
Initialize the object.
  __contains__(self, key)
  __delitem__(self, key)
Delete all values of an attribute.
  __eq__(self, other)
Comparison.
  __getitem__(self, key)
Get all values of an attribute.
  __len__(self)
  __ne__(self, other)
Inequality comparison.
  __nonzero__(self)
  __repr__(self)
  __setitem__(self, key, value)
Set values of an attribute.
  __str__(self)
Stringify as LDIF.
  commit(self)
Send all pending changes to the LDAP server.
  delete(self)
Delete this object from the LDAP server.
  fetch(self, *attributes)
Fetch the attributes of this object from the server.
  get(self, key, default)
Get all values of an attribute.
  has_key(self, key)
  items(self)
  journal(self, journalOperation)
Add an LDAPJournalOperation into the list of modifications that need to be flushed to the LDAP server.
  keys(self)
  move(self, newDN)
Move the object to a new DN.
  namingContext(self)
Return an LDAPEntry for the naming context that contains this object.
  search(self, filterText, filterObject, attributes, scope, derefAliases, sizeLimit, sizeLimitIsNonFatal, timeLimit, typesOnly, callback)
Perform an LDAP search with this object as the base.
  setPassword(self, newPasswd)
Set all applicable passwords for this object.
  setPassword_ExtendedOperation(self, newPasswd)
Set the password on this object.
  setPassword_Samba(self, newPasswd)
Set the Samba password on this object.
  setPasswordMaybe_ExtendedOperation(self, newPasswd)
Set the password on this object.
  setPasswordMaybe_Samba(self, newPasswd)
Set the Samba password on this object if it is a sambaAccount.
  undo(self)
Forget all pending changes.
  _canRemove(self, key, value)
Called by LDAPAttributeSet when it is about to remove a value of an attributeType.
  _canRemoveAll(self, key)
Called by LDAPAttributeSet when it is about to remove all values of an attributeType.
  _cbCommit(self, msg, d)
  _cbDeleteDone(self, msg, d)
  _cbFetch(self, results, overWrite)
  _cbMoveDone(self, msg, d)
  _cbNamingContext_Entries(self, results)
  _cbSearchEntry(self, callback, objectName, attributes, complete)
  _cbSearchMsg(self, msg, d, callback, complete, sizeLimitIsNonFatal)
  _cbSetPassword(self, dl, names)
  _cbSetPassword_ExtendedOperation(self, msg, d)
  _checkState(self)
  _commit_success(self, data)

Class Variable Summary
int _setPasswordPriority_ExtendedOperation = 0                                                                     
int _setPasswordPriority_Samba = 20                                                                    
str _state = 'invalid'

Method Details

__init__(self, client, dn, attributes={}, complete=0)
(Constructor)

Initialize the object.
Parameters:
client - The LDAP client connection this object belongs to.
dn - Distinguished Name of the object, as a string.
attributes - Attributes of the object. A dictionary of attribute types to list of attribute values.

__delitem__(self, key)
(Index deletion operator)

Delete all values of an attribute.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={
...     'anAttribute': ['itsValue', 'secondValue'],
...     'another': ['moreValues'],
...     })
>>> del o['anAttribute']
>>> o
LDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={'another': ['moreValues']})

__eq__(self, other)
(Equality operator)

Comparison. Only equality is supported.
>>> client=ldapclient.LDAPClient()
>>> a=LDAPEntry(client=client,
...             dn='dc=example,dc=com')
>>> b=LDAPEntry(client=client,
...             dn='dc=example,dc=com')
>>> a==b
1

>>> c=LDAPEntry(client=ldapclient.LDAPClient(),
...             dn='ou=different,dc=example,dc=com')
>>> a==c
0
Comparison does not consider the client of the object.
>>> anotherClient=ldapclient.LDAPClient()
>>> d=LDAPEntry(client=anotherClient,
...             dn='dc=example,dc=com')
>>> a==d
1

__getitem__(self, key)
(Indexing operator)

Get all values of an attribute.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={'anAttribute': ['itsValue']})
>>> o['anAttribute']
['itsValue']

__ne__(self, other)

Inequality comparison. See __eq__.

__setitem__(self, key, value)
(Index assignment operator)

Set values of an attribute. Please use lists. Do not modify the lists in place, that's not supported _yet_.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={'anAttribute': ['itsValue']})
>>> o['anAttribute']=['foo', 'bar']
>>> o['anAttribute']
['bar', 'foo']

__str__(self)
(Informal representation operator)

Stringify as LDIF.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={'anAttribute': ['itsValue', 'secondValue'],
...     'onemore': ['aValue'],
...     })
>>> # must use rstrip or doctests won't like it due to the empty line
>>> # you can just say "print o"
>>> print str(o).rstrip()
dn: cn=foo,dc=example,dc=com
anAttribute: itsValue
anAttribute: secondValue
onemore: aValue

commit(self)

Send all pending changes to the LDAP server.
Returns:
a Deferred that tells you whether the operation succeeded or not. (TODO specify how)

delete(self)

Delete this object from the LDAP server.
Returns:
A Deferred that will complete when the delete is done.

fetch(self, *attributes)

Fetch the attributes of this object from the server.
Returns:
A Deferred that will complete when the operation is done.

get(self, key, default=None)

Get all values of an attribute.
>>> o=LDAPEntry(client=ldapclient.LDAPClient(),
...     dn='cn=foo,dc=example,dc=com',
...     attributes={'anAttribute': ['itsValue']})
>>> o.get('anAttribute')
['itsValue']

>>> o.get('foo')
>>> o.get('foo', [])
[]

journal(self, journalOperation)

Add an LDAPJournalOperation into the list of modifications that need to be flushed to the LDAP server.

Normal callers should not use this, they should use the o['foo']=['bar', 'baz'] -style API that enforces schema, handles errors and updates the cached data.

move(self, newDN)

Move the object to a new DN.
Parameters:
newDN - the new DistinguishedName
Returns:
A Deferred that will complete when the move is done.

namingContext(self)

Return an LDAPEntry for the naming context that contains this object.

search(self, filterText=None, filterObject=None, attributes=(), scope=2, derefAliases=0, sizeLimit=0, sizeLimitIsNonFatal=False, timeLimit=0, typesOnly=0, callback=None)

Perform an LDAP search with this object as the base.
Parameters:
filterText - LDAP search filter as a string.
filterObject - LDAP search filter as LDAPFilter. Note if both filterText and filterObject are given, they are combined with AND. If neither is given, the search is made with a filter that matches everything.
attributes - List of attributes to retrieve for the result objects. An empty list and means all.
scope - Whether to recurse into subtrees.
derefAliases - Whether to deref LDAP aliases. TODO write better documentation.
sizeLimit - At most how many entries to return. 0 means unlimited.
timeLimit - At most how long to use for processing the search request. 0 means unlimited.
typesOnly - Whether to return attribute types only, or also values.
callback - Callback function to call for each resulting LDAPEntry. None means gather the results into a list and give that to the Deferred returned from here.
Returns:
A Deferred that will complete when the search is done. The Deferred gives None if callback was given and a list of the search results if callback is not given or is None.

setPassword(self, newPasswd)

Set all applicable passwords for this object.
Parameters:
newPasswd - A string containing the new password.
Returns:
A Deferred that will complete when the operation is done.

setPassword_ExtendedOperation(self, newPasswd)

Set the password on this object.
Parameters:
newPasswd - A string containing the new password.
Returns:
A Deferred that will complete when the operation is done.

setPassword_Samba(self, newPasswd)

Set the Samba password on this object.
Parameters:
newPasswd - A string containing the new password.
Returns:
A Deferred that will complete when the operation is done.

setPasswordMaybe_ExtendedOperation(self, newPasswd)

Set the password on this object.
Parameters:
newPasswd - A string containing the new password.
Returns:
A Deferred that will complete when the operation is done.

setPasswordMaybe_Samba(self, newPasswd)

Set the Samba password on this object if it is a sambaAccount.
Parameters:
newPasswd - A string containing the new password.
Returns:
A Deferred that will complete when the operation is done.

undo(self)

Forget all pending changes.

_canRemove(self, key, value)

Called by LDAPAttributeSet when it is about to remove a value of an attributeType.

_canRemoveAll(self, key)

Called by LDAPAttributeSet when it is about to remove all values of an attributeType.

Class Variable Details

_setPasswordPriority_ExtendedOperation

Type:
int
Value:
0                                                                     

_setPasswordPriority_Samba

Type:
int
Value:
20                                                                    

_state

Type:
str
Value:
'invalid'                                                              

Generated by Epydoc 2.0 on Fri Mar 12 17:21:13 2004 http://epydoc.sf.net