def handle_validate(bot, ievent): """ validate provided url or last url in log """ url = None if ievent.rest: url = ievent.rest else: if plugins.url: url = plugins.fetch("url").latest(bot, ievent) if not url: ievent.missing('<url>') ; return try: url = valid_url(url) except urllib.error.HTTPError as e: ievent.reply('error: %s' % e) ; return if not url: ievent.reply('invalid or bad URL') ; return result = geturl_validate(url) if result: host = urllib.parse.urlparse(url)[1] if len(host) > 20: host = host[0:20] + '...' ievent.reply('%s: %s | modified: %s | server: %s | size: %s | content-type: %s | encoding: %s | doctype: %s' % \ tuple([host] + [result[x] for x in ['result', 'modified', 'server', 'size', 'content', 'encoding', 'doctype']]))
def handle_snarf(bot, ievent, direct=True): """ snarf provided url or last url in log """ url = None if ievent.rest: url = ievent.rest else: try: url = plugins.fetch("url").latest(bot, ievent) except Exception as ex: handle_exception() if not url: ievent.missing('<url>') ; return try: url = valid_url(url) except KeyError: ievent.reply("can't detect content type") ; return except SnarfException as e: if direct: ievent.reply('unable to snarf: %s' % str(e)) return except urllib.error.HTTPError as e: ievent.reply('unable to snarf: %s' % str(e)) ; return except urllib.error.URLError as ex: ievent.reply('unable to snarf: %s' % str(ex)) ; return if not url: ievent.reply('invalid url') ; return try: title = geturl_title(url) except socket.timeout: ievent.reply('%s socket timeout' % url) ; return except urllib.error.HTTPError as e: ievent.reply('error: %s' % e) ; return if title: host = urllib.parse.urlparse(url)[1] if len(host) > 20: host = host[0:20] + '...' ievent.reply('%s: %s' % (host, title)) else: ievent.reply('no title found at %s' % urllib.parse.urlparse(url)[1])