def search_for_source(self, item): try: item = AssetResolver(None).resolve(item).abspath() except ImportError as e: raise BundleError(e) except ValueError as e: return super(PyramidResolver, self).search_for_source(item) return item
def _resolve_spec(self, spec): package, subpath = self._split_spec(spec) try: pkgpath = self.resolver.resolve(package + ':').abspath() except ImportError as e: raise BundleError(e) else: return path.join(pkgpath, subpath)
def _split_asset_spec(self, item): if ':' in item: package, filepath = item.split(':', 1) try: package = self.resolver.resolve('%s:' % package).abspath() except ImportError as e: raise BundleError(e) return (package, filepath) else: return (None, item)
def resolve_output_to_url(self, item): try: request = get_current_request() url = request.static_url(self.search_for_source(item)) return url except ValueError as e: if ':' in item: e.message += '(%s)' % item raise BundleError(e) return self.resolve_source_to_url(None, item)
def resolve_output_to_url(self, item): if not path.isabs(item): item = path.join(self.env.directory, item) try: request = get_current_request() url = request.static_url(self.search_for_source(item)) return url except ValueError as e: if ':' in item: e.message += '(%s)' % item raise BundleError(e)
def search_for_source(self, item): try: item = self.resolver.resolve(item).abspath() except ImportError as e: raise BundleError(e) except ValueError as e: return super(PyramidResolver, self).search_for_source(item) # Take care of globs if glob.has_magic(item): return [ filename for filename in glob.iglob(item) if not path.isdir(item) ] else: return item
def resolve_output_to_url(self, item): if not path.isabs(item): item = path.join(self.env.directory, item) try: request = get_current_request() url = request.static_url(self.search_for_source(item)) return url except ValueError as e: if ':' in item: e.message += '(%s)' % item raise BundleError(e) except AttributeError as e: # pragma: no cover if e.message == "'NoneType' object has no attribute 'static_url'": # render() has been called outside of a request # e.g., to compile assets before handling requests # and so failure is acceptable pass else: raise
def absurl(self, fragment): query = None request = get_current_request() settings = request.registry.settings use_route_path = settings.get('webassets.use_route_path', True) if self.url_expire != False and '?' in fragment: fragment, query = fragment.rsplit('?', 1) if not ':' in fragment: # Get the path to the file if it's not an asset spec fragment = super(Environment, self).abspath(fragment) try: if use_route_path: fragment = request.static_path(fragment) else: fragment = request.static_url(fragment) return query and "%s?%s" % (fragment, query) or fragment except ValueError, e: raise BundleError(e)
def _normalize_source_path(self, spath): # spath might be an asset spec try: spath = AssetResolver(None).resolve(spath).abspath() except ImportError, e: raise BundleError(e)