/usr/share/pyshared/d_rats/subst.py is in d-rats 0.3.3-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #!/usr/bin/python
import ConfigParser
import platform
sublist = None
class SubstitutionList(object):
delim = "/"
def __init__(self, configfile):
self.config = ConfigParser.ConfigParser()
self.config.read(configfile)
def get_sub(self, key):
if not self.config.has_section("subs") or \
not self.config.has_option("subs", key):
return ""
return self.config.get("subs", key)
def subst(self, string):
while string.count(self.delim) >= 2:
first, _, rest = string.partition(self.delim)
key, _, last = rest.partition(self.delim)
sub = self.get_sub(key)
print "Substitution for %s was: %s" % (key, sub)
string = first + sub + last
return string
def load_subs():
global sublist
if sublist:
return True
f = platform.get_platform().config_file("subst.conf")
if not f:
return False
sublist = SubstitutionList(f)
return True
def subst_string(string):
if not load_subs():
print "Unable to load substitution list"
return string
else:
return sublist.subst(string)
if __name__ == "__main__":
print subst_string("Status: /10-14/")
|