webdav: support explicit <allprop/> (WinSCP)

This commit is contained in:
ed 2024-10-02 22:28:23 +00:00
parent 1ff14b4e05
commit dc157fa28f
2 changed files with 32 additions and 28 deletions

View file

@ -44,6 +44,7 @@ from .util import unquote # type: ignore
from .util import ( from .util import (
APPLESAN_RE, APPLESAN_RE,
BITNESS, BITNESS,
DAV_ALLPROPS,
HAVE_SQLITE3, HAVE_SQLITE3,
HTTPCODE, HTTPCODE,
META_NOBOTS, META_NOBOTS,
@ -1203,7 +1204,7 @@ class HttpCli(object):
tap = vn.canonical(rem) tap = vn.canonical(rem)
if "davauth" in vn.flags and self.uname == "*": if "davauth" in vn.flags and self.uname == "*":
self.can_read = self.can_write = self.can_get = False raise Pebkac(401, "authenticate")
from .dxml import parse_xml from .dxml import parse_xml
@ -1211,6 +1212,7 @@ class HttpCli(object):
# enc = "shift_jis" # enc = "shift_jis"
enc = "utf-8" enc = "utf-8"
uenc = enc.upper() uenc = enc.upper()
props = DAV_ALLPROPS
clen = int(self.headers.get("content-length", 0)) clen = int(self.headers.get("content-length", 0))
if clen: if clen:
@ -1221,33 +1223,10 @@ class HttpCli(object):
break break
xroot = parse_xml(buf.decode(enc, "replace")) xroot = parse_xml(buf.decode(enc, "replace"))
xtag = next(x for x in xroot if x.tag.split("}")[-1] == "prop") xtag = next((x for x in xroot if x.tag.split("}")[-1] == "prop"), None)
props_lst = [y.tag.split("}")[-1] for y in xtag] if xtag is not None:
else: props = set([y.tag.split("}")[-1] for y in xtag])
props_lst = [ # assume <allprop/> otherwise; nobody ever gonna <propname/>
"contentclass",
"creationdate",
"defaultdocument",
"displayname",
"getcontentlanguage",
"getcontentlength",
"getcontenttype",
"getlastmodified",
"href",
"iscollection",
"ishidden",
"isreadonly",
"isroot",
"isstructureddocument",
"lastaccessed",
"name",
"parentname",
"resourcetype",
"supportedlock",
]
props = set(props_lst)
depth = self.headers.get("depth", "infinity").lower()
zi = int(time.time()) zi = int(time.time())
vst = os.stat_result((16877, -1, -1, 1, 1000, 1000, 8, zi, zi, zi)) vst = os.stat_result((16877, -1, -1, 1, 1000, 1000, 8, zi, zi, zi))
@ -1261,6 +1240,7 @@ class HttpCli(object):
fgen: Iterable[dict[str, Any]] = [] fgen: Iterable[dict[str, Any]] = []
depth = self.headers.get("depth", "infinity").lower()
if depth == "infinity": if depth == "infinity":
if not self.can_read: if not self.can_read:
t = "depth:infinity requires read-access in /%s" t = "depth:infinity requires read-access in /%s"

View file

@ -290,6 +290,30 @@ if ANYWIN:
UNPLICATIONS = [["no_dav", "daw"]] UNPLICATIONS = [["no_dav", "daw"]]
DAV_ALLPROP_L = [
"contentclass",
"creationdate",
"defaultdocument",
"displayname",
"getcontentlanguage",
"getcontentlength",
"getcontenttype",
"getlastmodified",
"href",
"iscollection",
"ishidden",
"isreadonly",
"isroot",
"isstructureddocument",
"lastaccessed",
"name",
"parentname",
"resourcetype",
"supportedlock",
]
DAV_ALLPROPS = set(DAV_ALLPROP_L)
MIMES = { MIMES = {
"opus": "audio/ogg; codecs=opus", "opus": "audio/ogg; codecs=opus",
} }