Commit 6782b68b authored by Hanno Schlichting's avatar Hanno Schlichting

Make the App and reStructuredText dependencies in DocumentTemplate optional

parent 7a14524a
...@@ -46,11 +46,3 @@ DocumentTemplate ...@@ -46,11 +46,3 @@ DocumentTemplate
* Missing * Missing
* RestrictedPython * RestrictedPython
* zExceptions * zExceptions
- Remaining outside imports:
* App (getConfiguration().structured_text_header_level)
* reStructuredText (HTML) - Both of these deal with format support and
configuration via zope.conf. The calls are localized to one function each.
Add an optional dependency on Zope2? Configure if it is available,
otherwise use some default?
...@@ -148,22 +148,23 @@ Evaluating expressions without rendering results ...@@ -148,22 +148,23 @@ Evaluating expressions without rendering results
A 'call' tag is provided for evaluating named objects or expressions A 'call' tag is provided for evaluating named objects or expressions
without rendering the result. without rendering the result.
$Id$
""" """
import string, re, sys import logging
import re
import string
import sys
from urllib import quote, quote_plus, unquote, unquote_plus from urllib import quote, quote_plus, unquote, unquote_plus
from Acquisition import aq_base
from AccessControl.tainted import TaintedString
from zope.structuredtext.document import DocumentWithImages
# for import by other modules, dont remove! # for import by other modules, dont remove!
from DocumentTemplate.html_quote import html_quote from DocumentTemplate.html_quote import html_quote
from DocumentTemplate.DT_Util import parse_params, name_param, str, ustr from DocumentTemplate.DT_Util import parse_params, name_param, str, ustr
from Acquisition import aq_base logger = logging.getLogger('DocumentTemplate')
from AccessControl.tainted import TaintedString
from zope.structuredtext.html import HTML
from zope.structuredtext.document import DocumentWithImages
from App.config import getConfiguration
class Var: class Var:
...@@ -399,30 +400,43 @@ def len_format(v, name='(Unknown name)', md={}): ...@@ -399,30 +400,43 @@ def len_format(v, name='(Unknown name)', md={}):
def len_comma(v, name='(Unknown name)', md={}): def len_comma(v, name='(Unknown name)', md={}):
return thousands_commas(str(len(v))) return thousands_commas(str(len(v)))
def restructured_text(v, name='(Unknown name)', md={}):
from reStructuredText import HTML
if isinstance(v, str): def restructured_text(v, name='(Unknown name)', md={}):
try:
from reStructuredText import HTML
except ImportError:
logger.info('The reStructuredText package is not available, therefor '
'the DT_Var.restructured_text function returns None.')
return None
if isinstance(v, str):
txt = v txt = v
elif aq_base(v).meta_type in ['DTML Document','DTML Method']: elif aq_base(v).meta_type in ['DTML Document','DTML Method']:
txt = aq_base(v).read_raw() txt = aq_base(v).read_raw()
else: else:
txt = str(v) txt = str(v)
return HTML(txt) return HTML(txt)
def structured_text(v, name='(Unknown name)', md={}): def structured_text(v, name='(Unknown name)', md={}):
from zope.structuredtext.html import HTML
if isinstance(v, str): if isinstance(v, str):
txt = v txt = v
elif aq_base(v).meta_type in ['DTML Document','DTML Method']: elif aq_base(v).meta_type in ['DTML Document','DTML Method']:
txt = aq_base(v).read_raw() txt = aq_base(v).read_raw()
else: else:
txt = str(v) txt = str(v)
level = getConfiguration().structured_text_header_level level = 3
try:
from App.config import getConfiguration
except ImportError:
pass
else:
level = getConfiguration().structured_text_header_level
doc = DocumentWithImages()(txt) doc = DocumentWithImages()(txt)
return HTML()(doc, level, header=False) return HTML()(doc, level, header=False)
......
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