This class is a utility class used to provide a bound method to the re.sub() function.
| 17 | site_template = 'template.html' |
| 18 | |
| 19 | class Replacer: |
| 20 | """This class is a utility class used to provide a bound method to the |
| 21 | re.sub() function.""" |
| 22 | def __init__(self, dict): |
| 23 | """The constructor. It's only duty is to populate itself with the |
| 24 | replacement dictionary passed.""" |
| 25 | self.dict = dict |
| 26 | |
| 27 | def replace(self, matchobj): |
| 28 | """The replacement method. This is passed a match object by re.sub(), |
| 29 | which it uses to index the replacement dictionary and find the |
| 30 | replacement string.""" |
| 31 | key = matchobj.group(1) |
| 32 | if self.dict.has_key(key): |
| 33 | return self.dict[key] |
| 34 | else: |
| 35 | return '' |
| 36 | |
| 37 | class OpagCGI: |
| 38 | """This class represents a running instance of a CGI on the OPAG website. |