-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.py
More file actions
41 lines (30 loc) · 722 Bytes
/
Copy pathfilter.py
File metadata and controls
41 lines (30 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from kamidana import (
as_filter,
)
from jinja2 import pass_context
import base64
import re
@as_filter
@pass_context
def regex_replace(ctx, v, pattern, repl, count=0, flags=0):
return re.sub(pattern, repl, v, count, flags)
@as_filter
@pass_context
def ternary(ctx, v, true_val, false_val, null_val=None):
if v:
return true_val
if null_val is not None and v is None:
return null_val
return false_val
@as_filter
@pass_context
def b64encode(ctx, v, *, encoding='utf-8'):
return base64.b64encode(v.encode(encoding))
@as_filter
@pass_context
def b64decode(ctx, v, *, encoding='utf-8'):
return base64.b64decode(v).decode(encoding)
@as_filter
@pass_context
def typeof(ctx, v):
return type(v)