ipapython.entity.py implements the Entity class used to hold LDAP attributes associated with a dn.
The Entity class will throw an exception if one tries to invoke str() or repr() on an Entity instance.
This is because Entity is an old style class and it's attribute access methods were improperly implemented.
The Entity class implements the getattr() special class method. As a convenience accesses to a non-existent attribute return None instead of raising an AttributeError. However getattr is use by the Python runtime on old-style classes to find the classes special methods. For example when you called str() or repr() the run-time calls:
getattr('members') getattr('methods')
and it expects to have an AttributeError raised if they do not exist, in which case it takes a different path to resolve the str and repr methods. But if it gets None back from getattr() then bad things happen because it tries to call the value it received, but None is not callable which raises another exception.
For old-style classes the solution is to test for special class members and if it's a special class member observe the AttributeError protocol, for example:
def __getattr__(self,name): """If name is the name of an LDAP attribute, return the first value for that attribute - equivalent to getValue - this allows the use of entry.cn instead of entry.getValue('cn') This also allows us to return None if an attribute is not found rather than throwing an exception""" value = self.getValue(name) if value is None and name.startswith('__') and name.endswith('__'): raise AttributeError
But really, the better solution is to use a new-style class and implement the getattribute method instead. A new-style class would also allow use to utilize class properties for attribute access, which for this particular class would be quite useful.
But before we start fixing the Entity class, we really need to figure out why we have both Entry and Entity classes. They get used with the IPAdmin class, in particular the IPAdmin.addEntry() method which after ticket #1879 is fixed forces IPAdmin.addEntry() to accept only an Entry or Entity class.
The Entry and Entity classes seem to have a fair amount of overlap, they should either be folded into one class or one should be a subclass of the other. In either case they should be new-style classes and support str() and repr() via str and repr respectively since this is a requirement of all classes in Python.
The classes have some "funky" code logic which really needs to be cleaned up to conform to Python class semantics, they need some attention.
At bare minimum the Entity class should not be throwing an exception with standard Python usage.
There are both legacy LDAP routines to be replaced by the ldap2 driver, we just lacked time to do so.
These were written for python 2.4.
Moving the ticket to the next month iteration.
We are going to move the code to use LDAP2 so this is irrelevant and will be retired. Closing.
General backlog was renamed to Beer Exchange
Metadata Update from @jdennis: - Issue assigned to jdennis - Issue set to the milestone: Ticket Backlog
Login to comment on this ticket.