本文整理汇总了Python中jinja2.select_autoescape方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.select_autoescape方法的具体用法?Python jinja2.select_autoescape怎么用?Python jinja2.select_autoescape使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2
的用法示例。
在下文中一共展示了jinja2.select_autoescape方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def __init__(self, app, app_type=None, config_path=None, config_url=None,
url_prefix='/api/doc', title='API doc', editor=False):
self._app = app
self._title = title
self._url_prefix = url_prefix.rstrip('/')
self._config_url = config_url
self._config_path = config_path
self._editor = editor
assert self._config_url or self._config_path, 'config_url or config_path is required!'
self._env = Environment(
loader=FileSystemLoader(str(CURRENT_DIR.joinpath('templates'))),
autoescape=select_autoescape(['html'])
)
if app_type and hasattr(self, '_{}_handler'.format(app_type)):
getattr(self, '_{}_handler'.format(app_type))()
else:
self._auto_match_handler()
示例2: main
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def main():
if OUTPUT_DIR.exists():
shutil.rmtree(OUTPUT_DIR)
OUTPUT_DIR.mkdir()
env = Environment(
loader=FileSystemLoader('templates'),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.get_template('index.html')
with open(OUTPUT_DIR / 'index.html', 'w') as f:
f.write(template.render(years=get_years()))
render_year_pages(env)
render_solution_pages(env)
for file in STATIC_DIR.glob('*'):
shutil.copy(file, OUTPUT_DIR / file.name)
示例3: _get_jinja_template
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def _get_jinja_template(self, template_file=None):
""""""
# First, try to read provided configuration file if given
if template_file:
self.logger.debug("\tTry to load provided jinja template file")
try:
with open(template_file) as fp:
template = jinja2.Template(fp.read())
return template
except (FileNotFoundError, IOError, jinja2.exceptions.TemplateNotFound, jinja2.exceptions.TemplateSyntaxError):
self.logger.debug ("\t\tFile not found, non-readable or invalid")
# Last use the default harcoded config_dict
self.logger.debug ("\tRead default jinja template")
env = jinja2.Environment (
loader=jinja2.PackageLoader('pycoQC', 'templates'),
autoescape=jinja2.select_autoescape(["html"]))
template = env.get_template('spectre.html.j2')
return template
示例4: decorate
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def decorate(self, response: StoqResponse) -> DecoratorResponse:
"""
Decorate results using a template
"""
results = None
try:
dirname = os.path.dirname(self.template)
basename = os.path.basename(self.template)
env = Environment(
loader=FileSystemLoader(dirname),
trim_blocks=True,
lstrip_blocks=True,
autoescape=select_autoescape(default_for_string=True, default=True),
)
results = env.get_template(basename).render(response=response)
except TemplateNotFound:
raise StoqPluginException(f'Template path not found: {self.template}')
return DecoratorResponse(results)
示例5: dispatch_request
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def dispatch_request(self, request):
env = Environment(
loader=PackageLoader("revelation", "templates"),
autoescape=select_autoescape(["html"]),
)
context = {
"meta": self.config.get("REVEAL_META"),
"slides": self.load_slides(
self.presentation,
self.config.get("REVEAL_SLIDE_SEPARATOR"),
self.config.get("REVEAL_VERTICAL_SLIDE_SEPARATOR"),
),
"config": self.config.get("REVEAL_CONFIG"),
"theme": self.get_theme(self.config.get("REVEAL_THEME")),
"style": self.style,
"reloader": self.reloader,
}
template = env.get_template("presentation.html")
return Response(
template.render(**context), headers={"content-type": "text/html"}
)
示例6: render
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def render(message, template_name, context=None):
context = context or {}
base_dir = os.path.join(os.getcwd(), 'templates')
paths = [base_dir]
paths.extend(settings.TEMPLATES)
env = Environment(
loader=FileSystemLoader(paths),
autoescape=select_autoescape(['html']))
template = env.get_template(template_name)
default_context = {
'user': message.user,
'platform': message.platform,
}
default_context.update(context)
return template.render(**default_context)
示例7: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def __init__(self, overwrite_enabled=False, root=None):
self.overwrite_enabled = overwrite_enabled
self.root = Path(root) if root else Path.cwd()
self.settings_path = self.root / SETTINGS_FILENAME
self.type_info = None
self.language = None
self._plugin = None
self.settings = None
self.schema = None
self.runtime = "noexec"
self.entrypoint = None
self.test_entrypoint = None
self.env = Environment(
trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
loader=PackageLoader(__name__, "templates/"),
autoescape=select_autoescape(["html", "htm", "xml", "md"]),
)
self.env.filters["escape_markdown"] = escape_markdown
LOG.debug("Root directory: %s", self.root)
示例8: _init_file_template
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def _init_file_template(path, run_dest=None, filters=None):
"""Returns template for path or None if path is not a text file.
Raises TemplateError if path does not exist or cannot be parsed as
a template.
"""
if not os.path.exists(path):
raise TemplateError("%s does not exist" % path)
if not util.is_text_file(path):
return None
dirname, basename = os.path.split(path)
templates_home = _local_path("templates")
env = jinja2.Environment(
loader=jinja2.FileSystemLoader([dirname, templates_home]),
autoescape=jinja2.select_autoescape(['html', 'xml']),
)
RunFilters(run_dest).install(env)
if filters:
env.filters.update(filters)
try:
return env.get_template(basename)
except jinja2.TemplateError as e:
raise TemplateError(e)
示例9: make_app
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def make_app(config):
app = aiohttp.web.Application(middlewares=[trust_x_forwarded_for])
app["config"] = config
# Check configured base url.
assert config.get("server", "base_url").startswith("http")
assert config.get("server", "base_url").endswith("/")
# Configure templating.
app["jinja"] = jinja2.Environment(
loader=jinja2.FileSystemLoader("templates"),
autoescape=jinja2.select_autoescape(["html"]))
app["jinja"].globals["DEFAULT_FEN"] = DEFAULT_FEN
app["jinja"].globals["STARTING_FEN"] = chess.STARTING_FEN
app["jinja"].globals["development"] = config.getboolean("server", "development")
app["jinja"].globals["asset_url"] = asset_url
app["jinja"].globals["kib"] = kib
# Load stats.
with open("stats.json") as f:
app["stats"] = json.load(f)
# Setup routes.
app.router.add_routes(routes)
app.router.add_static("/static", "static")
app.router.add_route("GET", "/checksums/bytes.tsv", static("checksums/bytes.tsv"))
app.router.add_route("GET", "/checksums/tbcheck.txt", static("checksums/tbcheck.txt", content_type="text/plain"))
app.router.add_route("GET", "/checksums/PackManifest", static("checksums/PackManifest", content_type="text/plain"))
app.router.add_route("GET", "/checksums/B2SUM", static("checksums/B2SUM", content_type="text/plain"))
app.router.add_route("GET", "/checksums/MD5SUM", static("checksums/MD5SUM", content_type="text/plain"))
app.router.add_route("GET", "/checksums/SHA1SUM", static("checksums/SHA1SUM", content_type="text/plain"))
app.router.add_route("GET", "/checksums/SHA256SUM", static("checksums/SHA256SUM", content_type="text/plain"))
app.router.add_route("GET", "/checksums/SHA512SUM", static("checksums/SHA512SUM", content_type="text/plain"))
app.router.add_route("GET", "/endgames.pgn", static("stats/regular/maxdtz.pgn", content_type="application/x-chess-pgn"))
app.router.add_route("GET", "/stats.json", static("stats.json"))
return app
示例10: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def __init__(self, language, app_type, github_pat, github_repository):
super(GithubYamlManager, self).__init__(pat=github_pat)
self._github_repo_mgr = GithubRepositoryManager(pat=github_pat)
self._github_repository = github_repository
self._language = language
self._app_type = app_type
self.jinja_env = Environment(
loader=FileSystemLoader(path.join(path.abspath(path.dirname(__file__)), 'templates')),
autoescape=select_autoescape(['jinja'])
)
示例11: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def __init__(self, language, app_type):
"""Inits YamlManager as to be able generate the yaml files easily"""
self._language = language
self._app_type = app_type
self.jinja_env = Environment(
loader=FileSystemLoader(path.join(path.abspath(path.dirname(__file__)), 'templates')),
autoescape=select_autoescape(['jinja'])
)
示例12: new_template_env
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def new_template_env(parent_package, tmp_folder):
# type: (str, str) -> Environment
return Environment(trim_blocks=True,
lstrip_blocks=True,
keep_trailing_newline=True,
autoescape=select_autoescape(default_for_string=False),
loader=PackageLoader(parent_package, package_path=tmp_folder),
enable_async=False,
)
示例13: __init__
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def __init__(self, package_name, template_dir):
self.template_env = Environment(
loader=PackageLoader(package_name, template_dir),
autoescape=select_autoescape(['html'])
)
示例14: render_html
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def render_html(config):
env = Environment(
loader=PackageLoader('adr_viewer', 'templates'),
autoescape=select_autoescape(['html', 'xml'])
)
template = env.get_template('index.html')
return template.render(config=config)
示例15: verify_generated_artifact
# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import select_autoescape [as 别名]
def verify_generated_artifact(template_file, config_file, expected_file):
env = Environment(loader = FileSystemLoader('./'), trim_blocks=True, lstrip_blocks=True, autoescape=select_autoescape(['yaml']))
tmpl = env.get_template(template_file)
output_from_parsed_template = tmpl.render(config_file)
with open('test_generated_artifact.yml', "w+") as f:
f.write(output_from_parsed_template)
comparison_result = filecmp.cmp('test_generated_artifact.yml', expected_file)
return comparison_result