summaryrefslogtreecommitdiff
path: root/docutils/transforms
diff options
context:
space:
mode:
authorwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-06-27 14:21:27 +0000
committerwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2005-06-27 14:21:27 +0000
commit40f643d01a54d73857a7a6fadd64794d654fcde4 (patch)
tree6485cc14e184255c6874562edabc673ba6fa7d72 /docutils/transforms
parent133e6176272678623431d07c7187147ec8172150 (diff)
downloaddocutils-40f643d01a54d73857a7a6fadd64794d654fcde4.tar.gz
pass kwargs as single parameter to add_transform;
to not pass on the kwargs to Transform.__init__ but to Transform.apply git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@3604 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils/transforms')
-rw-r--r--docutils/transforms/__init__.py20
1 files changed, 8 insertions, 12 deletions
diff --git a/docutils/transforms/__init__.py b/docutils/transforms/__init__.py
index ef827fd50..45a32fb8c 100644
--- a/docutils/transforms/__init__.py
+++ b/docutils/transforms/__init__.py
@@ -43,7 +43,7 @@ class Transform:
default_priority = None
"""Numerical priority of this transform, 0 through 999 (override)."""
- def __init__(self, document, startnode=None, **kwargs):
+ def __init__(self, document, startnode=None):
"""
Initial setup for in-place document transforms.
"""
@@ -60,11 +60,7 @@ class Transform:
document.settings.language_code)
"""Language module local to this document."""
- self.data = kwargs
- """Data specific to this transform instance. You can use this
- to parameterize the transform instance."""
-
- def apply(self):
+ def apply(self, **kwargs):
"""Override to apply the transform to the document tree."""
raise NotImplementedError('subclass must override this method')
@@ -109,11 +105,12 @@ class Transformer(TransformSpec):
"""Internal serial number to keep track of the add order of
transforms."""
- def add_transform(self, transform_class, priority=None, **kwargs):
+ def add_transform(self, transform_class, priority=None, kwargs={}):
"""
Store a single transform. Use `priority` to override the default.
- `kwargs` are passed on to the constructor of the transform. This can
- be used to pass application-specific data to the transform instance.
+ `kwargs` is a dictionary whose contents are passed as keyword
+ arguments to the `apply` method of the transform. This can be used to
+ pass application-specific data to the transform instance.
"""
if priority is None:
priority = transform_class.default_priority
@@ -183,7 +180,6 @@ class Transformer(TransformSpec):
self.transforms.reverse()
self.sorted = 1
priority, transform_class, pending, kwargs = self.transforms.pop()
- transform = transform_class(self.document, startnode=pending,
- **kwargs)
- transform.apply()
+ transform = transform_class(self.document, startnode=pending)
+ transform.apply(**kwargs)
self.applied.append((transform, priority, transform_class, pending))