Ticket #6965: faster_urlize_r7936_t6965.diff

File faster_urlize_r7936_t6965.diff, 1.3 KB (added by andrewbadr, 7 years ago)

Makes urlize faster

  • django/utils/html.py

     
    9494    words = word_split_re.split(force_unicode(text))
    9595    nofollow_attr = nofollow and ' rel="nofollow"' or ''
    9696    for i, word in enumerate(words):
    97         match = punctuation_re.match(word)
     97        match = None
     98        if '.' in word or '@' in word or ':' in word:
     99            match = punctuation_re.match(word)
    98100        if match:
    99101            lead, middle, trail = match.groups()
    100102            # Make URL we want to point to.
     
    102104            if middle.startswith('http://') or middle.startswith('https://'):
    103105                url = urlquote(middle, safe='/&=:;#?+*')
    104106            elif middle.startswith('www.') or ('@' not in middle and \
    105                     len(middle) > 0 and middle[0] in string.ascii_letters + string.digits and \
     107                    middle and middle[0] in string.ascii_letters + string.digits and \
    106108                    (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com'))):
    107109                url = urlquote('http://%s' % middle, safe='/&=:;#?+*')
    108110            elif '@' in middle and not ':' in middle and simple_email_re.match(middle):
Back to Top