Fix Prospector and Pylint warnings in test extauth.py

This commit is contained in:
Badlop 2023-02-14 15:33:02 +01:00
parent d504ed8a9b
commit dea452bdfd
1 changed files with 18 additions and 13 deletions

View File

@ -1,51 +1,56 @@
"""extauth dummy script for ejabberd testing."""
import sys import sys
import struct import struct
def read_from_stdin(bytes): def read_from_stdin(read_bytes):
if hasattr(sys.stdin, 'buffer'): """Read buffer from standard input."""
return sys.stdin.buffer.read(bytes) if hasattr(sys.stdin, 'buffer'):
else: return sys.stdin.buffer.read(read_bytes)
return sys.stdin.read(bytes) return sys.stdin.read(read_bytes)
def read(): def read():
"""Read input and process the command."""
(pkt_size,) = struct.unpack('>H', read_from_stdin(2)) (pkt_size,) = struct.unpack('>H', read_from_stdin(2))
pkt = sys.stdin.read(pkt_size) pkt = sys.stdin.read(pkt_size)
cmd = pkt.split(':')[0] cmd = pkt.split(':')[0]
if cmd == 'auth': if cmd == 'auth':
u, s, p = pkt.split(':', 3)[1:] user, _, _ = pkt.split(':', 3)[1:]
if u == "wrong": if user == "wrong":
write(False) write(False)
else: else:
write(True) write(True)
elif cmd == 'isuser': elif cmd == 'isuser':
u, s = pkt.split(':', 2)[1:] user, _ = pkt.split(':', 2)[1:]
if u == "wrong": if user == "wrong":
write(False) write(False)
else: else:
write(True) write(True)
elif cmd == 'setpass': elif cmd == 'setpass':
u, s, p = pkt.split(':', 3)[1:] user, _, _ = pkt.split(':', 3)[1:]
write(True) write(True)
elif cmd == 'tryregister': elif cmd == 'tryregister':
u, s, p = pkt.split(':', 3)[1:] user, _, _ = pkt.split(':', 3)[1:]
write(True) write(True)
elif cmd == 'removeuser': elif cmd == 'removeuser':
u, s = pkt.split(':', 2)[1:] user, _ = pkt.split(':', 2)[1:]
write(True) write(True)
elif cmd == 'removeuser3': elif cmd == 'removeuser3':
u, s, p = pkt.split(':', 3)[1:] user, _, _ = pkt.split(':', 3)[1:]
write(True) write(True)
else: else:
write(False) write(False)
read() read()
def write(result): def write(result):
"""write result to standard output."""
if result: if result:
sys.stdout.write('\x00\x02\x00\x01') sys.stdout.write('\x00\x02\x00\x01')
else: else:
sys.stdout.write('\x00\x02\x00\x00') sys.stdout.write('\x00\x02\x00\x00')
sys.stdout.flush() sys.stdout.flush()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
read() read()