[z3-checkins] r33675 - z3/deliverance/branches/packaged/deliverance
ianb at codespeak.net
ianb at codespeak.net
Tue Oct 24 19:25:13 CEST 2006
Author: ianb
Date: Tue Oct 24 19:25:11 2006
New Revision: 33675
Modified:
z3/deliverance/branches/packaged/deliverance/interpreter.py
z3/deliverance/branches/packaged/deliverance/utils.py
Log:
Style issue using len(); added new <drop> command for dropping elements from the theme or content. Note: no tests yet. Added better error message when xpath statements are bad (hasn't been applied everywhere it should be yet)
Modified: z3/deliverance/branches/packaged/deliverance/interpreter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/interpreter.py (original)
+++ z3/deliverance/branches/packaged/deliverance/interpreter.py Tue Oct 24 19:25:11 2006
@@ -52,6 +52,8 @@
self.apply_copy(rule, theme, content)
elif rule.tag == self.APPEND_OR_REPLACE_RULE_TAG:
self.apply_append_or_replace(rule, theme, content)
+ elif rule.tag == self.DROP_RULE_TAG:
+ self.apply_drop(rule, theme, content)
elif rule.tag == self.SUBRULES_TAG:
self.apply_rules(rule, theme, content)
elif rule.tag is etree.Comment:
@@ -261,14 +263,19 @@
i = parent.index(non_text_els[0])
parent[i+1:i+1] = non_text_els[1:]
+ def _xpath_copy(self, source, xpath):
+ try:
+ found_element = source.xpath(xpath)
+ except etree.XPathSyntaxError, e:
+ raise etree.XPathSyntaxError('%s (in expression %r)' % (e, xpath))
+ return copy.deepcopy(found_element)
def apply_copy(self, rule, theme, content):
theme_el = self.get_theme_el(rule,theme)
if theme_el is None:
return
- content_els = copy.deepcopy(
- content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
+ content_els = self._xpath_copy(content, rule.attrib[self.RULE_CONTENT_KEY])
if len(content_els) == 0:
if rule.attrib.get(self.NOCONTENT_KEY) != 'ignore':
@@ -334,6 +341,13 @@
theme_el.extend(content_els)
+ def apply_drop(self, rule, theme, content):
+ if 'theme' in rule.attrib:
+ for el in theme.xpath(rule.attrib['theme']):
+ el.getparent().remove(el)
+ if 'content' in rule.attrib:
+ for el in content.xpath(rule.attrib['content']):
+ el.getparent().remove(el)
def elements_in(self, els):
"""
Modified: z3/deliverance/branches/packaged/deliverance/utils.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/utils.py (original)
+++ z3/deliverance/branches/packaged/deliverance/utils.py Tue Oct 24 19:25:11 2006
@@ -59,6 +59,7 @@
COPY_RULE_TAG = "{http://www.plone.org/deliverance}copy"
APPEND_OR_REPLACE_RULE_TAG = "{http://www.plone.org/deliverance}append-or-replace"
SUBRULES_TAG = "{http://www.plone.org/deliverance}rules"
+ DROP_RULE_TAG = "{http://www.plone.org/deliverance}drop"
RULE_CONTENT_KEY = "content"
RULE_THEME_KEY = "theme"
@@ -154,7 +155,7 @@
"""
base_uri = uri
basetags = doc.xpath('//base[@href]')
- if (len(basetags)):
+ if basetags:
base_uri = basetags[0].attrib['href']
for b in basetags:
More information about the z3-checkins
mailing list