Commit ba0c66bc authored by 's avatar

merged from 2.2 branch - started adding roles assertions to all

private methods of base classes starting in DocumentTemplate,
since it will not be able to use the new security assertion
machinery without being dependent on Zope.
parent 4b25bd98
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""HTML formated DocumentTemplates """HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.23 1999/10/22 14:17:00 jim Exp $""" $Id: DT_HTML.py,v 1.24 2000/08/17 14:03:42 brian Exp $"""
from DT_String import String, FileMixin from DT_String import String, FileMixin
import DT_String, regex import DT_String, regex
...@@ -212,9 +212,11 @@ class HTML(DT_String.String): ...@@ -212,9 +212,11 @@ class HTML(DT_String.String):
are inserted into HTML editing forms. are inserted into HTML editing forms.
""" """
tagre__roles__=()
def tagre(self): def tagre(self):
return dtml_re_class() return dtml_re_class()
parseTag__roles__=()
def parseTag(self, tagre, command=None, sargs=''): def parseTag(self, tagre, command=None, sargs=''):
"""Parse a tag using an already matched re """Parse a tag using an already matched re
...@@ -250,15 +252,19 @@ class HTML(DT_String.String): ...@@ -250,15 +252,19 @@ class HTML(DT_String.String):
except KeyError: except KeyError:
raise ParseError, ('Unexpected tag', tag) raise ParseError, ('Unexpected tag', tag)
SubTemplate__roles__=()
def SubTemplate(self, name): return HTML('', __name__=name) def SubTemplate(self, name): return HTML('', __name__=name)
varExtra__roles__=()
def varExtra(self,tagre): return 's' def varExtra(self,tagre): return 's'
manage_edit__roles__=()
def manage_edit(self,data,REQUEST=None): def manage_edit(self,data,REQUEST=None):
'edit a template' 'edit a template'
self.munge(data) self.munge(data)
if REQUEST: return self.editConfirmation(self,REQUEST) if REQUEST: return self.editConfirmation(self,REQUEST)
quotedHTML__roles__=()
def quotedHTML(self, def quotedHTML(self,
text=None, text=None,
character_entities=( character_entities=(
...@@ -271,16 +277,20 @@ class HTML(DT_String.String): ...@@ -271,16 +277,20 @@ class HTML(DT_String.String):
if find(text, re) >= 0: text=join(split(text,re),name) if find(text, re) >= 0: text=join(split(text,re),name)
return text return text
errQuote__roles__=()
errQuote=quotedHTML errQuote=quotedHTML
def __str__(self): def __str__(self):
return self.quotedHTML() return self.quotedHTML()
# these should probably all be deprecated.
management_interface__roles__=()
def management_interface(self): def management_interface(self):
'''Hook to allow public execution of management interface with '''Hook to allow public execution of management interface with
everything else private.''' everything else private.'''
return self return self
manage_editForm__roles__=()
def manage_editForm(self, URL1, REQUEST): def manage_editForm(self, URL1, REQUEST):
'''Display doc template editing form''' #" '''Display doc template editing form''' #"
...@@ -291,6 +301,8 @@ class HTML(DT_String.String): ...@@ -291,6 +301,8 @@ class HTML(DT_String.String):
URL1=URL1 URL1=URL1
) )
manage_editDocument__roles__=()
manage__roles__=()
manage_editDocument=manage=manage_editForm manage_editDocument=manage=manage_editForm
class HTMLDefault(HTML): class HTMLDefault(HTML):
...@@ -300,8 +312,10 @@ class HTMLDefault(HTML): ...@@ -300,8 +312,10 @@ class HTMLDefault(HTML):
This is to make a distinction from HTML objects that should edit This is to make a distinction from HTML objects that should edit
themselves in place. themselves in place.
''' '''
copy_class__roles__=()
copy_class=HTML copy_class=HTML
manage_edit__roles__=()
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__)
...@@ -319,7 +333,7 @@ class HTMLFile(FileMixin, HTML): ...@@ -319,7 +333,7 @@ class HTMLFile(FileMixin, HTML):
Note that the file will not be read until the document Note that the file will not be read until the document
template is used the first time. template is used the first time.
""" """
manage_default__roles__=()
def manage_default(self, REQUEST=None): def manage_default(self, REQUEST=None):
'Revert to factory defaults' 'Revert to factory defaults'
if self.edited_source: if self.edited_source:
...@@ -327,6 +341,7 @@ class HTMLFile(FileMixin, HTML): ...@@ -327,6 +341,7 @@ class HTMLFile(FileMixin, HTML):
self._v_cooked=self.cook() self._v_cooked=self.cook()
if REQUEST: return self.editConfirmation(self,REQUEST) if REQUEST: return self.editConfirmation(self,REQUEST)
manage_editForm__roles__=()
def manage_editForm(self, URL1, REQUEST): def manage_editForm(self, URL1, REQUEST):
'''Display doc template editing form''' '''Display doc template editing form'''
...@@ -343,8 +358,11 @@ class HTMLFile(FileMixin, HTML): ...@@ -343,8 +358,11 @@ class HTMLFile(FileMixin, HTML):
__str__=str(self), __str__=str(self),
FactoryDefaultString=FactoryDefaultString, FactoryDefaultString=FactoryDefaultString,
) )
manage_editDocument__roles__=()
manage__roles__=()
manage_editDocument=manage=manage_editForm manage_editDocument=manage=manage_editForm
manage_edit__roles__=()
def manage_edit(self,data, def manage_edit(self,data,
PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT=''): PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT=''):
'edit a template' 'edit a template'
......
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
# attributions are listed in the accompanying credits file. # attributions are listed in the accompanying credits file.
# #
############################################################################## ##############################################################################
"$Id: DT_String.py,v 1.36 2000/06/15 18:50:47 brian Exp $" "$Id: DT_String.py,v 1.37 2000/08/17 14:03:42 brian Exp $"
from string import split, strip from string import split, strip
import regex, ts_regex import regex, ts_regex
...@@ -118,15 +118,21 @@ class String: ...@@ -118,15 +118,21 @@ class String:
func_code=func_code() func_code=func_code()
func_code.co_varnames='self','REQUEST' func_code.co_varnames='self','REQUEST'
func_code.co_argcount=2 func_code.co_argcount=2
func_code.__roles__=()
func_defaults__roles__=()
func_defaults=() func_defaults=()
errQuote__roles__=()
def errQuote(self, s): return s def errQuote(self, s): return s
parse_error__roles__=()
def parse_error(self, mess, tag, text, start): def parse_error(self, mess, tag, text, start):
raise ParseError, "%s, for tag %s, on line %s of %s<p>" % ( raise ParseError, "%s, for tag %s, on line %s of %s<p>" % (
mess, self.errQuote(tag), len(split(text[:start],'\n')), mess, self.errQuote(tag), len(split(text[:start],'\n')),
self.errQuote(self.__name__)) self.errQuote(self.__name__))
commands__roles__=()
commands={ commands={
'var': Var, 'var': Var,
'call': Call, 'call': Call,
...@@ -142,8 +148,11 @@ class String: ...@@ -142,8 +148,11 @@ class String:
'return': ReturnTag, 'return': ReturnTag,
} }
def SubTemplate(self, name): return String('', __name__=name) SubTemplate__roles__=()
def SubTemplate(self, name):
return String('', __name__=name)
tagre__roles__=()
def tagre(self): def tagre(self):
return regex.symcomp( return regex.symcomp(
'%(' # beginning '%(' # beginning
...@@ -155,6 +164,7 @@ class String: ...@@ -155,6 +164,7 @@ class String:
')\(<fmt>[0-9]*[.]?[0-9]*[a-z]\|[]![]\)' # end ')\(<fmt>[0-9]*[.]?[0-9]*[a-z]\|[]![]\)' # end
, regex.casefold) , regex.casefold)
_parseTag__roles__=()
def _parseTag(self, tagre, command=None, sargs='', tt=type(())): def _parseTag(self, tagre, command=None, sargs='', tt=type(())):
tag, args, command, coname = self.parseTag(tagre,command,sargs) tag, args, command, coname = self.parseTag(tagre,command,sargs)
if type(command) is tt: if type(command) is tt:
...@@ -167,7 +177,8 @@ class String: ...@@ -167,7 +177,8 @@ class String:
command=d[name] command=d[name]
self.commands[cname]=command self.commands[cname]=command
return tag, args, command, coname return tag, args, command, coname
parseTag__roles__=()
def parseTag(self, tagre, command=None, sargs=''): def parseTag(self, tagre, command=None, sargs=''):
"""Parse a tag using an already matched re """Parse a tag using an already matched re
...@@ -208,8 +219,11 @@ class String: ...@@ -208,8 +219,11 @@ class String:
args=args and ("%s %s" % (name, args)) or name args=args and ("%s %s" % (name, args)) or name
return tag, args, Var, None return tag, args, Var, None
def varExtra(self,tagre): return tagre.group('fmt') varExtra__roles__=()
def varExtra(self,tagre):
return tagre.group('fmt')
parse__roles__=()
def parse(self,text,start=0,result=None,tagre=None): def parse(self,text,start=0,result=None,tagre=None):
if result is None: result=[] if result is None: result=[]
if tagre is None: tagre=self.tagre() if tagre is None: tagre=self.tagre()
...@@ -240,12 +254,14 @@ class String: ...@@ -240,12 +254,14 @@ class String:
if text: result.append(text) if text: result.append(text)
return result return result
skip_eol__roles__=()
def skip_eol(self, text, start, eol=regex.compile('[ \t]*\n')): def skip_eol(self, text, start, eol=regex.compile('[ \t]*\n')):
# if block open is followed by newline, then skip past newline # if block open is followed by newline, then skip past newline
l=eol.match(text,start) l=eol.match(text,start)
if l > 0: start=start+l if l > 0: start=start+l
return start return start
parse_block__roles__=()
def parse_block(self, text, start, result, tagre, def parse_block(self, text, start, result, tagre,
stag, sloc, sargs, scommand): stag, sloc, sargs, scommand):
...@@ -292,7 +308,8 @@ class String: ...@@ -292,7 +308,8 @@ class String:
except ParseError, m: self.parse_error(m[0],stag,text,l) except ParseError, m: self.parse_error(m[0],stag,text,l)
return start return start
parse_close__roles__=()
def parse_close(self, text, start, tagre, stag, sloc, scommand, sa): def parse_close(self, text, start, tagre, stag, sloc, scommand, sa):
while 1: while 1:
l=tagre.search(text,start) l=tagre.search(text,start)
...@@ -309,6 +326,7 @@ class String: ...@@ -309,6 +326,7 @@ class String:
command,args) command,args)
elif not coname: return start elif not coname: return start
shared_globals__roles__=()
shared_globals={} shared_globals={}
def __init__(self, source_string='', mapping=None, __name__='<string>', def __init__(self, source_string='', mapping=None, __name__='<string>',
...@@ -323,12 +341,14 @@ class String: ...@@ -323,12 +341,14 @@ class String:
self.initvars(mapping, vars) self.initvars(mapping, vars)
self.setName(__name__) self.setName(__name__)
def name(self): return self.__name__ def name(self): return self.__name__
id=name id=name
setName__roles__=[] setName__roles__=[]
def setName(self,v): self.__dict__['__name__']=v def setName(self,v): self.__dict__['__name__']=v
default__roles__=()
def default(self,name=None,**kw): def default(self,name=None,**kw):
"""\ """\
Change or query default values in a document template. Change or query default values in a document template.
...@@ -342,6 +362,7 @@ class String: ...@@ -342,6 +362,7 @@ class String:
for key in kw.keys(): self.globals[key]=kw[key] for key in kw.keys(): self.globals[key]=kw[key]
return name return name
var__roles__=()
def var(self,name=None,**kw): def var(self,name=None,**kw):
"""\ """\
Change or query a variable in a document template. Change or query a variable in a document template.
...@@ -355,7 +376,7 @@ class String: ...@@ -355,7 +376,7 @@ class String:
for key in kw.keys(): self._vars[key]=kw[key] for key in kw.keys(): self._vars[key]=kw[key]
return name return name
munge__roles__=[] munge__roles__=()
def munge(self,source_string=None,mapping=None,**vars): def munge(self,source_string=None,mapping=None,**vars):
"""\ """\
Change the text or default values for a document template. Change the text or default values for a document template.
...@@ -366,15 +387,19 @@ class String: ...@@ -366,15 +387,19 @@ class String:
self.raw=source_string self.raw=source_string
self.cook() self.cook()
manage_edit__roles__=()
def manage_edit(self,data,REQUEST=None): def manage_edit(self,data,REQUEST=None):
self.munge(data) self.munge(data)
read_raw__roles__=()
def read_raw(self,raw=None): def read_raw(self,raw=None):
return self.raw return self.raw
read__roles__=()
def read(self,raw=None): def read(self,raw=None):
return self.read_raw() return self.read_raw()
cook__roles__=()
def cook(self, def cook(self,
cooklock=ts_regex.allocate_lock(), cooklock=ts_regex.allocate_lock(),
): ):
...@@ -385,6 +410,7 @@ class String: ...@@ -385,6 +410,7 @@ class String:
finally: finally:
cooklock.release() cooklock.release()
initvars__roles__=()
def initvars(self, globals, vars): def initvars(self, globals, vars):
if globals: if globals:
for k in globals.keys(): for k in globals.keys():
...@@ -505,6 +531,7 @@ class String: ...@@ -505,6 +531,7 @@ class String:
if pushed: md._pop(pushed) # Get rid of circular reference! if pushed: md._pop(pushed) # Get rid of circular reference!
md.level=level # Restore previous level md.level=level # Restore previous level
validate__roles__=()
validate=None validate=None
def __str__(self): def __str__(self):
...@@ -533,6 +560,7 @@ class FileMixin: ...@@ -533,6 +560,7 @@ class FileMixin:
self.initvars(mapping, vars) self.initvars(mapping, vars)
self.setName(__name__ or file_name) self.setName(__name__ or file_name)
read_raw__roles__=()
def read_raw(self): def read_raw(self):
if self.edited_source: return self.edited_source if self.edited_source: return self.edited_source
if self.raw: return open(self.raw,'r').read() if self.raw: return open(self.raw,'r').read()
...@@ -548,4 +576,5 @@ class File(FileMixin, String): ...@@ -548,4 +576,5 @@ class File(FileMixin, String):
Note that the file will not be read until the document Note that the file will not be read until the document
template is used the first time. template is used the first time.
""" """
manage_edit__roles__=()
def manage_edit(self,data): raise TypeError, 'cannot edit files' def manage_edit(self,data): raise TypeError, 'cannot edit files'
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