[Zope-Checkins] CVS: Zope/lib/python/docutils - __init__.py:1.1.2.2 core.py:1.1.2.2 frontend.py:1.1.2.2 io.py:1.1.2.2 nodes.py:1.1.2.2 optik.py:1.1.2.2 statemachine.py:1.1.2.2 utils.py:1.1.2.2

Andreas Jung andreas@andreas-jung.com
Sat, 25 Jan 2003 07:44:39 -0500


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

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	__init__.py core.py frontend.py io.py nodes.py optik.py 
	statemachine.py utils.py 
Log Message:
docutils updated


=== Zope/lib/python/docutils/__init__.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/__init__.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/__init__.py	Sat Jan 25 07:44:04 2003
@@ -55,9 +55,12 @@
 
 __docformat__ = 'reStructuredText'
 
-__version__ = '0.2.7'
-"""``major.minor.micro`` version number.  The ``micro`` number is bumped any
-time there's a change in the API incompatible with one of the front ends."""
+__version__ = '0.2.8'
+"""``major.minor.micro`` version number.  The micro number is bumped any time
+there's a change in the API incompatible with one of the front ends.  The
+minor number is bumped whenever there is a project release.  The major number
+will be bumped when the project is complete, and perhaps if there is a major
+change in the design."""
 
 
 class ApplicationError(StandardError): pass


=== Zope/lib/python/docutils/core.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/core.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/core.py	Sat Jan 25 07:44:04 2003
@@ -72,6 +72,16 @@
         writer_class = writers.get_writer_class(writer_name)
         self.writer = writer_class()
 
+    def set_components(self, reader_name, parser_name, writer_name):
+        if self.reader is None:
+            self.set_reader(reader_name, self.parser, parser_name)
+        if self.parser is None:
+            if self.reader.parser is None:
+                self.reader.set_parser(parser_name)
+            self.parser = self.reader.parser
+        if self.writer is None:
+            self.set_writer(writer_name)
+
     def setup_option_parser(self, usage=None, description=None,
                             settings_spec=None, **defaults):
         #@@@ Add self.source & self.destination to components in future?
@@ -127,8 +137,9 @@
             source_path = self.settings._source
         else:
             self.settings._source = source_path
-        self.source = self.source_class(self.settings, source=source,
-                                        source_path=source_path)
+        self.source = self.source_class(
+            source=source, source_path=source_path,
+            encoding=self.settings.input_encoding)
 
     def set_destination(self, destination=None, destination_path=None):
         if destination_path is None:
@@ -136,8 +147,8 @@
         else:
             self.settings._destination = destination_path
         self.destination = self.destination_class(
-            self.settings, destination=destination,
-            destination_path=destination_path)
+            destination=destination, destination_path=destination_path,
+            encoding=self.settings.output_encoding)
 
     def apply_transforms(self, document):
         document.transformer.populate_from_components(
@@ -216,10 +227,7 @@
       (along with command-line option descriptions).
     """
     pub = Publisher(reader, parser, writer, settings=settings)
-    if reader is None:
-        pub.set_reader(reader_name, parser, parser_name)
-    if writer is None:
-        pub.set_writer(writer_name)
+    pub.set_components(reader_name, parser_name, writer_name)
     pub.publish(argv, usage, description, settings_spec, settings_overrides)
 
 def publish_file(source=None, source_path=None,
@@ -257,10 +265,7 @@
       of component settings.
     """
     pub = Publisher(reader, parser, writer, settings=settings)
-    if reader is None:
-        pub.set_reader(reader_name, parser, parser_name)
-    if writer is None:
-        pub.set_writer(writer_name)
+    pub.set_components(reader_name, parser_name, writer_name)
     if settings is None:
         settings = pub.get_settings(settings_spec=settings_spec)
     if settings_overrides:
@@ -280,14 +285,14 @@
     For programmatic use with string I/O.
 
     For encoded string output, be sure to set the "output_encoding" setting to
-    the desired encoding.  Set it to "unicode" for Unicode string output.
+    the desired encoding.  Set it to "unicode" for unencoded Unicode string
+    output.
 
     Parameters:
 
-    - `source`: An input string; required.  This can be an encoded 8-big
-      string (in which case the "input_encoding" setting should be set) or a
-      Unicode string (in which case set the "input_encoding" setting to
-      "unicode").
+    - `source`: An input string; required.  This can be an encoded 8-bit
+      string (set the "input_encoding" setting to the correct encoding) or a
+      Unicode string (set the "input_encoding" setting to "unicode").
     - `source_path`: Path to the file or object that produced `source`;
       optional.  Only used for diagnostic output.
     - `destination_path`: Path to the file or object which will receive the
@@ -311,10 +316,7 @@
     pub = Publisher(reader, parser, writer, settings=settings,
                     source_class=io.StringInput,
                     destination_class=io.StringOutput)
-    if reader is None:
-        pub.set_reader(reader_name, parser, parser_name)
-    if writer is None:
-        pub.set_writer(writer_name)
+    pub.set_components(reader_name, parser_name, writer_name)
     if settings is None:
         settings = pub.get_settings(settings_spec=settings_spec)
     if settings_overrides:


=== Zope/lib/python/docutils/frontend.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/frontend.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/frontend.py	Sat Jan 25 07:44:04 2003
@@ -303,33 +303,8 @@
 
         The section DEFAULT is special.
         """
-        try:
-            sectdict = self._ConfigParser__sections[section].copy()
-        except KeyError:
-            sectdict = {}
-        d = self._ConfigParser__defaults.copy()
-        d.update(sectdict)
-        # Update with the entry specific variables
-        if vars:
-            d.update(vars)
-        if raw:
-            return sectdict
-        # do the string interpolation
-        for option in sectdict.keys():
-            rawval = sectdict[option]
-            value = rawval              # Make it a pretty variable name
-            depth = 0
-            while depth < 10:           # Loop through this until it's done
-                depth += 1
-                if value.find("%(") >= 0:
-                    try:
-                        value = value % d
-                    except KeyError, key:
-                        raise CP.InterpolationError(key, option, section,
-                                                    rawval)
-                else:
-                    break
-            if value.find("%(") >= 0:
-                raise CP.InterpolationDepthError(option, section, rawval)
-            sectdict[option] = value
-        return sectdict
+        section_dict = {}
+        if self.has_section(section):
+            for option in self.options(section):
+                section_dict[option] = self.get(section, option, raw, vars)
+        return section_dict


=== Zope/lib/python/docutils/io.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/io.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/io.py	Sat Jan 25 07:44:04 2003
@@ -26,10 +26,20 @@
 
     default_source_path = None
 
-    def __init__(self, settings, source=None, source_path=None):
-        self.settings = settings
-        """A settings object with "input_encoding" and "output_encoding"
-        attributes (typically a `docutils.optik.Values` object)."""
+    def __init__(self, settings=None, source=None, source_path=None,
+                 encoding=None):
+        self.encoding = encoding
+        """The character encoding for the input source."""
+
+        if settings:
+            if not encoding:
+                self.encoding = settings.input_encoding
+            import warnings, traceback
+            warnings.warn(
+                'Setting input encoding via a "settings" struct is '
+                'deprecated; send encoding directly instead.\n%s'
+                % ''.join(traceback.format_list(traceback.extract_stack()
+                                                [-3:-1])))
 
         self.source = source
         """The source of input data."""
@@ -44,7 +54,7 @@
         return '%s: source=%r, source_path=%r' % (self.__class__, self.source,
                                                   self.source_path)
 
-    def read(self, reader):
+    def read(self):
         raise NotImplementedError
 
     def decode(self, data):
@@ -57,10 +67,9 @@
 
             locale.setlocale(locale.LC_ALL, '')
         """
-        if self.settings.input_encoding \
-               and self.settings.input_encoding.lower() == 'unicode':
+        if self.encoding and self.encoding.lower() == 'unicode':
             return unicode(data)
-        encodings = [self.settings.input_encoding, 'utf-8']
+        encodings = [self.encoding, 'utf-8']
         try:
             encodings.append(locale.nl_langinfo(locale.CODESET))
         except:
@@ -97,10 +106,20 @@
 
     default_destination_path = None
 
-    def __init__(self, settings, destination=None, destination_path=None):
-        self.settings = settings
-        """A settings object with "input_encoding" and "output_encoding"
-        attributes (typically a `docutils.optik.Values` object)."""
+    def __init__(self, settings=None, destination=None, destination_path=None,
+                 encoding=None):
+        self.encoding = encoding
+        """The character encoding for the output destination."""
+
+        if settings:
+            if not encoding:
+                self.encoding = settings.output_encoding
+            import warnings, traceback
+            warnings.warn(
+                'Setting output encoding via a "settings" struct is '
+                'deprecated; send encoding directly instead.\n%s'
+                % ''.join(traceback.format_list(traceback.extract_stack()
+                                                [-3:-1])))
 
         self.destination = destination
         """The destination for output data."""
@@ -119,11 +138,10 @@
         raise NotImplementedError
 
     def encode(self, data):
-        if self.settings.output_encoding \
-               and self.settings.output_encoding.lower() == 'unicode':
+        if self.encoding and self.encoding.lower() == 'unicode':
             return data
         else:
-            return data.encode(self.settings.output_encoding or '')
+            return data.encode(self.encoding or '')
 
 
 class FileInput(Input):
@@ -132,7 +150,8 @@
     Input for single, simple file-like objects.
     """
 
-    def __init__(self, settings, source=None, source_path=None, autoclose=1):
+    def __init__(self, settings=None, source=None, source_path=None,
+                 encoding=None, autoclose=1):
         """
         :Parameters:
             - `source`: either a file-like object (which is read directly), or
@@ -141,7 +160,7 @@
             - `autoclose`: close automatically after read (boolean); always
               false if `sys.stdin` is the source.
         """
-        Input.__init__(self, settings, source, source_path)
+        Input.__init__(self, settings, source, source_path, encoding)
         self.autoclose = autoclose
         if source is None:
             if source_path:
@@ -155,7 +174,7 @@
             except AttributeError:
                 pass
 
-    def read(self, reader):
+    def read(self):
         """Read and decode a single file and return the data."""
         data = self.source.read()
         if self.autoclose:
@@ -172,8 +191,8 @@
     Output for single, simple file-like objects.
     """
 
-    def __init__(self, settings, destination=None, destination_path=None,
-                 autoclose=1):
+    def __init__(self, settings=None, destination=None, destination_path=None,
+                 encoding=None, autoclose=1):
         """
         :Parameters:
             - `destination`: either a file-like object (which is written
@@ -184,7 +203,8 @@
             - `autoclose`: close automatically after write (boolean); always
               false if `sys.stdout` is the destination.
         """
-        Output.__init__(self, settings, destination, destination_path)
+        Output.__init__(self, settings, destination, destination_path,
+                        encoding)
         self.opened = 1
         self.autoclose = autoclose
         if destination is None:
@@ -226,7 +246,7 @@
 
     default_source_path = '<string>'
 
-    def read(self, reader):
+    def read(self):
         """Decode and return the source string."""
         return self.decode(self.source)
 
@@ -253,7 +273,7 @@
 
     default_source_path = 'null input'
 
-    def read(self, reader):
+    def read(self):
         """Return a null string."""
         return u''
 


=== Zope/lib/python/docutils/nodes.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/nodes.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/nodes.py	Sat Jan 25 07:44:04 2003
@@ -57,8 +57,9 @@
         return 1
 
     def asdom(self, dom=xml.dom.minidom):
-        """Return a DOM representation of this Node."""
-        return self._dom_node(dom)
+        """Return a DOM **fragment** representation of this Node."""
+        domroot = dom.Document()
+        return self._dom_node(domroot)
 
     def pformat(self, indent='    ', level=0):
         """Return an indented pseudo-XML representation, for test purposes."""
@@ -180,10 +181,7 @@
             data = repr(self.data[:16] + ' ...')
         return '<%s: %s>' % (self.tagname, data)
 
-    def _dom_node(self, dom):
-        return dom.Text(self.data)
-
-    def _rooted_dom_node(self, domroot):
+    def _dom_node(self, domroot):
         return domroot.createTextNode(self.data)
 
     def astext(self):
@@ -260,22 +258,14 @@
         if self.tagname is None:
             self.tagname = self.__class__.__name__
 
-    def _dom_node(self, dom):
-        element = dom.Element(self.tagname)
-        for attribute, value in self.attributes.items():
-            element.setAttribute(attribute, str(value))
-        for child in self.children:
-            element.appendChild(child._dom_node(dom))
-        return element
-
-    def _rooted_dom_node(self, domroot):
+    def _dom_node(self, domroot):
         element = domroot.createElement(self.tagname)
         for attribute, value in self.attributes.items():
             if type(value) is ListType:
                 value = ' '.join(value)
             element.setAttribute(attribute, str(value))
         for child in self.children:
-            element.appendChild(child._rooted_dom_node(domroot))
+            element.appendChild(child._dom_node(domroot))
         return element
 
     def __repr__(self):
@@ -335,7 +325,7 @@
         elif isinstance(key, IntType):
             return self.children[key]
         elif isinstance(key, SliceType):
-            assert key.step is None, 'cannot handle slice with stride'
+            assert key.step in (None, 1), 'cannot handle slice with stride'
             return self.children[key.start:key.stop]
         else:
             raise TypeError, ('element index must be an integer, a slice, or '
@@ -348,7 +338,7 @@
             self.setup_child(item)
             self.children[key] = item
         elif isinstance(key, SliceType):
-            assert key.step is None, 'cannot handle slice with stride'
+            assert key.step in (None, 1), 'cannot handle slice with stride'
             for node in item:
                 self.setup_child(node)
             self.children[key.start:key.stop] = item
@@ -362,7 +352,7 @@
         elif isinstance(key, IntType):
             del self.children[key]
         elif isinstance(key, SliceType):
-            assert key.step is None, 'cannot handle slice with stride'
+            assert key.step in (None, 1), 'cannot handle slice with stride'
             del self.children[key.start:key.stop]
         else:
             raise TypeError, ('element index must be an integer, a simple '
@@ -701,8 +691,9 @@
         self.document = self
 
     def asdom(self, dom=xml.dom.minidom):
+        """Return a DOM representation of this document."""
         domroot = dom.Document()
-        domroot.appendChild(self._rooted_dom_node(domroot))
+        domroot.appendChild(self._dom_node(domroot))
         return domroot
 
     def set_id(self, node, msgnode=None):
@@ -899,11 +890,12 @@
     def note_transform_message(self, message):
         self.transform_messages.append(message)
 
-    def note_state_machine_change(self, state_machine):
-        self.current_line = state_machine.abs_line_number()
-
-    def note_source(self, source):
+    def note_source(self, source, offset):
         self.current_source = source
+        if offset is None:
+            self.current_line = offset
+        else:
+            self.current_line = offset + 1
 
     def copy(self):
         return self.__class__(self.settings, self.reporter,
@@ -1146,12 +1138,14 @@
 
 class emphasis(Inline, TextElement): pass
 class strong(Inline, TextElement): pass
-class interpreted(Inline, Referential, TextElement): pass
 class literal(Inline, TextElement): pass
 class reference(Inline, Referential, TextElement): pass
 class footnote_reference(Inline, Referential, TextElement): pass
 class citation_reference(Inline, Referential, TextElement): pass
 class substitution_reference(Inline, TextElement): pass
+class title_reference(Inline, TextElement): pass
+class abbreviation(Inline, TextElement): pass
+class acronym(Inline, TextElement): pass
 
 
 class image(General, Inline, TextElement):
@@ -1170,7 +1164,7 @@
 
 node_class_names = """
     Text
-    address attention author authors
+    abbreviation acronym address attention author authors
     block_quote bullet_list
     caption caution citation citation_reference classifier colspec comment
         contact copyright
@@ -1181,7 +1175,7 @@
         footnote footnote_reference
     generated
     header hint
-    image important interpreted
+    image important
     label legend line_block list_item literal literal_block
     note
     option option_argument option_group option_list option_list_item
@@ -1190,7 +1184,8 @@
     raw reference revision row
     section status strong substitution_definition substitution_reference
         subtitle system_message
-    table target tbody term tgroup thead tip title topic transition
+    table target tbody term tgroup thead tip title title_reference topic
+        transition
     version
     warning""".split()
 """A list of names of all concrete Node subclasses."""


=== Zope/lib/python/docutils/optik.py 1.1.2.1 => 1.1.2.2 ===


=== Zope/lib/python/docutils/statemachine.py 1.1.2.1 => 1.1.2.2 === (568/668 lines abridged)
--- Zope/lib/python/docutils/statemachine.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/statemachine.py	Sat Jan 25 07:44:04 2003
@@ -14,6 +14,8 @@
 - `StateWS`, a state superclass for use with `StateMachineWS`
 - `SearchStateMachine`, uses `re.search()` instead of `re.match()`
 - `SearchStateMachineWS`, uses `re.search()` instead of `re.match()`
+- `ViewList`, extends standard Python lists.
+- `StringList`, string-specific ViewList.
 
 Exception classes:
 
@@ -31,7 +33,7 @@
 Functions:
 
 - `string2lines()`: split a multi-line string into a list of one-line strings
-- `extract_indented()`: return indented lines with minimum indentation removed
+
 
 How To Use This Module
 ======================
@@ -108,6 +110,7 @@
 
 import sys
 import re
+from types import SliceType as _SliceType
 
 
 class StateMachine:
@@ -136,7 +139,8 @@
         """
 
         self.input_lines = None
-        """List of strings (without newlines). Filled by `self.run()`."""
+        """`StringList` of input lines (without newlines).
+        Filled by `self.run()`."""
 
         self.input_offset = 0
         """Offset of `self.input_lines` from the beginning of the file."""
@@ -172,7 +176,8 @@
             state.unlink()
         self.states = None
 
-    def run(self, input_lines, input_offset=0):
+    def run(self, input_lines, input_offset=0, context=None,
+            input_source=None):
         """
         Run the state machine on `input_lines`. Return results (a list).
 
@@ -187,19 +192,24 @@
 

[-=- -=- -=- 568 lines omitted -=- -=- -=-]

-def extract_indented(lines, until_blank=0, strip_indent=1):
-    """
-    Extract and return a list of indented lines of text.
-
-    Collect all lines with indentation, determine the minimum indentation,
-    remove the minimum indentation from all indented lines (unless
-    `strip_indent` is false), and return them. All lines up to but not
-    including the first unindented line will be returned.
-
-    :Parameters:
-        - `lines`: a list of one-line strings without newlines.
-        - `until_blank`: Stop collecting at the first blank line if true (1).
-        - `strip_indent`: Strip common leading indent if true (1, default).
-
-    :Return:
-        - a list of indented lines with mininum indent removed;
-        - the amount of the indent;
-        - whether or not the block finished with a blank line or at the end of
-          `lines`.
-    """
-    source = []
-    indent = None
-    for line in lines:
-        if line and line[0] != ' ':     # line not indented
-            # block finished properly iff the last indented line was blank
-            blank_finish = len(source) and not source[-1].strip()
-            break
-        stripped = line.lstrip()
-        if until_blank and not stripped: # blank line
-            blank_finish = 1
-            break
-        source.append(line)
-        if not stripped:                # blank line
-            continue
-        lineindent = len(line) - len(stripped)
-        if indent is None:
-            indent = lineindent
-        else:
-            indent = min(indent, lineindent)
-    else:
-        blank_finish = 1                 # block ends at end of lines
-    if indent:
-        if strip_indent:
-            source = [s[indent:] for s in source]
-        return source, indent, blank_finish
-    else:
-        return [], 0, blank_finish
 
 def _exception_data():
     """


=== Zope/lib/python/docutils/utils.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/utils.py:1.1.2.1	Tue Nov  5 04:03:57 2002
+++ Zope/lib/python/docutils/utils.py	Sat Jan 25 07:44:04 2003
@@ -373,12 +373,21 @@
     return ' '.join(name.lower().split())
 
 def new_document(source, settings=None):
+    """
+    Return a new empty document object.
+
+    :Parameters:
+        `source` : string
+            The path to or description of the source text of the document.
+        `settings` : optparse.Values object
+            Runtime settings.  If none provided, a default set will be used.
+    """
     if settings is None:
         settings = frontend.OptionParser().get_default_values()
     reporter = Reporter(source, settings.report_level, settings.halt_level,
                         settings.warning_stream, settings.debug)
     document = nodes.document(settings, reporter, source=source)
-    document.note_source(source)
+    document.note_source(source, -1)
     return document
 
 def clean_rcs_keywords(paragraph, keyword_substitutions):
@@ -396,7 +405,7 @@
 
     If there is no common prefix, return the absolute path to `target`.
     """
-    source_parts = os.path.abspath(source or '').split(os.sep)
+    source_parts = os.path.abspath(source or 'dummy_file').split(os.sep)
     target_parts = os.path.abspath(target).split(os.sep)
     # Check first 2 parts because '/dir'.split('/') == ['', 'dir']:
     if source_parts[:2] != target_parts[:2]: