Exemplo n.º 1
0
    def test_text_do_not_change_after_a_clean_xhtml_and_line_break_xhtml_cycle(self):
        """Mimics the input -> clean -> display -> input... cycle of the
        XHTMLTextArea widget.
        """
        expected_html = '<p>first line<br>second line</p>'
        htmlified_text = clean_xhtml('first line\n\nsecond line')
        assert_equals(expected_html, htmlified_text)

        # Ensure that re-cleaning the XHTML provides the same result.
        display_text = line_break_xhtml(htmlified_text)
        assert_equals('<p>first line<br>second line</p>', display_text)
        assert_equals(expected_html, clean_xhtml(display_text))
    def test_text_do_not_change_after_a_clean_xhtml_and_line_break_xhtml_cycle(self):
        """Mimics the input -> clean -> display -> input... cycle of the
        XHTMLTextArea widget.
        """
        expected_html = '<p>first line<br>second line</p>'
        htmlified_text = clean_xhtml('first line\n\nsecond line')
        assert_equals(expected_html, htmlified_text)

        # Ensure that re-cleaning the XHTML provides the same result.
        display_text = line_break_xhtml(htmlified_text)
        assert_equals('<p>first line<br>second line</p>', display_text)
        assert_equals(expected_html, clean_xhtml(display_text))
 def test_adds_target_blank_to_links(self):
     original = '<a href="http://example.com">link</a>'
     from copy import deepcopy
     settings = deepcopy(cleaner_settings)
     settings['add_target_blank'] = True
     cleaned = clean_xhtml(original, _cleaner_settings=settings)
     assert_equals(cleaned, '<p><a href="http://example.com" rel="nofollow" target="_blank">link</a></p>')
 def test_makes_automatic_links_nofollow(self):
     original = 'http://example.com'
     cleaned = clean_xhtml(original)
     assert_equals(
         cleaned,
         '<p><a href="http://example.com" rel="nofollow">http://example.com</a></p>'
     )
Exemplo n.º 5
0
 def test_adds_target_blank_to_links(self):
     original = '<a href="http://example.com">link</a>'
     from copy import deepcopy
     settings = deepcopy(cleaner_settings)
     settings['add_target_blank'] = True
     cleaned = clean_xhtml(original, _cleaner_settings=settings)
     assert_equals(cleaned, '<p><a href="http://example.com" rel="nofollow" target="_blank">link</a></p>')
Exemplo n.º 6
0
    def document(self, *args, **kwargs):
        """Render the error document for the general public.

        Essentially, when an error occurs, a second request is initiated for
        the URL ``/error/document``. The URL is set on initialization of the
        :class:`pylons.middleware.StatusCodeRedirect` object, and can be
        overridden in :func:`tg.configuration.add_error_middleware`. Also,
        before this method is called, some potentially useful environ vars
        are set in :meth:`pylons.middleware.StatusCodeRedirect.__call__`
        (access them via :attr:`tg.request.environ`).

        :rtype: Dict
        :returns:
            prefix
                The environ SCRIPT_NAME.
            vars
                A dict containing the first 2 KB of the original request.
            code
                Integer error code thrown by the original request, but it can
                also be overriden by setting ``tg.request.params['code']``.
            message
                A message to display to the user. Pulled from
                ``tg.request.params['message']``.

        """
        request = self._py_object.request
        environ = request.environ
        original_request = environ.get('pylons.original_request', None)
        original_response = environ.get('pylons.original_response', None)
        default_message = '<p>%s</p>' % _("We're sorry but we weren't able "
                                          "to process this request.")

        message = request.params.get('message', default_message)
        message = clean_xhtml(message)

        return dict(
            prefix=environ.get('SCRIPT_NAME', ''),
            code=int(
                request.params.get(
                    'code', getattr(original_response, 'status_int', 500))),
            message=message,
            vars=dict(POST_request=unicode(original_request)[:2048]),
        )
Exemplo n.º 7
0
    def document(self, *args, **kwargs):
        """Render the error document for the general public.

        Essentially, when an error occurs, a second request is initiated for
        the URL ``/error/document``. The URL is set on initialization of the
        :class:`pylons.middleware.StatusCodeRedirect` object, and can be
        overridden in :func:`tg.configuration.add_error_middleware`. Also,
        before this method is called, some potentially useful environ vars
        are set in :meth:`pylons.middleware.StatusCodeRedirect.__call__`
        (access them via :attr:`tg.request.environ`).

        :rtype: Dict
        :returns:
            prefix
                The environ SCRIPT_NAME.
            vars
                A dict containing the first 2 KB of the original request.
            code
                Integer error code thrown by the original request, but it can
                also be overriden by setting ``tg.request.params['code']``.
            message
                A message to display to the user. Pulled from
                ``tg.request.params['message']``.

        """
        request = self._py_object.request
        environ = request.environ
        original_request = environ.get('pylons.original_request', None)
        original_response = environ.get('pylons.original_response', None)
        default_message = '<p>%s</p>' % _("We're sorry but we weren't able "
                                          "to process this request.")

        message = request.params.get('message', default_message)
        message = clean_xhtml(message)

        return dict(
            prefix = environ.get('SCRIPT_NAME', ''),
            code = int(request.params.get('code', getattr(original_response,
                                                          'status_int', 500))),
            message = message,
            vars = dict(POST_request=unicode(original_request)[:2048]),
        )
Exemplo n.º 8
0
 def test_can_replace_linebreaks_with_p_tags(self):
     htmlified_text = clean_xhtml("first\nline\n\nsecond line")
     assert_equals("<p>first line</p><p>second line</p>", htmlified_text)
     assert_equals(htmlified_text, clean_xhtml(htmlified_text))
 def test_makes_automatic_links_nofollow(self):
     original = 'http://example.com'
     cleaned = clean_xhtml(original)
     assert_equals(cleaned, '<p><a href="http://example.com" rel="nofollow">http://example.com</a></p>')
Exemplo n.º 10
0
 def test_can_replace_linebreaks_with_br_tags(self):
     htmlified_text = clean_xhtml('first\nline\n\nsecond line')
     assert_equals('<p>first\nline<br>second line</p>', htmlified_text)
     assert_equals(htmlified_text, clean_xhtml(htmlified_text))
 def test_adds_nofollow_attribute_to_links(self):
     original = '<a href="http://example.com">link</a>'
     cleaned = clean_xhtml(original)
     assert_equals(cleaned, '<p><a href="http://example.com" rel="nofollow">link</a></p>')
 def _test_removes_follow_attribute_from_links(self):
     original = '<a href="http://example.com" rel="follow">link</a>'
     cleaned = clean_xhtml(original)
     assert_equals(cleaned, '<a href="http://example.com" rel="nofollow">link</a>')
 def test_trailing_newlines_are_removed_in_output(self):
     expected_html = '<p>first</p>'
     assert_equals(expected_html, clean_xhtml('first\n'))
     self.skipTest('broken by bleach')
     assert_equals(expected_html, clean_xhtml('first\n\n'))
Exemplo n.º 14
0
 def test_trailing_newlines_are_removed_in_output(self):
     expected_html = '<p>first</p>'
     assert_equals(expected_html, clean_xhtml('first\n'))
     self.skipTest('broken by bleach')
     assert_equals(expected_html, clean_xhtml('first\n\n'))
 def test_can_replace_linebreaks_with_br_tags(self):
     htmlified_text = clean_xhtml('first\nline\n\nsecond line')
     assert_equals('<p>first\nline<br>second line</p>', htmlified_text)
     assert_equals(htmlified_text, clean_xhtml(htmlified_text))
 def test_trailing_newlines_are_removed_in_output(self):
     assert_equals(clean_xhtml('first\n'), clean_xhtml('first\n\n'))
Exemplo n.º 17
0
 def test_trailing_newlines_are_removed_in_output(self):
     assert_equals(clean_xhtml('first\n'), clean_xhtml('first\n\n'))
Exemplo n.º 18
0
 def test_adds_nofollow_attribute_to_links(self):
     original = '<a href="http://example.com">link</a>'
     cleaned = clean_xhtml(original)
     assert_equals(cleaned, '<p><a href="http://example.com" rel="nofollow">link</a></p>')
Exemplo n.º 19
0
 def _test_removes_follow_attribute_from_links(self):
     original = '<a href="http://example.com" rel="follow">link</a>'
     cleaned = clean_xhtml(original)
     assert_equals(cleaned, '<a href="http://example.com" rel="nofollow">link</a>')