<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_hdu_list(self, rebuild=True):
 """ Force an update of the entire HDU list Normally you don't need to call this method directly if rebuild is false or the hdu_list is not yet set, the list is rebuilt from scratch """

        if not hasattr(self, 'hdu_list'):
            rebuild = True

        if rebuild:
            self.hdu_list = []
            self.hdu_map = {}

            # we don't know how many hdus there are, so iterate
            # until we can't open any more
            ext_start = 0
        else:
            # start from last
            ext_start = len(self)

        ext = ext_start
        while True:
            try:
                self._append_hdu_info(ext)
            except IOError:
                break
            except RuntimeError:
                break

            ext = ext + 1