Ejemplo n.º 1
0
 def _import_extension_module(self, fullname):
     vfile = vfs.getFile(self.filename, False)
     if hasattr(vfile, 'getMount') and isinstance(vfile.getMount(),
                                                  VirtualFileMountSystem):
         filename = self.filename
     else:
         if self.filename.exists():
             filename = self.filename
         else:
             filename = Filename.temporary(
                 '',
                 self.filename.getBasenameWoExtension(),
                 '.' + self.filename.getExtension(),
                 type=Filename.TDso)
             filename.setExtension(self.filename.getExtension())
             filename.setBinary()
             sin = vfile.openReadFile(True)
             sout = OFileStream()
             if not filename.openWrite(sout):
                 raise IOError
             if not copyStream(sin, sout):
                 raise IOError
             vfile.closeReadFile(sin)
             del sout
     module = imp.load_module(fullname, None, filename.toOsSpecific(),
                              self.desc)
     module.__file__ = self.filename.toOsSpecific()
     return module
Ejemplo n.º 2
0
    def _import_extension_module(self, fullname):
        """ Loads the binary shared object as a Python module, and
        returns it. """

        vfile = vfs.getFile(self.filename, False)

        # We can only import an extension module if it already exists on
        # disk.  This means if it's a truly virtual file that has no
        # on-disk equivalent, we have to write it to a temporary file
        # first.
        if hasattr(vfile, 'getMount') and \
           isinstance(vfile.getMount(), VirtualFileMountSystem):
            # It's a real file.
            filename = self.filename
        elif self.filename.exists():
            # It's a virtual file, but it's shadowing a real file in
            # the same directory.  Assume they're the same, and load
            # the real one.
            filename = self.filename
        else:
            # It's a virtual file with no real-world existence.  Dump
            # it to disk.  TODO: clean up this filename.
            filename = Filename.temporary(
                '',
                self.filename.getBasenameWoExtension(),
                '.' + self.filename.getExtension(),
                type=Filename.TDso)
            filename.setExtension(self.filename.getExtension())
            filename.setBinary()
            sin = vfile.openReadFile(True)
            sout = OFileStream()
            if not filename.openWrite(sout):
                raise IOError
            if not copyStream(sin, sout):
                raise IOError
            vfile.closeReadFile(sin)
            del sout

        module = imp.load_module(fullname, None, filename.toOsSpecific(),
                                 self.desc)
        module.__file__ = self.filename.toOsSpecific()
        return module
Ejemplo n.º 3
0
    def _import_extension_module(self, fullname):
        """ Loads the binary shared object as a Python module, and
        returns it. """

        vfile = vfs.getFile(self.filename, False)

        # We can only import an extension module if it already exists on
        # disk.  This means if it's a truly virtual file that has no
        # on-disk equivalent, we have to write it to a temporary file
        # first.
        if hasattr(vfile, 'getMount') and \
           isinstance(vfile.getMount(), VirtualFileMountSystem):
            # It's a real file.
            filename = self.filename
        elif self.filename.exists():
            # It's a virtual file, but it's shadowing a real file in
            # the same directory.  Assume they're the same, and load
            # the real one.
            filename = self.filename
        else:
            # It's a virtual file with no real-world existence.  Dump
            # it to disk.  TODO: clean up this filename.
            filename = Filename.temporary('', self.filename.getBasenameWoExtension(),
                                          '.' + self.filename.getExtension(),
                                          type = Filename.TDso)
            filename.setExtension(self.filename.getExtension())
            filename.setBinary()
            sin = vfile.openReadFile(True)
            sout = OFileStream()
            if not filename.openWrite(sout):
                raise IOError
            if not copyStream(sin, sout):
                raise IOError
            vfile.closeReadFile(sin)
            del sout

        module = imp.load_module(fullname, None, filename.toOsSpecific(),
                                 self.desc)
        module.__file__ = self.filename.toOsSpecific()
        return module