[z3-checkins] r33282 - in z3/deliverance/branches/packaged: . Deliverance.egg-info deliverance deliverance/test-data/nycsr doc
ianb at codespeak.net
ianb at codespeak.net
Sat Oct 14 03:21:49 CEST 2006
Author: ianb
Date: Sat Oct 14 03:21:39 2006
New Revision: 33282
Added:
z3/deliverance/branches/packaged/Deliverance.egg-info/ (props changed)
Modified:
z3/deliverance/branches/packaged/deliverance/interpreter.py
z3/deliverance/branches/packaged/deliverance/test-data/nycsr/nycsr.xml
z3/deliverance/branches/packaged/deliverance/test-data/nycsr/standardrules.xml
z3/deliverance/branches/packaged/deliverance/wsgifilter.py
z3/deliverance/branches/packaged/deliverance/xinclude.py
z3/deliverance/branches/packaged/doc/NewWorld.txt
z3/deliverance/branches/packaged/setup.py
Log:
Added a new attribute, nocontent='ignore' to rules to suppress error when there's no matching element in the content. Often this is not an error, such as when there's no <style> elements in the head.
Pass through the original URI to the xinclude code, so it can resolve references relative to that URI; as it was everything was relative to the root.
Change the standardrules.xml in the nycsr test to use nocontent='ignore'. Change nycsr.xml to use * instead of table for the content element, to more easily support non-Plone sites (like TaskTracker)
Add an entry point to setup.py and the wsgifilter, so that you can configure deliverance from a Paste configuration file.
Modified: z3/deliverance/branches/packaged/deliverance/interpreter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/interpreter.py (original)
+++ z3/deliverance/branches/packaged/deliverance/interpreter.py Sat Oct 14 03:21:39 2006
@@ -12,14 +12,17 @@
render time.
"""
- def __init__(self, theme, theme_uri, rules, reference_resolver=None):
+ def __init__(self, theme, theme_uri,
+ rule, rule_uri,
+ reference_resolver=None):
self.theme = self.fixup_links(theme, theme_uri)
- self.rules = rules
+ self.rules = rule
+ self.rules_uri = rule_uri
# perform xincludes on the rules
if reference_resolver:
- xinclude.include(self.rules, loader=reference_resolver)
+ xinclude.include(self.rules, self.rules_uri, loader=reference_resolver)
- debug = rules.get("debug", None)
+ debug = self.rules.get("debug", None)
if debug and debug.lower() == "true":
self.debug = True
else:
@@ -66,7 +69,8 @@
content_els = copy.deepcopy(content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
if len(content_els) == 0:
- self.add_to_body_start(theme, self.format_error("no content matched", rule))
+ if rule.get(self.NOCONTENT_KEY) != 'ignore':
+ self.add_to_body_start(theme, self.format_error("no content matched", rule))
return
if self.debug:
@@ -119,7 +123,8 @@
content_els = copy.deepcopy(content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
if len(content_els) == 0:
- self.add_to_body_start(theme, self.format_error("no content matched", rule))
+ if rule.attrib.get(self.NOCONTENT_KEY) != 'ignore':
+ self.add_to_body_start(theme, self.format_error("no content matched", rule))
return
if self.debug:
@@ -184,7 +189,8 @@
content_els = copy.deepcopy(content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
if len(content_els) == 0:
- self.add_to_body_start(theme, self.format_error("no content matched", rule))
+ if rule.attrib.get(self.NOCONTENT_KEY) == 'ignore':
+ self.add_to_body_start(theme, self.format_error("no content matched", rule))
return
if self.debug:
@@ -258,7 +264,8 @@
content_els = copy.deepcopy(content.xpath(rule.attrib[self.RULE_CONTENT_KEY]))
if len(content_els) == 0:
- self.add_to_body_start(theme, self.format_error("no content matched", rule))
+ if rule.attrib.get(self.NOCONTENT_KEY) != 'ignore':
+ self.add_to_body_start(theme, self.format_error("no content matched", rule))
return
non_text_els = self.elements_in(content_els)
@@ -299,7 +306,8 @@
content_els = copy.deepcopy(content.xpath(content_xpath))
if len(content_els) == 0:
- self.add_to_body_start(theme, self.format_error("no content matched", rule))
+ if rule.attrib.get(self.NOCONTENT_KEY) != 'ignore':
+ self.add_to_body_start(theme, self.format_error("no content matched", rule))
return
for el in theme_el:
Modified: z3/deliverance/branches/packaged/deliverance/test-data/nycsr/nycsr.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/nycsr/nycsr.xml (original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/nycsr/nycsr.xml Sat Oct 14 03:21:39 2006
@@ -3,5 +3,5 @@
<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance" >
<xi:include href="standardrules.xml" />
- <copy theme="//div[@id='container']" content="//table[@id='portal-columns']" />
+ <copy theme="//div[@id='container']" content="//*[@id='portal-columns']" />
</rules>
Modified: z3/deliverance/branches/packaged/deliverance/test-data/nycsr/standardrules.xml
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/test-data/nycsr/standardrules.xml (original)
+++ z3/deliverance/branches/packaged/deliverance/test-data/nycsr/standardrules.xml Sat Oct 14 03:21:39 2006
@@ -2,9 +2,10 @@
<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance">
- <prepend theme="//head" content="//head/link" />
- <prepend theme="//head" content="//head/style" />
- <append theme="//head" content="//head/script" />
- <append theme="//head" content="//head/meta" />
- <append-or-replace theme="//head" content="//head/title" />
+ <prepend theme="//head" content="//head/link" nocontent="ignore" />
+ <prepend theme="//head" content="//head/style" nocontent="ignore" />
+ <append theme="//head" content="//head/script" nocontent="ignore" />
+ <append theme="//head" content="//head/meta" nocontent="ignore" />
+ <append-or-replace theme="//head" content="//head/title"
+ nocontent="ignore" />
</rules>
Modified: z3/deliverance/branches/packaged/deliverance/wsgifilter.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/wsgifilter.py (original)
+++ z3/deliverance/branches/packaged/deliverance/wsgifilter.py Sat Oct 14 03:21:39 2006
@@ -20,7 +20,7 @@
import datetime
import threading
-DELIVERANCE_BASE_URL = 'deliverance-base-url'
+DELIVERANCE_BASE_URL = 'deliverance.base-url'
class DeliveranceMiddleware(object):
@@ -58,8 +58,12 @@
elif encoding:
return text.decode(encoding)
- return Renderer(parseHTML(theme), full_theme_uri, etree.XML(rule),
- reference_resolver=reference_resolver)
+ return Renderer(
+ theme=parseHTML(theme),
+ theme_uri=full_theme_uri,
+ rule=etree.XML(rule),
+ rule_uri=self.rule_uri,
+ reference_resolver=reference_resolver)
def cache_expired(self):
@@ -96,6 +100,8 @@
def should_intercept(self, status, headers):
type = header_value(headers, 'content-type')
+ if type is None:
+ return False
return type.startswith('text/html') or type.startswith('application/xhtml+xml')
def filter_body(self, environ, body):
@@ -104,10 +110,9 @@
def get_resource(self, environ, uri):
internalBaseURL = environ.get(DELIVERANCE_BASE_URL,None)
+ uri = urlparse.urljoin(internalBaseURL, uri)
- if self.relative_uri(uri):
- return self.get_internal_resource(environ, uri)
- elif internalBaseURL and uri.startswith(internalBaseURL):
+ if internalBaseURL and uri.startswith(internalBaseURL):
return self.get_internal_resource(environ, uri[len(internalBaseURL):])
else:
return self.get_external_resource(uri)
@@ -129,5 +134,32 @@
if not uri.startswith('/'):
uri = '/' + uri
environ['PATH_INFO'] = uri
+ environ['SCRIPT_NAME'] = environ[DELIVERANCE_BASE_URL]
+ if environ['QUERY_STRING']:
+ environ['QUERY_STRING'] += '¬heme'
+ else:
+ environ['QUERY_STRING'] = 'notheme'
+
+ path_info = environ['PATH_INFO']
status, headers, body = intercept_output(environ, self.app)
+ if not status.startswith('200'):
+ loc = header_value(headers, 'location')
+ if loc:
+ loc = ' location=%r' % loc
+ else:
+ loc = ''
+ raise Exception(
+ "Request for internal resource at %s (%r) failed with status code %r%s"
+ % (construct_url(environ), path_info, status,
+ loc))
return body
+
+def make_filter(app, global_conf,
+ theme_uri=None, rule_uri=None):
+ assert theme_uri is not None, (
+ "You must give a theme_uri")
+ assert rule_uri is not None, (
+ "You must give a rule_uri")
+ return DeliveranceMiddleware(
+ app, theme_uri, rule_uri)
+
Modified: z3/deliverance/branches/packaged/deliverance/xinclude.py
==============================================================================
--- z3/deliverance/branches/packaged/deliverance/xinclude.py (original)
+++ z3/deliverance/branches/packaged/deliverance/xinclude.py Sat Oct 14 03:21:39 2006
@@ -45,6 +45,7 @@
import copy
from lxml import etree
+import urlparse
XINCLUDE = "{http://www.w3.org/2001/XInclude}"
@@ -97,7 +98,7 @@
# xinclude) for use in Deliverance
-def include(elem, loader=None):
+def include(elem, base_href, loader=None):
if loader is None:
loader = default_loader
# look for xinclude elements
@@ -109,6 +110,7 @@
href = e.get("href")
parse = e.get("parse", "xml")
if parse == "xml":
+ href = urlparse.urljoin(base_href, href)
node = loader(href, parse)
if node is None:
raise FatalIncludeError(
Modified: z3/deliverance/branches/packaged/doc/NewWorld.txt
==============================================================================
--- z3/deliverance/branches/packaged/doc/NewWorld.txt (original)
+++ z3/deliverance/branches/packaged/doc/NewWorld.txt Sat Oct 14 03:21:39 2006
@@ -207,8 +207,8 @@
7. Tedious instructions.
In CMF/Plone templates, every `link`, `script`, `a`, `img`, etc. As
-such, each of these gets a `tal:attributes="src:
-{portal_url}/foo.png"` added to it, even though the image src was
+such, each of these gets a `tal:attributes="src
+${portal_url}/foo.png"` added to it, even though the image src was
stated on the actual src attribute.
What happens? First, nobody even bothers putting an actual src
Modified: z3/deliverance/branches/packaged/setup.py
==============================================================================
--- z3/deliverance/branches/packaged/setup.py (original)
+++ z3/deliverance/branches/packaged/setup.py Sat Oct 14 03:21:39 2006
@@ -21,6 +21,8 @@
'lxml',
],
entry_points="""
+ [paste.filter_app_factory]
+ main = deliverance.wsgifilter:make_filter
""",
)
More information about the z3-checkins
mailing list