Commit 62cce377 authored by Jim Fulton's avatar Jim Fulton

Made use (or non-use) of regex thread safe.

parent 699ed75c
"""HTML formated DocumentTemplates """HTML formated DocumentTemplates
$Id: DT_HTML.py,v 1.6 1998/04/02 17:37:35 jim Exp $""" $Id: DT_HTML.py,v 1.7 1998/08/11 19:32:38 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, find from string import strip, find, split, join
class dtml_re_class: class dtml_re_class:
...@@ -108,13 +108,13 @@ class HTML(DT_String.String): ...@@ -108,13 +108,13 @@ class HTML(DT_String.String):
def quotedHTML(self, def quotedHTML(self,
text=None, text=None,
character_entities=( character_entities=(
(regex.compile('&'), '&'), (('&'), '&'),
(regex.compile("<"), '&lt;' ), (("<"), '&lt;' ),
(regex.compile(">"), '&gt;' ), ((">"), '&gt;' ),
(regex.compile('"'), '&quot;'))): #" (('"'), '&quot;'))): #"
if text is None: 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) if find(text, re) >= 0: text=join(split(text,re),name)
return text return text
errQuote=quotedHTML errQuote=quotedHTML
...@@ -192,11 +192,13 @@ class HTMLFile(FileMixin, HTML): ...@@ -192,11 +192,13 @@ class HTMLFile(FileMixin, HTML):
manage_editDocument=manage=manage_editForm manage_editDocument=manage=manage_editForm
def manage_edit(self,data, def manage_edit(self,data,
PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT='', PARENTS=[],URL1='',URL2='',REQUEST='', SUBMIT=''):
crlf=regex.compile('\r\n\|\n\r')):
'edit a template' 'edit a template'
if SUBMIT==FactoryDefaultString: return self.manage_default(REQUEST) if SUBMIT==FactoryDefaultString: return self.manage_default(REQUEST)
data=gsub(crlf,'\n',data) if find(data,'\r'):
data=join(split(data,'\r\n'),'\n\r')
data=join(split(data,'\n\r'),'\n')
if self.edited_source: if self.edited_source:
self.edited_source=data self.edited_source=data
self.cooked=self.cook() self.cooked=self.cook()
...@@ -211,6 +213,9 @@ class HTMLFile(FileMixin, HTML): ...@@ -211,6 +213,9 @@ class HTMLFile(FileMixin, HTML):
########################################################################## ##########################################################################
# #
# $Log: DT_HTML.py,v $ # $Log: DT_HTML.py,v $
# Revision 1.7 1998/08/11 19:32:38 jim
# Made use (or non-use) of regex thread safe.
#
# Revision 1.6 1998/04/02 17:37:35 jim # Revision 1.6 1998/04/02 17:37:35 jim
# Major redesign of block rendering. The code inside a block tag is # Major redesign of block rendering. The code inside a block tag is
# compiled as a template but only the templates blocks are saved, and # compiled as a template but only the templates blocks are saved, and
......
...@@ -296,7 +296,7 @@ ...@@ -296,7 +296,7 @@
''' #' ''' #'
__rcs_id__='$Id: DT_In.py,v 1.24 1998/04/08 17:45:59 jim Exp $' __rcs_id__='$Id: DT_In.py,v 1.25 1998/08/11 19:34:48 jim Exp $'
############################################################################ ############################################################################
# Copyright # Copyright
...@@ -350,11 +350,11 @@ __rcs_id__='$Id: DT_In.py,v 1.24 1998/04/08 17:45:59 jim Exp $' ...@@ -350,11 +350,11 @@ __rcs_id__='$Id: DT_In.py,v 1.24 1998/04/08 17:45:59 jim Exp $'
# (540) 371-6909 # (540) 371-6909
# #
############################################################################ ############################################################################
__version__='$Revision: 1.24 $'[11:-2] __version__='$Revision: 1.25 $'[11:-2]
from DT_Util import * from DT_Util import *
from string import find, atoi, join from string import find, atoi, join
import regex import ts_regex
from regsub import gsub from regsub import gsub
from DT_InSV import sequence_variables, opt from DT_InSV import sequence_variables, opt
...@@ -402,7 +402,7 @@ class InClass: ...@@ -402,7 +402,7 @@ class InClass:
if type(v)==type(''): if type(v)==type(''):
try: atoi(v) try: atoi(v)
except: except:
self.start_name_re=regex.compile( self.start_name_re=ts_regex.compile(
'&+'+ '&+'+
join(map(lambda c: "[%s]" % c, v),'')+ join(map(lambda c: "[%s]" % c, v),'')+
'=[0-9]+&+') '=[0-9]+&+')
...@@ -690,6 +690,9 @@ def int_param(params,md,name,default=0): ...@@ -690,6 +690,9 @@ def int_param(params,md,name,default=0):
############################################################################ ############################################################################
# $Log: DT_In.py,v $ # $Log: DT_In.py,v $
# Revision 1.25 1998/08/11 19:34:48 jim
# Made use (or non-use) of regex thread safe.
#
# Revision 1.24 1998/04/08 17:45:59 jim # Revision 1.24 1998/04/08 17:45:59 jim
# Now check security of items, and new skip_unauthorized attr. # Now check security of items, and new skip_unauthorized attr.
# #
......
from string import * from string import *
import DT_Doc, DT_Var, DT_In, DT_If, regex, DT_Raise, DT_With import DT_Doc, DT_Var, DT_In, DT_If, regex, ts_regex, DT_Raise, DT_With
Var=DT_Var.Var Var=DT_Var.Var
from DT_Util import * from DT_Util import *
...@@ -39,7 +39,7 @@ class String: ...@@ -39,7 +39,7 @@ class String:
def SubTemplate(self, name): return String('', __name__=name) def SubTemplate(self, name): return String('', __name__=name)
def tagre(self): def tagre(self):
return regex.symcomp( return ts_regex.symcomp(
'%(' # beginning '%(' # beginning
'\(<name>[a-zA-Z0-9_/.-]+\)' # tag name '\(<name>[a-zA-Z0-9_/.-]+\)' # tag name
'\(' '\('
......
...@@ -114,7 +114,7 @@ Evaluating expressions without rendering results ...@@ -114,7 +114,7 @@ Evaluating expressions without rendering results
''' # ' ''' # '
__rcs_id__='$Id: DT_Var.py,v 1.14 1998/04/14 11:58:21 jim Exp $' __rcs_id__='$Id: DT_Var.py,v 1.15 1998/08/11 19:36:54 jim Exp $'
############################################################################ ############################################################################
# Copyright # Copyright
...@@ -168,10 +168,10 @@ __rcs_id__='$Id: DT_Var.py,v 1.14 1998/04/14 11:58:21 jim Exp $' ...@@ -168,10 +168,10 @@ __rcs_id__='$Id: DT_Var.py,v 1.14 1998/04/14 11:58:21 jim Exp $'
# (540) 371-6909 # (540) 371-6909
# #
############################################################################ ############################################################################
__version__='$Revision: 1.14 $'[11:-2] __version__='$Revision: 1.15 $'[11:-2]
from DT_Util import * from DT_Util import *
import ts_regex
from string import find, split, join from string import find, split, join
class Var: class Var:
...@@ -282,13 +282,13 @@ class Call: ...@@ -282,13 +282,13 @@ class Call:
def html_quote(v, name='(Unknown name)', md={}, def html_quote(v, name='(Unknown name)', md={},
character_entities=( character_entities=(
(regex.compile('&'), '&amp;'), (('&'), '&amp;'),
(regex.compile("<"), '&lt;' ), (("<"), '&lt;' ),
(regex.compile(">"), '&gt;' ), ((">"), '&gt;' ),
(regex.compile('"'), '&quot;'))): #" (('"'), '&quot;'))): #"
text=str(v) text=str(v)
for re,name in character_entities: for re,name in character_entities:
text=gsub(re,name,text) if find(text, re) >= 0: text=join(split(text,re),name)
return text return text
def url_quote(v, name='(Unknown name)', md={}): def url_quote(v, name='(Unknown name)', md={}):
...@@ -296,7 +296,7 @@ def url_quote(v, name='(Unknown name)', md={}): ...@@ -296,7 +296,7 @@ def url_quote(v, name='(Unknown name)', md={}):
return urllib.quote(str(v)) return urllib.quote(str(v))
def newline_to_br(v, name='(Unknown name)', md={}, def newline_to_br(v, name='(Unknown name)', md={},
nl=regex.compile('\r?\n')): nl=ts_regex.compile('\r?\n')):
return gsub(nl,'<br>\n',str(v)) return gsub(nl,'<br>\n',str(v))
def whole_dollars(v, name='(Unknown name)', md={}): def whole_dollars(v, name='(Unknown name)', md={}):
...@@ -308,7 +308,7 @@ def dollars_and_cents(v, name='(Unknown name)', md={}): ...@@ -308,7 +308,7 @@ def dollars_and_cents(v, name='(Unknown name)', md={}):
except: return '' except: return ''
def thousands_commas(v, name='(Unknown name)', md={}, def thousands_commas(v, name='(Unknown name)', md={},
thou=regex.compile("\([0-9]\)\([0-9][0-9][0-9]\([,.]\|$\)\)")): thou=ts_regex.compile("\([0-9]\)\([0-9][0-9][0-9]\([,.]\|$\)\)")):
v=str(v) v=str(v)
while thou.search(v) >= 0: while thou.search(v) >= 0:
v=sub(thou,"\\1,\\2",v) v=sub(thou,"\\1,\\2",v)
...@@ -370,6 +370,9 @@ modifiers=map(lambda f: (f.__name__, f), modifiers) ...@@ -370,6 +370,9 @@ modifiers=map(lambda f: (f.__name__, f), modifiers)
############################################################################ ############################################################################
# $Log: DT_Var.py,v $ # $Log: DT_Var.py,v $
# Revision 1.15 1998/08/11 19:36:54 jim
# Made use (or non-use) of regex thread safe.
#
# Revision 1.14 1998/04/14 11:58:21 jim # Revision 1.14 1998/04/14 11:58:21 jim
# Fixed bug in handling: %(foo)d # Fixed bug in handling: %(foo)d
# and in handling <!--#var foo--> where foo is a tuple. # and in handling <!--#var foo--> where foo is a tuple.
......
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