Some fixes on YCC and Networking module
This commit is contained in:
parent
22da70ac39
commit
1693488a56
@ -57,6 +57,10 @@ def traceURL(url, timeout=5, stack=None):
|
|||||||
stack = list()
|
stack = list()
|
||||||
stack.append(url)
|
stack.append(url)
|
||||||
|
|
||||||
|
if len(stack) > 15:
|
||||||
|
stack.append('stack overflow :(')
|
||||||
|
return stack
|
||||||
|
|
||||||
o = urlparse(url, "http")
|
o = urlparse(url, "http")
|
||||||
if o.netloc == "":
|
if o.netloc == "":
|
||||||
return stack
|
return stack
|
||||||
@ -72,12 +76,12 @@ def traceURL(url, timeout=5, stack=None):
|
|||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
print ("<tools.web> Unable to receive page %s from %s on %d."
|
print ("<tools.web> Unable to receive page %s from %s on %d."
|
||||||
% (o.path, o.netloc, o.port))
|
% (o.path, o.netloc, o.port))
|
||||||
return None
|
return stack
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = conn.getresponse()
|
res = conn.getresponse()
|
||||||
except http.client.BadStatusLine:
|
except http.client.BadStatusLine:
|
||||||
return None
|
return stack
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
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:
|
elif res.status == http.client.FOUND or res.status == http.client.MOVED_PERMANENTLY or res.status == http.client.SEE_OTHER:
|
||||||
url = res.getheader("Location")
|
url = res.getheader("Location")
|
||||||
if url in stack:
|
if url in stack:
|
||||||
stack.append(url)
|
stack.append("loop on " + url)
|
||||||
return stack
|
return stack
|
||||||
else:
|
else:
|
||||||
return traceURL(url, timeout, stack)
|
return traceURL(url, timeout, stack)
|
||||||
else:
|
else:
|
||||||
return None
|
return stack
|
||||||
|
@ -56,12 +56,12 @@ def cmd_ycc(msg):
|
|||||||
|
|
||||||
def parselisten(msg):
|
def parselisten(msg):
|
||||||
global LAST_URLS
|
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:
|
if res is not None:
|
||||||
url = res.group(1)
|
url = res.group(1)
|
||||||
o = urlparse(url)
|
o = urlparse(url)
|
||||||
if o.scheme != "":
|
if o.scheme != "":
|
||||||
if o.netloc == "ycc.fr":
|
if o.netloc == "ycc.fr" or (o.netloc == "" and len(o.path) < 10):
|
||||||
return False
|
return False
|
||||||
if msg.channel not in LAST_URLS:
|
if msg.channel not in LAST_URLS:
|
||||||
LAST_URLS[msg.channel] = list()
|
LAST_URLS[msg.channel] = list()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user