Example #1
0
    def test_canonical(self):
        h = xhtml.Renderer(request=Request({'PATH_INFO': ''}), response=self.h.response)
        self.assertEqual(top.wrap('text/html', h, h.root).write_xmlstring(), '<html><head/><body></body></html>')

        h = xhtml.Renderer(request=Request({'PATH_INFO': ''}), response=self.h.response)
        h.head << h.head.link(rel='canonical', href='/bar')
        self.assertEqual(top.wrap('text/html', h, h.root).write_xmlstring(), '<html><head><link href="/bar" rel="canonical"/></head><body></body></html>')

        h = xhtml.Renderer(request=Request({'PATH_INFO': '/foo'}), response=self.h.response)
        self.assertEqual(top.wrap('text/html', h, h.root).write_xmlstring(), '<html><head><link href="/foo" rel="canonical"/></head><body></body></html>')

        h = xhtml.Renderer(request=Request({'PATH_INFO': '/foo'}), response=self.h.response)
        h.head << h.head.link(rel='canonical', href='/bar')
        self.assertEqual(top.wrap('text/html', h, h.root).write_xmlstring(), '<html><head><link href="/bar" rel="canonical"/></head><body></body></html>')
Example #2
0
    def check_html(self, html):
        html2 = top.wrap("text/html", self.h, self.h.root)
        if not isinstance(html2, list):
            html2 = [html2]
        html2 = "".join(map(ET.tostring, html2))

        self.assertEqual(html2, html)
Example #3
0
    def check_html(self, html):
        html2 = top.wrap('text/html', self.h, self.h.root)
        if not isinstance(html2, list):
            html2 = [html2]
        html2 = ''.join(map(ET.tostring, html2))

        self.assertEqual(html2, html)
Example #4
0
    def test_canonical(self):
        h = xhtml.Renderer(request=Request({"PATH_INFO": ""}), response=self.h.response)
        self.assertEqual(top.wrap("text/html", h, h.root).write_xmlstring(), "<html><head/><body></body></html>")

        h = xhtml.Renderer(request=Request({"PATH_INFO": ""}), response=self.h.response)
        h.head << h.head.link(rel="canonical", href="/bar")
        self.assertEqual(
            top.wrap("text/html", h, h.root).write_xmlstring(),
            '<html><head><link href="/bar" rel="canonical"/></head><body></body></html>',
        )

        h = xhtml.Renderer(request=Request({"PATH_INFO": "/foo"}), response=self.h.response)
        self.assertEqual(
            top.wrap("text/html", h, h.root).write_xmlstring(),
            '<html><head><link href="/foo" rel="canonical"/></head><body></body></html>',
        )

        h = xhtml.Renderer(request=Request({"PATH_INFO": "/foo"}), response=self.h.response)
        h.head << h.head.link(rel="canonical", href="/bar")
        self.assertEqual(
            top.wrap("text/html", h, h.root).write_xmlstring(),
            '<html><head><link href="/bar" rel="canonical"/></head><body></body></html>',
        )
Example #5
0
                        use_same_state = True
                        response = self.on_after_post(request, response, session.sessionid_in_url(request, response))
                    else:
                        use_same_state = xhr_request

                        # Create a new renderer
                        renderer = self.create_renderer(xhr_request, session, request, response, callbacks)
                        # If the phase 1 has returned a render function, use it
                        # else, start the rendering by the application root component
                        output = render(renderer) if render else root.render(renderer)

                        if session.back_used:
                            output = self.on_back(request, response, renderer, output)

                        if not xhr_request:
                            output = top.wrap(renderer.content_type, renderer, output)

                        self._phase2(output, renderer.content_type, renderer.doctype, render is not None, response)

                        if not xhr_request:
                            # TODO: move it into a ``renderer.end_rendering()`` method
                            callbacks.clear_not_used(renderer._rendered)

                    # Store the session
                    session.set(use_same_state, (root, callbacks))

                    security.get_manager().end_rendering(request, response, session)
                except exc.HTTPException, response:
                    # When a ``webob.exc`` object is raised during phase 2, stop immediately
                    # use it as the response object
                    pass
Example #6
0
                        use_same_state = xhr_request

                        # Create a new renderer
                        renderer = self.create_renderer(
                            xhr_request, state, request, response)
                        # If the phase 1 has returned a render function, use it
                        # else, start the rendering by the application root component
                        output = render(renderer) if render else root.render(
                            renderer)

                        if state.back_used:
                            output = self.on_back(request, response, renderer,
                                                  output)

                        if not xhr_request:
                            output = top.wrap(renderer.content_type, renderer,
                                              output)

                        self._phase2(output, renderer.content_type,
                                     renderer.doctype, xhr_request, response)

                    # Store the state
                    state.set_root(use_same_state, root)

                    security.get_manager().end_rendering(
                        request, response, state)
                except exc.HTTPException, response:
                    # When a ``webob.exc`` object is raised during phase 2, stop immediately
                    # use it as the response object
                    pass
                except Exception:
                    self.last_exception = (request, sys.exc_info())