mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
rudimentary jython compat
This commit is contained in:
parent
85454e409a
commit
7b4871b7b8
|
@ -54,7 +54,7 @@ def boring_log(msg):
|
||||||
|
|
||||||
def rice_tid():
|
def rice_tid():
|
||||||
tid = threading.current_thread().ident
|
tid = threading.current_thread().ident
|
||||||
c = struct.unpack("B" * 5, struct.pack(">Q", tid)[-5:])
|
c = struct.unpack(b"B" * 5, struct.pack(b">Q", tid)[-5:])
|
||||||
return "".join("\033[1;37;48;5;{}m{:02x}".format(x, x) for x in c)
|
return "".join("\033[1;37;48;5;{}m{:02x}".format(x, x) for x in c)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,21 @@ class HttpConn(object):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
method = None
|
method = None
|
||||||
|
self.sr = None
|
||||||
if self.cert_path:
|
if self.cert_path:
|
||||||
|
try:
|
||||||
method = self.s.recv(4, socket.MSG_PEEK)
|
method = self.s.recv(4, socket.MSG_PEEK)
|
||||||
|
except AttributeError:
|
||||||
|
# jython does not support msg_peek; forget about https
|
||||||
|
method = self.s.recv(4)
|
||||||
|
self.sr = Unrecv(self.s)
|
||||||
|
self.sr.buf = method
|
||||||
|
|
||||||
|
# jython used to do this, they stopped since it's broken
|
||||||
|
# but reimplementing sendall is out of scope for now
|
||||||
|
if not getattr(self.s, "sendall", None):
|
||||||
|
self.s.sendall = self.s.send
|
||||||
|
|
||||||
if len(method) != 4:
|
if len(method) != 4:
|
||||||
err = "need at least 4 bytes in the first packet; got {}".format(
|
err = "need at least 4 bytes in the first packet; got {}".format(
|
||||||
len(method)
|
len(method)
|
||||||
|
@ -55,6 +68,10 @@ class HttpConn(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if method not in [None, b"GET ", b"HEAD", b"POST"]:
|
if method not in [None, b"GET ", b"HEAD", b"POST"]:
|
||||||
|
if self.sr:
|
||||||
|
self.log("\033[1;31mTODO: cannot do https in jython\033[0m")
|
||||||
|
return
|
||||||
|
|
||||||
self.log_src = self.log_src.replace("[36m", "[35m")
|
self.log_src = self.log_src.replace("[36m", "[35m")
|
||||||
try:
|
try:
|
||||||
self.s = ssl.wrap_socket(
|
self.s = ssl.wrap_socket(
|
||||||
|
@ -76,6 +93,7 @@ class HttpConn(object):
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.sr:
|
||||||
self.sr = Unrecv(self.s)
|
self.sr = Unrecv(self.s)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -75,8 +75,9 @@ class HttpSrv(object):
|
||||||
sck.shutdown(socket.SHUT_RDWR)
|
sck.shutdown(socket.SHUT_RDWR)
|
||||||
sck.close()
|
sck.close()
|
||||||
except (OSError, socket.error) as ex:
|
except (OSError, socket.error) as ex:
|
||||||
if ex.errno not in [107, 9]:
|
if ex.errno not in [107, 57, 9]:
|
||||||
# 107 Transport endpoint not connected
|
# 107 Transport endpoint not connected
|
||||||
|
# 57 Socket is not connected
|
||||||
# 9 Bad file descriptor
|
# 9 Bad file descriptor
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -22,10 +22,9 @@ class TcpSrv(object):
|
||||||
self.num_clients = Counter()
|
self.num_clients = Counter()
|
||||||
|
|
||||||
ip = "127.0.0.1"
|
ip = "127.0.0.1"
|
||||||
if self.args.i == ip:
|
|
||||||
eps = {ip: "local only"}
|
eps = {ip: "local only"}
|
||||||
else:
|
if self.args.i != ip:
|
||||||
eps = self.detect_interfaces(self.args.i)
|
eps = self.detect_interfaces(self.args.i) or eps
|
||||||
|
|
||||||
for ip, desc in sorted(eps.items(), key=lambda x: x[1]):
|
for ip, desc in sorted(eps.items(), key=lambda x: x[1]):
|
||||||
self.log(
|
self.log(
|
||||||
|
@ -97,9 +96,11 @@ class TcpSrv(object):
|
||||||
s.connect(("10.255.255.255", 1))
|
s.connect(("10.255.255.255", 1))
|
||||||
ip = s.getsockname()[0]
|
ip = s.getsockname()[0]
|
||||||
except (OSError, socket.error) as ex:
|
except (OSError, socket.error) as ex:
|
||||||
if ex.errno != 101:
|
if ex.errno not in [101, 10065]:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
if ext_ip in ["0.0.0.0", ip]:
|
if ext_ip in ["0.0.0.0", ip]:
|
||||||
|
|
|
@ -15,11 +15,14 @@ from .stolen import surrogateescape
|
||||||
|
|
||||||
FAKE_MP = False
|
FAKE_MP = False
|
||||||
|
|
||||||
|
try:
|
||||||
if FAKE_MP:
|
if FAKE_MP:
|
||||||
import multiprocessing.dummy as mp # noqa: F401
|
import multiprocessing.dummy as mp # noqa: F401
|
||||||
else:
|
else:
|
||||||
import multiprocessing as mp # noqa: F401
|
import multiprocessing as mp # noqa: F401
|
||||||
|
except ImportError:
|
||||||
|
# support jython
|
||||||
|
mp = None
|
||||||
|
|
||||||
if not PY2:
|
if not PY2:
|
||||||
from urllib.parse import unquote_to_bytes as unquote
|
from urllib.parse import unquote_to_bytes as unquote
|
||||||
|
@ -473,7 +476,7 @@ def chkcmd(*argv):
|
||||||
def gzip_orig_sz(fn):
|
def gzip_orig_sz(fn):
|
||||||
with open(fsenc(fn), "rb") as f:
|
with open(fsenc(fn), "rb") as f:
|
||||||
f.seek(-4, 2)
|
f.seek(-4, 2)
|
||||||
return struct.unpack("I", f.read(4))[0]
|
return struct.unpack(b"I", f.read(4))[0]
|
||||||
|
|
||||||
|
|
||||||
def py_desc():
|
def py_desc():
|
||||||
|
@ -482,7 +485,7 @@ def py_desc():
|
||||||
if ofs > 0:
|
if ofs > 0:
|
||||||
py_ver = py_ver[:ofs]
|
py_ver = py_ver[:ofs]
|
||||||
|
|
||||||
bitness = struct.calcsize("P") * 8
|
bitness = struct.calcsize(b"P") * 8
|
||||||
host_os = platform.system()
|
host_os = platform.system()
|
||||||
|
|
||||||
return "{0} on {1}{2}".format(py_ver, host_os, bitness)
|
return "{0} on {1}{2}".format(py_ver, host_os, bitness)
|
||||||
|
|
26
docs/mistakes.py
Normal file
26
docs/mistakes.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
|
||||||
|
method = self.s.recv(4)
|
||||||
|
self.s.unrecv(method)
|
||||||
|
print("xxx unrecv'd [{}]".format(method))
|
||||||
|
|
||||||
|
# jython used to do this, they stopped since it's broken
|
||||||
|
# but reimplementing sendall is out of scope for now
|
||||||
|
if not getattr(self.s.s, "sendall", None):
|
||||||
|
self.s.s.sendall = self.s.s.send
|
||||||
|
|
||||||
|
# TODO this is also pretty bad
|
||||||
|
have = dir(self.s)
|
||||||
|
for k in self.s.s.__dict__:
|
||||||
|
if k not in have and not k.startswith("__"):
|
||||||
|
if k == "recv":
|
||||||
|
raise Exception("wait what")
|
||||||
|
|
||||||
|
self.s.__dict__[k] = self.s.s.__dict__[k]
|
||||||
|
|
||||||
|
have = dir(self.s)
|
||||||
|
for k in dir(self.s.s):
|
||||||
|
if k not in have and not k.startswith("__"):
|
||||||
|
if k == "recv":
|
||||||
|
raise Exception("wait what")
|
||||||
|
|
||||||
|
setattr(self.s, k, getattr(self.s.s, k))
|
|
@ -76,3 +76,7 @@ cat copyparty/httpcli.py | awk '/^[^a-zA-Z0-9]+def / {printf "%s\n%s\n\n", f, pl
|
||||||
|
|
||||||
# create a folder with symlinks to big files
|
# create a folder with symlinks to big files
|
||||||
for d in /usr /var; do find $d -type f -size +30M 2>/dev/null; done | while IFS= read -r x; do ln -s "$x" big/; done
|
for d in /usr /var; do find $d -type f -size +30M 2>/dev/null; done | while IFS= read -r x; do ln -s "$x" big/; done
|
||||||
|
|
||||||
|
# py2 on osx
|
||||||
|
brew install python@2
|
||||||
|
pip install virtualenv
|
||||||
|
|
Loading…
Reference in a new issue