本文整理汇总了Python中context.Context.update方法的典型用法代码示例。如果您正苦于以下问题:Python Context.update方法的具体用法?Python Context.update怎么用?Python Context.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类context.Context
的用法示例。
在下文中一共展示了Context.update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_getter
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import update [as 别名]
def make_getter():
"""
NOT_RPYTHON:
"""
return lambda s: getattr(s, 'strval')
def to_repr(self):
return repr(self.strval)
def IntPtr(i):
return NodePtr(IntNode(i))
def CharPtr(c):
return NodePtr(CharNode(c))
def StrPtr(s):
return NodePtr(StringNode(s))
def BoolPtr(b):
if b:
return bool_true
else:
return bool_false
def UnitPtr():
return unit
from pyops import pyops_context
default_context.update(pyops_context)
示例2: Context
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import update [as 别名]
GLOBAL_ENV = Context()
GLOBAL_ENV.update(
{'+': op.add,
'-': op.sub,
'*': op.mul,
'/': op.div,
'not': op.not_,
'>': op.gt,
'<': op.lt,
'>=': op.ge,
'<=': op.le,
'==': op.eq,
'/=': op.ne,
'eq?': op.is_,
'length': len,
':': lambda x, y: [x] + y,
'head': lambda x: x[0],
'tail': lambda x: x[1:],
'append': op.add,
'list': lambda *x: list(x),
'list?': lambda x: isinstance(x, list),
'null?': lambda x: x == [],
'symbol?': lambda x: isinstance(x, str),
'map': lambda f, xs: [f(x) for x in xs],
}
)
def to_string(exp):
示例3: Converter
# 需要导入模块: from context import Context [as 别名]
# 或者: from context.Context import update [as 别名]
class Converter(object):
libraries = [calculator.library, functions.library, html.library]
elemlibraries = [elements.library]
filetype = 'html'
def __init__(self, manager=FileManager, context={}, config={},
compress=False, debug=False, optimize=False):
self.context = Context(true=True, false=False)
self.context.update(context)
self.config = config
self.manager = manager() if callable(manager) else manager
self.compress = compress
self.builder = Builder(debug, optimize)
def eval(self, element):
if element is None:
return ''
if not isinstance(element, Node):
return element
try:
return element.evaluate(self)
except FallThrough as e:
return e.result
def accepts(self, name, tag):
function = self.function(name)
return tag in self.function(name).receivers
def function(self, name):
for library in reversed(self.libraries):
try:
return library.get(name)
except KeyError:
continue
raise ConversionError('Could not find function %s' % name,
'Libraries searched: %s' % list(reversed(self.libraries)))
def element(self, name):
for library in reversed(self.elemlibraries):
try:
return library.get(name)
except KeyError:
continue
return elements.Element
def configuration(self, name):
if name in self.config:
return self.config
import cm.config
return getattr(cm.config, name, None)
def join(self, lines, compress=False):
if compress or self.compress:
return ''.join(str(line).strip() for line in lines)
return '\n'.join(map(str, lines))
def build(self, filename):
file = self.manager.input_file(filename)
name = self.manager.relname(file)
return self.builder.build(file.read(), name)
def render(self, filename, context=None):
self.context.update(context or {})
result = self.eval(self.build(filename))
self.context.pop()
return result
def convert(self, filename, outname=None, context=None):
file = self.manager.output_file(outname or filename)
file.write(self.render(filename, context))
return file.name