Exemple #1
0
def _run_compiled_module(space, w_modulename, filename, w_file, w_module):
    # the function 'imp._run_compiled_module' is a pypy-only extension
    stream = get_file(space, w_file, filename, "rb")

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    importing.load_compiled_module(space, w_modulename, w_module, filename, magic, timestamp, stream.readall())
    if space.is_w(w_file, space.w_None):
        stream.close()
Exemple #2
0
def _run_compiled_module(space, w_modulename, filename, w_file, w_module):
    # the function 'imp._run_compiled_module' is a pypy-only extension
    stream = get_file(space, w_file, filename, 'rb')

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    importing.load_compiled_module(space, w_modulename, w_module, filename,
                                   magic, timestamp, stream.readall())
    if space.is_w(w_file, space.w_None):
        stream.close()
Exemple #3
0
def _run_compiled_module(space, w_modulename, filename, w_file, w_module,
                         write_paths=True):
    # the function 'imp._run_compiled_module' is a pypy-only extension
    stream = get_file(space, w_file, filename, 'rb')

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    importing.load_compiled_module(
        space, w_modulename, w_module, filename, magic, timestamp,
        stream.readall(), write_paths)
    if space.is_none(w_file):
        stream.close()
Exemple #4
0
def load_compiled(space, w_modulename, w_filename, w_file=None):
    filename = space.str_w(w_filename)

    stream = get_file(space, w_file, filename, 'rb')

    w_mod = space.wrap(Module(space, w_modulename))
    importing._prepare_module(space, w_mod, filename, None)

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    importing.load_compiled_module(
        space, w_modulename, w_mod, filename, magic, timestamp,
        stream.readall())
    if space.is_w(w_file, space.w_None):
        stream.close()
    return w_mod
Exemple #5
0
def _run_compiled_module(space, w_modulename, filename, w_file, w_module,
                         check_afterwards=False):
    # the function 'imp._run_compiled_module' is a pypy-only extension
    stream = get_file(space, w_file, filename, 'rb')

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    w_mod = importing.load_compiled_module(
        space, w_modulename, w_module, filename, magic, timestamp,
        stream.readall(), check_afterwards=check_afterwards)
    if space.is_none(w_file):
        stream.close()
    return w_mod
Exemple #6
0
def _run_compiled_module(space, w_modulename, filename, w_file, w_module,
                         check_afterwards=False):
    # the function 'imp._run_compiled_module' is a pypy-only extension
    stream = get_file(space, w_file, filename, 'rb')

    magic = importing._r_long(stream)
    timestamp = importing._r_long(stream)

    w_mod = importing.load_compiled_module(
        space, w_modulename, w_module, filename, magic, timestamp,
        stream.readall(), check_afterwards=check_afterwards)
    if space.is_none(w_file):
        stream.close()
    return w_mod
Exemple #7
0
 def import_pyc_file(self, space, modname, filename, buf, pkgpath):
     w = space.wrap
     magic = importing._get_long(buf[:4])
     timestamp = importing._get_long(buf[4:8])
     if not self.can_use_pyc(space, filename, magic, timestamp):
         return None
     buf = buf[8:]  # XXX ugly copy, should use sequential read instead
     w_mod = w(Module(space, w(modname)))
     real_name = self.filename + os.path.sep + self.corr_zname(filename)
     space.setattr(w_mod, w('__loader__'), space.wrap(self))
     importing._prepare_module(space, w_mod, real_name, pkgpath)
     result = importing.load_compiled_module(space, w(modname), w_mod,
                                             real_name, magic, timestamp,
                                             buf)
     return result
Exemple #8
0
 def import_pyc_file(self, space, modname, filename, buf, pkgpath):
     w = space.wrap
     magic = importing._get_long(buf[:4])
     timestamp = importing._get_long(buf[4:8])
     if not self.can_use_pyc(space, filename, magic, timestamp):
         return None
     buf = buf[8:] # XXX ugly copy, should use sequential read instead
     w_mod = w(Module(space, w(modname)))
     real_name = self.filename + os.path.sep + self.corr_zname(filename)
     space.setattr(w_mod, w('__loader__'), space.wrap(self))
     importing._prepare_module(space, w_mod, real_name, pkgpath)
     w_result = importing.load_compiled_module(space, w(modname), w_mod,
                                             filename, magic, timestamp,
                                             buf)
     return w_result
Exemple #9
0
 def import_pyc_file(self, space, modname, filename, buf, pkgpath):
     w = space.wrap
     magic = importing._get_long(buf[:4])
     timestamp = importing._get_long(buf[4:8])
     if (self.check_newer_pyfile(space, filename[:-1], timestamp) or
         not self.check_compatible_mtime(space, filename, timestamp)):
         return self.import_py_file(space, modname, filename[:-1], buf,
                                    pkgpath)
     buf = buf[8:] # XXX ugly copy, should use sequential read instead
     w_mod = w(Module(space, w(modname)))
     real_name = self.name + os.path.sep + self.corr_zname(filename)
     space.setattr(w_mod, w('__loader__'), space.wrap(self))
     importing._prepare_module(space, w_mod, real_name, pkgpath)
     result = importing.load_compiled_module(space, w(modname), w_mod,
                                             filename, magic, timestamp,
                                             buf)
     return result
Exemple #10
0
 def import_pyc_file(self, space, modname, filename, buf, pkgpath):
     if len(buf) < 8:
         raise oefmt(get_error(space), "bad pyc data")
     magic = importing._get_long(buf[:4])
     timestamp = importing._get_long(buf[4:8])
     if not self.can_use_pyc(space, filename, magic, timestamp):
         return None
     buf = buf[8:]  # XXX ugly copy, should use sequential read instead
     w_mod = Module(space, space.newtext(modname))
     real_name = self.filename + os.path.sep + self.corr_zname(filename)
     space.setattr(w_mod, space.newtext('__loader__'), self)
     importing._prepare_module(space, w_mod, real_name, pkgpath)
     w_result = importing.load_compiled_module(space,
                                               space.newtext(modname),
                                               w_mod, filename, magic,
                                               timestamp, buf)
     return w_result
Exemple #11
0
 def test_load_compiled_module_nopathname(self):
     space = self.space
     mtime = 12345
     co = compile('x = 42', '?', 'exec')
     cpathname = _testfile(space, importing.get_pyc_magic(space), mtime, co)
     w_modulename = space.wrap('somemodule')
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         w_mod = space.wrap(Module(space, w_modulename))
         magic = _r_long(stream)
         timestamp = _r_long(stream)
         w_ret = importing.load_compiled_module(space, w_modulename, w_mod,
                                                None, magic, timestamp,
                                                stream.readall())
     finally:
         stream.close()
     filename = space.getattr(w_ret, space.wrap('__file__'))
     assert space.str_w(filename) == u'?'
Exemple #12
0
    def import_pyc_file(self, space, modname, filename, buf, pkgpath):
        # a field are four bytes
        # | magic | 0b00 | timestamp | size   # traditional timestamp based pyc
        # | magic | 0b01 | hash1     | hash2  # unchecked
        # | magic | 0b11 | hash1     | hash2  # checked

        if len(buf) < 16:
            raise oefmt(get_error(space), "bad pyc data")
        magic = importing._get_long(buf[:4])
        if not self.can_use_pyc(space, filename, magic, buf):
            return None
        buf = buf[16:]  # XXX ugly copy, should use sequential read instead
        w_mod = Module(space, space.newtext(modname))
        real_name = self.filename + os.path.sep + self.corr_zname(filename)
        space.setattr(w_mod, space.newtext('__loader__'), self)
        importing._prepare_module(space, w_mod, real_name, pkgpath)
        result = importing.load_compiled_module(space, space.newtext(modname),
                                                w_mod, real_name, magic, buf)
        return result
Exemple #13
0
 def test_load_compiled_module(self):
     space = self.space
     mtime = 12345
     co = compile("x = 42", "?", "exec")
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     w_modulename = space.wrap("somemodule")
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         w_mod = space.wrap(Module(space, w_modulename))
         magic = importing._r_long(stream)
         timestamp = importing._r_long(stream)
         w_ret = importing.load_compiled_module(
             space, w_modulename, w_mod, cpathname, magic, timestamp, stream.readall()
         )
     finally:
         stream.close()
     assert w_mod is w_ret
     w_ret = space.getattr(w_mod, space.wrap("x"))
     ret = space.int_w(w_ret)
     assert ret == 42
Exemple #14
0
 def test_load_compiled_module(self):
     space = self.space
     mtime = 12345
     co = compile('x = 42', '?', 'exec')
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     w_modulename = space.wrap('somemodule')
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         w_mod = space.wrap(Module(space, w_modulename))
         magic = importing._r_long(stream)
         timestamp = importing._r_long(stream)
         w_ret = importing.load_compiled_module(space, w_modulename, w_mod,
                                                cpathname, magic, timestamp,
                                                stream.readall())
     finally:
         stream.close()
     assert w_mod is w_ret
     w_ret = space.getattr(w_mod, space.wrap('x'))
     ret = space.int_w(w_ret)
     assert ret == 42
Exemple #15
0
def _load_compiled_module(space, w_modname, w_mod, *args, **kwds):
    kwds.setdefault("check_afterwards", False)
    return importing.load_compiled_module(space, w_modname, w_mod, *args, **kwds)