'Defines and returns a function that may be used instead of built-in
open() to open and read files. The returned function is implemented
by using self.run(\'cat <file>\') and may cache the results for the same
filename.
:param use_cache Cache results of self.run(\'cat <filename>\') for the
same filename
:return: a function that can be used instead of built-in open()'

def get_open_func(self, use_cache=True):

    cached_files = {}
    def open_func(filename):
        if ((not use_cache) or (filename not in cached_files)):
            output = self.run(("cat    '%s'" % filename), stdout_tee=open('/dev/null', 'w')).stdout
            fd = cStringIO.StringIO(output)
            if (not use_cache):
                return fd
            cached_files[filename] = fd
        else:
            cached_files[filename].seek(0)
        return cached_files[filename]
    return open_func
