本文整理汇总了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
示例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
示例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))