Networking module: improve curl stability

This commit is contained in:
Némunaire 2013-01-15 11:24:01 +01:00
parent b0d0b4a234
commit b9d7eda336

View File

@ -2,6 +2,8 @@
import http.client
import json
import socket
from urllib.parse import quote
from urllib.parse import urlparse
from urllib.request import urlopen
@ -25,14 +27,17 @@ def help_full ():
def cmd_curl(msg):
if len(msg.cmds) > 1:
req = web.getURLContent(" ".join(msg.cmds[1:]))
if req is not None:
res = Response(msg.sender, channel=msg.channel)
for m in req.decode().split("\n"):
res.append_message(m)
return res
else:
return Response(msg.sender, "Une erreur est survenue lors de l'accès à cette URL", channel=msg.channel)
try:
req = web.getURLContent(" ".join(msg.cmds[1:]))
if req is not None:
res = Response(msg.sender, channel=msg.channel)
for m in req.decode().split("\n"):
res.append_message(m)
return res
else:
return Response(msg.sender, "Une erreur est survenue lors de l'accès à cette URL", channel=msg.channel)
except socket.error as e:
return Response(msg.sender, e.strerror, channel=msg.channel)
else:
return Response(msg.sender, "Veuillez indiquer une URL à visiter.",
channel=msg.channel)