[z3-checkins] r52892 - in z3/deliverance/trunk: deliverance examples examples/static_site examples/static_site/content examples/static_site/theme
ianb at codespeak.net
ianb at codespeak.net
Tue Mar 25 01:22:54 CET 2008
Author: ianb
Date: Tue Mar 25 01:22:54 2008
New Revision: 52892
Added:
z3/deliverance/trunk/examples/
z3/deliverance/trunk/examples/static_site/
z3/deliverance/trunk/examples/static_site/README.txt (contents, props changed)
z3/deliverance/trunk/examples/static_site/content/
z3/deliverance/trunk/examples/static_site/content/index.html (contents, props changed)
z3/deliverance/trunk/examples/static_site/example.ini
z3/deliverance/trunk/examples/static_site/theme/
z3/deliverance/trunk/examples/static_site/theme/rule.xml
- copied, changed from r52889, z3/deliverance/trunk/deliverance/test-data/necoro/necoro.xml
z3/deliverance/trunk/examples/static_site/theme/standardrules.xml
- copied unchanged from r52889, z3/deliverance/trunk/deliverance/test-data/necoro/standardrules.xml
z3/deliverance/trunk/examples/static_site/theme/style.css
z3/deliverance/trunk/examples/static_site/theme/theme.html (contents, props changed)
Modified:
z3/deliverance/trunk/deliverance/wsgimiddleware.py
Log:
Make file:/// urls work in DeliveranceMiddleware configuration. Also added an example
Modified: z3/deliverance/trunk/deliverance/wsgimiddleware.py
==============================================================================
--- z3/deliverance/trunk/deliverance/wsgimiddleware.py (original)
+++ z3/deliverance/trunk/deliverance/wsgimiddleware.py Tue Mar 25 01:22:54 2008
@@ -5,6 +5,7 @@
"""
import re
+import os
import urlparse
import urllib
from lxml import etree
@@ -557,10 +558,43 @@
):
""" Configure DeliveranceError via Paste config.
"""
+ """
+ Wraps an app in deliverance, using the given theme_uri and rule_uri.
+
+ The theme_uri and rule_uri may be ``file:///`` URLs, which will
+ cause this to mount the containing directory in
+ ``/.deliverance/theme`` and ``/.deliverance/rules``. Note that in
+ this case your theme *must not* refer to any files in a parent
+ directory; only sibling files (and files in subdirectories under
+ the theme directory) will be accessible.
+ """
+ statics = {}
+ if theme_uri.lower().startswith('file:'):
+ theme_path = filename_for_uri(theme_uri)
+ theme_dir = os.path.dirname(theme_path)
+ statics['/.deliverance/theme'] = theme_dir
+ theme_uri = '/.deliverance/theme/%s' % os.path.basename(theme_path)
+ if rule_uri.lower().startswith('file:'):
+ rule_path = filename_for_uri(rule_uri)
+ rule_dir = os.path.dirname(theme_path)
+ if statics.get('/.deliverance/theme') == rule_dir:
+ rule_uri = '/.deliverance/theme/%s' % os.path.basename(rule_path)
+ else:
+ statics['/.deliverance/rules'] = rule_dir
+ rule_uri = '/.deliverance/rules/%s' % os.path.basename(rule_path)
assert theme_uri is not None, (
"You must give a theme_uri")
assert rule_uri is not None, (
"You must give a rule_uri")
+ if statics:
+ from paste.urlmap import URLMap
+ from paste.urlparser import StaticURLParser
+ mapper = URLMap()
+ mapper[''] = app
+ for path, dir in statics.items():
+ path_app = StaticURLParser(dir)
+ mapper[path] = path_app
+ app = mapper
return DeliveranceMiddleware(app=app,
theme_uri=theme_uri,
rule_uri=rule_uri,
@@ -570,6 +604,36 @@
serializer=serializer,
)
+_windows_drive_re = re.compile(r'^[a-z][|]', re.I)
+
+def filename_for_uri(uri):
+ """
+ Returns the filename for a given file: uri.
+
+ Uses cwd when you give ``file://`` (exactly TWO slashes)
+
+ On Windows you can give a drive with ``file:///C|/path``
+ """
+ assert uri.lower().startswith('file:'), (
+ "Not a file:/ uri: %r" % uri)
+ uri = uri[5:]
+ # Just in case they give a Windows path:
+ uri = uri.replace('\\', '/')
+ relative = uri.startswith('//') and not uri.startswith('///')
+ filename = uri.lstrip('/')
+ filename = urllib.unquote(filename)
+ if sys.platform == 'win32':
+ match = _windows_drive_re.match(filename)
+ if match:
+ filename = filename[0] + ':' + filename[2:]
+ elif not relative:
+ filename = '/' + filename
+ elif not relative:
+ filename = '/' + filename
+ if relative:
+ filename = os.path.abspath(filename)
+ return os.path.normpath(os.path.normcase(filename))
+
_http_equiv_re = re.compile(r'<meta\s+[^>]*http-equiv="?content-type"?[^>]*>', re.I|re.S)
_head_re = re.compile(r'<head[^>]*>', re.I|re.S)
_html_re = re.compile(r'<html[^>]*>', re.I|re.S)
Added: z3/deliverance/trunk/examples/static_site/README.txt
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/examples/static_site/README.txt Tue Mar 25 01:22:54 2008
@@ -0,0 +1,13 @@
+This shows an example of serving a site with Deliverance and static files.
+
+Running the Example
+-------------------
+
+You must have PasteScript installed (easy_install PasteScript). Then do:
+
+ $ paster serve example.ini
+
+This will start a server up on http://localhost:5000
+
+The theme and rule files are in theme/. The static files that contain
+the content are in content/
Added: z3/deliverance/trunk/examples/static_site/content/index.html
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/examples/static_site/content/index.html Tue Mar 25 01:22:54 2008
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Some content</title>
+</head>
+
+<body>
+<div>
+This is some content
+</div>
+</body> </html>
Added: z3/deliverance/trunk/examples/static_site/example.ini
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/examples/static_site/example.ini Tue Mar 25 01:22:54 2008
@@ -0,0 +1,17 @@
+[pipeline:main]
+pipeline = deliverance static
+
+[app:static]
+use = egg:Paste#static
+document_root = %(here)s/content/
+
+[filter:deliverance]
+use = egg:Deliverance
+theme_uri = file:%(here)s/theme/theme.html
+rule_uri = file:%(here)s/theme/rule.xml
+
+[server:main]
+use = egg:Paste#http
+# Change to 0.0.0.0 to make this app public:
+host = 127.0.0.1
+port = 5000
Copied: z3/deliverance/trunk/examples/static_site/theme/rule.xml (from r52889, z3/deliverance/trunk/deliverance/test-data/necoro/necoro.xml)
==============================================================================
--- z3/deliverance/trunk/deliverance/test-data/necoro/necoro.xml (original)
+++ z3/deliverance/trunk/examples/static_site/theme/rule.xml Tue Mar 25 01:22:54 2008
@@ -3,5 +3,5 @@
<rules xmlns:xi="http://www.w3.org/2001/XInclude" xmlns="http://www.plone.org/deliverance" >
<xi:include href="standardrules.xml" />
- <replace theme="/html/body/table[1]/tr[2]/td" content="//div[@id='content']//table[@class='columns']//td[@class='main']" />
+ <replace theme="//div[@id='content']" content="//body/*" />
</rules>
Added: z3/deliverance/trunk/examples/static_site/theme/style.css
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/examples/static_site/theme/style.css Tue Mar 25 01:22:54 2008
@@ -0,0 +1,4 @@
+body {
+ font-family: sans-serif;
+}
+
Added: z3/deliverance/trunk/examples/static_site/theme/theme.html
==============================================================================
--- (empty file)
+++ z3/deliverance/trunk/examples/static_site/theme/theme.html Tue Mar 25 01:22:54 2008
@@ -0,0 +1,13 @@
+<html>
+<head>
+<link href="./style.css" type="text/css" rel="stylesheet">
+<title>This is a theme</title>
+</head>
+
+<body>
+
+<div id="content">
+ Put some content here
+</div>
+
+</body> </html>
More information about the z3-checkins
mailing list