don't use bare except
authorBryan Stitt <bryan@stitthappens.com>
Sun, 10 Nov 2013 05:23:57 +0000 (21:23 -0800)
committerBryan Stitt <bryan@stitthappens.com>
Sun, 10 Nov 2013 05:23:57 +0000 (21:23 -0800)
lib/bitcoin.py
lib/blockchain.py
lib/commands.py
lib/interface.py
lib/network.py
lib/plugins.py
lib/simple_config.py
lib/transaction.py
lib/wallet.py

index 9780a65..36758f9 100644 (file)
@@ -115,7 +115,7 @@ def hash_160(public_key):
         md = hashlib.new('ripemd160')
         md.update(hashlib.sha256(public_key).digest())
         return md.digest()
-    except:
+    except Exception:
         import ripemd
         md = ripemd.new(hashlib.sha256(public_key).digest())
         return md.digest()
@@ -268,7 +268,7 @@ def is_valid(addr):
     if not ADDRESS_RE.match(addr): return False
     try:
         addrtype, h = bc_address_to_hash_160(addr)
-    except:
+    except Exception:
         return False
     return addr == hash_160_to_bc_address(h, addrtype)
 
@@ -277,7 +277,7 @@ def is_valid(addr):
 
 try:
     from ecdsa.ecdsa import curve_secp256k1, generator_secp256k1
-except:
+except Exception:
     print "cannot import ecdsa.curve_secp256k1. You probably need to upgrade ecdsa.\nTry: sudo pip install --upgrade ecdsa"
     exit()
 from ecdsa.curves import SECP256k1
@@ -316,7 +316,7 @@ class EC_KEY(object):
             try:
                 self.verify_message( address, sig, message)
                 return sig
-            except:
+            except Exception:
                 continue
         else:
             raise Exception("error: cannot sign message")
index c7dab20..08461d0 100644 (file)
@@ -119,7 +119,7 @@ class Blockchain(threading.Thread):
                 assert prev_hash == header.get('prev_block_hash')
                 assert bits == header.get('bits')
                 assert eval('0x'+_hash) < target
-            except:
+            except Exception:
                 return False
 
             prev_header = header
@@ -176,7 +176,7 @@ class Blockchain(threading.Thread):
             assert prev_hash == header.get('prev_block_hash')
             assert bits == header.get('bits')
             assert eval('0x'+_hash) < target
-        except:
+        except Exception:
             # this can be caused by a reorg.
             print_error("verify header failed"+ repr(header))
             verifier.undo_verifications()
@@ -227,7 +227,7 @@ class Blockchain(threading.Thread):
             print_error("downloading ", self.headers_url )
             urllib.urlretrieve(self.headers_url, filename)
             print_error("done.")
-        except:
+        except Exception:
             print_error( "download failed. creating file", filename )
             open(filename,'wb+').close()
 
@@ -411,7 +411,7 @@ class Blockchain(threading.Thread):
             index = params[0]
             try:
                 self.verify_chunk(index, result)
-            except:
+            except Exception:
                 print_error('Verify chunk failed!!')
                 return False
             requested_chunks.remove(index)
index aef1e9c..f34c10a 100644 (file)
@@ -306,7 +306,7 @@ class Commands:
             tx_hash, conf, is_mine, value, fee, balance, timestamp = item
             try:
                 time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
-            except:
+            except Exception:
                 time_str = "----"
 
             label, is_default_label = self.wallet.get_label(tx_hash)
index 360b82c..44de285 100644 (file)
@@ -49,7 +49,7 @@ def check_cert(host, cert):
 def cert_has_expired(cert_path):
     try:
         import OpenSSL
-    except:
+    except Exception:
         print_error("Warning: cannot import OpenSSL")
         return False
     from OpenSSL import crypto as c
@@ -112,7 +112,7 @@ class Interface(threading.Thread):
         try:
             host, port, protocol = self.server.split(':')
             port = int(port)
-        except:
+        except Exception:
             self.server = None
             return
 
@@ -196,7 +196,7 @@ class Interface(threading.Thread):
         self.connection_msg = ('https' if self.use_ssl else 'http') + '://%s:%d'%( self.host, self.port )
         try:
             self.poll()
-        except:
+        except Exception:
             print_error("http init session failed")
             self.is_connected = False
             return
@@ -218,7 +218,7 @@ class Interface(threading.Thread):
                 break
             except socket.error:
                 break
-            except:
+            except Exception:
                 traceback.print_exc(file=sys.stdout)
                 break
             
@@ -265,7 +265,7 @@ class Interface(threading.Thread):
         try:
             req = urllib2.Request(self.connection_msg, data_json, headers)
             response_stream = urllib2.urlopen(req, timeout=DEFAULT_TIMEOUT)
-        except:
+        except Exception:
             return
 
         for index, cookie in enumerate(cj):
@@ -318,7 +318,7 @@ class Interface(threading.Thread):
                 s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
                 try:
                     s.connect((self.host, self.port))
-                except:
+                except Exception:
                     # print_error("failed to connect", self.host, self.port)
                     return
 
@@ -346,7 +346,7 @@ class Interface(threading.Thread):
 
         try:
             s.connect(( self.host.encode('ascii'), int(self.port)))
-        except:
+        except Exception:
             print_error("failed to connect", self.host, self.port)
             return
 
@@ -370,7 +370,7 @@ class Interface(threading.Thread):
                     else:
                         print_msg("wrong certificate", self.host)
                 return
-            except:
+            except Exception:
                 print_error("wrap_socket failed", self.host)
                 traceback.print_exc(file=sys.stdout)
                 return
@@ -424,7 +424,7 @@ class Interface(threading.Thread):
                     c = json.loads(c)
                     self.queue_json_response(c)
 
-        except:
+        except Exception:
             traceback.print_exc(file=sys.stdout)
 
         self.is_connected = False
index 82bdcb4..c900cad 100644 (file)
@@ -385,7 +385,7 @@ class Network(threading.Thread):
                     if pruning_level == '': pruning_level = '0'
             try: 
                 is_recent = float(version)>=float(PROTOCOL_VERSION)
-            except:
+            except Exception:
                 is_recent = False
 
             if out and is_recent:
index 0e7e520..a3ba5bc 100644 (file)
@@ -24,7 +24,7 @@ def init_plugins(self):
     for name, p in zip(plugin_names, plugin_modules):
         try:
             plugins.append( p.Plugin(self, name) )
-        except:
+        except Exception:
             print_msg(_("Error: cannot initialize plugin"),p)
             traceback.print_exc(file=sys.stdout)
 
@@ -45,7 +45,7 @@ def run_hook(name, *args):
 
         try:
             f(*args)
-        except:
+        except Exception:
             print_error("Plugin error")
             traceback.print_exc(file=sys.stdout)
             
index e3614f5..1ae6579 100644 (file)
@@ -103,7 +103,7 @@ a SimpleConfig instance then reads the wallet file.
             import ast
             try:
                 out = ast.literal_eval(out)
-            except:
+            except Exception:
                 print "type error for '%s': using default value"%key
                 out = default
 
@@ -154,7 +154,7 @@ a SimpleConfig instance then reads the wallet file.
                 return
             try:
                 d = ast.literal_eval( data )  #parse raw data from reading wallet file
-            except:
+            except Exception:
                 raise IOError("Cannot read config file.")
 
             self.user_config = d
index 7e36369..b1c4bf5 100644 (file)
@@ -298,7 +298,7 @@ def match_decoded(decoded, to_match):
 def get_address_from_input_script(bytes):
     try:
         decoded = [ x for x in script_GetOp(bytes) ]
-    except:
+    except Exception:
         # coinbase transactions raise an exception
         print_error("cannot find address in input script", bytes.encode('hex'))
         return [], [], "(None)"
index 4297f2c..4cb7bd4 100644 (file)
@@ -55,7 +55,7 @@ def pw_decode(s, password):
         secret = Hash(password)
         try:
             d = DecodeAES(secret, s)
-        except:
+        except Exception:
             raise Exception('Invalid password')
         return d
     else:
@@ -117,7 +117,7 @@ class WalletStorage:
             return
         try:
             d = ast.literal_eval( data )  #parse raw data from reading wallet file
-        except:
+        except Exception:
             raise IOError("Cannot read wallet file.")
 
         self.data = d
@@ -192,7 +192,7 @@ class Wallet:
         for k,v in tx_list.items():
             try:
                 tx = Transaction(v)
-            except:
+            except Exception:
                 print_msg("Warning: Cannot deserialize transactions. skipping")
                 continue
 
@@ -256,7 +256,7 @@ class Wallet:
         seed = self.get_seed(password)
         try:
             address = address_from_private_key(sec)
-        except:
+        except Exception:
             raise Exception('Invalid private key')
 
         if self.is_mine(address):
@@ -314,7 +314,7 @@ class Wallet:
             self.seed_version = 4
             self.seed = str(seed)
             return
-        except:
+        except Exception:
             pass
 
         words = seed.split()
@@ -324,7 +324,7 @@ class Wallet:
         #try:
         #    mnemonic.mn_decode(words)
         #    uses_electrum_words = True
-        #except:
+        #except Exception:
         #    uses_electrum_words = False
         #
         #if uses_electrum_words and len(words) != 13:
@@ -608,7 +608,7 @@ class Wallet:
         try:
             K, Kc = get_pubkeys_from_secret(master_k.decode('hex'))
             assert K.encode('hex') == master_K
-        except:
+        except Exception:
             raise Exception("Invalid password")
         return master_k