本文整理汇总了Python中pystache.render方法的典型用法代码示例。如果您正苦于以下问题:Python pystache.render方法的具体用法?Python pystache.render怎么用?Python pystache.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache
的用法示例。
在下文中一共展示了pystache.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_colorscheme
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def get_colorscheme(self, scheme_file):
"""Return a string object with the colorscheme that is to be
inserted."""
scheme = get_yaml_dict(scheme_file)
scheme_slug = builder.slugify(scheme_file)
builder.format_scheme(scheme, scheme_slug)
try:
temp_base, temp_sub = self.temp.split("##")
except ValueError:
temp_base, temp_sub = (self.temp.strip("##"), "default")
temp_path = rel_to_cwd("templates", temp_base)
temp_group = builder.TemplateGroup(temp_path)
try:
single_temp = temp_group.templates[temp_sub]
except KeyError:
raise FileNotFoundError(None, None, self.path + " (sub-template)")
colorscheme = pystache.render(single_temp["parsed"], scheme)
return colorscheme
示例2: read_file
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def read_file(self, filename, render_variables=False, as_binary=False):
if filename.startswith("vault:"):
if filename.startswith("vault::"):
if not self.global_config or "vault" not in self.global_config or "key" not in self.global_config["vault"]:
raise ConfigurationException("vault definition without key but no key is defined in global config: %s" % filename)
_, filename = filename.split("::", 1)
key = self.variables_container.render(self.global_config["vault"]["key"])
else:
_, key, filename = filename.split(":", 2)
else:
key = None
filepath = self.abspath(filename)
mode = "r"
if as_binary:
mode = "rb"
with open(filepath, mode) as file_obj:
data = file_obj.read()
if key:
check_if_encrypted_is_older(filepath)
data = decrypt_data(key, data)
if render_variables:
data = self.variables_container.render(data)
return data
示例3: render
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def render(self, text):
variables = {**self.variables, **self.extra_vars}
result_text = pystache.render(text, variables)
if result_text.count("{{"):
raise ConfigurationException("Unresolved variable")
return result_text
示例4: _read_variable_value_from_file
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def _read_variable_value_from_file(self, base_path, fileconfig):
if isinstance(fileconfig, dict):
filename = fileconfig["path"]
render = fileconfig.get("render", False)
else:
filename = fileconfig
render = False
if filename.startswith("vault:"):
_, key, filename = filename.split(":", 2)
if not key:
if not self._vault_key:
raise ConfigurationException("vault definition without key but no key is defined in global config: %s" % filename)
key = self._vault_key
else:
key = None
filename = self.render_value(filename)
absolute_path = os.path.abspath(os.path.join(base_path, filename))
if key:
check_if_encrypted_is_older(absolute_path)
with open(absolute_path) as var_file:
value = var_file.read()
if key:
key = self.render_value(key)
value = decrypt_data(key, value)
if render:
value = pystache.render(value, self.variables)
return value
示例5: render_value
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def render_value(self, value, extra_vars=dict()):
if extra_vars:
variables = {**self.variables, **extra_vars}
else:
variables = self.variables
return pystache.render(value, variables)
示例6: render
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def render(self, text):
if text is None:
return None
return self.variables_container.render(text)
示例7: _expand_loop
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def _expand_loop(key, values):
loop = values["loop"]
del values["loop"]
extra_vars = values.get("extra_vars", dict())
loop_vars = loop.keys()
if "{{" in key:
name_template = key
else:
name_template = "%s-%s" % (key, '-'.join(["{{%s}}" % var for var in loop_vars]))
for combination in itertools.product(*[loop[var] for var in loop_vars]):
variables = {**extra_vars, **dict([(var, combination[idx]) for idx, var in enumerate(loop_vars)])}
name = pystache.render(name_template, variables)
entity_config = copy.deepcopy(values)
entity_config["extra_vars"] = variables
yield name, entity_config
示例8: _synthesize
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def _synthesize(self, attributes, requester, provider):
syn_attributes = dict()
context = dict()
for attr_name,values in attributes.items():
context[attr_name] = MustachAttrValue(attr_name, values)
recipes = get_dict_defaults(self.synthetic_attributes, requester, provider)
for attr_name, fmt in recipes.items():
syn_attributes[attr_name] = [v.strip().strip(';') for v in re.split("[;\n]+", pystache.render(fmt, context))]
return syn_attributes
示例9: generateMain
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def generateMain(commands):
txt = []
with open("templates/mbed.tmplt") as fp:
tmplt = fp.read()
txt.append(pystache.render(tmplt, commands))
return txt
示例10: generateCompleters
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def generateCompleters(commands):
txt = []
renderer = pystache.Renderer(escape=lambda u: u)
with open("templates/command.tmplt") as fp:
tmplt = fp.read()
for commandKey in commands:
txt.append(renderer.render(tmplt, commands[commandKey]))
# if need to add hacks add them here
return txt
示例11: load_networkx_graph
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def load_networkx_graph(self, rdfgraph: rdflib.Graph = None, predicates: Set[URIRef] = None, **kwargs) -> None:
"""
Fetch triples from the SPARQL endpoint and load them as edges.
Parameters
----------
rdfgraph: rdflib.Graph
A rdflib Graph (unused)
predicates: set
A set containing predicates in rdflib.URIRef form
kwargs: dict
Any additional arguments.
"""
for predicate in predicates:
predicate = '<{}>'.format(predicate)
q = render(self.edge_query, {'predicate': predicate})
results = self.query(q)
for r in results:
s = r['subject']['value']
p = r['predicate']['value']
o = r['object']['value']
if r['object']['type'] == 'literal':
self.add_node_attribute(s, key=p, value=o)
else:
self.add_edge(s, o, p)
示例12: compact
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def compact(self):
fmt = inspect.cleandoc(self.COMPACT_FMT)
return pystache.render(fmt, self)
示例13: detailed
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def detailed(self):
fmt = inspect.cleandoc(self.DETAILED_FMT_PLAIN)
return pystache.render(fmt, self)
示例14: markdown
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def markdown(self):
DocObject.use_links = False
fmt = inspect.cleandoc(self.DETAILED_FMT_MD)
return pystache.render(fmt, self)
示例15: markdown_links
# 需要导入模块: import pystache [as 别名]
# 或者: from pystache import render [as 别名]
def markdown_links(self):
DocObject.use_links = True
fmt = inspect.cleandoc(self.DETAILED_FMT_MD)
return pystache.render(fmt, self)