From e9a53b69ad68e531a789eff3128f7304fd411808 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Wed, 15 Apr 2020 15:24:32 -0700 Subject: Lint fixes, also delete Biz.Language --- Que/client.py | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'Que/client.py') diff --git a/Que/client.py b/Que/client.py index 3d9291d..6958576 100755 --- a/Que/client.py +++ b/Que/client.py @@ -17,16 +17,16 @@ MAX_TIMEOUT = 99999999 # basically never timeout def auth(args): - ns = args.target.split("/")[0] - if ns == "pub": + "Returns the auth key for the given ns from ~/.config/que.conf" + namespace = args.target.split("/")[0] + if namespace == "pub": return None - else: - conf_file = os.path.expanduser("~/.config/que.conf") - if not os.path.exists(conf_file): - sys.exit("you need a ~/.config/que.conf") + conf_file = os.path.expanduser("~/.config/que.conf") + if not os.path.exists(conf_file): + sys.exit("you need a ~/.config/que.conf") cfg = configparser.ConfigParser() cfg.read(conf_file) - return cfg[ns]["key"] + return cfg[namespace]["key"] def send(args): @@ -53,7 +53,9 @@ def recv(args): print(msg) if args.then: subprocess.run( - args.then.replace("\msg", msg).replace("\que", args.target), shell=True + args.then.replace(r"\msg", msg).replace(r"que", args.target), + shell=True, + check=False, ) params = urllib.parse.urlencode({"poll": args.poll}) @@ -70,8 +72,8 @@ def recv(args): _recv(_req) -def autodecode(b): - """Attempt to decode bytes `b` into common codecs, preferably utf-8. If +def autodecode(bytestring): + """Attempt to decode bytes `bs` into common codecs, preferably utf-8. If no decoding is available, just return the raw bytes. For all available codecs, see: @@ -81,13 +83,14 @@ def autodecode(b): codecs = ["utf-8", "ascii"] for codec in codecs: try: - return b.decode(codec) + return bytestring.decode(codec) except UnicodeDecodeError: pass - return b + return bytestring def get_args(): + "Command line parser" cli = argparse.ArgumentParser(description=__doc__) cli.add_argument( "--host", default="http://que.run", help="where que-server is running" @@ -101,7 +104,7 @@ def get_args(): [ "when polling, run this shell command after each response,", "presumably for side effects," - "replacing '\que' with the target and '\msg' with the body of the response", + r"replacing '\que' with the target and '\msg' with the body of the response", ] ), ) @@ -129,21 +132,21 @@ def get_args(): if __name__ == "__main__": - args = get_args() + ARGV = get_args() try: - if args.infile: - send(args) + if ARGV.infile: + send(ARGV) else: - recv(args) + recv(ARGV) except KeyboardInterrupt: sys.exit(0) - except urllib.error.HTTPError as e: - print(e) + except urllib.error.HTTPError as err: + print(err) sys.exit(1) - except http.client.RemoteDisconnected as e: + except http.client.RemoteDisconnected as err: print("disconnected... retrying in 5 seconds") time.sleep(5) - if args.infile: - send(args) + if ARGV.infile: + send(ARGV) else: - recv(args) + recv(ARGV) -- cgit v1.2.3