replace BaseException with Exception
authorBryan Stitt <bryan@stitthappens.com>
Sun, 10 Nov 2013 04:21:02 +0000 (20:21 -0800)
committerBryan Stitt <bryan@stitthappens.com>
Sun, 10 Nov 2013 04:21:02 +0000 (20:21 -0800)
15 files changed:
electrum
gui/android.py
gui/gtk.py
gui/qt/lite_window.py
gui/qt/main_window.py
gui/stdio.py
gui/text.py
lib/account.py
lib/bitcoin.py
lib/commands.py
lib/interface.py
lib/util.py
lib/wallet.py
plugins/aliases.py
plugins/qrscanner.py

index 8cdabcb..32c5411 100755 (executable)
--- a/electrum
+++ b/electrum
@@ -103,7 +103,7 @@ def run_command(cmd, password = None, args = []):
     cmd_runner.password = password
     try:
         result = func(*args[1:])
-    except BaseException, e:
+    except Exception as e:
         import traceback
         traceback.print_exc(file=sys.stdout)
         sys.exit(1)
index e254a46..800dc32 100644 (file)
@@ -458,7 +458,7 @@ def pay_to(recipient, amount, fee, label):
 
     try:
         tx = wallet.mktx( [(recipient, amount)], password, fee)
-    except BaseException, e:
+    except Exception as e:
         modal_dialog('error', e.message)
         droid.dialogDismiss()
         return
index e7a3a0f..7120af3 100644 (file)
@@ -807,7 +807,7 @@ class ElectrumWindow:
 
         try:
             tx = self.wallet.mktx( [(to_address, amount)], password, fee )
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
             return
 
index 3f24370..5131ae0 100644 (file)
@@ -750,7 +750,7 @@ class MiniActuator:
 
         try:
             tx = self.g.wallet.mktx([(dest_address, amount)], password, fee)
-        except BaseException as error:
+        except Exception as error:
             QMessageBox.warning(parent_window, _('Error'), str(error), _('OK'))
             return False
 
@@ -778,7 +778,7 @@ class MiniActuator:
                 with open(fileName,'w') as f:
                     f.write(json.dumps(tx.as_dict(),indent=4) + '\n')
                 QMessageBox.information(QWidget(), _('Unsigned transaction created'), _("Unsigned transaction was saved to file:") + " " +fileName, _('OK'))
-            except BaseException as e:
+            except Exception as e:
                 QMessageBox.warning(QWidget(), _('Error'), _('Could not write transaction to file: %s' % e), _('OK'))
         return True
 
index e3c6c1e..57f8307 100644 (file)
@@ -889,7 +889,7 @@ class ElectrumWindow(QMainWindow):
 
         try:
             tx = self.wallet.mktx_from_account( [(to_address, amount)], password, fee, self.current_account)
-        except BaseException, e:
+        except Exception as e:
             traceback.print_exc(file=sys.stdout)
             self.show_message(str(e))
             return
@@ -1635,7 +1635,7 @@ class ElectrumWindow(QMainWindow):
         if not address: return
         try:
             pk_list = self.wallet.get_private_key(address, password)
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
             return
         QMessageBox.information(self, _('Private key'), _('Address')+ ': ' + address + '\n\n' + _('Private key') + ': ' + '\n'.join(pk_list), _('OK'))
@@ -1648,7 +1648,7 @@ class ElectrumWindow(QMainWindow):
         try:
             sig = self.wallet.sign_message(str(address.text()), message, password)
             signature.setText(sig)
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
 
     def sign_message(self, address):
@@ -1840,7 +1840,7 @@ class ElectrumWindow(QMainWindow):
 
         try:
             tx = self.wallet.make_unsigned_transaction(outputs, None, None)
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
             return
 
@@ -1893,7 +1893,7 @@ class ElectrumWindow(QMainWindow):
             export_error_label = _("Electrum was unable to produce a private key-export.")
             QMessageBox.critical(None, _("Unable to create csv"), export_error_label + "\n" + str(reason))
 
-        except BaseException, e:
+        except Exception as e:
           self.show_message(str(e))
           return
 
@@ -1946,7 +1946,7 @@ class ElectrumWindow(QMainWindow):
         for key in text:
             try:
                 addr = self.wallet.import_key(key, password)
-            except BaseException as e:
+            except Exception as e:
                 badkeys.append(key)
                 continue
             if not addr: 
index f252a8a..517f8bb 100644 (file)
@@ -198,7 +198,7 @@ class ElectrumGui:
 
         try:
             tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee)
-        except BaseException, e:
+        except Exception as e:
             print(str(e))
             return
             
index 437ce35..d9b9520 100644 (file)
@@ -309,7 +309,7 @@ class ElectrumGui:
 
         try:
             tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee)
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
             return
             
index a220de8..9a262bf 100644 (file)
@@ -109,7 +109,7 @@ class OldAccount(Account):
         master_public_key = master_private_key.get_verifying_key().to_string()
         if master_public_key != self.mpk:
             print_error('invalid password (mpk)')
-            raise BaseException('Invalid password')
+            raise Exception('Invalid password')
         return True
 
     def redeem_script(self, sequence):
index 94d5075..9780a65 100644 (file)
@@ -294,7 +294,7 @@ def verify_message(address, signature, message):
     try:
         EC_KEY.verify_message(address, signature, message)
         return True
-    except BaseException as e:
+    except Exception as e:
         print_error("Verification error: {0}".format(e))
         return False
 
@@ -319,7 +319,7 @@ class EC_KEY(object):
             except:
                 continue
         else:
-            raise BaseException("error: cannot sign message")
+            raise Exception("error: cannot sign message")
 
     @classmethod
     def verify_message(self, address, signature, message):
@@ -331,11 +331,11 @@ class EC_KEY(object):
         order = G.order()
         # extract r,s from signature
         sig = base64.b64decode(signature)
-        if len(sig) != 65: raise BaseException("Wrong encoding")
+        if len(sig) != 65: raise Exception("Wrong encoding")
         r,s = util.sigdecode_string(sig[1:], order)
         nV = ord(sig[0])
         if nV < 27 or nV >= 35:
-            raise BaseException("Bad encoding")
+            raise Exception("Bad encoding")
         if nV >= 31:
             compressed = True
             nV -= 4
@@ -364,7 +364,7 @@ class EC_KEY(object):
         # check that we get the original signing address
         addr = public_key_to_bc_address( encode_point(public_key, compressed) )
         if address != addr:
-            raise BaseException("Bad signature")
+            raise Exception("Bad signature")
 
 
 ###################################### BIP32 ##############################
index 129b1c5..aef1e9c 100644 (file)
@@ -228,7 +228,7 @@ class Commands:
         try:
             addr = self.wallet.import_key(sec,self.password)
             out = "Keypair imported: ", addr
-        except BaseException as e:
+        except Exception as e:
             out = "Error: Keypair import failed: " + str(e)
         return out
 
@@ -245,19 +245,19 @@ class Commands:
 
         for to_address, amount in outputs:
             if not is_valid(to_address):
-                raise BaseException("Invalid Bitcoin address", to_address)
+                raise Exception("Invalid Bitcoin address", to_address)
 
         if change_addr:
             if not is_valid(change_addr):
-                raise BaseException("Invalid Bitcoin address", change_addr)
+                raise Exception("Invalid Bitcoin address", change_addr)
 
         if domain is not None:
             for addr in domain:
                 if not is_valid(addr):
-                    raise BaseException("invalid Bitcoin address", addr)
+                    raise Exception("invalid Bitcoin address", addr)
             
                 if not self.wallet.is_mine(addr):
-                    raise BaseException("address not in wallet", addr)
+                    raise Exception("address not in wallet", addr)
 
         for k, v in self.wallet.labels.items():
             if change_addr and v == change_addr:
index 43b0a6c..360b82c 100644 (file)
@@ -117,7 +117,7 @@ class Interface(threading.Thread):
             return
 
         if protocol not in 'ghst':
-            raise BaseException('Unknown protocol: %s'%protocol)
+            raise Exception('Unknown protocol: %s'%protocol)
 
         self.host = host
         self.port = port
index fb84b5d..b719fed 100644 (file)
@@ -49,7 +49,7 @@ def user_dir():
     elif 'ANDROID_DATA' in os.environ:
         return "/sdcard/electrum/"
     else:
-        #raise BaseException("No home directory found in environment variables.")
+        #raise Exception("No home directory found in environment variables.")
         return 
 
 def appdata_dir():
index cbc95a2..4297f2c 100644 (file)
@@ -56,7 +56,7 @@ def pw_decode(s, password):
         try:
             d = DecodeAES(secret, s)
         except:
-            raise BaseException('Invalid password')
+            raise Exception('Invalid password')
         return d
     else:
         return s
@@ -257,10 +257,10 @@ class Wallet:
         try:
             address = address_from_private_key(sec)
         except:
-            raise BaseException('Invalid private key')
+            raise Exception('Invalid private key')
 
         if self.is_mine(address):
-            raise BaseException('Address already in wallet')
+            raise Exception('Address already in wallet')
         
         # store the originally requested keypair into the imported keys table
         self.imported_keys[address] = pw_encode(sec, password )
@@ -296,7 +296,7 @@ class Wallet:
         import mnemonic
         
         if self.seed: 
-            raise BaseException("a seed exists")
+            raise Exception("a seed exists")
 
         if not seed:
             self.seed = random_seed(128)
@@ -438,7 +438,7 @@ class Wallet:
         elif account_type == '2of3':
             return "m/3'/%d & m/4'/%d & m/5'/%d"%(i,i,i)
         else:
-            raise BaseException('unknown account type')
+            raise Exception('unknown account type')
 
 
     def num_accounts(self, account_type):
@@ -609,7 +609,7 @@ class Wallet:
             K, Kc = get_pubkeys_from_secret(master_k.decode('hex'))
             assert K.encode('hex') == master_K
         except:
-            raise BaseException("Invalid password")
+            raise Exception("Invalid password")
         return master_k
 
 
@@ -628,7 +628,7 @@ class Wallet:
             if v == address:
                 return k, (0,0)
 
-        raise BaseException("Address not found", address)
+        raise Exception("Address not found", address)
 
 
     def get_roots(self, account):
@@ -1110,7 +1110,7 @@ class Wallet:
             if h == ['*']: continue
             for tx_hash, tx_height in h:
                 tx = self.transactions.get(tx_hash)
-                if tx is None: raise BaseException("Wallet not synchronized")
+                if tx is None: raise Exception("Wallet not synchronized")
                 is_coinbase = tx.inputs[0].get('prevout_hash') == '0'*64
                 for output in tx.d.get('outputs'):
                     if output.get('address') != addr: continue
@@ -1245,7 +1245,7 @@ class Wallet:
     def receive_history_callback(self, addr, hist):
 
         if not self.check_new_history(addr, hist):
-            raise BaseException("error: received history for %s is not consistent with known transactions"%addr)
+            raise Exception("error: received history for %s is not consistent with known transactions"%addr)
             
         with self.lock:
             self.history[addr] = hist
@@ -1754,12 +1754,12 @@ class WalletSynchronizer(threading.Thread):
                             hist.append( (tx_hash, item['height']) )
 
                     if len(hist) != len(result):
-                        raise BaseException("error: server sent history with non-unique txid", result)
+                        raise Exception("error: server sent history with non-unique txid", result)
 
                     # check that the status corresponds to what was announced
                     rs = requested_histories.pop(addr)
                     if self.wallet.get_status(hist) != rs:
-                        raise BaseException("error: status mismatch: %s"%addr)
+                        raise Exception("error: status mismatch: %s"%addr)
                 
                     # store received history
                     self.wallet.receive_history_callback(addr, hist)
index c294674..0a54d6d 100644 (file)
@@ -52,7 +52,7 @@ class Plugin(BasePlugin):
     def get_alias(self, alias, interactive = False, show_message=None, question = None):
         try:
             target, signing_address, auth_name = read_alias(self, alias)
-        except BaseException, e:
+        except Exception as e:
             # raise exception if verify fails (verify the chain)
             if interactive:
                 show_message("Alias error: " + str(e))
index d76742d..4826eeb 100644 (file)
@@ -110,7 +110,7 @@ class Plugin(BasePlugin):
 
         try:
             tx = self.gui.main_window.wallet.mktx( [(to_address, amount)], None, fee)
-        except BaseException, e:
+        except Exception as e:
             self.gui.main_window.show_message(str(e))
             return
 
@@ -126,13 +126,13 @@ class Plugin(BasePlugin):
     
             input_info = []
 
-        except BaseException, e:
+        except Exception as e:
             self.gui.main_window.show_message(str(e))
 
         try:
             json_text = json.dumps(tx.as_dict()).replace(' ', '')
             self.show_tx_qrcode(json_text, 'Unsigned Transaction')
-        except BaseException, e:
+        except Exception as e:
             self.gui.main_window.show_message(str(e))
 
     def show_tx_qrcode(self, data, title):
@@ -235,7 +235,7 @@ class Plugin(BasePlugin):
             self.gui.main_window.wallet.signrawtransaction(tx, input_info, [], password)
             txtext = json.dumps(tx.as_dict()).replace(' ', '')
             self.show_tx_qrcode(txtext, 'Signed Transaction')
-        except BaseException, e:
+        except Exception as e:
             self.gui.main_window.show_message(str(e))