[Zope-Checkins] CVS: Zope/lib/python/docutils - examples.py:1.1.2.1
__init__.py:1.2.10.3.8.1 core.py:1.2.10.3.8.1
frontend.py:1.2.10.4.8.1 io.py:1.2.10.3.8.1
nodes.py:1.2.10.3.8.1 statemachine.py:1.2.10.3.8.1
urischemes.py:1.2.10.2.8.1 utils.py:1.2.10.3.8.1
Christian 'Tiran' Heimes
heimes at faho.rwth-aachen.de
Wed May 12 15:58:13 EDT 2004
Update of /cvs-repository/Zope/lib/python/docutils
In directory cvs.zope.org:/tmp/cvs-serv1763/lib/python/docutils
Modified Files:
Tag: tiran-restfixing-branch
__init__.py core.py frontend.py io.py nodes.py statemachine.py
urischemes.py utils.py
Added Files:
Tag: tiran-restfixing-branch
examples.py
Log Message:
Installed docutils 0.3.4
=== Added File Zope/lib/python/docutils/examples.py ===
# Authors: David Goodger
# Contact: goodger at python.org
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2004/05/12 19:57:38 $
# Copyright: This module has been placed in the public domain.
"""
This module contains practical examples of Docutils client code.
Importing this module is not recommended; its contents are subject to change
in future Docutils releases. Instead, it is recommended that you copy and
paste the parts you need into your own code, modifying as necessary.
"""
from docutils import core
def html_parts(input_string, source_path=None, destination_path=None,
input_encoding='unicode', doctitle=1, initial_header_level=1):
"""
Given an input string, returns a dictionary of HTML document parts.
Dictionary keys are the names of parts, and values are Unicode strings;
encoding is up to the client.
Parameters:
- `input_string`: A multi-line text string; required.
- `source_path`: Path to the source file or object. Optional, but useful
for diagnostic output (system messages).
- `destination_path`: Path to the file or object which will receive the
output; optional. Used for determining relative paths (stylesheets,
source links, etc.).
- `input_encoding`: The encoding of `input_string`. If it is an encoded
8-bit string, provide the correct encoding. If it is a Unicode string,
use "unicode", the default.
- `doctitle`: Disable the promotion of a lone top-level section title to
document title (and subsequent section title to document subtitle
promotion); enabled by default.
- `initial_header_level`: The initial level for header elements (e.g. 1
for "<h1>").
"""
overrides = {'input_encoding': input_encoding,
'doctitle_xform': doctitle,
'initial_header_level': initial_header_level}
parts = core.publish_parts(
source=input_string, source_path=source_path,
destination_path=destination_path,
writer_name='html', settings_overrides=overrides)
return parts
def html_fragment(input_string, source_path=None, destination_path=None,
input_encoding='unicode', output_encoding='unicode',
doctitle=1, initial_header_level=1):
"""
Given an input string, returns an HTML fragment as a string.
The return value is the contents of the <body> tag, less the title,
subtitle, and docinfo.
Parameters (see `html_parts()` for the remainder):
- `output_encoding`: The desired encoding of the output. If a Unicode
string is desired, use the default value of "unicode" .
"""
parts = html_parts(
input_string=input_string, source_path=source_path,
destination_path=destination_path,
input_encoding=input_encoding, doctitle=doctitle,
initial_header_level=initial_header_level)
fragment = parts['fragment']
if output_encoding != 'unicode':
fragment = fragment.encode(output_encoding)
return fragment
=== Zope/lib/python/docutils/__init__.py 1.2.10.3 => 1.2.10.3.8.1 ===
--- Zope/lib/python/docutils/__init__.py:1.2.10.3 Sun Nov 30 11:05:21 2003
+++ Zope/lib/python/docutils/__init__.py Wed May 12 15:57:37 2004
@@ -51,12 +51,14 @@
__docformat__ = 'reStructuredText'
-__version__ = '0.3.1'
-"""``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 or
-significant new functionality. The minor number is bumped whenever there is a
+__version__ = '0.3.4'
+"""``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 or significant new functionality, and at any alpha or beta
+release. The minor number is bumped whenever there is a stable
project release. The major number will be bumped when the project is
-feature-complete, and perhaps if there is a major change in the design."""
+feature-complete, and perhaps if there is a major change in the
+design."""
class ApplicationError(StandardError): pass
@@ -122,6 +124,22 @@
default_transforms = ()
"""Transforms required by this class. Override in subclasses."""
+
+ unknown_reference_resolvers = ()
+ """List of functions to try to resolve unknown references. Called when
+ FinalCheckVisitor is unable to find a correct target. The list should
+ contain functions which will try to resolve unknown references, with the
+ following signature::
+
+ def reference_resolver(node):
+ '''Returns boolean: true if resolved, false if not.'''
+
+ Each function must have a "priority" attribute which will affect the order
+ the unknown_reference_resolvers are run::
+
+ reference_resolver.priority = 100
+
+ Override in subclasses."""
class Component(SettingsSpec, TransformSpec):
@@ -129,11 +147,12 @@
"""Base class for Docutils components."""
component_type = None
- """Override in subclasses."""
+ """Name of the component type ('reader', 'parser', 'writer'). Override in
+ subclasses."""
supported = ()
"""Names for this component. Override in subclasses."""
-
+
def supports(self, format):
"""
Is `format` supported by this component?
=== Zope/lib/python/docutils/core.py 1.2.10.3 => 1.2.10.3.8.1 ===
--- Zope/lib/python/docutils/core.py:1.2.10.3 Sun Nov 30 11:05:21 2003
+++ Zope/lib/python/docutils/core.py Wed May 12 15:57:38 2004
@@ -180,6 +180,7 @@
self.settings)
self.apply_transforms(document)
output = self.writer.write(document, self.destination)
+ self.writer.assemble_parts()
except utils.SystemMessage, error:
if self.settings.traceback:
raise
@@ -376,3 +377,63 @@
pub.set_source(source, source_path)
pub.set_destination(destination_path=destination_path)
return pub.publish(enable_exit=enable_exit)
+
+def publish_parts(source, source_path=None, destination_path=None,
+ reader=None, reader_name='standalone',
+ parser=None, parser_name='restructuredtext',
+ writer=None, writer_name='pseudoxml',
+ settings=None, settings_spec=None,
+ settings_overrides=None, config_section=None,
+ enable_exit=None):
+ """
+ Set up & run a `Publisher`, and return a dictionary of document parts.
+ Dictionary keys are the names of parts, and values are Unicode strings;
+ encoding is up to the client. For programmatic use with string I/O.
+
+ For encoded string input, be sure to set the "input_encoding" setting to
+ the desired encoding. Set it to "unicode" for unencoded Unicode string
+ input. Here's how::
+
+ publish_string(..., settings_overrides={'input_encoding': 'unicode'})
+
+ Parameters:
+
+ - `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
+ output; optional. Used for determining relative paths (stylesheets,
+ source links, etc.).
+ - `reader`: A `docutils.readers.Reader` object.
+ - `reader_name`: Name or alias of the Reader class to be instantiated if
+ no `reader` supplied.
+ - `parser`: A `docutils.parsers.Parser` object.
+ - `parser_name`: Name or alias of the Parser class to be instantiated if
+ no `parser` supplied.
+ - `writer`: A `docutils.writers.Writer` object.
+ - `writer_name`: Name or alias of the Writer class to be instantiated if
+ no `writer` supplied.
+ - `settings`: Runtime settings object.
+ - `settings_spec`: Extra settings specification; a `docutils.SettingsSpec`
+ subclass. Used only if no `settings` specified.
+ - `settings_overrides`: A dictionary containing program-specific overrides
+ of component settings.
+ - `config_section`: Name of configuration file section for application.
+ Used only if no `settings` or `settings_spec` specified.
+ - `enable_exit`: Boolean; enable exit status at end of processing?
+ """
+ pub = Publisher(reader, parser, writer, settings=settings,
+ source_class=io.StringInput,
+ destination_class=io.NullOutput)
+ pub.set_components(reader_name, parser_name, writer_name)
+ if settings is None:
+ settings = pub.get_settings(settings_spec=settings_spec,
+ config_section=config_section)
+ if settings_overrides:
+ settings._update(settings_overrides, 'loose')
+ pub.set_source(source, source_path)
+ pub.set_destination(destination_path=destination_path)
+ pub.publish(enable_exit=enable_exit)
+ return pub.writer.parts
=== Zope/lib/python/docutils/frontend.py 1.2.10.4 => 1.2.10.4.8.1 ===
--- Zope/lib/python/docutils/frontend.py:1.2.10.4 Sun Nov 30 11:05:21 2003
+++ Zope/lib/python/docutils/frontend.py Wed May 12 15:57:38 2004
@@ -126,8 +126,7 @@
def validate_threshold(setting, value, option_parser,
config_parser=None, config_section=None):
try:
- int(value)
- return value
+ return int(value)
except ValueError:
try:
return option_parser.thresholds[value.lower()]
@@ -294,6 +293,10 @@
('Disable backlinks from footnotes and citations.',
['--no-footnote-backlinks'],
{'dest': 'footnote_backlinks', 'action': 'store_false'}),
+ ('Disable Docutils section numbering',
+ ['--no-section-numbering'],
+ {'action': 'store_false', 'dest': 'sectnum_xform',
+ 'default': 1, 'validator': validate_boolean}),
('Set verbosity threshold; report system messages at or higher than '
'<level> (by name or number: "info" or "1", warning/2, error/3, '
'severe/4; also, "none" or "5"). Default is 2 (warning).',
@@ -346,7 +349,7 @@
{'metavar': '<name[:handler]>', 'default': 'utf-8',
'validator': validate_encoding_and_error_handler}),
(SUPPRESS_HELP, # usually handled by --output-encoding
- ['--output_encoding_error_handler'],
+ ['--output-encoding-error-handler'],
{'default': 'strict', 'validator': validate_encoding_error_handler}),
('Specify the text encoding for error output. Default is ASCII. '
'Optionally also specify the encoding error handler for unencodable '
@@ -357,7 +360,7 @@
{'metavar': '<name[:handler]>', 'default': 'ascii',
'validator': validate_encoding_and_error_handler}),
(SUPPRESS_HELP, # usually handled by --error-encoding
- ['--error_encoding_error_handler'],
+ ['--error-encoding-error-handler'],
{'default': default_error_encoding_error_handler,
'validator': validate_encoding_error_handler}),
('Specify the language of input text (ISO 639 2-letter identifier).'
=== Zope/lib/python/docutils/io.py 1.2.10.3 => 1.2.10.3.8.1 ===
--- Zope/lib/python/docutils/io.py:1.2.10.3 Sun Nov 30 11:05:21 2003
+++ Zope/lib/python/docutils/io.py Wed May 12 15:57:38 2004
@@ -12,7 +12,10 @@
__docformat__ = 'reStructuredText'
import sys
-import locale
+try:
+ import locale
+except:
+ pass
from types import UnicodeType
from docutils import TransformSpec
@@ -156,7 +159,7 @@
print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error)
print >>sys.stderr, (
- 'Unable to open source file for reading (%s). Exiting.'
+ 'Unable to open source file for reading (%r). Exiting.'
% source_path)
sys.exit(1)
else:
@@ -224,7 +227,7 @@
print >>sys.stderr, '%s: %s' % (error.__class__.__name__,
error)
print >>sys.stderr, ('Unable to open destination file for writing '
- '(%s). Exiting.' % source_path)
+ '(%r). Exiting.' % self.destination_path)
sys.exit(1)
self.opened = 1
=== Zope/lib/python/docutils/nodes.py 1.2.10.3 => 1.2.10.3.8.1 ===
--- Zope/lib/python/docutils/nodes.py:1.2.10.3 Sun Nov 30 11:05:22 2003
+++ Zope/lib/python/docutils/nodes.py Wed May 12 15:57:38 2004
@@ -517,6 +517,9 @@
its immediate parent is a `TextElement` instance (including subclasses).
This is handy for nodes like `image` that can appear both inline and as
standalone body elements.
+
+ If passing children to `__init__()`, make sure to set `text` to
+ ``''`` or some other suitable value.
"""
child_text_separator = ''
@@ -599,6 +602,9 @@
referenced = 0
+ indirect_reference_name = None
+ """Holds the whitespace_normalized_name (contains mixed case) of a target"""
+
class Labeled:
"""Contains a `label` as its first element."""
@@ -820,6 +826,7 @@
def has_name(self, name):
return self.nameids.has_key(name)
+ # "note" here is an imperative verb: "take note of".
def note_implicit_target(self, target, msgnode=None):
id = self.set_id(target, msgnode)
self.set_name_id_map(target, id, msgnode, explicit=None)
@@ -939,6 +946,7 @@
# ========================
class docinfo(Bibliographic, Element): pass
+class info(Bibliographic, Element): pass
class author(Bibliographic, TextElement): pass
class authors(Bibliographic, Element): pass
class organization(Bibliographic, TextElement): pass
@@ -1182,7 +1190,7 @@
class emphasis(Inline, TextElement): pass
class strong(Inline, TextElement): pass
class literal(Inline, TextElement): pass
-class reference(Inline, Referential, TextElement): pass
+class reference(General, Inline, Referential, TextElement): pass
class footnote_reference(Inline, Referential, TextElement): pass
class citation_reference(Inline, Referential, TextElement): pass
class substitution_reference(Inline, TextElement): pass
@@ -1222,7 +1230,7 @@
footnote footnote_reference
generated
header hint
- image important inline
+ image important info inline
label legend line_block list_item literal literal_block
note
option option_argument option_group option_list option_list_item
@@ -1273,8 +1281,8 @@
Raise an exception unless overridden.
"""
- raise NotImplementedError('visiting unknown node type: %s'
- % node.__class__.__name__)
+ raise NotImplementedError('%s visiting unknown node type: %s'
+ % (self.__class__, node.__class__.__name__))
def unknown_departure(self, node):
"""
@@ -1282,8 +1290,8 @@
Raise exception unless overridden.
"""
- raise NotImplementedError('departing unknown node type: %s'
- % node.__class__.__name__)
+ raise NotImplementedError('%s departing unknown node type: %s'
+ % (self.__class__, node.__class__.__name__))
class SparseNodeVisitor(NodeVisitor):
@@ -1295,16 +1303,6 @@
subclasses), subclass `NodeVisitor` instead.
"""
-def _nop(self, node):
- pass
-
-# Save typing with dynamic assignments:
-for _name in node_class_names:
- setattr(SparseNodeVisitor, "visit_" + _name, _nop)
- setattr(SparseNodeVisitor, "depart_" + _name, _nop)
-del _name, _nop
-
-
class GenericNodeVisitor(NodeVisitor):
"""
@@ -1337,12 +1335,18 @@
def _call_default_departure(self, node):
self.default_departure(node)
-# Save typing with dynamic assignments:
-for _name in node_class_names:
- setattr(GenericNodeVisitor, "visit_" + _name, _call_default_visit)
- setattr(GenericNodeVisitor, "depart_" + _name, _call_default_departure)
-del _name, _call_default_visit, _call_default_departure
+def _nop(self, node):
+ pass
+
+def _add_node_class_names(names):
+ """Save typing with dynamic assignments:"""
+ for _name in names:
+ setattr(GenericNodeVisitor, "visit_" + _name, _call_default_visit)
+ setattr(GenericNodeVisitor, "depart_" + _name, _call_default_departure)
+ setattr(SparseNodeVisitor, 'visit_' + _name, _nop)
+ setattr(SparseNodeVisitor, 'depart' + _name, _nop)
+_add_node_class_names(node_class_names)
class TreeCopyVisitor(GenericNodeVisitor):
=== Zope/lib/python/docutils/statemachine.py 1.2.10.3 => 1.2.10.3.8.1 ===
=== Zope/lib/python/docutils/urischemes.py 1.2.10.2 => 1.2.10.2.8.1 ===
--- Zope/lib/python/docutils/urischemes.py:1.2.10.2 Sun Nov 30 11:05:22 2003
+++ Zope/lib/python/docutils/urischemes.py Wed May 12 15:57:39 2004
@@ -1,7 +1,8 @@
"""
`schemes` is a dictionary with lowercase URI addressing schemes as
keys and descriptions as values. It was compiled from the index at
-http://www.w3.org/Addressing/schemes.html (revised 2001-08-20).
+http://www.iana.org/assignments/uri-schemes (revised 2003-11-26)
+and an older list at http://www.w3.org/Addressing/schemes.html.
"""
# Many values are blank and should be filled in with useful descriptions.
@@ -26,10 +27,12 @@
'specialized to justify their own schemes'),
'fax': ('a connection to a terminal that can handle telefaxes '
'(facsimiles); RFC 2806'),
+ 'feed' : 'NetNewsWire feed',
'file': 'Host-specific file names',
'finger': '',
'freenet': '',
'ftp': 'File Transfer Protocol',
+ 'go': 'go; RFC3368',
'gopher': 'The Gopher Protocol',
'gsm-sms': ('Global System for Mobile Communications Short Message '
'Service'),
@@ -40,16 +43,19 @@
'hnews': 'an HTTP-tunneling variant of the NNTP news protocol',
'http': 'Hypertext Transfer Protocol',
'https': 'HTTP over SSL',
+ 'hydra': 'SubEthaEdit URI. See http://www.codingmonkeys.de/subethaedit.',
'iioploc': 'Internet Inter-ORB Protocol Location?',
'ilu': 'Inter-Language Unification',
+ 'im': 'Instant Messaging',
'imap': 'Internet Message Access Protocol',
'ior': 'CORBA interoperable object reference',
'ipp': 'Internet Printing Protocol',
'irc': 'Internet Relay Chat',
+ 'iseek' : 'See www.ambrosiasw.com; a little util for OS X.',
'jar': 'Java archive',
'javascript': ('JavaScript code; evaluates the expression after the '
'colon'),
- 'jdbc': '',
+ 'jdbc': 'JDBC connection URI.',
'ldap': 'Lightweight Directory Access Protocol',
'lifn': '',
'livescript': '',
@@ -62,6 +68,7 @@
'mocha': '',
'modem': ('a connection to a terminal that can handle incoming data '
'calls; RFC 2806'),
+ 'mupdate': 'Mailbox Update (MUPDATE) Protocol',
'news': 'USENET news',
'nfs': 'Network File System protocol',
'nntp': 'USENET news using NNTP access',
@@ -69,8 +76,10 @@
'phone': '',
'pop': 'Post Office Protocol',
'pop3': 'Post Office Protocol v3',
+ 'pres': 'Presence',
'printer': '',
'prospero': 'Prospero Directory Service',
+ 'rdar' : 'URLs found in Darwin source (http://www.opensource.apple.com/darwinsource/).',
'res': '',
'rtsp': 'real time streaming protocol',
'rvp': '',
@@ -80,8 +89,12 @@
'service': 'service location',
'shttp': 'secure hypertext transfer protocol',
'sip': 'Session Initiation Protocol',
- 'smb': '',
+ 'sips': 'secure session intitiaion protocol',
+ 'smb': 'SAMBA filesystems.',
'snews': 'For NNTP postings via SSL',
+ 'soap.beep': '',
+ 'soap.beeps': '',
+ 'ssh': 'Reference to interactive sessions via ssh.',
't120': 'real time data conferencing (audiographics)',
'tcp': '',
'tel': ('a connection to a terminal that handles normal voice '
@@ -90,6 +103,7 @@
'RFC 2806.'),
'telephone': 'telephone',
'telnet': 'Reference to interactive sessions',
+ 'tftp': 'Trivial File Transfer Protocol',
'tip': 'Transaction Internet Protocol',
'tn3270': 'Interactive 3270 emulation sessions',
'tv': '',
@@ -101,5 +115,8 @@
'wais': 'Wide Area Information Servers',
'whodp': '',
'whois++': 'Distributed directory service.',
+ 'x-man-page': 'Opens man page in Terminal.app on OS X (see macosxhints.com)',
+ 'xmlrpc.beep': '',
+ 'xmlrpc.beeps': '',
'z39.50r': 'Z39.50 Retrieval',
'z39.50s': 'Z39.50 Session',}
=== Zope/lib/python/docutils/utils.py 1.2.10.3 => 1.2.10.3.8.1 ===
--- Zope/lib/python/docutils/utils.py:1.2.10.3 Sun Nov 30 11:05:22 2003
+++ Zope/lib/python/docutils/utils.py Wed May 12 15:57:39 2004
@@ -324,7 +324,9 @@
"""
options = {}
for name, value in option_list:
- convertor = options_spec[name] # raises KeyError if unknown
+ convertor = options_spec[name] # raises KeyError if unknown
+ if convertor is None:
+ raise KeyError(name) # or if explicitly disabled
if options.has_key(name):
raise DuplicateOptionError('duplicate option "%s"' % name)
try:
@@ -406,7 +408,7 @@
if len(paragraph) == 1 and isinstance(paragraph[0], nodes.Text):
textnode = paragraph[0]
for pattern, substitution in keyword_substitutions:
- match = pattern.match(textnode.data)
+ match = pattern.search(textnode.data)
if match:
textnode.data = pattern.sub(substitution, textnode.data)
return
More information about the Zope-Checkins
mailing list