Skip to content

Commit

Permalink
[mod] #5: use 'sys.exit()' instead of 'exit()'.
Browse files Browse the repository at this point in the history
  • Loading branch information
M5oul committed Apr 17, 2017
1 parent 709563c commit 4e8306c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
35 changes: 18 additions & 17 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pyaes
import getpass
import os
import sys


def auth_method(c):
Expand All @@ -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):
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -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]
Expand All @@ -127,15 +128,15 @@ 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(
nacl.hash.sha256(seed_fi, nacl.encoding.RawEncoder),
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
Expand All @@ -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:]
Expand All @@ -161,15 +162,15 @@ 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(
nacl.hash.sha256(wif_no_checksum, nacl.encoding.RawEncoder),
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")
Expand All @@ -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
9 changes: 5 additions & 4 deletions src/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import os
import sys
from collections import OrderedDict
from tabulate import tabulate
from operator import itemgetter
Expand Down Expand Up @@ -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(",")


Expand All @@ -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)]
Expand Down Expand Up @@ -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'):
Expand Down
9 changes: 5 additions & 4 deletions src/network_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import socket
import urllib.request
import sys


def discover_peers(ep, discover):
Expand Down Expand Up @@ -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))

Expand All @@ -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


Expand All @@ -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
4 changes: 2 additions & 2 deletions src/silkaj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import math
import time
import sys


def generate_and_send_transaction(ep, seed, AmountTransfered, outputAddr, Comment="", all_input=False, OutputbackChange=None):
Expand All @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4e8306c

Please sign in to comment.