def get_environment(): return jinja2.Environment( loader=jinja2.FileSystemLoader(str(STATIC_PATH)), autoescape=select_autoescape(["HTML"]), trim_blocks=True, lstrip_blocks=True, )
def loadJinjaEnv(self): env = Environment( #loader=PackageLoader('hsJinja',self.template_folder), loader=FileSystemLoader(searchpath=self.template_folder), extensions=["jinja2.ext.do", blog_commentsExtension, blog_social_sharingExtension, blog_subscribeExtension, booleanExtension, choiceExtension, colorExtension, ctaExtension, email_simple_subscriptionExtension, email_subscriptionsExtension, email_subscriptions_confirmationExtension, formExtension, galleryExtension, global_partialExtension, headerExtension, iconExtension, image_srcExtension, imageExtension, language_switcherExtension, linked_imageExtension, logoExtension, menuExtension, moduleExtension, page_footerExtension, password_promptExtension, post_filterExtension, post_listingExtension, raw_htmlExtension, related_blog_postsExtension, require_cssExtension, require_headExtension, require_jsExtension, rich_textExtension, rss_listingExtension, section_headerExtension, simple_menuExtension, social_sharingExtension, spaceExtension, textExtension, textareaExtension, video_playerExtension, widget_containerExtension ], autoescape=select_autoescape(["html","xml"]), auto_reload=True, cache_size=0 #disable cache so it rebuilds when watching for changes ) env.trim_blocks = True env.lstrip_blocks = True env.strip_trailing_newlines = True print(self.template_folder) return env
def test_autoescape_select(self): func = select_autoescape( enabled_extensions=('html', '.htm'), disabled_extensions=('txt', ), default_for_string='STRING', default='NONE', ) assert func(None) == 'STRING' assert func('unknown.foo') == 'NONE' assert func('foo.html') == True assert func('foo.htm') == True assert func('foo.txt') == False assert func('FOO.HTML') == True assert func('FOO.TXT') == False
def test_autoescape_select(self): func = select_autoescape( enabled_extensions=("html", ".htm"), disabled_extensions=("txt", ), default_for_string="STRING", default="NONE", ) assert func(None) == "STRING" assert func("unknown.foo") == "NONE" assert func("foo.html") assert func("foo.htm") assert not func("foo.txt") assert func("FOO.HTML") assert not func("FOO.TXT")
def test_autoescape_select(self): func = select_autoescape( enabled_extensions=('html', '.htm'), disabled_extensions=('txt',), default_for_string='STRING', default='NONE', ) assert func(None) == 'STRING' assert func('unknown.foo') == 'NONE' assert func('foo.html') == True assert func('foo.htm') == True assert func('foo.txt') == False assert func('FOO.HTML') == True assert func('FOO.TXT') == False
def __init__(self, pg_info, template_dir, static_dir, template_cache): self._pg_info = pg_info self._template_dir = template_dir self._static_dir = static_dir self._template_cache = template_cache self._templates = {} self._tpl_loader = Environment( loader=FileSystemLoader(self._template_dir, encoding='utf-8'), autoescape=select_autoescape(enabled_extensions=('html', ), default_for_string=True, default=True)) models.connect(pg_info.get('host', 'localhost'), pg_info.get('port', 5432), pg_info.get('user', 'sr2'), pg_info.get('pw', 'sr2miro'), pg_info.get('db', 'sr2'))
def __init__(self, pg_info, template_dir, static_dir, template_cache): self._pg_info = pg_info self._template_dir = template_dir self._static_dir = static_dir self._template_cache = template_cache self._templates = {} self._tpl_loader = Environment( loader=FileSystemLoader(self._template_dir, encoding='utf-8'), autoescape=select_autoescape( enabled_extensions=('html',), default_for_string=True, default=True ) ) models.connect( pg_info.get('host', 'localhost'), pg_info.get('port', 5432), pg_info.get('user', 'sr2'), pg_info.get('pw', 'sr2miro'), pg_info.get('db', 'sr2') )
resolve_external_file_path, resolve_local_file_path, ) from helpers.logging_manager import LoggingManager from helpers.device_manager import DeviceManager from helpers.state_manager import StateManager from helpers.the_terminator import Terminator from helpers.normalisation import get_normalised_filename_if_available from helpers.myradio_api import MyRadioAPI from helpers.alert_manager import AlertManager import package from baps_types.happytime import happytime env = Environment( loader=FileSystemLoader("%s/ui-templates/" % os.path.dirname(__file__)), autoescape=select_autoescape(), ) LOG_FILEPATH = resolve_external_file_path("logs") LOG_FILENAME = LOG_FILEPATH + "/WebServer.log" # From Sanic's default, but set to log to file. os.makedirs(LOG_FILEPATH, exist_ok=True) LOGGING_CONFIG = dict( version=1, disable_existing_loggers=False, loggers={ "sanic.root": { "level": "INFO", "handlers": ["file"] }, "sanic.error": {
'香港', } def get_territory_name(territory: Union[Locale, str], language: Locale) -> str: if isinstance(territory, Locale): territory = territory.territory return territory_names.get((territory, language), language.territories[territory]) template_loader = FileSystemLoader( os.path.join(os.path.dirname(__file__), 'templates')) template_env = Environment( loader=template_loader, autoescape=select_autoescape(['html']), extensions=['jinja2.ext.do'], ) template_env.filters.update( dictselect=contextfilter( lambda ctx, dict, test=None, *args, **kwargs: { k: v for k, v in dict.items() if (ctx.environment.call_test( test, v, *args, **kwargs) if test else v) }), territory_name=get_territory_name, zip=zip, ) table_template = template_env.get_template('table.html')