Classes Again !
Graeme Matthew
graeme.matthew at unite.com.au
Wed Apr 17 09:14:05 EDT 2002
Hi all I am going mad again, but making progress, been on a problem for 1
hour already and cannot see the cause ! please could someone help
The getSubDocument method in my template class is failing suddenly , i dont
have a clue why ! thanks a mil
ERROR:
Traceback (most recent call last):
File "C:\www\cgi-bin\main.cgi", line 10, in ?
data = t.getSubDocument('C:/www/templates/template_org_query.html')
AttributeError: Template instance has no attribute 'getSubDocument'
CGI SCRIPT BELOW
#! C:/python22/python.exe
import sys
sys.path.insert(0,'C:/www/classes/')
import Template
t = Template.Template('C:/www/templates/template_main.html')
t.loadTemplate()
data = "hello mom"
data = t.getSubDocument('C:/www/templates/template_org_query.html')
t.replaceDirective('workbench',data)
print "Content-type: text/html\n\n";
print t.document()
CLASS BELOW:
import re
class Template:
def __init__(self, filename):
self.filename = filename
self.subdoc = none
def loadTemplate(self):
f = open(self.filename,'rb')
self.data = f.read()
f.close
def replaceDirective(self, directive, data):
prog = re.compile('<!--\s*' + directive + '\s*-->.*?<!--\s*' +
directive + '\s*-->',re.DOTALL | re.IGNORECASE)
self.data = prog.sub(data,self.data)
def document(self):
return self.data
def getSubDocument(self, fil):
f = open(fil,'rb')
self.subdoc = f.read()
f.close
prog = re.compile('<body>(.*)</body>',re.DOTALL,re.IGNORECASE)
result = prog.match(self.subdoc)
if result != none:
self.subdoc = result.group(0)
else:
self.subdoc = '<parse error: no data, is it the correct file ?'
return self.subdoc
More information about the Python-list
mailing list