<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pop(self):
 """ remove self from binary search tree """

        entry = self
        parent = self.parent

        root = parent.child()

        dir_per_sector = self.storage.sector_size // 128
        max_dirs_entries = self.storage.dir_sector_count * dir_per_sector
        count = 0

        if root.dir_id == entry.dir_id:
            parent.child_id = None
        else:
            # find dir entry pointing to self
            while True:
                if count > max_dirs_entries:
                    raise CompoundFileBinaryError("max dir entries limit reached")

                if entry < root:
                    if root.left_id == entry.dir_id:
                        root.left_id = None
                        break
                    root = root.left()
                else:
                    if root.right_id == entry.dir_id:
                        # root right is pointing to self
                        root.right_id = None
                        break
                    root = root.right()

                count += 1


        left = entry.left()
        right = entry.right()

        # clear from cache
        if parent.dir_id in self.storage.children_cache:
            del self.storage.children_cache[parent.dir_id][entry.name]
            if left:
                del self.storage.children_cache[parent.dir_id][left.name]
            if right:
                del self.storage.children_cache[parent.dir_id][right.name]

        if left is not None:
            parent.add_child(left)
        if right is not None:
            parent.add_child(right)

        # clear parent and left and right
        self.left_id = None
        self.right_id = None
        self.parent = None