-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyapping.py
37 lines (32 loc) · 1.15 KB
/
yapping.py
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
import re
class Yapping:
def __init__(self, config):
self.config = config
def exuberant_elaboration(self, text):
# Apply verbose rules
for rule in self.config.get('verbose_rules', []):
pattern = re.compile(rule['pattern'])
replacement = rule['replacement']
text = pattern.sub(replacement, text)
return text
def speculative_shushing(self, text):
# Apply brief rules
for rule in self.config.get('brief_rules', []):
pattern = re.compile(rule['pattern'])
replacement = rule['replacement']
text = pattern.sub(replacement, text)
return text
def make_verbose(yapping_instance):
def decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return yapping_instance.exuberant_elaboration(result)
return wrapper
return decorator
def make_brief(yapping_instance):
def decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
return yapping_instance.speculative_shushing(result)
return wrapper
return decorator