rvrdata.jinja2.filters
Custom filters for Jinja2 environments.
All functions added to this module are made available as custom filters in rvrdata.
See https://jinja.palletsprojects.com/en/3.0.x/api/#writing-filters
env_override(value, key)
Retrieve an environment variable and override value.
Works with jinja2 filters in the following format: : “test” : {{ “default” | env_override(‘CUSTOM’) }}
regex_replace(s, find, replace)
Replace text using a non-optimal implementation of a regex filter.
str_to_utc_str(date_str, date_format)
Convert a date string to UTC ISO8601 Shorthand format.
Current implementation is timezone naive and assumes UTC.
For a list of date format codes, see: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes
is_ip(address)
Test if string is a valid IP address or network.
ip_address(address)
Convert a string or integer into an IP address.
See https://docs.python.org/3/howto/ipaddress.html
ip_network(network, strict=False)
Convert a string or integer into an IP network.
See https://docs.python.org/3/howto/ipaddress.html
ip_interface(address)
Convert a string or integer into an IP interface.
See https://docs.python.org/3/howto/ipaddress.html
is_subnet_of(cidr_a, cidr_b)
Check if a CIDR block (eg. x.x.x.x/yy) is child of another CIDR block.
The strings provided must be valid CIDR blocks or else a ValueError will be raised.
first_ip_address(cidr)
Get the first IP address of a CIDR block.
netmask_to_cidr(network_netmask)
Return the CIDR block version of network and netmask.
required(val, msg='', show_val=False, patt='')
Check if variable has a value.
Test for empty strings or missing values. For numbers, 0 is allowed, as is ‘False’ for booleans.
- Parameters:
- val (Any) – the value being tested.
- msg (str) – optional message returned if check fails.
- show_val (bool) – optional show value in error message.
- patt (str) – optional regex pattern to test for.