diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 8b990997..d9dc64dc 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -42,6 +42,7 @@ from .util import ( DEF_EXP, DEF_MTE, DEF_MTH, + HAVE_IPV6, IMPLICATIONS, JINJA_VER, MIMES, @@ -293,6 +294,9 @@ def get_ah_salt() -> str: def ensure_locale() -> None: + if ANYWIN and PY2: + return # maybe XP, so busted 65001 + safe = "en_US.UTF-8" for x in [ safe, @@ -1594,6 +1598,9 @@ def main(argv: Optional[list[str]] = None, rsrc: Optional[str] = None) -> None: if getattr(al, k1): setattr(al, k2, False) + if not HAVE_IPV6 and al.i == "::": + al.i = "0.0.0.0" + al.i = al.i.split(",") try: if "-" in al.p: diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index 8d00eaab..4ee1b4dd 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -15,6 +15,7 @@ from .util import ( E_ADDR_IN_USE, E_ADDR_NOT_AVAIL, E_UNREACH, + HAVE_IPV6, IP6ALL, Netdev, min_ex, @@ -111,8 +112,10 @@ class TcpSrv(object): eps = { "127.0.0.1": Netdev("127.0.0.1", 0, "", "local only"), - "::1": Netdev("::1", 0, "", "local only"), } + if HAVE_IPV6: + eps["::1"] = Netdev("::1", 0, "", "local only") + nonlocals = [x for x in self.args.i if x not in [k.split("/")[0] for k in eps]] if nonlocals: try: diff --git a/copyparty/tftpd.py b/copyparty/tftpd.py index 0ee45dec..c46a8fd5 100644 --- a/copyparty/tftpd.py +++ b/copyparty/tftpd.py @@ -33,7 +33,7 @@ from partftpy import ( ) from partftpy.TftpShared import TftpException -from .__init__ import EXE, TYPE_CHECKING +from .__init__ import EXE, PY2, TYPE_CHECKING from .authsrv import VFS from .bos import bos from .util import BytesIO, Daemon, ODict, exclude_dotfiles, min_ex, runhook, undot @@ -95,7 +95,7 @@ class Tftpd(object): TftpServer, ] cbak = [] - if not self.args.tftp_no_fast and not EXE: + if not self.args.tftp_no_fast and not EXE and not PY2: try: ptn = re.compile(r"(^\s*)log\.debug\(.*\)$") for C in Cs: @@ -105,7 +105,7 @@ class Tftpd(object): cfn = C.__spec__.origin exec (compile(src2, filename=cfn, mode="exec"), C.__dict__) except Exception: - t = "failed to optimize tftp code; run with --tftp-noopt if there are issues:\n" + t = "failed to optimize tftp code; run with --tftp-no-fast if there are issues:\n" self.log("tftp", t + min_ex(), 3) for n, zd in enumerate(cbak): Cs[n].__dict__ = zd diff --git a/copyparty/util.py b/copyparty/util.py index 55068fe0..14a0bf1c 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -158,6 +158,17 @@ else: from urllib import unquote # type: ignore # pylint: disable=no-name-in-module +try: + socket.inet_pton(socket.AF_INET6, "::1") + HAVE_IPV6 = True +except: + def inet_pton(fam, ip): + return socket.inet_aton(ip) + + socket.inet_pton = inet_pton + HAVE_IPV6 = False + + try: struct.unpack(b">i", b"idgi") spack = struct.pack # type: ignore @@ -2459,6 +2470,9 @@ def build_netmap(csv: str): csv += ", 127.0.0.0/8, ::1/128" # loopback srcs = [x.strip() for x in csv.split(",") if x.strip()] + if not HAVE_IPV6: + srcs = [x for x in srcs if ":" not in x] + cidrs = [] for zs in srcs: if not zs.endswith("."): diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index a1e3c190..798683fa 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -490,6 +490,11 @@ while IFS= read -r f; do tmv "$f" done +grep -rlE '^class [^(]+:' | +while IFS= read -r f; do + ised 's/(^class [^(:]+):/\1(object):/' "$f" +done + # up2k goes from 28k to 22k laff awk 'BEGIN{gensub(//,"",1)}' /dev/null && echo entabbening &&