diff options
author | alkorgun <alkorgun@gmail.com> | 2013-12-16 22:31:45 +0400 |
---|---|---|
committer | alkorgun <alkorgun@gmail.com> | 2013-12-16 22:31:45 +0400 |
commit | 180b1137d5a1b0fe05ca8d5aa99f6e43a25e3777 (patch) | |
tree | c7398892c1e4106d825d7f58550b09e1354445fd | |
parent | 85e01717e7c9866bbe574fbf5ad89689b6b2fe93 (diff) |
exceptions became more specified; fixed bug with unpacking args of socket.error in transports.py
-rw-r--r-- | xmpp/auth.py | 2 | ||||
-rw-r--r-- | xmpp/client.py | 2 | ||||
-rw-r--r-- | xmpp/commands.py | 16 | ||||
-rw-r--r-- | xmpp/debug.py | 8 | ||||
-rw-r--r-- | xmpp/dispatcher.py | 2 | ||||
-rw-r--r-- | xmpp/features.py | 4 | ||||
-rw-r--r-- | xmpp/filetransfer.py | 4 | ||||
-rw-r--r-- | xmpp/protocol.py | 6 | ||||
-rw-r--r-- | xmpp/simplexml.py | 14 | ||||
-rw-r--r-- | xmpp/transports.py | 18 |
10 files changed, 40 insertions, 36 deletions
diff --git a/xmpp/auth.py b/xmpp/auth.py index 95842f4..ca21835 100644 --- a/xmpp/auth.py +++ b/xmpp/auth.py @@ -207,7 +207,7 @@ class SASL(PlugIn): self.startsasl = "failure" try: reason = challenge.getChildren()[0] - except: + except Exception: reason = challenge self.DEBUG("Failed SASL authentification: %s" % reason, "error") raise NodeProcessed() diff --git a/xmpp/client.py b/xmpp/client.py index b1c090a..a28c818 100644 --- a/xmpp/client.py +++ b/xmpp/client.py @@ -370,5 +370,5 @@ class Component(CommonClient): return "sasl" else: raise auth.NotAuthorized(self.SASL.startsasl) - except: + except Exception: self.DEBUG(self.DBG, "Failed to authenticate %s" % name, "error") diff --git a/xmpp/commands.py b/xmpp/commands.py index f38fc2f..9c75649 100644 --- a/xmpp/commands.py +++ b/xmpp/commands.py @@ -92,7 +92,7 @@ class Commands(PlugIn): jid = str(request.getTo()) try: node = request.getTagAttr("command", "node") - except: + except Exception: conn.send(Error(request, ERR_BAD_REQUEST)) raise NodeProcessed() if self._handlers.has_key(jid): @@ -268,11 +268,11 @@ class Command_Handler_Prototype(PlugIn): # New request or old? try: session = request.getTagAttr("command", "sessionid") - except: + except Exception: session = None try: action = request.getTagAttr("command", "action") - except: + except Exception: action = None if action == None: action = "execute" @@ -331,7 +331,7 @@ class TestCommand(Command_Handler_Prototype): # This is the only place this should be repeated as all other stages should have SessionIDs try: session = request.getTagAttr("command", "sessionid") - except: + except Exception: session = None if session == None: session = self.getSessionID() @@ -413,14 +413,14 @@ class TestCommand(Command_Handler_Prototype): def cmdThirdStage(self, conn, request): form = DataForm(node=request.getTag(name="command").getTag(name="x", namespace=NS_DATA)) try: - num = float(form.getField("radius").getValue()) - except: + numb = float(form.getField("radius").getValue()) + except Exception: self.cmdSecondStageReply(conn, request) from math import pi if self.sessions[request.getTagAttr("command", "sessionid")]["data"]["type"] == "circlearea": - result = (num ** 2) * pi + result = (numb ** 2) * pi else: - result = num * 2 * pi + result = numb * 2 * pi reply = request.buildReply("result") form = DataForm(typ="result", data=[DataField(desc="result", name="result", value=result)]) reply.addChild(name="command", diff --git a/xmpp/debug.py b/xmpp/debug.py index be208c1..24329dc 100644 --- a/xmpp/debug.py +++ b/xmpp/debug.py @@ -77,7 +77,7 @@ class Debug: if isinstance(log_file, str): try: self._fh = open(log_file, "w") - except: + except Exception: print "ERROR: can open %s for writing." sys.exit(0) else: # assume its a stream type object @@ -97,7 +97,7 @@ class Debug: caller = sys._getframe(1) # used to get name of caller try: mod_name = ":%s" % caller.f_locals["__name__"] - except: + except Exception: mod_name = "" self.show("Debug created for %s%s" % (caller.f_code.co_filename, mod_name)) self.show(" flags defined: %s" % ",".join(self.active)) @@ -160,7 +160,7 @@ class Debug: output = output[:-1] try: self._fh.write(output) - except: + except Exception: # unicode strikes again ;) s = u"" for i in xrange(len(output)): @@ -211,7 +211,7 @@ class Debug: # assume comma string try: flags = active_flags.split(",") - except: + except Exception: self.show("***") self.show("*** Invalid debug param given: %s" % active_flags) self.show("*** please correct your param!") diff --git a/xmpp/dispatcher.py b/xmpp/dispatcher.py index c364ba9..62151d3 100644 --- a/xmpp/dispatcher.py +++ b/xmpp/dispatcher.py @@ -392,7 +392,7 @@ class Dispatcher(PlugIn): handler["func"](session, stanza) except NodeProcessed: user = 0 - except: + except Exception: self._pendingExceptions.insert(0, sys.exc_info()) if user and self._defaultHandler: self._defaultHandler(session, stanza) diff --git a/xmpp/features.py b/xmpp/features.py index 99088f7..8dbcbc3 100644 --- a/xmpp/features.py +++ b/xmpp/features.py @@ -175,7 +175,7 @@ def getPrivacyLists(disp): dict["lists"].append(list.getAttr("name")) else: dict[list.getName()] = list.getAttr("name") - except: + except Exception: pass else: return dict @@ -189,7 +189,7 @@ def getPrivacyList(disp, listname): resp = disp.SendAndWaitForResponse(Iq("get", NS_PRIVACY, payload=[Node("list", {"name": listname})])) if isResultNode(resp): return resp.getQueryPayload()[0] - except: + except Exception: pass def setActivePrivacyList(disp, listname=None, typ="active"): diff --git a/xmpp/filetransfer.py b/xmpp/filetransfer.py index fc938ab..c6ecdd9 100644 --- a/xmpp/filetransfer.py +++ b/xmpp/filetransfer.py @@ -82,7 +82,7 @@ class IBB(PlugIn): self.DEBUG("StreamOpenHandler called sid->%s blocksize->%s" % (sid, blocksize), "info") try: blocksize = int(blocksize) - except: + except Exception: err = ERR_BAD_REQUEST if not sid or not blocksize: err = ERR_BAD_REQUEST @@ -153,7 +153,7 @@ class IBB(PlugIn): try: seq = int(seq) data = decodestring(data) - except: + except Exception: seq = data = "" err = None if not sid in self._streams.keys(): diff --git a/xmpp/protocol.py b/xmpp/protocol.py index e9927b3..f49dcba 100644 --- a/xmpp/protocol.py +++ b/xmpp/protocol.py @@ -523,7 +523,7 @@ class Protocol(Node): try: if not self.getTimestamp() or x.getAttr("stamp") < self.getTimestamp(): self.setTimestamp(x.getAttr("stamp")) - except: + except Exception: pass if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp="" @@ -534,7 +534,7 @@ class Protocol(Node): """ try: to = self["to"] - except: + except Exception: to = None return to @@ -544,7 +544,7 @@ class Protocol(Node): """ try: frm = self["from"] - except: + except Exception: frm = None return frm diff --git a/xmpp/simplexml.py b/xmpp/simplexml.py index 19dcb29..a416d24 100644 --- a/xmpp/simplexml.py +++ b/xmpp/simplexml.py @@ -260,7 +260,7 @@ class Node(object): """ try: attr = self.attrs[key] - except: + except Exception: attr = None return attr @@ -321,7 +321,7 @@ class Node(object): """ try: attr = self.getTag(tag).attrs[attr] - except: + except Exception: attr = None return attr @@ -331,7 +331,7 @@ class Node(object): """ try: data = self.getTag(tag).getData() - except: + except Exception: data = None return data @@ -433,7 +433,7 @@ class Node(object): """ try: self.getTag(tag).attrs[attr] = val - except: + except Exception: self.addChild(tag, attrs={attr: val}) def setTagData(self, tag, val, attrs={}): @@ -443,7 +443,7 @@ class Node(object): """ try: self.getTag(tag, attrs).setData(ustr(val)) - except: + except Exception: self.addChild(tag, attrs, payload=[ustr(val)]) def has_attr(self, key): @@ -600,9 +600,9 @@ class NodeBuilder: ns = self._document_nsp.get(nsp, "http://www.gajim.org/xmlns/undeclared-root") try: self.stream_header_received(ns, name, attrs) - except ValueError as e: + except ValueError: self._document_attrs = None - raise ValueError(str(e)) + raise if not self.last_is_data and self._ptr.parent: self._ptr.parent.data.append("") self.last_is_data = 0 diff --git a/xmpp/transports.py b/xmpp/transports.py index 0a12a74..71e1fb3 100644 --- a/xmpp/transports.py +++ b/xmpp/transports.py @@ -147,9 +147,13 @@ class TCPsocket(PlugIn): self._sock.connect(server) self._send = self._sock.sendall self._recv = self._sock.recv - except socket.error, (errno, strerror): - self.DEBUG("Failed to connect to remote host %s: %s (%s)" % (repr(server), strerror, errno), "error") - except: + except socket.error as error: + try: + code, error = error + except Exception: + code = -1 + self.DEBUG("Failed to connect to remote host %s: %s (%s)" % (repr(server), error, code), "error") + except Exception: pass else: self.DEBUG("Successfully connected to remote host %s." % repr(server), "start") @@ -180,12 +184,12 @@ class TCPsocket(PlugIn): sys.exc_clear() self._owner.disconnected() raise IOError("Disconnected!") - except: + except Exception: data = "" while self.pending_data(0): try: add = self._recv(BUFLEN) - except: + except Exception: break if not add: break @@ -213,7 +217,7 @@ class TCPsocket(PlugIn): data = ustr(data).encode("utf-8") try: self._send(data) - except: + except Exception: self.DEBUG("Socket error while sending data.", "error") self._owner.disconnected() else: @@ -297,7 +301,7 @@ class HTTPPROXYsocket(TCPsocket): return None try: proto, code, desc = reply.split("\n")[0].split(" ", 2) - except: + except Exception: raise error("Invalid proxy reply") if code != "200": self.DEBUG("Invalid proxy reply: %s %s %s" % (proto, code, desc), "error") |