From 89968dce0273f49cf34e07480077f7843593f54e Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 4 Feb 2010 18:32:36 +0000 Subject: - Fix a bug whereby a ``renderer`` argument to the ``@bfg_view`` decorator that provided a package-relative template filename might not have been resolved properly. Symptom: inappropriate ``Missing template resource`` errors. --- repoze/bfg/resource.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'repoze/bfg/resource.py') diff --git a/repoze/bfg/resource.py b/repoze/bfg/resource.py index 25e6af4f7..ff10273e4 100644 --- a/repoze/bfg/resource.py +++ b/repoze/bfg/resource.py @@ -5,6 +5,7 @@ from zope.interface import implements from repoze.bfg.interfaces import IPackageOverrides +from repoze.bfg.path import package_path from repoze.bfg.threadlocal import get_current_registry class OverrideProvider(pkg_resources.DefaultProvider): @@ -180,3 +181,18 @@ def resolve_resource_spec(spec, package_name='__main__'): elif package_name is None: package_name, filename = None, spec return package_name, filename + +def resource_spec_from_abspath(abspath, package): + """ Try to convert an absolute path to a resource in a package to + a resource specification if possible; otherwise return the + absolute path. """ + if getattr(package, '__name__', None) == '__main__': + return abspath + pp = package_path(package) + os.path.sep + if abspath.startswith(pp): + relpath = abspath[len(pp):] + return '%s:%s' % (package.__name__, + relpath.replace(os.path.sep, '/')) + return abspath + + -- cgit v1.2.3