parse(dict) -> string This method parses the open file object passed, replacing any keys found using the replacement dictionary passed.
(self, dict, header=TRUE)
| 51 | raise OpagMissingPrecondition, "%s does not exist" % self.template |
| 52 | |
| 53 | def parse(self, dict, header=TRUE): |
| 54 | """parse(dict) -> string |
| 55 | This method parses the open file object passed, replacing any keys |
| 56 | found using the replacement dictionary passed.""" |
| 57 | if type(dict) != types.DictType: |
| 58 | raise TypeError, "Second argument must be a dictionary" |
| 59 | if not self.template: |
| 60 | raise OpagMissingPrecondition, "template path is not set" |
| 61 | # Open the file if its not already open. If it is, seek to the |
| 62 | # beginning of the file. |
| 63 | if not self.template_file: |
| 64 | self.template_file = open(self.template, "r") |
| 65 | else: |
| 66 | self.template_file.seek(0) |
| 67 | # Instantiate a new bound method to do the replacement. |
| 68 | replacer = Replacer(dict).replace |
| 69 | # Read in the entire template into memory. I guess we'd better keep |
| 70 | # the templates a reasonable size if we're going to keep doing this. |
| 71 | buffer = self.template_file.read() |
| 72 | replaced = "" |
| 73 | if header: |
| 74 | replaced = "Content-Type: text/html\n\n" |
| 75 | replaced = replaced + re.sub("%%(\w+)%%", replacer, buffer) |
| 76 | return replaced |
| 77 | |
| 78 | class OpagRuntimeError(RuntimeError): |
| 79 | """The purpose of this class is to act as the base class for all runtime |
no test coverage detected