[Checkins] SVN: Sandbox/malthe/chameleon.html/ Resource URLs are now made absolute.
Malthe Borch
mborch at gmail.com
Thu Oct 30 09:16:05 EDT 2008
Log message for revision 92697:
Resource URLs are now made absolute.
Changed:
U Sandbox/malthe/chameleon.html/CHANGES.txt
U Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
-=-
Modified: Sandbox/malthe/chameleon.html/CHANGES.txt
===================================================================
--- Sandbox/malthe/chameleon.html/CHANGES.txt 2008-10-30 13:05:38 UTC (rev 92696)
+++ Sandbox/malthe/chameleon.html/CHANGES.txt 2008-10-30 13:16:04 UTC (rev 92697)
@@ -4,6 +4,9 @@
Head
~~~~
+- Resource URLs are now made absolute to dettach them from the
+ template object. [malthe]
+
- Changed test setup to allow for python based tests, i.e. not
using the zope test runner. [seletz]
Modified: Sandbox/malthe/chameleon.html/src/chameleon/html/language.py
===================================================================
--- Sandbox/malthe/chameleon.html/src/chameleon/html/language.py 2008-10-30 13:05:38 UTC (rev 92696)
+++ Sandbox/malthe/chameleon.html/src/chameleon/html/language.py 2008-10-30 13:16:04 UTC (rev 92697)
@@ -47,6 +47,11 @@
def rebase(context, request, path):
return component.getMultiAdapter(
(context, request, path), IResourceLocation)
+
+def ensure_absolute(path, relative_path):
+ if not os.path.isabs(relative_path):
+ return os.path.join(path, relative_path)
+ return relative_path
class Element(translation.Element):
"""The XSS template language base element."""
@@ -200,6 +205,7 @@
# process dynamic rules
links = root.xpath(
'.//xmlns:link[@rel="xss"]', namespaces={'xmlns': config.XHTML_NS})
+
for link in links:
try:
href = link.attrib['href']
@@ -267,9 +273,11 @@
for element in elements:
href = element.attrib.get('href')
if href is not None:
+ element.attrib['href'] = ensure_absolute(self.path, href)
element.attrib['{http://namespaces.repoze.org/xss}rebase'] = 'href'
src = element.attrib.get('src')
if src is not None:
+ element.attrib['src'] = ensure_absolute(self.path, src)
element.attrib['{http://namespaces.repoze.org/xss}rebase'] = 'src'
elements = root.xpath(
'.//xmlns:style', namespaces={'xmlns': config.XHTML_NS})
More information about the Checkins
mailing list