Some fixes on YCC and Networking module

This commit is contained in:
Némunaire 2012-11-07 17:19:08 +01:00
parent 22da70ac39
commit 1693488a56
2 changed files with 10 additions and 6 deletions

View File

@ -57,6 +57,10 @@ def traceURL(url, timeout=5, stack=None):
stack = list()
stack.append(url)
if len(stack) > 15:
stack.append('stack overflow :(')
return stack
o = urlparse(url, "http")
if o.netloc == "":
return stack
@ -72,12 +76,12 @@ def traceURL(url, timeout=5, stack=None):
except socket.gaierror:
print ("<tools.web> Unable to receive page %s from %s on %d."
% (o.path, o.netloc, o.port))
return None
return stack
try:
res = conn.getresponse()
except http.client.BadStatusLine:
return None
return stack
finally:
conn.close()
@ -86,9 +90,9 @@ def traceURL(url, timeout=5, stack=None):
elif res.status == http.client.FOUND or res.status == http.client.MOVED_PERMANENTLY or res.status == http.client.SEE_OTHER:
url = res.getheader("Location")
if url in stack:
stack.append(url)
stack.append("loop on " + url)
return stack
else:
return traceURL(url, timeout, stack)
else:
return None
return stack

View File

@ -56,12 +56,12 @@ def cmd_ycc(msg):
def parselisten(msg):
global LAST_URLS
res = re.match(".*([a-zA-Z0-9+.-]+):(//)?([^ ]*).*", msg.content)
res = re.match("([a-zA-Z0-9+.-]+:(//)?[^ ]*)", msg.content)
if res is not None:
url = res.group(1)
o = urlparse(url)
if o.scheme != "":
if o.netloc == "ycc.fr":
if o.netloc == "ycc.fr" or (o.netloc == "" and len(o.path) < 10):
return False
if msg.channel not in LAST_URLS:
LAST_URLS[msg.channel] = list()