Fix bug 2896512 and add some more test cases.
[docutils.git] / docutils / __init__.py
blob035e2bdcd75707e2ae8c7d23abe257b583a648da
1 # $Id$
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
5 """
6 This is the Docutils (Python Documentation Utilities) package.
8 Package Structure
9 =================
11 Modules:
13 - __init__.py: Contains component base classes, exception classes, and
14 Docutils version information.
16 - core.py: Contains the ``Publisher`` class and ``publish_*()`` convenience
17 functions.
19 - frontend.py: Runtime settings (command-line interface, configuration files)
20 processing, for Docutils front-ends.
22 - io.py: Provides a uniform API for low-level input and output.
24 - nodes.py: Docutils document tree (doctree) node class library.
26 - statemachine.py: A finite state machine specialized for
27 regular-expression-based text filters.
29 - urischemes.py: Contains a complete mapping of known URI addressing
30 scheme names to descriptions.
32 - utils.py: Contains the ``Reporter`` system warning class and miscellaneous
33 utilities.
35 Subpackages:
37 - languages: Language-specific mappings of terms.
39 - parsers: Syntax-specific input parser modules or packages.
41 - readers: Context-specific input handlers which understand the data
42 source and manage a parser.
44 - transforms: Modules used by readers and writers to modify DPS
45 doctrees.
47 - writers: Format-specific output translators.
48 """
50 __docformat__ = 'reStructuredText'
52 __version__ = '0.7'
53 """``major.minor.micro`` version number. The micro number is bumped for API
54 changes, for new functionality, and for interim project releases. The minor
55 number is bumped whenever there is a significant project release. The major
56 number will be bumped when the project is feature-complete, and perhaps if
57 there is a major change in the design."""
59 __version_details__ = 'repository'
60 """Extra version details (e.g. 'snapshot 2005-05-29, r3410', 'repository',
61 'release'), modified automatically & manually."""
63 class ApplicationError(StandardError): pass
64 class DataError(ApplicationError): pass
67 class SettingsSpec:
69 """
70 Runtime setting specification base class.
72 SettingsSpec subclass objects used by `docutils.frontend.OptionParser`.
73 """
75 settings_spec = ()
76 """Runtime settings specification. Override in subclasses.
78 Defines runtime settings and associated command-line options, as used by
79 `docutils.frontend.OptionParser`. This is a tuple of:
81 - Option group title (string or `None` which implies no group, just a list
82 of single options).
84 - Description (string or `None`).
86 - A sequence of option tuples. Each consists of:
88 - Help text (string)
90 - List of option strings (e.g. ``['-Q', '--quux']``).
92 - Dictionary of keyword arguments sent to the OptionParser/OptionGroup
93 ``add_option`` method.
95 Runtime setting names are derived implicitly from long option names
96 ('--a-setting' becomes ``settings.a_setting``) or explicitly from the
97 'dest' keyword argument.
99 Most settings will also have a 'validator' keyword & function. The
100 validator function validates setting values (from configuration files
101 and command-line option arguments) and converts them to appropriate
102 types. For example, the ``docutils.frontend.validate_boolean``
103 function, **required by all boolean settings**, converts true values
104 ('1', 'on', 'yes', and 'true') to 1 and false values ('0', 'off',
105 'no', 'false', and '') to 0. Validators need only be set once per
106 setting. See the `docutils.frontend.validate_*` functions.
108 See the optparse docs for more details.
110 - More triples of group title, description, options, as many times as
111 needed. Thus, `settings_spec` tuples can be simply concatenated.
114 settings_defaults = None
115 """A dictionary of defaults for settings not in `settings_spec` (internal
116 settings, intended to be inaccessible by command-line and config file).
117 Override in subclasses."""
119 settings_default_overrides = None
120 """A dictionary of auxiliary defaults, to override defaults for settings
121 defined in other components. Override in subclasses."""
123 relative_path_settings = ()
124 """Settings containing filesystem paths. Override in subclasses.
125 Settings listed here are to be interpreted relative to the current working
126 directory."""
128 config_section = None
129 """The name of the config file section specific to this component
130 (lowercase, no brackets). Override in subclasses."""
132 config_section_dependencies = None
133 """A list of names of config file sections that are to be applied before
134 `config_section`, in order (from general to specific). In other words,
135 the settings in `config_section` are to be overlaid on top of the settings
136 from these sections. The "general" section is assumed implicitly.
137 Override in subclasses."""
140 class TransformSpec:
143 Runtime transform specification base class.
145 TransformSpec subclass objects used by `docutils.transforms.Transformer`.
148 def get_transforms(self):
149 """Transforms required by this class. Override in subclasses."""
150 if self.default_transforms != ():
151 import warnings
152 warnings.warn('default_transforms attribute deprecated.\n'
153 'Use get_transforms() method instead.',
154 DeprecationWarning)
155 return list(self.default_transforms)
156 return []
158 # Deprecated; for compatibility.
159 default_transforms = ()
161 unknown_reference_resolvers = ()
162 """List of functions to try to resolve unknown references. Unknown
163 references have a 'refname' attribute which doesn't correspond to any
164 target in the document. Called when the transforms in
165 `docutils.tranforms.references` are unable to find a correct target. The
166 list should contain functions which will try to resolve unknown
167 references, with the following signature::
169 def reference_resolver(node):
170 '''Returns boolean: true if resolved, false if not.'''
172 If the function is able to resolve the reference, it should also remove
173 the 'refname' attribute and mark the node as resolved::
175 del node['refname']
176 node.resolved = 1
178 Each function must have a "priority" attribute which will affect the order
179 the unknown_reference_resolvers are run::
181 reference_resolver.priority = 100
183 Override in subclasses."""
186 class Component(SettingsSpec, TransformSpec):
188 """Base class for Docutils components."""
190 component_type = None
191 """Name of the component type ('reader', 'parser', 'writer'). Override in
192 subclasses."""
194 supported = ()
195 """Names for this component. Override in subclasses."""
197 def supports(self, format):
199 Is `format` supported by this component?
201 To be used by transforms to ask the dependent component if it supports
202 a certain input context or output format.
204 return format in self.supported