Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ __pycache__/
# C extensions
*.so

# Local data and mappings
data/
mappings/

# Distribution / packaging
.Python
build/
Expand Down
16 changes: 16 additions & 0 deletions thebeast/contrib/jinja_custom_filters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import re

def regex_search(string, pattern):
# Search for a pattern in the given string.

match = re.search(pattern, string)
return match.group(0) if match else None

def regex_match(string, pattern):
#Check if the entire string matches the pattern.
return bool(re.fullmatch(pattern, string))

def regex_replace(string, pattern, replacement):
#Replace occurrences of the pattern with the replacement in the string.

return re.sub(pattern, replacement, string)
5 changes: 5 additions & 0 deletions thebeast/digest/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@


from jinja2 import Environment, BaseLoader, select_autoescape
from thebeast.contrib.jinja_custom_filters import regex_search, regex_match, regex_replace

from followthemoney.schema import Schema # type: ignore
from thebeast.contrib.ftm_ext.rigged_entity_proxy import StrProxy

from .utils import generate_pseudo_id, jmespath_results_as_array, resolve_callable, ensure_list

# TODO: expose jmespath to templates as a filter?
jinja_env = Environment(loader=BaseLoader(), autoescape=select_autoescape())
jinja_env.filters['regex_search'] = regex_search
jinja_env.filters['regex_match'] = regex_match
jinja_env.filters['regex_replace'] = regex_replace


@dataclass
Expand Down