[Zope-Checkins] CVS: Zope/lib/python/reStructuredText -
__init__.py:1.7.2.2.4.5
Christian 'Tiran' Heimes
heimes at faho.rwth-aachen.de
Wed May 12 16:12:25 EDT 2004
Update of /cvs-repository/Zope/lib/python/reStructuredText
In directory cvs.zope.org:/tmp/cvs-serv20959/lib/python/reStructuredText
Modified Files:
Tag: tiran-restfixing-branch
__init__.py
Log Message:
Ups, zope is already shipping with docutils. Removed all the old crap.
=== Zope/lib/python/reStructuredText/__init__.py 1.7.2.2.4.4 => 1.7.2.2.4.5 ===
--- Zope/lib/python/reStructuredText/__init__.py:1.7.2.2.4.4 Wed May 12 15:58:41 2004
+++ Zope/lib/python/reStructuredText/__init__.py Wed May 12 16:12:23 2004
@@ -10,23 +10,14 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
+"""Wrapper to integrate reStructuredText into Zope
-""" Wrapper to integrate reStructuredText into Zope """
+This implementation requires docutils 0.3.4+ from http://docutils.sf.net/
+"""
import sys, os, locale
-
-try:
- import docutils
-except ImportError:
- docutils_version = ''
- version_tuple = None
-else:
- docutils_version = docutils.__version__
- version_tuple = tuple(docutils_version.split('.'))
-
from App.config import getConfiguration
-from zLOG import LOG as log
-from zLOG import INFO, PROBLEM
+from docutils.core import publish_parts
# get encoding
default_enc = sys.getdefaultencoding()
@@ -42,19 +33,6 @@
if default_lang and '_' in default_lang:
default_lang = default_lang[:default_lang.index('_')]
-if version_tuple is None:
- USE_DOCUTILS = False
- log('reStructuredText', PROBLEM, 'docutils package not found.')
-elif version_tuple >= ('0', '3', '4'):
- USE_DOCUTILS = True
- USE_NEW_IMPLEMENTATION = True
- log('reStructuredText', INFO, 'is using the NEW implementation of the reST '
- 'writer (version %s).' % docutils_version)
-else:
- USE_DOCUTILS = True
- USE_NEW_IMPLEMENTATION = False
- log('reStructuredText', INFO, 'is using the OLD implementation of the reST '
- 'writer (version %s).' % docutils_version)
class Warnings:
@@ -64,90 +42,7 @@
def write(self, message):
self.messages.append(message)
-######################################################################
-# old style implementation (XXX remove it later)
-# works with older versions of docutils
-if USE_DOCUTILS and not USE_NEW_IMPLEMENTATION:
- from docutils.core import Publisher
- from docutils import io, writers
-
- # add html4zope to the docutils.writers
- import html4zope
- writers.html4zope = html4zope
- sys.modules['docutils.writers.html4zope'] = html4zope
-
-def HTML_old(src,
- writer='html4zope',
- report_level=1,
- stylesheet='default.css',
- input_encoding=default_input_encoding,
- output_encoding=default_output_encoding,
- language_code=default_lang,
- warnings = None,
- settings = {}):
-
- """ render HTML from a reStructuredText string
-
- - 'src' -- string containing a valid reST document
-
- - 'writer' -- docutils writer
-
- - 'report_level' - verbosity of reST parser
-
- - 'stylesheet' - Stylesheet to be used
-
- - 'input_encoding' - encoding of the reST input string
-
- - 'output_encoding' - encoding of the rendered HTML output
-
- - 'language_code' - docutils language
-
- - 'warnings' - will be overwritten with a string containing the warnings
-
- - 'settings' - more keyword args which are applied to the parser
- """
- pub = Publisher(source_class=io.StringInput,
- destination_class=io.StringOutput
- )
-
- # set reader and writer. Needs to be done before settings
- pub.set_reader('standalone', None, 'restructuredtext')
- pub.set_writer(writer)
-
- # update settings for kwargs
- settings.update({
- 'stylesheet' : stylesheet,
- '_destination' : None, # this is needed, but doesn't seem to do anything
- 'report_level' : report_level,
- 'halt_level' : 6, # don't break if we get errors
- 'warning_stream' : Warnings(),
- 'input_encoding' : input_encoding,
- 'output_encoding' : output_encoding,
- 'language_code' : language_code,
- })
- pub.get_settings()._update(settings, 'loose')
-
- # set source and destination
- pub.set_source(source=src)
- pub.set_destination()
-
- # parse!
- document = pub.reader.read(pub.source, pub.parser, pub.settings)
- # transform
- pub.apply_transforms(document)
-
- warnings = ''.join(pub.settings.warning_stream.messages)
-
- # do the format
- return pub.writer.write(document, pub.destination)
-
-######################################################################
-# new style implementation
-# requires docutils >= 0.3.4
-if USE_DOCUTILS and USE_NEW_IMPLEMENTATION:
- from docutils.core import publish_parts
-
-def HTML_new(src,
+def HTML(src,
writer='html4css1',
report_level=1,
stylesheet='default.css',
@@ -209,25 +104,5 @@
return output
-######################################################################
-# dummy writer
-
-def HTML_dummy(src,
- input_encoding=default_input_encoding,
- output_encoding=default_output_encoding,
- **kwargs):
-
- return unicode(src, input_encoding).encode(output_encoding)
-
-# end of implementations
-######################################################################
-
-if not USE_DOCUTILS:
- HTML = HTML_dummy
-elif USE_NEW_IMPLEMENTATION:
- HTML = HTML_new
-else:
- HTML = HTML_old
-
-__all__ = ("HTML", )
+__all__ = ("HTML", )
More information about the Zope-Checkins
mailing list