本文整理汇总了Python中context.Context.addLeaveAction方法的典型用法代码示例。如果您正苦于以下问题:Python Context.addLeaveAction方法的具体用法?Python Context.addLeaveAction怎么用?Python Context.addLeaveAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context.Context
的用法示例。
在下文中一共展示了Context.addLeaveAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import addLeaveAction [as 别名]
def parse(filename):
if filename is None:
configdir = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config/"))
filename = os.path.join(configdir, "shackleton", "config.json")
if not os.path.exists(filename):
raise IOError("File %s not found" % filename)
result = {}
for (context_name, context_data) in simplejson.load(open(filename)).iteritems():
context = Context(context_name)
result[context_name] = context
for data in context_data["rules"]:
rule_name = data.pop("source")
context.addRule(Rule(rule_name, **__stringise(data)))
for data in context_data.get("enter", []):
action_name = data.pop("action")
cls = getattr(actions, action_name, None)
if cls:
action = cls(**__stringise(data))
context.addEnterAction(action)
for data in context_data.get("leave", []):
action_name = data.pop("action")
cls = getattr(actions, action_name, None)
if cls:
action = cls(**__stringise(data))
context.addLeaveAction(action)
return result