Coverage for mfutil/jinja2_extensions.py: 0%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-13 15:33 +0000

1import uuid 

2import hashlib 

3from jinja2.ext import Extension 

4 

5 

6def uuid_filter(value): 

7 v = str(uuid.uuid4()) + value 

8 return hashlib.md5(v.encode()).hexdigest() 

9 

10 

11class UUIDExtension(Extension): 

12 def __init__(self, environment): 

13 super(UUIDExtension, self).__init__(environment) 

14 environment.filters['uuid'] = uuid_filter 

15 

16 

17def alnum_filter(value): 

18 return ''.join(c for c in value if c.isalnum()) 

19 

20 

21class AlphaNumericExtension(Extension): 

22 def __init__(self, environment): 

23 super(AlphaNumericExtension, self).__init__(environment) 

24 environment.filters['alnum'] = alnum_filter