Commit 470948b3 authored by Jim Fulton's avatar Jim Fulton

Removed old validation machinery.

Added a regex-like parser that doesn't have regex's tendency to hang
the process.  Maybe I'll be able to use re in the future. ;-)

Added errQuote to aid in parse error message generation.
parent 139bce07
"""HTML formated DocumentTemplates """HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.4 1997/09/25 18:56:37 jim Exp $""" $Id: DT_HTML.py,v 1.5 1997/10/27 17:35:32 jim Exp $"""
from DT_String import String, FileMixin from DT_String import String, FileMixin
import DT_Doc, DT_String, regex import DT_Doc, DT_String, regex
from DT_Util import * from DT_Util import *
from regsub import gsub from regsub import gsub
from string import strip from string import strip, find
class dtml_re_class:
def search(self, text, start=0,
name_match=regex.compile('[a-zA-Z]+[\0- ]*').match):
s=find(text,'<!--#',start)
if s < 0: return s
e=find(text,'-->',s)
if e < 0: return e
n=s+5
if text[n:n+1]=='/':
end=text[n:n+1]
n=n+1
elif text[n:n+3]=='end':
end=text[n:n+3]
n=n+3
else:
end=''
l=name_match(text,n)
if l < 0: return l
a=n+l
name=strip(text[n:a])
args=strip(text[a:e])
d=self.__dict__
d[0]=text[s:e+3]
d[1]=end
d['end']= end
d[2]=name
d['name']=name
d[3]=args
d['args']=args
return s
def group(self,*args):
g=self.__dict__
if len(args)==1: return g[args[0]]
r=[]
for arg in args:
r.append(g[arg])
return tuple(r)
class HTML(DT_String.String): class HTML(DT_String.String):
__doc__=DT_Doc.HTML__doc__ __doc__=DT_Doc.HTML__doc__
def tagre(self): def tagre(self):
return dtml_re_class()
return regex.symcomp( return regex.symcomp(
'<!--#' # beginning '<!--#' # beginning
'\(<end>/\|end\)?' # end tag marker '\(<end>/\|end\)?' # end tag marker
...@@ -67,16 +113,19 @@ class HTML(DT_String.String): ...@@ -67,16 +113,19 @@ class HTML(DT_String.String):
if REQUEST: return self.editConfirmation(self,REQUEST) if REQUEST: return self.editConfirmation(self,REQUEST)
def quotedHTML(self, def quotedHTML(self,
text=None,
character_entities=( character_entities=(
(regex.compile('&'), '&amp;'), (regex.compile('&'), '&amp;'),
(regex.compile("<"), '&lt;' ), (regex.compile("<"), '&lt;' ),
(regex.compile(">"), '&gt;' ), (regex.compile(">"), '&gt;' ),
(regex.compile('"'), '&quot;'))): #" (regex.compile('"'), '&quot;'))): #"
text=self.read_raw() if text is None: text=self.read_raw()
for re,name in character_entities: for re,name in character_entities:
text=gsub(re,name,text) text=gsub(re,name,text)
return text return text
errQuote=quotedHTML
def __str__(self): def __str__(self):
return self.quotedHTML() return self.quotedHTML()
...@@ -88,21 +137,15 @@ class HTML(DT_String.String): ...@@ -88,21 +137,15 @@ class HTML(DT_String.String):
def manage_editForm(self, PARENT_URL, REQUEST): def manage_editForm(self, PARENT_URL, REQUEST):
'''Display doc template editing form''' #" '''Display doc template editing form''' #"
self._manage_editForm.validator(self.validate)
return self._manage_editForm( return self._manage_editForm(
self, self,
mapping=REQUEST, mapping=REQUEST,
__str__=str(self), __str__=str(self),
vars=self._names.items(),
PARENT_URL=PARENT_URL PARENT_URL=PARENT_URL
) )
manage_editDocument=manage=manage_editForm manage_editDocument=manage=manage_editForm
def validate(self, key, value=None):
if os.environ.has_key(key): return 1
return 0
class HTMLDefault(HTML): class HTMLDefault(HTML):
'''\ '''\
HTML document templates that edit themselves through copy. HTML document templates that edit themselves through copy.
...@@ -114,8 +157,7 @@ class HTMLDefault(HTML): ...@@ -114,8 +157,7 @@ class HTMLDefault(HTML):
def manage_edit(self,data,PARENTS,URL1,REQUEST): def manage_edit(self,data,PARENTS,URL1,REQUEST):
'edit a template' 'edit a template'
newHTML=self.copy_class(data,self.globals,self.__name__, newHTML=self.copy_class(data,self.globals,self.__name__)
self._names, self._validator)
setattr(PARENTS[1],URL1[rfind(URL1,'/')+1:],newHTML) setattr(PARENTS[1],URL1[rfind(URL1,'/')+1:],newHTML)
return self.editConfirmation(self,REQUEST) return self.editConfirmation(self,REQUEST)
...@@ -139,9 +181,8 @@ class HTMLFile(FileMixin, HTML): ...@@ -139,9 +181,8 @@ class HTMLFile(FileMixin, HTML):
if REQUEST: return self.editConfirmation(self,REQUEST) if REQUEST: return self.editConfirmation(self,REQUEST)
def manage_editForm(self, PARENT_URL, REQUEST): def manage_editForm(self, PARENT_URL, REQUEST):
'''Display doc template editing form''' #" '''Display doc template editing form'''
self._manage_editForm.validator(self.validate)
return self._manage_editForm(mapping=REQUEST, return self._manage_editForm(mapping=REQUEST,
document_template_edit_width= document_template_edit_width=
self.document_template_edit_width, self.document_template_edit_width,
...@@ -153,7 +194,6 @@ class HTMLFile(FileMixin, HTML): ...@@ -153,7 +194,6 @@ class HTMLFile(FileMixin, HTML):
self.document_template_edit_footer, self.document_template_edit_footer,
PARENT_URL=PARENT_URL, PARENT_URL=PARENT_URL,
__str__=str(self), __str__=str(self),
vars=self._names.items(),
FactoryDefaultString=FactoryDefaultString, FactoryDefaultString=FactoryDefaultString,
) )
manage_editDocument=manage=manage_editForm manage_editDocument=manage=manage_editForm
...@@ -178,6 +218,14 @@ class HTMLFile(FileMixin, HTML): ...@@ -178,6 +218,14 @@ class HTMLFile(FileMixin, HTML):
########################################################################## ##########################################################################
# #
# $Log: DT_HTML.py,v $ # $Log: DT_HTML.py,v $
# Revision 1.5 1997/10/27 17:35:32 jim
# Removed old validation machinery.
#
# Added a regex-like parser that doesn't have regex's tendency to hang
# the process. Maybe I'll be able to use re in the future. ;-)
#
# Added errQuote to aid in parse error message generation.
#
# Revision 1.4 1997/09/25 18:56:37 jim # Revision 1.4 1997/09/25 18:56:37 jim
# fixed problem in reporting errors # fixed problem in reporting errors
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment