Skip to content

Commit

Permalink
support windows 2000 and XP
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Jun 16, 2024
1 parent 52e0622 commit 8c73e0c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 7 additions & 0 deletions copyparty/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
DEF_EXP,
DEF_MTE,
DEF_MTH,
HAVE_IPV6,
IMPLICATIONS,
JINJA_VER,
MIMES,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion copyparty/tcpsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
E_ADDR_IN_USE,
E_ADDR_NOT_AVAIL,
E_UNREACH,
HAVE_IPV6,
IP6ALL,
Netdev,
min_ex,
Expand Down Expand Up @@ -111,8 +112,10 @@ def __init__(self, hub: "SvcHub"):

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:
Expand Down
6 changes: 3 additions & 3 deletions copyparty/tftpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, **attr):
)
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
Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__(self, hub: "SvcHub") -> None:
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:
Expand All @@ -105,7 +105,7 @@ def __init__(self, hub: "SvcHub") -> None:
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
Expand Down
14 changes: 14 additions & 0 deletions copyparty/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ def __call__(self, msg: str, c: Union[int, str] = 0) -> None:
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
Expand Down Expand Up @@ -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("."):
Expand Down
5 changes: 5 additions & 0 deletions scripts/make-sfx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 2>/dev/null &&
echo entabbening &&
Expand Down

0 comments on commit 8c73e0c

Please sign in to comment.