[Zope-Checkins] CVS: Zope/lib/python/reStructuredText - __init__.py:1.7.2.2.4.3

Christian 'Tiran' Heimes heimes at faho.rwth-aachen.de
Wed May 12 15:24:10 EDT 2004


Update of /cvs-repository/Zope/lib/python/reStructuredText
In directory cvs.zope.org:/tmp/cvs-serv32129/lib/python/reStructuredText

Modified Files:
      Tag: tiran-restfixing-branch
	__init__.py 
Log Message:
Now the rest writer has three implementations:
* old (for docutils <0.3.4 - has to be removed later)
* new (for docutils 0.3.4+)
* dummy (for people without docutils)


=== Zope/lib/python/reStructuredText/__init__.py 1.7.2.2.4.2 => 1.7.2.2.4.3 ===
--- Zope/lib/python/reStructuredText/__init__.py:1.7.2.2.4.2	Wed May 12 14:28:19 2004
+++ Zope/lib/python/reStructuredText/__init__.py	Wed May 12 15:24:09 2004
@@ -13,10 +13,18 @@
 
 """ Wrapper to integrate reStructuredText into Zope """
 
+import sys, os, locale
 
-import sys, os
-from App.config import getConfiguration 
-from docutils import __version__ as docutils_version
+try:
+    import docutils
+except ImportError:
+    docutils_version = None
+else:
+    docutils_version = docutils.__version__
+
+from App.config import getConfiguration
+from zLOG import LOG as log
+from zLOG import INFO, PROBLEM
 
 # get encoding
 default_enc = sys.getdefaultencoding()
@@ -32,6 +40,19 @@
 if default_lang and '_' in default_lang:
     default_lang = default_lang[:default_lang.index('_')]
 
+if docutils_version is None:
+    USE_DOCUTILS = False
+    log('reStructuredText', PROBLEM, 'docutils package not found.')
+elif docutils_version >= '0.3.4':
+    USE_DOCUTILS = True
+    USE_NEW_IMPLEMENTATION = True
+    log('reStructuredText', INFO, 'is using the NEW implementation of the reST '
+                                  'writer.')
+else:
+    USE_DOCUTILS = True
+    USE_NEW_IMPLEMENTATION = False
+    log('reStructuredText', INFO, 'is using the OLD implementation of the reST '
+                                  'writer.')
 
 class Warnings:
 
@@ -44,14 +65,14 @@
 ######################################################################
 # old style implementation
 # works with older versions of docutils
-
-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
+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', 
@@ -122,8 +143,8 @@
 ######################################################################
 # new style implementation
 # requires docutils >= 0.3.4
-
-from docutils.core import publish_parts
+if USE_DOCUTILS and USE_NEW_IMPLEMENTATION:
+    from docutils.core import publish_parts
 
 def HTML_new(src,
          writer='html4css1',
@@ -187,13 +208,25 @@
 
     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 docutils_version < '0.3.4':
-    HTML = HTML_old
-else:
+if not USE_DOCUTILS:
+    HTML = HTML_dummy
+elif USE_NEW_IMPLEMENTATION:
     HTML = HTML_new
+else:
+    HTML = HTML_old
 
 __all__ = ("HTML", ) 
 




More information about the Zope-Checkins mailing list