summaryrefslogtreecommitdiff
path: root/repoze/bfg/view.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2010-07-02 01:47:47 +0000
committerChris McDonough <chrism@agendaless.com>2010-07-02 01:47:47 +0000
commitb29429e470c093573f3735b0dbf09d42c29cfe4d (patch)
tree8dfa266de6bd0f10a80d9654fe3ddf3a7897c467 /repoze/bfg/view.py
parent78a659d76e5bbb7544212174f010c1f50f8bcbe6 (diff)
downloadpyramid-b29429e470c093573f3735b0dbf09d42c29cfe4d.tar.gz
pyramid-b29429e470c093573f3735b0dbf09d42c29cfe4d.tar.bz2
pyramid-b29429e470c093573f3735b0dbf09d42c29cfe4d.zip
- The ``repoze.bfg.url.route_url`` API has changed. If a keyword
``_app_url`` is present in the arguments passed to ``route_url``, this value will be used as the protocol/hostname/port/leading path prefix of the generated URL. For example, using an ``_app_url`` of ``http://example.com:8080/foo`` would cause the URL ``http://example.com:8080/foo/fleeb/flub`` to be returned from this function if the expansion of the route pattern associated with the ``route_name`` expanded to ``/fleeb/flub``. - It is now possible to use a URL as the ``name`` argument fed to ``repoze.bfg.configuration.Configurator.add_static_view``. When the name argument is a URL, the ``repoze.bfg.url.static_url`` API will generate join this URL (as a prefix) to a path including the static file name. This makes it more possible to put static media on a separate webserver for production, while keeping static media package-internal and served by the development webserver during development.
Diffstat (limited to 'repoze/bfg/view.py')
-rw-r--r--repoze/bfg/view.py69
1 files changed, 3 insertions, 66 deletions
diff --git a/repoze/bfg/view.py b/repoze/bfg/view.py
index 1ab966be2..7a853eb28 100644
--- a/repoze/bfg/view.py
+++ b/repoze/bfg/view.py
@@ -17,8 +17,6 @@ from webob.exc import HTTPFound
import venusian
-from paste.urlparser import StaticURLParser
-
from zope.deprecation import deprecated
from zope.interface import providedBy
@@ -27,11 +25,9 @@ from repoze.bfg.interfaces import IRoutesMapper
from repoze.bfg.interfaces import IView
from repoze.bfg.interfaces import IViewClassifier
-from repoze.bfg.path import caller_package
from repoze.bfg.path import package_path
-from repoze.bfg.resource import resolve_resource_spec
from repoze.bfg.resource import resource_spec_from_abspath
-from repoze.bfg.static import PackageURLParser
+from repoze.bfg.static import static_view as static # B/C
from repoze.bfg.threadlocal import get_current_registry
# b/c imports
@@ -51,6 +47,8 @@ deprecated('NotFound',
"repoze.bfg.exceptions import NotFound')",
)
+static = static # dont yet deprecate this (ever?)
+
_marker = object()
def render_view_to_response(context, request, name='', secure=True):
@@ -166,67 +164,6 @@ def is_response(ob):
return True
return False
-class static(object):
- """ An instance of this class is a callable which can act as a
- :mod:`repoze.bfg` :term:`view callable`; this view will serve
- static files from a directory on disk based on the ``root_dir``
- you provide to its constructor.
-
- The directory may contain subdirectories (recursively); the static
- view implementation will descend into these directories as
- necessary based on the components of the URL in order to resolve a
- path into a response.
-
- You may pass an absolute or relative filesystem path or a
- :term:`resource specification` representing the directory
- containing static files as the ``root_dir`` argument to this
- class' constructor.
-
- If the ``root_dir`` path is relative, and the ``package_name``
- argument is ``None``, ``root_dir`` will be considered relative to
- the directory in which the Python file which *calls* ``static``
- resides. If the ``package_name`` name argument is provided, and a
- relative ``root_dir`` is provided, the ``root_dir`` will be
- considered relative to the Python :term:`package` specified by
- ``package_name`` (a dotted path to a Python package).
-
- ``cache_max_age`` influences the ``Expires`` and ``Max-Age``
- response headers returned by the view (default is 3600 seconds or
- five minutes).
-
- .. note:: If the ``root_dir`` is relative to a :term:`package`, or
- is a :term:`resource specification` the :mod:`repoze.bfg`
- ``resource`` ZCML directive or
- :class:`repoze.bfg.configuration.Configurator` method can be
- used to override resources within the named ``root_dir``
- package-relative directory. However, if the ``root_dir`` is
- absolute, the ``resource`` directive will not be able to
- override the resources it contains. """
-
- def __init__(self, root_dir, cache_max_age=3600, package_name=None):
- # package_name is for bw compat; it is preferred to pass in a
- # package-relative path as root_dir
- # (e.g. ``anotherpackage:foo/static``).
- caller_package_name = caller_package().__name__
- package_name = package_name or caller_package_name
- package_name, root_dir = resolve_resource_spec(root_dir, package_name)
- if package_name is None:
- app = StaticURLParser(root_dir, cache_max_age=cache_max_age)
- else:
- app = PackageURLParser(
- package_name, root_dir, cache_max_age=cache_max_age)
- self.app = app
-
- def __call__(self, context, request):
- subpath = '/'.join(request.subpath)
- request_copy = request.copy()
- # Fix up PATH_INFO to get rid of everything but the "subpath"
- # (the actual path to the file relative to the root dir).
- request_copy.environ['PATH_INFO'] = '/' + subpath
- # Zero out SCRIPT_NAME for good measure.
- request_copy.environ['SCRIPT_NAME'] = ''
- return request_copy.get_response(self.app)
-
class bfg_view(object):
""" A function, class or method :term:`decorator` which allows a
developer to create view registrations nearer to a :term:`view