Commit 4e8306cf authored by Moul's avatar Moul

[mod] #5: use 'sys.exit()' instead of 'exit()'.

- See https://github.com/pyinstaller/pyinstaller/issues/1687
parent 709563c3
......@@ -6,6 +6,7 @@ import scrypt
import pyaes
import getpass
import os
import sys
def auth_method(c):
......@@ -18,7 +19,7 @@ def auth_method(c):
if c.contains_switches('auth-wif'):
return auth_by_wif()
print("Error: no authentication method")
exit(1)
sys.exit(1)
def generate_auth_file(c):
......@@ -40,13 +41,13 @@ def auth_by_auth_file(c):
file = "authfile"
if not os.path.isfile(file):
print("Error: the file \"" + file + "\" does not exist")
exit(1)
sys.exit(1)
with open(file) as f:
seed = f.read()
regex = re.compile('^[0-9a-fA-F]{64}$')
if not re.search(regex, seed):
print("Error: the format of the file is invalid")
exit(1)
sys.exit(1)
return seed
......@@ -55,7 +56,7 @@ def auth_by_seed():
regex = re.compile('^[0-9a-fA-F]{64}$')
if not re.search(regex, seed):
print("Error: the format of the seed is invalid")
exit(1)
sys.exit(1)
return seed
......@@ -69,10 +70,10 @@ def auth_by_scrypt(c):
n, r, p = int(n), int(r), int(p)
if n <= 0 or n > 65536 or r <= 0 or r > 512 or p <= 0 or p > 32:
print("Error: the values of Scrypt parameters are not good")
exit(1)
sys.exit(1)
else:
print("one of n, r or p is not a number")
exit(1)
sys.exit(1)
else:
print("Using default values. Scrypt parameters not specified or wrong format")
n, r, p = 4096, 16, 1
......@@ -87,7 +88,7 @@ def auth_by_wif():
regex = re.compile('^[1-9A-HJ-NP-Za-km-z]*$')
if not re.search(regex, wif):
print("Error: the format of WIF is invalid")
exit(1)
sys.exit(1)
wif_bytes = b58_decode(wif)
fi = wif_bytes[0:1]
......@@ -100,7 +101,7 @@ def auth_by_wif():
return get_seed_from_ewifv1(wif, password)
print("Error: the format of WIF is invalid or unknown")
exit(1)
sys.exit(1)
def get_seed_from_scrypt(salt, password, N=4096, r=16, p=1):
......@@ -113,12 +114,12 @@ def get_seed_from_wifv1(wif):
regex = re.compile('^[1-9A-HJ-NP-Za-km-z]*$')
if not re.search(regex, wif):
print("Error: the format of WIF is invalid")
exit(1)
sys.exit(1)
wif_bytes = b58_decode(wif)
if len(wif_bytes) != 35:
print("Error: the size of WIF is invalid")
exit(1)
sys.exit(1)
checksum_from_wif = wif_bytes[-2:]
fi = wif_bytes[0:1]
......@@ -127,7 +128,7 @@ def get_seed_from_wifv1(wif):
if fi != b'\x01':
print("Error: It's not a WIF format")
exit(1)
sys.exit(1)
# checksum control
checksum = nacl.hash.sha256(
......@@ -135,7 +136,7 @@ def get_seed_from_wifv1(wif):
nacl.encoding.RawEncoder)[0:2]
if checksum_from_wif != checksum:
print("Error: bad checksum of the WIF")
exit(1)
sys.exit(1)
seedhex = nacl.encoding.HexEncoder.encode(seed).decode("utf-8")
return seedhex
......@@ -145,12 +146,12 @@ def get_seed_from_ewifv1(ewif, password):
regex = re.compile('^[1-9A-HJ-NP-Za-km-z]*$')
if not re.search(regex, ewif):
print("Error: the format of EWIF is invalid")
exit(1)
sys.exit(1)
wif_bytes = b58_decode(ewif)
if len(wif_bytes) != 39:
print("Error: the size of EWIF is invalid")
exit(1)
sys.exit(1)
wif_no_checksum = wif_bytes[0:-2]
checksum_from_ewif = wif_bytes[-2:]
......@@ -161,7 +162,7 @@ def get_seed_from_ewifv1(ewif, password):
if fi != b'\x02':
print("Error: It's not a EWIF format")
exit(1)
sys.exit(1)
# Checksum Control
checksum = nacl.hash.sha256(
......@@ -169,7 +170,7 @@ def get_seed_from_ewifv1(ewif, password):
nacl.encoding.RawEncoder)[0:2]
if checksum_from_ewif != checksum:
print("Error: bad checksum of EWIF address")
exit(1)
sys.exit(1)
# SCRYPT
password = password.encode("utf-8")
......@@ -196,6 +197,6 @@ def get_seed_from_ewifv1(ewif, password):
nacl.encoding.RawEncoder)[0:4]
if salt_from_seed != salt:
print("Error: bad Password of EWIF address")
exit(1)
sys.exit(1)
return seedhex
import datetime
import os
import sys
from collections import OrderedDict
from tabulate import tabulate
from operator import itemgetter
......@@ -82,7 +83,7 @@ def set_network_sort_keys(some_keys):
global network_sort_keys
if some_keys.endswith(","):
print("Argument 'sort' ends with a comma, you have probably inserted a space after the comma, which is incorrect.")
exit(1)
sys.exit(1)
network_sort_keys = some_keys.split(",")
......@@ -102,7 +103,7 @@ def network_info(ep, discover):
wide = int(columns)
if wide < 146:
print("Wide screen need to be larger than 146. Current wide:", wide)
exit(1)
sys.exit(1)
# discover peers
# and make sure fields are always ordered the same
endpoints = [OrderedDict((i, p.get(i, None)) for i in ("domain", "port", "ip4", "ip6", "pubkey")) for p in discover_peers(ep, discover)]
......@@ -232,10 +233,10 @@ def cmd_transaction(ep, c):
if not (c.contains_definitions('amount') or c.contains_definitions('amountDU')):
print("--amount or --amountDU is not set")
exit(1)
sys.exit(1)
if not c.contains_definitions('output'):
print("--output is not set")
exit(1)
sys.exit(1)
du = get_last_du_value(ep)
if c.contains_definitions('amount'):
......
......@@ -3,6 +3,7 @@ import ipaddress
import json
import socket
import urllib.request
import sys
def discover_peers(ep, discover):
......@@ -123,7 +124,7 @@ def post_request(ep, path, postdata):
response = urllib.request.urlopen(request)
except urllib.error.URLError as e:
print(e)
exit(1)
sys.exit(1)
encoding = response.info().get_content_charset('utf8')
return json.loads(response.read().decode(encoding))
......@@ -141,7 +142,7 @@ def best_node(ep, main):
pass
if main:
print("Wrong node gived as argument")
exit(1)
sys.exit(1)
return None
......@@ -150,8 +151,8 @@ def check_port(port):
port = int(port)
except:
print("Port must be an integer")
exit(1)
sys.exit(1)
if (port < 0 or port > 65536):
print("Wrong port number")
exit(1)
sys.exit(1)
return 1
......@@ -53,7 +53,7 @@ def usage():
\n \
\n - id <pubkey> or <identity>: get corresponding identity or pubkey from pubkey or identity.\
\n it could autocomplete the pubkey corresponding to an identity with three or four following characters.")
exit()
sys.exit()
def cli():
......@@ -64,7 +64,7 @@ def cli():
usage()
if c.is_version_request():
print("silkaj 0.2.0")
exit()
sys.exit()
ep["domain"], ep["port"] = "duniter.org", "10901"
try:
ep["domain"], ep["port"] = c.get_definition('p').rsplit(':', 1)
......
......@@ -4,6 +4,7 @@ from tools import *
import re
import math
import time
import sys
def generate_and_send_transaction(ep, seed, AmountTransfered, outputAddr, Comment="", all_input=False, OutputbackChange=None):
......@@ -17,7 +18,7 @@ def generate_and_send_transaction(ep, seed, AmountTransfered, outputAddr, Commen
totalamount = get_amount_from_pubkey(ep, issuers)[0]
if totalamount < AmountTransfered:
print("the account: " + issuers + " don't have enough money for this transaction")
exit(1)
sys.exit(1)
while True:
listinput_and_amount = get_list_input_for_transaction(ep, issuers, AmountTransfered, all_input)
......@@ -182,18 +183,18 @@ def get_list_input_for_transaction(ep, pubkey, TXamount, allinput=False):
break
if TXamount > 0 and not intermediatetransaction:
print("Error: you don't have enough money")
exit(1)
sys.exit(1)
return listinputfinal, totalAmountInput, intermediatetransaction
def checkComment(Comment):
if len(Comment) > 255:
print("Error: Comment is too long")
exit(1)
sys.exit(1)
regex = re.compile('^[0-9a-zA-Z\ \-\_\:\/\;\*\[\]\(\)\?\!\^\+\=\@\&\~\#\{\}\|\\\<\>\%\.]*$')
if not re.search(regex, Comment):
print("Error: the format of the comment is invalid")
exit(1)
sys.exit(1)
def truncBase(amount, base):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment