<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def scan_resource(self, pkg, path):
 r"""Scan a resource directory for colortable files and add them to the registry. Parameters pkg : str The package containing the resource directory path : str The path to the directory with the color tables """

        for fname in resource_listdir(pkg, path):
            if fname.endswith(TABLE_EXT):
                table_path = posixpath.join(path, fname)
                with contextlib.closing(resource_stream(pkg, table_path)) as stream:
                    self.add_colortable(stream,
                                        posixpath.splitext(posixpath.basename(fname))[0])