[Checkins] SVN: z3c.rml/trunk/ - Implemented the ``ABORT_ON_INVALID_DIRECTIVE`` flag, that when set ``True``
Stephen Richter
cvs-admin at zope.org
Wed Dec 19 02:00:31 UTC 2012
Log message for revision 128767:
- Implemented the ``ABORT_ON_INVALID_DIRECTIVE`` flag, that when set ``True``
will raise a ``ValueError`` error on the first occurence of a bad tag.
- Bug: Due to a logic error, bad directives were never properly detected and
logged about.
Changed:
U z3c.rml/trunk/CHANGES.txt
U z3c.rml/trunk/src/z3c/rml/directive.py
A z3c.rml/trunk/src/z3c/rml/tests/test_directive.py
-=-
Modified: z3c.rml/trunk/CHANGES.txt
===================================================================
--- z3c.rml/trunk/CHANGES.txt 2012-12-19 01:37:16 UTC (rev 128766)
+++ z3c.rml/trunk/CHANGES.txt 2012-12-19 02:00:30 UTC (rev 128767)
@@ -11,7 +11,12 @@
- Create a list of RML2PDF and z3c.rml differences.
+- Implemented the ``ABORT_ON_INVALID_DIRECTIVE`` flag, that when set ``True``
+ will raise a ``ValueError`` error on the first occurence of a bad tag.
+- Bug: Due to a logic error, bad directives were never properly detected and
+ logged about.
+
1.1.0 (2012-12-18)
------------------
Modified: z3c.rml/trunk/src/z3c/rml/directive.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/directive.py 2012-12-19 01:37:16 UTC (rev 128766)
+++ z3c.rml/trunk/src/z3c/rml/directive.py 2012-12-19 02:00:30 UTC (rev 128767)
@@ -26,6 +26,7 @@
logging.raiseExceptions = False
logger = logging.getLogger("z3c.rml")
+ABORT_ON_INVALID_DIRECTIVE = False
def DeprecatedDirective(iface, reason):
zope.interface.directlyProvides(iface, interfaces.IDeprecatedDirective)
@@ -92,18 +93,21 @@
# Ignore all comments
if isinstance(element, etree._Comment):
continue
+ # Raise an error/log any unknown directive.
+ if element.tag not in self.factories:
+ msg = "Directive %r could not be processed and was " \
+ "ignored. %s" %(element.tag, getFileInfo(self))
+ # Record any tags/elements that could not be processed.
+ logger.warn(msg)
+ if ABORT_ON_INVALID_DIRECTIVE:
+ raise ValueError(msg)
+ continue
if select is not None and element.tag not in select:
continue
if ignore is not None and element.tag in ignore:
continue
- # If the element is a directive, process it
- if element.tag in self.factories:
- directive = self.factories[element.tag](element, self)
- directive.process()
- else:
- # Record any tags/elements that could not be processed.
- logger.warn("Directive %r could not be processed and was "
- "ignored. %s" %(element.tag, getFileInfo(self)))
+ directive = self.factories[element.tag](element, self)
+ directive.process()
def process(self):
self.processSubDirectives()
Added: z3c.rml/trunk/src/z3c/rml/tests/test_directive.py
===================================================================
--- z3c.rml/trunk/src/z3c/rml/tests/test_directive.py (rev 0)
+++ z3c.rml/trunk/src/z3c/rml/tests/test_directive.py 2012-12-19 02:00:30 UTC (rev 128767)
@@ -0,0 +1,52 @@
+###############################################################################
+#
+# Copyright (c) 2012 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+###############################################################################
+"""Tests for the Book Documentation Module"""
+
+import doctest
+import unittest
+
+bad_rml = '''\
+<document filename="bad.pdf">
+ <bad />
+</document>
+'''
+
+def test_abort_on_invalid_tag():
+ """
+
+ We can set a flag that aborts execution when a bad tag/directive is
+ encountered:
+
+ >>> from z3c.rml import directive
+ >>> directive.ABORT_ON_INVALID_DIRECTIVE = True
+
+ Let's now render a template:
+
+ >>> from z3c.rml import rml2pdf
+ >>> rml2pdf.parseString(bad_rml, True, 'bad.rml')
+ Traceback (most recent call last):
+ ...
+ ValueError: Directive 'bad' could not be processed and was ignored.
+ (file bad.rml, line 1)
+
+ Cleanup:
+
+ >>> directive.ABORT_ON_INVALID_DIRECTIVE = False
+
+ """
+
+def test_suite():
+ return doctest.DocTestSuite(
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
+
Property changes on: z3c.rml/trunk/src/z3c/rml/tests/test_directive.py
___________________________________________________________________
Added: svn:keywords
+ Id
More information about the checkins
mailing list