electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 5be9b7c669d45016492a04e403453b9c267a465d
parent df58fab5bde9fb5613e2305c152eadba850d89a2
Author: ThomasV <thomasv1@gmx.de>
Date:   Sun, 10 Nov 2013 14:14:11 -0800

Merge pull request #388 from WyseNynja/fix_more_bare_except

fix more bare excepts
Diffstat:
Melectrum | 4++--
Mgui/android.py | 14+++++++-------
Mgui/gtk.py | 24++++++++++++------------
Mgui/qt/__init__.py | 4++--
Mgui/qt/console.py | 2+-
Mgui/qt/installwizard.py | 2+-
Mgui/qt/main_window.py | 22+++++++++++-----------
Mgui/qt/password_dialog.py | 4++--
Mgui/qt/qrcodewidget.py | 2+-
Mgui/qt/transaction_dialog.py | 2+-
Mgui/stdio.py | 6+++---
Mgui/text.py | 12++++++------
Mplugins/aliases.py | 6+++---
Mplugins/exchange_rate.py | 8++++----
Mplugins/labels.py | 2+-
Mplugins/pointofsale.py | 6+++---
Mplugins/qrscanner.py | 6+++---
Mscripts/get_balance | 2+-
Mscripts/get_history | 2+-
Mscripts/merchant/merchant.py | 2+-
Mscripts/watch_address | 2+-
21 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/electrum b/electrum @@ -215,7 +215,7 @@ if __name__ == '__main__': seed = getpass.getpass(prompt = "seed:", stream = None) if options.concealed else raw_input("seed:") try: seed.decode('hex') - except: + except Exception: print_error("Warning: Not hex, trying decode.") seed = mnemonic_decode( seed.split(' ') ) if not seed: @@ -274,7 +274,7 @@ if __name__ == '__main__': # check password try: seed = wallet.get_seed(password) - except: + except Exception: print_msg("Error: This password does not decode this wallet.") exit(1) else: diff --git a/gui/android.py b/gui/android.py @@ -345,7 +345,7 @@ def get_history_values(n): time_str = str( dt.time() ) else: time_str = str( dt.date() ) - except: + except Exception: time_str = 'pending' conf_str = 'v' if conf else 'o' @@ -600,7 +600,7 @@ def payto_loop(): try: amount = int( 100000000 * Decimal(amount) ) - except: + except Exception: modal_dialog('Error','Invalid amount') continue @@ -718,7 +718,7 @@ def show_seed(): try: seed = wallet.get_seed(password) - except: + except Exception: modal_dialog('error','incorrect password') return @@ -734,7 +734,7 @@ def change_password_dialog(): try: wallet.get_seed(password) - except: + except Exception: modal_dialog('error','incorrect password') return @@ -811,7 +811,7 @@ def settings_loop(): if fee: try: fee = int( 100000000 * Decimal(fee) ) - except: + except Exception: modal_dialog('error','invalid fee value') wallet.set_fee(fee) set_listview() @@ -828,7 +828,7 @@ def settings_loop(): auto_connect = False try: network.set_parameters(host, port, protocol, proxy, auto_connect) - except: + except Exception: modal_dialog('error','invalid server') set_listview() @@ -987,7 +987,7 @@ class ElectrumGui: m = modal_input('Mnemonic','please enter your code') try: seed = mnemonic_decode(m.split(' ')) - except: + except Exception: modal_dialog('error: could not decode this seed') return diff --git a/gui/gtk.py b/gui/gtk.py @@ -51,12 +51,12 @@ def numbify(entry, is_int = False): s = s[:p] + '.' + s[p:p+8] try: amount = int( Decimal(s) * 100000000 ) - except: + except Exception: amount = None else: try: amount = int( s ) - except: + except Exception: amount = None entry.set_text(s) return amount @@ -70,7 +70,7 @@ def show_seed_dialog(wallet, password, parent): return try: seed = wallet.get_seed(password) - except: + except Exception: show_message("Incorrect password") return dialog = gtk.MessageDialog( @@ -140,7 +140,7 @@ def run_recovery_dialog(): try: seed.decode('hex') - except: + except Exception: print_error("Warning: Not hex, trying decode") seed = mnemonic.mn_decode( seed.split(' ') ) if not seed: @@ -209,7 +209,7 @@ def run_settings_dialog(self): try: fee = int( 100000000 * Decimal(fee) ) - except: + except Exception: show_message("error") return self.wallet.set_fee(fee) @@ -217,7 +217,7 @@ def run_settings_dialog(self): try: nz = int( nz ) if nz>8: nz = 8 - except: + except Exception: show_message("error") return @@ -359,7 +359,7 @@ def run_network_dialog( network, parent ): proxy = network.config.get('proxy') auto_connect = network.config.get('auto_cycle') network.set_parameters(host, port, protocol, proxy, auto_connect) - except: + except Exception: show_message("error:" + server) return False @@ -441,7 +441,7 @@ def change_password_dialog(wallet, parent, icon): try: wallet.get_seed(password) - except: + except Exception: show_message("Incorrect password") return @@ -591,7 +591,7 @@ class ElectrumWindow: if re.match('^(|([\w\-\.]+)@)((\w[\w\-]+\.)+[\w\-]+)$', r): try: to_address = self.wallet.get_alias(r, interactive=False) - except: + except Exception: continue if to_address: s = r + ' <' + to_address + '>' @@ -789,12 +789,12 @@ class ElectrumWindow: try: amount = int( Decimal(amount_entry.get_text()) * 100000000 ) - except: + except Exception: self.show_message( "invalid amount") return try: fee = int( Decimal(fee_entry.get_text()) * 100000000 ) - except: + except Exception: self.show_message( "invalid fee") return @@ -1168,7 +1168,7 @@ class ElectrumWindow: if conf > 0: try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: + except Exception: time_str = "------" conf_icon = gtk.STOCK_APPLY elif conf == -1: diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py @@ -26,7 +26,7 @@ import shutil try: import PyQt4 -except: +except Exception: sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'") from PyQt4.QtGui import * @@ -39,7 +39,7 @@ from electrum.bitcoin import MIN_RELAY_TX_FEE try: import icons_rc -except: +except Exception: sys.exit("Error: Could not import icons_rc.py, please generate it with: 'pyrcc4 icons.qrc -o gui/qt/icons_rc.py'") from util import * diff --git a/gui/qt/console.py b/gui/qt/console.py @@ -219,7 +219,7 @@ class Console(QtGui.QPlainTextEdit): exec command in self.namespace except SystemExit: self.close() - except: + except Exception: traceback_lines = traceback.format_exc().split('\n') # Remove traceback mentioning this file, and a linebreak for i in (3,2,1,-1): diff --git a/gui/qt/installwizard.py b/gui/qt/installwizard.py @@ -284,7 +284,7 @@ class InstallWizard(QDialog): return try: wallet.init_seed(seed) - except: + except Exception: import traceback traceback.print_exc(file=sys.stdout) QMessageBox.warning(None, _('Error'), _('Incorrect seed'), _('OK')) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py @@ -690,7 +690,7 @@ class ElectrumWindow(QMainWindow): if conf > 0: try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: + except Exception: time_str = _("error") if conf == -1: @@ -872,12 +872,12 @@ class ElectrumWindow(QMainWindow): try: amount = self.read_amount(unicode( self.amount_e.text())) - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Invalid Amount'), _('OK')) return try: fee = self.read_amount(unicode( self.fee_e.text())) - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Invalid Fee'), _('OK')) return @@ -923,7 +923,7 @@ class ElectrumWindow(QMainWindow): with open(fileName,'w') as f: f.write(json.dumps(tx.as_dict(),indent=4) + '\n') QMessageBox.information(self, _('Unsigned transaction created'), _("Unsigned transaction was saved to file:") + " " +fileName, _('OK')) - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Could not write transaction to file'), _('OK')) # add recipient to addressbook @@ -1559,7 +1559,7 @@ class ElectrumWindow(QMainWindow): if self.wallet.seed: try: mnemonic = self.wallet.get_mnemonic(password) - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Incorrect Password'), _('OK')) return from seed_dialog import SeedDialog @@ -1781,7 +1781,7 @@ class ElectrumWindow(QMainWindow): txt.decode('hex') tx = Transaction(txt) return tx - except: + except Exception: pass try: @@ -1794,7 +1794,7 @@ class ElectrumWindow(QMainWindow): input_info = json.loads(tx_dict['input_info']) tx.add_input_info(input_info) return tx - except: + except Exception: pass QMessageBox.critical(None, _("Unable to parse transaction"), _("Electrum was unable to parse your transaction")) @@ -1991,7 +1991,7 @@ class ElectrumWindow(QMainWindow): lang_combo.addItems(languages.values()) try: index = languages.keys().index(self.config.get("language",'')) - except: + except Exception: index = 0 lang_combo.setCurrentIndex(index) grid.addWidget(lang_combo, 1, 1) @@ -2040,7 +2040,7 @@ class ElectrumWindow(QMainWindow): fee = unicode(fee_e.text()) try: fee = self.read_amount(fee) - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Invalid value') +': %s'%fee, _('OK')) return @@ -2050,7 +2050,7 @@ class ElectrumWindow(QMainWindow): try: nz = int( nz ) if nz>8: nz=8 - except: + except Exception: QMessageBox.warning(self, _('Error'), _('Invalid value')+':%s'%nz, _('OK')) return @@ -2146,7 +2146,7 @@ class ElectrumWindow(QMainWindow): w = None cb.clicked.connect(mk_toggle(cb,p,w)) grid.addWidget(HelpButton(p.description()), i, 2) - except: + except Exception: print_msg(_("Error: cannot display plugin"), p) traceback.print_exc(file=sys.stdout) grid.setRowStretch(i+1,1) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py @@ -85,7 +85,7 @@ def run_password_dialog(self, wallet, parent): try: wallet.get_seed(password) - except: + except Exception: QMessageBox.warning(parent, _('Error'), _('Incorrect Password'), _('OK')) return @@ -97,7 +97,7 @@ def run_password_dialog(self, wallet, parent): try: wallet.update_password(password, new_password) - except: + except Exception: QMessageBox.warning(parent, _('Error'), _('Failed to update password'), _('OK')) return diff --git a/gui/qt/qrcodewidget.py b/gui/qt/qrcodewidget.py @@ -35,7 +35,7 @@ class QRCodeWidget(QWidget): self.qr.addData(self.addr) self.qr.make() break - except: + except Exception: self.qr=None continue self.update() diff --git a/gui/qt/transaction_dialog.py b/gui/qt/transaction_dialog.py @@ -26,7 +26,7 @@ import StringIO try: import PyQt4 -except: +except Exception: sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'") from PyQt4.QtGui import * diff --git a/gui/stdio.py b/gui/stdio.py @@ -104,7 +104,7 @@ class ElectrumGui: if confirmations: try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: + except Exception: time_str = "unknown" else: time_str = 'pending' @@ -175,12 +175,12 @@ class ElectrumGui: return try: amount = int( Decimal( self.str_amount) * 100000000 ) - except: + except Exception: print(_('Invalid Amount')) return try: fee = int( Decimal( self.str_fee) * 100000000 ) - except: + except Exception: print(_('Invalid Fee')) return diff --git a/gui/text.py b/gui/text.py @@ -64,7 +64,7 @@ class ElectrumGui: def set_cursor(self, x): try: curses.curs_set(x) - except: + except Exception: pass def restore_or_create(self): @@ -112,7 +112,7 @@ class ElectrumGui: if conf: try: time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except: + except Exception: time_str = "------" else: time_str = 'pending' @@ -291,12 +291,12 @@ class ElectrumGui: return try: amount = int( Decimal( self.str_amount) * 100000000 ) - except: + except Exception: self.show_message(_('Invalid Amount')) return try: fee = int( Decimal( self.str_fee) * 100000000 ) - except: + except Exception: self.show_message(_('Invalid Fee')) return @@ -360,7 +360,7 @@ class ElectrumGui: if not auto_connect: try: host, port, protocol = server.split(':') - except: + except Exception: self.show_message("Error:" + server + "\nIn doubt, type \"auto-connect\"") return False @@ -468,7 +468,7 @@ class ElectrumGui: choices = item.get('choices') try: j = choices.index(item.get('value')) - except: + except Exception: j = 0 new_choice = choices[(j + 1)% len(choices)] item['value'] = new_choice diff --git a/plugins/aliases.py b/plugins/aliases.py @@ -42,7 +42,7 @@ class Plugin(BasePlugin): if re.match('^(|([\w\-\.]+)@)((\w[\w\-]+\.)+[\w\-]+)$', r): try: to_address = self.get_alias(r, True, self.gui.show_message, self.gui.question) - except: + except Exception: return if to_address: s = r + ' <' + to_address + '>' @@ -103,7 +103,7 @@ class Plugin(BasePlugin): return '' try: lines = urllib.urlopen(url).readlines() - except: + except Exception: return '' # line 0 @@ -147,7 +147,7 @@ class Plugin(BasePlugin): try: EC_KEY.verify_message(signing_address, signature, url ) self.receipt = (signing_address, signature, url) - except: + except Exception: show_message('Warning: the URI contains a bad signature.\nThe identity of the recipient cannot be verified.') address = amount = label = identity = message = '' diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py @@ -34,14 +34,14 @@ class Exchanger(threading.Thread): try: connection = httplib.HTTPConnection('blockchain.info') connection.request("GET", "/ticker") - except: + except Exception: return response = connection.getresponse() if response.reason == httplib.responses[httplib.NOT_FOUND]: return try: response = json.loads(response.read()) - except: + except Exception: return quote_currencies = {} try: @@ -122,12 +122,12 @@ class Plugin(BasePlugin): def set_currencies(combo): try: combo.clear() - except: + except Exception: return combo.addItems(self.currencies) try: index = self.currencies.index(self.config.get('currency', "EUR")) - except: + except Exception: index = 0 combo.setCurrentIndex(index) diff --git a/plugins/labels.py b/plugins/labels.py @@ -7,7 +7,7 @@ import json from urlparse import urlparse, parse_qs try: import PyQt4 -except: +except Exception: sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'") from PyQt4.QtGui import * diff --git a/plugins/pointofsale.py b/plugins/pointofsale.py @@ -165,7 +165,7 @@ class Plugin(BasePlugin): def update_receive_item(self, address, item): try: amount, currency = self.requested_amounts.get(address, (None, None)) - except: + except Exception: print "cannot get requested amount", address, self.requested_amounts.get(address) amount, currency = None, None self.requested_amounts.pop(address) @@ -183,7 +183,7 @@ class Plugin(BasePlugin): label = self.wallet.labels.get(address) try: amount, currency = self.requested_amounts.get(address, (None, None)) - except: + except Exception: amount, currency = None, None self.qr_window.set_content( address, label, amount, currency ) @@ -197,7 +197,7 @@ class Plugin(BasePlugin): try: seq = self.wallet.get_address_index(address) index = seq[1][1] - except: + except Exception: print "cannot get index" return diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py @@ -76,7 +76,7 @@ class Plugin(BasePlugin): while True: try: proc.process_one() - except: + except Exception: # User closed the preview window return {} @@ -99,12 +99,12 @@ class Plugin(BasePlugin): try: amount = self.gui.main_window.read_amount(unicode( self.gui.main_window.amount_e.text())) - except: + except Exception: QMessageBox.warning(self.gui.main_window, _('Error'), _('Invalid Amount'), _('OK')) return try: fee = self.gui.main_window.read_amount(unicode( self.gui.main_window.fee_e.text())) - except: + except Exception: QMessageBox.warning(self.gui.main_window, _('Error'), _('Invalid Fee'), _('OK')) return diff --git a/scripts/get_balance b/scripts/get_balance @@ -85,7 +85,7 @@ def main(address): if __name__ == "__main__": try: address = sys.argv[1] - except: + except Exception: print "usage: get_balance <bitcoin_address>" sys.exit(1) main(address) diff --git a/scripts/get_history b/scripts/get_history @@ -5,7 +5,7 @@ from electrum import Network try: addr = sys.argv[1] -except: +except Exception: print "usage: get_history <bitcoin_address>" sys.exit(1) diff --git a/scripts/merchant/merchant.py b/scripts/merchant/merchant.py @@ -104,7 +104,7 @@ def process_request(amount, confirmations, expires_in, password): amount = float(amount) confirmations = int(confirmations) expires_in = float(expires_in) - except: + except Exception: return "incorrect parameters" account = wallet.accounts["m/0'/0"] diff --git a/scripts/watch_address b/scripts/watch_address @@ -4,7 +4,7 @@ import sys, time, electrum try: addr = sys.argv[1] -except: +except Exception: print "usage: watch_address <bitcoin_address>" sys.exit(1)