human
Solve the following python programming problem given the following code:
@keep_lazy_text
def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
assistant
#Here is the Python code you requested.

    """Convert any URLs in text into clickable links.
    Works on http://, https://, www. links, and also on links ending in one of
    the original seven gTLDs (.com, .edu, .gov, .int, .mil, .net, and .org).
    Links can have trailing punctuation (periods, commas, close-parens) and
    leading punctuation (opening parens) and it\ll still do the right thing.
    If trim_url_limit is not None, truncate the URLs in the link text longer
    than this limit to trim_url_limit-3 characters and append an ellipsis.
    If nofollow is True, give the links a rel="nofollow" attribute.
    If autoescape is True, autoescape the link text and URLs.
    """
    safe_input = isinstance(text, SafeData)
    def trim_url(x, limit=trim_url_limit):
        if ((limit is None) or (len(x) <= limit)):
            return x
        return ('%s...' % x[:max(0, (limit - 3))])
    def unescape(text, trail):
        '\n                                If    input    URL    is    HTML-escaped,    unescape    it    so    that    it    can    be    safely    fed\n                                to    smart_urlquote.    For    example:\n                                http://example.com?x=1&amp;y=&lt;2&gt;    =>    http://example.com?x=1&y=<2>\n                                '
        unescaped = (text + trail).replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'")
        if (trail and unescaped.endswith(trail)):
            unescaped = unescaped[:(- len(trail))]
        elif (trail == ';'):
            text += trail
            trail = ''
        return (text, unescaped, trail)
    def trim_punctuation(lead, middle, trail):
        '\n                                Trim    trailing    and    wrapping    punctuation    from    `middle`.    Return    the    items\n                                of    the    new    state.\n                                '
        trimmed_something = True
        while trimmed_something:
            trimmed_something = False
            match = TRAILING_PUNCTUATION_RE.match(middle)
            if match:
                middle = match.group(1)
                trail = (match.group(2) + trail)
                trimmed_something = True
            for (opening, closing) in WRAPPING_PUNCTUATION:
                if middle.startswith(opening):
                    middle = middle[len(opening):]
                    lead += opening
                    trimmed_something = True
                if (middle.endswith(closing) and (middle.count(closing) == (middle.count(opening) + 1))):
                    middle = middle[:(- len(closing))]
                    trail = (closing + trail)
                   ...