[Checkins] SVN: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/ Polish publisher stepping through path segments. Rename hash_signature to publisher_signature.
Jan-Jaap Driessen
jdriessen at thehealthagency.com
Fri Nov 19 09:50:37 EST 2010
Log message for revision 118496:
Polish publisher stepping through path segments. Rename hash_signature to publisher_signature.
Changed:
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/__init__.py
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py
U hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/publisher.py
-=-
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt 2010-11-19 14:38:41 UTC (rev 118495)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/README.txt 2010-11-19 14:50:37 UTC (rev 118496)
@@ -1283,20 +1283,18 @@
The resources are handled by paste.fileapp.DirectoryApp, which sets the
ETag header, among other things::
- <<< res = app.get('/foo/style.css')
- <<< print res.body
+ >>> res = app.get('/:hash:12345/foo/style.css')
+ >>> print res.body
body {
color: #f00;
}
- <<< headers = dict(res.headers)
- <<< 'ETag' in headers
+ >>> headers = dict(res.headers)
+ >>> 'ETag' in headers
True
When we find the 'hash' marker in the requested URL, we send headers that let
the user agent cache the resources for a long time.
- >>> res = app.get('/:hash:12345/foo/style.css')
- >>> headers = dict(res.headers)
>>> 'Expires' in headers
True
>>> print headers['Cache-Control']
@@ -1313,6 +1311,16 @@
Hidden files and directories are not served:
- >>> res = app.get('/foo/sub/.svn/test', expect_errors=True)
+ >>> res = app.get('/:hash:foo/sub/.svn/test', expect_errors=True)
>>> print res.status
404
+
+The publisher_signature can be found arbitrarily deep in the path_info:
+
+ >>> res = app.get('/++skin++foo/++etc++bar/foo/:hash:12345/foo/style.css')
+ >>> res.status
+ 200
+ >>> print res.body
+ body {
+ color: #f00;
+ }
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/__init__.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/__init__.py 2010-11-19 14:38:41 UTC (rev 118495)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/__init__.py 2010-11-19 14:50:37 UTC (rev 118496)
@@ -21,7 +21,7 @@
global hashing
hashing = enable
-hash_signature = 'hash'
+publisher_signature = ':hash:'
devmode = False
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py 2010-11-19 14:38:41 UTC (rev 118495)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/core.py 2010-11-19 14:50:37 UTC (rev 118496)
@@ -434,9 +434,9 @@
hash_cache = {}
if base_url and not base_url.endswith('/'):
base_url += '/'
-
- signature = ''
+
for inclusion in inclusions:
+ signature = ''
library = inclusion.library
if hurry.resource.hashing:
# For every request, compute the hash of each library
@@ -446,7 +446,7 @@
if hash is None:
hash = library.hash()
hash_cache[library.name] = hash
- signature = ':%s:%s/' % (hurry.resource.hash_signature, hash)
+ signature = '%s%s/' % (hurry.resource.publisher_signature, hash)
library_url = base_url + signature + inclusion.library.name + '/'
result.append(render_inclusion(
inclusion, library_url + inclusion.relpath))
Modified: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/publisher.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/publisher.py 2010-11-19 14:38:41 UTC (rev 118495)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/publisher.py 2010-11-19 14:50:37 UTC (rev 118496)
@@ -1,3 +1,5 @@
+from itertools import dropwhile
+
import webob
from paste.request import path_info_pop, path_info_split
from paste.fileapp import DirectoryApp, CACHE_CONTROL, EXPIRES
@@ -16,7 +18,7 @@
class Publisher(object):
- def __init__(self, app, **local_conf):
+ def __init__(self, app):
self._wrapped_app = app
self.directory_apps = {}
for library in hurry.resource.libraries():
@@ -24,25 +26,26 @@
self.directory_apps[library.name] = app
def __call__(self, environ, start_response):
- path = environ['PATH_INFO']
- if hurry.resource.hash_signature not in path:
+ path_info = environ['PATH_INFO']
+
+ path_segments = [s for s in path_info.split('/') if s.strip() != '']
+
+ def hash_find(segment):
+ return not segment.startswith(hurry.resource.publisher_signature)
+
+ new_path = list(dropwhile(hash_find, path_segments))
+
+ if len(new_path) == 0:
# There's no hash signature found in the path, so we
# cannot publish it from here. Leave the response to the
# wrapped app.
- request = webob.Request(environ)
- response = request.get_response(self._wrapped_app)
- return response(environ, start_response)
+ return self._wrapped_app(environ, start_response)
- library_name = ''
- next_ = path_info_pop(environ)
- while next_:
- if next_.startswith(':%s:' % hurry.resource.hash_signature):
- # Skip over hash signature segment. The library name
- # will be that of the next step.
- library_name = path_info_pop(environ)
- break
- next_ = path_info_pop(environ)
- print 'STEPPIE', library_name, path, environ['PATH_INFO']
+ try:
+ hash = new_path.pop(0)
+ library_name = new_path.pop(0)
+ except IndexError:
+ return HTTPNotFound()(environ, start_response)
try:
directory_app = self.directory_apps[library_name]
@@ -57,8 +60,9 @@
EXPIRES.update(headers, delta=expires)
return start_response(status, headers, exc_info)
- response = cache_header_start_response
- return directory_app(environ, response)
+ # Reconstruct information for the directory_app to work with.
+ environ['PATH_INFO'] = '/' + '/'.join(new_path)
+ return directory_app(environ, cache_header_start_response)
-def make_publisher(app, global_conf, **local_conf):
+def make_publisher(app, global_conf):
return Publisher(app, **local_conf)
More information about the checkins
mailing list