session.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:pyldap_orm 作者: asyd 项目源码 文件源码
def parse_schema(self):
        """
        Create ``self.schema['attributes']`` dictionary where values are a tuple holding the syntax oid and a boolean
        (true if the attribute is single valued).
        """

        def get_attribute_syntax(attr_name):
            """
            Get some information about an attributeType, directly or by a potential inheritance.

            :param attr_name: Name of the attribute
            :return: a tuple with (SYNTAX_OID, Boolean) where boolean is True if the attribute is single valued.
            """
            attribute = schema.get_obj(ldap.schema.AttributeType, attr_name)
            if attribute.syntax is None:
                return get_attribute_syntax(attribute.sup[0])
            return attribute.syntax, attribute.single_value

        self._schema['attributes'] = {}
        self._schema['objectClass'] = {}
        # TODO: base must be discovered from server (using subSchemaEntry)
        request = self.server.search_s(base='cn=schema', scope=ldap.SCOPE_BASE, attrlist=['+'])
        schema = ldap.schema.SubSchema(request[0][1])

        for attr in schema.tree(ldap.schema.AttributeType):
            definition = schema.get_obj(ldap.schema.AttributeType, attr)
            if definition is not None:
                syntax = get_attribute_syntax(definition.names[0])
                for attribute_name in definition.names:
                    self._schema['attributes'][attribute_name] = (syntax[0], definition.single_value)

        self._schema['attributes']['memberOf'] = ('1.3.6.1.4.1.1466.115.121.1.12', False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号