MCPcopy Create free account
hub / github.com/ActiveState/code / Replacer

Class Replacer

recipes/Python/146460_HTML_Templates/recipe-146460.py:19–35  ·  view source on GitHub ↗

This class is a utility class used to provide a bound method to the re.sub() function.

Source from the content-addressed store, hash-verified

17site_template = 'template.html'
18
19class 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
37class OpagCGI:
38 """This class represents a running instance of a CGI on the OPAG website.

Callers 1

parseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected