'Internal method for deleting all of the subtree whose revisions match the as_functions'

def _delete_subtree(self, location, as_functions, draft_only=False):

    course_key = location.course_key
    def _delete_item(current_entry, to_be_deleted):
        '\n                                                Depth    first    deletion    of    nodes\n                                                '
        to_be_deleted.append(self._id_dict_to_son(current_entry['_id']))
        next_tier = []
        for child_loc in current_entry.get('definition', {}).get('children', []):
            child_loc = course_key.make_usage_key_from_deprecated_string(child_loc)
            if draft_only:
                revision = MongoRevisionKey.draft
            else:
                revision = ModuleStoreEnum.RevisionOption.all
            parents = self._get_raw_parent_locations(child_loc, revision)
            if all(((parent.to_deprecated_son() in to_be_deleted) for parent in parents)):
                for rev_func in as_functions:
                    current_loc = rev_func(child_loc)
                    current_son = current_loc.to_deprecated_son()
                    next_tier.append(current_son)
        return next_tier
    first_tier = [as_func(location) for as_func in as_functions]
    self._breadth_first(_delete_item, first_tier)
    self.refresh_cached_metadata_inheritance_tree(location.course_key)
