From bd769f5bdb08a0fd558f5cadd7f31af14562de33 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 6 Mar 2021 02:42:17 +0100 Subject: [PATCH] fix py2 + encourage py3 --- contrib/systemd/copyparty.service | 2 +- copyparty/httpcli.py | 18 +++++++++--------- copyparty/mtag.py | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/systemd/copyparty.service b/contrib/systemd/copyparty.service index 9802f296..d966e9ce 100644 --- a/contrib/systemd/copyparty.service +++ b/contrib/systemd/copyparty.service @@ -12,7 +12,7 @@ Description=copyparty file server [Service] -ExecStart=/usr/bin/python /usr/local/bin/copyparty-sfx.py -q -v /mnt::a +ExecStart=/usr/bin/python3 /usr/local/bin/copyparty-sfx.py -q -v /mnt::a ExecStartPre=/bin/bash -c 'mkdir -p /run/tmpfiles.d/ && echo "x /tmp/pe-copyparty*" > /run/tmpfiles.d/copyparty.conf' [Install] diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index a49dd768..5e0a1396 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -74,7 +74,7 @@ class HttpCli(object): except Pebkac as ex: # self.log("pebkac at httpcli.run #1: " + repr(ex)) self.keepalive = self._check_nonfatal(ex) - self.loud_reply(str(ex), status=ex.code) + self.loud_reply(unicode(ex), status=ex.code) return self.keepalive # time.sleep(0.4) @@ -163,7 +163,7 @@ class HttpCli(object): response = ["HTTP/1.1 {} {}".format(status, HTTPCODE[status])] if length is not None: - response.append("Content-Length: " + str(length)) + response.append("Content-Length: " + unicode(length)) # close if unknown length, otherwise take client's preference response.append("Connection: " + ("Keep-Alive" if self.keepalive else "Close")) @@ -521,7 +521,7 @@ class HttpCli(object): if len(cstart) > 1 and path != os.devnull: self.log( "clone {} to {}".format( - cstart[0], " & ".join(str(x) for x in cstart[1:]) + cstart[0], " & ".join(unicode(x) for x in cstart[1:]) ) ) ofs = 0 @@ -697,7 +697,7 @@ class HttpCli(object): raise except Pebkac as ex: - errmsg = str(ex) + errmsg = unicode(ex) td = max(0.1, time.time() - t0) sz_total = sum(x[0] for x in files) @@ -1006,7 +1006,7 @@ class HttpCli(object): mime=guess_mime(req_path)[0] or "application/octet-stream", ) - logmsg += str(status) + logtail + logmsg += unicode(status) + logtail if self.mode == "HEAD" or not do_send: self.log(logmsg) @@ -1020,7 +1020,7 @@ class HttpCli(object): remains = sendfile_py(lower, upper, f, self.s) if remains > 0: - logmsg += " \033[31m" + str(upper - remains) + "\033[0m" + logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m" spd = self._spd((upper - lower) - remains) self.log("{}, {}".format(logmsg, spd)) @@ -1067,7 +1067,7 @@ class HttpCli(object): sz_html = len(template.render(**targs).encode("utf-8")) self.send_headers(sz_html + sz_md, status) - logmsg += str(status) + logmsg += unicode(status) if self.mode == "HEAD" or not do_send: self.log(logmsg) return True @@ -1081,7 +1081,7 @@ class HttpCli(object): self.log(logmsg + " \033[31md/c\033[0m") return False - self.log(logmsg + " " + str(len(html))) + self.log(logmsg + " " + unicode(len(html))) return True def tx_mounts(self): @@ -1297,7 +1297,7 @@ class HttpCli(object): try: if not self.args.nih: - srv_info.append(str(socket.gethostname()).split(".")[0]) + srv_info.append(unicode(socket.gethostname()).split(".")[0]) except: self.log("#wow #whoa") pass diff --git a/copyparty/mtag.py b/copyparty/mtag.py index 1d668230..2454bd29 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -143,7 +143,7 @@ class MTag(object): ret[mk] = [pref, v[0]] # take first value - ret = {k: str(v[1]).strip() for k, v in ret.items()} + ret = {k: unicode(v[1]).strip() for k, v in ret.items()} # track 3/7 => track 3 for k, v in ret.items():