def ip_html(ip): if ip in ['::']: return ip h = '<span class="ip' c = geoip.city(ip) if c and c.get('country_code'): cc = c.get('country_code').lower() h += ' cc-' + cc if os.path.isfile(parsemail.__path__[0] + \ '/../htdocs/images/flags/' + cc + '.gif'): h += ' flag' h += '"' title = None if c and c.get('country_name'): title = c.get('country_name') if c.get('city'): title += ' (' + c.get('city') + ')' elif re.match(r'(?:127|192|10|172\.(?:1[6-9]|2[0-9]|3[01]))\.', ip): title = 'RFC 1918 private network' elif re.match(r'fe([89ab][0-9a-f]):', ip.lower()): title = 'Link-local unicast' elif re.match(r'ff[0-9a-f]{2}:', ip.lower()): title = 'Multicast' if title: h += ' title="' + html.escape(title) + '"' return h + '>' + ip + '</span>'
def url_html(data, className='link'): url = data if not re.match('^[a-zA-Z]+://', url): url = 'http://' + url h = '<a rel="nofollow" href="' + \ html.escape(url) + '"' if className: h += ' class="' + className + '"' return h + '>' + html.escape(data) + '</a>'