def _parse_urls(self, match):
        '''Parse URLs.'''

        mat = match.group(0)

        # Fix a bug in the regex concerning www...com and www.-foo.com domains
        # TODO fix this in the regex instead of working around it here
        domain = match.group(5)
        if domain[0] in '.-':
            return mat

        # Only allow IANA one letter domains that are actually registered
        if len(domain) == 5 \
           and domain[-4:].lower() in ('.com', '.org', '.net') \
           and not domain.lower() in IANA_ONE_LETTER_DOMAINS:

            return mat

        # Check for urls without http(s)
        pos = mat.find('http')
        if pos != -1:
            pre, url = mat[:pos], mat[pos:]
            full_url = url

        # Find the www and force https://
        else:
            pos = mat.lower().find('www')
            pre, url = mat[:pos], mat[pos:]
            full_url = 'https://%s' % url

        if self._include_spans:
            span = match.span(0)
            # add an offset if pre is e.g. ' '
            span = (span[0] + len(pre), span[1])
            self._urls.append((url, span))
        else:
            self._urls.append(url)

        if self._html:
            return '%s%s' % (pre, self.format_url(full_url,
                                                  self._shorten_url(escape(url))))
def _parse_urls ( self , match ) : mat = match . group ( 0 ) domain = match . group ( 5 ) if domain [ 0 ] in '.-' : return mat if len ( domain ) == 5 and domain [ - 4 : ] . lower ( ) in ( '.com' , '.org' , '.net' ) and not domain . lower ( ) in IANA_ONE_LETTER_DOMAINS : return mat pos = mat . find ( 'http' ) if pos != - 1 : pre , url = mat [ : pos ] , mat [ pos : ] full_url = url else : pos = mat . lower ( ) . find ( 'www' ) pre , url = mat [ : pos ] , mat [ pos : ] full_url = 'https://%s' % url if self . _include_spans : span = match . span ( 0 ) span = ( span [ 0 ] + len ( pre ) , span [ 1 ] ) self . _urls . append ( ( url , span ) ) else : self . _urls . append ( url ) if self . _html : return '%s%s' % ( pre , self . format_url ( full_url , self . _shorten_url ( escape ( url ) ) ) )
Parse URLs.