Exemple #1
0
    def render(self, jinja_env=None):
        """Read the static file."""
        timer = self.pod.profile.timer('RenderStaticDocumentController.render',
                                       label=self.serving_path,
                                       meta={
                                           'path': self.serving_path
                                       }).start_timer()
        pod_path = None
        if 'pod_path' in self.route_info.meta:
            pod_path = self.route_info.meta['pod_path']
        else:
            pod_path = self.serving_path[len(self.route_info.
                                             meta['path_format']):]
            pod_path = os.path.join(self.route_info.meta['source_format'],
                                    pod_path)

        if not self.pod.file_exists(pod_path):
            text = '{} was not found in static files.'
            raise errors.RouteNotFoundError(text.format(self.serving_path))

        # Validate the path with the static config specific filter.
        self.validate_path(self.route_info.meta['path_filter'])

        rendered_content = self.pod.read_file(pod_path)
        rendered_content = self.pod.extensions_controller.trigger(
            'post_render', self.static_doc, rendered_content)
        rendered_doc = rendered_document.RenderedDocument(
            self.serving_path, rendered_content)
        timer.stop_timer()
        return rendered_doc
Exemple #2
0
 def validate_path(self, *path_filters):
     """Validate that the path is valid against all filters."""
     # Default test against the pod filter for deployment specific filtering.
     path_filters = list(path_filters) or [self.pod.path_filter]
     for path_filter in path_filters:
         if not path_filter.is_valid(self.serving_path):
             text = '{} is an ignored path.'
             raise errors.RouteNotFoundError(text.format(self.serving_path))
Exemple #3
0
    def dispatch_request(self, request):
        path = url_parse.unquote(request.path)  # Support escaped paths.
        matched = self.routes.match(path)

        if not matched:
            text = '{} was not found in routes.'
            raise errors.RouteNotFoundError(text.format(path))

        kind = matched.value.kind
        if kind == 'console':
            if 'handler' in matched.value.meta:
                handler_meta = None
                if 'meta' in matched.value.meta:
                    handler_meta = matched.value.meta['meta']
                return matched.value.meta['handler'](self.pod,
                                                     request,
                                                     matched,
                                                     meta=handler_meta)
            return handlers.serve_console(self.pod, request, matched)
        return handlers.serve_pod(self.pod, request, matched)
Exemple #4
0
    def render(self, jinja_env=None):
        """Read the static file."""
        timer = self.pod.profile.timer(
            'RenderStaticDocumentController.render', label=self.serving_path,
            meta={'path': self.serving_path}).start_timer()
        pod_path = None
        if 'pod_path' in self.route_info.meta:
            pod_path = self.route_info.meta['pod_path']
        else:
            pod_path = self.serving_path[
                len(self.route_info.meta['path_format']):]
            pod_path = os.path.join(
                self.route_info.meta['source_format'], pod_path)

        if not self.pod.file_exists(pod_path):
            text = '{} was not found in static files.'
            raise errors.RouteNotFoundError(text.format(self.serving_path))

        rendered_doc = rendered_document.RenderedDocument(
            self.serving_path, self.pod.read_file(pod_path))
        # rendered_doc.render_timer = timer.stop_timer()
        timer.stop_timer()
        return rendered_doc