flexget.utils.template module#
- exception flexget.utils.template.RenderError[source]#
Bases:
ExceptionError raised when there is a problem with jinja rendering.
- class flexget.utils.template.CoercingDateTime[source]#
Bases:
DateTimeDatetime with some features that make it better when used in our templates.
The features are:
Avoids crashing when comparing tz aware and naive datetimes. When this happens, it will assume the naive datetime is in the same timezone as the dt aware one.
Allows comparisons with plain dates, where the date is assumed to be at midnight in the same timezone.
Returns
Intervalwith a nicer string representation for our templates
This allows us to introduce tz aware datetimes into entry fields without breaking old configs, or old plugins.
- class flexget.utils.template.FlexGetEnvironment(block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='\n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, loader=None, cache_size=400, auto_reload=True, bytecode_cache=None, enable_async=False)[source]#
Bases:
EnvironmentEnvironment with template_class support.
- Parameters:
block_start_string (str)
block_end_string (str)
variable_start_string (str)
variable_end_string (str)
comment_start_string (str)
comment_end_string (str)
line_statement_prefix (str | None)
line_comment_prefix (str | None)
trim_blocks (bool)
lstrip_blocks (bool)
newline_sequence (te.Literal['\n', '\r\n', '\r'])
keep_trailing_newline (bool)
optimized (bool)
undefined (Type[Undefined])
loader (BaseLoader | None)
cache_size (int)
auto_reload (bool)
bytecode_cache (BytecodeCache | None)
enable_async (bool)
- class flexget.utils.template.FlexGetNativeTemplate(source, block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='\n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, enable_async=False)[source]#
Bases:
FlexGetTemplate,NativeTemplateLazy lookup support and native python return types.
- Parameters:
source (str | Template)
block_start_string (str)
block_end_string (str)
variable_start_string (str)
variable_end_string (str)
comment_start_string (str)
comment_end_string (str)
line_statement_prefix (str | None)
line_comment_prefix (str | None)
trim_blocks (bool)
lstrip_blocks (bool)
newline_sequence (te.Literal['\n', '\r\n', '\r'])
keep_trailing_newline (bool)
optimized (bool)
undefined (Type[Undefined])
enable_async (bool)
- Return type:
- class flexget.utils.template.FlexGetTemplate(source, block_start_string='{%', block_end_string='%}', variable_start_string='{{', variable_end_string='}}', comment_start_string='{#', comment_end_string='#}', line_statement_prefix=None, line_comment_prefix=None, trim_blocks=False, lstrip_blocks=False, newline_sequence='\n', keep_trailing_newline=False, extensions=(), optimized=True, undefined=<class 'jinja2.runtime.Undefined'>, finalize=None, autoescape=False, enable_async=False)[source]#
Bases:
TemplateAdds lazy lookup support when rendering templates.
- Parameters:
source (str | Template)
block_start_string (str)
block_end_string (str)
variable_start_string (str)
variable_end_string (str)
comment_start_string (str)
comment_end_string (str)
line_statement_prefix (str | None)
line_comment_prefix (str | None)
trim_blocks (bool)
lstrip_blocks (bool)
newline_sequence (te.Literal['\n', '\r\n', '\r'])
keep_trailing_newline (bool)
optimized (bool)
undefined (Type[Undefined])
enable_async (bool)
- Return type:
- new_context(vars=None, shared=False, locals=None)[source]#
Create a new
Contextfor this template. The vars provided will be passed to the template. Per default the globals are added to the context. If shared is set to True the data is passed as is to the context without adding the globals.locals can be a dict of local variables for internal usage.
- class flexget.utils.template.Interval(start, end, absolute=False)[source]#
Bases:
IntervalSame as normal Interval, but gives a better string representation for our templates.
- Parameters:
start (_T)
end (_T)
absolute (bool)
- Return type:
Self
- flexget.utils.template.evaluate_expression(expression, context)[source]#
Evaluate a jinja
expressionusing a givencontextwith support forLazyDict(Entry).- Parameters:
expression (str) – A jinja expression to evaluate
context (Mapping) – dictlike, supporting LazyDicts
- Return type:
Any
- flexget.utils.template.filter_d(value, default_value='', boolean=True)#
Override the built-in Jinja default filter to set the boolean param to True by default.
- flexget.utils.template.filter_date_suffix(date_str)[source]#
Return a date suffix for a given date.
- Parameters:
date_str (str)
- flexget.utils.template.filter_default(value, default_value='', boolean=True)[source]#
Override the built-in Jinja default filter to set the boolean param to True by default.
- flexget.utils.template.filter_format_number(val, places=None, grouping=True)[source]#
Format a number according to the user’s locale.
- flexget.utils.template.filter_format_size(size, si=False, unit=None)[source]#
- Parameters:
size (float)
- flexget.utils.template.filter_formatdate(val, format_str)[source]#
Return a string representation of a datetime object according to format string.
- flexget.utils.template.filter_pad(val, width, fillchar='0')[source]#
Pad a number or string with fillchar to the specified width.
- flexget.utils.template.filter_parse_size(val, si=False, match_re=None)[source]#
Parse human-readable file size to bytes.
- flexget.utils.template.filter_parsedate(val)[source]#
Attempt to parse a date according to the rules in ISO 8601 and RFC 2822.
- flexget.utils.template.filter_pathdir(val='')[source]#
Directory containing the given path.
- Parameters:
- Return type:
- flexget.utils.template.filter_pathname(val='')[source]#
Return base name of a path, without its extension.
- flexget.utils.template.filter_pathscrub(val, os_mode=None)[source]#
Replace problematic characters in a path.
- flexget.utils.template.filter_re_replace(val, pattern, repl)[source]#
Perform a regexp replacement on the given string.
- flexget.utils.template.filter_re_search(val, pattern)[source]#
Perform a search for given regexp pattern, return the matching portion of the text.
- Parameters:
pattern (str)
- flexget.utils.template.filter_to_date(date_time_val)[source]#
Return the date from any date-time object.
- flexget.utils.template.get_filters()[source]#
Return all built-in and custom Jinja filters in a dict.
The key is the name, and the value is the filter func
- Return type:
- flexget.utils.template.get_template(template_name, scope='task')[source]#
Load a template from disk. Looks in both included plugins and users custom scope dir.
- Parameters:
- Return type:
- flexget.utils.template.is_fs_dir(pathname)[source]#
Test whether item is existing directory in filesystem.
- flexget.utils.template.is_fs_file(pathname)[source]#
Test whether item is existing file in filesystem.
- flexget.utils.template.is_fs_link(pathname)[source]#
Test whether item is existing link in filesystem.
- flexget.utils.template.list_templates(extensions=None)[source]#
Return all templates names that are configured under environment loader dirs.
- flexget.utils.template.make_environment(manager)[source]#
Create our environment and add our custom filters.
- Parameters:
manager (Manager)
- Return type:
None
- flexget.utils.template.render(template, context, native=False)[source]#
Render a Template with context as its context.
- Parameters:
template (FlexGetTemplate | str) – Template or template string to render.
context (Mapping) – Context to render the template from.
native (bool) – If True, and the rendering result can be all native python types, not just strings.
- Returns:
The rendered template text.
- Return type: