Package easyLDAP :: Module easyLDAP_class_object_base :: Class easyLDAP_object
[frames] | no frames]

Class easyLDAP_object

source code

easyLDAP_class_base.easyLDAP --+
                               |
                              easyLDAP_object

Instance Methods
 
__init__(self, dn_or_cacheobject, bind_dn=None, bind_pw=None, config_defaults={'AdminRDN': 'cn=admin', 'AutomountRDN': 'ou=automount', 'Base..., update_schema_cache=False, use_cache_history=True, ldapsession=None) source code
 
__deepcopy__(self, memo)
Creates a deepcopy of the easyLDAP object class.
source code
 
__call__(self) source code
 
set_object_dn(self, dn) source code
 
add_attrdesc_values(self, attrdesc, values) source code
 
get_object(self) source code
 
get_parent_dn(self)
thisClass.get_parent_dn ('myDN')
source code
 
get_object_dn(self) source code
 
get_object_rdn(thisClass)
returns the relative DN of the cached easyLDAPobject (i.e.
source code
 
get_used_attrdescs_aliases(self, attrdescs, capitalize=True) source code
 
get_attrdesc_values(self, attrdesc) source code
 
get_attrtype_values(self, attrtype)
get_attrtype_values('myATTRTYPE')
source code
 
get_used_attrtypes(self, pyldapobject=None)
returns a list of attribute types that are used in the current easyLDAP object.
source code
 
get_used_attroptions(self, attrdesc)
thisClass.get_used_attroptions('myATTRDESC', [mySINGLELDAPOBJECT])
source code
 
get_used_objectclasses(thisClass, mySINGLELDAPOBJECT=...)
returns a list of objectClasses that are used in the current easyLDAP object.
source code
 
get_used_attrdescs(thisClass)
returns a list of all attribute descriptions that are used in the current easyLDAP object.
source code
 
has_objectclass_set(self, objectclass)
thisClass.has_objectclass_set('myOBJECTCLASS'):
source code
 
has_attrtype_set(self, attrtype)
thisClass.has_attrtype_set('myATTRTYPE'):
source code
 
has_attrdesc_set(self, attrdesc)
thisClass.has_attrdesc_set('myATTRDESC'):
source code
 
has_value(self, value)
thisClass.has_value('myVALUE'):
source code
 
has_attrdesc_values_set(self, attrdesc, values)
thisClass.has_attrdesc_values_set('myATTRDESC', 'myVALUE'):
source code
 
has_attrdesc_value_set_in_values(self, attrdesc, value)
thisClass.has_attrdesc_value_set_in_values('myVALUE','myATTRDESC'):
source code
 
refresh_cache(thisClass)
loads/refreshes the easyLDAP object cache.
source code
 
map_diff2modlist(thisClass)
returns a list of changes that have been applied to the easyLDAP object chache.
source code
 
map_reverse_diff2modlist(thisClass)
returns a list of changes applied to the easyLDAP object cache that these changes can be undone with.
source code
 
map_diff2ldif(thisClass)
returns the changes applied to the easyLDAP object cache in ldif format.
source code
 
map_reverse_diff2ldif(thisClass)
returns ldif output that can undo the changes applied to the easyLDAP object cache.
source code
 
flush_cache(thisClass)
writes the easyLDAP object cache to the LDAP directory.
source code
 
add_objectclasses(self, objectclasses)
thisClass.add_objectclass('myOBJECTCLASS'|['myOBJECTCLASS1', 'myOBJECTCLASS2', ...])
source code
 
get_used_attrtype_oids(thisClass)
returns a list of those attribute OIDs, that are used the LDAP object 'mySINGLEOBJECT'.
source code
 
has_oid_set(self, oid, pyldapobject=None)
thisClass.has_oid_set('myOID')
source code
 
del_objectclass(self, del_these_objectClasses)
thisClass.del_objectclass('myOBJECTCLASS'|['myOBJECTCLASS1', 'myOBJECTCLASS2', ...])
source code
 
del_attrdesc_values(self, attrdesc, value, ignore_case=False, by_oid=False)
thisClass.del_attrdesc_value('myATTRDESC', 'myVALUE' ignore_case={True|FALSE})
source code
 
del_attrdesc(self, attrdesc, by_oid=False)
thisClass.del_attrdesc('myATTRDESC')
source code
 
del_attrtype(self, attrtype, by_oid=False)
thisClass.del_attrtype('myATTRTYPE')
source code
 
set_attrdesc(self, attrdesc, value)
thisClass.set_attr('myLDAP_ATTRDESC', 'myVALUE'|['myVALUE1', 'myVALUE2', ...])
source code
 
set_attrtype(self, attrtype_dict)
thisClass.set_attr('myATTRDESCDICT)
source code
 
add_attrdesc(self, attrdesc, value)
thisClass.add_attrdesc('myLDAP_ATTRDESC', 'myVALUE'|['myVALUE1', 'myVALUE2', ...])
source code
 
push_cache_history(self) source code
 
show_cache(thisClass)
will display the cached easyLDAP object just like the console tool 'ldapsearch' does...
source code
 
clear_cache(self) source code
 
new_object(self, objectclasses, attrdesc_dict)
thisClass.new_object(['myOBJ_CLASS1', 'myOBJ_CLASS2'], { 'myATTR1': ['myVAL1_1', 'myVAL1_2', ...], 'myATTR2': ['myVAL2_1', 'myVAL2_2', ...], ' ...
source code
 
undo(self) source code
 
redo(self) source code
 
set_userPassword(self, pw=None, HASH='CRYPT')
thisClass.set_userPassword('myUNIXPASSWORD','myHASH')
source code
 
set_naming_attrdesc(self, naming_attrdesc) source code
 
is_naming_attrdesc(self, naming_attrdesc) source code

Inherited from easyLDAP_class_base.easyLDAP: __del__, adminbind, adminbind_norefresh, anonymous_bind, anonymous_bind_norefresh, attrtype_needs_objectclass, bind, bind_norefresh, check_objectclass_dependencies, cn_bind, cn_bind_norefresh, find_newGidNumber, find_newUidNumber, generate_attributetypes_dict, generate_ldapsyntaxes_dict, generate_objectclass_dict, generate_reverse_attributetypes_dict, get_admin_dn, get_attributetypes, get_attrtype_aliases, get_basedn, get_cache_reference, get_groups_basedn, get_hosts_basedn, get_objectclasses, get_parent_rdn, get_people_basedn, get_samba3_algorithmicRidBase, get_samba3_domainSID, get_samelevel_dns, get_sublevel_dns, get_sublevel_rdns, get_subtree_dns, has_dn, has_parent_dn, has_samba2_schema, has_samba3_schema, has_valid_attrtype, is_collectiveattr, is_nousermodattr, is_obsoleteattr, is_pyldapobject, is_pyldaptree, is_singlevalueattr, is_valid_attrtype, is_valid_objectclass, map_attrtype2ldapsyntax, map_attrtype2ldapsyntaxname, map_attrtype2ldapsyntaxoid, map_attrtype2objectclasses, map_attrtype2valuemaxlen, map_attrtypes2oids, map_cn2dn, map_dn2ufn, map_gid2dn, map_gid2gidNumber, map_gidNumber2gid, map_objectclass2attr, map_oid2attrtypes, map_ou2dn, map_uid2dn, map_uid2posixgroups, map_uid2uniquemembergroups, map_uidNumber2uid, search, show_objectclass, uid_bind, uid_bind_norefresh

Method Details

__init__(self, dn_or_cacheobject, bind_dn=None, bind_pw=None, config_defaults={'AdminRDN': 'cn=admin', 'AutomountRDN': 'ou=automount', 'Base..., update_schema_cache=False, use_cache_history=True, ldapsession=None)
(Constructor)

source code 
Overrides: easyLDAP_class_base.easyLDAP.__init__

__deepcopy__(self, memo)

source code 

Creates a deepcopy of the easyLDAP object class.

Overrides: easyLDAP_class_base.easyLDAP.__deepcopy__

get_parent_dn(self)

source code 

thisClass.get_parent_dn ('myDN')

returns the parent absolute DN of 'myDN' from the LDAP server's directory tree.

Overrides: easyLDAP_class_base.easyLDAP.get_parent_dn
(inherited documentation)

get_object_rdn(thisClass)

source code 

returns the relative DN of the cached easyLDAPobject (i.e. the first protion of the object's DN).

get_attrtype_values(self, attrtype)

source code 

get_attrtype_values('myATTRTYPE')

returns a dictionary that contains all attribute descriptions in the easyLDAP object cache that contain the attribute type 'myATTRTYPE'.

This method is handy for e.g. viewing all attribute type's translations.

On failure, the method returns an empty dictionary.

get_used_attrtypes(self, pyldapobject=None)

source code 

returns a list of attribute types that are used in the current easyLDAP object. If - by some reason - the cache is empty, an empty list is returned.

Another LDAP object than the one currently cached can be analyzed by passing 'mySINGLELDAPOBJECT'. The lengths of the passed LDAP object has to be 1.

Overrides: easyLDAP_class_base.easyLDAP.get_used_attrtypes
(inherited documentation)

get_used_attroptions(self, attrdesc)

source code 

thisClass.get_used_attroptions('myATTRDESC', [mySINGLELDAPOBJECT])

returns a list of all attribute options used with attribute type same as in 'myATTRDESC'. The comparison is performed on an OID basis. So, if an alias of an 'myATTRDESC' is used, it will be taken into account.

Overrides: easyLDAP_class_base.easyLDAP.get_used_attroptions
(inherited documentation)

get_used_objectclasses(thisClass, mySINGLELDAPOBJECT=...)

source code 

returns a list of objectClasses that are used in the current easyLDAP object. If - by some reason - the cache is empty, an empty list is returned.

Another LDAP object than the one currently cached can be analyzed by passing 'mySINGLELDAPOBJECT'. The lengths of the passed LDAP object has to be 1.

has_objectclass_set(self, objectclass)

source code 

thisClass.has_objectclass_set('myOBJECTCLASS'):

returns True, if the objectClass 'myOBJECTCLASS' is set in the cached easyLDAP object.

has_attrtype_set(self, attrtype)

source code 

thisClass.has_attrtype_set('myATTRTYPE'):

returns True, if the attribute type 'myATTRTYPE' is set in the cached easyLDAP object. The attribute type is checked on an OID basis.

has_attrdesc_set(self, attrdesc)

source code 

thisClass.has_attrdesc_set('myATTRDESC'):

returns True, if the attribute 'myATTRDESC' is set in the cached easyLDAP object. The attribute type is checked on an OID basis.

has_value(self, value)

source code 

thisClass.has_value('myVALUE'):

returns True, if the value 'myVALUE' is set in the cached easyLDAP object, regardless from the attribute it is set for.

has_attrdesc_values_set(self, attrdesc, values)

source code 

thisClass.has_attrdesc_values_set('myATTRDESC', 'myVALUE'):

returns True, if the list of values 'myVALUES' is identical to those found in the cached easyLDAP object's attribute description 'myATTRDESC'.

has_attrdesc_value_set_in_values(self, attrdesc, value)

source code 

thisClass.has_attrdesc_value_set_in_values('myVALUE','myATTRDESC'):

returns True, if the value 'myVALUE' is set in the cached easyLDAP object's attribute description 'myATTRDESC' (amongst other possible values).

refresh_cache(thisClass)

source code 
loads/refreshes the easyLDAP object cache. This method should be the only 
easyLDAP module code that performs a read operation on the actual
LDAP directory server.

BEWARE: This method is called, when thisClass is initiated.

If the given DN (at __init__ time) exists in the LDAP directory, 
this method:

- reads the DN's data LDAP directory from the LDAP directory,
- checks and repairs objectClass dependencies violations,
- moves the data in the easyLDAP cache.

If the given DN is new to the LDAP directory, this method:

- creates an empty easyLDAP object cache,
- marks the object as a new object, so the first 
  thisClass.flush_cache() operation will be 'ldap.add_s' 
  as opposed to 'ldap.modify_s'

Once the easyLDAP cache is filled with the DN data all modification
will be performed in the easyLDAP object cache. Once you are done,
use thisClass.flush_cache() to update the LDAP directory's 
data.

WARNING: this method tries to repair buggy LDAP objects. If it finds an 
         attribute that does not have an objectClass set, the method will
         try to find a usable objectClass (it will take the first it finds, 
         which might not be wanted). If there is no such objectClass 
         in the server's LDAP schema, the invalid attributes will be purged
         from the object. This is a repair functionality and should not come to
         use...

Overrides: easyLDAP_class_base.easyLDAP.refresh_cache

map_diff2modlist(thisClass)

source code 

returns a list of changes that have been applied to the easyLDAP object chache. The format of this list is conformant with the modlist structure in python- ldap that is used for the methods

ldap.modify() / ldap.modify_s()

map_reverse_diff2modlist(thisClass)

source code 

returns a list of changes applied to the easyLDAP object cache that these changes can be undone with. The format of this list is conformant with the modlist structure in python-ldap that is used for the methods

ldap.modify() / ldap.modify_s()

map_diff2ldif(thisClass)

source code 

returns the changes applied to the easyLDAP object cache in ldif format. The method returns a python list in which each item represents a line of the text base ldif format.

map_reverse_diff2ldif(thisClass)

source code 

returns ldif output that can undo the changes applied to the easyLDAP object cache. The method returns a python list in which each item represents a line of the text base ldif format.

flush_cache(thisClass)

source code 
writes the easyLDAP object cache to the LDAP directory. This method 
should be the only easyLDAP module code that performs a write operation 
on the actual LDAP directory server. 

If the given DN existed in the LDAP directory at __init__ time, 
this method:

- checks, if the cached DN still exists in the LDAP directory 
  (otherwise, it switches to object creation mode).
- flushes modifications and additions to the easyLDAP object 
  cache to the server's LDAP directory.

If the given DN was new to the LDAP directory at __init__ time, 
this method:

- checks, if the cached DN is still new to the LDAP directory 
  (otherwise, it switches to object modification mode).
- checks, if the underlying DN still exists in the directory. If 
  not the flush_cache() operation will fail.
- adds easyLDAP object cache to the LDAP directory.

If the easyLDAP object cache does not need a flush_cache() operation
(as it is up-to-date), the flush will not be performed (i.e. fail).

add_objectclasses(self, objectclasses)

source code 

thisClass.add_objectclass('myOBJECTCLASS'|['myOBJECTCLASS1', 
                                           'myOBJECTCLASS2', ...])

adds one ore more objectClass(es) and all needed SUPerior 
objectClasses to the cached easyLDAP object. Attributes 
that - according to the server's LDAP schema - MUST be 
present will be set to default values regarding their 
proposed syntaxes in thisClass.LDAPSyntaxes. 

The default values are stored in thisClass.templateLDAPSyntaxValues.

get_used_attrtype_oids(thisClass)

source code 

returns a list of those attribute OIDs, that are used the LDAP object 'mySINGLEOBJECT'. This list is taken from the server's LDAP schema.

Overrides: easyLDAP_class_base.easyLDAP.get_used_attrtype_oids

has_oid_set(self, oid, pyldapobject=None)

source code 

thisClass.has_oid_set('myOID')

checks if the given OID 'myOID' is set in the LDAP object 'mySINGLELDAPOBJECT'. If so, the method's result is True.

Overrides: easyLDAP_class_base.easyLDAP.has_oid_set

del_objectclass(self, del_these_objectClasses)

source code 

thisClass.del_objectclass('myOBJECTCLASS'|['myOBJECTCLASS1', 
                                           'myOBJECTCLASS2', ...])

deletes one ore more objectClass(es) from the cached 
easyLDAP object. All attributes that only occur in the
deleted objectClass(es) are also removed - so be careful!

The method will abort ...

if one of the given objectClass names are not set in
the easyLDAP object cache.

The method ignores ...

objectClasses that are to be deleted, but are needed 
as a SUPerior objectClass by another objectClass.

del_attrdesc_values(self, attrdesc, value, ignore_case=False, by_oid=False)

source code 

thisClass.del_attrdesc_value('myATTRDESC', 'myVALUE' ignore_case={True|FALSE})

deletes the value 'myVALUE' from the LDAP attribute description 'myATTRDESC' in the currently cached object.

If 'myVALUE' is the only value for 'myATTRDESC', the whole attribute is removed from the cached easyLDAP object.

The method returns True on successful deletion.

del_attrdesc(self, attrdesc, by_oid=False)

source code 

thisClass.del_attrdesc('myATTRDESC')

deletes the whole entry for attribute description 'myATTRDESC' from the cached easyLDAP object.

The method returns True on successful deletion.

del_attrtype(self, attrtype, by_oid=False)

source code 

thisClass.del_attrtype('myATTRTYPE')

deletes all entries for attribute type 'myATTRTYPE' from the cached easyLDAP object. Be aware that all subentries of the attribute type 'myATTRTYPE' will be removed (e.g. all language options with one shot).

The method returns True on successful deletion.

set_attrdesc(self, attrdesc, value)

source code 

thisClass.set_attr('myLDAP_ATTRDESC', 
                   'myVALUE'|['myVALUE1', 'myVALUE2', ...]) 

is a wrapper for 

thisClass._modify_attrdesc('myLDAP_ATTRDESC', 
  'myVALUE'|['myVALUE1', 'myVALUE2', ...], 
  easyLDAP_REPLACEATTR)

or

thisClass.del_attrdesc('myLDAP_ATTRIBUTE')

depending on the attribute description's context...

set_attrtype(self, attrtype_dict)

source code 

thisClass.set_attr('myATTRDESCDICT) 

helps copy+pasting a whole attribute type from one easyLDAP object
into another easyLDAP object.

Little HOWTO:

    o connect to two easyLDAP objects. Let's call them ,,source" and ,,target".
    o retrieve all attribute descriptions (including all subentries) of a certain
      attribute type 'myATTRTYPE' from easyLDAPobject ,,source" with 

      my_attrtype = source.get_attrtype_values('myATTRTYPE')

    o paste the retrieved data (a python dictionary) into easyLDAPobject 
      ,,target" with

      target.set_attrtype(my_attrtype)

    o flush the easyLDAP object cache of ,,target" with

      target.flush_cache()    

If necessary objectClasses can be detected automagically they will be 
added silently. If not, the method returns a list of possible objectClasses 
that all provide the attribute type of your interest.

The structure of myATTRDESCDICT is expected to be an excerpt from 
a python-ldap object

{
  'attrtype;attropt1': ['val1','val2'],
  'attrtype;attropt2': [...],
  ...
}

Keys of myATTRDESCDICT must alwasy have the same attribute type. 
The attribute options must be supported by LDAPv3 protocol. Attribute 
description values must be given as multi-valued or single-valued 
lists (depending on the attribute's properties in the server's schema).

add_attrdesc(self, attrdesc, value)

source code 

thisClass.add_attrdesc('myLDAP_ATTRDESC', 
  'myVALUE'|['myVALUE1', 'myVALUE2', ...]) 

is a wrapper for

thisClass._modify_attrdesc('myLDAP_ATTRDESC', 
  'myVALUE'|['myVALUE1', 'myVALUE2', ...], 
  easyLDAP_ADDATTR)

show_cache(thisClass)

source code 

will display the cached easyLDAP object just like the console tool 'ldapsearch' does... unset but possible attributes are not listed.

new_object(self, objectclasses, attrdesc_dict)

source code 

thisClass.new_object(['myOBJ_CLASS1', 'myOBJ_CLASS2'], 
    {
     'myATTR1': ['myVAL1_1', 'myVAL1_2', ...], 
     'myATTR2': ['myVAL2_1', 'myVAL2_2', ...], '
     ...
    }
)

creates an empty object in the easyLDAP object cache. The object 
will only be uploaded to the LDAP directory, until the method 
thisClass.flush_cash() is evoked.

This action overwrites the current easyLDAP object cache and 
creates a new cache object if the used DN was not existent in 
the LDAP directory at the time of thisClass.__init__ ('myDN').

This newly created object can be modified by several easyLDAP methods. 
Use dir(thisClass).

To view the contents of the new easyLDAP object cache, use 
thisClass.show().

set_userPassword(self, pw=None, HASH='CRYPT')

source code 

thisClass.set_userPassword('myUNIXPASSWORD','myHASH')

sets the user's unix password to 'myUNIXPASSWORD'.
As encryption hash 'myHASH' you can additionally pass

    CLEAR
    CRYPT

The default hash is 'CRYPT'.

If the easyLDAP object has the shadowAccount objectclass
set, the attribute shadowLastChange will be set to the
current date (in days since 1970).