human
Complete this python program:
def ClosureTable(model_class, foreign_key=None, referencing_class=None, referencing_key=None):
assistant
#Here is the Python code you requested.

    """Model factory for the transitive closure extension.
    """
    if (referencing_class is None):
        referencing_class = model_class
    if (foreign_key is None):
        for field_obj in model_class._meta.rel.values():
            if (field_obj.rel_model is model_class):
                foreign_key = field_obj
                break
        else:
            raise ValueError('Unable    to    find    self-referential    foreign    key.')
    source_key = model_class._meta.primary_key
    if (referencing_key is None):
        referencing_key = source_key
    class BaseClosureTable(VirtualModel, ):
        depth = VirtualIntegerField()
        id = VirtualIntegerField()
        idcolumn = VirtualCharField()
        parentcolumn = VirtualCharField()
        root = VirtualIntegerField()
        tablename = VirtualCharField()
        class Meta:
            extension_module = 'transitive_closure'
        @classmethod
        def descendants(cls, node, depth=None, include_node=False):
            query = model_class.select(model_class, cls.depth.alias('depth')).join(cls, on=(source_key == cls.id)).where((cls.root == node)).naive()
            if (depth is not None):
                query = query.where((cls.depth == depth))
            elif (not include_node):
                query = query.where((cls.depth > 0))
            return query
        @classmethod
        def ancestors(cls, node, depth=None, include_node=False):
            query = model_class.select(model_class, cls.depth.alias('depth')).join(cls, on=(source_key == cls.root)).where((cls.id == node)).naive()
            if depth:
                query = query.where((cls.depth == depth))
            elif (not include_node):
                query = query.where((cls.depth > 0))
            return query
        @classmethod
        def siblings(cls, node, include_node=False):
            if (referencing_class is model_class):
                fk_value = node._data.get(foreign_key.name)
                query = model_class.select().where((foreign_key == fk_value))
            else:
                siblings =...