human
I wrote the below code

    from urllib import quote as urlquote
    LEADING_PUNCTUATION = ['(', '<', '&lt;']
    TRAILING_PUNCTUATION = ['.', ',', ')', '>', '\n', '&gt;']
    word_split_re = re.compile('([\\s\\xa0]+|&nbsp;)')
    punctuation_re = re.compile(('^(?P<lead>(?:%s)*)(?P<middle>.*?)(?P<trail>(?:%s)*)$' % ('|'.join([re.escape(x) for x in LEADING_PUNCTUATION]), '|'.join([re.escape(x) for x in TRAILING_PUNCTUATION]))))
    simple_email_re = re.compile('^\\S+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+$')
    del x
    def escape(html):
        return html.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
    trim_url = (lambda x, limit=trim_url_limit: (((limit is not None) and ((len(x) > limit) and ('%s...' % x[:max(0, (limit - 3))]))) or x))
    words = word_split_re.split(text)
    nofollow_attr = ((nofollow and '    rel="nofollow"') or '')
    for (i, word) in enumerate(words):
        match = None
        if (('.' in word) or ('@' in word) or (':' in word)):
            match = punctuation_re.match(word.replace(u'\u2019', "'"))
        if match:
            (lead, middle, trail) = match.groups()
            middle = middle.encode('utf-8')
            url = None
            if (middle.startswith('http://') or middle.startswith('https://')):
                url = urlquote(middle, safe='%/&=:;#?+*')
            elif (middle.startswith('www.') or (('@' not in middle) and middle and (middle[0] in (string.ascii_letters + string.digits)) and (middle.endswith('.org') or middle.endswith('.net') or middle.endswith('.com')))):
                url = urlquote(('http://%s' % middle), safe='%/&=:;#?+*')
            elif (('@' in middle) and (not (':' in middle)) and simple_email_re.match(middle)):
                url = ('mailto:%s' % middle)
                nofollow_attr = ''
            if url:
                trimmed = trim_url(middle)
                if autoescape:
                    (lead, trail) = (escape(lead), escape(trail))
                    (url, trimmed) = (escape(url),...

What's a good function header?
assistant
#Here's a good function header.

def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):