From c1315a3b395522171a88848e0e1e5b2690178ba3 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 26 Nov 2022 20:06:48 +0000 Subject: [PATCH] webdav: misc fixes --- copyparty/__init__.py | 4 ++-- copyparty/httpcli.py | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/copyparty/__init__.py b/copyparty/__init__.py index b5c50ad4..a9bdaf95 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -12,11 +12,11 @@ except: TYPE_CHECKING = False if True: - from typing import Any, Callable + from typing import Any, Union, Callable PY2 = sys.version_info < (3,) if not PY2: - unicode: Callable[[str], str] = str + unicode: Callable[[Union[str, int, float]], str] = str else: sys.dont_write_bytecode = True unicode = unicode # noqa: F821 # pylint: disable=undefined-variable,self-assigning-variable diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 459bcecf..2cc09b16 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -425,7 +425,7 @@ class HttpCli(object): raise Pebkac(400, 'invalid HTTP mode "{0}"'.format(self.mode)) except Exception as ex: - if not hasattr(ex, "code"): + if not isinstance(ex, Pebkac): pex = Pebkac(500) else: pex: Pebkac = ex # type: ignore @@ -793,6 +793,10 @@ class HttpCli(object): _, vfs_ls, vfs_virt = vn.ls( rem, self.uname, not self.args.no_scandir, [[True, False]] ) + if not self.args.ed: + names = set(exclude_dotfiles([x[0] for x in vfs_ls])) + vfs_ls = [x for x in vfs_ls if x[0] in names] + zi = int(time.time()) zsr = os.stat_result((16877, -1, -1, 1, 1000, 1000, 8, zi, zi, zi)) ls = [{"vp": vp, "st": st} for vp, st in vfs_ls] @@ -826,22 +830,21 @@ class HttpCli(object): ret = '\n' ret = ret.format(uenc) for x in fgen: - vp = x["vp"] + rp = vjoin(vtop, x["vp"]) st: os.stat_result = x["st"] - rp = vjoin(vtop, vp) isdir = stat.S_ISDIR(st.st_mode) t = "/{}{}" - ret += t.format(quotep(rp), "/" if isdir and vp else "") + ret += t.format(quotep(rp), "/" if isdir and rp else "") pvs: dict[str, str] = { - "displayname": html_escape(vp.split("/")[-1]), + "displayname": html_escape(rp.split("/")[-1]), "getlastmodified": formatdate(st.st_mtime, usegmt=True), "resourcetype": '' if isdir else "", "supportedlock": '', } if not isdir: - pvs["getcontenttype"] = guess_mime(vp) + pvs["getcontenttype"] = guess_mime(rp) pvs["getcontentlength"] = str(st.st_size) for k, v in pvs.items(): @@ -868,6 +871,7 @@ class HttpCli(object): ret = self.send_chunk(ret, enc, chunksz) self.send_chunk("", enc, chunksz) + # self.reply(ret.encode(enc, "replace"),207, "text/xml; charset=" + enc) return True def handle_proppatch(self) -> bool: @@ -882,6 +886,7 @@ class HttpCli(object): raise Pebkac(401, "authenticate") from xml.etree import ElementTree as ET + from .dxml import mkenod, mktnod, parse_xml self.asrv.vfs.get(self.vpath, self.uname, False, False) @@ -940,6 +945,7 @@ class HttpCli(object): raise Pebkac(401, "authenticate") from xml.etree import ElementTree as ET + from .dxml import mkenod, mktnod, parse_xml vn, rem = self.asrv.vfs.get(self.vpath, self.uname, False, False)