def phase_copy(self, fpi, fpo, phase_in, phase_out):
        "Copy chunks from fpi to fpo storing failures in phase_out"
        while phase_in:
            chunk= phase_in.popleft()
            try: # to make sure this chunk is not skipped, eg by KeyboardInterrupt
                self.report_attempt(chunk)
                try:
                    self.copy_chunk(fpi, fpo, chunk)
                except IOError, exc:
                    if read_failed(exc): # the way windows reports failure
                            for new_chunk in chunk.next_attempt():
                                phase_out.append(new_chunk)
                            chunk= None
                            self.report_failure(chunk)
                    else:
                        raise
                else:
                    # report success, but first make sure chunk is None
                    _, chunk= chunk, None
                    self.report_success(_)
            finally:
                if chunk: phase_in.appendleft(chunk)
Copy chunks from fpi to fpo storing failures in phase_out
recipes/Python/496839_Recover_files_from_damaged_media/recipe-496839.py