Skip to content

Commit

Permalink
Take proper advantage of Sphinx's default domains.
Browse files Browse the repository at this point in the history
  • Loading branch information
earwig committed Jul 11, 2014
1 parent 2b1f7e5 commit 87e0079
Show file tree
Hide file tree
Showing 19 changed files with 248 additions and 256 deletions.
8 changes: 4 additions & 4 deletions mwparserfromhell/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

"""
Implements support for both Python 2 and Python 3 by defining common types in
terms of their Python 2/3 variants. For example, :py:class:`str` is set to
:py:class:`unicode` on Python 2 but :py:class:`str` on Python 3; likewise,
:py:class:`bytes` is :py:class:`str` on 2 but :py:class:`bytes` on 3. These
types are meant to be imported directly from within the parser's modules.
terms of their Python 2/3 variants. For example, :class:`str` is set to
:class:`unicode` on Python 2 but :class:`str` on Python 3; likewise,
:class:`bytes` is :class:`str` on 2 but :class:`bytes` on 3. These types are
meant to be imported directly from within the parser's modules.
"""

import sys
Expand Down
26 changes: 13 additions & 13 deletions mwparserfromhell/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
# SOFTWARE.

"""
This package contains :py:class:`~.Wikicode` "nodes", which represent a single
unit of wikitext, such as a Template, an HTML tag, a Heading, or plain text.
The node "tree" is far from flat, as most types can contain additional
:py:class:`~.Wikicode` types within them - and with that, more nodes. For
example, the name of a :py:class:`~.Template` is a :py:class:`~.Wikicode`
object that can contain text or more templates.
This package contains :class:`.Wikicode` "nodes", which represent a single unit
of wikitext, such as a Template, an HTML tag, a Heading, or plain text. The
node "tree" is far from flat, as most types can contain additional
:class:`.Wikicode` types within them - and with that, more nodes. For example,
the name of a :class:`.Template` is a :class:`.Wikicode` object that can
contain text or more templates.
"""

from __future__ import unicode_literals
Expand All @@ -40,16 +40,16 @@
class Node(StringMixIn):
"""Represents the base Node type, demonstrating the methods to override.
:py:meth:`__unicode__` must be overridden. It should return a ``unicode``
or (``str`` in py3k) representation of the node. If the node contains
:py:class:`~.Wikicode` objects inside of it, :py:meth:`__children__`
should be a generator that iterates over them. If the node is printable
(shown when the page is rendered), :py:meth:`__strip__` should return its
:meth:`__unicode__` must be overridden. It should return a ``unicode`` or
(``str`` in py3k) representation of the node. If the node contains
:class:`.Wikicode` objects inside of it, :meth:`__children__` should be a
generator that iterates over them. If the node is printable
(shown when the page is rendered), :meth:`__strip__` should return its
printable version, stripping out any formatting marks. It does not have to
return a string, but something that can be converted to a string with
``str()``. Finally, :py:meth:`__showtree__` can be overridden to build a
``str()``. Finally, :meth:`__showtree__` can be overridden to build a
nice tree representation of the node, if desired, for
:py:meth:`~.Wikicode.get_tree`.
:meth:`~.Wikicode.get_tree`.
"""
def __unicode__(self):
raise NotImplementedError()
Expand Down
4 changes: 2 additions & 2 deletions mwparserfromhell/nodes/external_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ def __showtree__(self, write, get, mark):

@property
def url(self):
"""The URL of the link target, as a :py:class:`~.Wikicode` object."""
"""The URL of the link target, as a :class:`.Wikicode` object."""
return self._url

@property
def title(self):
"""The link title (if given), as a :py:class:`~.Wikicode` object."""
"""The link title (if given), as a :class:`.Wikicode` object."""
return self._title

@property
Expand Down
5 changes: 2 additions & 3 deletions mwparserfromhell/nodes/extras/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
# SOFTWARE.

"""
This package contains objects used by
:py:class:`~.Node`\ s, but are not nodes themselves. This includes the
parameters of Templates or the attributes of HTML tags.
This package contains objects used by :class:`.Node`\ s, but that are not nodes
themselves. This includes template parameters and HTML tag attributes.
"""

from .attribute import Attribute
Expand Down
6 changes: 3 additions & 3 deletions mwparserfromhell/nodes/extras/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class Attribute(StringMixIn):
"""Represents an attribute of an HTML tag.
This is used by :py:class:`~.Tag` objects. For example, the tag
This is used by :class:`.Tag` objects. For example, the tag
``<ref name="foo">`` contains an Attribute whose name is ``"name"`` and
whose value is ``"foo"``.
"""
Expand Down Expand Up @@ -84,12 +84,12 @@ def coerce_quotes(quotes):

@property
def name(self):
"""The name of the attribute as a :py:class:`~.Wikicode` object."""
"""The name of the attribute as a :class:`.Wikicode` object."""
return self._name

@property
def value(self):
"""The value of the attribute as a :py:class:`~.Wikicode` object."""
"""The value of the attribute as a :class:`.Wikicode` object."""
return self._value

@property
Expand Down
4 changes: 2 additions & 2 deletions mwparserfromhell/nodes/extras/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def can_hide_key(key):

@property
def name(self):
"""The name of the parameter as a :py:class:`~.Wikicode` object."""
"""The name of the parameter as a :class:`.Wikicode` object."""
return self._name

@property
def value(self):
"""The value of the parameter as a :py:class:`~.Wikicode` object."""
"""The value of the parameter as a :class:`.Wikicode` object."""
return self._value

@property
Expand Down
2 changes: 1 addition & 1 deletion mwparserfromhell/nodes/heading.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __showtree__(self, write, get, mark):

@property
def title(self):
"""The title of the heading, as a :py:class:`~.Wikicode` object."""
"""The title of the heading, as a :class:`.Wikicode` object."""
return self._title

@property
Expand Down
26 changes: 13 additions & 13 deletions mwparserfromhell/nodes/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ def __showtree__(self, write, get, mark):

@property
def tag(self):
"""The tag itself, as a :py:class:`~.Wikicode` object."""
"""The tag itself, as a :class:`.Wikicode` object."""
return self._tag

@property
def contents(self):
"""The contents of the tag, as a :py:class:`~.Wikicode` object."""
"""The contents of the tag, as a :class:`.Wikicode` object."""
return self._contents

@property
def attributes(self):
"""The list of attributes affecting the tag.
Each attribute is an instance of :py:class:`~.Attribute`.
Each attribute is an instance of :class:`.Attribute`.
"""
return self._attrs

Expand All @@ -146,7 +146,7 @@ def invalid(self):
This makes the tag look like a lone close tag. It is technically
invalid and is only parsable Wikicode when the tag itself is
single-only, like ``<br>`` and ``<img>``. See
:py:func:`.definitions.is_single_only`.
:func:`.definitions.is_single_only`.
"""
return self._invalid

Expand All @@ -155,8 +155,8 @@ def implicit(self):
"""Whether the tag is implicitly self-closing, with no ending slash.
This is only possible for specific "single" tags like ``<br>`` and
``<li>``. See :py:func:`.definitions.is_single`. This field only has an
effect if :py:attr:`self_closing` is also ``True``.
``<li>``. See :func:`.definitions.is_single`. This field only has an
effect if :attr:`self_closing` is also ``True``.
"""
return self._implicit

Expand All @@ -167,9 +167,9 @@ def padding(self):

@property
def closing_tag(self):
"""The closing tag, as a :py:class:`~.Wikicode` object.
"""The closing tag, as a :class:`.Wikicode` object.
This will usually equal :py:attr:`tag`, unless there is additional
This will usually equal :attr:`tag`, unless there is additional
spacing, comments, or the like.
"""
return self._closing_tag
Expand Down Expand Up @@ -226,8 +226,8 @@ def has(self, name):
def get(self, name):
"""Get the attribute with the given *name*.
The returned object is a :py:class:`~.Attribute` instance. Raises
:py:exc:`ValueError` if no attribute has this name. Since multiple
The returned object is a :class:`.Attribute` instance. Raises
:exc:`ValueError` if no attribute has this name. Since multiple
attributes can have the same name, we'll return the last match, since
all but the last are ignored by the MediaWiki parser.
"""
Expand All @@ -241,9 +241,9 @@ def add(self, name, value=None, quotes='"', pad_first=" ",
"""Add an attribute with the given *name* and *value*.
*name* and *value* can be anything parsable by
:py:func:`.utils.parse_anything`; *value* can be omitted if the
attribute is valueless. If *quotes* is not ``None``, it should be a
string (either ``"`` or ``'``) that *value* will be wrapped in (this is
:func:`.utils.parse_anything`; *value* can be omitted if the attribute
is valueless. If *quotes* is not ``None``, it should be a string
(either ``"`` or ``'``) that *value* will be wrapped in (this is
recommended). ``None`` is only legal if *value* contains no spacing.
*pad_first*, *pad_before_eq*, and *pad_after_eq* are whitespace used as
Expand Down
32 changes: 16 additions & 16 deletions mwparserfromhell/nodes/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ def _get_spacing_conventions(self, use_names):
"""Try to determine the whitespace conventions for parameters.
This will examine the existing parameters and use
:py:meth:`_select_theory` to determine if there are any preferred
styles for how much whitespace to put before or after the value.
:meth:`_select_theory` to determine if there are any preferred styles
for how much whitespace to put before or after the value.
"""
before_theories = defaultdict(lambda: 0)
after_theories = defaultdict(lambda: 0)
Expand Down Expand Up @@ -159,7 +159,7 @@ def _remove_exact(self, needle, keep_field):

@property
def name(self):
"""The name of the template, as a :py:class:`~.Wikicode` object."""
"""The name of the template, as a :class:`.Wikicode` object."""
return self._name

@property
Expand Down Expand Up @@ -189,13 +189,13 @@ def has(self, name, ignore_empty=False):

has_param = lambda self, name, ignore_empty=False: \
self.has(name, ignore_empty)
has_param.__doc__ = "Alias for :py:meth:`has`."
has_param.__doc__ = "Alias for :meth:`has`."

def get(self, name):
"""Get the parameter whose name is *name*.
The returned object is a :py:class:`~.Parameter` instance. Raises
:py:exc:`ValueError` if no parameter has this name. Since multiple
The returned object is a :class:`.Parameter` instance. Raises
:exc:`ValueError` if no parameter has this name. Since multiple
parameters can have the same name, we'll return the last match, since
the last parameter is the only one read by the MediaWiki parser.
"""
Expand All @@ -210,8 +210,8 @@ def add(self, name, value, showkey=None, before=None,
"""Add a parameter to the template with a given *name* and *value*.
*name* and *value* can be anything parsable by
:py:func:`.utils.parse_anything`; pipes and equal signs are
automatically escaped from *value* when appropriate.
:func:`.utils.parse_anything`; pipes and equal signs are automatically
escaped from *value* when appropriate.
If *showkey* is given, this will determine whether or not to show the
parameter's name (e.g., ``{{foo|bar}}``'s parameter has a name of
Expand All @@ -221,13 +221,13 @@ def add(self, name, value, showkey=None, before=None,
If *name* is already a parameter in the template, we'll replace its
value while keeping the same whitespace around it. We will also try to
guess the dominant spacing convention when adding a new parameter using
:py:meth:`_get_spacing_conventions`.
:meth:`_get_spacing_conventions`.
If *before* is given (either a :py:class:`~.Parameter` object or a
name), then we will place the parameter immediately before this one.
If *before* is given (either a :class:`.Parameter` object or a name),
then we will place the parameter immediately before this one.
Otherwise, it will be added at the end. If *before* is a name and
exists multiple times in the template, we will place it before the last
occurrence. If *before* is not in the template, :py:exc:`ValueError` is
occurrence. If *before* is not in the template, :exc:`ValueError` is
raised. The argument is ignored if the new parameter already exists.
If *preserve_spacing* is ``False``, we will avoid preserving spacing
Expand Down Expand Up @@ -289,9 +289,9 @@ def add(self, name, value, showkey=None, before=None,
def remove(self, param, keep_field=False):
"""Remove a parameter from the template, identified by *param*.
If *param* is a :py:class:`.Parameter` object, it will be matched
exactly, otherwise it will be treated like the *name* argument to
:py:meth:`has` and :py:meth:`get`.
If *param* is a :class:`.Parameter` object, it will be matched exactly,
otherwise it will be treated like the *name* argument to :meth:`has`
and :meth:`get`.
If *keep_field* is ``True``, we will keep the parameter's name, but
blank its value. Otherwise, we will remove the parameter completely
Expand All @@ -300,7 +300,7 @@ def remove(self, param, keep_field=False):
we expected, so ``{{foo||baz}}`` will be produced instead).
If the parameter shows up multiple times in the template and *param* is
not a :py:class:`.Parameter` object, we will remove all instances of it
not a :class:`.Parameter` object, we will remove all instances of it
(and keep only one if *keep_field* is ``True`` - the first instance if
none have dependents, otherwise the one with dependents will be kept).
"""
Expand Down
4 changes: 2 additions & 2 deletions mwparserfromhell/nodes/wikilink.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ def __showtree__(self, write, get, mark):

@property
def title(self):
"""The title of the linked page, as a :py:class:`~.Wikicode` object."""
"""The title of the linked page, as a :class:`.Wikicode` object."""
return self._title

@property
def text(self):
"""The text to display (if any), as a :py:class:`~.Wikicode` object."""
"""The text to display (if any), as a :class:`.Wikicode` object."""
return self._text

@title.setter
Expand Down
36 changes: 18 additions & 18 deletions mwparserfromhell/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

"""
This package contains the actual wikicode parser, split up into two main
modules: the :py:mod:`~.tokenizer` and the :py:mod:`~.builder`. This module
joins them together under one interface.
modules: the :mod:`.tokenizer` and the :mod:`.builder`. This module joins them
together into one interface.
"""

class ParserError(Exception):
Expand Down Expand Up @@ -54,16 +54,16 @@ class Parser(object):
"""Represents a parser for wikicode.
Actual parsing is a two-step process: first, the text is split up into a
series of tokens by the :py:class:`.Tokenizer`, and then the tokens are
converted into trees of :py:class:`.Wikicode` objects and
:py:class:`.Node`\ s by the :py:class:`.Builder`.
series of tokens by the :class:`.Tokenizer`, and then the tokens are
converted into trees of :class:`.Wikicode` objects and :class:`.Node`\ s by
the :class:`.Builder`.
Instances of this class or its dependents (:py:class:`.Tokenizer` and
:py:class:`.Builder`) should not be shared between threads.
:py:meth:`parse` can be called multiple times as long as it is not done
concurrently. In general, there is no need to do this because parsing
should be done through :py:func:`mwparserfromhell.parse`, which creates a
new :py:class:`.Parser` object as necessary.
Instances of this class or its dependents (:class:`.Tokenizer` and
:class:`.Builder`) should not be shared between threads. :meth:`parse` can
be called multiple times as long as it is not done concurrently. In
general, there is no need to do this because parsing should be done through
:func:`mwparserfromhell.parse`, which creates a new :class:`.Parser` object
as necessary.
"""

def __init__(self):
Expand All @@ -74,20 +74,20 @@ def __init__(self):
self._builder = Builder()

def parse(self, text, context=0, skip_style_tags=False):
"""Parse *text*, returning a :py:class:`~.Wikicode` object tree.
"""Parse *text*, returning a :class:`.Wikicode` object tree.
If given, *context* will be passed as a starting context to the parser.
This is helpful when this function is used inside node attribute
setters. For example, :py:class:`~.ExternalLink`\ 's
:py:attr:`~.ExternalLink.url` setter sets *context* to
:py:mod:`contexts.EXT_LINK_URI <.contexts>` to prevent the URL itself
from becoming an :py:class:`~.ExternalLink`.
setters. For example, :class:`.ExternalLink`\ 's
:attr:`~.ExternalLink.url` setter sets *context* to
:mod:`contexts.EXT_LINK_URI <.contexts>` to prevent the URL itself
from becoming an :class:`.ExternalLink`.
If *skip_style_tags* is ``True``, then ``''`` and ``'''`` will not be
parsed, but instead will be treated as plain text.
If there is an internal error while parsing, :py:exc:`.ParserError`
will be raised.
If there is an internal error while parsing, :exc:`.ParserError` will
be raised.
"""
tokens = self._tokenizer.tokenize(text, context, skip_style_tags)
code = self._builder.build(tokens)
Expand Down
Loading

0 comments on commit 87e0079

Please sign in to comment.