Changeset 9898

Show
Ignore:
Timestamp:
07/08/08 20:49:51 (2 months ago)
Author:
steve-e
Message:

[Florob] Improved URL matching.

We don't match all valid URIs like blub:blaa but include common used (non)-urls like www.google.de

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/config.py

    r9886 r9898  
    252252                'check_idle_every_foo_seconds': [opt_int, 2, _('Choose interval between 2 checks of idleness.')], 
    253253                'latex_png_dpi': [opt_str, '108',_('Change the value to change the size of latex formulas displayed. The higher is larger.') ], 
     254                'uri_schemes': [opt_str, 'http https ftp ftps gopher news ed2k irc magnet sip', _('Valid uri schemes. Only schemes in this list will be made accepted as "real" uri.')], 
    254255        } 
    255256 
  • trunk/src/conversation_textview.py

    r9827 r9898  
    908908                        # add with possible animation 
    909909                        self.tv.add_child_at_anchor(img, anchor) 
    910                 #FIXME: one day, somehow sync with regexp in gajim.py 
    911                 elif special_text.startswith('http://') or \ 
    912                         special_text.startswith('www.') or \ 
    913                         special_text.startswith('ftp://') or \ 
    914                         special_text.startswith('ftp.') or \ 
    915                         special_text.startswith('https://') or \ 
    916                         special_text.startswith('gopher://') or \ 
    917                         special_text.startswith('news://') or \ 
    918                         special_text.startswith('ed2k://') or \ 
    919                         special_text.startswith('irc://') or \ 
    920                         special_text.startswith('sip:') or \ 
    921                         special_text.startswith('magnet:'): 
    922                         # it's a url 
     910                elif special_text.startswith('www.') or \ 
     911                special_text.startswith('ftp.'): 
    923912                        tags.append('url') 
    924913                        use_other_tags = False 
     
    992981                        use_other_tags = False 
    993982                else: 
    994                         #it's a url 
    995                         tags.append('url') 
    996                         use_other_tags = False 
     983                        # Check if we accept this as an uri 
     984                        schemes = gajim.config.get('uri_schemes').split() 
     985                        for scheme in schemes: 
     986                                if special_text.startswith(scheme + ':'): 
     987                                        tags.append('url') 
     988                                        use_other_tags = False 
     989                        # It's not a accepted uri 
     990                        if use_other_tags: 
     991                                end_iter = buffer.get_end_iter() 
     992                                buffer.insert_with_tags_by_name(end_iter, special_text, *other_tags) 
    997993 
    998994                if len(tags) > 0: 
     
    11721168                if name and (text.startswith('/me ') or text.startswith('/me\n')): 
    11731169                        text = '* ' + name + text[3:] 
     1170                        text_tags.append('italic') 
    11741171                # detect urls formatting and if the user has it on emoticons 
    11751172                index = self.detect_and_print_special_text(text, text_tags) 
  • trunk/src/gajim.py

    r9894 r9898  
    22752275                # so http://be) will match http://be and http://be)be) will match http://be)be 
    22762276 
    2277                 prefixes = '|'.join((r'http://', r'https://', r'gopher://', r'news://', 
    2278                         r'ftp://', r'ed2k://', r'irc://', r'magnet:', r'sip:', r'www\.', 
    2279                         r'ftp\.')) 
     2277                legacy_prefixes = r"((?<=\()(www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))"\ 
     2278                                r"|((www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+"\ 
     2279                                r"\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+)" 
    22802280                # NOTE: it's ok to catch www.gr such stuff exist! 
    22812281 
     
    22962296                latex = r'|\$\$[^$\\]*?([\]\[0-9A-Za-z()|+*/-]|[\\][\]\[0-9A-Za-z()|{}$])(.*?[^\\])?\$\$' 
    22972297 
    2298                 basic_pattern = links + '|' + mail 
     2298                basic_pattern = links + '|' + mail + '|' + legacy_prefixes 
    22992299 
    23002300                if gajim.config.get('use_latex'):