-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstitutor.py
More file actions
34 lines (26 loc) · 863 Bytes
/
substitutor.py
File metadata and controls
34 lines (26 loc) · 863 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
import re
class Substitutor():
storage = {}
sleepTime = 0
def put(self, key, value):
self.storage[key] = value
def get(self, key, inProgress=None):
if not inProgress:
inProgress = set()
elif key in inProgress:
inProgress.clear()
raise InfiniteRecursionException
if key in self.storage:
out = self.storage[key]
else: return ''
inProgress.add(key)
for templ in set(re.findall(r'\$\{(\S+)\}', out)):
part = self.get(templ, inProgress)
out = out.replace('${' + templ + '}', part)
inProgress.remove(key)
return out
def getSleepTime(self):
return self.sleepTime
def setSleepTime(self, seconds):
Substitutor.sleepTime = seconds
class InfiniteRecursionException(ValueError): pass