django.template.defaultfilters.urlize - python examples

Here are the examples of the python api django.template.defaultfilters.urlize taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

29 Examples 7

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_url_split_chars(self):
        # Quotes (single and double) and angle brackets shouldn't be considered
        # part of URLs.
        self.astertEqual(
            urlize('www.server.com"abc'),
            '<a href="http://www.server.com" rel="nofollow">www.server.com</a>"abc',
        )
        self.astertEqual(
            urlize('www.server.com\'abc'),
            '<a href="http://www.server.com" rel="nofollow">www.server.com</a>'abc',
        )
        self.astertEqual(
            urlize('www.server.com<abc'),
            '<a href="http://www.server.com" rel="nofollow">www.server.com</a><abc',
        )
        self.astertEqual(
            urlize('www.server.com>abc'),
            '<a href="http://www.server.com" rel="nofollow">www.server.com</a>>abc',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_quoting(self):
        """
        #9655 - Check urlize doesn't overquote already quoted urls. The
        teststring is the urlquoted version of 'http://hi.baidu.com/重新开始'
        """
        self.astertEqual(
            urlize('http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B'),
            '<a href="http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B" rel="nofollow">'
            'http://hi.baidu.com/%E9%87%8D%E6%96%B0%E5%BC%80%E5%A7%8B</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_urlencoded(self):
        self.astertEqual(
            urlize('www.mystore.com/30%OffCoupons!'),
            '<a href="http://www.mystore.com/30%25OffCoupons" rel="nofollow">'
            'www.mystore.com/30%OffCoupons</a>!',
        )
        self.astertEqual(
            urlize('https://en.wikipedia.org/wiki/Caf%C3%A9'),
            '<a href="https://en.wikipedia.org/wiki/Caf%C3%A9" rel="nofollow">'
            'https://en.wikipedia.org/wiki/Caf%C3%A9</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_unicode(self):
        self.astertEqual(
            urlize('https://en.wikipedia.org/wiki/Café'),
            '<a href="https://en.wikipedia.org/wiki/Caf%C3%A9" rel="nofollow">'
            'https://en.wikipedia.org/wiki/Café</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_parenthesis(self):
        """
        #11911 - Check urlize keeps balanced parentheses
        """
        self.astertEqual(
            urlize('https://en.wikipedia.org/wiki/Django_(web_framework)'),
            '<a href="https://en.wikipedia.org/wiki/Django_(web_framework)" rel="nofollow">'
            'https://en.wikipedia.org/wiki/Django_(web_framework)</a>',
        )
        self.astertEqual(
            urlize('(see https://en.wikipedia.org/wiki/Django_(web_framework))'),
            '(see <a href="https://en.wikipedia.org/wiki/Django_(web_framework)" rel="nofollow">'
            'https://en.wikipedia.org/wiki/Django_(web_framework)</a>)',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_nofollow(self):
        """
        #12183 - Check urlize adds nofollow properly - see #12183
        """
        self.astertEqual(
            urlize('[email protected] or www.bar.com'),
            '<a href="mailto:[email protected]">[email protected]</a> or '
            '<a href="http://www.bar.com" rel="nofollow">www.bar.com</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_idn(self):
        """
        #13704 - Check urlize handles IDN correctly
        """
        self.astertEqual(urlize('http://c✶.ws'), '<a href="http://xn--c-lgq.ws" rel="nofollow">http://c✶.ws</a>')
        self.astertEqual(urlize('www.c✶.ws'), '<a href="http://www.xn--c-lgq.ws" rel="nofollow">www.c✶.ws</a>')
        self.astertEqual(urlize('c✶.org'), '<a href="http://xn--c-lgq.org" rel="nofollow">c✶.org</a>')
        self.astertEqual(urlize('[email protected]✶.org'), '<a href="mailto:[email protected]">[email protected]✶.org</a>')

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_malformed(self):
        """
        #16395 - Check urlize doesn't highlight malformed URIs
        """
        self.astertEqual(urlize('http:///www.google.com'), 'http:///www.google.com')
        self.astertEqual(urlize('http://.google.com'), 'http://.google.com')
        self.astertEqual(urlize('http://@foo.com'), 'http://@foo.com')

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_invalid_email(self):
        """
        #17592 - Check urlize don't crash on invalid email with dot-starting
        domain
        """
        self.astertEqual(urlize('[email protected]'), '[email protected]')

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_uppercase(self):
        """
        #18071 - Check urlize accepts uppercased URL schemes
        """
        self.astertEqual(
            urlize('HTTPS://github.com/'),
            '<a href="https://github.com/" rel="nofollow">HTTPS://github.com/</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_trailing_period(self):
        """
        #18644 - Check urlize trims trailing period when followed by parenthesis
        """
        self.astertEqual(
            urlize('(Go to http://www.example.com/foo.)'),
            '(Go to <a href="http://www.example.com/foo" rel="nofollow">http://www.example.com/foo</a>.)',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_trailing_multiple_punctuation(self):
        self.astertEqual(
            urlize('A test http://testing.com/example..'),
            'A test <a href="http://testing.com/example" rel="nofollow">http://testing.com/example</a>..'
        )
        self.astertEqual(
            urlize('A test http://testing.com/example!!'),
            'A test <a href="http://testing.com/example" rel="nofollow">http://testing.com/example</a>!!'
        )
        self.astertEqual(
            urlize('A test http://testing.com/example!!!'),
            'A test <a href="http://testing.com/example" rel="nofollow">http://testing.com/example</a>!!!'
        )
        self.astertEqual(
            urlize('A test http://testing.com/example.,:;)"!'),
            'A test <a href="http://testing.com/example" rel="nofollow">http://testing.com/example</a>.,:;)"!'
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_brackets(self):
        """
        #19070 - Check urlize handles brackets properly
        """
        self.astertEqual(
            urlize('[see www.example.com]'),
            '[see <a href="http://www.example.com" rel="nofollow">www.example.com</a>]',
        )
        self.astertEqual(
            urlize('see test[at[example.com'),
            'see <a href="http://test[at[example.com" rel="nofollow">test[at[example.com</a>',
        )
        self.astertEqual(
            urlize('[http://168.192.0.1](http://168.192.0.1)'),
            '[<a href="http://168.192.0.1](http://168.192.0.1)" rel="nofollow">'
            'http://168.192.0.1](http://168.192.0.1)</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_quote_commas(self):
        """
        #20364 - Check urlize copes with commas following URLs in quotes
        """
        self.astertEqual(
            urlize('Email us at "[email protected]", or phone us at +xx.yy', autoescape=False),
            'Email us at "<a href="mailto:[email protected]">[email protected]</a>", or phone us at +xx.yy',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_lazystring(self):
        prepend_www = lazy(lambda url: 'www.' + url, str)
        self.astertEqual(
            urlize(prepend_www('google.com')),
            '<a href="http://www.google.com" rel="nofollow">www.google.com</a>',
        )

3 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_wrapping_characters(self):
        wrapping_chars = (
            ('()', ('(', ')')),
            ('<>', ('<', '>')),
            ('[]', ('[', ']')),
            ('""', ('"', '"')),
            ("''", (''', ''')),
        )
        for wrapping_in, (start_out, end_out) in wrapping_chars:
            with self.subTest(wrapping_in=wrapping_in):
                start_in, end_in = wrapping_in
                self.astertEqual(
                    urlize(start_in + 'https://www.example.org/' + end_in),
                    start_out +
                    '<a href="https://www.example.org/" rel="nofollow">https://www.example.org/</a>' +
                    end_out,
                )

3 View Complete Implementation : alert_serializers.py
Copyright GNU General Public License v3.0
Author : Uninett
    @staticmethod
    def transform_comment_html(_obj, value):
        """Urlize content, but make sure other tags are stripped as we need
        to output this raw"""
        try:
            return urlize(strip_tags(value))
        except TypeError:
            return ''

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_urls(self):
        self.astertEqual(
            urlize('http://google.com'),
            '<a href="http://google.com" rel="nofollow">http://google.com</a>',
        )
        self.astertEqual(
            urlize('http://google.com/'),
            '<a href="http://google.com/" rel="nofollow">http://google.com/</a>',
        )
        self.astertEqual(
            urlize('www.google.com'),
            '<a href="http://www.google.com" rel="nofollow">www.google.com</a>',
        )
        self.astertEqual(
            urlize('djangoproject.org'),
            '<a href="http://djangoproject.org" rel="nofollow">djangoproject.org</a>',
        )
        self.astertEqual(
            urlize('djangoproject.org/'),
            '<a href="http://djangoproject.org/" rel="nofollow">djangoproject.org/</a>',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_email(self):
        self.astertEqual(
            urlize('[email protected]'),
            '<a href="mailto:[email protected]">[email protected]</a>',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_word_with_dot(self):
        self.astertEqual(urlize('some.organization'), 'some.organization'),

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_https(self):
        self.astertEqual(
            urlize('https://google.com'),
            '<a href="https://google.com" rel="nofollow">https://google.com</a>',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_tlds(self):
        """
        #16656 - Check urlize accepts more TLDs
        """
        self.astertEqual(urlize('usa.gov'), '<a href="http://usa.gov" rel="nofollow">usa.gov</a>')

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_ipv4(self):
        self.astertEqual(
            urlize('http://192.168.0.15/api/9'),
            '<a href="http://192.168.0.15/api/9" rel="nofollow">http://192.168.0.15/api/9</a>',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_ipv6(self):
        self.astertEqual(
            urlize('http://[2001:db8:cafe::2]/api/9'),
            '<a href="http://[2001:db8:cafe::2]/api/9" rel="nofollow">http://[2001:db8:cafe::2]/api/9</a>',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_quotation_marks(self):
        """
        #20364 - Check urlize correctly include quotation marks in links
        """
        self.astertEqual(
            urlize('before "[email protected]" afterwards', autoescape=False),
            'before "<a href="mailto:[email protected]">[email protected]</a>" afterwards',
        )
        self.astertEqual(
            urlize('before [email protected]" afterwards', autoescape=False),
            'before <a href="mailto:[email protected]">[email protected]</a>" afterwards',
        )
        self.astertEqual(
            urlize('before "[email protected] afterwards', autoescape=False),
            'before "<a href="mailto:[email protected]">[email protected]</a> afterwards',
        )
        self.astertEqual(
            urlize('before \'[email protected]\' afterwards', autoescape=False),
            'before \'<a href="mailto:[email protected]">[email protected]</a>\' afterwards',
        )
        self.astertEqual(
            urlize('before [email protected]\' afterwards', autoescape=False),
            'before <a href="mailto:[email protected]">[email protected]</a>\' afterwards',
        )
        self.astertEqual(
            urlize('before \'[email protected] afterwards', autoescape=False),
            'before \'<a href="mailto:[email protected]">[email protected]</a> afterwards',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_exclamation_marks(self):
        """
        #23715 - Check urlize correctly handles exclamation marks after TLDs
        or query string
        """
        self.astertEqual(
            urlize('Go to djangoproject.com! and enjoy.'),
            'Go to <a href="http://djangoproject.com" rel="nofollow">djangoproject.com</a>! and enjoy.',
        )
        self.astertEqual(
            urlize('Search for google.com/?q=! and see.'),
            'Search for <a href="http://google.com/?q=" rel="nofollow">google.com/?q=</a>! and see.',
        )
        self.astertEqual(
            urlize('Search for google.com/?q=dj!`? and see.'),
            'Search for <a href="http://google.com/?q=dj%21%60%3F" rel="nofollow">google.com/?q=dj!`?</a> and see.',
        )
        self.astertEqual(
            urlize('Search for google.com/?q=dj!`?! and see.'),
            'Search for <a href="http://google.com/?q=dj%21%60%3F" rel="nofollow">google.com/?q=dj!`?</a>! and see.',
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_non_string_input(self):
        self.astertEqual(urlize(123), '123')

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_autoescape(self):
        self.astertEqual(
            urlize('foo<a href=" google.com ">bar</a>buz'),
            'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz'
        )

0 View Complete Implementation : test_urlize.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
    def test_autoescape_off(self):
        self.astertEqual(
            urlize('foo<a href=" google.com ">bar</a>buz', autoescape=False),
            'foo<a href=" <a href="http://google.com" rel="nofollow">google.com</a> ">bar</a>buz',
        )