mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 15:30:18 +00:00
style: Change comparations according PEP8
According PEP8 this is the recommended way to do it. I'm 99% sure that this does not speed up the code, but we are comparing identity, not equality, so "is" and "is not" must be used. Signed-off-by: nothingbutlucas <69118979+nothingbutlucas@users.noreply.github.com>
This commit is contained in:
parent
cf41187e2f
commit
7159e6a523
@ -40,11 +40,11 @@ CHUNK_SIZE = 16*1024*1024
|
|||||||
def spin(until=None, msg=None, timeout=None):
|
def spin(until=None, msg=None, timeout=None):
|
||||||
i = 0
|
i = 0
|
||||||
syms = "⢄⢂⢁⡁⡈⡐⡠"
|
syms = "⢄⢂⢁⡁⡈⡐⡠"
|
||||||
if timeout != None:
|
if timeout is not None:
|
||||||
timeout = time.time()+timeout
|
timeout = time.time()+timeout
|
||||||
|
|
||||||
print(msg+" ", end=" ")
|
print(msg+" ", end=" ")
|
||||||
while (timeout == None or time.time()<timeout) and not until():
|
while (timeout is None or time.time()<timeout) and not until():
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
print(("\b\b"+syms[i]+" "), end="")
|
print(("\b\b"+syms[i]+" "), end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
@ -52,7 +52,7 @@ def spin(until=None, msg=None, timeout=None):
|
|||||||
|
|
||||||
print("\r"+" "*len(msg)+" \r", end="")
|
print("\r"+" "*len(msg)+" \r", end="")
|
||||||
|
|
||||||
if timeout != None and time.time() > timeout:
|
if timeout is not None and time.time() > timeout:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@ -204,7 +204,7 @@ def main():
|
|||||||
destination_hash = bytes.fromhex(identity_str)
|
destination_hash = bytes.fromhex(identity_str)
|
||||||
identity = RNS.Identity.recall(destination_hash)
|
identity = RNS.Identity.recall(destination_hash)
|
||||||
|
|
||||||
if identity == None:
|
if identity is None:
|
||||||
if not args.request:
|
if not args.request:
|
||||||
RNS.log("Could not recall Identity for "+RNS.prettyhexrep(destination_hash)+".", RNS.LOG_ERROR)
|
RNS.log("Could not recall Identity for "+RNS.prettyhexrep(destination_hash)+".", RNS.LOG_ERROR)
|
||||||
RNS.log("You can query the network for unknown Identities with the -R option.", RNS.LOG_ERROR)
|
RNS.log("You can query the network for unknown Identities with the -R option.", RNS.LOG_ERROR)
|
||||||
@ -212,7 +212,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
RNS.Transport.request_path(destination_hash)
|
RNS.Transport.request_path(destination_hash)
|
||||||
def spincheck():
|
def spincheck():
|
||||||
return RNS.Identity.recall(destination_hash) != None
|
return RNS.Identity.recall(destination_hash) is not None
|
||||||
spin(spincheck, "Requesting unknown Identity for "+RNS.prettyhexrep(destination_hash), args.t)
|
spin(spincheck, "Requesting unknown Identity for "+RNS.prettyhexrep(destination_hash), args.t)
|
||||||
|
|
||||||
if not spincheck():
|
if not spincheck():
|
||||||
@ -245,7 +245,7 @@ def main():
|
|||||||
RNS.log("Could not decode Identity from specified file")
|
RNS.log("Could not decode Identity from specified file")
|
||||||
exit(9)
|
exit(9)
|
||||||
|
|
||||||
if identity != None:
|
if identity is not None:
|
||||||
if args.hash:
|
if args.hash:
|
||||||
try:
|
try:
|
||||||
aspects = args.hash.split(".")
|
aspects = args.hash.split(".")
|
||||||
@ -255,7 +255,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
app_name = aspects[0]
|
app_name = aspects[0]
|
||||||
aspects = aspects[1:]
|
aspects = aspects[1:]
|
||||||
if identity.pub != None:
|
if identity.pub is not None:
|
||||||
destination = RNS.Destination(identity, RNS.Destination.OUT, RNS.Destination.SINGLE, app_name, *aspects)
|
destination = RNS.Destination(identity, RNS.Destination.OUT, RNS.Destination.SINGLE, app_name, *aspects)
|
||||||
RNS.log("The "+str(args.hash)+" destination for this Identity is "+RNS.prettyhexrep(destination.hash))
|
RNS.log("The "+str(args.hash)+" destination for this Identity is "+RNS.prettyhexrep(destination.hash))
|
||||||
RNS.log("The full destination specifier is "+str(destination))
|
RNS.log("The full destination specifier is "+str(destination))
|
||||||
@ -278,7 +278,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
app_name = aspects[0]
|
app_name = aspects[0]
|
||||||
aspects = aspects[1:]
|
aspects = aspects[1:]
|
||||||
if identity.prv != None:
|
if identity.prv is not None:
|
||||||
destination = RNS.Destination(identity, RNS.Destination.IN, RNS.Destination.SINGLE, app_name, *aspects)
|
destination = RNS.Destination(identity, RNS.Destination.IN, RNS.Destination.SINGLE, app_name, *aspects)
|
||||||
RNS.log("Created destination "+str(destination))
|
RNS.log("Created destination "+str(destination))
|
||||||
RNS.log("Announcing destination "+RNS.prettyhexrep(destination.hash))
|
RNS.log("Announcing destination "+RNS.prettyhexrep(destination.hash))
|
||||||
@ -369,7 +369,7 @@ def main():
|
|||||||
if args.decrypt and not args.write and not args.stdout and args.read and args.read.lower().endswith("."+ENCRYPT_EXT):
|
if args.decrypt and not args.write and not args.stdout and args.read and args.read.lower().endswith("."+ENCRYPT_EXT):
|
||||||
args.write = str(args.read).replace("."+ENCRYPT_EXT, "")
|
args.write = str(args.read).replace("."+ENCRYPT_EXT, "")
|
||||||
|
|
||||||
if args.sign and identity.prv == None:
|
if args.sign and identity.prv is None:
|
||||||
RNS.log("Specified Identity does not hold a private key. Cannot sign.", RNS.LOG_ERROR)
|
RNS.log("Specified Identity does not hold a private key. Cannot sign.", RNS.LOG_ERROR)
|
||||||
exit(14)
|
exit(14)
|
||||||
|
|
||||||
@ -395,7 +395,7 @@ def main():
|
|||||||
# data_output = sys.stdout
|
# data_output = sys.stdout
|
||||||
|
|
||||||
if args.sign:
|
if args.sign:
|
||||||
if identity.prv == None:
|
if identity.prv is None:
|
||||||
RNS.log("Specified Identity does not hold a private key. Cannot sign.", RNS.LOG_ERROR)
|
RNS.log("Specified Identity does not hold a private key. Cannot sign.", RNS.LOG_ERROR)
|
||||||
exit(16)
|
exit(16)
|
||||||
|
|
||||||
@ -525,7 +525,7 @@ def main():
|
|||||||
exit(26)
|
exit(26)
|
||||||
|
|
||||||
if args.decrypt:
|
if args.decrypt:
|
||||||
if identity.prv == None:
|
if identity.prv is None:
|
||||||
RNS.log("Specified Identity does not hold a private key. Cannot decrypt.", RNS.LOG_ERROR)
|
RNS.log("Specified Identity does not hold a private key. Cannot decrypt.", RNS.LOG_ERROR)
|
||||||
exit(27)
|
exit(27)
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ def main():
|
|||||||
chunk = data_input.read(CHUNK_SIZE)
|
chunk = data_input.read(CHUNK_SIZE)
|
||||||
if chunk:
|
if chunk:
|
||||||
plaintext = identity.decrypt(chunk)
|
plaintext = identity.decrypt(chunk)
|
||||||
if plaintext == None:
|
if plaintext is None:
|
||||||
if not args.stdout:
|
if not args.stdout:
|
||||||
RNS.log("Data could not be decrypted with the specified Identity")
|
RNS.log("Data could not be decrypted with the specified Identity")
|
||||||
exit(30)
|
exit(30)
|
||||||
|
Loading…
Reference in New Issue
Block a user