diff --git a/main.py b/main.py index 6c77bfa..aa5fc9b 100644 --- a/main.py +++ b/main.py @@ -112,7 +112,7 @@ def transactions(): page = request.args.get('page', 1) try: page = int(page) - except: + except ValueError: page = 1 if page < 1: @@ -209,7 +209,7 @@ def sendConfirmed(): address = request.args.get("address") amount = float(request.args.get("amount","0")) response = account_module.send(request.cookies.get("account"),address,amount) - if 'error' in response and response['error'] != None: + if 'error' in response and response['error'] is not None: # If error is a dict get the message if isinstance(response['error'], dict): if 'message' in response['error']: @@ -280,7 +280,7 @@ def auctions(): # Sort sort = request.args.get("sort") - if sort == None: + if sort is None: sort = "time" sort = sort.lower() sort_price = "" @@ -294,7 +294,7 @@ def auctions(): reverse = False direction = request.args.get("direction") - if direction == None: + if direction is None: if sort == "time": direction = "⬆" else: @@ -363,7 +363,7 @@ def revealAllBids(): return redirect("/auctions?message=Failed to reveal bids") if 'error' in response: - if response['error'] != None: + if response['error'] is not None: if response['error']['message'] == "Nothing to do.": return redirect("/auctions?message=No reveals pending") return redirect("/auctions?message=" + response['error']['message']) @@ -386,7 +386,7 @@ def redeemAllBids(): return redirect("/auctions?message=Failed to redeem bids") if 'error' in response: - if response['error'] != None: + if response['error'] is not None: if response['error']['message'] == "Nothing to do.": return redirect("/auctions?message=No redeems pending") return redirect("/auctions?message=" + response['error']['message']) @@ -408,7 +408,7 @@ def registerAllDomains(): return redirect("/auctions?message=Failed to register domains") if 'error' in response: - if response['error'] != None: + if response['error'] is not None: if response['error']['message'] == "Nothing to do.": return redirect("/auctions?message=No domains to register") return redirect("/auctions?message=" + response['error']['message']) @@ -427,7 +427,7 @@ def finalizeAllBids(): response = account_module.finalizeAll(request.cookies.get("account")) if 'error' in response: - if response['error'] != None: + if response['error'] is not None: if response['error']['message'] == "Nothing to do.": return redirect("/dashboard?message=No domains to finalize") return redirect("/dashboard?message=" + response['error']['message']) @@ -505,7 +505,6 @@ def search(): domain_info = account_module.getDomain(search_term) owner = 'Unknown' dns = [] - txs = [] if domain_info: # Check if info and info.owner @@ -558,10 +557,10 @@ def manage(domain: str): dns = render.dns(dns) errorMessage = request.args.get("error") - if errorMessage == None: + if errorMessage is None: errorMessage = "" address = request.args.get("address") - if address == None: + if address is None: address = "" finalize_time = "" @@ -605,7 +604,7 @@ def finalize(domain: str): domain = domain.lower() response = account_module.finalize(request.cookies.get("account"),domain) - if response['error'] != None: + if response['error'] is not None: print(response) return redirect("/manage/" + domain + "?error=" + response['error']['message']) @@ -624,7 +623,7 @@ def cancelTransfer(domain: str): domain = domain.lower() response = account_module.cancelTransfer(request.cookies.get("account"),domain) if 'error' in response: - if response['error'] != None: + if response['error'] is not None: print(response) return redirect("/manage/" + domain + "?error=" + response['error']['message']) @@ -674,13 +673,13 @@ def revokeConfirm(domain: str): return redirect("/manage/" + domain + "?error=An error occurred. Please try again.") response = account_module.check_password(request.cookies.get("account"),password) - if response == False: + if not response: return redirect("/manage/" + domain + "?error=Invalid password") response = account_module.revoke(request.cookies.get("account"),domain) if 'error' in response: - if response['error'] != None: + if response['error'] is not None: print(response) return redirect("/manage/" + domain + "?error=" + response['error']['message']) @@ -720,7 +719,7 @@ def editPage(domain: str): user_edits = request.args.get("dns") - if user_edits != None: + if user_edits is not None: dns = urllib.parse.unquote(user_edits) else: dns = account_module.getDNS(domain) @@ -733,7 +732,7 @@ def editPage(domain: str): # Check if new records have been added dnsType = request.args.get("type") dnsValue = request.args.get("value") - if dnsType != None and dnsValue != None: + if dnsType is not None and dnsValue is not None: if dnsType != "DS": dns.append({"type": dnsType, "value": dnsValue}) else: @@ -747,7 +746,7 @@ def editPage(domain: str): key_tag = int(ds[0]) algorithm = int(ds[1]) digest_type = int(ds[2]) - except: + except ValueError: raw_dns = str(dns).replace("'",'"') return redirect("/manage/" + domain + "/edit?dns=" + urllib.parse.quote(str(raw_dns)) + "&error=Invalid DS record") @@ -759,7 +758,7 @@ def editPage(domain: str): raw_dns = str(dns).replace("'",'"') dns = render.dns(dns,True) errorMessage = request.args.get("error") - if errorMessage == None: + if errorMessage is None: errorMessage = "" @@ -845,7 +844,7 @@ def signMessage(domain): content = "Message to sign:
" + message + "

" signedMessage = account_module.signMessage(request.cookies.get("account"),domain,message) - if signedMessage["error"] != None: + if signedMessage["error"] is not None: return redirect("/manage/" + domain + "?error=" + signedMessage["error"]) content += f"Signature:
{signedMessage['result']}

" @@ -904,7 +903,7 @@ def auction(domain): domainInfo = account_module.getDomain(search_term) error = request.args.get("error") - if error == None: + if error is None: error = "" if 'error' in domainInfo: @@ -914,7 +913,7 @@ def auction(domain): error=error) if domainInfo['info'] is None: - if 'registered' in domainInfo and domainInfo['registered'] == False and 'expired' in domainInfo and domainInfo['expired'] == False: + if 'registered' in domainInfo and not domainInfo['registered'] and 'expired' in domainInfo and not domainInfo['expired']: # Needs to be registered next_action = 'ERROR GETTING NEXT STATE' else: @@ -995,7 +994,7 @@ def rescan_auction(domain): domain = domain.lower() - response = account_module.rescan_auction(account,domain) + account_module.rescan_auction(account,domain) return redirect("/auction/" + domain) @app.route('/auction//bid') @@ -1091,7 +1090,7 @@ def open_auction(domain): response = account_module.openAuction(request.cookies.get("account"),domain) if 'error' in response: - if response['error'] != None: + if response['error'] is not None: return redirect("/auction/" + domain + "?error=" + response['error']['message']) return redirect(f"/success?tx={response['hash']}") @@ -1140,10 +1139,10 @@ def settings(): return redirect("/logout") error = request.args.get("error") - if error == None: + if error is None: error = "" success = request.args.get("success") - if success == None: + if success is None: success = "" @@ -1202,7 +1201,7 @@ def settings_action(action): if action == "zap": resp = account_module.zapTXs(request.cookies.get("account")) - if type(resp) == dict and 'error' in resp: + if type(resp) is dict and 'error' in resp: return redirect("/settings?error=" + str(resp['error'])) return redirect("/settings?success=Zapped transactions") @@ -1288,7 +1287,7 @@ def login_post(): account = request.form.get("account") password = request.form.get("password") - if account == None or password == None: + if account is None or password is None: wallets = account_module.listWallets() wallets = render.wallets(wallets) return render_template("login.html", @@ -1327,7 +1326,7 @@ def register(): password = request.form.get("password") repeatPassword = request.form.get("password_repeat") - if account == None or password == None or repeatPassword == None: + if account is None or password is None or repeatPassword is None: return render_template("register.html", error="Invalid account or password", name=account,password=password,password_repeat=repeatPassword) @@ -1374,7 +1373,7 @@ def import_wallet(): repeatPassword = request.form.get("password_repeat") seed = request.form.get("seed") - if account == None or password == None or repeatPassword == None or seed == None: + if account is None or password is None or repeatPassword is None or seed is None: return render_template("import-wallet.html", error="Invalid account, password or seed", name=account,password=password,password_repeat=repeatPassword, @@ -1473,12 +1472,12 @@ def plugin(ptype,plugin): functions = plugins_module.getPluginFunctions(plugin) functions = render.plugin_functions(functions,plugin) - if data['verified'] == False: + if not data['verified']: functions = "
" + functions error = request.args.get("error") - if error == None: + if error is None: error = "" return render_template("plugin.html", account=account, @@ -1504,7 +1503,7 @@ def plugin_verify(ptype,plugin): data = plugins_module.getPluginData(plugin) - if data['verified'] == False: + if not data['verified']: plugins_module.verifyPlugin(plugin) return redirect("/plugin/" + plugin) @@ -1591,7 +1590,7 @@ def api_hsd(function): if not domain: return jsonify({"error": "No domain specified"}), 400 domainInfo = account_module.getDomain(domain) - if 'error' in domainInfo and domainInfo['error'] != None: + if 'error' in domainInfo and domainInfo['error'] is not None: return jsonify({"error": domainInfo['error']}), 400 stats = domainInfo['info']['stats'] if 'stats' in domainInfo['info'] else {} state = domainInfo['info']['state'] @@ -1712,7 +1711,7 @@ def api_wallet(function): if function == "domains": domains = account_module.getDomains(account) - if type(domains) == dict and 'error' in domains: + if type(domains) is dict and 'error' in domains: return jsonify({"result": [], "error": domains['error']}) # Add nameRender to each domain @@ -1726,7 +1725,7 @@ def api_wallet(function): page = request.args.get('page', 1) try: page = int(page) - except: + except ValueError: page = 1 if page < 1: @@ -1799,7 +1798,6 @@ def api_wallet_mobile(function): return jsonify({"error": "Not logged in"}) account = account_module.check_account(request.cookies.get("account")) - password = request.cookies.get("account","").split(":")[1] if not account: return jsonify({"error": "Invalid account"}) diff --git a/plugin.py b/plugin.py index ec4b923..4695b87 100644 --- a/plugin.py +++ b/plugin.py @@ -62,7 +62,8 @@ def listPlugins(update=False): try: with open("user_data/plugin_signatures.json", "r") as f: signatures = json.load(f) - except: + except Exception as e: + print(f"Error loading plugin signatures: {e}") # Write a new signatures file with open("user_data/plugin_signatures.json", "w") as f: json.dump(signatures, f) @@ -87,7 +88,8 @@ def verifyPlugin(plugin: str): try: with open("user_data/plugin_signatures.json", "r") as f: signatures = json.load(f) - except: + except Exception as e: + print(f"Error loading plugin signatures: {e}") # Write a new signatures file with open("user_data/plugin_signatures.json", "w") as f: json.dump(signatures, f) @@ -120,7 +122,8 @@ def getPluginData(pluginStr: str): try: with open("user_data/plugin_signatures.json", "r") as f: signatures = json.load(f) - except: + except Exception as e: + print(f"Error loading plugin signatures: {e}") # Write a new signatures file with open("user_data/plugin_signatures.json", "w") as f: json.dump(signatures, f) @@ -171,7 +174,8 @@ def runPluginFunction(plugin: str, function: str, params: dict, authentication: try: with open("user_data/plugin_signatures.json", "r") as f: signatures = json.load(f) - except: + except Exception as e: + print(f"Error loading plugin signatures: {e}") # Write a new signatures file with open("user_data/plugin_signatures.json", "w") as f: json.dump(signatures, f) diff --git a/render.py b/render.py index a9fea93..626ea74 100644 --- a/render.py +++ b/render.py @@ -53,7 +53,7 @@ def domains(domains, mobile=False): link = f'/manage/{domain["name"]}' link_action = "Manage" - if domain['registered'] == False: + if not domain['registered']: link_action = "Register" link = f'/auction/{domain["name"]}/register' @@ -251,7 +251,7 @@ def txs(data): amount = entry['amount'] amount = amount / 1000000 - if entry['blind'] == None: + if entry['blind'] is None: html_output += f"{amount:,.2f} HNS\n" else: blind = entry['blind'] @@ -496,7 +496,7 @@ def plugin_output_dash(outputs, returns): for returnOutput in returns: if returnOutput not in outputs: continue - if outputs[returnOutput] == None: + if outputs[returnOutput] is None: continue html += render_template('components/dashboard-plugin.html', name=returns[returnOutput]["name"], output=outputs[returnOutput]) return html