当前位置: 首页>>代码示例>>Python>>正文


Python GlobalsDict.define_virtual方法代码示例

本文整理汇总了Python中topaz.celldict.GlobalsDict.define_virtual方法的典型用法代码示例。如果您正苦于以下问题:Python GlobalsDict.define_virtual方法的具体用法?Python GlobalsDict.define_virtual怎么用?Python GlobalsDict.define_virtual使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在topaz.celldict.GlobalsDict的用法示例。


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

示例1: test_globals

# 需要导入模块: from topaz.celldict import GlobalsDict [as 别名]
# 或者: from topaz.celldict.GlobalsDict import define_virtual [as 别名]
    def test_globals(self, space):
        space.stuff = 4
        g = GlobalsDict()
        g.define_virtual("x", lambda s: s.stuff)
        assert g.get(space, "x") == 4
        with self.raises(space, "NameError"):
            g.set(space, "x", 5)

        g.define_virtual("y", lambda s: s.stuff, lambda s, v: setattr(s, "stuff", v))
        assert g.get(space, "y") == 4
        g.set(space, "y", 5)
        assert g.get(space, "y") == 5
开发者ID:AlekSi,项目名称:topaz,代码行数:14,代码来源:test_celldict.py

示例2: ObjectSpace

# 需要导入模块: from topaz.celldict import GlobalsDict [as 别名]
# 或者: from topaz.celldict.GlobalsDict import define_virtual [as 别名]

#.........这里部分代码省略.........

            self.getclassfor(W_ExceptionObject),
            self.getclassfor(W_StandardError),
            self.getclassfor(W_ThreadError),

            self.getmoduleobject(Comparable.moduledef),
            self.getmoduleobject(Enumerable.moduledef),
            self.getmoduleobject(Math.moduledef),
            self.getmoduleobject(Process.moduledef),
            self.getmoduleobject(Signal.moduledef),
            self.getmoduleobject(ObjectSpaceModule.moduledef),
        ]:
            self.set_const(
                self.w_object,
                self.str_w(self.send(w_cls, self.newsymbol("name"))),
                w_cls
            )

        for w_cls in [
            self.getclassfor(W_EnvObject), self.getclassfor(W_HashIterator),
        ]:
            self.set_const(
                self.w_topaz,
                self.str_w(self.send(w_cls, self.newsymbol("name"))),
                w_cls
            )

        # This is bootstrap. We have to delay sending until true, false and nil
        # are defined
        self.send(self.w_object, self.newsymbol("include"), [self.w_kernel])
        self.bootstrap = False

        self.w_load_path = self.newarray([])
        self.globals.define_virtual("$LOAD_PATH", lambda space: space.w_load_path)
        self.globals.define_virtual("$:", lambda space: space.w_load_path)

        self.w_loaded_features = self.newarray([])
        self.globals.define_virtual("$LOADED_FEATURES", lambda space: space.w_loaded_features)
        self.globals.define_virtual('$"', lambda space: space.w_loaded_features)

        self.w_main_thread = W_ThreadObject(self)

        self.w_load_path = self.newarray([])
        self.base_lib_path = os.path.abspath(os.path.join(os.path.join(os.path.dirname(__file__), os.path.pardir), "lib-ruby"))
        # TODO: this should really go in a better place.
        self.execute("""
        def self.include *mods
            Object.include *mods
        end
        """)

    def _freeze_(self):
        return True

    def setup(self, executable):
        """
        Performs runtime setup.
        """
        path = rpath.rabspath(executable)
        # Fallback to a path relative to the compiled location.
        lib_path = self.base_lib_path
        while path:
            path = rpath.rabspath(os.path.join(path, os.path.pardir))
            if os.path.isdir(os.path.join(path, "lib-ruby")):
                lib_path = os.path.join(path, "lib-ruby")
                break
开发者ID:Wanderfalke,项目名称:topaz,代码行数:70,代码来源:objspace.py

示例3: ObjectSpace

# 需要导入模块: from topaz.celldict import GlobalsDict [as 别名]
# 或者: from topaz.celldict.GlobalsDict import define_virtual [as 别名]

#.........这里部分代码省略.........
            self.getclassfor(W_FiberObject),

            self.getclassfor(W_ExceptionObject),
            self.getclassfor(W_ThreadError),

            self.getmoduleobject(Comparable.moduledef),
            self.getmoduleobject(Enumerable.moduledef),
            self.getmoduleobject(Math.moduledef),
            self.getmoduleobject(Process.moduledef),
            self.getmoduleobject(Signal.moduledef),
            self.getmoduleobject(ObjectSpaceModule.moduledef),
        ]:
            self.set_const(
                self.w_object,
                self.str_w(self.send(w_cls, "name")),
                w_cls
            )

        for w_cls in [
            self.getclassfor(W_EnvObject), self.getclassfor(W_HashIterator),
        ]:
            self.set_const(
                self.w_topaz,
                self.str_w(self.send(w_cls, "name")),
                w_cls
            )

        # This is bootstrap. We have to delay sending until true, false and nil
        # are defined
        self.send(self.w_object, "include", [self.w_kernel])
        self.bootstrap = False

        self.w_load_path = self.newarray([])
        self.globals.define_virtual("$LOAD_PATH", lambda space: space.w_load_path)
        self.globals.define_virtual("$:", lambda space: space.w_load_path)

        self.w_loaded_features = self.newarray([])
        self.globals.define_virtual("$LOADED_FEATURES", lambda space: space.w_loaded_features)
        self.globals.define_virtual('$"', lambda space: space.w_loaded_features)

        self.w_main_thread = W_ThreadObject(self)

        self.w_load_path = self.newarray([])
        self.base_lib_path = os.path.abspath(os.path.join(os.path.join(os.path.dirname(__file__), os.path.pardir), "lib-ruby"))

    def _freeze_(self):
        self._executioncontexts.clear()
        return True

    def find_executable(self, executable):
        if os.sep in executable or (system.IS_WINDOWS and ":" in executable):
            return executable
        path = os.environ.get("PATH")
        if path:
            for dir in path.split(os.pathsep):
                f = os.path.join(dir, executable)
                if os.path.isfile(f):
                    executable = f
                    break
        return rpath.rabspath(executable)

    def setup(self, executable):
        """
        Performs runtime setup.
        """
        path = rpath.rabspath(self.find_executable(executable))
开发者ID:Freidrichs,项目名称:topaz,代码行数:70,代码来源:objspace.py


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