schema.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import sys,ldap,ldap.schema
  2. schema_attrs = ldap.schema.SCHEMA_ATTRS
  3. ldap.set_option(ldap.OPT_DEBUG_LEVEL,0)
  4. ldap._trace_level = 0
  5. subschemasubentry_dn,schema = ldap.schema.urlfetch(sys.argv[-1])
  6. schema_reverse = ldap.schema.SubSchema(schema.ldap_entry())
  7. if subschemasubentry_dn is None:
  8. print 'No sub schema sub entry found!'
  9. sys.exit(1)
  10. print '*** Schema from',repr(subschemasubentry_dn)
  11. # Display schema
  12. for attr_type,schema_class in ldap.schema.SCHEMA_CLASS_MAPPING.items():
  13. print '*'*20,attr_type,'*'*20
  14. for element_id in schema.listall(schema_class):
  15. se_orig = schema.get_obj(schema_class,element_id)
  16. se_reverse = schema_reverse.get_obj(schema_class,element_id)
  17. # assert str(se_orig)==str(se_reverse)
  18. print attr_type,str(se_orig)
  19. print '*** Testing object class inetOrgPerson ***'
  20. inetOrgPerson = schema.get_obj(ldap.schema.ObjectClass,'inetOrgPerson')
  21. if not inetOrgPerson is None:
  22. print inetOrgPerson.must,inetOrgPerson.may
  23. print '*** person,organizationalPerson,inetOrgPerson ***'
  24. try:
  25. print schema.attribute_types(
  26. ['person','organizationalPerson','inetOrgPerson']
  27. )
  28. print schema.attribute_types(
  29. ['person','organizationalPerson','inetOrgPerson'],
  30. attr_type_filter = [
  31. ('no_user_mod',[0]),
  32. ('usage',range(2)),
  33. ]
  34. )
  35. except KeyError,e:
  36. print '***KeyError',str(e)
  37. drink = schema.get_obj(ldap.schema.AttributeType,'favouriteDrink')
  38. if not drink is None:
  39. print '*** drink ***'
  40. print 'drink.names',repr(drink.names)
  41. print 'drink.collective',repr(drink.collective)
  42. schema.ldap_entry()
  43. print str(schema.get_obj(ldap.schema.MatchingRule,'2.5.13.0'))
  44. print str(schema.get_obj(ldap.schema.MatchingRuleUse,'2.5.13.0'))
  45. print str(schema.get_obj(ldap.schema.AttributeType,'name'))
  46. print str(schema.get_inheritedobj(ldap.schema.AttributeType,'cn',['syntax','equality','substr','ordering']))