fix py2 + encourage py3

This commit is contained in:
ed 2021-03-06 02:42:17 +01:00
parent 2381692aba
commit bd769f5bdb
3 changed files with 11 additions and 11 deletions

View file

@ -12,7 +12,7 @@
Description=copyparty file server Description=copyparty file server
[Service] [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' ExecStartPre=/bin/bash -c 'mkdir -p /run/tmpfiles.d/ && echo "x /tmp/pe-copyparty*" > /run/tmpfiles.d/copyparty.conf'
[Install] [Install]

View file

@ -74,7 +74,7 @@ class HttpCli(object):
except Pebkac as ex: except Pebkac as ex:
# self.log("pebkac at httpcli.run #1: " + repr(ex)) # self.log("pebkac at httpcli.run #1: " + repr(ex))
self.keepalive = self._check_nonfatal(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 return self.keepalive
# time.sleep(0.4) # time.sleep(0.4)
@ -163,7 +163,7 @@ class HttpCli(object):
response = ["HTTP/1.1 {} {}".format(status, HTTPCODE[status])] response = ["HTTP/1.1 {} {}".format(status, HTTPCODE[status])]
if length is not None: 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 # close if unknown length, otherwise take client's preference
response.append("Connection: " + ("Keep-Alive" if self.keepalive else "Close")) 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: if len(cstart) > 1 and path != os.devnull:
self.log( self.log(
"clone {} to {}".format( "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 ofs = 0
@ -697,7 +697,7 @@ class HttpCli(object):
raise raise
except Pebkac as ex: except Pebkac as ex:
errmsg = str(ex) errmsg = unicode(ex)
td = max(0.1, time.time() - t0) td = max(0.1, time.time() - t0)
sz_total = sum(x[0] for x in files) 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", 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: if self.mode == "HEAD" or not do_send:
self.log(logmsg) self.log(logmsg)
@ -1020,7 +1020,7 @@ class HttpCli(object):
remains = sendfile_py(lower, upper, f, self.s) remains = sendfile_py(lower, upper, f, self.s)
if remains > 0: 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) spd = self._spd((upper - lower) - remains)
self.log("{}, {}".format(logmsg, spd)) self.log("{}, {}".format(logmsg, spd))
@ -1067,7 +1067,7 @@ class HttpCli(object):
sz_html = len(template.render(**targs).encode("utf-8")) sz_html = len(template.render(**targs).encode("utf-8"))
self.send_headers(sz_html + sz_md, status) self.send_headers(sz_html + sz_md, status)
logmsg += str(status) logmsg += unicode(status)
if self.mode == "HEAD" or not do_send: if self.mode == "HEAD" or not do_send:
self.log(logmsg) self.log(logmsg)
return True return True
@ -1081,7 +1081,7 @@ class HttpCli(object):
self.log(logmsg + " \033[31md/c\033[0m") self.log(logmsg + " \033[31md/c\033[0m")
return False return False
self.log(logmsg + " " + str(len(html))) self.log(logmsg + " " + unicode(len(html)))
return True return True
def tx_mounts(self): def tx_mounts(self):
@ -1297,7 +1297,7 @@ class HttpCli(object):
try: try:
if not self.args.nih: if not self.args.nih:
srv_info.append(str(socket.gethostname()).split(".")[0]) srv_info.append(unicode(socket.gethostname()).split(".")[0])
except: except:
self.log("#wow #whoa") self.log("#wow #whoa")
pass pass

View file

@ -143,7 +143,7 @@ class MTag(object):
ret[mk] = [pref, v[0]] ret[mk] = [pref, v[0]]
# take first value # 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 # track 3/7 => track 3
for k, v in ret.items(): for k, v in ret.items():