• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python importing.get_pyc_magic函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pypy.module.imp.importing.get_pyc_magic函数的典型用法代码示例。如果您正苦于以下问题:Python get_pyc_magic函数的具体用法?Python get_pyc_magic怎么用?Python get_pyc_magic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_pyc_magic函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_check_compiled_module

    def test_check_compiled_module(self):
        space = self.space
        mtime = 12345
        cpathname = _testfile(importing.get_pyc_magic(space), mtime)
        ret = importing.check_compiled_module(space, cpathname, mtime)
        assert ret is not None
        ret.close()

        # check for wrong mtime
        ret = importing.check_compiled_module(space, cpathname, mtime + 1)
        assert ret is None

        # also check with expected mtime==0 (nothing special any more about 0)
        ret = importing.check_compiled_module(space, cpathname, 0)
        assert ret is None
        os.remove(cpathname)

        # check for wrong version
        cpathname = _testfile(importing.get_pyc_magic(space) + 1, mtime)
        ret = importing.check_compiled_module(space, cpathname, mtime)
        assert ret is None

        # check for empty .pyc file
        f = open(cpathname, "wb")
        f.close()
        ret = importing.check_compiled_module(space, cpathname, mtime)
        assert ret is None
        os.remove(cpathname)
开发者ID:cimarieta,项目名称:usp,代码行数:28,代码来源:test_import.py


示例2: test_check_compiled_module

    def test_check_compiled_module(self):
        space = self.space
        mtime = 12345
        cpathname = _testfile(importing.get_pyc_magic(space), mtime)
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is not None
        ret.close()

        # check for wrong mtime
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime+1)
        assert ret is None
        os.remove(cpathname)

        # check for wrong version
        cpathname = _testfile(importing.get_pyc_magic(space)+1, mtime)
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is None

        # check for empty .pyc file
        f = open(cpathname, 'wb')
        f.close()
        ret = importing.check_compiled_module(space,
                                              cpathname,
                                              mtime)
        assert ret is None
        os.remove(cpathname)
开发者ID:alkorzt,项目名称:pypy,代码行数:32,代码来源:test_import.py


示例3: setup_after_space_initialization

 def setup_after_space_initialization(self):
     """NOT_RPYTHON"""
     if not self.space.config.translating:
         self.extra_interpdef('interp_pdb', 'interp_magic.interp_pdb')
     if self.space.config.objspace.std.withmethodcachecounter:
         self.extra_interpdef('method_cache_counter',
                              'interp_magic.method_cache_counter')
         self.extra_interpdef('reset_method_cache_counter',
                              'interp_magic.reset_method_cache_counter')
         if self.space.config.objspace.std.withmapdict:
             self.extra_interpdef('mapdict_cache_counter',
                                  'interp_magic.mapdict_cache_counter')
     PYC_MAGIC = get_pyc_magic(self.space)
     self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
     #
     try:
         from rpython.jit.backend import detect_cpu
         model = detect_cpu.autodetect()
         self.extra_interpdef('cpumodel', 'space.wrap(%r)' % model)
     except Exception:
         if self.space.config.translation.jit:
             raise
         else:
             pass   # ok fine to ignore in this case
     #
     if self.space.config.translation.jit:
         features = detect_cpu.getcpufeatures(model)
         self.extra_interpdef('jit_backend_features',
                                 'space.wrap(%r)' % features)
开发者ID:charred,项目名称:pypy,代码行数:29,代码来源:__init__.py


示例4: test_pyc_magic_changes

 def test_pyc_magic_changes(self):
     py.test.skip("For now, PyPy generates only one kind of .pyc files")
     # test that the pyc files produced by a space are not reimportable
     # from another, if they differ in what opcodes they support
     allspaces = [self.space]
     for opcodename in self.space.config.objspace.opcodes.getpaths():
         key = 'objspace.opcodes.' + opcodename
         space2 = maketestobjspace(make_config(None, **{key: True}))
         allspaces.append(space2)
     for space1 in allspaces:
         for space2 in allspaces:
             if space1 is space2:
                 continue
             pathname = "whatever"
             mtime = 12345
             co = compile('x = 42', '?', 'exec')
             cpathname = _testfile(importing.get_pyc_magic(space1),
                                   mtime, co)
             w_modulename = space2.wrap('somemodule')
             stream = streamio.open_file_as_stream(cpathname, "rb")
             try:
                 w_mod = space2.wrap(Module(space2, w_modulename))
                 magic = importing._r_long(stream)
                 timestamp = importing._r_long(stream)
                 space2.raises_w(space2.w_ImportError,
                                 importing.load_compiled_module,
                                 space2,
                                 w_modulename,
                                 w_mod,
                                 cpathname,
                                 magic,
                                 timestamp,
                                 stream.readall())
             finally:
                 stream.close()
开发者ID:yuyichao,项目名称:pypy,代码行数:35,代码来源:test_import.py


示例5: can_use_pyc

 def can_use_pyc(self, space, filename, magic, timestamp):
     if magic != importing.get_pyc_magic(space):
         return False
     if self.check_newer_pyfile(space, filename[:-1], timestamp):
         return False
     if not self.check_compatible_mtime(space, filename, timestamp):
         return False
     return True
开发者ID:are-prabhu,项目名称:pypy,代码行数:8,代码来源:interp_zipimport.py


示例6: get_magic

def get_magic(space):
    x = importing.get_pyc_magic(space)
    a = x & 0xff
    x >>= 8
    b = x & 0xff
    x >>= 8
    c = x & 0xff
    x >>= 8
    d = x & 0xff
    return space.wrap(chr(a) + chr(b) + chr(c) + chr(d))
开发者ID:mozillazg,项目名称:pypy,代码行数:10,代码来源:interp_imp.py


示例7: setup_after_space_initialization

 def setup_after_space_initialization(self):
     """NOT_RPYTHON"""
     if not self.space.config.translating:
         self.extra_interpdef('isfake', 'interp_magic.isfake')
         self.extra_interpdef('interp_pdb', 'interp_magic.interp_pdb')
     if self.space.config.objspace.std.withmethodcachecounter:
         self.extra_interpdef('method_cache_counter',
                              'interp_magic.method_cache_counter')
         self.extra_interpdef('reset_method_cache_counter',
                              'interp_magic.reset_method_cache_counter')
     PYC_MAGIC = get_pyc_magic(self.space)
     self.extra_interpdef('PYC_MAGIC', 'space.wrap(%d)' % PYC_MAGIC)
开发者ID:alkorzt,项目名称:pypy,代码行数:12,代码来源:__init__.py


示例8: make_pyc

 def make_pyc(cls, space, co, mtime):
     data = marshal.dumps(co)
     if type(mtime) is type(0.0):
         # Mac mtimes need a bit of special casing
         if mtime < 0x7fffffff:
             mtime = int(mtime)
         else:
             mtime = int(-0x100000000L + long(mtime))
     s = StringIO()
     try:
         _w_long(s, get_pyc_magic(space))
     except AttributeError:
         import imp
         s.write(imp.get_magic())
     pyc = s.getvalue() + struct.pack("<i", int(mtime)) + data
     return pyc
开发者ID:Darriall,项目名称:pypy,代码行数:16,代码来源:test_zipimport.py


示例9: setup_after_space_initialization

    def setup_after_space_initialization(self):
        """NOT_RPYTHON"""
        if not self.space.config.translating:
            self.extra_interpdef("isfake", "interp_magic.isfake")
            self.extra_interpdef("interp_pdb", "interp_magic.interp_pdb")
        if self.space.config.objspace.std.withmethodcachecounter:
            self.extra_interpdef("method_cache_counter", "interp_magic.method_cache_counter")
            self.extra_interpdef("reset_method_cache_counter", "interp_magic.reset_method_cache_counter")
            if self.space.config.objspace.std.withmapdict:
                self.extra_interpdef("mapdict_cache_counter", "interp_magic.mapdict_cache_counter")
        PYC_MAGIC = get_pyc_magic(self.space)
        self.extra_interpdef("PYC_MAGIC", "space.wrap(%d)" % PYC_MAGIC)
        #
        from pypy.jit.backend import detect_cpu

        model = detect_cpu.autodetect_main_model_and_size()
        self.extra_interpdef("cpumodel", "space.wrap(%r)" % model)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:17,代码来源:__init__.py


示例10: test_read_compiled_module

 def test_read_compiled_module(self):
     space = self.space
     mtime = 12345
     co = compile("x = 42", "?", "exec")
     cpathname = _testfile(importing.get_pyc_magic(space), mtime, co)
     stream = streamio.open_file_as_stream(cpathname, "rb")
     try:
         stream.seek(8, 0)
         w_code = importing.read_compiled_module(space, cpathname, stream.readall())
         pycode = w_code
     finally:
         stream.close()
     assert type(pycode) is pypy.interpreter.pycode.PyCode
     w_dic = space.newdict()
     pycode.exec_code(space, w_dic, w_dic)
     w_ret = space.getitem(w_dic, space.wrap("x"))
     ret = space.int_w(w_ret)
     assert ret == 42
开发者ID:cimarieta,项目名称:usp,代码行数:18,代码来源:test_import.py


示例11: test_load_compiled_module

 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 = _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
开发者ID:mozillazg,项目名称:pypy,代码行数:18,代码来源:test_import.py



注:本文中的pypy.module.imp.importing.get_pyc_magic函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python importing.load_source_module函数代码示例发布时间:2022-05-27
下一篇:
Python pyobject.track_reference函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap