'read FILENAME: Processes SQL and commands in FILENAME (or Python if FILENAME ends with .py)
Treats the specified file as input (a mixture or SQL and/or
dot commands).  If the filename ends in .py then it is treated
as Python code instead.
For Python code the symbol \'shell\' refers to the instance of
the shell and \'apsw\' is the apsw module.'

def command_read(self, cmd):

    if (len(cmd) != 1):
        raise self.Error('read    takes    a    single    filename')
    if cmd[0].lower().endswith('.py'):
        g = {}
        g.update({'apsw': apsw, 'shell': self})
        if (sys.version_info < (3, 0)):
            execfile(cmd[0], g, g)
        else:
            exec compile(open(cmd[0]).read(), cmd[0], 'exec') in g, g
    else:
        f = codecs.open(cmd[0], 'rU', self.encoding[0])
        try:
            self.push_input()
            self.stdin = f
            self.interactive = False
            self.input_line_number = 0
            while True:
                line = self.getcompleteline()
                if (line is None):
                    break
                self.process_complete_line(line)
        except:
            eval = sys.exc_info()[1]
            if (not isinstance(eval, SystemExit)):
                self._append_input_description()
            raise
        finally:
            self.pop_input()
            f.close()
