def autolink(text, trim_url_limit=None, nofollow=False):
 trim_url = (lambda x, limit=trim_url_limit: (((limit is not None) and (x[:limit] + (((len(x) >= limit) and '...') or ''))) or x))
 words = word_split_re.split(text)
 nofollow_attr = ((nofollow and ' rel="nofollow"') or '')
 for (i, word) in enumerate(words):
  match = punctuation_re.match(word)
  if match:
   (lead, middle, trail) = match.groups()
   if (middle.startswith('www.') or (('@' not in middle) and (not middle.startswith('http://')) and (not middle.startswith('https://')) and (len(middle) > 0) and (middle[0] in (string.letters + string.digits)) and (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com')))):
    middle = ('<a href="http://%s"%s target="_blank">%s</a>' % (middle, nofollow_attr, trim_url(middle)))
   if (middle.startswith('http://') or middle.startswith('https://')):
    middle = ('<a href="%s"%s target="_blank">%s</a>' % (middle, nofollow_attr, trim_url(middle)))
   if (('@' in middle) and (not middle.startswith('www.')) and (not (':' in middle)) and simple_email_re.match(middle)):
    middle = ('<a href="mailto:%s">%s</a>' % (middle, middle))
   if (((lead + middle) + trail) != word):
    words[i] = ((lead + middle) + trail)
 return ''.join(words)

def autolink ( text , trim_url_limit = None , nofollow = False ) : trim_url = ( lambda x , limit = trim_url_limit : ( ( ( limit is not None ) and ( x [ : limit ] + ( ( ( len ( x ) >= limit ) and '...' ) or '' ) ) ) or x ) ) words = word_split_re . split ( text ) nofollow_attr = ( ( nofollow and ' rel="nofollow"' ) or '' ) for ( i , word ) in enumerate ( words ) : match = punctuation_re . match ( word ) if match : ( lead , middle , trail ) = match . groups ( ) if ( middle . startswith ( 'www.' ) or ( ( '@' not in middle ) and ( not middle . startswith ( 'http://' ) ) and ( not middle . startswith ( 'https://' ) ) and ( len ( middle ) > 0 ) and ( middle [ 0 ] in ( string . letters + string . digits ) ) and ( middle . endswith ( '.org' ) or middle . endswith ( '.net' ) or middle . endswith ( '.com' ) ) ) ) : middle = ( '<a href="http://%s"%s target="_blank">%s</a>' % ( middle , nofollow_attr , trim_url ( middle ) ) ) if ( middle . startswith ( 'http://' ) or middle . startswith ( 'https://' ) ) : middle = ( '<a href="%s"%s target="_blank">%s</a>' % ( middle , nofollow_attr , trim_url ( middle ) ) ) if ( ( '@' in middle ) and ( not middle . startswith ( 'www.' ) ) and ( not ( ':' in middle ) ) and simple_email_re . match ( middle ) ) : middle = ( '<a href="mailto:%s">%s</a>' % ( middle , middle ) ) if ( ( ( lead + middle ) + trail ) != word ) : words [ i ] = ( ( lead + middle ) + trail ) return '' . join ( words )
turn any urls into links .